Submission #331801

# Submission time Handle Problem Language Result Execution time Memory
331801 2020-11-30T07:15:21 Z daniel920712 Snake Escaping (JOI18_snake_escaping) C++14
65 / 100
2000 ms 18176 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<=6)
        {
            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<=6)
        {
            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<=6)
        {
            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 3 ms 364 KB Output is correct
2 Correct 2 ms 364 KB Output is correct
3 Correct 2 ms 364 KB Output is correct
4 Correct 2 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 492 KB Output is correct
8 Correct 1 ms 364 KB Output is correct
9 Correct 2 ms 364 KB Output is correct
10 Correct 2 ms 364 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 364 KB Output is correct
2 Correct 2 ms 364 KB Output is correct
3 Correct 2 ms 364 KB Output is correct
4 Correct 2 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 492 KB Output is correct
8 Correct 1 ms 364 KB Output is correct
9 Correct 2 ms 364 KB Output is correct
10 Correct 2 ms 364 KB Output is correct
11 Correct 1818 ms 4544 KB Output is correct
12 Correct 494 ms 4204 KB Output is correct
13 Correct 826 ms 3464 KB Output is correct
14 Correct 861 ms 3564 KB Output is correct
15 Correct 704 ms 4460 KB Output is correct
16 Correct 1186 ms 3564 KB Output is correct
17 Correct 1208 ms 3916 KB Output is correct
18 Correct 387 ms 5464 KB Output is correct
19 Correct 1770 ms 2700 KB Output is correct
20 Correct 1555 ms 4204 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 364 KB Output is correct
2 Correct 2 ms 364 KB Output is correct
3 Correct 2 ms 364 KB Output is correct
4 Correct 2 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 492 KB Output is correct
8 Correct 1 ms 364 KB Output is correct
9 Correct 2 ms 364 KB Output is correct
10 Correct 2 ms 364 KB Output is correct
11 Correct 1818 ms 4544 KB Output is correct
12 Correct 494 ms 4204 KB Output is correct
13 Correct 826 ms 3464 KB Output is correct
14 Correct 861 ms 3564 KB Output is correct
15 Correct 704 ms 4460 KB Output is correct
16 Correct 1186 ms 3564 KB Output is correct
17 Correct 1208 ms 3916 KB Output is correct
18 Correct 387 ms 5464 KB Output is correct
19 Correct 1770 ms 2700 KB Output is correct
20 Correct 1555 ms 4204 KB Output is correct
21 Execution timed out 2086 ms 2824 KB Time limit exceeded
22 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 3 ms 364 KB Output is correct
2 Correct 2 ms 364 KB Output is correct
3 Correct 2 ms 364 KB Output is correct
4 Correct 2 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 492 KB Output is correct
8 Correct 1 ms 364 KB Output is correct
9 Correct 2 ms 364 KB Output is correct
10 Correct 2 ms 364 KB Output is correct
11 Correct 115 ms 18028 KB Output is correct
12 Correct 96 ms 18028 KB Output is correct
13 Correct 211 ms 17900 KB Output is correct
14 Correct 353 ms 18028 KB Output is correct
15 Correct 160 ms 18104 KB Output is correct
16 Correct 302 ms 18028 KB Output is correct
17 Correct 252 ms 18028 KB Output is correct
18 Correct 84 ms 18156 KB Output is correct
19 Correct 97 ms 18028 KB Output is correct
20 Correct 122 ms 18028 KB Output is correct
21 Correct 212 ms 18156 KB Output is correct
22 Correct 367 ms 18156 KB Output is correct
23 Correct 154 ms 17900 KB Output is correct
24 Correct 315 ms 18028 KB Output is correct
25 Correct 251 ms 17988 KB Output is correct
26 Correct 83 ms 17900 KB Output is correct
27 Correct 98 ms 18120 KB Output is correct
28 Correct 103 ms 17900 KB Output is correct
29 Correct 229 ms 18028 KB Output is correct
30 Correct 312 ms 18028 KB Output is correct
31 Correct 162 ms 17900 KB Output is correct
32 Correct 386 ms 18028 KB Output is correct
33 Correct 253 ms 18028 KB Output is correct
34 Correct 82 ms 17900 KB Output is correct
35 Correct 215 ms 18176 KB Output is correct
36 Correct 209 ms 18156 KB Output is correct
37 Correct 209 ms 18028 KB Output is correct
38 Correct 211 ms 18028 KB Output is correct
39 Correct 207 ms 18028 KB Output is correct
40 Correct 211 ms 18028 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 364 KB Output is correct
2 Correct 2 ms 364 KB Output is correct
3 Correct 2 ms 364 KB Output is correct
4 Correct 2 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 492 KB Output is correct
8 Correct 1 ms 364 KB Output is correct
9 Correct 2 ms 364 KB Output is correct
10 Correct 2 ms 364 KB Output is correct
11 Correct 1818 ms 4544 KB Output is correct
12 Correct 494 ms 4204 KB Output is correct
13 Correct 826 ms 3464 KB Output is correct
14 Correct 861 ms 3564 KB Output is correct
15 Correct 704 ms 4460 KB Output is correct
16 Correct 1186 ms 3564 KB Output is correct
17 Correct 1208 ms 3916 KB Output is correct
18 Correct 387 ms 5464 KB Output is correct
19 Correct 1770 ms 2700 KB Output is correct
20 Correct 1555 ms 4204 KB Output is correct
21 Execution timed out 2086 ms 2824 KB Time limit exceeded
22 Halted 0 ms 0 KB -