# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
199754 | 2020-02-03T07:18:19 Z | Mercenary | Snake Escaping (JOI18_snake_escaping) | C++14 | 1924 ms | 43416 KB |
#include<bits/stdc++.h> #define pb push_back #define mp make_pair #define taskname "A" using namespace std; typedef long long ll; typedef long double ld; typedef pair<int,int> ii; const int maxn = (1 << 20); string s; int n , q; int dp[2][maxn]; int res , f , nf , tmp; int cnt[3] , a[maxn]; int main() { ios_base::sync_with_stdio(0); cin.tie(0); if(fopen(taskname".INP","r")){ freopen(taskname".INP", "r",stdin); freopen(taskname".OUT", "w",stdout); } cin >> n >> q >> s; for(int i = 0 ; i < (1 << n) ; ++i){ dp[0][i] = dp[1][(1 << n) - 1 - i] = a[i] = s[i] - '0'; } for(int i = 0 ; i < n ; ++i){ for(int j = (1 << n) - 1 ; j >= 0 ; --j){ if(j & (1 << i))dp[0][j ^ (1 << i)] += dp[0][j] , dp[1][j ^ (1 << i)] += dp[1][j] ; } } // cout << dp[1][7]; while(q--){ cnt[0] = cnt[1] = cnt[2] = res = f = nf = 0; cin >> s; for(int i = 0 ; i < n ; ++i){ if(s[i] == '0')s[i] = 0; else if(s[i] == '1')s[i] = 1; else s[i] = 2; cnt[s[i]] |= (1 << (n - i - 1)); } tmp = min_element(cnt,cnt+3,[&](const int x , const int y){ return __builtin_popcount(x)<__builtin_popcount(y);})-cnt; int *dp = ::dp[tmp]; for(int i = cnt[tmp] ;; i = (i - 1) & cnt[tmp]){ if(tmp < 2){ if(__builtin_popcount(i) & 1)res -= dp[i | cnt[!tmp]]; else res += dp[i | cnt[!tmp]]; }else{ res += a[i | cnt[1]]; } if(i == 0)break; } cout << res << '\n'; } }
Compilation message
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 6 ms | 376 KB | Output is correct |
2 | Correct | 5 ms | 376 KB | Output is correct |
3 | Correct | 6 ms | 376 KB | Output is correct |
4 | Correct | 5 ms | 376 KB | Output is correct |
5 | Correct | 5 ms | 376 KB | Output is correct |
6 | Correct | 5 ms | 376 KB | Output is correct |
7 | Correct | 6 ms | 376 KB | Output is correct |
8 | Correct | 5 ms | 504 KB | Output is correct |
9 | Correct | 5 ms | 376 KB | Output is correct |
10 | Correct | 5 ms | 376 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 6 ms | 376 KB | Output is correct |
2 | Correct | 5 ms | 376 KB | Output is correct |
3 | Correct | 6 ms | 376 KB | Output is correct |
4 | Correct | 5 ms | 376 KB | Output is correct |
5 | Correct | 5 ms | 376 KB | Output is correct |
6 | Correct | 5 ms | 376 KB | Output is correct |
7 | Correct | 6 ms | 376 KB | Output is correct |
8 | Correct | 5 ms | 504 KB | Output is correct |
9 | Correct | 5 ms | 376 KB | Output is correct |
10 | Correct | 5 ms | 376 KB | Output is correct |
11 | Correct | 287 ms | 4472 KB | Output is correct |
12 | Correct | 293 ms | 4088 KB | Output is correct |
13 | Correct | 307 ms | 3448 KB | Output is correct |
14 | Correct | 356 ms | 3576 KB | Output is correct |
15 | Correct | 300 ms | 4344 KB | Output is correct |
16 | Correct | 323 ms | 3576 KB | Output is correct |
17 | Correct | 315 ms | 3576 KB | Output is correct |
18 | Correct | 278 ms | 5368 KB | Output is correct |
19 | Correct | 293 ms | 2424 KB | Output is correct |
20 | Correct | 275 ms | 4088 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 6 ms | 376 KB | Output is correct |
2 | Correct | 5 ms | 376 KB | Output is correct |
3 | Correct | 6 ms | 376 KB | Output is correct |
4 | Correct | 5 ms | 376 KB | Output is correct |
5 | Correct | 5 ms | 376 KB | Output is correct |
6 | Correct | 5 ms | 376 KB | Output is correct |
7 | Correct | 6 ms | 376 KB | Output is correct |
8 | Correct | 5 ms | 504 KB | Output is correct |
9 | Correct | 5 ms | 376 KB | Output is correct |
10 | Correct | 5 ms | 376 KB | Output is correct |
11 | Correct | 287 ms | 4472 KB | Output is correct |
12 | Correct | 293 ms | 4088 KB | Output is correct |
13 | Correct | 307 ms | 3448 KB | Output is correct |
14 | Correct | 356 ms | 3576 KB | Output is correct |
15 | Correct | 300 ms | 4344 KB | Output is correct |
16 | Correct | 323 ms | 3576 KB | Output is correct |
17 | Correct | 315 ms | 3576 KB | Output is correct |
18 | Correct | 278 ms | 5368 KB | Output is correct |
19 | Correct | 293 ms | 2424 KB | Output is correct |
20 | Correct | 275 ms | 4088 KB | Output is correct |
21 | Correct | 302 ms | 4472 KB | Output is correct |
22 | Correct | 336 ms | 4728 KB | Output is correct |
23 | Correct | 359 ms | 3680 KB | Output is correct |
24 | Correct | 408 ms | 3564 KB | Output is correct |
25 | Correct | 333 ms | 5624 KB | Output is correct |
26 | Correct | 384 ms | 4088 KB | Output is correct |
27 | Correct | 378 ms | 4064 KB | Output is correct |
28 | Correct | 305 ms | 6520 KB | Output is correct |
29 | Correct | 316 ms | 2552 KB | Output is correct |
30 | Correct | 311 ms | 4728 KB | Output is correct |
31 | Correct | 357 ms | 4600 KB | Output is correct |
32 | Correct | 410 ms | 4600 KB | Output is correct |
33 | Correct | 313 ms | 3448 KB | Output is correct |
34 | Correct | 390 ms | 3576 KB | Output is correct |
35 | Correct | 384 ms | 3960 KB | Output is correct |
36 | Correct | 281 ms | 2500 KB | Output is correct |
37 | Correct | 328 ms | 4728 KB | Output is correct |
38 | Correct | 325 ms | 2424 KB | Output is correct |
39 | Correct | 340 ms | 3832 KB | Output is correct |
40 | Correct | 404 ms | 3576 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 6 ms | 376 KB | Output is correct |
2 | Correct | 5 ms | 376 KB | Output is correct |
3 | Correct | 6 ms | 376 KB | Output is correct |
4 | Correct | 5 ms | 376 KB | Output is correct |
5 | Correct | 5 ms | 376 KB | Output is correct |
6 | Correct | 5 ms | 376 KB | Output is correct |
7 | Correct | 6 ms | 376 KB | Output is correct |
8 | Correct | 5 ms | 504 KB | Output is correct |
9 | Correct | 5 ms | 376 KB | Output is correct |
10 | Correct | 5 ms | 376 KB | Output is correct |
11 | Correct | 74 ms | 14104 KB | Output is correct |
12 | Correct | 74 ms | 14104 KB | Output is correct |
13 | Correct | 84 ms | 13992 KB | Output is correct |
14 | Correct | 118 ms | 14104 KB | Output is correct |
15 | Correct | 77 ms | 14104 KB | Output is correct |
16 | Correct | 124 ms | 13976 KB | Output is correct |
17 | Correct | 105 ms | 13976 KB | Output is correct |
18 | Correct | 66 ms | 14232 KB | Output is correct |
19 | Correct | 75 ms | 13856 KB | Output is correct |
20 | Correct | 69 ms | 14104 KB | Output is correct |
21 | Correct | 93 ms | 14104 KB | Output is correct |
22 | Correct | 88 ms | 13980 KB | Output is correct |
23 | Correct | 69 ms | 13976 KB | Output is correct |
24 | Correct | 120 ms | 13976 KB | Output is correct |
25 | Correct | 109 ms | 14064 KB | Output is correct |
26 | Correct | 64 ms | 13848 KB | Output is correct |
27 | Correct | 67 ms | 14104 KB | Output is correct |
28 | Correct | 67 ms | 13976 KB | Output is correct |
29 | Correct | 90 ms | 14024 KB | Output is correct |
30 | Correct | 78 ms | 13980 KB | Output is correct |
31 | Correct | 66 ms | 13952 KB | Output is correct |
32 | Correct | 144 ms | 13976 KB | Output is correct |
33 | Correct | 104 ms | 13980 KB | Output is correct |
34 | Correct | 56 ms | 13844 KB | Output is correct |
35 | Correct | 99 ms | 13972 KB | Output is correct |
36 | Correct | 99 ms | 13976 KB | Output is correct |
37 | Correct | 97 ms | 14100 KB | Output is correct |
38 | Correct | 95 ms | 13976 KB | Output is correct |
39 | Correct | 94 ms | 14060 KB | Output is correct |
40 | Correct | 96 ms | 13976 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 6 ms | 376 KB | Output is correct |
2 | Correct | 5 ms | 376 KB | Output is correct |
3 | Correct | 6 ms | 376 KB | Output is correct |
4 | Correct | 5 ms | 376 KB | Output is correct |
5 | Correct | 5 ms | 376 KB | Output is correct |
6 | Correct | 5 ms | 376 KB | Output is correct |
7 | Correct | 6 ms | 376 KB | Output is correct |
8 | Correct | 5 ms | 504 KB | Output is correct |
9 | Correct | 5 ms | 376 KB | Output is correct |
10 | Correct | 5 ms | 376 KB | Output is correct |
11 | Correct | 287 ms | 4472 KB | Output is correct |
12 | Correct | 293 ms | 4088 KB | Output is correct |
13 | Correct | 307 ms | 3448 KB | Output is correct |
14 | Correct | 356 ms | 3576 KB | Output is correct |
15 | Correct | 300 ms | 4344 KB | Output is correct |
16 | Correct | 323 ms | 3576 KB | Output is correct |
17 | Correct | 315 ms | 3576 KB | Output is correct |
18 | Correct | 278 ms | 5368 KB | Output is correct |
19 | Correct | 293 ms | 2424 KB | Output is correct |
20 | Correct | 275 ms | 4088 KB | Output is correct |
21 | Correct | 302 ms | 4472 KB | Output is correct |
22 | Correct | 336 ms | 4728 KB | Output is correct |
23 | Correct | 359 ms | 3680 KB | Output is correct |
24 | Correct | 408 ms | 3564 KB | Output is correct |
25 | Correct | 333 ms | 5624 KB | Output is correct |
26 | Correct | 384 ms | 4088 KB | Output is correct |
27 | Correct | 378 ms | 4064 KB | Output is correct |
28 | Correct | 305 ms | 6520 KB | Output is correct |
29 | Correct | 316 ms | 2552 KB | Output is correct |
30 | Correct | 311 ms | 4728 KB | Output is correct |
31 | Correct | 357 ms | 4600 KB | Output is correct |
32 | Correct | 410 ms | 4600 KB | Output is correct |
33 | Correct | 313 ms | 3448 KB | Output is correct |
34 | Correct | 390 ms | 3576 KB | Output is correct |
35 | Correct | 384 ms | 3960 KB | Output is correct |
36 | Correct | 281 ms | 2500 KB | Output is correct |
37 | Correct | 328 ms | 4728 KB | Output is correct |
38 | Correct | 325 ms | 2424 KB | Output is correct |
39 | Correct | 340 ms | 3832 KB | Output is correct |
40 | Correct | 404 ms | 3576 KB | Output is correct |
41 | Correct | 74 ms | 14104 KB | Output is correct |
42 | Correct | 74 ms | 14104 KB | Output is correct |
43 | Correct | 84 ms | 13992 KB | Output is correct |
44 | Correct | 118 ms | 14104 KB | Output is correct |
45 | Correct | 77 ms | 14104 KB | Output is correct |
46 | Correct | 124 ms | 13976 KB | Output is correct |
47 | Correct | 105 ms | 13976 KB | Output is correct |
48 | Correct | 66 ms | 14232 KB | Output is correct |
49 | Correct | 75 ms | 13856 KB | Output is correct |
50 | Correct | 69 ms | 14104 KB | Output is correct |
51 | Correct | 93 ms | 14104 KB | Output is correct |
52 | Correct | 88 ms | 13980 KB | Output is correct |
53 | Correct | 69 ms | 13976 KB | Output is correct |
54 | Correct | 120 ms | 13976 KB | Output is correct |
55 | Correct | 109 ms | 14064 KB | Output is correct |
56 | Correct | 64 ms | 13848 KB | Output is correct |
57 | Correct | 67 ms | 14104 KB | Output is correct |
58 | Correct | 67 ms | 13976 KB | Output is correct |
59 | Correct | 90 ms | 14024 KB | Output is correct |
60 | Correct | 78 ms | 13980 KB | Output is correct |
61 | Correct | 66 ms | 13952 KB | Output is correct |
62 | Correct | 144 ms | 13976 KB | Output is correct |
63 | Correct | 104 ms | 13980 KB | Output is correct |
64 | Correct | 56 ms | 13844 KB | Output is correct |
65 | Correct | 99 ms | 13972 KB | Output is correct |
66 | Correct | 99 ms | 13976 KB | Output is correct |
67 | Correct | 97 ms | 14100 KB | Output is correct |
68 | Correct | 95 ms | 13976 KB | Output is correct |
69 | Correct | 94 ms | 14060 KB | Output is correct |
70 | Correct | 96 ms | 13976 KB | Output is correct |
71 | Correct | 493 ms | 18968 KB | Output is correct |
72 | Correct | 536 ms | 18968 KB | Output is correct |
73 | Correct | 770 ms | 17560 KB | Output is correct |
74 | Correct | 1106 ms | 18072 KB | Output is correct |
75 | Correct | 616 ms | 20140 KB | Output is correct |
76 | Correct | 1388 ms | 18304 KB | Output is correct |
77 | Correct | 1263 ms | 21144 KB | Output is correct |
78 | Correct | 434 ms | 43416 KB | Output is correct |
79 | Correct | 543 ms | 37528 KB | Output is correct |
80 | Correct | 560 ms | 40732 KB | Output is correct |
81 | Correct | 863 ms | 40728 KB | Output is correct |
82 | Correct | 1095 ms | 39576 KB | Output is correct |
83 | Correct | 775 ms | 38560 KB | Output is correct |
84 | Correct | 1455 ms | 39448 KB | Output is correct |
85 | Correct | 1117 ms | 39704 KB | Output is correct |
86 | Correct | 859 ms | 37400 KB | Output is correct |
87 | Correct | 1924 ms | 40472 KB | Output is correct |
88 | Correct | 1140 ms | 37400 KB | Output is correct |
89 | Correct | 1217 ms | 39220 KB | Output is correct |
90 | Correct | 1426 ms | 39436 KB | Output is correct |
91 | Correct | 1075 ms | 38680 KB | Output is correct |
92 | Correct | 1742 ms | 39704 KB | Output is correct |
93 | Correct | 1226 ms | 39540 KB | Output is correct |
94 | Correct | 360 ms | 37528 KB | Output is correct |
95 | Correct | 1100 ms | 39452 KB | Output is correct |
96 | Correct | 1008 ms | 39468 KB | Output is correct |
97 | Correct | 1018 ms | 39576 KB | Output is correct |
98 | Correct | 1029 ms | 39648 KB | Output is correct |
99 | Correct | 1109 ms | 39776 KB | Output is correct |
100 | Correct | 1072 ms | 39576 KB | Output is correct |