Submission #331799

# Submission time Handle Problem Language Result Execution time Memory
331799 2020-11-30T07:13:52 Z daniel920712 Snake Escaping (JOI18_snake_escaping) C++14
75 / 100
2000 ms 22968 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;
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<=a&&b<=c)
        {
            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<=b&&a<=c)
        {
            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<=b&&c<=a)
        {
            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:42:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   42 |         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 384 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 384 KB Output is correct
9 Correct 1 ms 364 KB Output is correct
10 Correct 2 ms 364 KB Output is correct
11 Correct 489 ms 4588 KB Output is correct
12 Correct 497 ms 4076 KB Output is correct
13 Correct 604 ms 3564 KB Output is correct
14 Correct 860 ms 3348 KB Output is correct
15 Correct 589 ms 4460 KB Output is correct
16 Correct 784 ms 3564 KB Output is correct
17 Correct 699 ms 3564 KB Output is correct
18 Correct 415 ms 5360 KB Output is correct
19 Correct 445 ms 2412 KB Output is correct
20 Correct 488 ms 4076 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 384 KB Output is correct
9 Correct 1 ms 364 KB Output is correct
10 Correct 2 ms 364 KB Output is correct
11 Correct 489 ms 4588 KB Output is correct
12 Correct 497 ms 4076 KB Output is correct
13 Correct 604 ms 3564 KB Output is correct
14 Correct 860 ms 3348 KB Output is correct
15 Correct 589 ms 4460 KB Output is correct
16 Correct 784 ms 3564 KB Output is correct
17 Correct 699 ms 3564 KB Output is correct
18 Correct 415 ms 5360 KB Output is correct
19 Correct 445 ms 2412 KB Output is correct
20 Correct 488 ms 4076 KB Output is correct
21 Correct 597 ms 4636 KB Output is correct
22 Correct 644 ms 4716 KB Output is correct
23 Correct 922 ms 3692 KB Output is correct
24 Correct 1502 ms 3772 KB Output is correct
25 Correct 764 ms 5740 KB Output is correct
26 Correct 1233 ms 4012 KB Output is correct
27 Correct 1062 ms 3948 KB Output is correct
28 Correct 522 ms 6672 KB Output is correct
29 Correct 532 ms 2540 KB Output is correct
30 Correct 603 ms 4844 KB Output is correct
31 Correct 1014 ms 4576 KB Output is correct
32 Correct 1545 ms 4572 KB Output is correct
33 Correct 745 ms 3348 KB Output is correct
34 Correct 1286 ms 3548 KB Output is correct
35 Correct 1061 ms 4100 KB Output is correct
36 Correct 494 ms 2468 KB Output is correct
37 Correct 655 ms 4492 KB Output is correct
38 Correct 523 ms 2456 KB Output is correct
39 Correct 951 ms 3780 KB Output is correct
40 Correct 1469 ms 3632 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 384 KB Output is correct
9 Correct 1 ms 364 KB Output is correct
10 Correct 2 ms 364 KB Output is correct
11 Correct 122 ms 18028 KB Output is correct
12 Correct 106 ms 18028 KB Output is correct
13 Correct 188 ms 18028 KB Output is correct
14 Correct 412 ms 17988 KB Output is correct
15 Correct 121 ms 18156 KB Output is correct
16 Correct 300 ms 18020 KB Output is correct
17 Correct 275 ms 18028 KB Output is correct
18 Correct 102 ms 18156 KB Output is correct
19 Correct 108 ms 17900 KB Output is correct
20 Correct 102 ms 18028 KB Output is correct
21 Correct 179 ms 18156 KB Output is correct
22 Correct 359 ms 18028 KB Output is correct
23 Correct 132 ms 17900 KB Output is correct
24 Correct 291 ms 18028 KB Output is correct
25 Correct 237 ms 18156 KB Output is correct
26 Correct 102 ms 17900 KB Output is correct
27 Correct 96 ms 18028 KB Output is correct
28 Correct 92 ms 17900 KB Output is correct
29 Correct 168 ms 17900 KB Output is correct
30 Correct 329 ms 18092 KB Output is correct
31 Correct 116 ms 17900 KB Output is correct
32 Correct 320 ms 18028 KB Output is correct
33 Correct 234 ms 18028 KB Output is correct
34 Correct 83 ms 17900 KB Output is correct
35 Correct 189 ms 18092 KB Output is correct
36 Correct 192 ms 18028 KB Output is correct
37 Correct 193 ms 18156 KB Output is correct
38 Correct 186 ms 18028 KB Output is correct
39 Correct 188 ms 18028 KB Output is correct
40 Correct 190 ms 17964 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 384 KB Output is correct
9 Correct 1 ms 364 KB Output is correct
10 Correct 2 ms 364 KB Output is correct
11 Correct 489 ms 4588 KB Output is correct
12 Correct 497 ms 4076 KB Output is correct
13 Correct 604 ms 3564 KB Output is correct
14 Correct 860 ms 3348 KB Output is correct
15 Correct 589 ms 4460 KB Output is correct
16 Correct 784 ms 3564 KB Output is correct
17 Correct 699 ms 3564 KB Output is correct
18 Correct 415 ms 5360 KB Output is correct
19 Correct 445 ms 2412 KB Output is correct
20 Correct 488 ms 4076 KB Output is correct
21 Correct 597 ms 4636 KB Output is correct
22 Correct 644 ms 4716 KB Output is correct
23 Correct 922 ms 3692 KB Output is correct
24 Correct 1502 ms 3772 KB Output is correct
25 Correct 764 ms 5740 KB Output is correct
26 Correct 1233 ms 4012 KB Output is correct
27 Correct 1062 ms 3948 KB Output is correct
28 Correct 522 ms 6672 KB Output is correct
29 Correct 532 ms 2540 KB Output is correct
30 Correct 603 ms 4844 KB Output is correct
31 Correct 1014 ms 4576 KB Output is correct
32 Correct 1545 ms 4572 KB Output is correct
33 Correct 745 ms 3348 KB Output is correct
34 Correct 1286 ms 3548 KB Output is correct
35 Correct 1061 ms 4100 KB Output is correct
36 Correct 494 ms 2468 KB Output is correct
37 Correct 655 ms 4492 KB Output is correct
38 Correct 523 ms 2456 KB Output is correct
39 Correct 951 ms 3780 KB Output is correct
40 Correct 1469 ms 3632 KB Output is correct
41 Correct 122 ms 18028 KB Output is correct
42 Correct 106 ms 18028 KB Output is correct
43 Correct 188 ms 18028 KB Output is correct
44 Correct 412 ms 17988 KB Output is correct
45 Correct 121 ms 18156 KB Output is correct
46 Correct 300 ms 18020 KB Output is correct
47 Correct 275 ms 18028 KB Output is correct
48 Correct 102 ms 18156 KB Output is correct
49 Correct 108 ms 17900 KB Output is correct
50 Correct 102 ms 18028 KB Output is correct
51 Correct 179 ms 18156 KB Output is correct
52 Correct 359 ms 18028 KB Output is correct
53 Correct 132 ms 17900 KB Output is correct
54 Correct 291 ms 18028 KB Output is correct
55 Correct 237 ms 18156 KB Output is correct
56 Correct 102 ms 17900 KB Output is correct
57 Correct 96 ms 18028 KB Output is correct
58 Correct 92 ms 17900 KB Output is correct
59 Correct 168 ms 17900 KB Output is correct
60 Correct 329 ms 18092 KB Output is correct
61 Correct 116 ms 17900 KB Output is correct
62 Correct 320 ms 18028 KB Output is correct
63 Correct 234 ms 18028 KB Output is correct
64 Correct 83 ms 17900 KB Output is correct
65 Correct 189 ms 18092 KB Output is correct
66 Correct 192 ms 18028 KB Output is correct
67 Correct 193 ms 18156 KB Output is correct
68 Correct 186 ms 18028 KB Output is correct
69 Correct 188 ms 18028 KB Output is correct
70 Correct 190 ms 17964 KB Output is correct
71 Correct 927 ms 22884 KB Output is correct
72 Correct 935 ms 22968 KB Output is correct
73 Execution timed out 2054 ms 20844 KB Time limit exceeded
74 Halted 0 ms 0 KB -