# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
66936 | ekrem | Snake Escaping (JOI18_snake_escaping) | C++98 | 1253 ms | 35988 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 1600005
using namespace std;
int n, m, a[(1<<20)+10], dp[159323], prec[N], cvp[N], kaps[3000][200];
char c;
pair < int , int > q[1000002];
void hesapla(int);
bool kapsar(int uc, int iki){
// cout << uc << iki << endl;
if(kaps[uc][iki] != -1)
return kaps[uc][iki];
int yuc = uc;
int yiki = iki;
for(int i = 1; i <= 7; i++){
if(yuc%3 != 2 and yiki%2 != yuc%3)
return kaps[uc][iki] = 0;
yuc /= 3;
yiki /= 3;
}
return kaps[uc][iki] = 1;
}
int main() {
// freopen("in.txt", "r", stdin);
// freopen("out.txt", "w", stdout);
for(int i = 0; i < 1594323; i++){
int x = i, crp = 1, ckr = -1, say = 0, bit = 0;
while(x){
if(x%3 == 2){
ckr = crp;
break;
}
bit += (1<<say)*(x%3);
say++;
crp *= 3;
x /= 3;
}
if(ckr == -1)
prec[i] = -bit;
else
prec[i] = ckr;
// cout << i << " -> " << prec[i] << endl;
}
memset(dp, -1, sizeof dp);
memset(kaps, -1, sizeof kaps);
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, say = 0, son = 0, crp = 1;
for(int i = 1; i <= n; i++){
scanf(" %c" ,&c);
bit *= 3;
bit += (c == '?') ? 2 : c - '0';
}
// cout << bit << endl;
for(int say = 1; say <= 13; say++){
son += crp*(bit%3);
crp *= 3;
bit/=3;
}
// cout << bit << " -> " << son << endl;
q[i] = mp(bit, son);
// printf("%d\n",bul(bit, son));
}
// for(int i = 0; i < 2187 ; i++)
// for(int j = 0; j < (1<<7); j++)
// kapsar(i, j);
for(int i = 0; i < (1<<7); i++){
for(int j = 0; j < 159323; j++){
if(prec[j] <= 0)
dp[j] = a[i*(1<<13) - prec[j]];
else
dp[j] = dp[j - prec[j]] + dp[j - prec[j]*2];
}
for(int j = 1; j <= m; j++)
if(kapsar(q[j].st, i))
cvp[j] += dp[q[j].nd];
}
for(int i = 1; i <= m; i++)
printf("%d\n",cvp[i]);
return 0;
}
void hesapla(int bit){
int yed = bit, crp = 1, ckr = -1;
while(yed){
if(yed%3 == 2){
ckr = crp;
break;
}
crp *= 3;
yed /= 3;
}
prec[bit] = ckr;
if(ckr == -1){
yed = bit;
int say = 0, cvp = 0;
while(yed){
cvp += (1<<say)*(yed%3);
say++;
yed /= 3;
}
prec[bit] = -cvp;
}
}
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... |