# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
197290 | 2020-01-20T08:14:51 Z | dennisstar | Snake Escaping (JOI18_snake_escaping) | C++11 | 2000 ms | 19320 KB |
#include <bits/stdc++.h> #pragma GCC optimize("Ofast") #pragma GCC optimize("unroll-loops") #define fi first #define se second #define ryan bear #define sq(X) ((X)*(X)) #define eb emplace_back #define all(V) (V).begin(), (V).end() #define unq(V) (V).erase(unique(all(V)), (V).end()) using namespace std; typedef long long ll; typedef vector<ll> vlm; typedef vector<int> vim; typedef pair<ll, ll> pll; typedef pair<int, int> pii; int L, Q; int a1[(1<<20)], a2[(1<<20)], a3[(1<<20)], a4[(1<<20)]; //01, 0?, ?1 char s[20]; pii stk[(1<<20)]; vim bs; inline void f1() { int x, y, ans; x=y=ans=0; for (int i=0; i<L; i++) { if (s[i]=='1') x|=(1<<i); if (s[i]=='0') y|=(1<<i); } ans+=a3[x]; for (int i=y; i; i=(i-1)&y) ans+=a3[i|x]*(a4[i]%2?-1:1); printf("%d\n", ans); } inline void f2() { int x, y, ans; x=y=ans=0; for (int i=0; i<L; i++) { if (s[i]=='0') x|=(1<<i); if (s[i]=='1') y|=(1<<i); } ans+=a2[x]; for (int i=y; i; i=(i-1)&y) ans+=a2[i|x]*(a4[i]%2?-1:1); printf("%d\n", ans); } inline void f3() { int x, y, ans; x=y=ans=0; for (int i=0; i<L; i++) { if (s[i]=='1') x|=(1<<i); if (s[i]=='?') y|=(1<<i); } ans+=a1[x]; for (int i=y; i; i=(i-1)&y) ans+=a1[i|x]; printf("%d\n", ans); } int main() { scanf("%d %d", &L, &Q); for (int i=0; i<(1<<L); i++) scanf("%1d", &a1[i]); for (int i=0; i<(1<<L); i++) { if (i) a4[i]=a4[i-(i&-i)]+1; a2[i^((1<<L)-1)]+=a1[i]; a3[i]+=a1[i]; } for (int i=0; i<L; i++) for (int j=0; j<(1<<L); j++) if (!((j>>i)&1)) { a2[j]+=a2[j|(1<<i)]; a3[j]+=a3[j|(1<<i)]; } while (Q--) { scanf("%s", s); int c0=0, c1=0, cq=0; for (int i=0; i<L; i++) (s[i]=='0'?c0:s[i]=='1'?c1:cq)++; reverse(s, s+L); f1(); continue; if (c0<=L/3) f1(); else if (c1<=L/3) f2(); else f3(); } return 0; }
Compilation message
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 3 ms | 504 KB | Output is correct |
2 | Correct | 3 ms | 376 KB | Output is correct |
3 | Correct | 3 ms | 376 KB | Output is correct |
4 | Correct | 3 ms | 376 KB | Output is correct |
5 | Correct | 3 ms | 376 KB | Output is correct |
6 | Correct | 2 ms | 376 KB | Output is correct |
7 | Correct | 2 ms | 376 KB | Output is correct |
8 | Correct | 2 ms | 376 KB | Output is correct |
9 | Correct | 2 ms | 376 KB | Output is correct |
10 | Correct | 2 ms | 380 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 3 ms | 504 KB | Output is correct |
2 | Correct | 3 ms | 376 KB | Output is correct |
3 | Correct | 3 ms | 376 KB | Output is correct |
4 | Correct | 3 ms | 376 KB | Output is correct |
5 | Correct | 3 ms | 376 KB | Output is correct |
6 | Correct | 2 ms | 376 KB | Output is correct |
7 | Correct | 2 ms | 376 KB | Output is correct |
8 | Correct | 2 ms | 376 KB | Output is correct |
9 | Correct | 2 ms | 376 KB | Output is correct |
10 | Correct | 2 ms | 380 KB | Output is correct |
11 | Correct | 269 ms | 6748 KB | Output is correct |
12 | Correct | 336 ms | 6492 KB | Output is correct |
13 | Correct | 307 ms | 5596 KB | Output is correct |
14 | Correct | 281 ms | 5756 KB | Output is correct |
15 | Correct | 260 ms | 6648 KB | Output is correct |
16 | Correct | 282 ms | 5876 KB | Output is correct |
17 | Correct | 317 ms | 5848 KB | Output is correct |
18 | Correct | 234 ms | 7672 KB | Output is correct |
19 | Correct | 314 ms | 4728 KB | Output is correct |
20 | Correct | 282 ms | 6344 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 3 ms | 504 KB | Output is correct |
2 | Correct | 3 ms | 376 KB | Output is correct |
3 | Correct | 3 ms | 376 KB | Output is correct |
4 | Correct | 3 ms | 376 KB | Output is correct |
5 | Correct | 3 ms | 376 KB | Output is correct |
6 | Correct | 2 ms | 376 KB | Output is correct |
7 | Correct | 2 ms | 376 KB | Output is correct |
8 | Correct | 2 ms | 376 KB | Output is correct |
9 | Correct | 2 ms | 376 KB | Output is correct |
10 | Correct | 2 ms | 380 KB | Output is correct |
11 | Correct | 269 ms | 6748 KB | Output is correct |
12 | Correct | 336 ms | 6492 KB | Output is correct |
13 | Correct | 307 ms | 5596 KB | Output is correct |
14 | Correct | 281 ms | 5756 KB | Output is correct |
15 | Correct | 260 ms | 6648 KB | Output is correct |
16 | Correct | 282 ms | 5876 KB | Output is correct |
17 | Correct | 317 ms | 5848 KB | Output is correct |
18 | Correct | 234 ms | 7672 KB | Output is correct |
19 | Correct | 314 ms | 4728 KB | Output is correct |
20 | Correct | 282 ms | 6344 KB | Output is correct |
21 | Correct | 331 ms | 7152 KB | Output is correct |
22 | Correct | 633 ms | 7212 KB | Output is correct |
23 | Correct | 427 ms | 6368 KB | Output is correct |
24 | Correct | 371 ms | 5980 KB | Output is correct |
25 | Correct | 305 ms | 7928 KB | Output is correct |
26 | Correct | 358 ms | 6520 KB | Output is correct |
27 | Correct | 426 ms | 6408 KB | Output is correct |
28 | Correct | 255 ms | 8860 KB | Output is correct |
29 | Correct | 424 ms | 4600 KB | Output is correct |
30 | Correct | 361 ms | 6520 KB | Output is correct |
31 | Correct | 360 ms | 6392 KB | Output is correct |
32 | Correct | 340 ms | 6392 KB | Output is correct |
33 | Correct | 344 ms | 5240 KB | Output is correct |
34 | Correct | 405 ms | 5240 KB | Output is correct |
35 | Correct | 431 ms | 5624 KB | Output is correct |
36 | Correct | 246 ms | 16296 KB | Output is correct |
37 | Correct | 470 ms | 18296 KB | Output is correct |
38 | Correct | 718 ms | 16216 KB | Output is correct |
39 | Correct | 377 ms | 17400 KB | Output is correct |
40 | Correct | 355 ms | 17300 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 3 ms | 504 KB | Output is correct |
2 | Correct | 3 ms | 376 KB | Output is correct |
3 | Correct | 3 ms | 376 KB | Output is correct |
4 | Correct | 3 ms | 376 KB | Output is correct |
5 | Correct | 3 ms | 376 KB | Output is correct |
6 | Correct | 2 ms | 376 KB | Output is correct |
7 | Correct | 2 ms | 376 KB | Output is correct |
8 | Correct | 2 ms | 376 KB | Output is correct |
9 | Correct | 2 ms | 376 KB | Output is correct |
10 | Correct | 2 ms | 380 KB | Output is correct |
11 | Correct | 156 ms | 19192 KB | Output is correct |
12 | Correct | 606 ms | 19164 KB | Output is correct |
13 | Correct | 328 ms | 18936 KB | Output is correct |
14 | Correct | 178 ms | 19064 KB | Output is correct |
15 | Correct | 156 ms | 19108 KB | Output is correct |
16 | Correct | 169 ms | 19092 KB | Output is correct |
17 | Correct | 228 ms | 19040 KB | Output is correct |
18 | Correct | 149 ms | 19224 KB | Output is correct |
19 | Correct | 330 ms | 19028 KB | Output is correct |
20 | Correct | 159 ms | 19320 KB | Output is correct |
21 | Correct | 166 ms | 19024 KB | Output is correct |
22 | Correct | 166 ms | 19008 KB | Output is correct |
23 | Correct | 158 ms | 18964 KB | Output is correct |
24 | Correct | 212 ms | 19172 KB | Output is correct |
25 | Correct | 210 ms | 19064 KB | Output is correct |
26 | Correct | 147 ms | 18936 KB | Output is correct |
27 | Correct | 341 ms | 19320 KB | Output is correct |
28 | Correct | 636 ms | 19036 KB | Output is correct |
29 | Correct | 168 ms | 18944 KB | Output is correct |
30 | Correct | 178 ms | 19044 KB | Output is correct |
31 | Correct | 1329 ms | 19024 KB | Output is correct |
32 | Correct | 208 ms | 19064 KB | Output is correct |
33 | Correct | 210 ms | 19064 KB | Output is correct |
34 | Execution timed out | 2035 ms | 18040 KB | Time limit exceeded |
35 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 3 ms | 504 KB | Output is correct |
2 | Correct | 3 ms | 376 KB | Output is correct |
3 | Correct | 3 ms | 376 KB | Output is correct |
4 | Correct | 3 ms | 376 KB | Output is correct |
5 | Correct | 3 ms | 376 KB | Output is correct |
6 | Correct | 2 ms | 376 KB | Output is correct |
7 | Correct | 2 ms | 376 KB | Output is correct |
8 | Correct | 2 ms | 376 KB | Output is correct |
9 | Correct | 2 ms | 376 KB | Output is correct |
10 | Correct | 2 ms | 380 KB | Output is correct |
11 | Correct | 269 ms | 6748 KB | Output is correct |
12 | Correct | 336 ms | 6492 KB | Output is correct |
13 | Correct | 307 ms | 5596 KB | Output is correct |
14 | Correct | 281 ms | 5756 KB | Output is correct |
15 | Correct | 260 ms | 6648 KB | Output is correct |
16 | Correct | 282 ms | 5876 KB | Output is correct |
17 | Correct | 317 ms | 5848 KB | Output is correct |
18 | Correct | 234 ms | 7672 KB | Output is correct |
19 | Correct | 314 ms | 4728 KB | Output is correct |
20 | Correct | 282 ms | 6344 KB | Output is correct |
21 | Correct | 331 ms | 7152 KB | Output is correct |
22 | Correct | 633 ms | 7212 KB | Output is correct |
23 | Correct | 427 ms | 6368 KB | Output is correct |
24 | Correct | 371 ms | 5980 KB | Output is correct |
25 | Correct | 305 ms | 7928 KB | Output is correct |
26 | Correct | 358 ms | 6520 KB | Output is correct |
27 | Correct | 426 ms | 6408 KB | Output is correct |
28 | Correct | 255 ms | 8860 KB | Output is correct |
29 | Correct | 424 ms | 4600 KB | Output is correct |
30 | Correct | 361 ms | 6520 KB | Output is correct |
31 | Correct | 360 ms | 6392 KB | Output is correct |
32 | Correct | 340 ms | 6392 KB | Output is correct |
33 | Correct | 344 ms | 5240 KB | Output is correct |
34 | Correct | 405 ms | 5240 KB | Output is correct |
35 | Correct | 431 ms | 5624 KB | Output is correct |
36 | Correct | 246 ms | 16296 KB | Output is correct |
37 | Correct | 470 ms | 18296 KB | Output is correct |
38 | Correct | 718 ms | 16216 KB | Output is correct |
39 | Correct | 377 ms | 17400 KB | Output is correct |
40 | Correct | 355 ms | 17300 KB | Output is correct |
41 | Correct | 156 ms | 19192 KB | Output is correct |
42 | Correct | 606 ms | 19164 KB | Output is correct |
43 | Correct | 328 ms | 18936 KB | Output is correct |
44 | Correct | 178 ms | 19064 KB | Output is correct |
45 | Correct | 156 ms | 19108 KB | Output is correct |
46 | Correct | 169 ms | 19092 KB | Output is correct |
47 | Correct | 228 ms | 19040 KB | Output is correct |
48 | Correct | 149 ms | 19224 KB | Output is correct |
49 | Correct | 330 ms | 19028 KB | Output is correct |
50 | Correct | 159 ms | 19320 KB | Output is correct |
51 | Correct | 166 ms | 19024 KB | Output is correct |
52 | Correct | 166 ms | 19008 KB | Output is correct |
53 | Correct | 158 ms | 18964 KB | Output is correct |
54 | Correct | 212 ms | 19172 KB | Output is correct |
55 | Correct | 210 ms | 19064 KB | Output is correct |
56 | Correct | 147 ms | 18936 KB | Output is correct |
57 | Correct | 341 ms | 19320 KB | Output is correct |
58 | Correct | 636 ms | 19036 KB | Output is correct |
59 | Correct | 168 ms | 18944 KB | Output is correct |
60 | Correct | 178 ms | 19044 KB | Output is correct |
61 | Correct | 1329 ms | 19024 KB | Output is correct |
62 | Correct | 208 ms | 19064 KB | Output is correct |
63 | Correct | 210 ms | 19064 KB | Output is correct |
64 | Execution timed out | 2035 ms | 18040 KB | Time limit exceeded |
65 | Halted | 0 ms | 0 KB | - |