Submission #792467

# Submission time Handle Problem Language Result Execution time Memory
792467 2023-07-25T05:15:33 Z Cookie Snake Escaping (JOI18_snake_escaping) C++14
22 / 100
371 ms 13180 KB
#include<bits/stdc++.h>
#include<fstream>
#pragma GCC optimize("Ofast,O3,unroll-loops")
#pragma GCC target("avx2")
using namespace std;
//ifstream fin("FEEDING.INP");
//ofstream fout("FEEDING.OUT");
#define sz(a) (int)a.size()
#define ll long long
#define pb push_back
#define forr(i, a, b) for(int i = a; i < b; i++)
#define dorr(i, a, b) for(int i = a; i >= b; i--)
#define ld long double
#define vt vector
#include<fstream>
#define fi first
#define se second
#define pll pair<ll, ll>
#define pii pair<int, int>
const ll mxn = 3e5 + 5, base = 972663749;
const ll mod = 911382323, mxv = 1e9 + 1, inf = 2e9;
int l, q;
int big[(1 << 20)], small[(1 << 20)];
string s;
signed main()
{
     ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); 
    cin >> l >> q;
    cin >> s;
    for(int i = 0; i < (1 << l); i++){
        
        big[i] = (s[i] - '0'); small[i] = (s[i] - '0');
    }
    for(int i = 0; i < l; i++){
        for(int j = 0; j < (1 << l); j++){
            if(j & (1 << i))small[j] += small[j ^ (1 << i)];
            else big[j] += big[j ^ (1 << i)];
        }
    }
    if(l == 20 && q > 10000)return(0);
    
    while(q--){
       
       char c;
        int zero = 0, one = 0, que = 0;
        for(int i = 0; i < l; i++){
            cin >> c;
            if(c == '0')zero += (1 << (l - i - 1));
            else if(c == '1')one += (1 << (l - i - 1));
            else que += (1 << (l - i - 1));
        }
        int ans = 0;
        if(__builtin_popcount(que) <= 6){
            int mask = one;
            for(int j = que;j; j = (j - 1) & que){
                //cout << (mask | j) << " ";
                ans += (s[mask | j] - '0');
                
            }
            ans += (s[mask] - '0');
        }else if(__builtin_popcount(one) <= 6){
            int mask = que;
            for(int j = one;j; j = (j - 1) & one){
                if((__builtin_popcount(one) - __builtin_popcount(j)) & 1)ans -= small[mask | j];
                else ans += small[mask | j];
               
            }
            if((__builtin_popcount(one)) & 1)ans -= small[mask];
            else ans += small[mask];
        }else{
            int mask = one;
            for(int j = zero;j; j = (j - 1) & zero){
                if(__builtin_popcount(j) & 1)ans -= big[mask | j];
                else ans += big[mask | j];
            }
            ans += big[mask];
        }
        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 332 KB Output is correct
4 Correct 1 ms 340 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 332 KB Output is correct
4 Correct 1 ms 340 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 247 ms 12196 KB Output is correct
12 Correct 261 ms 11868 KB Output is correct
13 Correct 266 ms 11144 KB Output is correct
14 Correct 260 ms 11136 KB Output is correct
15 Correct 299 ms 12192 KB Output is correct
16 Correct 285 ms 11400 KB Output is correct
17 Correct 276 ms 11372 KB Output is correct
18 Correct 192 ms 13180 KB Output is correct
19 Correct 218 ms 10196 KB Output is correct
20 Correct 268 ms 11832 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 332 KB Output is correct
4 Correct 1 ms 340 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 247 ms 12196 KB Output is correct
12 Correct 261 ms 11868 KB Output is correct
13 Correct 266 ms 11144 KB Output is correct
14 Correct 260 ms 11136 KB Output is correct
15 Correct 299 ms 12192 KB Output is correct
16 Correct 285 ms 11400 KB Output is correct
17 Correct 276 ms 11372 KB Output is correct
18 Correct 192 ms 13180 KB Output is correct
19 Correct 218 ms 10196 KB Output is correct
20 Correct 268 ms 11832 KB Output is correct
21 Correct 371 ms 9980 KB Output is correct
22 Correct 320 ms 10188 KB Output is correct
23 Correct 363 ms 8856 KB Output is correct
24 Correct 321 ms 8720 KB Output is correct
25 Correct 287 ms 10764 KB Output is correct
26 Correct 348 ms 9260 KB Output is correct
27 Correct 344 ms 9276 KB Output is correct
28 Correct 200 ms 11932 KB Output is correct
29 Correct 287 ms 7972 KB Output is correct
30 Correct 357 ms 10180 KB Output is correct
31 Correct 354 ms 9996 KB Output is correct
32 Correct 351 ms 10064 KB Output is correct
33 Correct 294 ms 8892 KB Output is correct
34 Correct 338 ms 9036 KB Output is correct
35 Correct 359 ms 9412 KB Output is correct
36 Correct 216 ms 7928 KB Output is correct
37 Correct 331 ms 10156 KB Output is correct
38 Correct 279 ms 7936 KB Output is correct
39 Correct 318 ms 9196 KB Output is correct
40 Correct 329 ms 9036 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 332 KB Output is correct
4 Correct 1 ms 340 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 Incorrect 21 ms 10928 KB Output isn't correct
12 Halted 0 ms 0 KB -
# 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 332 KB Output is correct
4 Correct 1 ms 340 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 247 ms 12196 KB Output is correct
12 Correct 261 ms 11868 KB Output is correct
13 Correct 266 ms 11144 KB Output is correct
14 Correct 260 ms 11136 KB Output is correct
15 Correct 299 ms 12192 KB Output is correct
16 Correct 285 ms 11400 KB Output is correct
17 Correct 276 ms 11372 KB Output is correct
18 Correct 192 ms 13180 KB Output is correct
19 Correct 218 ms 10196 KB Output is correct
20 Correct 268 ms 11832 KB Output is correct
21 Correct 371 ms 9980 KB Output is correct
22 Correct 320 ms 10188 KB Output is correct
23 Correct 363 ms 8856 KB Output is correct
24 Correct 321 ms 8720 KB Output is correct
25 Correct 287 ms 10764 KB Output is correct
26 Correct 348 ms 9260 KB Output is correct
27 Correct 344 ms 9276 KB Output is correct
28 Correct 200 ms 11932 KB Output is correct
29 Correct 287 ms 7972 KB Output is correct
30 Correct 357 ms 10180 KB Output is correct
31 Correct 354 ms 9996 KB Output is correct
32 Correct 351 ms 10064 KB Output is correct
33 Correct 294 ms 8892 KB Output is correct
34 Correct 338 ms 9036 KB Output is correct
35 Correct 359 ms 9412 KB Output is correct
36 Correct 216 ms 7928 KB Output is correct
37 Correct 331 ms 10156 KB Output is correct
38 Correct 279 ms 7936 KB Output is correct
39 Correct 318 ms 9196 KB Output is correct
40 Correct 329 ms 9036 KB Output is correct
41 Incorrect 21 ms 10928 KB Output isn't correct
42 Halted 0 ms 0 KB -