Submission #1036968

# Submission time Handle Problem Language Result Execution time Memory
1036968 2024-07-27T20:46:31 Z arashMLG Snake Escaping (JOI18_snake_escaping) C++17
100 / 100
499 ms 20676 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)

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:61:5: note: in expansion of macro 'debug'
   61 |     debug(s,s|mask1);
      |     ^~~~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 4440 KB Output is correct
2 Correct 1 ms 4444 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 4440 KB Output is correct
10 Correct 1 ms 4444 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 4440 KB Output is correct
2 Correct 1 ms 4444 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 4440 KB Output is correct
10 Correct 1 ms 4444 KB Output is correct
11 Correct 151 ms 8532 KB Output is correct
12 Correct 145 ms 8008 KB Output is correct
13 Correct 163 ms 7336 KB Output is correct
14 Correct 152 ms 7508 KB Output is correct
15 Correct 145 ms 8528 KB Output is correct
16 Correct 168 ms 7504 KB Output is correct
17 Correct 166 ms 7544 KB Output is correct
18 Correct 97 ms 9556 KB Output is correct
19 Correct 139 ms 6492 KB Output is correct
20 Correct 153 ms 8020 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 4440 KB Output is correct
2 Correct 1 ms 4444 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 4440 KB Output is correct
10 Correct 1 ms 4444 KB Output is correct
11 Correct 151 ms 8532 KB Output is correct
12 Correct 145 ms 8008 KB Output is correct
13 Correct 163 ms 7336 KB Output is correct
14 Correct 152 ms 7508 KB Output is correct
15 Correct 145 ms 8528 KB Output is correct
16 Correct 168 ms 7504 KB Output is correct
17 Correct 166 ms 7544 KB Output is correct
18 Correct 97 ms 9556 KB Output is correct
19 Correct 139 ms 6492 KB Output is correct
20 Correct 153 ms 8020 KB Output is correct
21 Correct 164 ms 8528 KB Output is correct
22 Correct 162 ms 8648 KB Output is correct
23 Correct 193 ms 7764 KB Output is correct
24 Correct 184 ms 7572 KB Output is correct
25 Correct 182 ms 9556 KB Output is correct
26 Correct 192 ms 7912 KB Output is correct
27 Correct 205 ms 8020 KB Output is correct
28 Correct 103 ms 10576 KB Output is correct
29 Correct 150 ms 6480 KB Output is correct
30 Correct 177 ms 8596 KB Output is correct
31 Correct 203 ms 8452 KB Output is correct
32 Correct 201 ms 8540 KB Output is correct
33 Correct 156 ms 7248 KB Output is correct
34 Correct 178 ms 7568 KB Output is correct
35 Correct 183 ms 7956 KB Output is correct
36 Correct 104 ms 6476 KB Output is correct
37 Correct 135 ms 8432 KB Output is correct
38 Correct 142 ms 6396 KB Output is correct
39 Correct 179 ms 7528 KB Output is correct
40 Correct 164 ms 7512 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 4440 KB Output is correct
2 Correct 1 ms 4444 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 4440 KB Output is correct
10 Correct 1 ms 4444 KB Output is correct
11 Correct 32 ms 12892 KB Output is correct
12 Correct 33 ms 12924 KB Output is correct
13 Correct 36 ms 12892 KB Output is correct
14 Correct 44 ms 12884 KB Output is correct
15 Correct 35 ms 12892 KB Output is correct
16 Correct 39 ms 12892 KB Output is correct
17 Correct 41 ms 12884 KB Output is correct
18 Correct 28 ms 13016 KB Output is correct
19 Correct 31 ms 12620 KB Output is correct
20 Correct 32 ms 12892 KB Output is correct
21 Correct 36 ms 12884 KB Output is correct
22 Correct 46 ms 12884 KB Output is correct
23 Correct 34 ms 12772 KB Output is correct
24 Correct 37 ms 12880 KB Output is correct
25 Correct 38 ms 12760 KB Output is correct
26 Correct 37 ms 12636 KB Output is correct
27 Correct 42 ms 12764 KB Output is correct
28 Correct 35 ms 12632 KB Output is correct
29 Correct 37 ms 12844 KB Output is correct
30 Correct 40 ms 12760 KB Output is correct
31 Correct 37 ms 12888 KB Output is correct
32 Correct 45 ms 12756 KB Output is correct
33 Correct 36 ms 12880 KB Output is correct
34 Correct 26 ms 12632 KB Output is correct
35 Correct 39 ms 12892 KB Output is correct
36 Correct 39 ms 12760 KB Output is correct
37 Correct 34 ms 12880 KB Output is correct
38 Correct 36 ms 12892 KB Output is correct
39 Correct 36 ms 12892 KB Output is correct
40 Correct 34 ms 12892 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 4440 KB Output is correct
2 Correct 1 ms 4444 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 4440 KB Output is correct
10 Correct 1 ms 4444 KB Output is correct
11 Correct 151 ms 8532 KB Output is correct
12 Correct 145 ms 8008 KB Output is correct
13 Correct 163 ms 7336 KB Output is correct
14 Correct 152 ms 7508 KB Output is correct
15 Correct 145 ms 8528 KB Output is correct
16 Correct 168 ms 7504 KB Output is correct
17 Correct 166 ms 7544 KB Output is correct
18 Correct 97 ms 9556 KB Output is correct
19 Correct 139 ms 6492 KB Output is correct
20 Correct 153 ms 8020 KB Output is correct
21 Correct 164 ms 8528 KB Output is correct
22 Correct 162 ms 8648 KB Output is correct
23 Correct 193 ms 7764 KB Output is correct
24 Correct 184 ms 7572 KB Output is correct
25 Correct 182 ms 9556 KB Output is correct
26 Correct 192 ms 7912 KB Output is correct
27 Correct 205 ms 8020 KB Output is correct
28 Correct 103 ms 10576 KB Output is correct
29 Correct 150 ms 6480 KB Output is correct
30 Correct 177 ms 8596 KB Output is correct
31 Correct 203 ms 8452 KB Output is correct
32 Correct 201 ms 8540 KB Output is correct
33 Correct 156 ms 7248 KB Output is correct
34 Correct 178 ms 7568 KB Output is correct
35 Correct 183 ms 7956 KB Output is correct
36 Correct 104 ms 6476 KB Output is correct
37 Correct 135 ms 8432 KB Output is correct
38 Correct 142 ms 6396 KB Output is correct
39 Correct 179 ms 7528 KB Output is correct
40 Correct 164 ms 7512 KB Output is correct
41 Correct 32 ms 12892 KB Output is correct
42 Correct 33 ms 12924 KB Output is correct
43 Correct 36 ms 12892 KB Output is correct
44 Correct 44 ms 12884 KB Output is correct
45 Correct 35 ms 12892 KB Output is correct
46 Correct 39 ms 12892 KB Output is correct
47 Correct 41 ms 12884 KB Output is correct
48 Correct 28 ms 13016 KB Output is correct
49 Correct 31 ms 12620 KB Output is correct
50 Correct 32 ms 12892 KB Output is correct
51 Correct 36 ms 12884 KB Output is correct
52 Correct 46 ms 12884 KB Output is correct
53 Correct 34 ms 12772 KB Output is correct
54 Correct 37 ms 12880 KB Output is correct
55 Correct 38 ms 12760 KB Output is correct
56 Correct 37 ms 12636 KB Output is correct
57 Correct 42 ms 12764 KB Output is correct
58 Correct 35 ms 12632 KB Output is correct
59 Correct 37 ms 12844 KB Output is correct
60 Correct 40 ms 12760 KB Output is correct
61 Correct 37 ms 12888 KB Output is correct
62 Correct 45 ms 12756 KB Output is correct
63 Correct 36 ms 12880 KB Output is correct
64 Correct 26 ms 12632 KB Output is correct
65 Correct 39 ms 12892 KB Output is correct
66 Correct 39 ms 12760 KB Output is correct
67 Correct 34 ms 12880 KB Output is correct
68 Correct 36 ms 12892 KB Output is correct
69 Correct 36 ms 12892 KB Output is correct
70 Correct 34 ms 12892 KB Output is correct
71 Correct 238 ms 17752 KB Output is correct
72 Correct 213 ms 17744 KB Output is correct
73 Correct 297 ms 16340 KB Output is correct
74 Correct 499 ms 16536 KB Output is correct
75 Correct 275 ms 18728 KB Output is correct
76 Correct 403 ms 16976 KB Output is correct
77 Correct 349 ms 16720 KB Output is correct
78 Correct 171 ms 20676 KB Output is correct
79 Correct 210 ms 14672 KB Output is correct
80 Correct 270 ms 17744 KB Output is correct
81 Correct 325 ms 17540 KB Output is correct
82 Correct 491 ms 16720 KB Output is correct
83 Correct 248 ms 15956 KB Output is correct
84 Correct 361 ms 16724 KB Output is correct
85 Correct 342 ms 16828 KB Output is correct
86 Correct 147 ms 14672 KB Output is correct
87 Correct 215 ms 17652 KB Output is correct
88 Correct 234 ms 14648 KB Output is correct
89 Correct 275 ms 16464 KB Output is correct
90 Correct 327 ms 16720 KB Output is correct
91 Correct 254 ms 15956 KB Output is correct
92 Correct 423 ms 16980 KB Output is correct
93 Correct 337 ms 16720 KB Output is correct
94 Correct 135 ms 14616 KB Output is correct
95 Correct 299 ms 16720 KB Output is correct
96 Correct 292 ms 16720 KB Output is correct
97 Correct 291 ms 16720 KB Output is correct
98 Correct 302 ms 16724 KB Output is correct
99 Correct 288 ms 16720 KB Output is correct
100 Correct 293 ms 16720 KB Output is correct