답안 #949444

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
949444 2024-03-19T08:51:14 Z mansur Snake Escaping (JOI18_snake_escaping) C++17
75 / 100
2000 ms 39312 KB
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx")
#pragma GCC optimize("Ofast,unroll-loops,fast-math,O3")

#include<bits/stdc++.h>	

using namespace std;

#define all(a) a.begin(), a.end()                                                   
#define rall(a) a.rbegin(), a.rend()                 
#define sz(a) (int)a.size()
#define s second
#define f first
 
using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;

mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());
     
vector<pii> rid = {{0, 1}, {0, -1}, {1, 0}, {-1, 0}};
vector<pii> dir = {{-1, -1}, {-1, 1}, {1, -1}, {1, 1}};
 
const int N = 2e5 + 1, mod = 1e9 + 7;

const ll inf = 1e9;
 
double eps = 1e-15;
                                                
bool flg = 0;

int dp[2][(1 << 20)];

int f(int x, int mk, vector<int> &s) {
	int ans = dp[x][mk];
	for (int msk = 1; msk < (1 << sz(s)); msk++) {
		int mask = mk;
		for (int i = 0; i < sz(s); i++) {
			if (msk >> i & 1) mask += (1 << s[i]);
		}
		if ((__builtin_popcount(msk)) & 1) ans -= dp[x][mask];
		else ans += dp[x][mask];
	}
	return ans;
}

void slv() {      	
	int l, q;
	cin >> l >> q;
	string s;
	cin >> s;
	for (int i = 0; i < sz(s); i++) {
		int m0 = 0, m1 = 0;
		for (int b = 0; b < l; b++) {
			if (i >> b & 1) m1 += (1 << b);
			else m0 += (1 << b);
		}
		dp[0][m0] += s[i] - '0';
		dp[1][m1] += s[i] - '0';
	}
	for (int i = 0; i < l; i++) {
		for (int msk = 0; msk < (1 << l); msk++) {
			if (!(msk >> i & 1)) {
				dp[1][msk] += dp[1][msk + (1 << i)];
				dp[0][msk] += dp[0][msk + (1 << i)];
			}
		}
	}
	while (q--) {
		string h;
		cin >> h;
		vector<int> p0, p1;
		int msk0 = 0, msk1 = 0;
		for (int i = 0; i < sz(h); i++) {
			if (h[i] == '0') {
				p0.push_back(sz(h) - i - 1);
				msk0 += (1 << p0.back());
			}
			if (h[i] == '1') {
				p1.push_back(sz(h) - i - 1);
				msk1 += (1 << p1.back());
			}
		}
		if (sz(p0) > sz(p1)) cout << f(0, msk0, p1) << '\n';
		else cout << f(1, msk1, p0) << '\n';
	}
}                                                                           
 
main() {
	//freopen("rsq.in", "r", stdin);                                                                                     
	//freopen("rsq.out", "w", stdout);                                                                                     
	ios_base::sync_with_stdio(0);	                                                                                       
	cin.tie(0);
	int tp = 1;
	if (flg) cin >> tp;
	while (tp--) {  	
		slv();
	}
}
//wenomechainsama                                              

Compilation message

snake_escaping.cpp:88:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
   88 | main() {
      | ^~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 1 ms 344 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
7 Correct 1 ms 348 KB Output is correct
8 Correct 1 ms 348 KB Output is correct
9 Correct 1 ms 348 KB Output is correct
10 Correct 1 ms 348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 1 ms 344 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
7 Correct 1 ms 348 KB Output is correct
8 Correct 1 ms 348 KB Output is correct
9 Correct 1 ms 348 KB Output is correct
10 Correct 1 ms 348 KB Output is correct
11 Correct 264 ms 4436 KB Output is correct
12 Correct 279 ms 3952 KB Output is correct
13 Correct 381 ms 3284 KB Output is correct
14 Correct 368 ms 3276 KB Output is correct
15 Correct 282 ms 4340 KB Output is correct
16 Correct 372 ms 3412 KB Output is correct
17 Correct 382 ms 3844 KB Output is correct
18 Correct 132 ms 5292 KB Output is correct
19 Correct 540 ms 2444 KB Output is correct
20 Correct 277 ms 4056 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 1 ms 344 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
7 Correct 1 ms 348 KB Output is correct
8 Correct 1 ms 348 KB Output is correct
9 Correct 1 ms 348 KB Output is correct
10 Correct 1 ms 348 KB Output is correct
11 Correct 264 ms 4436 KB Output is correct
12 Correct 279 ms 3952 KB Output is correct
13 Correct 381 ms 3284 KB Output is correct
14 Correct 368 ms 3276 KB Output is correct
15 Correct 282 ms 4340 KB Output is correct
16 Correct 372 ms 3412 KB Output is correct
17 Correct 382 ms 3844 KB Output is correct
18 Correct 132 ms 5292 KB Output is correct
19 Correct 540 ms 2444 KB Output is correct
20 Correct 277 ms 4056 KB Output is correct
21 Correct 287 ms 4432 KB Output is correct
22 Correct 305 ms 4468 KB Output is correct
23 Correct 493 ms 3628 KB Output is correct
24 Correct 461 ms 3488 KB Output is correct
25 Correct 321 ms 5560 KB Output is correct
26 Correct 456 ms 3812 KB Output is correct
27 Correct 475 ms 3924 KB Output is correct
28 Correct 150 ms 6444 KB Output is correct
29 Correct 826 ms 3052 KB Output is correct
30 Correct 297 ms 4508 KB Output is correct
31 Correct 392 ms 4456 KB Output is correct
32 Correct 449 ms 4944 KB Output is correct
33 Correct 388 ms 3412 KB Output is correct
34 Correct 458 ms 3484 KB Output is correct
35 Correct 479 ms 3852 KB Output is correct
36 Correct 260 ms 2356 KB Output is correct
37 Correct 284 ms 4340 KB Output is correct
38 Correct 708 ms 2452 KB Output is correct
39 Correct 522 ms 3924 KB Output is correct
40 Correct 462 ms 3508 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 1 ms 344 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
7 Correct 1 ms 348 KB Output is correct
8 Correct 1 ms 348 KB Output is correct
9 Correct 1 ms 348 KB Output is correct
10 Correct 1 ms 348 KB Output is correct
11 Correct 103 ms 10332 KB Output is correct
12 Correct 104 ms 9832 KB Output is correct
13 Correct 140 ms 9972 KB Output is correct
14 Correct 128 ms 9972 KB Output is correct
15 Correct 104 ms 9856 KB Output is correct
16 Correct 132 ms 9976 KB Output is correct
17 Correct 145 ms 9888 KB Output is correct
18 Correct 92 ms 9972 KB Output is correct
19 Correct 616 ms 9900 KB Output is correct
20 Correct 104 ms 12216 KB Output is correct
21 Correct 115 ms 12088 KB Output is correct
22 Correct 136 ms 12020 KB Output is correct
23 Correct 114 ms 12016 KB Output is correct
24 Correct 142 ms 12016 KB Output is correct
25 Correct 142 ms 11868 KB Output is correct
26 Correct 97 ms 11768 KB Output is correct
27 Correct 101 ms 12076 KB Output is correct
28 Correct 361 ms 11948 KB Output is correct
29 Correct 143 ms 11896 KB Output is correct
30 Correct 164 ms 12532 KB Output is correct
31 Correct 114 ms 11824 KB Output is correct
32 Correct 140 ms 12016 KB Output is correct
33 Correct 144 ms 11964 KB Output is correct
34 Correct 98 ms 12388 KB Output is correct
35 Correct 168 ms 11848 KB Output is correct
36 Correct 199 ms 12024 KB Output is correct
37 Correct 186 ms 12160 KB Output is correct
38 Correct 172 ms 11940 KB Output is correct
39 Correct 170 ms 12020 KB Output is correct
40 Correct 190 ms 12024 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 1 ms 344 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
7 Correct 1 ms 348 KB Output is correct
8 Correct 1 ms 348 KB Output is correct
9 Correct 1 ms 348 KB Output is correct
10 Correct 1 ms 348 KB Output is correct
11 Correct 264 ms 4436 KB Output is correct
12 Correct 279 ms 3952 KB Output is correct
13 Correct 381 ms 3284 KB Output is correct
14 Correct 368 ms 3276 KB Output is correct
15 Correct 282 ms 4340 KB Output is correct
16 Correct 372 ms 3412 KB Output is correct
17 Correct 382 ms 3844 KB Output is correct
18 Correct 132 ms 5292 KB Output is correct
19 Correct 540 ms 2444 KB Output is correct
20 Correct 277 ms 4056 KB Output is correct
21 Correct 287 ms 4432 KB Output is correct
22 Correct 305 ms 4468 KB Output is correct
23 Correct 493 ms 3628 KB Output is correct
24 Correct 461 ms 3488 KB Output is correct
25 Correct 321 ms 5560 KB Output is correct
26 Correct 456 ms 3812 KB Output is correct
27 Correct 475 ms 3924 KB Output is correct
28 Correct 150 ms 6444 KB Output is correct
29 Correct 826 ms 3052 KB Output is correct
30 Correct 297 ms 4508 KB Output is correct
31 Correct 392 ms 4456 KB Output is correct
32 Correct 449 ms 4944 KB Output is correct
33 Correct 388 ms 3412 KB Output is correct
34 Correct 458 ms 3484 KB Output is correct
35 Correct 479 ms 3852 KB Output is correct
36 Correct 260 ms 2356 KB Output is correct
37 Correct 284 ms 4340 KB Output is correct
38 Correct 708 ms 2452 KB Output is correct
39 Correct 522 ms 3924 KB Output is correct
40 Correct 462 ms 3508 KB Output is correct
41 Correct 103 ms 10332 KB Output is correct
42 Correct 104 ms 9832 KB Output is correct
43 Correct 140 ms 9972 KB Output is correct
44 Correct 128 ms 9972 KB Output is correct
45 Correct 104 ms 9856 KB Output is correct
46 Correct 132 ms 9976 KB Output is correct
47 Correct 145 ms 9888 KB Output is correct
48 Correct 92 ms 9972 KB Output is correct
49 Correct 616 ms 9900 KB Output is correct
50 Correct 104 ms 12216 KB Output is correct
51 Correct 115 ms 12088 KB Output is correct
52 Correct 136 ms 12020 KB Output is correct
53 Correct 114 ms 12016 KB Output is correct
54 Correct 142 ms 12016 KB Output is correct
55 Correct 142 ms 11868 KB Output is correct
56 Correct 97 ms 11768 KB Output is correct
57 Correct 101 ms 12076 KB Output is correct
58 Correct 361 ms 11948 KB Output is correct
59 Correct 143 ms 11896 KB Output is correct
60 Correct 164 ms 12532 KB Output is correct
61 Correct 114 ms 11824 KB Output is correct
62 Correct 140 ms 12016 KB Output is correct
63 Correct 144 ms 11964 KB Output is correct
64 Correct 98 ms 12388 KB Output is correct
65 Correct 168 ms 11848 KB Output is correct
66 Correct 199 ms 12024 KB Output is correct
67 Correct 186 ms 12160 KB Output is correct
68 Correct 172 ms 11940 KB Output is correct
69 Correct 170 ms 12020 KB Output is correct
70 Correct 190 ms 12024 KB Output is correct
71 Correct 516 ms 36420 KB Output is correct
72 Correct 557 ms 36416 KB Output is correct
73 Correct 1297 ms 34864 KB Output is correct
74 Correct 989 ms 35648 KB Output is correct
75 Correct 548 ms 37516 KB Output is correct
76 Correct 1042 ms 35704 KB Output is correct
77 Correct 1251 ms 35464 KB Output is correct
78 Correct 259 ms 39312 KB Output is correct
79 Execution timed out 2025 ms 14884 KB Time limit exceeded
80 Halted 0 ms 0 KB -