답안 #943577

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
943577 2024-03-11T15:39:59 Z guechotjrhh Snake Escaping (JOI18_snake_escaping) C++14
12 / 100
1507 ms 65536 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;
map<string, int> mp;
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;
}
void rec(string s, int i) {
	if (s.size() == n) {
		if (i == -1) {
			mp[s] = str[sti(s)]-'0'; return;
		}
		int u = 0;
		s[i] = '0';
		u = mp[s];
		s[i] = '1';
		u += mp[s];
		s[i] = '?';
		mp[s] = u;

		return;
	}

	rec(s + '0', i);
	rec(s + '1', i);
	rec(s + '?', s.size());
}
void init(int N, int Q, string S) {
	n = N;
	str = S;
	int z = 1; for (int i = 0; i < n; i++) z *= 3;
	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) mp[s] = str[sti(s)]-'0';
		else {
			int u = 0;
			s[ind] = '0';
			u = mp[s];
			s[ind] = '1';
			u += mp[s];
			s[ind] = '?';
			mp[s] = u;
		}
		//cout << i << ' ' << s << ' ' << mp[s] << endl;
	}
}
int query(string A) {
	return mp[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;
	}
}

Compilation message

snake_escaping.cpp: In function 'void rec(std::string, int)':
snake_escaping.cpp:33:15: warning: comparison of integer expressions of different signedness: 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   33 |  if (s.size() == n) {
      |      ~~~~~~~~~^~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 34 ms 4948 KB Output is correct
2 Correct 38 ms 4948 KB Output is correct
3 Correct 34 ms 4956 KB Output is correct
4 Correct 34 ms 4944 KB Output is correct
5 Correct 34 ms 4920 KB Output is correct
6 Correct 34 ms 4948 KB Output is correct
7 Correct 34 ms 4944 KB Output is correct
8 Correct 44 ms 5068 KB Output is correct
9 Correct 34 ms 4952 KB Output is correct
10 Correct 34 ms 4948 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 34 ms 4948 KB Output is correct
2 Correct 38 ms 4948 KB Output is correct
3 Correct 34 ms 4956 KB Output is correct
4 Correct 34 ms 4944 KB Output is correct
5 Correct 34 ms 4920 KB Output is correct
6 Correct 34 ms 4948 KB Output is correct
7 Correct 34 ms 4944 KB Output is correct
8 Correct 44 ms 5068 KB Output is correct
9 Correct 34 ms 4952 KB Output is correct
10 Correct 34 ms 4948 KB Output is correct
11 Correct 1394 ms 14904 KB Output is correct
12 Correct 1422 ms 14424 KB Output is correct
13 Correct 1483 ms 13752 KB Output is correct
14 Correct 1478 ms 14340 KB Output is correct
15 Correct 1463 ms 15560 KB Output is correct
16 Correct 1507 ms 14016 KB Output is correct
17 Correct 1489 ms 14100 KB Output is correct
18 Correct 1383 ms 16064 KB Output is correct
19 Correct 1392 ms 13104 KB Output is correct
20 Correct 1479 ms 14680 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 34 ms 4948 KB Output is correct
2 Correct 38 ms 4948 KB Output is correct
3 Correct 34 ms 4956 KB Output is correct
4 Correct 34 ms 4944 KB Output is correct
5 Correct 34 ms 4920 KB Output is correct
6 Correct 34 ms 4948 KB Output is correct
7 Correct 34 ms 4944 KB Output is correct
8 Correct 44 ms 5068 KB Output is correct
9 Correct 34 ms 4952 KB Output is correct
10 Correct 34 ms 4948 KB Output is correct
11 Correct 1394 ms 14904 KB Output is correct
12 Correct 1422 ms 14424 KB Output is correct
13 Correct 1483 ms 13752 KB Output is correct
14 Correct 1478 ms 14340 KB Output is correct
15 Correct 1463 ms 15560 KB Output is correct
16 Correct 1507 ms 14016 KB Output is correct
17 Correct 1489 ms 14100 KB Output is correct
18 Correct 1383 ms 16064 KB Output is correct
19 Correct 1392 ms 13104 KB Output is correct
20 Correct 1479 ms 14680 KB Output is correct
21 Runtime error 556 ms 65536 KB Execution killed with signal 9
22 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 34 ms 4948 KB Output is correct
2 Correct 38 ms 4948 KB Output is correct
3 Correct 34 ms 4956 KB Output is correct
4 Correct 34 ms 4944 KB Output is correct
5 Correct 34 ms 4920 KB Output is correct
6 Correct 34 ms 4948 KB Output is correct
7 Correct 34 ms 4944 KB Output is correct
8 Correct 44 ms 5068 KB Output is correct
9 Correct 34 ms 4952 KB Output is correct
10 Correct 34 ms 4948 KB Output is correct
11 Runtime error 453 ms 65536 KB Execution killed with signal 9
12 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 34 ms 4948 KB Output is correct
2 Correct 38 ms 4948 KB Output is correct
3 Correct 34 ms 4956 KB Output is correct
4 Correct 34 ms 4944 KB Output is correct
5 Correct 34 ms 4920 KB Output is correct
6 Correct 34 ms 4948 KB Output is correct
7 Correct 34 ms 4944 KB Output is correct
8 Correct 44 ms 5068 KB Output is correct
9 Correct 34 ms 4952 KB Output is correct
10 Correct 34 ms 4948 KB Output is correct
11 Correct 1394 ms 14904 KB Output is correct
12 Correct 1422 ms 14424 KB Output is correct
13 Correct 1483 ms 13752 KB Output is correct
14 Correct 1478 ms 14340 KB Output is correct
15 Correct 1463 ms 15560 KB Output is correct
16 Correct 1507 ms 14016 KB Output is correct
17 Correct 1489 ms 14100 KB Output is correct
18 Correct 1383 ms 16064 KB Output is correct
19 Correct 1392 ms 13104 KB Output is correct
20 Correct 1479 ms 14680 KB Output is correct
21 Runtime error 556 ms 65536 KB Execution killed with signal 9
22 Halted 0 ms 0 KB -