Submission #792443

# Submission time Handle Problem Language Result Execution time Memory
792443 2023-07-25T04:58:48 Z Cookie Snake Escaping (JOI18_snake_escaping) C++14
22 / 100
2000 ms 20120 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)];
char s[(1 << 20)];
signed main()
{
     ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); 
    cin >> l >> q;
    for(int i = 0; i < (1 << l); i++){
        cin >> s[i];
        big[i] = (s[i] - '0'); small[i] = (s[i] - '0');
    }
    for(int i = 0; i < 20; i++){
        for(int j = 0; j < (1 << l); j++){
            if(j & (1 << i))small[j] += small[j ^ (1 << i)];
            if(!(j & (1 << i)))big[j] = big[j ^ (1 << i)];
        }
    }
    while(q--){
        string ss; cin >> ss;
        reverse(ss.begin(), ss.end());
        int zero = 0, one = 0, que = 0;
        for(int i = 0; i < l; i++){
            if(ss[i] == '0')zero += (1 << i);
            else if(ss[i] == '1')one += (1 << i);
            else que += (1 << i);
        }
        int ans = 0;
        if(__builtin_popcount(que) <= 6){
            int mask = one;
            for(int j = que;; j = (j - 1) & que){
                //cout << (mask | j) << " ";
                ans += (s[mask | j] - '0');
                if(j == 0)break;
            }
        }else if(__builtin_popcount(one) <= 6){
            int mask = que;
            for(int j = one;; j = (j - 1) & one){
                if((__builtin_popcount(one) - __builtin_popcount(j)) & 1)ans -= small[mask | j];
                else ans += small[mask | j];
                if(j == 0)break;
            }
        }else{
            int mask = one;
            for(int j = zero;; j = (j - 1) & zero){
                if(__builtin_popcount(j) & 1)ans -= big[mask | j];
                else ans += big[mask | j];
            }
        }
        cout << ans << "\n";
    }
    return(0);
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 332 KB Output is correct
3 Correct 1 ms 340 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 332 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 1 ms 332 KB Output is correct
9 Correct 1 ms 336 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 332 KB Output is correct
3 Correct 1 ms 340 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 332 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 1 ms 332 KB Output is correct
9 Correct 1 ms 336 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 225 ms 15096 KB Output is correct
12 Correct 223 ms 14756 KB Output is correct
13 Correct 204 ms 13924 KB Output is correct
14 Correct 197 ms 14116 KB Output is correct
15 Correct 244 ms 15124 KB Output is correct
16 Correct 223 ms 14292 KB Output is correct
17 Correct 236 ms 14172 KB Output is correct
18 Correct 168 ms 16148 KB Output is correct
19 Correct 177 ms 13032 KB Output is correct
20 Correct 227 ms 14724 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 332 KB Output is correct
3 Correct 1 ms 340 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 332 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 1 ms 332 KB Output is correct
9 Correct 1 ms 336 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 225 ms 15096 KB Output is correct
12 Correct 223 ms 14756 KB Output is correct
13 Correct 204 ms 13924 KB Output is correct
14 Correct 197 ms 14116 KB Output is correct
15 Correct 244 ms 15124 KB Output is correct
16 Correct 223 ms 14292 KB Output is correct
17 Correct 236 ms 14172 KB Output is correct
18 Correct 168 ms 16148 KB Output is correct
19 Correct 177 ms 13032 KB Output is correct
20 Correct 227 ms 14724 KB Output is correct
21 Correct 324 ms 18072 KB Output is correct
22 Correct 235 ms 18232 KB Output is correct
23 Correct 253 ms 17192 KB Output is correct
24 Correct 253 ms 17116 KB Output is correct
25 Correct 228 ms 19056 KB Output is correct
26 Correct 247 ms 17608 KB Output is correct
27 Correct 269 ms 17596 KB Output is correct
28 Correct 163 ms 20120 KB Output is correct
29 Correct 201 ms 16016 KB Output is correct
30 Correct 267 ms 18284 KB Output is correct
31 Correct 282 ms 18092 KB Output is correct
32 Correct 250 ms 18032 KB Output is correct
33 Correct 208 ms 16944 KB Output is correct
34 Correct 233 ms 17036 KB Output is correct
35 Correct 249 ms 17516 KB Output is correct
36 Correct 149 ms 16084 KB Output is correct
37 Correct 252 ms 18144 KB Output is correct
38 Correct 205 ms 16056 KB Output is correct
39 Correct 229 ms 17308 KB Output is correct
40 Correct 224 ms 17068 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 332 KB Output is correct
3 Correct 1 ms 340 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 332 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 1 ms 332 KB Output is correct
9 Correct 1 ms 336 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Execution timed out 2071 ms 10708 KB Time limit exceeded
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 332 KB Output is correct
3 Correct 1 ms 340 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 332 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 1 ms 332 KB Output is correct
9 Correct 1 ms 336 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 225 ms 15096 KB Output is correct
12 Correct 223 ms 14756 KB Output is correct
13 Correct 204 ms 13924 KB Output is correct
14 Correct 197 ms 14116 KB Output is correct
15 Correct 244 ms 15124 KB Output is correct
16 Correct 223 ms 14292 KB Output is correct
17 Correct 236 ms 14172 KB Output is correct
18 Correct 168 ms 16148 KB Output is correct
19 Correct 177 ms 13032 KB Output is correct
20 Correct 227 ms 14724 KB Output is correct
21 Correct 324 ms 18072 KB Output is correct
22 Correct 235 ms 18232 KB Output is correct
23 Correct 253 ms 17192 KB Output is correct
24 Correct 253 ms 17116 KB Output is correct
25 Correct 228 ms 19056 KB Output is correct
26 Correct 247 ms 17608 KB Output is correct
27 Correct 269 ms 17596 KB Output is correct
28 Correct 163 ms 20120 KB Output is correct
29 Correct 201 ms 16016 KB Output is correct
30 Correct 267 ms 18284 KB Output is correct
31 Correct 282 ms 18092 KB Output is correct
32 Correct 250 ms 18032 KB Output is correct
33 Correct 208 ms 16944 KB Output is correct
34 Correct 233 ms 17036 KB Output is correct
35 Correct 249 ms 17516 KB Output is correct
36 Correct 149 ms 16084 KB Output is correct
37 Correct 252 ms 18144 KB Output is correct
38 Correct 205 ms 16056 KB Output is correct
39 Correct 229 ms 17308 KB Output is correct
40 Correct 224 ms 17068 KB Output is correct
41 Execution timed out 2071 ms 10708 KB Time limit exceeded
42 Halted 0 ms 0 KB -