# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
66868 | ekrem | Snake Escaping (JOI18_snake_escaping) | C++98 | 978 ms | 14316 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
#define st first
#define nd second
#define mp make_pair
#define pb push_back
#define N 1000005
using namespace std;
int n, m, a[N], dp[N];
char c;
int f(int bit){
if(dp[bit] != -1)
return dp[bit];
int yed = bit, crp = 1, ckr = -1;
while(yed){
if(yed%3 == 2){
ckr = crp;
break;
}
crp *= 3;
yed /= 3;
}
if(ckr == -1){
yed = bit;
int say = 0, cvp = 0;
while(yed){
cvp += (1<<say)*(yed%3);
say++;
yed /= 3;
}
return dp[bit] = a[cvp];
}
return dp[bit] = f(bit - ckr) + f(bit - ckr - ckr);
}
int main() {
// freopen("in.txt", "r", stdin);
// freopen("out.txt", "w", stdout);
memset(dp, -1, sizeof dp);
scanf("%d %d",&n ,&m);
for(int i = 0; i < (1<<n); i++){
scanf(" %c",&c);
a[i] = c - '0';
}
for(int i = 1; i <= m; i++){
int bit = 0;
for(int i = 1; i <= n; i++){
scanf(" %c" ,&c);
bit *= 3;
bit += (c == '?') ? 2 : c - '0';
}
printf("%d\n",f(bit));
}
return 0;
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |