답안 #533925

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
533925 2022-03-07T15:57:44 Z radal Snake Escaping (JOI18_snake_escaping) C++14
75 / 100
2000 ms 22952 KB
#include <bits/stdc++.h>
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,avx2,tune=native")
#pragma GCC optimize("unroll-loops")
#define rep(i,l,r) for (int i = l; i < r; i++)
#define repr(i,r,l) for (int i = r; i >= l; i--)
#define X first
#define Y second
#define pb push_back
#define endl '\n'
#define debug(x) cerr << #x << " : " << x << endl;
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> pll;
constexpr ll N = 2e6+20,mod = 1e9+7,inf = 1e9+10,maxm = 1e6;
inline int mkay(int a,int b){
    if (a+b >= mod) return a+b-mod;
    if (a+b < 0) return a+b+mod;
    return a+b;
}

inline int poww(int a,int k){
    if (k < 0) return 0;
    int z = 1;
    while (k){
        if (k&1) z = 1ll*z*a%mod;
        a = 1ll*a*a%mod;
        k >>= 1;
    }
    return z;
}
int sos[N][2][2];
int main(){
    ios :: sync_with_stdio(0); cin.tie(0);
    int l,q;
    cin >> l >> q;
    string s;
    cin >> s;
    int n = s.size();
    rep(i,0,n)
        sos[i][(l&1)][1] = sos[i][(l&1)][0] = (s[i]-'0');
    repr(j,l-1,0){
        bool d = (j&1);
        rep(i,0,n){
            sos[i][d][0] = sos[i][1-d][0];
            sos[i][d][1] = sos[i][1-d][1];
            if (i&(1 << j))
                sos[i][d][1] += sos[i-(1 << j)][!d][1];
            else
                sos[i][d][0] += sos[i+(1 << j)][!d][0];
        }
    }
    while (q--){
        string t;
        cin >> t;
        reverse(t.begin(),t.end());
        int t0 = 0,t2 = 0,t1 = 0,mask = 0;
        vector<int> ve;
        rep(i,0,l){
            if (t[i] == '1'){
                t1++;
                mask += (1 << i);
            }
            else if (t[i] == '0') t0++;
            else
                t2++;
        }
        if (t2 < 7){
            rep(i,0,l) if (t[i] == '?') ve.pb(i);
            int y = (1 << t2);
            int ans = 0;
            rep(j,0,y){
                int sum = mask;
                rep(k,0,t2)
                    if (j&(1 << k)) 
                        sum += (1 << ve[k]);
                ans += (s[sum]-'0');
            }
            cout << ans << endl;
            continue;
        }
        if (t1 <= t0){
            rep(i,0,l){
                if (t[i] == '1') ve.pb(i);
                if (t[i] == '?') mask += (1 << i);
            }
            int y = (1 << t1),ans = 0;
            rep(i,0,y){
                int cnt = 0,sum = mask;
                rep(j,0,t1){
                    if ((1 << j)&i){
                        sum -= (1 << ve[j]);
                        cnt ^= 1;
                    }
                }
                if (cnt) ans -= sos[sum][0][1];
                else ans += sos[sum][0][1];
            }
            cout << ans << endl;
            continue;
        }
        rep(i,0,l)
            if (t[i] == '0')
                ve.pb(i);
        int y = (1 << t0),ans = 0;
        rep(i,0,y){
            int cnt = 0,sum = mask;
            rep(j,0,t0)
                if ((1 << j)&i){
                    sum += (1 << ve[j]);
                    cnt ^= 1;
                }
            if (cnt) ans -= sos[sum][0][0];
            else ans += sos[sum][0][0];
        }
        cout << ans << endl;
    }
}
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 332 KB Output is correct
2 Correct 1 ms 328 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 2 ms 332 KB Output is correct
5 Correct 2 ms 332 KB Output is correct
6 Correct 1 ms 332 KB Output is correct
7 Correct 1 ms 332 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 332 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 332 KB Output is correct
2 Correct 1 ms 328 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 2 ms 332 KB Output is correct
5 Correct 2 ms 332 KB Output is correct
6 Correct 1 ms 332 KB Output is correct
7 Correct 1 ms 332 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 332 KB Output is correct
11 Correct 590 ms 5180 KB Output is correct
12 Correct 638 ms 4820 KB Output is correct
13 Correct 401 ms 4152 KB Output is correct
14 Correct 386 ms 4164 KB Output is correct
15 Correct 928 ms 5164 KB Output is correct
16 Correct 501 ms 4488 KB Output is correct
17 Correct 531 ms 4260 KB Output is correct
18 Correct 199 ms 6212 KB Output is correct
19 Correct 201 ms 3220 KB Output is correct
20 Correct 578 ms 4956 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 332 KB Output is correct
2 Correct 1 ms 328 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 2 ms 332 KB Output is correct
5 Correct 2 ms 332 KB Output is correct
6 Correct 1 ms 332 KB Output is correct
7 Correct 1 ms 332 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 332 KB Output is correct
11 Correct 590 ms 5180 KB Output is correct
12 Correct 638 ms 4820 KB Output is correct
13 Correct 401 ms 4152 KB Output is correct
14 Correct 386 ms 4164 KB Output is correct
15 Correct 928 ms 5164 KB Output is correct
16 Correct 501 ms 4488 KB Output is correct
17 Correct 531 ms 4260 KB Output is correct
18 Correct 199 ms 6212 KB Output is correct
19 Correct 201 ms 3220 KB Output is correct
20 Correct 578 ms 4956 KB Output is correct
21 Correct 244 ms 5336 KB Output is correct
22 Correct 632 ms 5476 KB Output is correct
23 Correct 526 ms 4512 KB Output is correct
24 Correct 487 ms 4348 KB Output is correct
25 Correct 361 ms 6264 KB Output is correct
26 Correct 644 ms 4732 KB Output is correct
27 Correct 637 ms 4700 KB Output is correct
28 Correct 192 ms 7392 KB Output is correct
29 Correct 234 ms 3396 KB Output is correct
30 Correct 547 ms 5428 KB Output is correct
31 Correct 1052 ms 5300 KB Output is correct
32 Correct 679 ms 5316 KB Output is correct
33 Correct 421 ms 4244 KB Output is correct
34 Correct 564 ms 4264 KB Output is correct
35 Correct 615 ms 4784 KB Output is correct
36 Correct 196 ms 3336 KB Output is correct
37 Correct 968 ms 5276 KB Output is correct
38 Correct 236 ms 3140 KB Output is correct
39 Correct 597 ms 4364 KB Output is correct
40 Correct 509 ms 4048 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 332 KB Output is correct
2 Correct 1 ms 328 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 2 ms 332 KB Output is correct
5 Correct 2 ms 332 KB Output is correct
6 Correct 1 ms 332 KB Output is correct
7 Correct 1 ms 332 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 332 KB Output is correct
11 Correct 76 ms 18860 KB Output is correct
12 Correct 85 ms 18648 KB Output is correct
13 Correct 104 ms 18512 KB Output is correct
14 Correct 172 ms 18548 KB Output is correct
15 Correct 85 ms 18648 KB Output is correct
16 Correct 147 ms 18660 KB Output is correct
17 Correct 135 ms 18520 KB Output is correct
18 Correct 68 ms 18740 KB Output is correct
19 Correct 74 ms 18404 KB Output is correct
20 Correct 83 ms 18652 KB Output is correct
21 Correct 141 ms 18568 KB Output is correct
22 Correct 150 ms 18512 KB Output is correct
23 Correct 99 ms 18520 KB Output is correct
24 Correct 129 ms 18532 KB Output is correct
25 Correct 125 ms 18472 KB Output is correct
26 Correct 66 ms 18400 KB Output is correct
27 Correct 82 ms 18524 KB Output is correct
28 Correct 74 ms 18396 KB Output is correct
29 Correct 106 ms 18524 KB Output is correct
30 Correct 111 ms 18500 KB Output is correct
31 Correct 91 ms 18436 KB Output is correct
32 Correct 145 ms 18608 KB Output is correct
33 Correct 120 ms 18476 KB Output is correct
34 Correct 68 ms 18400 KB Output is correct
35 Correct 112 ms 18584 KB Output is correct
36 Correct 111 ms 18532 KB Output is correct
37 Correct 102 ms 18524 KB Output is correct
38 Correct 105 ms 18528 KB Output is correct
39 Correct 108 ms 18564 KB Output is correct
40 Correct 115 ms 18524 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 332 KB Output is correct
2 Correct 1 ms 328 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 2 ms 332 KB Output is correct
5 Correct 2 ms 332 KB Output is correct
6 Correct 1 ms 332 KB Output is correct
7 Correct 1 ms 332 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 332 KB Output is correct
11 Correct 590 ms 5180 KB Output is correct
12 Correct 638 ms 4820 KB Output is correct
13 Correct 401 ms 4152 KB Output is correct
14 Correct 386 ms 4164 KB Output is correct
15 Correct 928 ms 5164 KB Output is correct
16 Correct 501 ms 4488 KB Output is correct
17 Correct 531 ms 4260 KB Output is correct
18 Correct 199 ms 6212 KB Output is correct
19 Correct 201 ms 3220 KB Output is correct
20 Correct 578 ms 4956 KB Output is correct
21 Correct 244 ms 5336 KB Output is correct
22 Correct 632 ms 5476 KB Output is correct
23 Correct 526 ms 4512 KB Output is correct
24 Correct 487 ms 4348 KB Output is correct
25 Correct 361 ms 6264 KB Output is correct
26 Correct 644 ms 4732 KB Output is correct
27 Correct 637 ms 4700 KB Output is correct
28 Correct 192 ms 7392 KB Output is correct
29 Correct 234 ms 3396 KB Output is correct
30 Correct 547 ms 5428 KB Output is correct
31 Correct 1052 ms 5300 KB Output is correct
32 Correct 679 ms 5316 KB Output is correct
33 Correct 421 ms 4244 KB Output is correct
34 Correct 564 ms 4264 KB Output is correct
35 Correct 615 ms 4784 KB Output is correct
36 Correct 196 ms 3336 KB Output is correct
37 Correct 968 ms 5276 KB Output is correct
38 Correct 236 ms 3140 KB Output is correct
39 Correct 597 ms 4364 KB Output is correct
40 Correct 509 ms 4048 KB Output is correct
41 Correct 76 ms 18860 KB Output is correct
42 Correct 85 ms 18648 KB Output is correct
43 Correct 104 ms 18512 KB Output is correct
44 Correct 172 ms 18548 KB Output is correct
45 Correct 85 ms 18648 KB Output is correct
46 Correct 147 ms 18660 KB Output is correct
47 Correct 135 ms 18520 KB Output is correct
48 Correct 68 ms 18740 KB Output is correct
49 Correct 74 ms 18404 KB Output is correct
50 Correct 83 ms 18652 KB Output is correct
51 Correct 141 ms 18568 KB Output is correct
52 Correct 150 ms 18512 KB Output is correct
53 Correct 99 ms 18520 KB Output is correct
54 Correct 129 ms 18532 KB Output is correct
55 Correct 125 ms 18472 KB Output is correct
56 Correct 66 ms 18400 KB Output is correct
57 Correct 82 ms 18524 KB Output is correct
58 Correct 74 ms 18396 KB Output is correct
59 Correct 106 ms 18524 KB Output is correct
60 Correct 111 ms 18500 KB Output is correct
61 Correct 91 ms 18436 KB Output is correct
62 Correct 145 ms 18608 KB Output is correct
63 Correct 120 ms 18476 KB Output is correct
64 Correct 68 ms 18400 KB Output is correct
65 Correct 112 ms 18584 KB Output is correct
66 Correct 111 ms 18532 KB Output is correct
67 Correct 102 ms 18524 KB Output is correct
68 Correct 105 ms 18528 KB Output is correct
69 Correct 108 ms 18564 KB Output is correct
70 Correct 115 ms 18524 KB Output is correct
71 Correct 490 ms 22884 KB Output is correct
72 Correct 694 ms 22952 KB Output is correct
73 Correct 892 ms 21628 KB Output is correct
74 Execution timed out 2065 ms 21448 KB Time limit exceeded
75 Halted 0 ms 0 KB -