답안 #476495

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
476495 2021-09-27T11:26:15 Z keta_tsimakuridze Snake Escaping (JOI18_snake_escaping) C++14
100 / 100
1186 ms 47436 KB
#include<bits/stdc++.h>
#define f first
#define s second
////#define int long long
#define pii pair<int,int>
using namespace std;
const int N = 1048576 + 5, mod = 1e9 + 7; // !
int t,dp1[2][N],dp2[2][N],L,q,cnt[N];
main(){
			ios_base::sync_with_stdio(false),cin.tie(0),cout.tie(0);
            cin >> L >> q;
            string s;
            cin >> s;
            for(int i = 0; i < (1 << L); i++) { 
                        dp1[0][i] = s[i] - '0';
                        dp2[0][i] = s[i] - '0';
            
			}
			for(int j = 0; j < L; j++) {
				for(int i = 0; i < (1 << L); i++) {
                        dp1[1][i] = dp1[0][i];
                        if((1 << j) & i) dp1[1][i] += dp1[1][i ^ (1 << j)];					
				}
				swap(dp1[0],dp1[1]);
			} 
			for(int j = 0; j < L; j++) {
				for(int i = (1 << L) - 1; i >= 0; i--) {
                        dp2[1][i] = dp2[0][i];
                        if(!((1 << j) & i)) dp2[1][i] += dp2[1][i ^ (1 << j)];					
				}
				swap(dp2[0],dp2[1]);
			}
            
            while(q--) {
                        string t;
                        cin >> t;
                        int x = 0;
                        reverse(t.begin(),t.end());
                        int c = 0, a = 0, b = 0;
                        for(int i = 0; i < 3; i++) cnt[i] = 0;
                        for(int i = 0; i < (int)t.size(); i++) {
                                    if(t[i] == '0') cnt[0]++, a += 1 << i;
                                    else if(t[i] == '1') cnt[1]++,b += 1 << i;
                                    else cnt[2]++,c += 1 << i;
                        }
                        long long ans = 0;
                        if(cnt[2] < 7) {
                        		
                                    for(int i = c;; i = (i - 1) & c) {
                                                ans += s[i | b] - '0';
                                                if(i == 0) break;
                                    }
                        }
                        else if(cnt[1] < 7) {	
                                    int p = __builtin_popcount(b) % 2;
                                    for(int i = b;; i = (i - 1) & b) {
                                            ans += (__builtin_popcount(i) % 2 == p ? 1 : -1)
                                                    * dp1[0][i | c];
                                            if(i == 0) break;
                                                    
                                    }
                        }
                        else {
                                    for(int i = a;; i = (i - 1) & a) {
                                            ans += (__builtin_popcount(i) % 2 == 0 ? 1 : -1)
                                                       * dp2[0][i | b];
                                            if(i == 0) break;    
                                    }
                        }
                        cout << ans << "\n";
            }
 }

Compilation message

snake_escaping.cpp:9:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
    9 | main(){
      | ^~~~
snake_escaping.cpp: In function 'int main()':
snake_escaping.cpp:37:29: warning: unused variable 'x' [-Wunused-variable]
   37 |                         int x = 0;
      |                             ^
# 결과 실행 시간 메모리 Grader output
1 Correct 31 ms 16708 KB Output is correct
2 Correct 32 ms 16604 KB Output is correct
3 Correct 33 ms 16716 KB Output is correct
4 Correct 29 ms 16712 KB Output is correct
5 Correct 35 ms 16736 KB Output is correct
6 Correct 35 ms 16676 KB Output is correct
7 Correct 29 ms 16708 KB Output is correct
8 Correct 34 ms 16636 KB Output is correct
9 Correct 27 ms 16732 KB Output is correct
10 Correct 27 ms 16736 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 31 ms 16708 KB Output is correct
2 Correct 32 ms 16604 KB Output is correct
3 Correct 33 ms 16716 KB Output is correct
4 Correct 29 ms 16712 KB Output is correct
5 Correct 35 ms 16736 KB Output is correct
6 Correct 35 ms 16676 KB Output is correct
7 Correct 29 ms 16708 KB Output is correct
8 Correct 34 ms 16636 KB Output is correct
9 Correct 27 ms 16732 KB Output is correct
10 Correct 27 ms 16736 KB Output is correct
11 Correct 302 ms 20740 KB Output is correct
12 Correct 297 ms 20340 KB Output is correct
13 Correct 290 ms 19648 KB Output is correct
14 Correct 277 ms 19824 KB Output is correct
15 Correct 361 ms 20708 KB Output is correct
16 Correct 318 ms 19972 KB Output is correct
17 Correct 328 ms 19844 KB Output is correct
18 Correct 222 ms 21700 KB Output is correct
19 Correct 255 ms 18628 KB Output is correct
20 Correct 312 ms 20420 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 31 ms 16708 KB Output is correct
2 Correct 32 ms 16604 KB Output is correct
3 Correct 33 ms 16716 KB Output is correct
4 Correct 29 ms 16712 KB Output is correct
5 Correct 35 ms 16736 KB Output is correct
6 Correct 35 ms 16676 KB Output is correct
7 Correct 29 ms 16708 KB Output is correct
8 Correct 34 ms 16636 KB Output is correct
9 Correct 27 ms 16732 KB Output is correct
10 Correct 27 ms 16736 KB Output is correct
11 Correct 302 ms 20740 KB Output is correct
12 Correct 297 ms 20340 KB Output is correct
13 Correct 290 ms 19648 KB Output is correct
14 Correct 277 ms 19824 KB Output is correct
15 Correct 361 ms 20708 KB Output is correct
16 Correct 318 ms 19972 KB Output is correct
17 Correct 328 ms 19844 KB Output is correct
18 Correct 222 ms 21700 KB Output is correct
19 Correct 255 ms 18628 KB Output is correct
20 Correct 312 ms 20420 KB Output is correct
21 Correct 594 ms 20704 KB Output is correct
22 Correct 327 ms 20848 KB Output is correct
23 Correct 365 ms 19844 KB Output is correct
24 Correct 349 ms 19716 KB Output is correct
25 Correct 330 ms 21704 KB Output is correct
26 Correct 389 ms 20180 KB Output is correct
27 Correct 372 ms 20164 KB Output is correct
28 Correct 228 ms 22748 KB Output is correct
29 Correct 300 ms 18836 KB Output is correct
30 Correct 457 ms 20804 KB Output is correct
31 Correct 396 ms 20676 KB Output is correct
32 Correct 359 ms 20760 KB Output is correct
33 Correct 300 ms 19592 KB Output is correct
34 Correct 340 ms 19652 KB Output is correct
35 Correct 371 ms 20292 KB Output is correct
36 Correct 236 ms 18628 KB Output is correct
37 Correct 376 ms 20704 KB Output is correct
38 Correct 283 ms 18728 KB Output is correct
39 Correct 341 ms 19880 KB Output is correct
40 Correct 339 ms 19652 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 31 ms 16708 KB Output is correct
2 Correct 32 ms 16604 KB Output is correct
3 Correct 33 ms 16716 KB Output is correct
4 Correct 29 ms 16712 KB Output is correct
5 Correct 35 ms 16736 KB Output is correct
6 Correct 35 ms 16676 KB Output is correct
7 Correct 29 ms 16708 KB Output is correct
8 Correct 34 ms 16636 KB Output is correct
9 Correct 27 ms 16732 KB Output is correct
10 Correct 27 ms 16736 KB Output is correct
11 Correct 121 ms 20172 KB Output is correct
12 Correct 121 ms 20172 KB Output is correct
13 Correct 124 ms 20044 KB Output is correct
14 Correct 138 ms 20060 KB Output is correct
15 Correct 126 ms 20172 KB Output is correct
16 Correct 159 ms 20068 KB Output is correct
17 Correct 147 ms 20176 KB Output is correct
18 Correct 117 ms 20300 KB Output is correct
19 Correct 120 ms 19940 KB Output is correct
20 Correct 122 ms 20176 KB Output is correct
21 Correct 121 ms 20184 KB Output is correct
22 Correct 147 ms 20064 KB Output is correct
23 Correct 130 ms 20052 KB Output is correct
24 Correct 117 ms 20060 KB Output is correct
25 Correct 151 ms 20064 KB Output is correct
26 Correct 123 ms 19916 KB Output is correct
27 Correct 119 ms 20196 KB Output is correct
28 Correct 110 ms 19928 KB Output is correct
29 Correct 126 ms 20052 KB Output is correct
30 Correct 144 ms 20068 KB Output is correct
31 Correct 126 ms 20052 KB Output is correct
32 Correct 140 ms 20056 KB Output is correct
33 Correct 130 ms 20052 KB Output is correct
34 Correct 107 ms 19940 KB Output is correct
35 Correct 136 ms 20060 KB Output is correct
36 Correct 137 ms 20056 KB Output is correct
37 Correct 121 ms 20172 KB Output is correct
38 Correct 127 ms 20056 KB Output is correct
39 Correct 140 ms 20040 KB Output is correct
40 Correct 148 ms 20068 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 31 ms 16708 KB Output is correct
2 Correct 32 ms 16604 KB Output is correct
3 Correct 33 ms 16716 KB Output is correct
4 Correct 29 ms 16712 KB Output is correct
5 Correct 35 ms 16736 KB Output is correct
6 Correct 35 ms 16676 KB Output is correct
7 Correct 29 ms 16708 KB Output is correct
8 Correct 34 ms 16636 KB Output is correct
9 Correct 27 ms 16732 KB Output is correct
10 Correct 27 ms 16736 KB Output is correct
11 Correct 302 ms 20740 KB Output is correct
12 Correct 297 ms 20340 KB Output is correct
13 Correct 290 ms 19648 KB Output is correct
14 Correct 277 ms 19824 KB Output is correct
15 Correct 361 ms 20708 KB Output is correct
16 Correct 318 ms 19972 KB Output is correct
17 Correct 328 ms 19844 KB Output is correct
18 Correct 222 ms 21700 KB Output is correct
19 Correct 255 ms 18628 KB Output is correct
20 Correct 312 ms 20420 KB Output is correct
21 Correct 594 ms 20704 KB Output is correct
22 Correct 327 ms 20848 KB Output is correct
23 Correct 365 ms 19844 KB Output is correct
24 Correct 349 ms 19716 KB Output is correct
25 Correct 330 ms 21704 KB Output is correct
26 Correct 389 ms 20180 KB Output is correct
27 Correct 372 ms 20164 KB Output is correct
28 Correct 228 ms 22748 KB Output is correct
29 Correct 300 ms 18836 KB Output is correct
30 Correct 457 ms 20804 KB Output is correct
31 Correct 396 ms 20676 KB Output is correct
32 Correct 359 ms 20760 KB Output is correct
33 Correct 300 ms 19592 KB Output is correct
34 Correct 340 ms 19652 KB Output is correct
35 Correct 371 ms 20292 KB Output is correct
36 Correct 236 ms 18628 KB Output is correct
37 Correct 376 ms 20704 KB Output is correct
38 Correct 283 ms 18728 KB Output is correct
39 Correct 341 ms 19880 KB Output is correct
40 Correct 339 ms 19652 KB Output is correct
41 Correct 121 ms 20172 KB Output is correct
42 Correct 121 ms 20172 KB Output is correct
43 Correct 124 ms 20044 KB Output is correct
44 Correct 138 ms 20060 KB Output is correct
45 Correct 126 ms 20172 KB Output is correct
46 Correct 159 ms 20068 KB Output is correct
47 Correct 147 ms 20176 KB Output is correct
48 Correct 117 ms 20300 KB Output is correct
49 Correct 120 ms 19940 KB Output is correct
50 Correct 122 ms 20176 KB Output is correct
51 Correct 121 ms 20184 KB Output is correct
52 Correct 147 ms 20064 KB Output is correct
53 Correct 130 ms 20052 KB Output is correct
54 Correct 117 ms 20060 KB Output is correct
55 Correct 151 ms 20064 KB Output is correct
56 Correct 123 ms 19916 KB Output is correct
57 Correct 119 ms 20196 KB Output is correct
58 Correct 110 ms 19928 KB Output is correct
59 Correct 126 ms 20052 KB Output is correct
60 Correct 144 ms 20068 KB Output is correct
61 Correct 126 ms 20052 KB Output is correct
62 Correct 140 ms 20056 KB Output is correct
63 Correct 130 ms 20052 KB Output is correct
64 Correct 107 ms 19940 KB Output is correct
65 Correct 136 ms 20060 KB Output is correct
66 Correct 137 ms 20056 KB Output is correct
67 Correct 121 ms 20172 KB Output is correct
68 Correct 127 ms 20056 KB Output is correct
69 Correct 140 ms 20040 KB Output is correct
70 Correct 148 ms 20068 KB Output is correct
71 Correct 494 ms 44496 KB Output is correct
72 Correct 513 ms 44576 KB Output is correct
73 Correct 589 ms 43128 KB Output is correct
74 Correct 1090 ms 43608 KB Output is correct
75 Correct 592 ms 45404 KB Output is correct
76 Correct 1186 ms 43824 KB Output is correct
77 Correct 979 ms 43788 KB Output is correct
78 Correct 377 ms 47436 KB Output is correct
79 Correct 455 ms 41440 KB Output is correct
80 Correct 550 ms 44564 KB Output is correct
81 Correct 691 ms 44600 KB Output is correct
82 Correct 1135 ms 43568 KB Output is correct
83 Correct 514 ms 42672 KB Output is correct
84 Correct 606 ms 43364 KB Output is correct
85 Correct 879 ms 43580 KB Output is correct
86 Correct 381 ms 41472 KB Output is correct
87 Correct 496 ms 44504 KB Output is correct
88 Correct 447 ms 41416 KB Output is correct
89 Correct 560 ms 43136 KB Output is correct
90 Correct 615 ms 43480 KB Output is correct
91 Correct 484 ms 42596 KB Output is correct
92 Correct 992 ms 43748 KB Output is correct
93 Correct 948 ms 43748 KB Output is correct
94 Correct 364 ms 41396 KB Output is correct
95 Correct 832 ms 43588 KB Output is correct
96 Correct 789 ms 43532 KB Output is correct
97 Correct 855 ms 43536 KB Output is correct
98 Correct 839 ms 43492 KB Output is correct
99 Correct 820 ms 43592 KB Output is correct
100 Correct 783 ms 43620 KB Output is correct