# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
199752 | 2020-02-03T07:14:36 Z | Mercenary | Snake Escaping (JOI18_snake_escaping) | C++14 | 2000 ms | 19028 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)-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
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 5 ms | 376 KB | Output is correct |
2 | Correct | 6 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 | 8 ms | 376 KB | Output is correct |
8 | Correct | 6 ms | 376 KB | Output is correct |
9 | Correct | 5 ms | 376 KB | Output is correct |
10 | Correct | 5 ms | 376 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 5 ms | 376 KB | Output is correct |
2 | Correct | 6 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 | 8 ms | 376 KB | Output is correct |
8 | Correct | 6 ms | 376 KB | Output is correct |
9 | Correct | 5 ms | 376 KB | Output is correct |
10 | Correct | 5 ms | 376 KB | Output is correct |
11 | Correct | 263 ms | 4600 KB | Output is correct |
12 | Correct | 287 ms | 4344 KB | Output is correct |
13 | Correct | 327 ms | 3576 KB | Output is correct |
14 | Correct | 321 ms | 3576 KB | Output is correct |
15 | Correct | 296 ms | 4728 KB | Output is correct |
16 | Correct | 316 ms | 3704 KB | Output is correct |
17 | Correct | 336 ms | 3704 KB | Output is correct |
18 | Correct | 257 ms | 5624 KB | Output is correct |
19 | Correct | 275 ms | 2680 KB | Output is correct |
20 | Correct | 265 ms | 4216 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 5 ms | 376 KB | Output is correct |
2 | Correct | 6 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 | 8 ms | 376 KB | Output is correct |
8 | Correct | 6 ms | 376 KB | Output is correct |
9 | Correct | 5 ms | 376 KB | Output is correct |
10 | Correct | 5 ms | 376 KB | Output is correct |
11 | Correct | 263 ms | 4600 KB | Output is correct |
12 | Correct | 287 ms | 4344 KB | Output is correct |
13 | Correct | 327 ms | 3576 KB | Output is correct |
14 | Correct | 321 ms | 3576 KB | Output is correct |
15 | Correct | 296 ms | 4728 KB | Output is correct |
16 | Correct | 316 ms | 3704 KB | Output is correct |
17 | Correct | 336 ms | 3704 KB | Output is correct |
18 | Correct | 257 ms | 5624 KB | Output is correct |
19 | Correct | 275 ms | 2680 KB | Output is correct |
20 | Correct | 265 ms | 4216 KB | Output is correct |
21 | Correct | 292 ms | 4740 KB | Output is correct |
22 | Correct | 320 ms | 4984 KB | Output is correct |
23 | Correct | 407 ms | 3836 KB | Output is correct |
24 | Correct | 403 ms | 3704 KB | Output is correct |
25 | Correct | 381 ms | 5752 KB | Output is correct |
26 | Correct | 405 ms | 4372 KB | Output is correct |
27 | Correct | 405 ms | 4216 KB | Output is correct |
28 | Correct | 293 ms | 6648 KB | Output is correct |
29 | Correct | 305 ms | 2808 KB | Output is correct |
30 | Correct | 290 ms | 4984 KB | Output is correct |
31 | Correct | 380 ms | 4856 KB | Output is correct |
32 | Correct | 380 ms | 4728 KB | Output is correct |
33 | Correct | 428 ms | 3832 KB | Output is correct |
34 | Correct | 405 ms | 3836 KB | Output is correct |
35 | Correct | 410 ms | 4252 KB | Output is correct |
36 | Correct | 276 ms | 2680 KB | Output is correct |
37 | Correct | 309 ms | 4856 KB | Output is correct |
38 | Correct | 317 ms | 2680 KB | Output is correct |
39 | Correct | 404 ms | 3960 KB | Output is correct |
40 | Correct | 391 ms | 3704 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 5 ms | 376 KB | Output is correct |
2 | Correct | 6 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 | 8 ms | 376 KB | Output is correct |
8 | Correct | 6 ms | 376 KB | Output is correct |
9 | Correct | 5 ms | 376 KB | Output is correct |
10 | Correct | 5 ms | 376 KB | Output is correct |
11 | Correct | 68 ms | 14232 KB | Output is correct |
12 | Correct | 84 ms | 14240 KB | Output is correct |
13 | Correct | 168 ms | 14300 KB | Output is correct |
14 | Correct | 156 ms | 14232 KB | Output is correct |
15 | Correct | 131 ms | 14360 KB | Output is correct |
16 | Correct | 167 ms | 14232 KB | Output is correct |
17 | Correct | 173 ms | 14232 KB | Output is correct |
18 | Correct | 66 ms | 14612 KB | Output is correct |
19 | Correct | 74 ms | 14104 KB | Output is correct |
20 | Correct | 70 ms | 14232 KB | Output is correct |
21 | Correct | 145 ms | 14232 KB | Output is correct |
22 | Correct | 147 ms | 14232 KB | Output is correct |
23 | Correct | 214 ms | 14104 KB | Output is correct |
24 | Correct | 164 ms | 14236 KB | Output is correct |
25 | Correct | 177 ms | 14256 KB | Output is correct |
26 | Correct | 62 ms | 14104 KB | Output is correct |
27 | Correct | 70 ms | 14232 KB | Output is correct |
28 | Correct | 70 ms | 14108 KB | Output is correct |
29 | Correct | 152 ms | 14232 KB | Output is correct |
30 | Correct | 162 ms | 14232 KB | Output is correct |
31 | Correct | 216 ms | 14208 KB | Output is correct |
32 | Correct | 164 ms | 14232 KB | Output is correct |
33 | Correct | 177 ms | 14232 KB | Output is correct |
34 | Correct | 66 ms | 14104 KB | Output is correct |
35 | Correct | 144 ms | 14232 KB | Output is correct |
36 | Correct | 137 ms | 14232 KB | Output is correct |
37 | Correct | 139 ms | 14232 KB | Output is correct |
38 | Correct | 142 ms | 14216 KB | Output is correct |
39 | Correct | 152 ms | 14340 KB | Output is correct |
40 | Correct | 145 ms | 14360 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 5 ms | 376 KB | Output is correct |
2 | Correct | 6 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 | 8 ms | 376 KB | Output is correct |
8 | Correct | 6 ms | 376 KB | Output is correct |
9 | Correct | 5 ms | 376 KB | Output is correct |
10 | Correct | 5 ms | 376 KB | Output is correct |
11 | Correct | 263 ms | 4600 KB | Output is correct |
12 | Correct | 287 ms | 4344 KB | Output is correct |
13 | Correct | 327 ms | 3576 KB | Output is correct |
14 | Correct | 321 ms | 3576 KB | Output is correct |
15 | Correct | 296 ms | 4728 KB | Output is correct |
16 | Correct | 316 ms | 3704 KB | Output is correct |
17 | Correct | 336 ms | 3704 KB | Output is correct |
18 | Correct | 257 ms | 5624 KB | Output is correct |
19 | Correct | 275 ms | 2680 KB | Output is correct |
20 | Correct | 265 ms | 4216 KB | Output is correct |
21 | Correct | 292 ms | 4740 KB | Output is correct |
22 | Correct | 320 ms | 4984 KB | Output is correct |
23 | Correct | 407 ms | 3836 KB | Output is correct |
24 | Correct | 403 ms | 3704 KB | Output is correct |
25 | Correct | 381 ms | 5752 KB | Output is correct |
26 | Correct | 405 ms | 4372 KB | Output is correct |
27 | Correct | 405 ms | 4216 KB | Output is correct |
28 | Correct | 293 ms | 6648 KB | Output is correct |
29 | Correct | 305 ms | 2808 KB | Output is correct |
30 | Correct | 290 ms | 4984 KB | Output is correct |
31 | Correct | 380 ms | 4856 KB | Output is correct |
32 | Correct | 380 ms | 4728 KB | Output is correct |
33 | Correct | 428 ms | 3832 KB | Output is correct |
34 | Correct | 405 ms | 3836 KB | Output is correct |
35 | Correct | 410 ms | 4252 KB | Output is correct |
36 | Correct | 276 ms | 2680 KB | Output is correct |
37 | Correct | 309 ms | 4856 KB | Output is correct |
38 | Correct | 317 ms | 2680 KB | Output is correct |
39 | Correct | 404 ms | 3960 KB | Output is correct |
40 | Correct | 391 ms | 3704 KB | Output is correct |
41 | Correct | 68 ms | 14232 KB | Output is correct |
42 | Correct | 84 ms | 14240 KB | Output is correct |
43 | Correct | 168 ms | 14300 KB | Output is correct |
44 | Correct | 156 ms | 14232 KB | Output is correct |
45 | Correct | 131 ms | 14360 KB | Output is correct |
46 | Correct | 167 ms | 14232 KB | Output is correct |
47 | Correct | 173 ms | 14232 KB | Output is correct |
48 | Correct | 66 ms | 14612 KB | Output is correct |
49 | Correct | 74 ms | 14104 KB | Output is correct |
50 | Correct | 70 ms | 14232 KB | Output is correct |
51 | Correct | 145 ms | 14232 KB | Output is correct |
52 | Correct | 147 ms | 14232 KB | Output is correct |
53 | Correct | 214 ms | 14104 KB | Output is correct |
54 | Correct | 164 ms | 14236 KB | Output is correct |
55 | Correct | 177 ms | 14256 KB | Output is correct |
56 | Correct | 62 ms | 14104 KB | Output is correct |
57 | Correct | 70 ms | 14232 KB | Output is correct |
58 | Correct | 70 ms | 14108 KB | Output is correct |
59 | Correct | 152 ms | 14232 KB | Output is correct |
60 | Correct | 162 ms | 14232 KB | Output is correct |
61 | Correct | 216 ms | 14208 KB | Output is correct |
62 | Correct | 164 ms | 14232 KB | Output is correct |
63 | Correct | 177 ms | 14232 KB | Output is correct |
64 | Correct | 66 ms | 14104 KB | Output is correct |
65 | Correct | 144 ms | 14232 KB | Output is correct |
66 | Correct | 137 ms | 14232 KB | Output is correct |
67 | Correct | 139 ms | 14232 KB | Output is correct |
68 | Correct | 142 ms | 14216 KB | Output is correct |
69 | Correct | 152 ms | 14340 KB | Output is correct |
70 | Correct | 145 ms | 14360 KB | Output is correct |
71 | Correct | 501 ms | 18840 KB | Output is correct |
72 | Correct | 571 ms | 19028 KB | Output is correct |
73 | Execution timed out | 2081 ms | 17560 KB | Time limit exceeded |
74 | Halted | 0 ms | 0 KB | - |