forked from daiwb/Algorithm
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path160.cpp
More file actions
50 lines (47 loc) · 858 Bytes
/
160.cpp
File metadata and controls
50 lines (47 loc) · 858 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
//ac
#include <iostream>
#include <cstdio>
#include <cstring>
#include <string>
#include <vector>
using namespace std;
int a[10000], n, m;
int mm[1000];
int bk[1000];
int res[1000];
int out[1000];
int main() {
scanf("%d %d", &n, &m);
for (int i = 0; i < n; ++i) scanf("%d", &a[i]);
memset(mm, 0, sizeof(mm));
mm[1] = 1;
int ret = 1;
for (int i = 0; i < n; ++i) {
memcpy(bk, mm, sizeof(mm));
for (int j = 1; j <= ret; ++j) {
if (bk[j]) {
int now = (a[i] * j) % m;
if (mm[now] == 0) {
if (now > ret) {
ret = now;
}
mm[now] = j;
res[now] = i;
}
}
}
}
printf("%d\n", ret);
if (ret == 1) return 0;
int num = 0;
while (ret != 1) {
out[num++] = res[ret];
ret = mm[ret];
}
for (int i = 0; i < num; ++i) {
if (i) printf(" ");
printf("%d", out[num - 1 - i] + 1);
}
printf("\n");
return 0;
}