#include <bits/stdc++.h>
#define ff first
#define ss second
#define pb push_back
#define mp make_pair
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<ll, ll> pll;
typedef pair<ull, ull> pull;
typedef pair<ll, ll> pii;
typedef pair<ld, ld> pld;
ll l, q;
string s;
ll totzero = 0;
ll a = 13, b = 5;
ll sum[(1<<13)+10][(1<<7)+10];
ll p3[30];
//unordered_map<ll, ll> dp[23][(1<<13)+10];
unordered_map<ll, ll> dp;
ll v2;
ll calc(ll step, ll idx, ll val){
/*if(dp[step][idx][val] != 0){
return dp[step][idx][val]-1;
}*/
if(step == a || step == s.size()){
//dp[step][idx][val] = sum[idx][v2]+1;
//return dp[step][idx][val]-1;
return sum[idx][v2];
}
//dp[step][idx][val] = 1;
ll ret = 0;
if(s[step] != '1')
ret += calc(step+1, idx, val/3);
//dp[step][idx][val] += calc(step+1, idx, val/3);
if(s[step] != '0')
ret += calc(step+1, idx+(1LL<<step), val/3);
//dp[step][idx][val] += calc(step+1, idx+(1LL<<step), val/3);
return ret;
//return dp[step][idx][val]-1;
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
//freopen("in.txt", "r", stdin);
//freopen("out.txt", "w", stdout);
p3[0] = 1;
for(ll i = 1; i < 30; ++i)
p3[i] = 3*p3[i-1];
cin >> l >> q;
ll n = (1<<l);
cin >> s;
for(ll i = 0; i < n; ++i){
ll v1 = (i&((1<<a)-1));
for(ll bit = 0; bit < (1<<b); ++bit){
ll idx = 0;
ll val = (i>>a);
for(ll j = 0; j < b; ++j){
if((1<<j)&bit)
idx += p3[j]*(val%2);
else
idx += p3[j]*2;
val /= 2;
}
sum[v1][idx] += s[i]-'0';
}
}
for(ll i = 0; i < q; ++i){
cin >> s;
reverse(s.begin(), s.end());
ll v1 = 0;
for(ll i = 0; i < s.size(); ++i){
if(s[i] == '1')
v1 += p3[i];
else if(s[i] == '?')
v1 += 2*p3[i];
}
v2 = 0;
for(ll i = a; i < s.size(); ++i){
if(s[i] == '1')
v2 += p3[i-a];
else if(s[i] == '?')
v2 += 2*p3[i-a];
}
if(dp[v1] == 0)
dp[v1] = calc(0, 0, v1)+1;
cout << dp[v1]-1 << '\n';
}
}
Compilation message
snake_escaping.cpp: In function 'll calc(ll, ll, ll)':
snake_escaping.cpp:27:26: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
if(step == a || step == s.size()){
~~~~~^~~~~~~~~~~
snake_escaping.cpp: In function 'int main()':
snake_escaping.cpp:76:25: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for(ll i = 0; i < s.size(); ++i){
~~^~~~~~~~~~
snake_escaping.cpp:83:25: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for(ll i = a; i < s.size(); ++i){
~~^~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
1408 KB |
Output is correct |
2 |
Correct |
3 ms |
1536 KB |
Output is correct |
3 |
Correct |
2 ms |
1536 KB |
Output is correct |
4 |
Correct |
2 ms |
1536 KB |
Output is correct |
5 |
Correct |
3 ms |
1536 KB |
Output is correct |
6 |
Correct |
2 ms |
1536 KB |
Output is correct |
7 |
Correct |
2 ms |
1536 KB |
Output is correct |
8 |
Correct |
2 ms |
1408 KB |
Output is correct |
9 |
Correct |
1 ms |
1408 KB |
Output is correct |
10 |
Correct |
2 ms |
1536 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
1408 KB |
Output is correct |
2 |
Correct |
3 ms |
1536 KB |
Output is correct |
3 |
Correct |
2 ms |
1536 KB |
Output is correct |
4 |
Correct |
2 ms |
1536 KB |
Output is correct |
5 |
Correct |
3 ms |
1536 KB |
Output is correct |
6 |
Correct |
2 ms |
1536 KB |
Output is correct |
7 |
Correct |
2 ms |
1536 KB |
Output is correct |
8 |
Correct |
2 ms |
1408 KB |
Output is correct |
9 |
Correct |
1 ms |
1408 KB |
Output is correct |
10 |
Correct |
2 ms |
1536 KB |
Output is correct |
11 |
Correct |
238 ms |
5496 KB |
Output is correct |
12 |
Correct |
261 ms |
5240 KB |
Output is correct |
13 |
Correct |
269 ms |
4728 KB |
Output is correct |
14 |
Correct |
262 ms |
4728 KB |
Output is correct |
15 |
Correct |
252 ms |
5624 KB |
Output is correct |
16 |
Correct |
289 ms |
5496 KB |
Output is correct |
17 |
Correct |
325 ms |
7304 KB |
Output is correct |
18 |
Correct |
196 ms |
6648 KB |
Output is correct |
19 |
Correct |
243 ms |
3960 KB |
Output is correct |
20 |
Correct |
257 ms |
5884 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
1408 KB |
Output is correct |
2 |
Correct |
3 ms |
1536 KB |
Output is correct |
3 |
Correct |
2 ms |
1536 KB |
Output is correct |
4 |
Correct |
2 ms |
1536 KB |
Output is correct |
5 |
Correct |
3 ms |
1536 KB |
Output is correct |
6 |
Correct |
2 ms |
1536 KB |
Output is correct |
7 |
Correct |
2 ms |
1536 KB |
Output is correct |
8 |
Correct |
2 ms |
1408 KB |
Output is correct |
9 |
Correct |
1 ms |
1408 KB |
Output is correct |
10 |
Correct |
2 ms |
1536 KB |
Output is correct |
11 |
Correct |
238 ms |
5496 KB |
Output is correct |
12 |
Correct |
261 ms |
5240 KB |
Output is correct |
13 |
Correct |
269 ms |
4728 KB |
Output is correct |
14 |
Correct |
262 ms |
4728 KB |
Output is correct |
15 |
Correct |
252 ms |
5624 KB |
Output is correct |
16 |
Correct |
289 ms |
5496 KB |
Output is correct |
17 |
Correct |
325 ms |
7304 KB |
Output is correct |
18 |
Correct |
196 ms |
6648 KB |
Output is correct |
19 |
Correct |
243 ms |
3960 KB |
Output is correct |
20 |
Correct |
257 ms |
5884 KB |
Output is correct |
21 |
Correct |
273 ms |
13816 KB |
Output is correct |
22 |
Correct |
327 ms |
14200 KB |
Output is correct |
23 |
Correct |
735 ms |
34836 KB |
Output is correct |
24 |
Correct |
473 ms |
29700 KB |
Output is correct |
25 |
Correct |
562 ms |
29608 KB |
Output is correct |
26 |
Correct |
1086 ms |
40608 KB |
Output is correct |
27 |
Correct |
1679 ms |
57020 KB |
Output is correct |
28 |
Correct |
231 ms |
28920 KB |
Output is correct |
29 |
Correct |
284 ms |
25080 KB |
Output is correct |
30 |
Correct |
318 ms |
27512 KB |
Output is correct |
31 |
Correct |
1094 ms |
35460 KB |
Output is correct |
32 |
Correct |
691 ms |
30724 KB |
Output is correct |
33 |
Correct |
374 ms |
27640 KB |
Output is correct |
34 |
Correct |
1030 ms |
40200 KB |
Output is correct |
35 |
Execution timed out |
2023 ms |
56772 KB |
Time limit exceeded |
36 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
1408 KB |
Output is correct |
2 |
Correct |
3 ms |
1536 KB |
Output is correct |
3 |
Correct |
2 ms |
1536 KB |
Output is correct |
4 |
Correct |
2 ms |
1536 KB |
Output is correct |
5 |
Correct |
3 ms |
1536 KB |
Output is correct |
6 |
Correct |
2 ms |
1536 KB |
Output is correct |
7 |
Correct |
2 ms |
1536 KB |
Output is correct |
8 |
Correct |
2 ms |
1408 KB |
Output is correct |
9 |
Correct |
1 ms |
1408 KB |
Output is correct |
10 |
Correct |
2 ms |
1536 KB |
Output is correct |
11 |
Incorrect |
733 ms |
13716 KB |
Output isn't correct |
12 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
1408 KB |
Output is correct |
2 |
Correct |
3 ms |
1536 KB |
Output is correct |
3 |
Correct |
2 ms |
1536 KB |
Output is correct |
4 |
Correct |
2 ms |
1536 KB |
Output is correct |
5 |
Correct |
3 ms |
1536 KB |
Output is correct |
6 |
Correct |
2 ms |
1536 KB |
Output is correct |
7 |
Correct |
2 ms |
1536 KB |
Output is correct |
8 |
Correct |
2 ms |
1408 KB |
Output is correct |
9 |
Correct |
1 ms |
1408 KB |
Output is correct |
10 |
Correct |
2 ms |
1536 KB |
Output is correct |
11 |
Correct |
238 ms |
5496 KB |
Output is correct |
12 |
Correct |
261 ms |
5240 KB |
Output is correct |
13 |
Correct |
269 ms |
4728 KB |
Output is correct |
14 |
Correct |
262 ms |
4728 KB |
Output is correct |
15 |
Correct |
252 ms |
5624 KB |
Output is correct |
16 |
Correct |
289 ms |
5496 KB |
Output is correct |
17 |
Correct |
325 ms |
7304 KB |
Output is correct |
18 |
Correct |
196 ms |
6648 KB |
Output is correct |
19 |
Correct |
243 ms |
3960 KB |
Output is correct |
20 |
Correct |
257 ms |
5884 KB |
Output is correct |
21 |
Correct |
273 ms |
13816 KB |
Output is correct |
22 |
Correct |
327 ms |
14200 KB |
Output is correct |
23 |
Correct |
735 ms |
34836 KB |
Output is correct |
24 |
Correct |
473 ms |
29700 KB |
Output is correct |
25 |
Correct |
562 ms |
29608 KB |
Output is correct |
26 |
Correct |
1086 ms |
40608 KB |
Output is correct |
27 |
Correct |
1679 ms |
57020 KB |
Output is correct |
28 |
Correct |
231 ms |
28920 KB |
Output is correct |
29 |
Correct |
284 ms |
25080 KB |
Output is correct |
30 |
Correct |
318 ms |
27512 KB |
Output is correct |
31 |
Correct |
1094 ms |
35460 KB |
Output is correct |
32 |
Correct |
691 ms |
30724 KB |
Output is correct |
33 |
Correct |
374 ms |
27640 KB |
Output is correct |
34 |
Correct |
1030 ms |
40200 KB |
Output is correct |
35 |
Execution timed out |
2023 ms |
56772 KB |
Time limit exceeded |
36 |
Halted |
0 ms |
0 KB |
- |