답안 #964771

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

using namespace std;

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';
            }
        }
    }
}

Compilation message

snake_escaping.cpp: In function 'int main()':
snake_escaping.cpp:30:24: warning: comparison of integer expressions of different signedness: 'std::vector<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   30 |         if (zero.size()<=(l/3))
      |             ~~~~~~~~~~~^~~~~~~
snake_escaping.cpp:48:28: warning: comparison of integer expressions of different signedness: 'std::vector<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   48 |         else if (one.size()<=(l/3))
      |                  ~~~~~~~~~~^~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 4444 KB Output is correct
2 Correct 1 ms 4444 KB Output is correct
3 Correct 1 ms 4568 KB Output is correct
4 Correct 2 ms 4444 KB Output is correct
5 Correct 2 ms 4440 KB Output is correct
6 Correct 2 ms 4444 KB Output is correct
7 Correct 2 ms 4444 KB Output is correct
8 Correct 1 ms 4444 KB Output is correct
9 Correct 1 ms 4444 KB Output is correct
10 Correct 1 ms 4440 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 4444 KB Output is correct
2 Correct 1 ms 4444 KB Output is correct
3 Correct 1 ms 4568 KB Output is correct
4 Correct 2 ms 4444 KB Output is correct
5 Correct 2 ms 4440 KB Output is correct
6 Correct 2 ms 4444 KB Output is correct
7 Correct 2 ms 4444 KB Output is correct
8 Correct 1 ms 4444 KB Output is correct
9 Correct 1 ms 4444 KB Output is correct
10 Correct 1 ms 4440 KB Output is correct
11 Correct 464 ms 14036 KB Output is correct
12 Correct 461 ms 13692 KB Output is correct
13 Correct 546 ms 12980 KB Output is correct
14 Correct 555 ms 12960 KB Output is correct
15 Correct 519 ms 14108 KB Output is correct
16 Correct 588 ms 13332 KB Output is correct
17 Correct 560 ms 16084 KB Output is correct
18 Correct 310 ms 18084 KB Output is correct
19 Correct 412 ms 15028 KB Output is correct
20 Correct 445 ms 16704 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 4444 KB Output is correct
2 Correct 1 ms 4444 KB Output is correct
3 Correct 1 ms 4568 KB Output is correct
4 Correct 2 ms 4444 KB Output is correct
5 Correct 2 ms 4440 KB Output is correct
6 Correct 2 ms 4444 KB Output is correct
7 Correct 2 ms 4444 KB Output is correct
8 Correct 1 ms 4444 KB Output is correct
9 Correct 1 ms 4444 KB Output is correct
10 Correct 1 ms 4440 KB Output is correct
11 Correct 464 ms 14036 KB Output is correct
12 Correct 461 ms 13692 KB Output is correct
13 Correct 546 ms 12980 KB Output is correct
14 Correct 555 ms 12960 KB Output is correct
15 Correct 519 ms 14108 KB Output is correct
16 Correct 588 ms 13332 KB Output is correct
17 Correct 560 ms 16084 KB Output is correct
18 Correct 310 ms 18084 KB Output is correct
19 Correct 412 ms 15028 KB Output is correct
20 Correct 445 ms 16704 KB Output is correct
21 Correct 524 ms 19500 KB Output is correct
22 Correct 524 ms 21408 KB Output is correct
23 Correct 737 ms 21456 KB Output is correct
24 Correct 773 ms 21256 KB Output is correct
25 Correct 626 ms 23284 KB Output is correct
26 Correct 780 ms 21688 KB Output is correct
27 Correct 746 ms 21508 KB Output is correct
28 Correct 328 ms 20172 KB Output is correct
29 Correct 501 ms 16068 KB Output is correct
30 Correct 555 ms 22408 KB Output is correct
31 Correct 662 ms 22208 KB Output is correct
32 Correct 743 ms 22216 KB Output is correct
33 Correct 644 ms 21164 KB Output is correct
34 Correct 748 ms 21276 KB Output is correct
35 Correct 721 ms 21532 KB Output is correct
36 Correct 293 ms 20248 KB Output is correct
37 Correct 485 ms 22096 KB Output is correct
38 Correct 537 ms 20120 KB Output is correct
39 Correct 711 ms 21440 KB Output is correct
40 Correct 767 ms 19168 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 4444 KB Output is correct
2 Correct 1 ms 4444 KB Output is correct
3 Correct 1 ms 4568 KB Output is correct
4 Correct 2 ms 4444 KB Output is correct
5 Correct 2 ms 4440 KB Output is correct
6 Correct 2 ms 4444 KB Output is correct
7 Correct 2 ms 4444 KB Output is correct
8 Correct 1 ms 4444 KB Output is correct
9 Correct 1 ms 4444 KB Output is correct
10 Correct 1 ms 4440 KB Output is correct
11 Correct 85 ms 15032 KB Output is correct
12 Correct 87 ms 15020 KB Output is correct
13 Correct 109 ms 14772 KB Output is correct
14 Correct 152 ms 14776 KB Output is correct
15 Correct 98 ms 14868 KB Output is correct
16 Correct 141 ms 14792 KB Output is correct
17 Correct 129 ms 14780 KB Output is correct
18 Correct 82 ms 15032 KB Output is correct
19 Correct 82 ms 14780 KB Output is correct
20 Correct 82 ms 15036 KB Output is correct
21 Correct 104 ms 14812 KB Output is correct
22 Correct 134 ms 14996 KB Output is correct
23 Correct 99 ms 14928 KB Output is correct
24 Correct 175 ms 14992 KB Output is correct
25 Correct 144 ms 14792 KB Output is correct
26 Correct 69 ms 14680 KB Output is correct
27 Correct 84 ms 15052 KB Output is correct
28 Correct 84 ms 14828 KB Output is correct
29 Correct 101 ms 14976 KB Output is correct
30 Correct 117 ms 14988 KB Output is correct
31 Correct 98 ms 14848 KB Output is correct
32 Correct 138 ms 14780 KB Output is correct
33 Correct 135 ms 14844 KB Output is correct
34 Correct 61 ms 14700 KB Output is correct
35 Correct 122 ms 14984 KB Output is correct
36 Correct 109 ms 14788 KB Output is correct
37 Correct 136 ms 14956 KB Output is correct
38 Correct 116 ms 14944 KB Output is correct
39 Correct 129 ms 14960 KB Output is correct
40 Correct 136 ms 14796 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 4444 KB Output is correct
2 Correct 1 ms 4444 KB Output is correct
3 Correct 1 ms 4568 KB Output is correct
4 Correct 2 ms 4444 KB Output is correct
5 Correct 2 ms 4440 KB Output is correct
6 Correct 2 ms 4444 KB Output is correct
7 Correct 2 ms 4444 KB Output is correct
8 Correct 1 ms 4444 KB Output is correct
9 Correct 1 ms 4444 KB Output is correct
10 Correct 1 ms 4440 KB Output is correct
11 Correct 464 ms 14036 KB Output is correct
12 Correct 461 ms 13692 KB Output is correct
13 Correct 546 ms 12980 KB Output is correct
14 Correct 555 ms 12960 KB Output is correct
15 Correct 519 ms 14108 KB Output is correct
16 Correct 588 ms 13332 KB Output is correct
17 Correct 560 ms 16084 KB Output is correct
18 Correct 310 ms 18084 KB Output is correct
19 Correct 412 ms 15028 KB Output is correct
20 Correct 445 ms 16704 KB Output is correct
21 Correct 524 ms 19500 KB Output is correct
22 Correct 524 ms 21408 KB Output is correct
23 Correct 737 ms 21456 KB Output is correct
24 Correct 773 ms 21256 KB Output is correct
25 Correct 626 ms 23284 KB Output is correct
26 Correct 780 ms 21688 KB Output is correct
27 Correct 746 ms 21508 KB Output is correct
28 Correct 328 ms 20172 KB Output is correct
29 Correct 501 ms 16068 KB Output is correct
30 Correct 555 ms 22408 KB Output is correct
31 Correct 662 ms 22208 KB Output is correct
32 Correct 743 ms 22216 KB Output is correct
33 Correct 644 ms 21164 KB Output is correct
34 Correct 748 ms 21276 KB Output is correct
35 Correct 721 ms 21532 KB Output is correct
36 Correct 293 ms 20248 KB Output is correct
37 Correct 485 ms 22096 KB Output is correct
38 Correct 537 ms 20120 KB Output is correct
39 Correct 711 ms 21440 KB Output is correct
40 Correct 767 ms 19168 KB Output is correct
41 Correct 85 ms 15032 KB Output is correct
42 Correct 87 ms 15020 KB Output is correct
43 Correct 109 ms 14772 KB Output is correct
44 Correct 152 ms 14776 KB Output is correct
45 Correct 98 ms 14868 KB Output is correct
46 Correct 141 ms 14792 KB Output is correct
47 Correct 129 ms 14780 KB Output is correct
48 Correct 82 ms 15032 KB Output is correct
49 Correct 82 ms 14780 KB Output is correct
50 Correct 82 ms 15036 KB Output is correct
51 Correct 104 ms 14812 KB Output is correct
52 Correct 134 ms 14996 KB Output is correct
53 Correct 99 ms 14928 KB Output is correct
54 Correct 175 ms 14992 KB Output is correct
55 Correct 144 ms 14792 KB Output is correct
56 Correct 69 ms 14680 KB Output is correct
57 Correct 84 ms 15052 KB Output is correct
58 Correct 84 ms 14828 KB Output is correct
59 Correct 101 ms 14976 KB Output is correct
60 Correct 117 ms 14988 KB Output is correct
61 Correct 98 ms 14848 KB Output is correct
62 Correct 138 ms 14780 KB Output is correct
63 Correct 135 ms 14844 KB Output is correct
64 Correct 61 ms 14700 KB Output is correct
65 Correct 122 ms 14984 KB Output is correct
66 Correct 109 ms 14788 KB Output is correct
67 Correct 136 ms 14956 KB Output is correct
68 Correct 116 ms 14944 KB Output is correct
69 Correct 129 ms 14960 KB Output is correct
70 Correct 136 ms 14796 KB Output is correct
71 Correct 815 ms 39356 KB Output is correct
72 Correct 869 ms 39380 KB Output is correct
73 Correct 1301 ms 37928 KB Output is correct
74 Correct 1762 ms 38336 KB Output is correct
75 Correct 926 ms 40392 KB Output is correct
76 Correct 1954 ms 38552 KB Output is correct
77 Correct 1915 ms 35096 KB Output is correct
78 Correct 450 ms 42176 KB Output is correct
79 Correct 803 ms 36280 KB Output is correct
80 Correct 874 ms 39396 KB Output is correct
81 Correct 1304 ms 39140 KB Output is correct
82 Correct 1854 ms 38140 KB Output is correct
83 Correct 944 ms 37284 KB Output is correct
84 Execution timed out 2044 ms 34732 KB Time limit exceeded
85 Halted 0 ms 0 KB -