# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
66943 | hamzqq9 | Snake Escaping (JOI18_snake_escaping) | C++14 | 1602 ms | 29492 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include<bits/stdc++.h>
#define st first
#define nd second
#define pb push_back
#define ppb pop_back
#define umax(x,y) x=max(x,y)
#define umin(x,y) x=min(x,y)
#define ll long long
#define ii pair<int,int>
#define iii pair<int,ii>
#define sz(x) ((int) x.size())
#define orta ((bas+son)>>1)
#define all(x) x.begin(),x.end()
#define dbgs(x) cerr<<(#x)<<" --> "<<(x)<<" "
#define dbg(x) cerr<<(#x)<<" --> "<<(x)<<endl;getchar()
#define pw(x) (1<<(x))
#define inf 100000000000000
#define MOD 1000000007
#define N 3005
#define MAX 10000006
#define LOG 22
#define L 7
#define R 13
using namespace std;
int n,q,l;
int cnt[1594325],ans[pw(20)+5];
int po3[20],po2[25],pos[1594325];
char val[pw(20)+5],s[pw(20)+5];
bool oops[1594325],inc[2188][129];
int Right[pw(20)+5];
short Left[pw(20)+5];
void do_dp(int value) {
for(int i=0;i<1594323;i++) {
if(oops[i]) cnt[i]=val[value*po2[R]+pos[i]];
else cnt[i]=cnt[i-po3[pos[i]]]+cnt[i-2*po3[pos[i]]];
}
}
void pre_cal() {
oops[0]=oops[1]=true;
pos[1]=1;
for(int i=3;i<1594323;i++) {
if(i%3==2) pos[i]=0;
else {
int val=i/3;
if(oops[val]) {
oops[i]=true;
pos[i]=pos[val]*2+i%3;
}
else {
pos[i]=pos[val]+1;
}
}
}
for(int i=0;i<2187;i++) {
if(i<3) {
for(int j=0;j<128;j++) {
if(i==2 || j%3==i) inc[i][j]=true;
}
continue ;
}
for(int j=0;j<128;j++) {
if(i%3==2 || i%3==j%2) inc[i][j]=inc[i/3][j/2];
}
}
}
int get_value(int bas,int son) {
int res=0;
for(int i=bas;i<=son;i++) {
res=res*3+(s[i]=='?'?2:(s[i]-'0'));
}
return res;
}
int main() {
//freopen("input.txt","r",stdin);
po3[0]=po2[0]=1;
for(int i=1;i<=15;i++) po3[i]=po3[i-1]*3;
for(int i=1;i<=20;i++) po2[i]=po2[i-1]*2;
scanf("%d %d",&l,&q);
n=po2[l];
scanf("%s",s);
for(int i=0;i<n;i++) val[i]=s[i]-'0';
for(int i=1;i<=q;i++) {
scanf("%s",s+20-l);
for(int i=0;i<20-l;i++) s[i]='0';
Right[i]=get_value(L,19);
Left[i]=get_value(0,L-1);
}
pre_cal();
for(int i=0;i<po2[L];i++) {
do_dp(i);
for(int j=1;j<=q;j++) {
if(inc[Left[j]][i]) {
ans[j]+=cnt[Right[j]];
}
}
}
for(int i=1;i<=q;i++) printf("%d\n",ans[i]);
}
컴파일 시 표준 에러 (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... |