답안 #1036966

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1036966 2024-07-27T20:45:28 Z arashMLG Snake Escaping (JOI18_snake_escaping) C++17
100 / 100
572 ms 54536 KB
#include<bits/stdc++.h>
#ifdef LOCAL
#include "Essentials/algo/debug.h"
#else
#define debug(...)    69
#define debugArr(...)  69
#endif
using namespace std;

typedef long long     ll;
typedef pair<int,int> pii;
typedef pair<ll,ll>   pll;

const int N = 5e5 + 23;
const int LOG = 20;
const ll inf = 1e18;

#define F           first
#define S           second
#define pb          push_back
#define kill(x)     cout<<x<<endl, exit(0);
#define all(x)      x.begin(),x.end()
#define sz(x)       (int)x.size()
#define lc          (v << 1)
#define rc          ((v<<1) |1)
#define int         ll

int n,q;
int a[1<<LOG];
int sub[1<<LOG],super[1<<LOG];

int32_t main() {
    cin.tie(nullptr)->sync_with_stdio(false);
    cin>>n>>q;
	for(int i = 0 ;i < (1 << n) ; i ++) {
		char c; cin>>c;
		a[i] = c-'0';
		super[i] = sub[i] = a[i];
	}
	for(int i = 0 ; i < n; i++) for(int mask =0 ;mask < (1  << n); mask++) {
		if((mask >> i)&1) sub[mask] += sub[mask^(1<<i)];
		else              super[mask] += super[mask^(1<<i)];
	}
	while(q--) {
		int mask0=0,mask1=0,maskq=0;
		string str; cin>>str;
		reverse(all(str));
		for(int i = 0 ; i < n; i ++) {
			char c= str[i];
			if(c == '0') {
				mask0 |= (1 << i);
			} else if(c == '1') {
				mask1 |= (1 << i);
			} else {
				maskq |= (1 << i);
			}
		}
		if(__builtin_popcount(maskq) <= n/3) {
			int ans =0;
			for(int s = maskq; ;s = maskq&(s-1)) {
				ans += a[s|mask1];
				debug(s,s|mask1);
				if(s == 0) break;
			}		
			cout<<ans << '\n';
		} else if(__builtin_popcount(mask1) <= n/3) {
			int ans = 0;
			for(int s = mask1; ; s = mask1&(s-1)) {
				int zarib = ((__builtin_popcount(mask1)-__builtin_popcount(s))&1 ? -1 : 1);
				ans += zarib * sub[maskq | s];
				if(s == 0) break;
			}
			cout<<ans << '\n';
		} else {
			int ans =0;
			for(int s = mask0; ; s = mask0&(s-1)) {
				int zarib = (__builtin_popcount(s)&1 ? -1 : 1);
				ans += zarib * super[mask1|s];
				if(s == 0) break;
			}
			cout<<ans << '\n';
		}
	}
	return 0;
}

// Jumpsuit, Jumpsuit cover me!
// Jumpsuit, Jumpsuit cover me!

Compilation message

snake_escaping.cpp: In function 'int32_t main()':
snake_escaping.cpp:5:23: warning: statement has no effect [-Wunused-value]
    5 | #define debug(...)    69
      |                       ^~
snake_escaping.cpp:62:5: note: in expansion of macro 'debug'
   62 |     debug(s,s|mask1);
      |     ^~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 4444 KB Output is correct
2 Correct 1 ms 4544 KB Output is correct
3 Correct 1 ms 4444 KB Output is correct
4 Correct 1 ms 4444 KB Output is correct
5 Correct 1 ms 4444 KB Output is correct
6 Correct 1 ms 4444 KB Output is correct
7 Correct 1 ms 4444 KB Output is correct
8 Correct 1 ms 4444 KB Output is correct
9 Correct 1 ms 4444 KB Output is correct
10 Correct 1 ms 4444 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 4444 KB Output is correct
2 Correct 1 ms 4544 KB Output is correct
3 Correct 1 ms 4444 KB Output is correct
4 Correct 1 ms 4444 KB Output is correct
5 Correct 1 ms 4444 KB Output is correct
6 Correct 1 ms 4444 KB Output is correct
7 Correct 1 ms 4444 KB Output is correct
8 Correct 1 ms 4444 KB Output is correct
9 Correct 1 ms 4444 KB Output is correct
10 Correct 1 ms 4444 KB Output is correct
11 Correct 143 ms 19284 KB Output is correct
12 Correct 146 ms 18836 KB Output is correct
13 Correct 164 ms 18124 KB Output is correct
14 Correct 152 ms 18260 KB Output is correct
15 Correct 158 ms 19168 KB Output is correct
16 Correct 175 ms 18516 KB Output is correct
17 Correct 177 ms 18332 KB Output is correct
18 Correct 112 ms 20304 KB Output is correct
19 Correct 132 ms 17236 KB Output is correct
20 Correct 159 ms 18768 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 4444 KB Output is correct
2 Correct 1 ms 4544 KB Output is correct
3 Correct 1 ms 4444 KB Output is correct
4 Correct 1 ms 4444 KB Output is correct
5 Correct 1 ms 4444 KB Output is correct
6 Correct 1 ms 4444 KB Output is correct
7 Correct 1 ms 4444 KB Output is correct
8 Correct 1 ms 4444 KB Output is correct
9 Correct 1 ms 4444 KB Output is correct
10 Correct 1 ms 4444 KB Output is correct
11 Correct 143 ms 19284 KB Output is correct
12 Correct 146 ms 18836 KB Output is correct
13 Correct 164 ms 18124 KB Output is correct
14 Correct 152 ms 18260 KB Output is correct
15 Correct 158 ms 19168 KB Output is correct
16 Correct 175 ms 18516 KB Output is correct
17 Correct 177 ms 18332 KB Output is correct
18 Correct 112 ms 20304 KB Output is correct
19 Correct 132 ms 17236 KB Output is correct
20 Correct 159 ms 18768 KB Output is correct
21 Correct 171 ms 22096 KB Output is correct
22 Correct 176 ms 22356 KB Output is correct
23 Correct 196 ms 21292 KB Output is correct
24 Correct 185 ms 21328 KB Output is correct
25 Correct 194 ms 23124 KB Output is correct
26 Correct 215 ms 21672 KB Output is correct
27 Correct 213 ms 21556 KB Output is correct
28 Correct 117 ms 24144 KB Output is correct
29 Correct 153 ms 20304 KB Output is correct
30 Correct 195 ms 22488 KB Output is correct
31 Correct 206 ms 22240 KB Output is correct
32 Correct 219 ms 22168 KB Output is correct
33 Correct 171 ms 21112 KB Output is correct
34 Correct 188 ms 21116 KB Output is correct
35 Correct 206 ms 21584 KB Output is correct
36 Correct 112 ms 20308 KB Output is correct
37 Correct 156 ms 22100 KB Output is correct
38 Correct 169 ms 20308 KB Output is correct
39 Correct 184 ms 21328 KB Output is correct
40 Correct 198 ms 21328 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 4444 KB Output is correct
2 Correct 1 ms 4544 KB Output is correct
3 Correct 1 ms 4444 KB Output is correct
4 Correct 1 ms 4444 KB Output is correct
5 Correct 1 ms 4444 KB Output is correct
6 Correct 1 ms 4444 KB Output is correct
7 Correct 1 ms 4444 KB Output is correct
8 Correct 1 ms 4444 KB Output is correct
9 Correct 1 ms 4444 KB Output is correct
10 Correct 1 ms 4444 KB Output is correct
11 Correct 38 ms 27216 KB Output is correct
12 Correct 37 ms 27220 KB Output is correct
13 Correct 41 ms 27220 KB Output is correct
14 Correct 56 ms 27220 KB Output is correct
15 Correct 39 ms 27220 KB Output is correct
16 Correct 47 ms 27324 KB Output is correct
17 Correct 47 ms 27228 KB Output is correct
18 Correct 33 ms 27356 KB Output is correct
19 Correct 37 ms 26964 KB Output is correct
20 Correct 46 ms 27216 KB Output is correct
21 Correct 38 ms 27220 KB Output is correct
22 Correct 43 ms 27216 KB Output is correct
23 Correct 32 ms 27216 KB Output is correct
24 Correct 39 ms 27248 KB Output is correct
25 Correct 39 ms 27284 KB Output is correct
26 Correct 29 ms 27092 KB Output is correct
27 Correct 41 ms 27356 KB Output is correct
28 Correct 36 ms 27216 KB Output is correct
29 Correct 37 ms 27100 KB Output is correct
30 Correct 43 ms 27216 KB Output is correct
31 Correct 39 ms 27100 KB Output is correct
32 Correct 48 ms 27220 KB Output is correct
33 Correct 47 ms 27216 KB Output is correct
34 Correct 31 ms 27100 KB Output is correct
35 Correct 42 ms 27096 KB Output is correct
36 Correct 42 ms 27220 KB Output is correct
37 Correct 42 ms 27220 KB Output is correct
38 Correct 43 ms 27104 KB Output is correct
39 Correct 41 ms 27220 KB Output is correct
40 Correct 43 ms 27104 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 4444 KB Output is correct
2 Correct 1 ms 4544 KB Output is correct
3 Correct 1 ms 4444 KB Output is correct
4 Correct 1 ms 4444 KB Output is correct
5 Correct 1 ms 4444 KB Output is correct
6 Correct 1 ms 4444 KB Output is correct
7 Correct 1 ms 4444 KB Output is correct
8 Correct 1 ms 4444 KB Output is correct
9 Correct 1 ms 4444 KB Output is correct
10 Correct 1 ms 4444 KB Output is correct
11 Correct 143 ms 19284 KB Output is correct
12 Correct 146 ms 18836 KB Output is correct
13 Correct 164 ms 18124 KB Output is correct
14 Correct 152 ms 18260 KB Output is correct
15 Correct 158 ms 19168 KB Output is correct
16 Correct 175 ms 18516 KB Output is correct
17 Correct 177 ms 18332 KB Output is correct
18 Correct 112 ms 20304 KB Output is correct
19 Correct 132 ms 17236 KB Output is correct
20 Correct 159 ms 18768 KB Output is correct
21 Correct 171 ms 22096 KB Output is correct
22 Correct 176 ms 22356 KB Output is correct
23 Correct 196 ms 21292 KB Output is correct
24 Correct 185 ms 21328 KB Output is correct
25 Correct 194 ms 23124 KB Output is correct
26 Correct 215 ms 21672 KB Output is correct
27 Correct 213 ms 21556 KB Output is correct
28 Correct 117 ms 24144 KB Output is correct
29 Correct 153 ms 20304 KB Output is correct
30 Correct 195 ms 22488 KB Output is correct
31 Correct 206 ms 22240 KB Output is correct
32 Correct 219 ms 22168 KB Output is correct
33 Correct 171 ms 21112 KB Output is correct
34 Correct 188 ms 21116 KB Output is correct
35 Correct 206 ms 21584 KB Output is correct
36 Correct 112 ms 20308 KB Output is correct
37 Correct 156 ms 22100 KB Output is correct
38 Correct 169 ms 20308 KB Output is correct
39 Correct 184 ms 21328 KB Output is correct
40 Correct 198 ms 21328 KB Output is correct
41 Correct 38 ms 27216 KB Output is correct
42 Correct 37 ms 27220 KB Output is correct
43 Correct 41 ms 27220 KB Output is correct
44 Correct 56 ms 27220 KB Output is correct
45 Correct 39 ms 27220 KB Output is correct
46 Correct 47 ms 27324 KB Output is correct
47 Correct 47 ms 27228 KB Output is correct
48 Correct 33 ms 27356 KB Output is correct
49 Correct 37 ms 26964 KB Output is correct
50 Correct 46 ms 27216 KB Output is correct
51 Correct 38 ms 27220 KB Output is correct
52 Correct 43 ms 27216 KB Output is correct
53 Correct 32 ms 27216 KB Output is correct
54 Correct 39 ms 27248 KB Output is correct
55 Correct 39 ms 27284 KB Output is correct
56 Correct 29 ms 27092 KB Output is correct
57 Correct 41 ms 27356 KB Output is correct
58 Correct 36 ms 27216 KB Output is correct
59 Correct 37 ms 27100 KB Output is correct
60 Correct 43 ms 27216 KB Output is correct
61 Correct 39 ms 27100 KB Output is correct
62 Correct 48 ms 27220 KB Output is correct
63 Correct 47 ms 27216 KB Output is correct
64 Correct 31 ms 27100 KB Output is correct
65 Correct 42 ms 27096 KB Output is correct
66 Correct 42 ms 27220 KB Output is correct
67 Correct 42 ms 27220 KB Output is correct
68 Correct 43 ms 27104 KB Output is correct
69 Correct 41 ms 27220 KB Output is correct
70 Correct 43 ms 27104 KB Output is correct
71 Correct 252 ms 51636 KB Output is correct
72 Correct 272 ms 51600 KB Output is correct
73 Correct 340 ms 50148 KB Output is correct
74 Correct 558 ms 50512 KB Output is correct
75 Correct 314 ms 52444 KB Output is correct
76 Correct 453 ms 50932 KB Output is correct
77 Correct 457 ms 50668 KB Output is correct
78 Correct 181 ms 54536 KB Output is correct
79 Correct 259 ms 48608 KB Output is correct
80 Correct 288 ms 51792 KB Output is correct
81 Correct 378 ms 51536 KB Output is correct
82 Correct 551 ms 50536 KB Output is correct
83 Correct 262 ms 49744 KB Output is correct
84 Correct 395 ms 50524 KB Output is correct
85 Correct 401 ms 50772 KB Output is correct
86 Correct 171 ms 48568 KB Output is correct
87 Correct 252 ms 51652 KB Output is correct
88 Correct 314 ms 48424 KB Output is correct
89 Correct 343 ms 50256 KB Output is correct
90 Correct 413 ms 50512 KB Output is correct
91 Correct 306 ms 49632 KB Output is correct
92 Correct 572 ms 50796 KB Output is correct
93 Correct 570 ms 50660 KB Output is correct
94 Correct 175 ms 48432 KB Output is correct
95 Correct 421 ms 50660 KB Output is correct
96 Correct 456 ms 50672 KB Output is correct
97 Correct 387 ms 50612 KB Output is correct
98 Correct 362 ms 50512 KB Output is correct
99 Correct 378 ms 50552 KB Output is correct
100 Correct 374 ms 50516 KB Output is correct