forked from hughbzhang/Competitive_Programming
-
Notifications
You must be signed in to change notification settings - Fork 0
/
blink.cpp
69 lines (62 loc) · 1.27 KB
/
blink.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
66
67
68
69
#include <cstdio>
#define MAX (1<<17)
using namespace std;
int num;
int cnt = 0;
long long time;
int reverse[MAX];
bool lights[16];
int vis[MAX];
bool toggle[16];//whether to toggle or not
int convert(){
int total = 0;
int now = 1;
for(int x = 0;x<num;x++){
total+=now*lights[x];
now*=2;
}
return total;
}
void print(){
for(int x = 0;x<num;x++){
printf("%d",lights[x]);
}
printf("\n");
}
void run(){
if(lights[num-1]) toggle[0] = 1;
else toggle[0] = 0;
for(int x = 1;x<num;x++){
if(lights[x-1]) toggle[x] = 1;
else toggle[x] = 0;
}
for(int x = 0;x<num;x++){
if(toggle[x]) lights[x] = !lights[x];
}
print();
}
int main(){
freopen("blink.in","r",stdin);
scanf("%d%lld",&num,&time);
for(int x = 0;x<num;x++){
int a;
scanf("%d",&a);
if(a==0) lights[x] = 0;
else lights[x] = 1;
}
int now;
while(true){
now = convert();
if(vis[now]) break;
vis[now] = cnt;
reverse[cnt] = now;
run();
cnt++;
}
int done = reverse[vis[now]+((time-vis[now])%(cnt-vis[now]))];
for(int x = 0;x<num;x++){
if(done&(1<<x)) printf("1\n");
else printf("0\n");
}
return 0;
}