답안 #1115167

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1115167 2024-11-20T07:41:36 Z Dan4Life Snake Escaping (JOI18_snake_escaping) C++17
100 / 100
928 ms 65536 KB
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define sz(a) (int)a.size()
#define all(a) begin(a),end(a)
 
const int B1 = 7;
const int B2 = 20-B1;
const int N1 = (1<<B1)+10;
const int N2 = (1<<B2)+2;
const int M1 = 2190;
const int M2 = 1594325;
vector<array<int,2>> v, w[N1];
string s;
bitset<N1+10> submask[M1];
int l, q, ans[M2], dp[M2], nx[2][M2];
 
int calc(string lol){
	int p = 1, ans = 0, xd;
	for(int i = 0; i < sz(lol); i++){
		if(lol[i]=='?') xd=2;
		else xd = lol[i]-'0';
		ans+=xd*p, p*=3;
	}
	return ans;
}
 
int calc(int lol){
	int p = 1, ans = 0;
	while(lol){
		int r = lol%2; lol/=2;
		ans+=r*p; p*=3;
	}
	return ans;
}
 
int32_t main(){
	ios_base::sync_with_stdio(false); cin.tie(0);
	cin >> l >> q >> s;
	memset(nx,-1,sizeof(nx));
	for(int i = 0; i < M2; i++){
		int xd = i, p = 1;
		while(xd){
			int r = xd%3;
			if(r==2){
				nx[0][i] = i-2*p; 
				nx[1][i] = i-p; break;
			}
			xd/=3; p*=3;
		}
	}
	for(int i = 0; i < M1; i++){
		for(int j = 0; j < N1; j++){
			int ok = 1, cur = i, cur2 = j;
			for(int k = 0; k < B1; k++){
				int t = cur%3, t2=cur2%2; cur/=3; cur2/=2;
				if(t==2 or t==t2) continue; ok=0; break;
			}
			if(ok) submask[i][j]=1;
		}
	}
	for(int mask = 0; mask < (1<<l); mask++){
		int m1 = 0, m2 = mask;
		if(l>B1) m1 = mask&((1<<B1)-1), m2>>=B1;
		w[m1].pb({calc(m2),s[mask]-'0'});
	}
	for(int i = 0; i < q; i++){
		string t; cin >> t; 
		reverse(all(t)); string x="";
		if(l>B1) x = t.substr(0,B1),t=t.substr(B1);
		v.pb({calc(x),calc(t)});
	}
	for(int _ = 0; _ < N1-9; _++){
		memset(dp,0,sizeof(dp));
		for(auto [xd,sc] : w[_]) dp[xd]=sc;
		for(int i = 0; i < M2; i++)
			if(nx[0][i]!=-1) dp[i]=dp[nx[0][i]]+dp[nx[1][i]];
		for(int i = 0; i < q; i++){
			auto [x,y] = v[i];
			if(submask[x][_]) ans[i]+=dp[y];
		}
	}
	for(int i = 0; i < q; i++) cout << ans[i] << "\n";
}

Compilation message

snake_escaping.cpp: In function 'int32_t main()':
snake_escaping.cpp:57:5: warning: this 'if' clause does not guard... [-Wmisleading-indentation]
   57 |     if(t==2 or t==t2) continue; ok=0; break;
      |     ^~
snake_escaping.cpp:57:33: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'if'
   57 |     if(t==2 or t==t2) continue; ok=0; break;
      |                                 ^~
# 결과 실행 시간 메모리 Grader output
1 Correct 204 ms 21072 KB Output is correct
2 Correct 203 ms 21144 KB Output is correct
3 Correct 206 ms 21152 KB Output is correct
4 Correct 209 ms 21236 KB Output is correct
5 Correct 206 ms 21072 KB Output is correct
6 Correct 208 ms 21240 KB Output is correct
7 Correct 202 ms 21072 KB Output is correct
8 Correct 207 ms 21228 KB Output is correct
9 Correct 202 ms 21072 KB Output is correct
10 Correct 209 ms 21072 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 204 ms 21072 KB Output is correct
2 Correct 203 ms 21144 KB Output is correct
3 Correct 206 ms 21152 KB Output is correct
4 Correct 209 ms 21236 KB Output is correct
5 Correct 206 ms 21072 KB Output is correct
6 Correct 208 ms 21240 KB Output is correct
7 Correct 202 ms 21072 KB Output is correct
8 Correct 207 ms 21228 KB Output is correct
9 Correct 202 ms 21072 KB Output is correct
10 Correct 209 ms 21072 KB Output is correct
11 Correct 622 ms 35456 KB Output is correct
12 Correct 704 ms 35252 KB Output is correct
13 Correct 577 ms 34400 KB Output is correct
14 Correct 544 ms 34396 KB Output is correct
15 Correct 659 ms 35460 KB Output is correct
16 Correct 546 ms 34740 KB Output is correct
17 Correct 567 ms 34740 KB Output is correct
18 Correct 509 ms 36456 KB Output is correct
19 Correct 561 ms 33460 KB Output is correct
20 Correct 672 ms 35204 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 204 ms 21072 KB Output is correct
2 Correct 203 ms 21144 KB Output is correct
3 Correct 206 ms 21152 KB Output is correct
4 Correct 209 ms 21236 KB Output is correct
5 Correct 206 ms 21072 KB Output is correct
6 Correct 208 ms 21240 KB Output is correct
7 Correct 202 ms 21072 KB Output is correct
8 Correct 207 ms 21228 KB Output is correct
9 Correct 202 ms 21072 KB Output is correct
10 Correct 209 ms 21072 KB Output is correct
11 Correct 622 ms 35456 KB Output is correct
12 Correct 704 ms 35252 KB Output is correct
13 Correct 577 ms 34400 KB Output is correct
14 Correct 544 ms 34396 KB Output is correct
15 Correct 659 ms 35460 KB Output is correct
16 Correct 546 ms 34740 KB Output is correct
17 Correct 567 ms 34740 KB Output is correct
18 Correct 509 ms 36456 KB Output is correct
19 Correct 561 ms 33460 KB Output is correct
20 Correct 672 ms 35204 KB Output is correct
21 Correct 664 ms 35496 KB Output is correct
22 Correct 681 ms 35772 KB Output is correct
23 Correct 608 ms 34728 KB Output is correct
24 Correct 580 ms 34472 KB Output is correct
25 Correct 770 ms 36524 KB Output is correct
26 Correct 626 ms 35008 KB Output is correct
27 Correct 602 ms 35244 KB Output is correct
28 Correct 527 ms 37564 KB Output is correct
29 Correct 602 ms 33444 KB Output is correct
30 Correct 640 ms 37796 KB Output is correct
31 Correct 610 ms 37284 KB Output is correct
32 Correct 576 ms 35492 KB Output is correct
33 Correct 563 ms 34500 KB Output is correct
34 Correct 571 ms 34492 KB Output is correct
35 Correct 626 ms 38820 KB Output is correct
36 Correct 541 ms 35188 KB Output is correct
37 Correct 635 ms 35496 KB Output is correct
38 Correct 614 ms 33684 KB Output is correct
39 Correct 621 ms 39924 KB Output is correct
40 Correct 567 ms 34480 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 204 ms 21072 KB Output is correct
2 Correct 203 ms 21144 KB Output is correct
3 Correct 206 ms 21152 KB Output is correct
4 Correct 209 ms 21236 KB Output is correct
5 Correct 206 ms 21072 KB Output is correct
6 Correct 208 ms 21240 KB Output is correct
7 Correct 202 ms 21072 KB Output is correct
8 Correct 207 ms 21228 KB Output is correct
9 Correct 202 ms 21072 KB Output is correct
10 Correct 209 ms 21072 KB Output is correct
11 Correct 264 ms 32452 KB Output is correct
12 Correct 264 ms 32492 KB Output is correct
13 Correct 251 ms 32488 KB Output is correct
14 Correct 243 ms 32492 KB Output is correct
15 Correct 253 ms 33000 KB Output is correct
16 Correct 254 ms 33768 KB Output is correct
17 Correct 246 ms 34532 KB Output is correct
18 Correct 244 ms 34792 KB Output is correct
19 Correct 238 ms 34536 KB Output is correct
20 Correct 236 ms 32488 KB Output is correct
21 Correct 249 ms 34536 KB Output is correct
22 Correct 232 ms 34540 KB Output is correct
23 Correct 234 ms 34556 KB Output is correct
24 Correct 244 ms 34548 KB Output is correct
25 Correct 234 ms 33764 KB Output is correct
26 Correct 237 ms 34512 KB Output is correct
27 Correct 253 ms 32868 KB Output is correct
28 Correct 243 ms 34564 KB Output is correct
29 Correct 249 ms 34536 KB Output is correct
30 Correct 265 ms 34532 KB Output is correct
31 Correct 258 ms 33700 KB Output is correct
32 Correct 256 ms 33896 KB Output is correct
33 Correct 264 ms 34540 KB Output is correct
34 Correct 256 ms 32444 KB Output is correct
35 Correct 266 ms 33748 KB Output is correct
36 Correct 255 ms 33768 KB Output is correct
37 Correct 250 ms 34536 KB Output is correct
38 Correct 256 ms 33768 KB Output is correct
39 Correct 271 ms 34484 KB Output is correct
40 Correct 241 ms 34540 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 204 ms 21072 KB Output is correct
2 Correct 203 ms 21144 KB Output is correct
3 Correct 206 ms 21152 KB Output is correct
4 Correct 209 ms 21236 KB Output is correct
5 Correct 206 ms 21072 KB Output is correct
6 Correct 208 ms 21240 KB Output is correct
7 Correct 202 ms 21072 KB Output is correct
8 Correct 207 ms 21228 KB Output is correct
9 Correct 202 ms 21072 KB Output is correct
10 Correct 209 ms 21072 KB Output is correct
11 Correct 622 ms 35456 KB Output is correct
12 Correct 704 ms 35252 KB Output is correct
13 Correct 577 ms 34400 KB Output is correct
14 Correct 544 ms 34396 KB Output is correct
15 Correct 659 ms 35460 KB Output is correct
16 Correct 546 ms 34740 KB Output is correct
17 Correct 567 ms 34740 KB Output is correct
18 Correct 509 ms 36456 KB Output is correct
19 Correct 561 ms 33460 KB Output is correct
20 Correct 672 ms 35204 KB Output is correct
21 Correct 664 ms 35496 KB Output is correct
22 Correct 681 ms 35772 KB Output is correct
23 Correct 608 ms 34728 KB Output is correct
24 Correct 580 ms 34472 KB Output is correct
25 Correct 770 ms 36524 KB Output is correct
26 Correct 626 ms 35008 KB Output is correct
27 Correct 602 ms 35244 KB Output is correct
28 Correct 527 ms 37564 KB Output is correct
29 Correct 602 ms 33444 KB Output is correct
30 Correct 640 ms 37796 KB Output is correct
31 Correct 610 ms 37284 KB Output is correct
32 Correct 576 ms 35492 KB Output is correct
33 Correct 563 ms 34500 KB Output is correct
34 Correct 571 ms 34492 KB Output is correct
35 Correct 626 ms 38820 KB Output is correct
36 Correct 541 ms 35188 KB Output is correct
37 Correct 635 ms 35496 KB Output is correct
38 Correct 614 ms 33684 KB Output is correct
39 Correct 621 ms 39924 KB Output is correct
40 Correct 567 ms 34480 KB Output is correct
41 Correct 264 ms 32452 KB Output is correct
42 Correct 264 ms 32492 KB Output is correct
43 Correct 251 ms 32488 KB Output is correct
44 Correct 243 ms 32492 KB Output is correct
45 Correct 253 ms 33000 KB Output is correct
46 Correct 254 ms 33768 KB Output is correct
47 Correct 246 ms 34532 KB Output is correct
48 Correct 244 ms 34792 KB Output is correct
49 Correct 238 ms 34536 KB Output is correct
50 Correct 236 ms 32488 KB Output is correct
51 Correct 249 ms 34536 KB Output is correct
52 Correct 232 ms 34540 KB Output is correct
53 Correct 234 ms 34556 KB Output is correct
54 Correct 244 ms 34548 KB Output is correct
55 Correct 234 ms 33764 KB Output is correct
56 Correct 237 ms 34512 KB Output is correct
57 Correct 253 ms 32868 KB Output is correct
58 Correct 243 ms 34564 KB Output is correct
59 Correct 249 ms 34536 KB Output is correct
60 Correct 265 ms 34532 KB Output is correct
61 Correct 258 ms 33700 KB Output is correct
62 Correct 256 ms 33896 KB Output is correct
63 Correct 264 ms 34540 KB Output is correct
64 Correct 256 ms 32444 KB Output is correct
65 Correct 266 ms 33748 KB Output is correct
66 Correct 255 ms 33768 KB Output is correct
67 Correct 250 ms 34536 KB Output is correct
68 Correct 256 ms 33768 KB Output is correct
69 Correct 271 ms 34484 KB Output is correct
70 Correct 241 ms 34540 KB Output is correct
71 Correct 745 ms 65536 KB Output is correct
72 Correct 779 ms 65536 KB Output is correct
73 Correct 676 ms 57924 KB Output is correct
74 Correct 670 ms 65536 KB Output is correct
75 Correct 928 ms 65536 KB Output is correct
76 Correct 702 ms 65536 KB Output is correct
77 Correct 637 ms 65536 KB Output is correct
78 Correct 523 ms 57188 KB Output is correct
79 Correct 608 ms 65536 KB Output is correct
80 Correct 755 ms 51924 KB Output is correct
81 Correct 754 ms 65536 KB Output is correct
82 Correct 678 ms 64176 KB Output is correct
83 Correct 635 ms 57932 KB Output is correct
84 Correct 666 ms 65536 KB Output is correct
85 Correct 697 ms 64320 KB Output is correct
86 Correct 549 ms 45520 KB Output is correct
87 Correct 743 ms 65536 KB Output is correct
88 Correct 701 ms 64060 KB Output is correct
89 Correct 679 ms 65536 KB Output is correct
90 Correct 652 ms 49480 KB Output is correct
91 Correct 632 ms 47656 KB Output is correct
92 Correct 682 ms 65536 KB Output is correct
93 Correct 645 ms 64484 KB Output is correct
94 Correct 533 ms 64088 KB Output is correct
95 Correct 755 ms 49508 KB Output is correct
96 Correct 770 ms 65536 KB Output is correct
97 Correct 768 ms 65536 KB Output is correct
98 Correct 773 ms 65536 KB Output is correct
99 Correct 771 ms 65536 KB Output is correct
100 Correct 718 ms 65536 KB Output is correct