Submission #287839

# Submission time Handle Problem Language Result Execution time Memory
287839 2020-09-01T03:57:29 Z MatheusLealV Snake Escaping (JOI18_snake_escaping) C++17
22 / 100
453 ms 26360 KB
#include <bits/stdc++.h>
#define f first
#define s second
#define pb push_back
#define mp make_pair
#define all(x) begin(x), end(x)
#define sz(x) (int)(x).size()
using namespace std;
typedef pair<int, int> pii;
#define N 350010
 
int n, q;
string t;
int ans[1600000], pow3[30], cost[1600000];
int get_mask(int mask, int i){
	return (mask/pow3[i]) % 3;
}

bool vis[N];
void gen(int mask){
	if(vis[mask]) return;
	vis[mask] = 1;
	for(int i = 0; i < n; i++){
		int value = get_mask(mask, i);
		if(value == 2){
			int L = mask, R = mask;
			L += -2*pow3[i] + pow3[i];
			R += -2*pow3[i];
			gen(L);
			gen(R);
			cost[mask] += cost[L] + cost[R];
			break;
		}
	}
}
int32_t main(){
	ios::sync_with_stdio(false); cin.tie(0);
	cin>>n>>q;
	cin>>t;
	pow3[0] = 1;
	for(int i = 1; i < 30; i++) pow3[i] = (3*pow3[i-1]);
	for(int i = 0; i < (1<<n); i++){
		int mask = 0;
		for(int j= 0; j < n; j++){
			if(i & (1<<j)) mask += pow3[j];
		}
		cost[mask] += t[i]-'0';
	}
		for(int i = 1 ; i < pow3[n] ; i ++){
			for(int j = 0 ; j < n ; j ++){
				if(get_mask(i,j) == 2){
					int u = i - pow3[j]*2 , v = u + pow3[j];
					cost[i] += cost[u] + cost[v];
					break ; 
				}
			}
		}
	while(q--){
		string s;
		int mask = 0;
		cin>>s;
		reverse(all(s));
		for(int i = 0; i < n; i++){
			if(s[i] == '1') mask += pow3[i];
			else if(s[i] == '?') mask += 2*pow3[i];
		}
		// gen(mask);
		cout<<cost[mask]<<"\n";
	}
}
# Verdict Execution time Memory Grader output
1 Correct 3 ms 640 KB Output is correct
2 Correct 2 ms 640 KB Output is correct
3 Correct 2 ms 640 KB Output is correct
4 Correct 2 ms 640 KB Output is correct
5 Correct 2 ms 640 KB Output is correct
6 Correct 2 ms 640 KB Output is correct
7 Correct 2 ms 640 KB Output is correct
8 Correct 2 ms 640 KB Output is correct
9 Correct 2 ms 640 KB Output is correct
10 Correct 2 ms 640 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 640 KB Output is correct
2 Correct 2 ms 640 KB Output is correct
3 Correct 2 ms 640 KB Output is correct
4 Correct 2 ms 640 KB Output is correct
5 Correct 2 ms 640 KB Output is correct
6 Correct 2 ms 640 KB Output is correct
7 Correct 2 ms 640 KB Output is correct
8 Correct 2 ms 640 KB Output is correct
9 Correct 2 ms 640 KB Output is correct
10 Correct 2 ms 640 KB Output is correct
11 Correct 259 ms 4740 KB Output is correct
12 Correct 261 ms 4732 KB Output is correct
13 Correct 269 ms 3960 KB Output is correct
14 Correct 263 ms 3948 KB Output is correct
15 Correct 254 ms 4984 KB Output is correct
16 Correct 281 ms 4216 KB Output is correct
17 Correct 286 ms 4088 KB Output is correct
18 Correct 208 ms 6136 KB Output is correct
19 Correct 243 ms 2940 KB Output is correct
20 Correct 260 ms 4600 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 640 KB Output is correct
2 Correct 2 ms 640 KB Output is correct
3 Correct 2 ms 640 KB Output is correct
4 Correct 2 ms 640 KB Output is correct
5 Correct 2 ms 640 KB Output is correct
6 Correct 2 ms 640 KB Output is correct
7 Correct 2 ms 640 KB Output is correct
8 Correct 2 ms 640 KB Output is correct
9 Correct 2 ms 640 KB Output is correct
10 Correct 2 ms 640 KB Output is correct
11 Correct 259 ms 4740 KB Output is correct
12 Correct 261 ms 4732 KB Output is correct
13 Correct 269 ms 3960 KB Output is correct
14 Correct 263 ms 3948 KB Output is correct
15 Correct 254 ms 4984 KB Output is correct
16 Correct 281 ms 4216 KB Output is correct
17 Correct 286 ms 4088 KB Output is correct
18 Correct 208 ms 6136 KB Output is correct
19 Correct 243 ms 2940 KB Output is correct
20 Correct 260 ms 4600 KB Output is correct
21 Correct 316 ms 11192 KB Output is correct
22 Correct 343 ms 24440 KB Output is correct
23 Correct 404 ms 23672 KB Output is correct
24 Correct 410 ms 23288 KB Output is correct
25 Correct 345 ms 25336 KB Output is correct
26 Correct 436 ms 23932 KB Output is correct
27 Correct 453 ms 23800 KB Output is correct
28 Correct 264 ms 26360 KB Output is correct
29 Correct 311 ms 22392 KB Output is correct
30 Correct 342 ms 24440 KB Output is correct
31 Correct 405 ms 24312 KB Output is correct
32 Correct 421 ms 24248 KB Output is correct
33 Correct 367 ms 23160 KB Output is correct
34 Correct 429 ms 23420 KB Output is correct
35 Correct 442 ms 23888 KB Output is correct
36 Correct 247 ms 22264 KB Output is correct
37 Correct 316 ms 24312 KB Output is correct
38 Correct 326 ms 22392 KB Output is correct
39 Correct 414 ms 23544 KB Output is correct
40 Correct 409 ms 23544 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 640 KB Output is correct
2 Correct 2 ms 640 KB Output is correct
3 Correct 2 ms 640 KB Output is correct
4 Correct 2 ms 640 KB Output is correct
5 Correct 2 ms 640 KB Output is correct
6 Correct 2 ms 640 KB Output is correct
7 Correct 2 ms 640 KB Output is correct
8 Correct 2 ms 640 KB Output is correct
9 Correct 2 ms 640 KB Output is correct
10 Correct 2 ms 640 KB Output is correct
11 Runtime error 11 ms 5284 KB Execution killed with signal 11
12 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 3 ms 640 KB Output is correct
2 Correct 2 ms 640 KB Output is correct
3 Correct 2 ms 640 KB Output is correct
4 Correct 2 ms 640 KB Output is correct
5 Correct 2 ms 640 KB Output is correct
6 Correct 2 ms 640 KB Output is correct
7 Correct 2 ms 640 KB Output is correct
8 Correct 2 ms 640 KB Output is correct
9 Correct 2 ms 640 KB Output is correct
10 Correct 2 ms 640 KB Output is correct
11 Correct 259 ms 4740 KB Output is correct
12 Correct 261 ms 4732 KB Output is correct
13 Correct 269 ms 3960 KB Output is correct
14 Correct 263 ms 3948 KB Output is correct
15 Correct 254 ms 4984 KB Output is correct
16 Correct 281 ms 4216 KB Output is correct
17 Correct 286 ms 4088 KB Output is correct
18 Correct 208 ms 6136 KB Output is correct
19 Correct 243 ms 2940 KB Output is correct
20 Correct 260 ms 4600 KB Output is correct
21 Correct 316 ms 11192 KB Output is correct
22 Correct 343 ms 24440 KB Output is correct
23 Correct 404 ms 23672 KB Output is correct
24 Correct 410 ms 23288 KB Output is correct
25 Correct 345 ms 25336 KB Output is correct
26 Correct 436 ms 23932 KB Output is correct
27 Correct 453 ms 23800 KB Output is correct
28 Correct 264 ms 26360 KB Output is correct
29 Correct 311 ms 22392 KB Output is correct
30 Correct 342 ms 24440 KB Output is correct
31 Correct 405 ms 24312 KB Output is correct
32 Correct 421 ms 24248 KB Output is correct
33 Correct 367 ms 23160 KB Output is correct
34 Correct 429 ms 23420 KB Output is correct
35 Correct 442 ms 23888 KB Output is correct
36 Correct 247 ms 22264 KB Output is correct
37 Correct 316 ms 24312 KB Output is correct
38 Correct 326 ms 22392 KB Output is correct
39 Correct 414 ms 23544 KB Output is correct
40 Correct 409 ms 23544 KB Output is correct
41 Runtime error 11 ms 5284 KB Execution killed with signal 11
42 Halted 0 ms 0 KB -