답안 #286819

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
286819 2020-08-31T04:16:05 Z MatheusLealV Snake Escaping (JOI18_snake_escaping) C++17
22 / 100
884 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], pot3[30];

void solve(int i, int mask, int mask2, int cost){
	if(i >= n){
		ans[mask2] += cost;
		return;
	}
	solve(i + 1, mask, mask2 + 2*pot3[i], cost); // adiciona ?
	if(mask & (1<<i)) solve(i + 1, mask, mask2 + pot3[i], cost); // adiciona 1
	else solve(i + 1, mask, mask2, cost); // adiciona 0
}
int32_t main(){
	ios::sync_with_stdio(false); cin.tie(0);
	cin>>n>>q;
	cin>>t;
	pot3[0] = 1;
	for(int i = 1; i < 30; i++) pot3[i] = (3*pot3[i-1]);

	for (int mask=0; mask<(1<<n); ++mask){
		solve(0, mask, 0, (t[mask]-'0'));
	}
	while(q--){
		string s;
		int mask = 0;
		cin>>s;
		reverse(all(s));
		for(int i = 0; i < n; i++){
			if(s[i] == '1') mask += pot3[i];
			else if(s[i] == '?') mask += 2*pot3[i];
		}
		cout<<ans[mask]<<"\n";
	}
}
# 결과 실행 시간 메모리 Grader output
1 Correct 8 ms 640 KB Output is correct
2 Correct 8 ms 640 KB Output is correct
3 Correct 8 ms 640 KB Output is correct
4 Correct 8 ms 640 KB Output is correct
5 Correct 8 ms 640 KB Output is correct
6 Correct 8 ms 640 KB Output is correct
7 Correct 8 ms 640 KB Output is correct
8 Correct 8 ms 640 KB Output is correct
9 Correct 8 ms 512 KB Output is correct
10 Correct 8 ms 640 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 8 ms 640 KB Output is correct
2 Correct 8 ms 640 KB Output is correct
3 Correct 8 ms 640 KB Output is correct
4 Correct 8 ms 640 KB Output is correct
5 Correct 8 ms 640 KB Output is correct
6 Correct 8 ms 640 KB Output is correct
7 Correct 8 ms 640 KB Output is correct
8 Correct 8 ms 640 KB Output is correct
9 Correct 8 ms 512 KB Output is correct
10 Correct 8 ms 640 KB Output is correct
11 Correct 244 ms 15348 KB Output is correct
12 Correct 259 ms 15000 KB Output is correct
13 Correct 261 ms 14328 KB Output is correct
14 Correct 264 ms 14368 KB Output is correct
15 Correct 251 ms 15352 KB Output is correct
16 Correct 280 ms 14616 KB Output is correct
17 Correct 285 ms 14608 KB Output is correct
18 Correct 203 ms 16376 KB Output is correct
19 Correct 235 ms 13440 KB Output is correct
20 Correct 255 ms 14968 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 8 ms 640 KB Output is correct
2 Correct 8 ms 640 KB Output is correct
3 Correct 8 ms 640 KB Output is correct
4 Correct 8 ms 640 KB Output is correct
5 Correct 8 ms 640 KB Output is correct
6 Correct 8 ms 640 KB Output is correct
7 Correct 8 ms 640 KB Output is correct
8 Correct 8 ms 640 KB Output is correct
9 Correct 8 ms 512 KB Output is correct
10 Correct 8 ms 640 KB Output is correct
11 Correct 244 ms 15348 KB Output is correct
12 Correct 259 ms 15000 KB Output is correct
13 Correct 261 ms 14328 KB Output is correct
14 Correct 264 ms 14368 KB Output is correct
15 Correct 251 ms 15352 KB Output is correct
16 Correct 280 ms 14616 KB Output is correct
17 Correct 285 ms 14608 KB Output is correct
18 Correct 203 ms 16376 KB Output is correct
19 Correct 235 ms 13440 KB Output is correct
20 Correct 255 ms 14968 KB Output is correct
21 Correct 753 ms 24320 KB Output is correct
22 Correct 767 ms 24696 KB Output is correct
23 Correct 834 ms 23672 KB Output is correct
24 Correct 848 ms 23544 KB Output is correct
25 Correct 777 ms 25336 KB Output is correct
26 Correct 869 ms 24184 KB Output is correct
27 Correct 878 ms 23932 KB Output is correct
28 Correct 698 ms 26360 KB Output is correct
29 Correct 741 ms 22392 KB Output is correct
30 Correct 768 ms 24396 KB Output is correct
31 Correct 825 ms 24340 KB Output is correct
32 Correct 840 ms 24232 KB Output is correct
33 Correct 790 ms 23316 KB Output is correct
34 Correct 850 ms 23416 KB Output is correct
35 Correct 884 ms 23740 KB Output is correct
36 Correct 685 ms 22380 KB Output is correct
37 Correct 756 ms 24440 KB Output is correct
38 Correct 761 ms 22648 KB Output is correct
39 Correct 851 ms 23544 KB Output is correct
40 Correct 830 ms 23416 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 8 ms 640 KB Output is correct
2 Correct 8 ms 640 KB Output is correct
3 Correct 8 ms 640 KB Output is correct
4 Correct 8 ms 640 KB Output is correct
5 Correct 8 ms 640 KB Output is correct
6 Correct 8 ms 640 KB Output is correct
7 Correct 8 ms 640 KB Output is correct
8 Correct 8 ms 640 KB Output is correct
9 Correct 8 ms 512 KB Output is correct
10 Correct 8 ms 640 KB Output is correct
11 Runtime error 7 ms 4132 KB Execution killed with signal 11
12 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 8 ms 640 KB Output is correct
2 Correct 8 ms 640 KB Output is correct
3 Correct 8 ms 640 KB Output is correct
4 Correct 8 ms 640 KB Output is correct
5 Correct 8 ms 640 KB Output is correct
6 Correct 8 ms 640 KB Output is correct
7 Correct 8 ms 640 KB Output is correct
8 Correct 8 ms 640 KB Output is correct
9 Correct 8 ms 512 KB Output is correct
10 Correct 8 ms 640 KB Output is correct
11 Correct 244 ms 15348 KB Output is correct
12 Correct 259 ms 15000 KB Output is correct
13 Correct 261 ms 14328 KB Output is correct
14 Correct 264 ms 14368 KB Output is correct
15 Correct 251 ms 15352 KB Output is correct
16 Correct 280 ms 14616 KB Output is correct
17 Correct 285 ms 14608 KB Output is correct
18 Correct 203 ms 16376 KB Output is correct
19 Correct 235 ms 13440 KB Output is correct
20 Correct 255 ms 14968 KB Output is correct
21 Correct 753 ms 24320 KB Output is correct
22 Correct 767 ms 24696 KB Output is correct
23 Correct 834 ms 23672 KB Output is correct
24 Correct 848 ms 23544 KB Output is correct
25 Correct 777 ms 25336 KB Output is correct
26 Correct 869 ms 24184 KB Output is correct
27 Correct 878 ms 23932 KB Output is correct
28 Correct 698 ms 26360 KB Output is correct
29 Correct 741 ms 22392 KB Output is correct
30 Correct 768 ms 24396 KB Output is correct
31 Correct 825 ms 24340 KB Output is correct
32 Correct 840 ms 24232 KB Output is correct
33 Correct 790 ms 23316 KB Output is correct
34 Correct 850 ms 23416 KB Output is correct
35 Correct 884 ms 23740 KB Output is correct
36 Correct 685 ms 22380 KB Output is correct
37 Correct 756 ms 24440 KB Output is correct
38 Correct 761 ms 22648 KB Output is correct
39 Correct 851 ms 23544 KB Output is correct
40 Correct 830 ms 23416 KB Output is correct
41 Runtime error 7 ms 4132 KB Execution killed with signal 11
42 Halted 0 ms 0 KB -