Submission #331790

# Submission time Handle Problem Language Result Execution time Memory
331790 2020-11-30T06:53:08 Z daniel920712 Snake Escaping (JOI18_snake_escaping) C++14
75 / 100
2000 ms 36188 KB
#include <iostream>
#include <stdio.h>
#include <stdlib.h>
#include <vector>
#include <string.h>
#include <map>
#include <utility>
#include <algorithm>
#include <stack>
using namespace std;
char all[1148576];
char tt[25];
int con1[5][1100005];
int con2[5][1100005];
int ans=0;
int N;
void F(int x,int y,int z)
{
    if(x==N)
    {
        if(z%2==0) ans+=con1[N%2][y];
        else ans-=con1[N%2][y];
        return;
    }
    if(tt[x]=='1')
    {
        F(x+1,y+(1<<(N-x-1)),z);
        F(x+1,y,z+1);
    }
    else if(tt[x]=='0') F(x+1,y,z);
    else F(x+1,y+(1<<(N-x-1)),z);

}
void F2(int x,int y)
{
    if(x==N)
    {
        ans+=(all[y]-'0');
        return;
    }
    if(tt[x]=='?')
    {
        F2(x+1,y);
        F2(x+1,y+(1<<(N-x-1)));
    }
    else F2(x+1,y+(1<<(N-x-1))*(tt[x]-'0'));
}
void F3(int x,int y,int z)
{
    if(x==N)
    {
        if(z%2==0) ans+=con2[N%2][y];
        else ans-=con2[N%2][y];
        return;
    }
    if(tt[x]=='0')
    {
        F3(x+1,y+(1<<(N-x-1)),z+1);
        F3(x+1,y,z);
    }
    else if(tt[x]=='1') F3(x+1,y+(1<<(N-x-1)),z);
    else F3(x+1,y,z);

}
int main()
{
    int M,i,j,ok,a,b,c;
    scanf("%d %d",&N,&M);
    scanf("%s",all);
    for(i=0;i<(1<<N);i++) con1[0][i]=all[i]-'0';
    for(i=0;i<(1<<N);i++) con2[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];
            if(j&(1<<i)) con1[1-i%2][j]+=con1[i%2][j-(1<<i)];
        }
    }

    for(i=0;i<N;i++)
    {
        for(j=0;j<(1<<N);j++)
        {
            con2[1-i%2][j]=con2[i%2][j];
            if((j&(1<<i))==0) 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) F(0,0,0);
        else if(a<=b&&a<=c) F2(0,0);
        else F3(0,0,0);
        printf("%d\n",ans);

    }

	return 0;
}

Compilation message

snake_escaping.cpp: In function 'int main()':
snake_escaping.cpp:67:15: warning: unused variable 'ok' [-Wunused-variable]
   67 |     int M,i,j,ok,a,b,c;
      |               ^~
snake_escaping.cpp:68:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   68 |     scanf("%d %d",&N,&M);
      |     ~~~~~^~~~~~~~~~~~~~~
snake_escaping.cpp:69:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   69 |     scanf("%s",all);
      |     ~~~~~^~~~~~~~~~
snake_escaping.cpp:92:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   92 |         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 2 ms 364 KB Output is correct
7 Correct 2 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 1 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 2 ms 364 KB Output is correct
7 Correct 2 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 1 ms 364 KB Output is correct
11 Correct 313 ms 4460 KB Output is correct
12 Correct 358 ms 4084 KB Output is correct
13 Correct 437 ms 3436 KB Output is correct
14 Correct 530 ms 3436 KB Output is correct
15 Correct 394 ms 4484 KB Output is correct
16 Correct 477 ms 3664 KB Output is correct
17 Correct 468 ms 3564 KB Output is correct
18 Correct 257 ms 5356 KB Output is correct
19 Correct 284 ms 2500 KB Output is correct
20 Correct 372 ms 4204 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 2 ms 364 KB Output is correct
7 Correct 2 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 1 ms 364 KB Output is correct
11 Correct 313 ms 4460 KB Output is correct
12 Correct 358 ms 4084 KB Output is correct
13 Correct 437 ms 3436 KB Output is correct
14 Correct 530 ms 3436 KB Output is correct
15 Correct 394 ms 4484 KB Output is correct
16 Correct 477 ms 3664 KB Output is correct
17 Correct 468 ms 3564 KB Output is correct
18 Correct 257 ms 5356 KB Output is correct
19 Correct 284 ms 2500 KB Output is correct
20 Correct 372 ms 4204 KB Output is correct
21 Correct 397 ms 4844 KB Output is correct
22 Correct 403 ms 4716 KB Output is correct
23 Correct 533 ms 3640 KB Output is correct
24 Correct 862 ms 3564 KB Output is correct
25 Correct 484 ms 5572 KB Output is correct
26 Correct 665 ms 4056 KB Output is correct
27 Correct 651 ms 3988 KB Output is correct
28 Correct 302 ms 6764 KB Output is correct
29 Correct 327 ms 2668 KB Output is correct
30 Correct 415 ms 4716 KB Output is correct
31 Correct 625 ms 4588 KB Output is correct
32 Correct 832 ms 4688 KB Output is correct
33 Correct 450 ms 3532 KB Output is correct
34 Correct 694 ms 3564 KB Output is correct
35 Correct 681 ms 4092 KB Output is correct
36 Correct 284 ms 2668 KB Output is correct
37 Correct 381 ms 4736 KB Output is correct
38 Correct 326 ms 2540 KB Output is correct
39 Correct 547 ms 3692 KB Output is correct
40 Correct 623 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 2 ms 364 KB Output is correct
7 Correct 2 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 1 ms 364 KB Output is correct
11 Correct 95 ms 18028 KB Output is correct
12 Correct 122 ms 18028 KB Output is correct
13 Correct 136 ms 18028 KB Output is correct
14 Correct 189 ms 18028 KB Output is correct
15 Correct 109 ms 18156 KB Output is correct
16 Correct 233 ms 18004 KB Output is correct
17 Correct 172 ms 18060 KB Output is correct
18 Correct 83 ms 18212 KB Output is correct
19 Correct 94 ms 18048 KB Output is correct
20 Correct 98 ms 18028 KB Output is correct
21 Correct 142 ms 18176 KB Output is correct
22 Correct 211 ms 18028 KB Output is correct
23 Correct 109 ms 17900 KB Output is correct
24 Correct 174 ms 18156 KB Output is correct
25 Correct 170 ms 18048 KB Output is correct
26 Correct 83 ms 17900 KB Output is correct
27 Correct 93 ms 18028 KB Output is correct
28 Correct 110 ms 17900 KB Output is correct
29 Correct 129 ms 18028 KB Output is correct
30 Correct 149 ms 18028 KB Output is correct
31 Correct 102 ms 17900 KB Output is correct
32 Correct 217 ms 18028 KB Output is correct
33 Correct 164 ms 18028 KB Output is correct
34 Correct 86 ms 17900 KB Output is correct
35 Correct 146 ms 18028 KB Output is correct
36 Correct 138 ms 18028 KB Output is correct
37 Correct 142 ms 18028 KB Output is correct
38 Correct 179 ms 18176 KB Output is correct
39 Correct 145 ms 18156 KB Output is correct
40 Correct 144 ms 18028 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 2 ms 364 KB Output is correct
7 Correct 2 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 1 ms 364 KB Output is correct
11 Correct 313 ms 4460 KB Output is correct
12 Correct 358 ms 4084 KB Output is correct
13 Correct 437 ms 3436 KB Output is correct
14 Correct 530 ms 3436 KB Output is correct
15 Correct 394 ms 4484 KB Output is correct
16 Correct 477 ms 3664 KB Output is correct
17 Correct 468 ms 3564 KB Output is correct
18 Correct 257 ms 5356 KB Output is correct
19 Correct 284 ms 2500 KB Output is correct
20 Correct 372 ms 4204 KB Output is correct
21 Correct 397 ms 4844 KB Output is correct
22 Correct 403 ms 4716 KB Output is correct
23 Correct 533 ms 3640 KB Output is correct
24 Correct 862 ms 3564 KB Output is correct
25 Correct 484 ms 5572 KB Output is correct
26 Correct 665 ms 4056 KB Output is correct
27 Correct 651 ms 3988 KB Output is correct
28 Correct 302 ms 6764 KB Output is correct
29 Correct 327 ms 2668 KB Output is correct
30 Correct 415 ms 4716 KB Output is correct
31 Correct 625 ms 4588 KB Output is correct
32 Correct 832 ms 4688 KB Output is correct
33 Correct 450 ms 3532 KB Output is correct
34 Correct 694 ms 3564 KB Output is correct
35 Correct 681 ms 4092 KB Output is correct
36 Correct 284 ms 2668 KB Output is correct
37 Correct 381 ms 4736 KB Output is correct
38 Correct 326 ms 2540 KB Output is correct
39 Correct 547 ms 3692 KB Output is correct
40 Correct 623 ms 3564 KB Output is correct
41 Correct 95 ms 18028 KB Output is correct
42 Correct 122 ms 18028 KB Output is correct
43 Correct 136 ms 18028 KB Output is correct
44 Correct 189 ms 18028 KB Output is correct
45 Correct 109 ms 18156 KB Output is correct
46 Correct 233 ms 18004 KB Output is correct
47 Correct 172 ms 18060 KB Output is correct
48 Correct 83 ms 18212 KB Output is correct
49 Correct 94 ms 18048 KB Output is correct
50 Correct 98 ms 18028 KB Output is correct
51 Correct 142 ms 18176 KB Output is correct
52 Correct 211 ms 18028 KB Output is correct
53 Correct 109 ms 17900 KB Output is correct
54 Correct 174 ms 18156 KB Output is correct
55 Correct 170 ms 18048 KB Output is correct
56 Correct 83 ms 17900 KB Output is correct
57 Correct 93 ms 18028 KB Output is correct
58 Correct 110 ms 17900 KB Output is correct
59 Correct 129 ms 18028 KB Output is correct
60 Correct 149 ms 18028 KB Output is correct
61 Correct 102 ms 17900 KB Output is correct
62 Correct 217 ms 18028 KB Output is correct
63 Correct 164 ms 18028 KB Output is correct
64 Correct 86 ms 17900 KB Output is correct
65 Correct 146 ms 18028 KB Output is correct
66 Correct 138 ms 18028 KB Output is correct
67 Correct 142 ms 18028 KB Output is correct
68 Correct 179 ms 18176 KB Output is correct
69 Correct 145 ms 18156 KB Output is correct
70 Correct 144 ms 18028 KB Output is correct
71 Correct 662 ms 30640 KB Output is correct
72 Correct 686 ms 36188 KB Output is correct
73 Correct 1382 ms 34796 KB Output is correct
74 Execution timed out 2097 ms 34116 KB Time limit exceeded
75 Halted 0 ms 0 KB -