forked from volzkzg/sgu
-
Notifications
You must be signed in to change notification settings - Fork 1
/
160.cpp
65 lines (61 loc) · 1.39 KB
/
160.cpp
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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <algorithm>
using namespace std;
bool f[10011][1011];
int pre[10011][1011];
int ans[10011],ans_num;
int n,m,tmp,i,j,k;
int a[10011],max_num=1,max_pos;
int main(){
freopen("test.in","r",stdin);
freopen("test.out","w",stdout);
scanf("%d%d\n",&n,&m);
memset(f,false,sizeof(f));
f[0][1] = true;
for (i=1;i<=n;++i)
{
scanf("%d",&tmp);
a[i] = tmp;
f[i][1] = true;
for (j=1;j<m;++j)
pre[i][j] = 1;
for (j=1;j<m;++j){
if (f[i-1][j]){
k = (j*tmp)%m;
if (k>max_num){
max_num = k;
max_pos = i;
}
f[i][k] = true;
pre[i][k] = j;
//cout << i << " " << k << " " << tmp << " " << j << endl;
f[i][j] = true;
pre[i][j] = j;
//cout << i << " " << j << " " << tmp << " " << j << endl;
}
}
f[i][tmp%m] = true;
pre[i][tmp%m] = 1;
}
if (max_num==1){
printf("1\n");
return 0;
}else{
tmp = max_num;
k = max_pos;
printf("%d\n",tmp);
while ((tmp != 1 || k==n) && k>=1 ){
//cout << pre[k][tmp] << " " << tmp << " " << k << endl;
if (pre[k][tmp] != tmp){
ans[ans_num++] = k;
tmp = pre[k][tmp];
}
k--;
}sort(ans,ans+ans_num);
for (i=0;i<ans_num-1;++i) printf("%d ",ans[i]);
printf("%d\n",ans[ans_num-1]);
}return 0;
}