Submission #532548

# Submission time Handle Problem Language Result Execution time Memory
532548 2022-03-03T06:57:48 Z rk42745417 Snake Escaping (JOI18_snake_escaping) C++17
22 / 100
395 ms 32708 KB
#include <bits/stdc++.h>
using namespace std;

#define EmiliaMyWife ios::sync_with_stdio(0); cin.tie(0);
using ll = int64_t;
using uint = uint32_t;
using ull = uint64_t;
using ld = long double;
const int INF = 0x3f3f3f3f;
const int MOD = 1e9 + 7;
const double EPS = 1e-8;
const ll LINF = ll(4e18) + ll(2e15);
static int LamyIsCute = []() {
	EmiliaMyWife
	return 48763;
}();

signed main() {
	int n, q;
	cin >> n >> q;
	vector<int> mpow(n + 1, 1);
	for(int i = 1; i <= n; i++)
		mpow[i] = mpow[i - 1] * 3;
	vector<int> dp(mpow[n]), prv(mpow[n]);
	{
		string s;
		cin >> s;
		for(int i = 0; i < s.size(); i++) {
			int r = 0;
			for(int j = 0; j < n; j++)
				if(i >> j & 1)
					r += mpow[j];
			dp[r] = s[i] - '0';
		}
	}
	for(int i = 0; i < n; i++) {
		swap(prv, dp);
		for(int j = 0; j < mpow[n]; j++) {
			int x = j / mpow[i] % 3;
			if(x < 2)
				dp[j] = prv[j];
			else
				dp[j] = prv[j - mpow[i] * 2] + prv[j - mpow[i]];
		}
	}

	while(q--) {
		string s;
		cin >> s;
		reverse(s.begin(), s.end());
		int r = 0;
		for(int i = 0; i < n; i++) {
			if(s[i] == '?')
				r += mpow[i] * 2;
			else
				r += mpow[i] * (s[i] & 1);
		}
		cout << dp[r] << '\n';
	}
}

Compilation message

snake_escaping.cpp: In function 'int main()':
snake_escaping.cpp:28:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   28 |   for(int i = 0; i < s.size(); i++) {
      |                  ~~^~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 4 ms 716 KB Output is correct
2 Correct 5 ms 716 KB Output is correct
3 Correct 4 ms 808 KB Output is correct
4 Correct 4 ms 700 KB Output is correct
5 Correct 4 ms 716 KB Output is correct
6 Correct 4 ms 704 KB Output is correct
7 Correct 4 ms 716 KB Output is correct
8 Correct 4 ms 716 KB Output is correct
9 Correct 5 ms 716 KB Output is correct
10 Correct 5 ms 700 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 716 KB Output is correct
2 Correct 5 ms 716 KB Output is correct
3 Correct 4 ms 808 KB Output is correct
4 Correct 4 ms 700 KB Output is correct
5 Correct 4 ms 716 KB Output is correct
6 Correct 4 ms 704 KB Output is correct
7 Correct 4 ms 716 KB Output is correct
8 Correct 4 ms 716 KB Output is correct
9 Correct 5 ms 716 KB Output is correct
10 Correct 5 ms 700 KB Output is correct
11 Correct 193 ms 15552 KB Output is correct
12 Correct 209 ms 15172 KB Output is correct
13 Correct 194 ms 14708 KB Output is correct
14 Correct 192 ms 14472 KB Output is correct
15 Correct 192 ms 15496 KB Output is correct
16 Correct 193 ms 14612 KB Output is correct
17 Correct 204 ms 14724 KB Output is correct
18 Correct 160 ms 16568 KB Output is correct
19 Correct 165 ms 13432 KB Output is correct
20 Correct 199 ms 15180 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 716 KB Output is correct
2 Correct 5 ms 716 KB Output is correct
3 Correct 4 ms 808 KB Output is correct
4 Correct 4 ms 700 KB Output is correct
5 Correct 4 ms 716 KB Output is correct
6 Correct 4 ms 704 KB Output is correct
7 Correct 4 ms 716 KB Output is correct
8 Correct 4 ms 716 KB Output is correct
9 Correct 5 ms 716 KB Output is correct
10 Correct 5 ms 700 KB Output is correct
11 Correct 193 ms 15552 KB Output is correct
12 Correct 209 ms 15172 KB Output is correct
13 Correct 194 ms 14708 KB Output is correct
14 Correct 192 ms 14472 KB Output is correct
15 Correct 192 ms 15496 KB Output is correct
16 Correct 193 ms 14612 KB Output is correct
17 Correct 204 ms 14724 KB Output is correct
18 Correct 160 ms 16568 KB Output is correct
19 Correct 165 ms 13432 KB Output is correct
20 Correct 199 ms 15180 KB Output is correct
21 Correct 371 ms 30440 KB Output is correct
22 Correct 361 ms 30688 KB Output is correct
23 Correct 339 ms 29692 KB Output is correct
24 Correct 352 ms 29468 KB Output is correct
25 Correct 360 ms 31532 KB Output is correct
26 Correct 369 ms 29988 KB Output is correct
27 Correct 384 ms 29940 KB Output is correct
28 Correct 307 ms 32708 KB Output is correct
29 Correct 298 ms 28472 KB Output is correct
30 Correct 355 ms 30584 KB Output is correct
31 Correct 359 ms 30512 KB Output is correct
32 Correct 354 ms 30532 KB Output is correct
33 Correct 333 ms 29324 KB Output is correct
34 Correct 370 ms 29500 KB Output is correct
35 Correct 395 ms 29964 KB Output is correct
36 Correct 318 ms 28440 KB Output is correct
37 Correct 347 ms 30452 KB Output is correct
38 Correct 299 ms 28408 KB Output is correct
39 Correct 346 ms 29620 KB Output is correct
40 Correct 344 ms 29440 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 716 KB Output is correct
2 Correct 5 ms 716 KB Output is correct
3 Correct 4 ms 808 KB Output is correct
4 Correct 4 ms 700 KB Output is correct
5 Correct 4 ms 716 KB Output is correct
6 Correct 4 ms 704 KB Output is correct
7 Correct 4 ms 716 KB Output is correct
8 Correct 4 ms 716 KB Output is correct
9 Correct 5 ms 716 KB Output is correct
10 Correct 5 ms 700 KB Output is correct
11 Runtime error 2 ms 588 KB Execution killed with signal 6
12 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 4 ms 716 KB Output is correct
2 Correct 5 ms 716 KB Output is correct
3 Correct 4 ms 808 KB Output is correct
4 Correct 4 ms 700 KB Output is correct
5 Correct 4 ms 716 KB Output is correct
6 Correct 4 ms 704 KB Output is correct
7 Correct 4 ms 716 KB Output is correct
8 Correct 4 ms 716 KB Output is correct
9 Correct 5 ms 716 KB Output is correct
10 Correct 5 ms 700 KB Output is correct
11 Correct 193 ms 15552 KB Output is correct
12 Correct 209 ms 15172 KB Output is correct
13 Correct 194 ms 14708 KB Output is correct
14 Correct 192 ms 14472 KB Output is correct
15 Correct 192 ms 15496 KB Output is correct
16 Correct 193 ms 14612 KB Output is correct
17 Correct 204 ms 14724 KB Output is correct
18 Correct 160 ms 16568 KB Output is correct
19 Correct 165 ms 13432 KB Output is correct
20 Correct 199 ms 15180 KB Output is correct
21 Correct 371 ms 30440 KB Output is correct
22 Correct 361 ms 30688 KB Output is correct
23 Correct 339 ms 29692 KB Output is correct
24 Correct 352 ms 29468 KB Output is correct
25 Correct 360 ms 31532 KB Output is correct
26 Correct 369 ms 29988 KB Output is correct
27 Correct 384 ms 29940 KB Output is correct
28 Correct 307 ms 32708 KB Output is correct
29 Correct 298 ms 28472 KB Output is correct
30 Correct 355 ms 30584 KB Output is correct
31 Correct 359 ms 30512 KB Output is correct
32 Correct 354 ms 30532 KB Output is correct
33 Correct 333 ms 29324 KB Output is correct
34 Correct 370 ms 29500 KB Output is correct
35 Correct 395 ms 29964 KB Output is correct
36 Correct 318 ms 28440 KB Output is correct
37 Correct 347 ms 30452 KB Output is correct
38 Correct 299 ms 28408 KB Output is correct
39 Correct 346 ms 29620 KB Output is correct
40 Correct 344 ms 29440 KB Output is correct
41 Runtime error 2 ms 588 KB Execution killed with signal 6
42 Halted 0 ms 0 KB -