답안 #943582

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
943582 2024-03-11T15:47:37 Z guechotjrhh Snake Escaping (JOI18_snake_escaping) C++14
22 / 100
1466 ms 26452 KB
#include<iostream>
#include<string>
using namespace std;

#include<map>
#include<string>
#include<algorithm>
#include<vector>
using namespace std;
#define all(x) x.begin(),x.end()
string str;
int n;
vector<int> vc;
string its(int a, int l) {
	string res = "";
	for (int i = 0; i < l; i++) {
		if ((a % 3) == 2) res += '?';
		else res += '0' + a % 3;
		a /= 3;
	}
	reverse(all(res));
	return res;
}
int sti(string s) {
	int res = 0;
	for (int i = 0; i < n; i++) {
		res <<= 1;
		res += s[i] - '0';
	}
	return res;
}
int st3(string s) {
	int res = 0;
	for (int i = 0; i < n; i++) {
		res *= 3;
		if (s[i] == '?') res += 2;
		else res += s[i] - '0';
	}
	return res;
}
void init(int N, int Q, string S) {
	n = N;
	str = S;
	int z = 1; for (int i = 0; i < n; i++) z *= 3;
	vc.resize(z);
	for (int i = 0; i < z; i++) {
		string s = its(i, n);
		int ind = -1;
		for (int j = 0; j < n; j++) if (s[j] == '?') ind = j;
		if (ind == -1) vc[i] = str[sti(s)]-'0';
		else {
			int u = 0;
			s[ind] = '0';
			u = vc[st3(s)];
			s[ind] = '1';
			u += vc[st3(s)];
			vc[i] = u;
		}
		//cout << i << ' ' << s << ' ' << mp[s] << endl;
	}
}
int query(string A) {
	return vc[st3(A)];
}

int main() {
	ios::sync_with_stdio(0); cin.tie(0);
	int N, Q; cin >> N >> Q;
	string S; cin >> S;
	init(N, Q, move(S));
	
	for (int i = 0; i < Q; i++) {
		string A;
		cin >> A;
		cout << query(move(A)) << endl;
	}
}
# 결과 실행 시간 메모리 Grader output
1 Correct 6 ms 604 KB Output is correct
2 Correct 7 ms 708 KB Output is correct
3 Correct 7 ms 856 KB Output is correct
4 Correct 7 ms 600 KB Output is correct
5 Correct 7 ms 604 KB Output is correct
6 Correct 7 ms 704 KB Output is correct
7 Correct 6 ms 856 KB Output is correct
8 Correct 6 ms 604 KB Output is correct
9 Correct 6 ms 604 KB Output is correct
10 Correct 7 ms 604 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 6 ms 604 KB Output is correct
2 Correct 7 ms 708 KB Output is correct
3 Correct 7 ms 856 KB Output is correct
4 Correct 7 ms 600 KB Output is correct
5 Correct 7 ms 604 KB Output is correct
6 Correct 7 ms 704 KB Output is correct
7 Correct 6 ms 856 KB Output is correct
8 Correct 6 ms 604 KB Output is correct
9 Correct 6 ms 604 KB Output is correct
10 Correct 7 ms 604 KB Output is correct
11 Correct 1244 ms 4628 KB Output is correct
12 Correct 1214 ms 4688 KB Output is correct
13 Correct 1234 ms 3656 KB Output is correct
14 Correct 1226 ms 3796 KB Output is correct
15 Correct 1210 ms 4732 KB Output is correct
16 Correct 1226 ms 3956 KB Output is correct
17 Correct 1218 ms 3968 KB Output is correct
18 Correct 1217 ms 5548 KB Output is correct
19 Correct 1217 ms 3024 KB Output is correct
20 Correct 1284 ms 4380 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 6 ms 604 KB Output is correct
2 Correct 7 ms 708 KB Output is correct
3 Correct 7 ms 856 KB Output is correct
4 Correct 7 ms 600 KB Output is correct
5 Correct 7 ms 604 KB Output is correct
6 Correct 7 ms 704 KB Output is correct
7 Correct 6 ms 856 KB Output is correct
8 Correct 6 ms 604 KB Output is correct
9 Correct 6 ms 604 KB Output is correct
10 Correct 7 ms 604 KB Output is correct
11 Correct 1244 ms 4628 KB Output is correct
12 Correct 1214 ms 4688 KB Output is correct
13 Correct 1234 ms 3656 KB Output is correct
14 Correct 1226 ms 3796 KB Output is correct
15 Correct 1210 ms 4732 KB Output is correct
16 Correct 1226 ms 3956 KB Output is correct
17 Correct 1218 ms 3968 KB Output is correct
18 Correct 1217 ms 5548 KB Output is correct
19 Correct 1217 ms 3024 KB Output is correct
20 Correct 1284 ms 4380 KB Output is correct
21 Correct 1399 ms 24496 KB Output is correct
22 Correct 1425 ms 24752 KB Output is correct
23 Correct 1413 ms 23664 KB Output is correct
24 Correct 1417 ms 23316 KB Output is correct
25 Correct 1403 ms 25584 KB Output is correct
26 Correct 1452 ms 23912 KB Output is correct
27 Correct 1437 ms 23732 KB Output is correct
28 Correct 1408 ms 26452 KB Output is correct
29 Correct 1397 ms 22240 KB Output is correct
30 Correct 1404 ms 24532 KB Output is correct
31 Correct 1424 ms 24668 KB Output is correct
32 Correct 1443 ms 24504 KB Output is correct
33 Correct 1406 ms 23356 KB Output is correct
34 Correct 1428 ms 23348 KB Output is correct
35 Correct 1443 ms 24020 KB Output is correct
36 Correct 1397 ms 22364 KB Output is correct
37 Correct 1444 ms 24388 KB Output is correct
38 Correct 1466 ms 22416 KB Output is correct
39 Correct 1422 ms 23484 KB Output is correct
40 Correct 1403 ms 23632 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 6 ms 604 KB Output is correct
2 Correct 7 ms 708 KB Output is correct
3 Correct 7 ms 856 KB Output is correct
4 Correct 7 ms 600 KB Output is correct
5 Correct 7 ms 604 KB Output is correct
6 Correct 7 ms 704 KB Output is correct
7 Correct 6 ms 856 KB Output is correct
8 Correct 6 ms 604 KB Output is correct
9 Correct 6 ms 604 KB Output is correct
10 Correct 7 ms 604 KB Output is correct
11 Runtime error 7 ms 6140 KB Execution killed with signal 6
12 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 6 ms 604 KB Output is correct
2 Correct 7 ms 708 KB Output is correct
3 Correct 7 ms 856 KB Output is correct
4 Correct 7 ms 600 KB Output is correct
5 Correct 7 ms 604 KB Output is correct
6 Correct 7 ms 704 KB Output is correct
7 Correct 6 ms 856 KB Output is correct
8 Correct 6 ms 604 KB Output is correct
9 Correct 6 ms 604 KB Output is correct
10 Correct 7 ms 604 KB Output is correct
11 Correct 1244 ms 4628 KB Output is correct
12 Correct 1214 ms 4688 KB Output is correct
13 Correct 1234 ms 3656 KB Output is correct
14 Correct 1226 ms 3796 KB Output is correct
15 Correct 1210 ms 4732 KB Output is correct
16 Correct 1226 ms 3956 KB Output is correct
17 Correct 1218 ms 3968 KB Output is correct
18 Correct 1217 ms 5548 KB Output is correct
19 Correct 1217 ms 3024 KB Output is correct
20 Correct 1284 ms 4380 KB Output is correct
21 Correct 1399 ms 24496 KB Output is correct
22 Correct 1425 ms 24752 KB Output is correct
23 Correct 1413 ms 23664 KB Output is correct
24 Correct 1417 ms 23316 KB Output is correct
25 Correct 1403 ms 25584 KB Output is correct
26 Correct 1452 ms 23912 KB Output is correct
27 Correct 1437 ms 23732 KB Output is correct
28 Correct 1408 ms 26452 KB Output is correct
29 Correct 1397 ms 22240 KB Output is correct
30 Correct 1404 ms 24532 KB Output is correct
31 Correct 1424 ms 24668 KB Output is correct
32 Correct 1443 ms 24504 KB Output is correct
33 Correct 1406 ms 23356 KB Output is correct
34 Correct 1428 ms 23348 KB Output is correct
35 Correct 1443 ms 24020 KB Output is correct
36 Correct 1397 ms 22364 KB Output is correct
37 Correct 1444 ms 24388 KB Output is correct
38 Correct 1466 ms 22416 KB Output is correct
39 Correct 1422 ms 23484 KB Output is correct
40 Correct 1403 ms 23632 KB Output is correct
41 Runtime error 7 ms 6140 KB Execution killed with signal 6
42 Halted 0 ms 0 KB -