# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
80247 | Bodo171 | Snake Escaping (JOI18_snake_escaping) | C++14 | 963 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 <cstdio>
using namespace std;
const int nmax=(1<<20)+5;
char s[22],str[nmax];
char t;
char pc[nmax];
int sub[nmax],supra[nmax];
int l,q,i,j,m0,m1,mq,ans,cnt;
char mn;
bool brk;
int main()
{
//freopen("data.in","r",stdin);
scanf("%d%d",&l,&q);
scanf("%s",&str);
for(i=0;i<(1<<l);i++)
{
if(i!=0)
pc[i]=pc[(i&(i-1))]+1;
sub[i]=supra[i]=str[i]=str[i]-'0';
}
for(i=0;i<l;i++)
for(j=0;j<(1<<l);j++)
if(((1<<i)&j))
sub[j]+=sub[(j^(1<<i))];
else supra[j]+=supra[(j^(1<<i))];
for(cnt=1;cnt<=q;cnt++)
{
scanf("%s",&s);
m0=m1=mq=0;
for(j=l-1;j>=0;j--)
{
t=s[l-1-j];
if(t=='0') m0|=(1<<j);
else if(t=='1') m1|=(1<<j);
else mq|=(1<<j);
}
mn=pc[m0];
if(pc[m1]<mn) mn=pc[m1];
if(pc[mq]<mn) mn=pc[mq];
ans=0;brk=0;
if(mn==pc[m0])
{
ans=supra[m1];
i=m0;
while(i!=0)
{
if((pc[i]&1)) ans-=supra[(i|m1)];
else ans+=supra[(i|m1)];
i=((i-1)&m0);
}
}
else
{
if(mn==pc[m1])
{
i=m1;
while(!brk)
{
if(i==0)
brk=1;
if(((pc[m1]-pc[i])&1)) ans-=sub[(i|mq)];
else ans+=sub[(i|mq)];
i=((i-1)&m1);
}
}
else
{
i=mq;
while(!brk)
{
ans+=(int)str[(m1|i)];
if(i==0)
brk=1;
i=((i-1)&mq);
}
}
}
printf("%d\n",ans);
}
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... |