답안 #535429

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
535429 2022-03-10T09:19:52 Z getac Snake Escaping (JOI18_snake_escaping) C++14
100 / 100
1316 ms 24716 KB
//InTheNameOfGOD 
//PRS;) 
#include<iostream> 
#define Fast ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0); 
using namespace std; 
typedef int ll; 
const ll xn = (1 << 20) + 5; 
ll dp[xn][2], a[xn], cnt[xn]; 
int main() 
{ 
    Fast 
    ll n, q; 
    cin >> n >> q; 
    for(ll i = 1; i < (1 << n); i++) cnt[i] = cnt[i - (i & -i)] + 1; 
    for(ll i = 0; i < (1 << n); i++) 
    { 
        char c; 
        cin >> c; 
        dp[i][0] = dp[i][1] = a[i] = c - '0'; 
    } 
    for(ll j = 0; j < n; j++) for(ll i = 0; i < (1 << n); i++) 
        if((i >> j) & 1) dp[i][0] += dp[i ^ (1 << j)][0], dp[i ^ (1 << j)][1] += dp[i][1]; 
    while(q--) 
    { 
        ll t0 = 0, t1 = 0, t2 = 0, ans = 0; 
        for(ll i = 0, j = n - 1; i < n; i++, j--) 
        { 
            char c; 
            cin >> c; 
            if(c == '0') t0 |= (1 << j); 
            if(c == '1') t1 |= (1 << j); 
            if(c == '?') t2 |= (1 << j); 
        } 
        if(cnt[t0] <= n / 3) 
        { 
            for(ll prs = t0; ;prs = t0 & (prs - 1)) 
            { 
                (cnt[prs] & 1) ? ans -= dp[t1 | prs][1] : ans += dp[t1 | prs][1]; 
                if(!prs) break; 
            } 
        } 
        else if(cnt[t1] <= n / 3) 
        { 
            for(ll prs = t1; ;prs = t1 & (prs - 1)) 
            { 
                (cnt[prs ^ t1] & 1) ? ans -= dp[t2 | prs][0] : ans += dp[t2 | prs][0]; 
                if(!prs) break; 
            } 
        } 
        else
        { 
            for(ll prs = t2; ;prs= t2 & (prs - 1)) 
            { 
                ans += a[t1 | prs]; 
                if(!prs) break; 
            } 
        } 
        cout << ans << '\n'; 
    } 
    return 0; 
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 368 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 368 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 325 ms 4428 KB Output is correct
12 Correct 363 ms 4016 KB Output is correct
13 Correct 394 ms 3224 KB Output is correct
14 Correct 425 ms 3360 KB Output is correct
15 Correct 334 ms 4336 KB Output is correct
16 Correct 406 ms 3500 KB Output is correct
17 Correct 410 ms 3392 KB Output is correct
18 Correct 250 ms 5304 KB Output is correct
19 Correct 321 ms 2236 KB Output is correct
20 Correct 351 ms 3920 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 368 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 325 ms 4428 KB Output is correct
12 Correct 363 ms 4016 KB Output is correct
13 Correct 394 ms 3224 KB Output is correct
14 Correct 425 ms 3360 KB Output is correct
15 Correct 334 ms 4336 KB Output is correct
16 Correct 406 ms 3500 KB Output is correct
17 Correct 410 ms 3392 KB Output is correct
18 Correct 250 ms 5304 KB Output is correct
19 Correct 321 ms 2236 KB Output is correct
20 Correct 351 ms 3920 KB Output is correct
21 Correct 406 ms 4432 KB Output is correct
22 Correct 431 ms 4524 KB Output is correct
23 Correct 499 ms 3564 KB Output is correct
24 Correct 510 ms 3460 KB Output is correct
25 Correct 416 ms 5408 KB Output is correct
26 Correct 479 ms 3900 KB Output is correct
27 Correct 482 ms 3820 KB Output is correct
28 Correct 326 ms 6364 KB Output is correct
29 Correct 399 ms 2412 KB Output is correct
30 Correct 366 ms 4556 KB Output is correct
31 Correct 417 ms 4476 KB Output is correct
32 Correct 451 ms 4424 KB Output is correct
33 Correct 359 ms 3364 KB Output is correct
34 Correct 447 ms 3404 KB Output is correct
35 Correct 474 ms 3912 KB Output is correct
36 Correct 255 ms 2376 KB Output is correct
37 Correct 405 ms 4404 KB Output is correct
38 Correct 378 ms 2512 KB Output is correct
39 Correct 426 ms 3564 KB Output is correct
40 Correct 478 ms 3468 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 368 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 79 ms 18556 KB Output is correct
12 Correct 82 ms 18552 KB Output is correct
13 Correct 98 ms 18492 KB Output is correct
14 Correct 124 ms 18524 KB Output is correct
15 Correct 83 ms 18624 KB Output is correct
16 Correct 110 ms 18504 KB Output is correct
17 Correct 124 ms 18508 KB Output is correct
18 Correct 66 ms 18748 KB Output is correct
19 Correct 83 ms 18436 KB Output is correct
20 Correct 92 ms 18588 KB Output is correct
21 Correct 94 ms 18616 KB Output is correct
22 Correct 116 ms 18488 KB Output is correct
23 Correct 77 ms 18380 KB Output is correct
24 Correct 134 ms 18484 KB Output is correct
25 Correct 106 ms 18500 KB Output is correct
26 Correct 64 ms 18380 KB Output is correct
27 Correct 79 ms 18552 KB Output is correct
28 Correct 95 ms 18332 KB Output is correct
29 Correct 87 ms 18508 KB Output is correct
30 Correct 118 ms 18548 KB Output is correct
31 Correct 83 ms 18444 KB Output is correct
32 Correct 109 ms 18508 KB Output is correct
33 Correct 111 ms 18488 KB Output is correct
34 Correct 78 ms 18360 KB Output is correct
35 Correct 101 ms 18480 KB Output is correct
36 Correct 92 ms 18536 KB Output is correct
37 Correct 97 ms 18520 KB Output is correct
38 Correct 123 ms 18508 KB Output is correct
39 Correct 90 ms 18504 KB Output is correct
40 Correct 101 ms 18476 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 368 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 325 ms 4428 KB Output is correct
12 Correct 363 ms 4016 KB Output is correct
13 Correct 394 ms 3224 KB Output is correct
14 Correct 425 ms 3360 KB Output is correct
15 Correct 334 ms 4336 KB Output is correct
16 Correct 406 ms 3500 KB Output is correct
17 Correct 410 ms 3392 KB Output is correct
18 Correct 250 ms 5304 KB Output is correct
19 Correct 321 ms 2236 KB Output is correct
20 Correct 351 ms 3920 KB Output is correct
21 Correct 406 ms 4432 KB Output is correct
22 Correct 431 ms 4524 KB Output is correct
23 Correct 499 ms 3564 KB Output is correct
24 Correct 510 ms 3460 KB Output is correct
25 Correct 416 ms 5408 KB Output is correct
26 Correct 479 ms 3900 KB Output is correct
27 Correct 482 ms 3820 KB Output is correct
28 Correct 326 ms 6364 KB Output is correct
29 Correct 399 ms 2412 KB Output is correct
30 Correct 366 ms 4556 KB Output is correct
31 Correct 417 ms 4476 KB Output is correct
32 Correct 451 ms 4424 KB Output is correct
33 Correct 359 ms 3364 KB Output is correct
34 Correct 447 ms 3404 KB Output is correct
35 Correct 474 ms 3912 KB Output is correct
36 Correct 255 ms 2376 KB Output is correct
37 Correct 405 ms 4404 KB Output is correct
38 Correct 378 ms 2512 KB Output is correct
39 Correct 426 ms 3564 KB Output is correct
40 Correct 478 ms 3468 KB Output is correct
41 Correct 79 ms 18556 KB Output is correct
42 Correct 82 ms 18552 KB Output is correct
43 Correct 98 ms 18492 KB Output is correct
44 Correct 124 ms 18524 KB Output is correct
45 Correct 83 ms 18624 KB Output is correct
46 Correct 110 ms 18504 KB Output is correct
47 Correct 124 ms 18508 KB Output is correct
48 Correct 66 ms 18748 KB Output is correct
49 Correct 83 ms 18436 KB Output is correct
50 Correct 92 ms 18588 KB Output is correct
51 Correct 94 ms 18616 KB Output is correct
52 Correct 116 ms 18488 KB Output is correct
53 Correct 77 ms 18380 KB Output is correct
54 Correct 134 ms 18484 KB Output is correct
55 Correct 106 ms 18500 KB Output is correct
56 Correct 64 ms 18380 KB Output is correct
57 Correct 79 ms 18552 KB Output is correct
58 Correct 95 ms 18332 KB Output is correct
59 Correct 87 ms 18508 KB Output is correct
60 Correct 118 ms 18548 KB Output is correct
61 Correct 83 ms 18444 KB Output is correct
62 Correct 109 ms 18508 KB Output is correct
63 Correct 111 ms 18488 KB Output is correct
64 Correct 78 ms 18360 KB Output is correct
65 Correct 101 ms 18480 KB Output is correct
66 Correct 92 ms 18536 KB Output is correct
67 Correct 97 ms 18520 KB Output is correct
68 Correct 123 ms 18508 KB Output is correct
69 Correct 90 ms 18504 KB Output is correct
70 Correct 101 ms 18476 KB Output is correct
71 Correct 647 ms 21740 KB Output is correct
72 Correct 708 ms 21920 KB Output is correct
73 Correct 1038 ms 20348 KB Output is correct
74 Correct 1312 ms 20752 KB Output is correct
75 Correct 659 ms 22756 KB Output is correct
76 Correct 1316 ms 21100 KB Output is correct
77 Correct 1100 ms 20952 KB Output is correct
78 Correct 385 ms 24716 KB Output is correct
79 Correct 557 ms 18704 KB Output is correct
80 Correct 558 ms 21960 KB Output is correct
81 Correct 769 ms 21772 KB Output is correct
82 Correct 1054 ms 20756 KB Output is correct
83 Correct 539 ms 19872 KB Output is correct
84 Correct 1147 ms 20788 KB Output is correct
85 Correct 1079 ms 20964 KB Output is correct
86 Correct 385 ms 18728 KB Output is correct
87 Correct 706 ms 21836 KB Output is correct
88 Correct 617 ms 18816 KB Output is correct
89 Correct 782 ms 20544 KB Output is correct
90 Correct 892 ms 20692 KB Output is correct
91 Correct 732 ms 19952 KB Output is correct
92 Correct 1193 ms 21080 KB Output is correct
93 Correct 1040 ms 20924 KB Output is correct
94 Correct 359 ms 18684 KB Output is correct
95 Correct 855 ms 20880 KB Output is correct
96 Correct 843 ms 20940 KB Output is correct
97 Correct 843 ms 20832 KB Output is correct
98 Correct 875 ms 20896 KB Output is correct
99 Correct 870 ms 20776 KB Output is correct
100 Correct 827 ms 20888 KB Output is correct