Submission #943449

# Submission time Handle Problem Language Result Execution time Memory
943449 2024-03-11T13:23:30 Z guechotjrhh Snake Escaping (JOI18_snake_escaping) C++14
12 / 100
1542 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++) {
		res += '0' + (a & 1);
		a >>= 1;
	}
	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;
	rec("", -1);
}
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:32:15: warning: comparison of integer expressions of different signedness: 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   32 |  if (s.size() == n) {
      |      ~~~~~~~~~^~~~
# Verdict Execution time Memory Grader output
1 Correct 31 ms 4904 KB Output is correct
2 Correct 34 ms 4952 KB Output is correct
3 Correct 42 ms 4984 KB Output is correct
4 Correct 37 ms 4888 KB Output is correct
5 Correct 41 ms 5032 KB Output is correct
6 Correct 34 ms 4888 KB Output is correct
7 Correct 34 ms 4956 KB Output is correct
8 Correct 37 ms 4956 KB Output is correct
9 Correct 35 ms 5056 KB Output is correct
10 Correct 32 ms 5036 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 31 ms 4904 KB Output is correct
2 Correct 34 ms 4952 KB Output is correct
3 Correct 42 ms 4984 KB Output is correct
4 Correct 37 ms 4888 KB Output is correct
5 Correct 41 ms 5032 KB Output is correct
6 Correct 34 ms 4888 KB Output is correct
7 Correct 34 ms 4956 KB Output is correct
8 Correct 37 ms 4956 KB Output is correct
9 Correct 35 ms 5056 KB Output is correct
10 Correct 32 ms 5036 KB Output is correct
11 Correct 1452 ms 14812 KB Output is correct
12 Correct 1473 ms 14172 KB Output is correct
13 Correct 1542 ms 13468 KB Output is correct
14 Correct 1511 ms 13920 KB Output is correct
15 Correct 1459 ms 14984 KB Output is correct
16 Correct 1485 ms 13908 KB Output is correct
17 Correct 1516 ms 13880 KB Output is correct
18 Correct 1392 ms 15704 KB Output is correct
19 Correct 1356 ms 12768 KB Output is correct
20 Correct 1403 ms 14260 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 31 ms 4904 KB Output is correct
2 Correct 34 ms 4952 KB Output is correct
3 Correct 42 ms 4984 KB Output is correct
4 Correct 37 ms 4888 KB Output is correct
5 Correct 41 ms 5032 KB Output is correct
6 Correct 34 ms 4888 KB Output is correct
7 Correct 34 ms 4956 KB Output is correct
8 Correct 37 ms 4956 KB Output is correct
9 Correct 35 ms 5056 KB Output is correct
10 Correct 32 ms 5036 KB Output is correct
11 Correct 1452 ms 14812 KB Output is correct
12 Correct 1473 ms 14172 KB Output is correct
13 Correct 1542 ms 13468 KB Output is correct
14 Correct 1511 ms 13920 KB Output is correct
15 Correct 1459 ms 14984 KB Output is correct
16 Correct 1485 ms 13908 KB Output is correct
17 Correct 1516 ms 13880 KB Output is correct
18 Correct 1392 ms 15704 KB Output is correct
19 Correct 1356 ms 12768 KB Output is correct
20 Correct 1403 ms 14260 KB Output is correct
21 Runtime error 522 ms 65536 KB Execution killed with signal 9
22 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 31 ms 4904 KB Output is correct
2 Correct 34 ms 4952 KB Output is correct
3 Correct 42 ms 4984 KB Output is correct
4 Correct 37 ms 4888 KB Output is correct
5 Correct 41 ms 5032 KB Output is correct
6 Correct 34 ms 4888 KB Output is correct
7 Correct 34 ms 4956 KB Output is correct
8 Correct 37 ms 4956 KB Output is correct
9 Correct 35 ms 5056 KB Output is correct
10 Correct 32 ms 5036 KB Output is correct
11 Runtime error 427 ms 65536 KB Execution killed with signal 9
12 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 31 ms 4904 KB Output is correct
2 Correct 34 ms 4952 KB Output is correct
3 Correct 42 ms 4984 KB Output is correct
4 Correct 37 ms 4888 KB Output is correct
5 Correct 41 ms 5032 KB Output is correct
6 Correct 34 ms 4888 KB Output is correct
7 Correct 34 ms 4956 KB Output is correct
8 Correct 37 ms 4956 KB Output is correct
9 Correct 35 ms 5056 KB Output is correct
10 Correct 32 ms 5036 KB Output is correct
11 Correct 1452 ms 14812 KB Output is correct
12 Correct 1473 ms 14172 KB Output is correct
13 Correct 1542 ms 13468 KB Output is correct
14 Correct 1511 ms 13920 KB Output is correct
15 Correct 1459 ms 14984 KB Output is correct
16 Correct 1485 ms 13908 KB Output is correct
17 Correct 1516 ms 13880 KB Output is correct
18 Correct 1392 ms 15704 KB Output is correct
19 Correct 1356 ms 12768 KB Output is correct
20 Correct 1403 ms 14260 KB Output is correct
21 Runtime error 522 ms 65536 KB Execution killed with signal 9
22 Halted 0 ms 0 KB -