#include <bits/stdc++.h>
using namespace std;
#define scd(x) scanf("%d", &x)
#define sclld(x) scanf("%lld", &x)
#define frange(i, n) for(int i=0; i<n; i++)
#define forr(i, l, r) for(int i=l; i<r; i++)
#define all(vec) vec.begin(), vec.end()
#define mp make_pair
#define pb push_back
#define f first
#define s second
typedef long long lli;
typedef vector<int> vi;
typedef pair<int, int> pii;
typedef vector<pii> vii;
typedef vector<lli> vll;
typedef vector<vi> vvi;
typedef vector<bool> vb;
typedef set<int> seti;
void usaco() {
freopen("/media/hariaakash646/785EF1075EF0BF46/CompetitiveProgramming/input.in", "r", stdin);
}
int main() {
// usaco();
int l, q;
cin >> l >> q;
string str;
cin >> str;
map<int, int> mv;
frange(i, 1<<l) {
mv[i] = str[i] - '0';
}
// int v = 1;
// frange(i, l) v *= 3;
// vi tot(v);
// frange(i, v) {
// int li=0;
// int r = 0;
// int x = 0;
// int k = i;
// bool done = false;
// frange(j, l) {
// if(k % 3 == 1) {
// x += pow(3, j);
// li += pow(3, j);
// r += pow(3, j);
// }
// else if(k % 3 == 2) {
// x += pow(3, j) * 2;
// if(!done)
// {r += pow(3, j); done = true;}
// else {
// li += pow(3, j) * 2;;
// r += pow(3, j) * 2;
// }
// }
// k /= 3;
// }
// k = i;
// if(!done) {
// int x2 = 0;
// frange(j, l) {
// if(k % 3 == 1) {
// x2 += (1<<j);
// }
// k /= 3;
// }
// tot[x] = mv[x2];
// }
// else {
// cout << x << " " << li << " " << r << "\n";
// tot[x] = tot[li] + tot[r];
// }
// }
frange(_, q) {
string str;
cin >> str;
// int v = 0;
// frange(i, j) {
// if(str[i] == '1') v += pow(3, i);
// else if(str[i] == '?') v += 2*pow(3, i);
// }
int to = 0;
frange(i, 1<<l) {
bool done = true;
frange(j, l) {
if(str[j] == '?') continue;
else {
if(bool(str[j] - '0') != bool(i&(1<<(l-j-1)))) done = false;
}
}
if(done) to += mv[i];
}
// cout << str << " " << v << " ";
cout << to << "\n";
}
}
Compilation message
snake_escaping.cpp: In function 'void usaco()':
snake_escaping.cpp:25:9: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
25 | freopen("/media/hariaakash646/785EF1075EF0BF46/CompetitiveProgramming/input.in", "r", stdin);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
14 ms |
344 KB |
Output is correct |
2 |
Correct |
15 ms |
348 KB |
Output is correct |
3 |
Correct |
14 ms |
348 KB |
Output is correct |
4 |
Correct |
13 ms |
444 KB |
Output is correct |
5 |
Correct |
16 ms |
348 KB |
Output is correct |
6 |
Correct |
13 ms |
344 KB |
Output is correct |
7 |
Correct |
14 ms |
348 KB |
Output is correct |
8 |
Correct |
41 ms |
348 KB |
Output is correct |
9 |
Correct |
12 ms |
348 KB |
Output is correct |
10 |
Correct |
19 ms |
440 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
14 ms |
344 KB |
Output is correct |
2 |
Correct |
15 ms |
348 KB |
Output is correct |
3 |
Correct |
14 ms |
348 KB |
Output is correct |
4 |
Correct |
13 ms |
444 KB |
Output is correct |
5 |
Correct |
16 ms |
348 KB |
Output is correct |
6 |
Correct |
13 ms |
344 KB |
Output is correct |
7 |
Correct |
14 ms |
348 KB |
Output is correct |
8 |
Correct |
41 ms |
348 KB |
Output is correct |
9 |
Correct |
12 ms |
348 KB |
Output is correct |
10 |
Correct |
19 ms |
440 KB |
Output is correct |
11 |
Execution timed out |
2029 ms |
2772 KB |
Time limit exceeded |
12 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
14 ms |
344 KB |
Output is correct |
2 |
Correct |
15 ms |
348 KB |
Output is correct |
3 |
Correct |
14 ms |
348 KB |
Output is correct |
4 |
Correct |
13 ms |
444 KB |
Output is correct |
5 |
Correct |
16 ms |
348 KB |
Output is correct |
6 |
Correct |
13 ms |
344 KB |
Output is correct |
7 |
Correct |
14 ms |
348 KB |
Output is correct |
8 |
Correct |
41 ms |
348 KB |
Output is correct |
9 |
Correct |
12 ms |
348 KB |
Output is correct |
10 |
Correct |
19 ms |
440 KB |
Output is correct |
11 |
Execution timed out |
2029 ms |
2772 KB |
Time limit exceeded |
12 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
14 ms |
344 KB |
Output is correct |
2 |
Correct |
15 ms |
348 KB |
Output is correct |
3 |
Correct |
14 ms |
348 KB |
Output is correct |
4 |
Correct |
13 ms |
444 KB |
Output is correct |
5 |
Correct |
16 ms |
348 KB |
Output is correct |
6 |
Correct |
13 ms |
344 KB |
Output is correct |
7 |
Correct |
14 ms |
348 KB |
Output is correct |
8 |
Correct |
41 ms |
348 KB |
Output is correct |
9 |
Correct |
12 ms |
348 KB |
Output is correct |
10 |
Correct |
19 ms |
440 KB |
Output is correct |
11 |
Execution timed out |
2041 ms |
51780 KB |
Time limit exceeded |
12 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
14 ms |
344 KB |
Output is correct |
2 |
Correct |
15 ms |
348 KB |
Output is correct |
3 |
Correct |
14 ms |
348 KB |
Output is correct |
4 |
Correct |
13 ms |
444 KB |
Output is correct |
5 |
Correct |
16 ms |
348 KB |
Output is correct |
6 |
Correct |
13 ms |
344 KB |
Output is correct |
7 |
Correct |
14 ms |
348 KB |
Output is correct |
8 |
Correct |
41 ms |
348 KB |
Output is correct |
9 |
Correct |
12 ms |
348 KB |
Output is correct |
10 |
Correct |
19 ms |
440 KB |
Output is correct |
11 |
Execution timed out |
2029 ms |
2772 KB |
Time limit exceeded |
12 |
Halted |
0 ms |
0 KB |
- |