Submission #334791

# Submission time Handle Problem Language Result Execution time Memory
334791 2020-12-10T02:00:50 Z HoneyBadger Snake Escaping (JOI18_snake_escaping) C++17
100 / 100
1263 ms 24816 KB
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <vector>
#include <bitset>
#include <string>
#include <cstring>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <deque>
#include <utility>
#include <algorithm>
#include <random>
#include <cmath>
#include <cassert>
#include <climits>
#include <ctime>
#include <chrono>
 
 
 
#pragma GCC optimize("Ofast")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,sse4.1,sse4.2,popcnt,abm,mmx,avx,avx2,tune=native")
 
 
 
#ifdef LOCAL
    #define dbg(x) cout << #x << " : " << x << endl;
#else
    #define dbg(x)
#endif
 
 
#define pb push_back
#define ppb pop_back()
#define mp make_pair
#define fi(a, b) for (int i = a; i < b; i++)
#define fj(a, b) for (int j = a; j < b; j++)
#define fk(a, b) for (int k = a; k < b; k++)
#define fi1(a, b) for (int i = a - 1; i >= b; i--)
#define fj1(a, b) for (int j = a - 1; j >= b; j--)
#define fk1(a, b) for (int k = a - 1; k >= b; k--)
#define fx(x, a) for (auto& x : a)
#define rep(i, a, b) for (int i = a; i < b; ++i)
#define rep1(i, a, b) for (int i = a - 1; i >= b; --i)
#define siz(x) (int)x.size()
#define lb lower_bound
#define ub upper_bound
#define all(x) x.begin(), x.end()
 
using namespace std;
 
template<typename T1, typename T2>inline void mine(T1 &x, const T2 &y) { if (y < x) x = y; }
template<typename T1, typename T2>inline void maxe(T1 &x, const T2 &y) { if (x < y) x = y; }
 
ostream& operator << (ostream &out, const vector<int> &b) {
    for (auto k : b) out << k << ' ';
    return out;
}
 
typedef long long ll;
typedef long double ld;
typedef char ch;
typedef string str;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<pii> vpii;
typedef vector<vpii> vvpii;
typedef vector<ch> vch;
typedef vector<vch> vvch;
typedef vector<str> vs;
 
 
 
const int MOD = 1000000007;
const int INF = 1000000050;
const long long BIG = (long long)2e18 + 50;
const int MX = 1 << 20;
const int PW = 20;
const double EPS = 1e-9;
 
 
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
 
int n, q;
int a[MX];
int sos1[MX];
int sos0[MX];
int bits[MX];
 
void calc() {
    for (int mask = 0; mask < (1 << n); ++mask) {
        sos1[mask] = a[mask];
        sos0[mask] = a[mask];
        bits[mask] = bits[mask >> 1] + (mask & 1);
    }
    for (int i = 0; i < n; ++i) {
        for (int mask = 0; mask < (1 << n); ++mask) {
            if ((mask >> i) & 1) {
                sos1[mask] += sos1[mask ^ (1 << i)];
            } else {
                sos0[mask] += sos0[mask ^ (1 << i)];
            }
        }
    }
 
}
 
int32_t main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
 
    cin >> n >> q;
    for (int i = 0; i < (1 << n); ++i) {
        char c;
        cin >> c;
        a[i] = c - '0';
    }
 
    calc();
    while (q--) {
        int mq = 0, m0 = 0, m1 = 0;
        fi(0, n) {
            char c;
            cin >> c;
            mq = (mq << 1) | (c == '?');
            m0 = (m0 << 1) | (c == '0');
            m1 = (m1 << 1) | (c == '1');
        }
        int ans = 0;
        if (bits[mq] < 7) {
            for (int mask = mq;;mask = (mask - 1) & mq) {
                ans += a[m1 ^ mask];
                if (!mask) break;
            }
        } else if (bits[m0] < 7) {
            for (int mask = m0;;mask = (mask - 1) & m0) {
                ans += sos0[m1 ^ mask] * (bits[mask] % 2 ? -1 : 1);
                if (!mask) break;
            }
        } else {
            for (int mask = m1;;mask = (mask - 1) & m1) {
                ans += sos1[mq ^ mask] * (bits[mask ^ m1] % 2 ? -1 : 1);
                if (!mask) break;
            }
        }
        cout << ans << '\n';
    }
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 368 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 1 ms 364 KB Output is correct
6 Correct 1 ms 364 KB Output is correct
7 Correct 1 ms 364 KB Output is correct
8 Correct 1 ms 364 KB Output is correct
9 Correct 1 ms 364 KB Output is correct
10 Correct 1 ms 364 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 368 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 1 ms 364 KB Output is correct
6 Correct 1 ms 364 KB Output is correct
7 Correct 1 ms 364 KB Output is correct
8 Correct 1 ms 364 KB Output is correct
9 Correct 1 ms 364 KB Output is correct
10 Correct 1 ms 364 KB Output is correct
11 Correct 299 ms 4460 KB Output is correct
12 Correct 304 ms 4076 KB Output is correct
13 Correct 297 ms 3308 KB Output is correct
14 Correct 276 ms 3460 KB Output is correct
15 Correct 371 ms 4496 KB Output is correct
16 Correct 298 ms 3632 KB Output is correct
17 Correct 286 ms 3564 KB Output is correct
18 Correct 268 ms 5484 KB Output is correct
19 Correct 275 ms 2460 KB Output is correct
20 Correct 315 ms 4228 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 368 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 1 ms 364 KB Output is correct
6 Correct 1 ms 364 KB Output is correct
7 Correct 1 ms 364 KB Output is correct
8 Correct 1 ms 364 KB Output is correct
9 Correct 1 ms 364 KB Output is correct
10 Correct 1 ms 364 KB Output is correct
11 Correct 299 ms 4460 KB Output is correct
12 Correct 304 ms 4076 KB Output is correct
13 Correct 297 ms 3308 KB Output is correct
14 Correct 276 ms 3460 KB Output is correct
15 Correct 371 ms 4496 KB Output is correct
16 Correct 298 ms 3632 KB Output is correct
17 Correct 286 ms 3564 KB Output is correct
18 Correct 268 ms 5484 KB Output is correct
19 Correct 275 ms 2460 KB Output is correct
20 Correct 315 ms 4228 KB Output is correct
21 Correct 316 ms 4492 KB Output is correct
22 Correct 432 ms 4760 KB Output is correct
23 Correct 348 ms 3836 KB Output is correct
24 Correct 376 ms 3564 KB Output is correct
25 Correct 364 ms 5536 KB Output is correct
26 Correct 390 ms 4072 KB Output is correct
27 Correct 362 ms 4008 KB Output is correct
28 Correct 349 ms 6588 KB Output is correct
29 Correct 315 ms 2544 KB Output is correct
30 Correct 361 ms 4844 KB Output is correct
31 Correct 402 ms 4844 KB Output is correct
32 Correct 351 ms 4716 KB Output is correct
33 Correct 329 ms 3692 KB Output is correct
34 Correct 329 ms 3948 KB Output is correct
35 Correct 354 ms 4460 KB Output is correct
36 Correct 313 ms 2872 KB Output is correct
37 Correct 396 ms 4844 KB Output is correct
38 Correct 313 ms 2924 KB Output is correct
39 Correct 336 ms 4024 KB Output is correct
40 Correct 339 ms 4076 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 368 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 1 ms 364 KB Output is correct
6 Correct 1 ms 364 KB Output is correct
7 Correct 1 ms 364 KB Output is correct
8 Correct 1 ms 364 KB Output is correct
9 Correct 1 ms 364 KB Output is correct
10 Correct 1 ms 364 KB Output is correct
11 Correct 79 ms 17388 KB Output is correct
12 Correct 79 ms 17388 KB Output is correct
13 Correct 86 ms 17260 KB Output is correct
14 Correct 110 ms 17388 KB Output is correct
15 Correct 84 ms 17388 KB Output is correct
16 Correct 106 ms 17004 KB Output is correct
17 Correct 101 ms 17004 KB Output is correct
18 Correct 74 ms 17132 KB Output is correct
19 Correct 73 ms 16876 KB Output is correct
20 Correct 78 ms 17004 KB Output is correct
21 Correct 91 ms 17004 KB Output is correct
22 Correct 124 ms 17004 KB Output is correct
23 Correct 78 ms 16876 KB Output is correct
24 Correct 89 ms 17288 KB Output is correct
25 Correct 100 ms 17388 KB Output is correct
26 Correct 72 ms 17260 KB Output is correct
27 Correct 78 ms 17388 KB Output is correct
28 Correct 85 ms 17260 KB Output is correct
29 Correct 89 ms 17260 KB Output is correct
30 Correct 87 ms 17260 KB Output is correct
31 Correct 90 ms 17260 KB Output is correct
32 Correct 109 ms 17404 KB Output is correct
33 Correct 107 ms 17388 KB Output is correct
34 Correct 73 ms 17260 KB Output is correct
35 Correct 98 ms 17388 KB Output is correct
36 Correct 100 ms 17388 KB Output is correct
37 Correct 94 ms 17388 KB Output is correct
38 Correct 103 ms 17388 KB Output is correct
39 Correct 93 ms 17388 KB Output is correct
40 Correct 92 ms 17388 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 368 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 1 ms 364 KB Output is correct
6 Correct 1 ms 364 KB Output is correct
7 Correct 1 ms 364 KB Output is correct
8 Correct 1 ms 364 KB Output is correct
9 Correct 1 ms 364 KB Output is correct
10 Correct 1 ms 364 KB Output is correct
11 Correct 299 ms 4460 KB Output is correct
12 Correct 304 ms 4076 KB Output is correct
13 Correct 297 ms 3308 KB Output is correct
14 Correct 276 ms 3460 KB Output is correct
15 Correct 371 ms 4496 KB Output is correct
16 Correct 298 ms 3632 KB Output is correct
17 Correct 286 ms 3564 KB Output is correct
18 Correct 268 ms 5484 KB Output is correct
19 Correct 275 ms 2460 KB Output is correct
20 Correct 315 ms 4228 KB Output is correct
21 Correct 316 ms 4492 KB Output is correct
22 Correct 432 ms 4760 KB Output is correct
23 Correct 348 ms 3836 KB Output is correct
24 Correct 376 ms 3564 KB Output is correct
25 Correct 364 ms 5536 KB Output is correct
26 Correct 390 ms 4072 KB Output is correct
27 Correct 362 ms 4008 KB Output is correct
28 Correct 349 ms 6588 KB Output is correct
29 Correct 315 ms 2544 KB Output is correct
30 Correct 361 ms 4844 KB Output is correct
31 Correct 402 ms 4844 KB Output is correct
32 Correct 351 ms 4716 KB Output is correct
33 Correct 329 ms 3692 KB Output is correct
34 Correct 329 ms 3948 KB Output is correct
35 Correct 354 ms 4460 KB Output is correct
36 Correct 313 ms 2872 KB Output is correct
37 Correct 396 ms 4844 KB Output is correct
38 Correct 313 ms 2924 KB Output is correct
39 Correct 336 ms 4024 KB Output is correct
40 Correct 339 ms 4076 KB Output is correct
41 Correct 79 ms 17388 KB Output is correct
42 Correct 79 ms 17388 KB Output is correct
43 Correct 86 ms 17260 KB Output is correct
44 Correct 110 ms 17388 KB Output is correct
45 Correct 84 ms 17388 KB Output is correct
46 Correct 106 ms 17004 KB Output is correct
47 Correct 101 ms 17004 KB Output is correct
48 Correct 74 ms 17132 KB Output is correct
49 Correct 73 ms 16876 KB Output is correct
50 Correct 78 ms 17004 KB Output is correct
51 Correct 91 ms 17004 KB Output is correct
52 Correct 124 ms 17004 KB Output is correct
53 Correct 78 ms 16876 KB Output is correct
54 Correct 89 ms 17288 KB Output is correct
55 Correct 100 ms 17388 KB Output is correct
56 Correct 72 ms 17260 KB Output is correct
57 Correct 78 ms 17388 KB Output is correct
58 Correct 85 ms 17260 KB Output is correct
59 Correct 89 ms 17260 KB Output is correct
60 Correct 87 ms 17260 KB Output is correct
61 Correct 90 ms 17260 KB Output is correct
62 Correct 109 ms 17404 KB Output is correct
63 Correct 107 ms 17388 KB Output is correct
64 Correct 73 ms 17260 KB Output is correct
65 Correct 98 ms 17388 KB Output is correct
66 Correct 100 ms 17388 KB Output is correct
67 Correct 94 ms 17388 KB Output is correct
68 Correct 103 ms 17388 KB Output is correct
69 Correct 93 ms 17388 KB Output is correct
70 Correct 92 ms 17388 KB Output is correct
71 Correct 611 ms 22124 KB Output is correct
72 Correct 643 ms 22100 KB Output is correct
73 Correct 717 ms 20628 KB Output is correct
74 Correct 1136 ms 20784 KB Output is correct
75 Correct 660 ms 22804 KB Output is correct
76 Correct 1263 ms 21228 KB Output is correct
77 Correct 1092 ms 21004 KB Output is correct
78 Correct 497 ms 24816 KB Output is correct
79 Correct 537 ms 18732 KB Output is correct
80 Correct 618 ms 21868 KB Output is correct
81 Correct 865 ms 21776 KB Output is correct
82 Correct 1097 ms 21004 KB Output is correct
83 Correct 543 ms 19900 KB Output is correct
84 Correct 872 ms 20752 KB Output is correct
85 Correct 1038 ms 21124 KB Output is correct
86 Correct 473 ms 18784 KB Output is correct
87 Correct 599 ms 21916 KB Output is correct
88 Correct 551 ms 18828 KB Output is correct
89 Correct 726 ms 20516 KB Output is correct
90 Correct 843 ms 20844 KB Output is correct
91 Correct 556 ms 20008 KB Output is correct
92 Correct 1210 ms 21116 KB Output is correct
93 Correct 1044 ms 21100 KB Output is correct
94 Correct 462 ms 18796 KB Output is correct
95 Correct 895 ms 20844 KB Output is correct
96 Correct 905 ms 21100 KB Output is correct
97 Correct 903 ms 21132 KB Output is correct
98 Correct 917 ms 20876 KB Output is correct
99 Correct 897 ms 20844 KB Output is correct
100 Correct 919 ms 21100 KB Output is correct