# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
68375 | IvanC | Snake Escaping (JOI18_snake_escaping) | C++14 | 327 ms | 66560 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>
using namespace std;
const int MAXL = 15;
const int MAXN = (1 << 13) + 3;
const int MAXV = 1594326;
char entrada[MAXL];
int pot2[MAXL],pot3[MAXL];
int tab[MAXV],valor[MAXN];
int L,Q;
void brute(int pos,int base3,int base2,int first_2){
if(pos == L){
if(first_2 == -1){
tab[base3] = valor[base2];
}
else{
tab[base3] = tab[base3 - pot3[first_2]] + tab[base3 - 2*pot3[first_2]];
}
return;
}
brute(pos + 1, base3, base2, first_2 );
brute(pos + 1, base3 + pot3[pos], base2 + pot2[pos], first_2 );
brute(pos + 1, base3 + 2*pot3[pos], base2, (first_2 != -1) ? (first_2) : (pos) );
}
int main(){
scanf("%d %d",&L,&Q);
assert(L <= 13);
for(int i = 0;i<(1 << L);i++){
char c;
scanf(" %c",&c);
valor[i] = (c - '0');
}
pot3[0] = pot2[0] = 1;
for(int i = 1;i<L;i++){
pot3[i] = pot3[i-1]*3;
pot2[i] = pot2[i-1]*2;
}
brute(0,0,0,-1);
for(int q = 0;q<Q;q++){
int numero = 0;
scanf("%s",entrada);
for(int i = 0,j = L - 1;i<L;i++,j--){
int davez = entrada[i] - '0';
if(entrada[i] == '?') davez = 2;
numero += pot3[j]*davez;
}
printf("%d\n",tab[numero]);
}
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... |