답안 #80210

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
80210 2018-10-19T14:36:55 Z Bodo171 Snake Escaping (JOI18_snake_escaping) C++14
75 / 100
1028 ms 66560 KB
#include <cstdio>
#include <iostream>

using namespace std;
const int nmax=(1<<20)+5;
char s[22],str[nmax];
char t;
char pc[nmax],v[nmax];
int sub[nmax],supra[nmax];
int l,q,i,j,m0,m1,mq,mn,ans;
bool brk;
int main()
{
    //freopen("data.in","r",stdin);
    scanf("%d%d",&l,&q);
    scanf("%s",&str);
    for(i=0;i<(1<<l);i++)
    {
        if(i!=0)
            pc[i]=pc[(i&(i-1))]+1;
        sub[i]=supra[i]=v[i]=str[i]-'0';
    }
    for(i=0;i<l;i++)
        for(j=0;j<(1<<l);j++)
           if(((1<<i)&j))
              sub[j]+=sub[(j^(1<<i))];
            else supra[j]+=supra[(j^(1<<i))];
    for(int cnt=1;cnt<=q;cnt++)
    {
        scanf("%s",&s);
        m0=m1=mq=0;
        for(j=l-1;j>=0;j--)
        {
            t=s[l-1-j];
            if(t=='0') m0+=(1<<j);
            else if(t=='1') m1+=(1<<j);
             else mq+=(1<<j);
        }
        mn=min(min(pc[m0],pc[m1]),pc[mq]);
        ans=0;brk=0;
        if(mn==pc[m0])
        {
            ans=supra[m1];
            i=m0;
            while(i!=0)
            {
                if((pc[i]&1)) ans-=supra[(i|m1)];
                else ans+=supra[(i|m1)];
                i=((i-1)&m0);
            }
        }
        else
        {
            if(mn==pc[m1])
            {
                i=m1;
                while(!brk)
                {
                    if(i==0)
                        brk=1;
                    if(((pc[m1]-pc[i])&1)) ans-=sub[(i|mq)];
                    else ans+=sub[(i|mq)];
                    i=((i-1)&m1);
                }
            }
            else
            {
                    i=mq;
                    while(!brk)
                    {
                        ans+=v[(m1|i)];
                        if(i==0)
                            brk=1;
                        i=((i-1)&mq);
                    }
            }
        }
        printf("%d\n",ans);
    }
    return 0;
}

Compilation message

snake_escaping.cpp: In function 'int main()':
snake_escaping.cpp:16:20: warning: format '%s' expects argument of type 'char*', but argument 2 has type 'char (*)[1048581]' [-Wformat=]
     scanf("%s",&str);
                ~~~~^
snake_escaping.cpp:30:22: warning: format '%s' expects argument of type 'char*', but argument 2 has type 'char (*)[22]' [-Wformat=]
         scanf("%s",&s);
                    ~~^
snake_escaping.cpp:15:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d%d",&l,&q);
     ~~~~~^~~~~~~~~~~~~~
snake_escaping.cpp:16:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%s",&str);
     ~~~~~^~~~~~~~~~~
snake_escaping.cpp:30:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf("%s",&s);
         ~~~~~^~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 376 KB Output is correct
2 Correct 3 ms 520 KB Output is correct
3 Correct 3 ms 608 KB Output is correct
4 Correct 3 ms 608 KB Output is correct
5 Correct 2 ms 608 KB Output is correct
6 Correct 3 ms 608 KB Output is correct
7 Correct 3 ms 608 KB Output is correct
8 Correct 2 ms 788 KB Output is correct
9 Correct 3 ms 788 KB Output is correct
10 Correct 3 ms 788 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 376 KB Output is correct
2 Correct 3 ms 520 KB Output is correct
3 Correct 3 ms 608 KB Output is correct
4 Correct 3 ms 608 KB Output is correct
5 Correct 2 ms 608 KB Output is correct
6 Correct 3 ms 608 KB Output is correct
7 Correct 3 ms 608 KB Output is correct
8 Correct 2 ms 788 KB Output is correct
9 Correct 3 ms 788 KB Output is correct
10 Correct 3 ms 788 KB Output is correct
11 Correct 302 ms 5028 KB Output is correct
12 Correct 321 ms 5252 KB Output is correct
13 Correct 357 ms 5252 KB Output is correct
14 Correct 343 ms 5252 KB Output is correct
15 Correct 291 ms 5496 KB Output is correct
16 Correct 335 ms 5496 KB Output is correct
17 Correct 334 ms 5496 KB Output is correct
18 Correct 251 ms 6676 KB Output is correct
19 Correct 258 ms 6676 KB Output is correct
20 Correct 323 ms 6676 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 376 KB Output is correct
2 Correct 3 ms 520 KB Output is correct
3 Correct 3 ms 608 KB Output is correct
4 Correct 3 ms 608 KB Output is correct
5 Correct 2 ms 608 KB Output is correct
6 Correct 3 ms 608 KB Output is correct
7 Correct 3 ms 608 KB Output is correct
8 Correct 2 ms 788 KB Output is correct
9 Correct 3 ms 788 KB Output is correct
10 Correct 3 ms 788 KB Output is correct
11 Correct 302 ms 5028 KB Output is correct
12 Correct 321 ms 5252 KB Output is correct
13 Correct 357 ms 5252 KB Output is correct
14 Correct 343 ms 5252 KB Output is correct
15 Correct 291 ms 5496 KB Output is correct
16 Correct 335 ms 5496 KB Output is correct
17 Correct 334 ms 5496 KB Output is correct
18 Correct 251 ms 6676 KB Output is correct
19 Correct 258 ms 6676 KB Output is correct
20 Correct 323 ms 6676 KB Output is correct
21 Correct 459 ms 6676 KB Output is correct
22 Correct 354 ms 6676 KB Output is correct
23 Correct 415 ms 6676 KB Output is correct
24 Correct 428 ms 6676 KB Output is correct
25 Correct 345 ms 6808 KB Output is correct
26 Correct 413 ms 6808 KB Output is correct
27 Correct 437 ms 6808 KB Output is correct
28 Correct 265 ms 21528 KB Output is correct
29 Correct 341 ms 21528 KB Output is correct
30 Correct 364 ms 21528 KB Output is correct
31 Correct 459 ms 21528 KB Output is correct
32 Correct 403 ms 21528 KB Output is correct
33 Correct 398 ms 21528 KB Output is correct
34 Correct 438 ms 21528 KB Output is correct
35 Correct 423 ms 21528 KB Output is correct
36 Correct 278 ms 21528 KB Output is correct
37 Correct 308 ms 21528 KB Output is correct
38 Correct 332 ms 21528 KB Output is correct
39 Correct 393 ms 21528 KB Output is correct
40 Correct 386 ms 21528 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 376 KB Output is correct
2 Correct 3 ms 520 KB Output is correct
3 Correct 3 ms 608 KB Output is correct
4 Correct 3 ms 608 KB Output is correct
5 Correct 2 ms 608 KB Output is correct
6 Correct 3 ms 608 KB Output is correct
7 Correct 3 ms 608 KB Output is correct
8 Correct 2 ms 788 KB Output is correct
9 Correct 3 ms 788 KB Output is correct
10 Correct 3 ms 788 KB Output is correct
11 Correct 70 ms 28908 KB Output is correct
12 Correct 79 ms 28908 KB Output is correct
13 Correct 78 ms 28908 KB Output is correct
14 Correct 81 ms 28908 KB Output is correct
15 Correct 71 ms 28908 KB Output is correct
16 Correct 100 ms 28908 KB Output is correct
17 Correct 85 ms 28908 KB Output is correct
18 Correct 67 ms 28976 KB Output is correct
19 Correct 70 ms 28976 KB Output is correct
20 Correct 70 ms 28976 KB Output is correct
21 Correct 79 ms 28976 KB Output is correct
22 Correct 87 ms 28976 KB Output is correct
23 Correct 70 ms 28976 KB Output is correct
24 Correct 99 ms 28976 KB Output is correct
25 Correct 90 ms 28976 KB Output is correct
26 Correct 63 ms 28976 KB Output is correct
27 Correct 74 ms 28976 KB Output is correct
28 Correct 70 ms 28976 KB Output is correct
29 Correct 80 ms 28976 KB Output is correct
30 Correct 75 ms 28976 KB Output is correct
31 Correct 71 ms 28976 KB Output is correct
32 Correct 113 ms 28976 KB Output is correct
33 Correct 91 ms 28976 KB Output is correct
34 Correct 59 ms 28976 KB Output is correct
35 Correct 93 ms 29096 KB Output is correct
36 Correct 213 ms 29144 KB Output is correct
37 Correct 87 ms 29144 KB Output is correct
38 Correct 96 ms 29364 KB Output is correct
39 Correct 87 ms 29364 KB Output is correct
40 Correct 131 ms 29364 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 376 KB Output is correct
2 Correct 3 ms 520 KB Output is correct
3 Correct 3 ms 608 KB Output is correct
4 Correct 3 ms 608 KB Output is correct
5 Correct 2 ms 608 KB Output is correct
6 Correct 3 ms 608 KB Output is correct
7 Correct 3 ms 608 KB Output is correct
8 Correct 2 ms 788 KB Output is correct
9 Correct 3 ms 788 KB Output is correct
10 Correct 3 ms 788 KB Output is correct
11 Correct 302 ms 5028 KB Output is correct
12 Correct 321 ms 5252 KB Output is correct
13 Correct 357 ms 5252 KB Output is correct
14 Correct 343 ms 5252 KB Output is correct
15 Correct 291 ms 5496 KB Output is correct
16 Correct 335 ms 5496 KB Output is correct
17 Correct 334 ms 5496 KB Output is correct
18 Correct 251 ms 6676 KB Output is correct
19 Correct 258 ms 6676 KB Output is correct
20 Correct 323 ms 6676 KB Output is correct
21 Correct 459 ms 6676 KB Output is correct
22 Correct 354 ms 6676 KB Output is correct
23 Correct 415 ms 6676 KB Output is correct
24 Correct 428 ms 6676 KB Output is correct
25 Correct 345 ms 6808 KB Output is correct
26 Correct 413 ms 6808 KB Output is correct
27 Correct 437 ms 6808 KB Output is correct
28 Correct 265 ms 21528 KB Output is correct
29 Correct 341 ms 21528 KB Output is correct
30 Correct 364 ms 21528 KB Output is correct
31 Correct 459 ms 21528 KB Output is correct
32 Correct 403 ms 21528 KB Output is correct
33 Correct 398 ms 21528 KB Output is correct
34 Correct 438 ms 21528 KB Output is correct
35 Correct 423 ms 21528 KB Output is correct
36 Correct 278 ms 21528 KB Output is correct
37 Correct 308 ms 21528 KB Output is correct
38 Correct 332 ms 21528 KB Output is correct
39 Correct 393 ms 21528 KB Output is correct
40 Correct 386 ms 21528 KB Output is correct
41 Correct 70 ms 28908 KB Output is correct
42 Correct 79 ms 28908 KB Output is correct
43 Correct 78 ms 28908 KB Output is correct
44 Correct 81 ms 28908 KB Output is correct
45 Correct 71 ms 28908 KB Output is correct
46 Correct 100 ms 28908 KB Output is correct
47 Correct 85 ms 28908 KB Output is correct
48 Correct 67 ms 28976 KB Output is correct
49 Correct 70 ms 28976 KB Output is correct
50 Correct 70 ms 28976 KB Output is correct
51 Correct 79 ms 28976 KB Output is correct
52 Correct 87 ms 28976 KB Output is correct
53 Correct 70 ms 28976 KB Output is correct
54 Correct 99 ms 28976 KB Output is correct
55 Correct 90 ms 28976 KB Output is correct
56 Correct 63 ms 28976 KB Output is correct
57 Correct 74 ms 28976 KB Output is correct
58 Correct 70 ms 28976 KB Output is correct
59 Correct 80 ms 28976 KB Output is correct
60 Correct 75 ms 28976 KB Output is correct
61 Correct 71 ms 28976 KB Output is correct
62 Correct 113 ms 28976 KB Output is correct
63 Correct 91 ms 28976 KB Output is correct
64 Correct 59 ms 28976 KB Output is correct
65 Correct 93 ms 29096 KB Output is correct
66 Correct 213 ms 29144 KB Output is correct
67 Correct 87 ms 29144 KB Output is correct
68 Correct 96 ms 29364 KB Output is correct
69 Correct 87 ms 29364 KB Output is correct
70 Correct 131 ms 29364 KB Output is correct
71 Correct 560 ms 55588 KB Output is correct
72 Correct 600 ms 55768 KB Output is correct
73 Correct 786 ms 55768 KB Output is correct
74 Correct 982 ms 57172 KB Output is correct
75 Correct 599 ms 57884 KB Output is correct
76 Correct 1028 ms 57884 KB Output is correct
77 Runtime error 967 ms 66560 KB Memory limit exceeded: We have a known bug that the memory usage is measured incorrectly (possibly because of Meltdown/Spectre patch), so your solution may be correct. Please submit again. Sorry for the inconvenience.
78 Halted 0 ms 0 KB -