답안 #1098876

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1098876 2024-10-10T09:28:25 Z steveonalex Snake Escaping (JOI18_snake_escaping) C++17
22 / 100
334 ms 19984 KB
#include <bits/stdc++.h>
 
using namespace std;
 
typedef long long ll;
typedef unsigned long long ull;
 
#define MASK(i) (1LL << (i))
#define GETBIT(mask, i) (((mask) >> (i)) & 1)
#define ALL(v) (v).begin(), (v).end()
#define block_of_code if(true)
 
ll max(ll a, ll b){return (a > b) ? a : b;}
ll min(ll a, ll b){return (a < b) ? a : b;}
ll gcd(ll a, ll b){return __gcd(a, b);}
ll lcm(ll a, ll b){return a / gcd(a, b) * b;}
 
ll LASTBIT(ll mask){return (mask) & (-mask);}
int pop_cnt(ll mask){return __builtin_popcountll(mask);}
int ctz(ull mask){return __builtin_ctzll(mask);}
int logOf(ull mask){return 63 - __builtin_clzll(mask);}
 
mt19937_64 rng(chrono::high_resolution_clock::now().time_since_epoch().count());
ll rngesus(ll l, ll r){return l + (ull) rng() % (r - l + 1);}
double rngesus_d(double l, double r){
    double cur = rngesus(0, MASK(60) - 1);
    cur /= MASK(60) - 1;
    return l + cur * (r - l);
}
 
template <class T1, class T2>
    bool maximize(T1 &a, T2 b){
        if (a < b) {a = b; return true;}
        return false;
    }
 
template <class T1, class T2>
    bool minimize(T1 &a, T2 b){
        if (a > b) {a = b; return true;}
        return false;
    }
 
template <class T>
    void printArr(T container, string separator = " ", string finish = "\n", ostream &out = cout){
        for(auto item: container) out << item << separator;
        out << finish;
    }
 
template <class T>
    void remove_dup(vector<T> &a){
        sort(ALL(a));
        a.resize(unique(ALL(a)) - a.begin());
    }
 
 
 
int main(void){
    ios::sync_with_stdio(0);cin.tie(0); cout.tie(0);
    clock_t start = clock();
 
    int l, q; cin >> l >> q;
    string s; cin >> s;
 
    int sum1[MASK(l)], sum2[MASK(l)];
    memset(sum1, 0, sizeof sum1);
    for(int i= 0; i<MASK(l); ++i){
        sum1[i] = s[i] - '0';
        sum2[i] = s[i] - '0';
    }
 
    for(int j = 0; j < l; ++j) for(int i = 0; i<MASK(l); ++i) if (GETBIT(i, j)){
        sum1[i] += sum1[i - MASK(j)];
    }
    for(int j = 0; j < l; ++j) for(int i = 0; i<MASK(l); ++i) if (!GETBIT(i, j)){
        sum2[i] += sum2[i + MASK(j)];
    }


 
    while(q--){
        string _s; cin >> _s;
        reverse(ALL(_s));
 
        int mask1 = 0, mask2 = 0;
        for(int i = 0; i<l; ++i) {
            if (_s[i] == '1') mask1 += MASK(i);
            else if (_s[i] == '?') mask2 += MASK(i);
        }
 
        if (pop_cnt(mask2) <= 6){
            int ans = 0;
            for(int mask = mask2; mask >= 0; mask = (mask - 1) & mask2){
                ans += s[mask + mask1] - '0';
                if (mask == 0) break;
            }
            cout << ans << "\n";
        }
        else if (pop_cnt(mask1) <= 6){
            int ans = 0;
            int cur_pop = pop_cnt(mask1);
            for(int mask = mask1; mask >= 0; mask = (mask - 1) & mask1){
                if ((pop_cnt(mask) & 1) == (cur_pop & 1)) ans += sum1[mask + mask2];
                else ans -= sum1[mask + mask2];
                if (mask == 0) break;
            }
            cout << ans << "\n";
        }
        else{
            int ans = 0;
            int mask3 = (MASK(l) - 1) ^ mask1 ^ mask2;
            for(int mask = mask3; mask >= 0; mask = (mask - 1) & mask3){
                if (pop_cnt(mask) & 1) ans -= sum2[mask1 + mask];
                else ans += sum1[mask1 + mask];
                if (mask == 0) break;
            }
            cout << ans << "\n";
        }
    }
 
    cerr << "Time elapsed: " << clock() - start << " ms\n";
    return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Correct 0 ms 472 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 1 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Correct 0 ms 472 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 1 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 168 ms 15008 KB Output is correct
12 Correct 141 ms 14712 KB Output is correct
13 Correct 139 ms 13904 KB Output is correct
14 Correct 142 ms 14032 KB Output is correct
15 Correct 183 ms 15012 KB Output is correct
16 Correct 166 ms 14292 KB Output is correct
17 Correct 174 ms 14160 KB Output is correct
18 Correct 121 ms 16212 KB Output is correct
19 Correct 147 ms 13136 KB Output is correct
20 Correct 182 ms 14676 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Correct 0 ms 472 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 1 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 168 ms 15008 KB Output is correct
12 Correct 141 ms 14712 KB Output is correct
13 Correct 139 ms 13904 KB Output is correct
14 Correct 142 ms 14032 KB Output is correct
15 Correct 183 ms 15012 KB Output is correct
16 Correct 166 ms 14292 KB Output is correct
17 Correct 174 ms 14160 KB Output is correct
18 Correct 121 ms 16212 KB Output is correct
19 Correct 147 ms 13136 KB Output is correct
20 Correct 182 ms 14676 KB Output is correct
21 Correct 334 ms 18000 KB Output is correct
22 Correct 152 ms 18260 KB Output is correct
23 Correct 181 ms 17236 KB Output is correct
24 Correct 186 ms 16976 KB Output is correct
25 Correct 162 ms 19068 KB Output is correct
26 Correct 189 ms 17688 KB Output is correct
27 Correct 180 ms 17492 KB Output is correct
28 Correct 122 ms 19984 KB Output is correct
29 Correct 150 ms 16168 KB Output is correct
30 Correct 240 ms 18260 KB Output is correct
31 Correct 207 ms 18112 KB Output is correct
32 Correct 179 ms 18004 KB Output is correct
33 Correct 171 ms 16980 KB Output is correct
34 Correct 173 ms 17060 KB Output is correct
35 Correct 187 ms 17492 KB Output is correct
36 Correct 107 ms 16064 KB Output is correct
37 Correct 165 ms 18092 KB Output is correct
38 Correct 171 ms 16212 KB Output is correct
39 Correct 182 ms 17236 KB Output is correct
40 Correct 171 ms 17208 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Correct 0 ms 472 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 1 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Incorrect 57 ms 12020 KB Output isn't correct
12 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Correct 0 ms 472 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 1 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 168 ms 15008 KB Output is correct
12 Correct 141 ms 14712 KB Output is correct
13 Correct 139 ms 13904 KB Output is correct
14 Correct 142 ms 14032 KB Output is correct
15 Correct 183 ms 15012 KB Output is correct
16 Correct 166 ms 14292 KB Output is correct
17 Correct 174 ms 14160 KB Output is correct
18 Correct 121 ms 16212 KB Output is correct
19 Correct 147 ms 13136 KB Output is correct
20 Correct 182 ms 14676 KB Output is correct
21 Correct 334 ms 18000 KB Output is correct
22 Correct 152 ms 18260 KB Output is correct
23 Correct 181 ms 17236 KB Output is correct
24 Correct 186 ms 16976 KB Output is correct
25 Correct 162 ms 19068 KB Output is correct
26 Correct 189 ms 17688 KB Output is correct
27 Correct 180 ms 17492 KB Output is correct
28 Correct 122 ms 19984 KB Output is correct
29 Correct 150 ms 16168 KB Output is correct
30 Correct 240 ms 18260 KB Output is correct
31 Correct 207 ms 18112 KB Output is correct
32 Correct 179 ms 18004 KB Output is correct
33 Correct 171 ms 16980 KB Output is correct
34 Correct 173 ms 17060 KB Output is correct
35 Correct 187 ms 17492 KB Output is correct
36 Correct 107 ms 16064 KB Output is correct
37 Correct 165 ms 18092 KB Output is correct
38 Correct 171 ms 16212 KB Output is correct
39 Correct 182 ms 17236 KB Output is correct
40 Correct 171 ms 17208 KB Output is correct
41 Incorrect 57 ms 12020 KB Output isn't correct
42 Halted 0 ms 0 KB -