답안 #964774

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
964774 2024-04-17T14:10:24 Z 12345678 Snake Escaping (JOI18_snake_escaping) C++17
100 / 100
1530 ms 42320 KB
#include <bits/stdc++.h>

using namespace std;

#pragma GCC optimize("O3,unroll-loops")
#pragma GCC target("avx2,bmi,bmi2,lzcnt,popcnt")

const int nx=(1<<20)+5;

int l, q, a[nx], sub[nx], super[nx];
char c;
string s;

int main()
{
    cin.tie(NULL)->sync_with_stdio(false);
    cin>>l>>q;
    for (int i=0; i<(1<<l); i++) cin>>c, a[i]=sub[i]=super[i]=c-'0';
    for (int i=0; i<l; i++) for (int j=0; j<(1<<l); j++) if (j&(1<<i)) sub[j]+=sub[j^(1<<i)];
    for (int i=0; i<l; i++) for (int j=(1<<l)-1; j>=0; j--) if (!(j&(1<<i))) super[j]+=super[j^(1<<i)];
    while (q--)
    {
        cin>>s;
        reverse(s.begin(), s.end());
        int tmp=0;
        vector<int> zero, one, qrs;
        for (int i=0; i<l; i++)
        {
            if (s[i]=='0') zero.push_back(i);
            if (s[i]=='1') one.push_back(i);
            if (s[i]=='?') qrs.push_back(i);
        }
        if (zero.size()<=(l/3))
        {
            for (int i=0; i<l; i++) if (s[i]=='1') tmp+=(1<<i);
            if (zero.empty()) cout<<super[tmp]<<'\n';
            else
            {
                int sz=zero.size(), res=0;
                for (int i=0; i<(1<<sz); i++)
                {
                    int vl=tmp;
                    for (int j=0; j<sz; j++) if ((i&(1<<j))) vl+=(1<<zero[j]);
                    //cout<<"debug "<<i<<' '<<vl<<'\n';
                    if ((__builtin_popcount(i)%2)==0) res+=super[vl];
                    else res-=super[vl];
                }
                cout<<res<<'\n';
            }
        }
        else if (one.size()<=(l/3))
        {
            for (int i=0; i<l; i++) if (s[i]=='?') tmp+=(1<<i);
            if (one.empty()) cout<<sub[tmp]<<'\n';
            else
            {
                int sz=one.size(), res=0;
                for (int i=0; i<(1<<sz); i++)
                {
                    int vl=tmp;
                    for (int j=0; j<sz; j++) if (i&(1<<j)) vl+=(1<<one[j]);
                    if ((sz-__builtin_popcount(i))%2==0) res+=sub[vl];
                    else res-=sub[vl];
                }
                cout<<res<<'\n';
            }     
        }
        else
        {
            for (int i=0; i<l; i++) if (s[i]=='1') tmp+=(1<<i);
            if (qrs.empty()) cout<<a[tmp]<<'\n';
            else
            {
                int sz=qrs.size(), res=0;
                for (int i=0; i<(1<<sz); i++)
                {
                    int vl=tmp;
                    for (int j=0; j<sz; j++) if (i&(1<<j)) vl+=(1<<qrs[j]);
                    res+=a[vl];
                }
                cout<<res<<'\n';
            }
        }
    }
}

// 00011???

Compilation message

snake_escaping.cpp: In function 'int main()':
snake_escaping.cpp:33:24: warning: comparison of integer expressions of different signedness: 'std::vector<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   33 |         if (zero.size()<=(l/3))
      |             ~~~~~~~~~~~^~~~~~~
snake_escaping.cpp:51:28: warning: comparison of integer expressions of different signedness: 'std::vector<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   51 |         else if (one.size()<=(l/3))
      |                  ~~~~~~~~~~^~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 4444 KB Output is correct
2 Correct 1 ms 4568 KB Output is correct
3 Correct 2 ms 4564 KB Output is correct
4 Correct 1 ms 4576 KB Output is correct
5 Correct 2 ms 4444 KB Output is correct
6 Correct 1 ms 4444 KB Output is correct
7 Correct 1 ms 4444 KB Output is correct
8 Correct 2 ms 4444 KB Output is correct
9 Correct 1 ms 4444 KB Output is correct
10 Correct 1 ms 4444 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 4444 KB Output is correct
2 Correct 1 ms 4568 KB Output is correct
3 Correct 2 ms 4564 KB Output is correct
4 Correct 1 ms 4576 KB Output is correct
5 Correct 2 ms 4444 KB Output is correct
6 Correct 1 ms 4444 KB Output is correct
7 Correct 1 ms 4444 KB Output is correct
8 Correct 2 ms 4444 KB Output is correct
9 Correct 1 ms 4444 KB Output is correct
10 Correct 1 ms 4444 KB Output is correct
11 Correct 445 ms 19068 KB Output is correct
12 Correct 435 ms 18772 KB Output is correct
13 Correct 513 ms 18036 KB Output is correct
14 Correct 513 ms 18284 KB Output is correct
15 Correct 431 ms 19100 KB Output is correct
16 Correct 560 ms 18260 KB Output is correct
17 Correct 528 ms 18260 KB Output is correct
18 Correct 305 ms 20316 KB Output is correct
19 Correct 412 ms 17308 KB Output is correct
20 Correct 418 ms 18768 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 4444 KB Output is correct
2 Correct 1 ms 4568 KB Output is correct
3 Correct 2 ms 4564 KB Output is correct
4 Correct 1 ms 4576 KB Output is correct
5 Correct 2 ms 4444 KB Output is correct
6 Correct 1 ms 4444 KB Output is correct
7 Correct 1 ms 4444 KB Output is correct
8 Correct 2 ms 4444 KB Output is correct
9 Correct 1 ms 4444 KB Output is correct
10 Correct 1 ms 4444 KB Output is correct
11 Correct 445 ms 19068 KB Output is correct
12 Correct 435 ms 18772 KB Output is correct
13 Correct 513 ms 18036 KB Output is correct
14 Correct 513 ms 18284 KB Output is correct
15 Correct 431 ms 19100 KB Output is correct
16 Correct 560 ms 18260 KB Output is correct
17 Correct 528 ms 18260 KB Output is correct
18 Correct 305 ms 20316 KB Output is correct
19 Correct 412 ms 17308 KB Output is correct
20 Correct 418 ms 18768 KB Output is correct
21 Correct 464 ms 22372 KB Output is correct
22 Correct 522 ms 22272 KB Output is correct
23 Correct 632 ms 21368 KB Output is correct
24 Correct 669 ms 21252 KB Output is correct
25 Correct 539 ms 23404 KB Output is correct
26 Correct 646 ms 21596 KB Output is correct
27 Correct 652 ms 21588 KB Output is correct
28 Correct 300 ms 24148 KB Output is correct
29 Correct 454 ms 20032 KB Output is correct
30 Correct 516 ms 22424 KB Output is correct
31 Correct 623 ms 22052 KB Output is correct
32 Correct 667 ms 22100 KB Output is correct
33 Correct 547 ms 20976 KB Output is correct
34 Correct 683 ms 21192 KB Output is correct
35 Correct 667 ms 21548 KB Output is correct
36 Correct 302 ms 20160 KB Output is correct
37 Correct 462 ms 20444 KB Output is correct
38 Correct 545 ms 20048 KB Output is correct
39 Correct 632 ms 21376 KB Output is correct
40 Correct 677 ms 21224 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 4444 KB Output is correct
2 Correct 1 ms 4568 KB Output is correct
3 Correct 2 ms 4564 KB Output is correct
4 Correct 1 ms 4576 KB Output is correct
5 Correct 2 ms 4444 KB Output is correct
6 Correct 1 ms 4444 KB Output is correct
7 Correct 1 ms 4444 KB Output is correct
8 Correct 2 ms 4444 KB Output is correct
9 Correct 1 ms 4444 KB Output is correct
10 Correct 1 ms 4444 KB Output is correct
11 Correct 59 ms 15028 KB Output is correct
12 Correct 66 ms 14928 KB Output is correct
13 Correct 73 ms 14980 KB Output is correct
14 Correct 91 ms 14928 KB Output is correct
15 Correct 72 ms 15236 KB Output is correct
16 Correct 87 ms 14844 KB Output is correct
17 Correct 90 ms 15008 KB Output is correct
18 Correct 49 ms 15188 KB Output is correct
19 Correct 57 ms 14672 KB Output is correct
20 Correct 66 ms 14840 KB Output is correct
21 Correct 86 ms 15020 KB Output is correct
22 Correct 86 ms 14796 KB Output is correct
23 Correct 68 ms 14788 KB Output is correct
24 Correct 110 ms 15000 KB Output is correct
25 Correct 83 ms 14928 KB Output is correct
26 Correct 54 ms 14776 KB Output is correct
27 Correct 56 ms 15048 KB Output is correct
28 Correct 61 ms 14676 KB Output is correct
29 Correct 75 ms 14772 KB Output is correct
30 Correct 82 ms 14788 KB Output is correct
31 Correct 65 ms 14792 KB Output is correct
32 Correct 83 ms 14928 KB Output is correct
33 Correct 93 ms 14884 KB Output is correct
34 Correct 52 ms 14792 KB Output is correct
35 Correct 93 ms 14788 KB Output is correct
36 Correct 82 ms 14824 KB Output is correct
37 Correct 94 ms 14928 KB Output is correct
38 Correct 79 ms 14928 KB Output is correct
39 Correct 78 ms 14796 KB Output is correct
40 Correct 80 ms 14928 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 4444 KB Output is correct
2 Correct 1 ms 4568 KB Output is correct
3 Correct 2 ms 4564 KB Output is correct
4 Correct 1 ms 4576 KB Output is correct
5 Correct 2 ms 4444 KB Output is correct
6 Correct 1 ms 4444 KB Output is correct
7 Correct 1 ms 4444 KB Output is correct
8 Correct 2 ms 4444 KB Output is correct
9 Correct 1 ms 4444 KB Output is correct
10 Correct 1 ms 4444 KB Output is correct
11 Correct 445 ms 19068 KB Output is correct
12 Correct 435 ms 18772 KB Output is correct
13 Correct 513 ms 18036 KB Output is correct
14 Correct 513 ms 18284 KB Output is correct
15 Correct 431 ms 19100 KB Output is correct
16 Correct 560 ms 18260 KB Output is correct
17 Correct 528 ms 18260 KB Output is correct
18 Correct 305 ms 20316 KB Output is correct
19 Correct 412 ms 17308 KB Output is correct
20 Correct 418 ms 18768 KB Output is correct
21 Correct 464 ms 22372 KB Output is correct
22 Correct 522 ms 22272 KB Output is correct
23 Correct 632 ms 21368 KB Output is correct
24 Correct 669 ms 21252 KB Output is correct
25 Correct 539 ms 23404 KB Output is correct
26 Correct 646 ms 21596 KB Output is correct
27 Correct 652 ms 21588 KB Output is correct
28 Correct 300 ms 24148 KB Output is correct
29 Correct 454 ms 20032 KB Output is correct
30 Correct 516 ms 22424 KB Output is correct
31 Correct 623 ms 22052 KB Output is correct
32 Correct 667 ms 22100 KB Output is correct
33 Correct 547 ms 20976 KB Output is correct
34 Correct 683 ms 21192 KB Output is correct
35 Correct 667 ms 21548 KB Output is correct
36 Correct 302 ms 20160 KB Output is correct
37 Correct 462 ms 20444 KB Output is correct
38 Correct 545 ms 20048 KB Output is correct
39 Correct 632 ms 21376 KB Output is correct
40 Correct 677 ms 21224 KB Output is correct
41 Correct 59 ms 15028 KB Output is correct
42 Correct 66 ms 14928 KB Output is correct
43 Correct 73 ms 14980 KB Output is correct
44 Correct 91 ms 14928 KB Output is correct
45 Correct 72 ms 15236 KB Output is correct
46 Correct 87 ms 14844 KB Output is correct
47 Correct 90 ms 15008 KB Output is correct
48 Correct 49 ms 15188 KB Output is correct
49 Correct 57 ms 14672 KB Output is correct
50 Correct 66 ms 14840 KB Output is correct
51 Correct 86 ms 15020 KB Output is correct
52 Correct 86 ms 14796 KB Output is correct
53 Correct 68 ms 14788 KB Output is correct
54 Correct 110 ms 15000 KB Output is correct
55 Correct 83 ms 14928 KB Output is correct
56 Correct 54 ms 14776 KB Output is correct
57 Correct 56 ms 15048 KB Output is correct
58 Correct 61 ms 14676 KB Output is correct
59 Correct 75 ms 14772 KB Output is correct
60 Correct 82 ms 14788 KB Output is correct
61 Correct 65 ms 14792 KB Output is correct
62 Correct 83 ms 14928 KB Output is correct
63 Correct 93 ms 14884 KB Output is correct
64 Correct 52 ms 14792 KB Output is correct
65 Correct 93 ms 14788 KB Output is correct
66 Correct 82 ms 14824 KB Output is correct
67 Correct 94 ms 14928 KB Output is correct
68 Correct 79 ms 14928 KB Output is correct
69 Correct 78 ms 14796 KB Output is correct
70 Correct 80 ms 14928 KB Output is correct
71 Correct 615 ms 39152 KB Output is correct
72 Correct 694 ms 39208 KB Output is correct
73 Correct 1032 ms 37748 KB Output is correct
74 Correct 1142 ms 38132 KB Output is correct
75 Correct 712 ms 40140 KB Output is correct
76 Correct 1204 ms 38500 KB Output is correct
77 Correct 1387 ms 38308 KB Output is correct
78 Correct 411 ms 42320 KB Output is correct
79 Correct 597 ms 36084 KB Output is correct
80 Correct 620 ms 39252 KB Output is correct
81 Correct 993 ms 39240 KB Output is correct
82 Correct 1227 ms 38264 KB Output is correct
83 Correct 739 ms 37288 KB Output is correct
84 Correct 1530 ms 37508 KB Output is correct
85 Correct 1389 ms 38456 KB Output is correct
86 Correct 390 ms 36324 KB Output is correct
87 Correct 588 ms 39116 KB Output is correct
88 Correct 696 ms 36256 KB Output is correct
89 Correct 900 ms 37984 KB Output is correct
90 Correct 1091 ms 38188 KB Output is correct
91 Correct 791 ms 37508 KB Output is correct
92 Correct 1313 ms 38560 KB Output is correct
93 Correct 1307 ms 38264 KB Output is correct
94 Correct 382 ms 36392 KB Output is correct
95 Correct 1038 ms 38304 KB Output is correct
96 Correct 1118 ms 38316 KB Output is correct
97 Correct 984 ms 38256 KB Output is correct
98 Correct 1090 ms 38312 KB Output is correct
99 Correct 1208 ms 38384 KB Output is correct
100 Correct 1049 ms 38228 KB Output is correct