Submission #391312

# Submission time Handle Problem Language Result Execution time Memory
391312 2021-04-18T13:39:06 Z hhhhaura Snake Escaping (JOI18_snake_escaping) C++14
100 / 100
1218 ms 24388 KB
#define wiwihorz
#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
#pragma loop-opt(on)

#define rep(i, a, b) for(int i = a; i <= b; i++)
#define rrep(i, a, b) for(int i = b; i >= a; i--)
#define all(x) x.begin(), x.end()
#define ceil(a, b) for(int i = a; i <= b; i++)

#define INF 1000000000000000000
#define MAXN 1000005
#define MOD 1000000007
#define eps (1e-9)

#define lld long double
#define pii pair<int, int>
#define random mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count())

using namespace std;
#ifdef wiwihorz
#define print(a...) kout("[" + string(#a) + "] = ", a )
void vprint(auto L, auto R) { while(L < R) cerr << *L << " \n"[next(L) == R], ++L;}
void kout() { cerr << endl; }
template<class T1, class ... T2> void kout(T1 a, T2 ... e) { cerr << a << " ",kout(e...);}
#else 
#define print(...) 0
#define vprint(...) 0
#endif
namespace solver {
	int L; string s;
	vector<int> sp, sb, cnt;
	void init_(int _L, string _s) {
		L = _L, s = _s;
		sp.assign(1 << L, 0);
		sb.assign(1 << L, 0);
		cnt.assign(1 << L, 0);
		
		rep(i, 0, (1 << L) - 1) {
			sp[i] = s[i] - '0';
			sb[i] = s[i] - '0';
			cnt[i] = __builtin_popcount(i);
		}
		rep(i, 0, L - 1) {
			rep(j, 0, (1 << L) - 1) 
				if(!((j >> i) & 1)) sp[j] += sp[j ^ (1 << i)];
			rrep(j, 0, (1 << L) - 1) 
				if((j >> i) & 1) sb[j] += sb[j ^ (1 << i)];
		}
	}
	int query(string a) {
		int A = 0, B = 0, C = 0;
		rep(i, 0, L - 1) {
			if(a[i] == '1') B |= (1 << (L - 1 - i));
			else if(a[i] == '0') A |= (1 << (L - 1 - i));
			else C |= (1 << (L - 1 - i));
		}
		int mn = min({cnt[A], cnt[B], cnt[C]});
		if(cnt[A] == mn) { 
			int ans = sp[B];
			for(int i = A; i > 0; i = (i - 1) & A) {
				ans += sp[i | B] * ((cnt[i] & 1) ? -1 : 1);
			}
			return ans;
		}
		else if(cnt[B] == mn) { 
			int ans = sb[C] * ((cnt[B] & 1) ? -1 : 1);
			for(int i = B; i > 0; i = (i - 1) & B) {
				ans += sb[C | i] * (((cnt[B] - cnt[i]) & 1) ? -1 : 1);
			}
			return ans;
		}
		else {
			int ans = s[B] - '0';
			for(int i = C; i > 0; i = (i - 1) & C) {
				ans += s[B | i] - '0';
			}
			return ans;
		}
	} 
};
using namespace solver;
signed main() {
	ios::sync_with_stdio(false), cin.tie(0);
	int L, Q; cin >> L >> Q;
	string s; cin >> s;
	init_(L, s);
	rep(i, 1, Q) {
		string cur; cin >> cur;
		cout << query(cur) << "\n";
	}
	return 0;
}

Compilation message

snake_escaping.cpp:4: warning: ignoring #pragma loop  [-Wunknown-pragmas]
    4 | #pragma loop-opt(on)
      | 
snake_escaping.cpp:23:13: warning: use of 'auto' in parameter declaration only available with '-fconcepts'
   23 | void vprint(auto L, auto R) { while(L < R) cerr << *L << " \n"[next(L) == R], ++L;}
      |             ^~~~
snake_escaping.cpp:23:21: warning: use of 'auto' in parameter declaration only available with '-fconcepts'
   23 | void vprint(auto L, auto R) { while(L < R) cerr << *L << " \n"[next(L) == R], ++L;}
      |                     ^~~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 332 KB Output is correct
2 Correct 1 ms 332 KB Output is correct
3 Correct 1 ms 332 KB Output is correct
4 Correct 1 ms 332 KB Output is correct
5 Correct 1 ms 332 KB Output is correct
6 Correct 1 ms 332 KB Output is correct
7 Correct 1 ms 332 KB Output is correct
8 Correct 1 ms 332 KB Output is correct
9 Correct 1 ms 332 KB Output is correct
10 Correct 1 ms 332 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 332 KB Output is correct
2 Correct 1 ms 332 KB Output is correct
3 Correct 1 ms 332 KB Output is correct
4 Correct 1 ms 332 KB Output is correct
5 Correct 1 ms 332 KB Output is correct
6 Correct 1 ms 332 KB Output is correct
7 Correct 1 ms 332 KB Output is correct
8 Correct 1 ms 332 KB Output is correct
9 Correct 1 ms 332 KB Output is correct
10 Correct 1 ms 332 KB Output is correct
11 Correct 255 ms 11104 KB Output is correct
12 Correct 272 ms 13404 KB Output is correct
13 Correct 296 ms 12520 KB Output is correct
14 Correct 280 ms 12704 KB Output is correct
15 Correct 261 ms 13592 KB Output is correct
16 Correct 286 ms 12832 KB Output is correct
17 Correct 299 ms 12916 KB Output is correct
18 Correct 227 ms 14676 KB Output is correct
19 Correct 250 ms 11760 KB Output is correct
20 Correct 268 ms 13108 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 332 KB Output is correct
2 Correct 1 ms 332 KB Output is correct
3 Correct 1 ms 332 KB Output is correct
4 Correct 1 ms 332 KB Output is correct
5 Correct 1 ms 332 KB Output is correct
6 Correct 1 ms 332 KB Output is correct
7 Correct 1 ms 332 KB Output is correct
8 Correct 1 ms 332 KB Output is correct
9 Correct 1 ms 332 KB Output is correct
10 Correct 1 ms 332 KB Output is correct
11 Correct 255 ms 11104 KB Output is correct
12 Correct 272 ms 13404 KB Output is correct
13 Correct 296 ms 12520 KB Output is correct
14 Correct 280 ms 12704 KB Output is correct
15 Correct 261 ms 13592 KB Output is correct
16 Correct 286 ms 12832 KB Output is correct
17 Correct 299 ms 12916 KB Output is correct
18 Correct 227 ms 14676 KB Output is correct
19 Correct 250 ms 11760 KB Output is correct
20 Correct 268 ms 13108 KB Output is correct
21 Correct 310 ms 13508 KB Output is correct
22 Correct 324 ms 13636 KB Output is correct
23 Correct 319 ms 12548 KB Output is correct
24 Correct 334 ms 12196 KB Output is correct
25 Correct 286 ms 14124 KB Output is correct
26 Correct 342 ms 12604 KB Output is correct
27 Correct 348 ms 12404 KB Output is correct
28 Correct 239 ms 14784 KB Output is correct
29 Correct 273 ms 10724 KB Output is correct
30 Correct 291 ms 12836 KB Output is correct
31 Correct 319 ms 12516 KB Output is correct
32 Correct 341 ms 12480 KB Output is correct
33 Correct 324 ms 11344 KB Output is correct
34 Correct 393 ms 11300 KB Output is correct
35 Correct 344 ms 11560 KB Output is correct
36 Correct 221 ms 9956 KB Output is correct
37 Correct 278 ms 11956 KB Output is correct
38 Correct 287 ms 9796 KB Output is correct
39 Correct 325 ms 10816 KB Output is correct
40 Correct 372 ms 10488 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 332 KB Output is correct
2 Correct 1 ms 332 KB Output is correct
3 Correct 1 ms 332 KB Output is correct
4 Correct 1 ms 332 KB Output is correct
5 Correct 1 ms 332 KB Output is correct
6 Correct 1 ms 332 KB Output is correct
7 Correct 1 ms 332 KB Output is correct
8 Correct 1 ms 332 KB Output is correct
9 Correct 1 ms 332 KB Output is correct
10 Correct 1 ms 332 KB Output is correct
11 Correct 87 ms 15856 KB Output is correct
12 Correct 86 ms 15800 KB Output is correct
13 Correct 93 ms 15840 KB Output is correct
14 Correct 120 ms 15772 KB Output is correct
15 Correct 106 ms 15760 KB Output is correct
16 Correct 136 ms 15856 KB Output is correct
17 Correct 106 ms 15820 KB Output is correct
18 Correct 90 ms 15860 KB Output is correct
19 Correct 91 ms 15764 KB Output is correct
20 Correct 96 ms 15784 KB Output is correct
21 Correct 104 ms 15848 KB Output is correct
22 Correct 118 ms 15808 KB Output is correct
23 Correct 93 ms 15856 KB Output is correct
24 Correct 113 ms 15856 KB Output is correct
25 Correct 111 ms 15856 KB Output is correct
26 Correct 76 ms 15868 KB Output is correct
27 Correct 96 ms 15852 KB Output is correct
28 Correct 105 ms 15872 KB Output is correct
29 Correct 103 ms 15848 KB Output is correct
30 Correct 97 ms 15856 KB Output is correct
31 Correct 106 ms 15856 KB Output is correct
32 Correct 157 ms 15860 KB Output is correct
33 Correct 110 ms 15856 KB Output is correct
34 Correct 89 ms 15864 KB Output is correct
35 Correct 153 ms 15856 KB Output is correct
36 Correct 106 ms 15832 KB Output is correct
37 Correct 101 ms 15856 KB Output is correct
38 Correct 105 ms 15856 KB Output is correct
39 Correct 123 ms 15856 KB Output is correct
40 Correct 125 ms 15784 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 332 KB Output is correct
2 Correct 1 ms 332 KB Output is correct
3 Correct 1 ms 332 KB Output is correct
4 Correct 1 ms 332 KB Output is correct
5 Correct 1 ms 332 KB Output is correct
6 Correct 1 ms 332 KB Output is correct
7 Correct 1 ms 332 KB Output is correct
8 Correct 1 ms 332 KB Output is correct
9 Correct 1 ms 332 KB Output is correct
10 Correct 1 ms 332 KB Output is correct
11 Correct 255 ms 11104 KB Output is correct
12 Correct 272 ms 13404 KB Output is correct
13 Correct 296 ms 12520 KB Output is correct
14 Correct 280 ms 12704 KB Output is correct
15 Correct 261 ms 13592 KB Output is correct
16 Correct 286 ms 12832 KB Output is correct
17 Correct 299 ms 12916 KB Output is correct
18 Correct 227 ms 14676 KB Output is correct
19 Correct 250 ms 11760 KB Output is correct
20 Correct 268 ms 13108 KB Output is correct
21 Correct 310 ms 13508 KB Output is correct
22 Correct 324 ms 13636 KB Output is correct
23 Correct 319 ms 12548 KB Output is correct
24 Correct 334 ms 12196 KB Output is correct
25 Correct 286 ms 14124 KB Output is correct
26 Correct 342 ms 12604 KB Output is correct
27 Correct 348 ms 12404 KB Output is correct
28 Correct 239 ms 14784 KB Output is correct
29 Correct 273 ms 10724 KB Output is correct
30 Correct 291 ms 12836 KB Output is correct
31 Correct 319 ms 12516 KB Output is correct
32 Correct 341 ms 12480 KB Output is correct
33 Correct 324 ms 11344 KB Output is correct
34 Correct 393 ms 11300 KB Output is correct
35 Correct 344 ms 11560 KB Output is correct
36 Correct 221 ms 9956 KB Output is correct
37 Correct 278 ms 11956 KB Output is correct
38 Correct 287 ms 9796 KB Output is correct
39 Correct 325 ms 10816 KB Output is correct
40 Correct 372 ms 10488 KB Output is correct
41 Correct 87 ms 15856 KB Output is correct
42 Correct 86 ms 15800 KB Output is correct
43 Correct 93 ms 15840 KB Output is correct
44 Correct 120 ms 15772 KB Output is correct
45 Correct 106 ms 15760 KB Output is correct
46 Correct 136 ms 15856 KB Output is correct
47 Correct 106 ms 15820 KB Output is correct
48 Correct 90 ms 15860 KB Output is correct
49 Correct 91 ms 15764 KB Output is correct
50 Correct 96 ms 15784 KB Output is correct
51 Correct 104 ms 15848 KB Output is correct
52 Correct 118 ms 15808 KB Output is correct
53 Correct 93 ms 15856 KB Output is correct
54 Correct 113 ms 15856 KB Output is correct
55 Correct 111 ms 15856 KB Output is correct
56 Correct 76 ms 15868 KB Output is correct
57 Correct 96 ms 15852 KB Output is correct
58 Correct 105 ms 15872 KB Output is correct
59 Correct 103 ms 15848 KB Output is correct
60 Correct 97 ms 15856 KB Output is correct
61 Correct 106 ms 15856 KB Output is correct
62 Correct 157 ms 15860 KB Output is correct
63 Correct 110 ms 15856 KB Output is correct
64 Correct 89 ms 15864 KB Output is correct
65 Correct 153 ms 15856 KB Output is correct
66 Correct 106 ms 15832 KB Output is correct
67 Correct 101 ms 15856 KB Output is correct
68 Correct 105 ms 15856 KB Output is correct
69 Correct 123 ms 15856 KB Output is correct
70 Correct 125 ms 15784 KB Output is correct
71 Correct 617 ms 21460 KB Output is correct
72 Correct 582 ms 21668 KB Output is correct
73 Correct 718 ms 20188 KB Output is correct
74 Correct 967 ms 20448 KB Output is correct
75 Correct 646 ms 22508 KB Output is correct
76 Correct 1128 ms 20748 KB Output is correct
77 Correct 1010 ms 20576 KB Output is correct
78 Correct 373 ms 24388 KB Output is correct
79 Correct 529 ms 18348 KB Output is correct
80 Correct 595 ms 21552 KB Output is correct
81 Correct 848 ms 21444 KB Output is correct
82 Correct 921 ms 20428 KB Output is correct
83 Correct 596 ms 19560 KB Output is correct
84 Correct 1218 ms 20316 KB Output is correct
85 Correct 988 ms 20512 KB Output is correct
86 Correct 381 ms 18396 KB Output is correct
87 Correct 544 ms 21308 KB Output is correct
88 Correct 573 ms 18356 KB Output is correct
89 Correct 741 ms 19980 KB Output is correct
90 Correct 661 ms 20360 KB Output is correct
91 Correct 587 ms 19424 KB Output is correct
92 Correct 1198 ms 20752 KB Output is correct
93 Correct 1051 ms 20428 KB Output is correct
94 Correct 396 ms 18332 KB Output is correct
95 Correct 886 ms 20360 KB Output is correct
96 Correct 908 ms 20292 KB Output is correct
97 Correct 855 ms 20360 KB Output is correct
98 Correct 927 ms 20212 KB Output is correct
99 Correct 864 ms 20332 KB Output is correct
100 Correct 884 ms 19164 KB Output is correct