Submission #636058

# Submission time Handle Problem Language Result Execution time Memory
636058 2022-08-27T20:52:28 Z Bruteforceman Snake Escaping (JOI18_snake_escaping) C++11
100 / 100
1669 ms 39264 KB
          #include <bits/stdc++.h>
    //   #pragma GCC optimize ("Ofast,unroll-loops")
    // #pragma GCC target ("avx2")
        using namespace std;
      typedef long long ll;
       typedef pair<int, int> pp;
        #define er(args ...) cerr << __LINE__ << ": ", err(new istringstream(string(#args)), args), cerr << endl
          #define per(i,r,l) for(int i = (r); i >= (l); i--)
            #define rep(i,l,r) for(int i = (l); i < (r); i++)
               #define all(x) begin(x), end(x)
                  #define sz(x) (int)(x).size()
                      #define pb push_back
                          #define ss second
                               #define ff first
                                       void err(istringstream *iss){}template<typename T,typename ...Args> void err(istringstream *iss,const T &_val, const Args&...args){string _name;*iss>>_name;if(_name.back()==',')_name.pop_back();cerr<<_name<<" = "<<_val<<", ",err(iss,args...);}
    void IOS(){
         cin.tie(0) -> sync_with_stdio(0);
         // #ifndef ONLINE_JUDGE
         //      freopen("in.in", "r", stdin);
         //      freopen("out.out", "w", stdout);
         // #endif
    }
    mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
    const ll mod = 1e9 + 7, maxn = 5e5 + 5, lg = 20, inf = ll(1e18) + 5;
    ll pw(ll a,ll b,ll md=mod){if(!b)return 1;ll k=pw(a,b>>1ll);return k*k%md*(b&1ll?a:1)%md;}
     
    int sml[1<<lg], lrg[1<<lg];
     
    int main(){ IOS();
         int n, q; cin >> n >> q;
         string s; cin >> s;
         rep(i,0,sz(s)) sml[i] = lrg[i] = s[i] - '0';
         rep(i,0,n){
              rep(j,0,1<<n){
                   if(j>>i&1){
                        sml[j] += sml[j^(1<<i)];
                   }else{
                        lrg[j] += lrg[j^(1<<i)];
                   }
              }
         }
         while(q--){
              string t; cin >> t;
              vector<int> a[3];
              rep(i,0,n){
                   if(t[n-1-i] == '?') a[2].pb(i);
                   else a[t[n-1-i]-'0'].pb(i);
              }
              int ans = 0;
              if(sz(a[0]) <= n/3){
                   int vl = 0;
                   for(char c: t){
                        vl <<= 1;
                        if(c == '1') vl |= 1;
                   }
                   rep(i,0,1<<sz(a[0])){
                        int bt = vl;
                        int ptr = 0;
                        bool f = false;
                        for(int p: a[0]){
                             if(i>>ptr&1) bt ^= 1<<p, f ^= 1;
                             ptr++;
                        }
                        ans += (f?-1:1)*lrg[bt];
                   }
              }else if(sz(a[1]) <= n/3){
                   int vl = 0;
                   for(char c: t){
                        vl <<= 1;
                        if(c != '0') vl |= 1;
                   }
                   rep(i,0,1<<sz(a[1])){
                        int bt = vl;
                        int ptr = 0;
                        bool f = false;
                        for(int p: a[1]){
                             if(i>>ptr&1) bt ^= 1<<p, f ^= 1;
                             ptr++;
                        }
                        ans += (f?-1:1)*sml[bt];
                   }
              }else{
                   int vl = 0;
                   for(char c: t){
                        vl <<= 1;
                        if(c == '1') vl |= 1;
                   }
                   rep(i,0,1<<sz(a[2])){
                        int bt = vl;
                        int ptr = 0;
                        for(int p: a[2]){
                             if(i>>ptr&1) bt ^= 1<<p;
                             ptr++;
                        }
                        ans += s[bt]-'0';
                   }
              }
              cout << ans << '\n';
         }
         return 0; 
    }
# Verdict Execution time Memory Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 492 ms 5736 KB Output is correct
12 Correct 477 ms 5384 KB Output is correct
13 Correct 536 ms 4636 KB Output is correct
14 Correct 560 ms 4784 KB Output is correct
15 Correct 493 ms 5864 KB Output is correct
16 Correct 532 ms 4868 KB Output is correct
17 Correct 515 ms 4880 KB Output is correct
18 Correct 298 ms 6820 KB Output is correct
19 Correct 458 ms 3716 KB Output is correct
20 Correct 442 ms 5344 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 492 ms 5736 KB Output is correct
12 Correct 477 ms 5384 KB Output is correct
13 Correct 536 ms 4636 KB Output is correct
14 Correct 560 ms 4784 KB Output is correct
15 Correct 493 ms 5864 KB Output is correct
16 Correct 532 ms 4868 KB Output is correct
17 Correct 515 ms 4880 KB Output is correct
18 Correct 298 ms 6820 KB Output is correct
19 Correct 458 ms 3716 KB Output is correct
20 Correct 442 ms 5344 KB Output is correct
21 Correct 506 ms 5724 KB Output is correct
22 Correct 523 ms 5952 KB Output is correct
23 Correct 622 ms 4972 KB Output is correct
24 Correct 691 ms 4864 KB Output is correct
25 Correct 545 ms 6576 KB Output is correct
26 Correct 655 ms 4856 KB Output is correct
27 Correct 632 ms 4768 KB Output is correct
28 Correct 309 ms 7344 KB Output is correct
29 Correct 496 ms 3320 KB Output is correct
30 Correct 515 ms 5452 KB Output is correct
31 Correct 619 ms 5396 KB Output is correct
32 Correct 661 ms 5096 KB Output is correct
33 Correct 555 ms 4036 KB Output is correct
34 Correct 632 ms 4104 KB Output is correct
35 Correct 632 ms 4692 KB Output is correct
36 Correct 371 ms 2860 KB Output is correct
37 Correct 486 ms 4920 KB Output is correct
38 Correct 495 ms 2992 KB Output is correct
39 Correct 602 ms 3916 KB Output is correct
40 Correct 634 ms 3860 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 62 ms 10708 KB Output is correct
12 Correct 62 ms 11944 KB Output is correct
13 Correct 81 ms 11884 KB Output is correct
14 Correct 102 ms 11888 KB Output is correct
15 Correct 66 ms 12036 KB Output is correct
16 Correct 101 ms 11976 KB Output is correct
17 Correct 93 ms 11884 KB Output is correct
18 Correct 45 ms 12124 KB Output is correct
19 Correct 56 ms 11760 KB Output is correct
20 Correct 59 ms 11948 KB Output is correct
21 Correct 86 ms 11952 KB Output is correct
22 Correct 98 ms 11856 KB Output is correct
23 Correct 70 ms 11848 KB Output is correct
24 Correct 104 ms 11944 KB Output is correct
25 Correct 92 ms 11840 KB Output is correct
26 Correct 48 ms 11820 KB Output is correct
27 Correct 59 ms 11884 KB Output is correct
28 Correct 60 ms 11760 KB Output is correct
29 Correct 81 ms 11896 KB Output is correct
30 Correct 89 ms 11932 KB Output is correct
31 Correct 71 ms 11812 KB Output is correct
32 Correct 109 ms 11884 KB Output is correct
33 Correct 95 ms 11888 KB Output is correct
34 Correct 48 ms 11756 KB Output is correct
35 Correct 89 ms 11872 KB Output is correct
36 Correct 83 ms 11864 KB Output is correct
37 Correct 84 ms 11852 KB Output is correct
38 Correct 85 ms 11848 KB Output is correct
39 Correct 90 ms 11836 KB Output is correct
40 Correct 96 ms 11852 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 492 ms 5736 KB Output is correct
12 Correct 477 ms 5384 KB Output is correct
13 Correct 536 ms 4636 KB Output is correct
14 Correct 560 ms 4784 KB Output is correct
15 Correct 493 ms 5864 KB Output is correct
16 Correct 532 ms 4868 KB Output is correct
17 Correct 515 ms 4880 KB Output is correct
18 Correct 298 ms 6820 KB Output is correct
19 Correct 458 ms 3716 KB Output is correct
20 Correct 442 ms 5344 KB Output is correct
21 Correct 506 ms 5724 KB Output is correct
22 Correct 523 ms 5952 KB Output is correct
23 Correct 622 ms 4972 KB Output is correct
24 Correct 691 ms 4864 KB Output is correct
25 Correct 545 ms 6576 KB Output is correct
26 Correct 655 ms 4856 KB Output is correct
27 Correct 632 ms 4768 KB Output is correct
28 Correct 309 ms 7344 KB Output is correct
29 Correct 496 ms 3320 KB Output is correct
30 Correct 515 ms 5452 KB Output is correct
31 Correct 619 ms 5396 KB Output is correct
32 Correct 661 ms 5096 KB Output is correct
33 Correct 555 ms 4036 KB Output is correct
34 Correct 632 ms 4104 KB Output is correct
35 Correct 632 ms 4692 KB Output is correct
36 Correct 371 ms 2860 KB Output is correct
37 Correct 486 ms 4920 KB Output is correct
38 Correct 495 ms 2992 KB Output is correct
39 Correct 602 ms 3916 KB Output is correct
40 Correct 634 ms 3860 KB Output is correct
41 Correct 62 ms 10708 KB Output is correct
42 Correct 62 ms 11944 KB Output is correct
43 Correct 81 ms 11884 KB Output is correct
44 Correct 102 ms 11888 KB Output is correct
45 Correct 66 ms 12036 KB Output is correct
46 Correct 101 ms 11976 KB Output is correct
47 Correct 93 ms 11884 KB Output is correct
48 Correct 45 ms 12124 KB Output is correct
49 Correct 56 ms 11760 KB Output is correct
50 Correct 59 ms 11948 KB Output is correct
51 Correct 86 ms 11952 KB Output is correct
52 Correct 98 ms 11856 KB Output is correct
53 Correct 70 ms 11848 KB Output is correct
54 Correct 104 ms 11944 KB Output is correct
55 Correct 92 ms 11840 KB Output is correct
56 Correct 48 ms 11820 KB Output is correct
57 Correct 59 ms 11884 KB Output is correct
58 Correct 60 ms 11760 KB Output is correct
59 Correct 81 ms 11896 KB Output is correct
60 Correct 89 ms 11932 KB Output is correct
61 Correct 71 ms 11812 KB Output is correct
62 Correct 109 ms 11884 KB Output is correct
63 Correct 95 ms 11888 KB Output is correct
64 Correct 48 ms 11756 KB Output is correct
65 Correct 89 ms 11872 KB Output is correct
66 Correct 83 ms 11864 KB Output is correct
67 Correct 84 ms 11852 KB Output is correct
68 Correct 85 ms 11848 KB Output is correct
69 Correct 90 ms 11836 KB Output is correct
70 Correct 96 ms 11852 KB Output is correct
71 Correct 720 ms 36196 KB Output is correct
72 Correct 775 ms 36396 KB Output is correct
73 Correct 1127 ms 35036 KB Output is correct
74 Correct 1526 ms 35464 KB Output is correct
75 Correct 852 ms 37196 KB Output is correct
76 Correct 1500 ms 35520 KB Output is correct
77 Correct 1437 ms 35528 KB Output is correct
78 Correct 442 ms 39264 KB Output is correct
79 Correct 659 ms 33176 KB Output is correct
80 Correct 759 ms 36296 KB Output is correct
81 Correct 1077 ms 36376 KB Output is correct
82 Correct 1398 ms 35204 KB Output is correct
83 Correct 875 ms 34464 KB Output is correct
84 Correct 1538 ms 35304 KB Output is correct
85 Correct 1515 ms 35460 KB Output is correct
86 Correct 504 ms 33160 KB Output is correct
87 Correct 712 ms 36232 KB Output is correct
88 Correct 759 ms 33364 KB Output is correct
89 Correct 1060 ms 35052 KB Output is correct
90 Correct 1290 ms 35256 KB Output is correct
91 Correct 886 ms 34424 KB Output is correct
92 Correct 1669 ms 35568 KB Output is correct
93 Correct 1456 ms 34800 KB Output is correct
94 Correct 498 ms 33228 KB Output is correct
95 Correct 1197 ms 35440 KB Output is correct
96 Correct 1192 ms 35476 KB Output is correct
97 Correct 1206 ms 35532 KB Output is correct
98 Correct 1217 ms 35360 KB Output is correct
99 Correct 1207 ms 35364 KB Output is correct
100 Correct 1224 ms 35420 KB Output is correct