Submission #331803

# Submission time Handle Problem Language Result Execution time Memory
331803 2020-11-30T07:54:18 Z daniel920712 Snake Escaping (JOI18_snake_escaping) C++14
22 / 100
1533 ms 18156 KB
#include <iostream>
#include <stdio.h>
#include <stdlib.h>
#include <vector>
#include <string.h>
#include <map>
#include <utility>
#include <algorithm>
#include <stack>
#include <queue>
using namespace std;
char all[1148576];
char tt[25];
int con1[2][1100005];
int con2[2][1100005];
int ans=0;
int N,K=4;
queue < pair < pair < int , int > , int > > BFS;
int main()
{
    //freopen("05-05.txt","rt",stdin);
    //freopen("tt.txt","w+t",stdout);
    int M,i,j,ok,a,b,c,x,y,z;
    scanf("%d %d",&N,&M);
    scanf("%s",all);
    for(i=0;i<(1<<N);i++) con2[0][i]=con1[0][i]=all[i]-'0';
    for(i=0;i<N;i++)
    {
        for(j=0;j<(1<<N);j++)
        {
            con1[1-i%2][j]=con1[i%2][j];
            con2[1-i%2][j]=con2[i%2][j];
            if(j&(1<<i)) con1[1-i%2][j]+=con1[i%2][j-(1<<i)];
            else con2[1-i%2][j]+=con2[i%2][j+(1<<i)];
        }
    }
    while(M--)
    {
        scanf("%s",tt);
        ans=0;
        a=0;
        b=0;
        c=0;
        for(i=0;i<N;i++)
        {
            if(tt[i]=='?') a++;
            else if(tt[i]=='1') b++;
            else c++;
        }
        if(b<=K)
        {
            BFS.push(make_pair(make_pair(0,0),0));
            while(!BFS.empty())
            {
                x=BFS.front().first.first;
                y=BFS.front().first.second;
                z=BFS.front().second;
                BFS.pop();
                if(x==N)
                {
                    if(z==0) ans+=con1[N%2][y];
                    else ans-=con1[N%2][y];
                    continue;
                }
                if(tt[x]=='1')
                {
                    BFS.push(make_pair(make_pair(x+1,y+(1<<(N-x-1))),z));
                    BFS.push(make_pair(make_pair(x+1,y),z^1));
                }
                else if(tt[x]=='0') BFS.push(make_pair(make_pair(x+1,y),z));
                else BFS.push(make_pair(make_pair(x+1,y+(1<<(N-x-1))),z));
            }
        }
        else if(a<=K)
        {
            BFS.push(make_pair(make_pair(0,0),0));
            while(!BFS.empty())
            {
                x=BFS.front().first.first;
                y=BFS.front().first.second;
                z=BFS.front().second;
                BFS.pop();
                if(x==N)
                {
                    ans+=(all[y]-'0');
                    continue;
                }
                if(tt[x]=='?')
                {
                    BFS.push(make_pair(make_pair(x+1,y+(1<<(N-x-1))),z));
                    BFS.push(make_pair(make_pair(x+1,y),z));
                }
                else BFS.push(make_pair(make_pair(x+1,y+(1<<(N-x-1))*(tt[x]-'0')),z));
            }
        }
        else if(c<=K)
        {
            BFS.push(make_pair(make_pair(0,0),0));
            while(!BFS.empty())
            {
                x=BFS.front().first.first;
                y=BFS.front().first.second;
                z=BFS.front().second;
                BFS.pop();
                if(x==N)
                {
                    if(z==0) ans+=con2[N%2][y];
                    else ans-=con2[N%2][y];
                    continue;
                }
                if(tt[x]=='0')
                {
                    BFS.push(make_pair(make_pair(x+1,y+(1<<(N-x-1))),z^1));
                    BFS.push(make_pair(make_pair(x+1,y),z));
                }
                else if(tt[x]=='1') BFS.push(make_pair(make_pair(x+1,y+(1<<(N-x-1))),z));
                else BFS.push(make_pair(make_pair(x+1,y),z));
            }
        }
        printf("%d\n",ans);
    }
	return 0;
}

Compilation message

snake_escaping.cpp: In function 'int main()':
snake_escaping.cpp:23:15: warning: unused variable 'ok' [-Wunused-variable]
   23 |     int M,i,j,ok,a,b,c,x,y,z;
      |               ^~
snake_escaping.cpp:24:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   24 |     scanf("%d %d",&N,&M);
      |     ~~~~~^~~~~~~~~~~~~~~
snake_escaping.cpp:25:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   25 |     scanf("%s",all);
      |     ~~~~~^~~~~~~~~~
snake_escaping.cpp:39:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   39 |         scanf("%s",tt);
      |         ~~~~~^~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 1 ms 364 KB Output is correct
6 Correct 1 ms 364 KB Output is correct
7 Correct 1 ms 364 KB Output is correct
8 Correct 1 ms 364 KB Output is correct
9 Correct 1 ms 364 KB Output is correct
10 Correct 2 ms 364 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 1 ms 364 KB Output is correct
6 Correct 1 ms 364 KB Output is correct
7 Correct 1 ms 364 KB Output is correct
8 Correct 1 ms 364 KB Output is correct
9 Correct 1 ms 364 KB Output is correct
10 Correct 2 ms 364 KB Output is correct
11 Correct 449 ms 4504 KB Output is correct
12 Correct 541 ms 4076 KB Output is correct
13 Correct 798 ms 3384 KB Output is correct
14 Correct 857 ms 3564 KB Output is correct
15 Correct 741 ms 4564 KB Output is correct
16 Correct 898 ms 3692 KB Output is correct
17 Correct 881 ms 3692 KB Output is correct
18 Correct 412 ms 5356 KB Output is correct
19 Correct 420 ms 2412 KB Output is correct
20 Correct 865 ms 4332 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 1 ms 364 KB Output is correct
6 Correct 1 ms 364 KB Output is correct
7 Correct 1 ms 364 KB Output is correct
8 Correct 1 ms 364 KB Output is correct
9 Correct 1 ms 364 KB Output is correct
10 Correct 2 ms 364 KB Output is correct
11 Correct 449 ms 4504 KB Output is correct
12 Correct 541 ms 4076 KB Output is correct
13 Correct 798 ms 3384 KB Output is correct
14 Correct 857 ms 3564 KB Output is correct
15 Correct 741 ms 4564 KB Output is correct
16 Correct 898 ms 3692 KB Output is correct
17 Correct 881 ms 3692 KB Output is correct
18 Correct 412 ms 5356 KB Output is correct
19 Correct 420 ms 2412 KB Output is correct
20 Correct 865 ms 4332 KB Output is correct
21 Correct 611 ms 4728 KB Output is correct
22 Correct 602 ms 4844 KB Output is correct
23 Correct 1035 ms 3724 KB Output is correct
24 Correct 1495 ms 3824 KB Output is correct
25 Correct 936 ms 5516 KB Output is correct
26 Correct 1263 ms 4176 KB Output is correct
27 Correct 1192 ms 3980 KB Output is correct
28 Correct 451 ms 6532 KB Output is correct
29 Correct 502 ms 2604 KB Output is correct
30 Correct 776 ms 4652 KB Output is correct
31 Correct 1053 ms 4576 KB Output is correct
32 Correct 1533 ms 4632 KB Output is correct
33 Correct 878 ms 3436 KB Output is correct
34 Correct 1368 ms 3716 KB Output is correct
35 Correct 1141 ms 4076 KB Output is correct
36 Correct 468 ms 2540 KB Output is correct
37 Correct 572 ms 4460 KB Output is correct
38 Correct 632 ms 2540 KB Output is correct
39 Correct 1016 ms 3692 KB Output is correct
40 Correct 1423 ms 3564 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 1 ms 364 KB Output is correct
6 Correct 1 ms 364 KB Output is correct
7 Correct 1 ms 364 KB Output is correct
8 Correct 1 ms 364 KB Output is correct
9 Correct 1 ms 364 KB Output is correct
10 Correct 2 ms 364 KB Output is correct
11 Correct 94 ms 18028 KB Output is correct
12 Correct 97 ms 18156 KB Output is correct
13 Incorrect 156 ms 18028 KB Output isn't correct
14 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 1 ms 364 KB Output is correct
6 Correct 1 ms 364 KB Output is correct
7 Correct 1 ms 364 KB Output is correct
8 Correct 1 ms 364 KB Output is correct
9 Correct 1 ms 364 KB Output is correct
10 Correct 2 ms 364 KB Output is correct
11 Correct 449 ms 4504 KB Output is correct
12 Correct 541 ms 4076 KB Output is correct
13 Correct 798 ms 3384 KB Output is correct
14 Correct 857 ms 3564 KB Output is correct
15 Correct 741 ms 4564 KB Output is correct
16 Correct 898 ms 3692 KB Output is correct
17 Correct 881 ms 3692 KB Output is correct
18 Correct 412 ms 5356 KB Output is correct
19 Correct 420 ms 2412 KB Output is correct
20 Correct 865 ms 4332 KB Output is correct
21 Correct 611 ms 4728 KB Output is correct
22 Correct 602 ms 4844 KB Output is correct
23 Correct 1035 ms 3724 KB Output is correct
24 Correct 1495 ms 3824 KB Output is correct
25 Correct 936 ms 5516 KB Output is correct
26 Correct 1263 ms 4176 KB Output is correct
27 Correct 1192 ms 3980 KB Output is correct
28 Correct 451 ms 6532 KB Output is correct
29 Correct 502 ms 2604 KB Output is correct
30 Correct 776 ms 4652 KB Output is correct
31 Correct 1053 ms 4576 KB Output is correct
32 Correct 1533 ms 4632 KB Output is correct
33 Correct 878 ms 3436 KB Output is correct
34 Correct 1368 ms 3716 KB Output is correct
35 Correct 1141 ms 4076 KB Output is correct
36 Correct 468 ms 2540 KB Output is correct
37 Correct 572 ms 4460 KB Output is correct
38 Correct 632 ms 2540 KB Output is correct
39 Correct 1016 ms 3692 KB Output is correct
40 Correct 1423 ms 3564 KB Output is correct
41 Correct 94 ms 18028 KB Output is correct
42 Correct 97 ms 18156 KB Output is correct
43 Incorrect 156 ms 18028 KB Output isn't correct
44 Halted 0 ms 0 KB -