답안 #331789

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
331789 2020-11-30T06:47:32 Z daniel920712 Snake Escaping (JOI18_snake_escaping) C++14
75 / 100
2000 ms 16476 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 con[5][1100005];
int ans=0;
int N;
void F(int x,int y,int z)
{
    if(x==N)
    {
        if(z%2==0) ans+=con[N%2][y];
        else ans-=con[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'));
}
int main()
{
    int M,i,j,ok,a,b;
    scanf("%d %d",&N,&M);
    scanf("%s",all);
    for(i=0;i<(1<<N);i++) con[0][i]=all[i]-'0';
    for(i=0;i<N;i++)
    {
        for(j=0;j<(1<<N);j++)
        {
            con[1-i%2][j]=con[i%2][j];
            if(j&(1<<i)) con[1-i%2][j]+=con[i%2][j-(1<<i)];
        }
    }
    while(M--)
    {
        scanf("%s",tt);
        ans=0;
        a=0;
        b=0;
        for(i=0;i<N;i++)
        {
            if(tt[i]=='?') a++;
            else b++;
        }
        if(a>b) F(0,0,0);
        else F2(0,0);
        printf("%d\n",ans);

    }

	return 0;
}

Compilation message

snake_escaping.cpp: In function 'int main()':
snake_escaping.cpp:49:15: warning: unused variable 'ok' [-Wunused-variable]
   49 |     int M,i,j,ok,a,b;
      |               ^~
snake_escaping.cpp:50:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   50 |     scanf("%d %d",&N,&M);
      |     ~~~~~^~~~~~~~~~~~~~~
snake_escaping.cpp:51:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   51 |     scanf("%s",all);
      |     ~~~~~^~~~~~~~~~
snake_escaping.cpp:63:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   63 |         scanf("%s",tt);
      |         ~~~~~^~~~~~~~~
# 결과 실행 시간 메모리 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 1 ms 364 KB Output is correct
# 결과 실행 시간 메모리 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 1 ms 364 KB Output is correct
11 Correct 670 ms 4392 KB Output is correct
12 Correct 522 ms 4084 KB Output is correct
13 Correct 368 ms 3436 KB Output is correct
14 Correct 370 ms 3568 KB Output is correct
15 Correct 413 ms 4332 KB Output is correct
16 Correct 522 ms 3596 KB Output is correct
17 Correct 435 ms 3584 KB Output is correct
18 Correct 259 ms 5484 KB Output is correct
19 Correct 240 ms 2368 KB Output is correct
20 Correct 566 ms 4204 KB Output is correct
# 결과 실행 시간 메모리 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 1 ms 364 KB Output is correct
11 Correct 670 ms 4392 KB Output is correct
12 Correct 522 ms 4084 KB Output is correct
13 Correct 368 ms 3436 KB Output is correct
14 Correct 370 ms 3568 KB Output is correct
15 Correct 413 ms 4332 KB Output is correct
16 Correct 522 ms 3596 KB Output is correct
17 Correct 435 ms 3584 KB Output is correct
18 Correct 259 ms 5484 KB Output is correct
19 Correct 240 ms 2368 KB Output is correct
20 Correct 566 ms 4204 KB Output is correct
21 Correct 1232 ms 4460 KB Output is correct
22 Correct 643 ms 4588 KB Output is correct
23 Correct 594 ms 3564 KB Output is correct
24 Correct 637 ms 3436 KB Output is correct
25 Correct 547 ms 5484 KB Output is correct
26 Correct 716 ms 3948 KB Output is correct
27 Correct 690 ms 3820 KB Output is correct
28 Correct 280 ms 6380 KB Output is correct
29 Correct 268 ms 2540 KB Output is correct
30 Correct 1069 ms 4608 KB Output is correct
31 Correct 1084 ms 4676 KB Output is correct
32 Correct 794 ms 4460 KB Output is correct
33 Correct 447 ms 3348 KB Output is correct
34 Correct 577 ms 3636 KB Output is correct
35 Correct 688 ms 4076 KB Output is correct
36 Correct 260 ms 2540 KB Output is correct
37 Correct 1082 ms 4792 KB Output is correct
38 Correct 260 ms 2668 KB Output is correct
39 Correct 569 ms 3564 KB Output is correct
40 Correct 602 ms 3564 KB Output is correct
# 결과 실행 시간 메모리 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 1 ms 364 KB Output is correct
11 Correct 543 ms 11892 KB Output is correct
12 Correct 222 ms 12012 KB Output is correct
13 Correct 110 ms 11756 KB Output is correct
14 Correct 181 ms 11776 KB Output is correct
15 Correct 93 ms 11912 KB Output is correct
16 Correct 190 ms 11884 KB Output is correct
17 Correct 183 ms 11888 KB Output is correct
18 Correct 58 ms 12012 KB Output is correct
19 Correct 63 ms 11756 KB Output is correct
20 Correct 338 ms 11884 KB Output is correct
21 Correct 517 ms 12012 KB Output is correct
22 Correct 163 ms 11884 KB Output is correct
23 Correct 86 ms 11756 KB Output is correct
24 Correct 127 ms 11824 KB Output is correct
25 Correct 177 ms 11884 KB Output is correct
26 Correct 58 ms 11756 KB Output is correct
27 Correct 534 ms 12012 KB Output is correct
28 Correct 57 ms 11756 KB Output is correct
29 Correct 114 ms 11804 KB Output is correct
30 Correct 125 ms 11884 KB Output is correct
31 Correct 83 ms 11884 KB Output is correct
32 Correct 196 ms 11884 KB Output is correct
33 Correct 190 ms 11884 KB Output is correct
34 Correct 59 ms 11756 KB Output is correct
35 Correct 192 ms 11884 KB Output is correct
36 Correct 195 ms 11884 KB Output is correct
37 Correct 188 ms 11884 KB Output is correct
38 Correct 182 ms 11884 KB Output is correct
39 Correct 226 ms 11884 KB Output is correct
40 Correct 183 ms 11884 KB Output is correct
# 결과 실행 시간 메모리 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 1 ms 364 KB Output is correct
11 Correct 670 ms 4392 KB Output is correct
12 Correct 522 ms 4084 KB Output is correct
13 Correct 368 ms 3436 KB Output is correct
14 Correct 370 ms 3568 KB Output is correct
15 Correct 413 ms 4332 KB Output is correct
16 Correct 522 ms 3596 KB Output is correct
17 Correct 435 ms 3584 KB Output is correct
18 Correct 259 ms 5484 KB Output is correct
19 Correct 240 ms 2368 KB Output is correct
20 Correct 566 ms 4204 KB Output is correct
21 Correct 1232 ms 4460 KB Output is correct
22 Correct 643 ms 4588 KB Output is correct
23 Correct 594 ms 3564 KB Output is correct
24 Correct 637 ms 3436 KB Output is correct
25 Correct 547 ms 5484 KB Output is correct
26 Correct 716 ms 3948 KB Output is correct
27 Correct 690 ms 3820 KB Output is correct
28 Correct 280 ms 6380 KB Output is correct
29 Correct 268 ms 2540 KB Output is correct
30 Correct 1069 ms 4608 KB Output is correct
31 Correct 1084 ms 4676 KB Output is correct
32 Correct 794 ms 4460 KB Output is correct
33 Correct 447 ms 3348 KB Output is correct
34 Correct 577 ms 3636 KB Output is correct
35 Correct 688 ms 4076 KB Output is correct
36 Correct 260 ms 2540 KB Output is correct
37 Correct 1082 ms 4792 KB Output is correct
38 Correct 260 ms 2668 KB Output is correct
39 Correct 569 ms 3564 KB Output is correct
40 Correct 602 ms 3564 KB Output is correct
41 Correct 543 ms 11892 KB Output is correct
42 Correct 222 ms 12012 KB Output is correct
43 Correct 110 ms 11756 KB Output is correct
44 Correct 181 ms 11776 KB Output is correct
45 Correct 93 ms 11912 KB Output is correct
46 Correct 190 ms 11884 KB Output is correct
47 Correct 183 ms 11888 KB Output is correct
48 Correct 58 ms 12012 KB Output is correct
49 Correct 63 ms 11756 KB Output is correct
50 Correct 338 ms 11884 KB Output is correct
51 Correct 517 ms 12012 KB Output is correct
52 Correct 163 ms 11884 KB Output is correct
53 Correct 86 ms 11756 KB Output is correct
54 Correct 127 ms 11824 KB Output is correct
55 Correct 177 ms 11884 KB Output is correct
56 Correct 58 ms 11756 KB Output is correct
57 Correct 534 ms 12012 KB Output is correct
58 Correct 57 ms 11756 KB Output is correct
59 Correct 114 ms 11804 KB Output is correct
60 Correct 125 ms 11884 KB Output is correct
61 Correct 83 ms 11884 KB Output is correct
62 Correct 196 ms 11884 KB Output is correct
63 Correct 190 ms 11884 KB Output is correct
64 Correct 59 ms 11756 KB Output is correct
65 Correct 192 ms 11884 KB Output is correct
66 Correct 195 ms 11884 KB Output is correct
67 Correct 188 ms 11884 KB Output is correct
68 Correct 182 ms 11884 KB Output is correct
69 Correct 226 ms 11884 KB Output is correct
70 Correct 183 ms 11884 KB Output is correct
71 Execution timed out 2073 ms 16476 KB Time limit exceeded
72 Halted 0 ms 0 KB -