답안 #889854

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
889854 2023-12-20T08:19:04 Z hariaakas646 Snake Escaping (JOI18_snake_escaping) C++17
100 / 100
1682 ms 55796 KB
#include <bits/stdc++.h>

using namespace std;

#define scd(t) scanf("%d", &t)
#define sclld(t) scanf("%lld", &t)
#define forr(i, j, k) for (int i = j; i < k; i++)
#define frange(i, j) forr(i, 0, j)
#define all(cont) cont.begin(), cont.end()
#define mp make_pair
#define pb push_back
#define f first
#define s second
typedef long long int lli;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<bool> vb;
typedef vector<lli> vll;
typedef vector<string> vs;
typedef vector<pii> vii;
typedef vector<vi> vvi;
typedef map<int, int> mpii;
typedef set<int> seti;
typedef multiset<int> mseti;
typedef long double ld;


void usaco()
{
    freopen("/media/hariaakash646/785EF1075EF0BF46/CompetitiveProgramming/input.in", "r", stdin);
//    freopen("problem.out", "w", stdout);
}

void fastio()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
}

int main() {
    fastio();
    // usaco();

    int l, q;
    cin >> l >> q;

    string str;
    cin >> str;

    vll val(1<<l);

    vll dp0(1<<l);
    vll dp1(1<<l);

    frange(i, 1<<l) {
        val[i] = dp0[i] = dp1[i] = str[i] - '0';
    }
    frange(j, l) {
    frange(i, 1<<l) {
        
            if(i&(1<<j)) dp1[i] += dp1[i^(1<<j)];
            else dp0[i] += dp0[i^(1<<j)];
        }
    }

    frange(_, q) {
        string quer;
        cin >> quer;

        reverse(all(quer));

        int n0 = 0, n1 = 0, nq = 0;

        for(auto e : quer) {
            if(e == '0') n0++;
            else if(e == '1') n1++;
            else nq++;
        }
        lli out = 0;
        if(nq <= 6) {
            int v = 0;
            vi pos;

            frange(i, l) {
                if(quer[i] =='1') v += (1<<i);
                else if(quer[i] == '?') pos.pb(i);
            }

            frange(i, 1<<nq) {
                int tmp = v;
                frange(j, nq) {
                    if(i & (1<<j)) tmp += (1<<pos[j]);
                }
                out += val[tmp];
            }
        }
        else if(n0 <= 6) {
            int v = 0;
            vi pos;

            frange(i, l) {
                if(quer[i] =='1') v += (1<<i);
                else if(quer[i] == '0') pos.pb(i);
            }

            frange(i, 1<<n0) {
                int tmp = v;
                frange(j, n0) {
                    if(i & (1<<j)) tmp += (1<<pos[j]);
                }
                if(__builtin_popcount(i) % 2 == 0) out += dp0[tmp];
                else out -= dp0[tmp];
            }
        }
        else {
            int v = 0;
            vi pos;

            frange(i, l) {
                if(quer[i] =='1') {
                    v += (1<<i);
                    pos.pb(i);
                }
                else if(quer[i] == '?') v += (1<<i);
            }

            frange(i, 1<<n1) {
                int tmp = v;
                frange(j, n1) {
                    if(i & (1<<j)) tmp -= (1<<pos[j]);
                }
                if(__builtin_popcount(i) % 2 == 0) out += dp1[tmp];
                else out -= dp1[tmp];
            }
        }
        printf("%lld\n", out);
    }
}

Compilation message

snake_escaping.cpp: In function 'void usaco()':
snake_escaping.cpp:30:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   30 |     freopen("/media/hariaakash646/785EF1075EF0BF46/CompetitiveProgramming/input.in", "r", stdin);
      |     ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
7 Correct 1 ms 600 KB Output is correct
8 Correct 1 ms 348 KB Output is correct
9 Correct 1 ms 348 KB Output is correct
10 Correct 1 ms 348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
7 Correct 1 ms 600 KB Output is correct
8 Correct 1 ms 348 KB Output is correct
9 Correct 1 ms 348 KB Output is correct
10 Correct 1 ms 348 KB Output is correct
11 Correct 544 ms 15196 KB Output is correct
12 Correct 518 ms 14928 KB Output is correct
13 Correct 374 ms 13908 KB Output is correct
14 Correct 374 ms 14156 KB Output is correct
15 Correct 842 ms 15140 KB Output is correct
16 Correct 473 ms 14316 KB Output is correct
17 Correct 464 ms 14340 KB Output is correct
18 Correct 160 ms 16212 KB Output is correct
19 Correct 205 ms 13276 KB Output is correct
20 Correct 506 ms 14740 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
7 Correct 1 ms 600 KB Output is correct
8 Correct 1 ms 348 KB Output is correct
9 Correct 1 ms 348 KB Output is correct
10 Correct 1 ms 348 KB Output is correct
11 Correct 544 ms 15196 KB Output is correct
12 Correct 518 ms 14928 KB Output is correct
13 Correct 374 ms 13908 KB Output is correct
14 Correct 374 ms 14156 KB Output is correct
15 Correct 842 ms 15140 KB Output is correct
16 Correct 473 ms 14316 KB Output is correct
17 Correct 464 ms 14340 KB Output is correct
18 Correct 160 ms 16212 KB Output is correct
19 Correct 205 ms 13276 KB Output is correct
20 Correct 506 ms 14740 KB Output is correct
21 Correct 269 ms 18220 KB Output is correct
22 Correct 796 ms 18380 KB Output is correct
23 Correct 524 ms 17352 KB Output is correct
24 Correct 473 ms 17748 KB Output is correct
25 Correct 469 ms 19280 KB Output is correct
26 Correct 613 ms 17660 KB Output is correct
27 Correct 597 ms 17748 KB Output is correct
28 Correct 179 ms 20300 KB Output is correct
29 Correct 265 ms 16208 KB Output is correct
30 Correct 502 ms 18256 KB Output is correct
31 Correct 918 ms 18452 KB Output is correct
32 Correct 615 ms 18256 KB Output is correct
33 Correct 393 ms 16980 KB Output is correct
34 Correct 476 ms 17232 KB Output is correct
35 Correct 588 ms 17720 KB Output is correct
36 Correct 165 ms 16292 KB Output is correct
37 Correct 865 ms 18304 KB Output is correct
38 Correct 293 ms 16328 KB Output is correct
39 Correct 508 ms 17520 KB Output is correct
40 Correct 467 ms 17252 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
7 Correct 1 ms 600 KB Output is correct
8 Correct 1 ms 348 KB Output is correct
9 Correct 1 ms 348 KB Output is correct
10 Correct 1 ms 348 KB Output is correct
11 Correct 56 ms 28408 KB Output is correct
12 Correct 50 ms 28544 KB Output is correct
13 Correct 69 ms 28428 KB Output is correct
14 Correct 90 ms 28408 KB Output is correct
15 Correct 62 ms 28404 KB Output is correct
16 Correct 100 ms 28400 KB Output is correct
17 Correct 100 ms 28324 KB Output is correct
18 Correct 40 ms 28656 KB Output is correct
19 Correct 54 ms 28144 KB Output is correct
20 Correct 58 ms 28404 KB Output is correct
21 Correct 73 ms 28540 KB Output is correct
22 Correct 102 ms 28280 KB Output is correct
23 Correct 63 ms 28312 KB Output is correct
24 Correct 85 ms 28404 KB Output is correct
25 Correct 121 ms 28660 KB Output is correct
26 Correct 40 ms 28148 KB Output is correct
27 Correct 51 ms 28400 KB Output is correct
28 Correct 52 ms 28152 KB Output is correct
29 Correct 76 ms 28268 KB Output is correct
30 Correct 87 ms 28384 KB Output is correct
31 Correct 58 ms 28404 KB Output is correct
32 Correct 111 ms 28404 KB Output is correct
33 Correct 96 ms 28404 KB Output is correct
34 Correct 50 ms 28204 KB Output is correct
35 Correct 81 ms 28480 KB Output is correct
36 Correct 92 ms 28404 KB Output is correct
37 Correct 83 ms 28376 KB Output is correct
38 Correct 87 ms 28332 KB Output is correct
39 Correct 85 ms 28252 KB Output is correct
40 Correct 82 ms 28400 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
7 Correct 1 ms 600 KB Output is correct
8 Correct 1 ms 348 KB Output is correct
9 Correct 1 ms 348 KB Output is correct
10 Correct 1 ms 348 KB Output is correct
11 Correct 544 ms 15196 KB Output is correct
12 Correct 518 ms 14928 KB Output is correct
13 Correct 374 ms 13908 KB Output is correct
14 Correct 374 ms 14156 KB Output is correct
15 Correct 842 ms 15140 KB Output is correct
16 Correct 473 ms 14316 KB Output is correct
17 Correct 464 ms 14340 KB Output is correct
18 Correct 160 ms 16212 KB Output is correct
19 Correct 205 ms 13276 KB Output is correct
20 Correct 506 ms 14740 KB Output is correct
21 Correct 269 ms 18220 KB Output is correct
22 Correct 796 ms 18380 KB Output is correct
23 Correct 524 ms 17352 KB Output is correct
24 Correct 473 ms 17748 KB Output is correct
25 Correct 469 ms 19280 KB Output is correct
26 Correct 613 ms 17660 KB Output is correct
27 Correct 597 ms 17748 KB Output is correct
28 Correct 179 ms 20300 KB Output is correct
29 Correct 265 ms 16208 KB Output is correct
30 Correct 502 ms 18256 KB Output is correct
31 Correct 918 ms 18452 KB Output is correct
32 Correct 615 ms 18256 KB Output is correct
33 Correct 393 ms 16980 KB Output is correct
34 Correct 476 ms 17232 KB Output is correct
35 Correct 588 ms 17720 KB Output is correct
36 Correct 165 ms 16292 KB Output is correct
37 Correct 865 ms 18304 KB Output is correct
38 Correct 293 ms 16328 KB Output is correct
39 Correct 508 ms 17520 KB Output is correct
40 Correct 467 ms 17252 KB Output is correct
41 Correct 56 ms 28408 KB Output is correct
42 Correct 50 ms 28544 KB Output is correct
43 Correct 69 ms 28428 KB Output is correct
44 Correct 90 ms 28408 KB Output is correct
45 Correct 62 ms 28404 KB Output is correct
46 Correct 100 ms 28400 KB Output is correct
47 Correct 100 ms 28324 KB Output is correct
48 Correct 40 ms 28656 KB Output is correct
49 Correct 54 ms 28144 KB Output is correct
50 Correct 58 ms 28404 KB Output is correct
51 Correct 73 ms 28540 KB Output is correct
52 Correct 102 ms 28280 KB Output is correct
53 Correct 63 ms 28312 KB Output is correct
54 Correct 85 ms 28404 KB Output is correct
55 Correct 121 ms 28660 KB Output is correct
56 Correct 40 ms 28148 KB Output is correct
57 Correct 51 ms 28400 KB Output is correct
58 Correct 52 ms 28152 KB Output is correct
59 Correct 76 ms 28268 KB Output is correct
60 Correct 87 ms 28384 KB Output is correct
61 Correct 58 ms 28404 KB Output is correct
62 Correct 111 ms 28404 KB Output is correct
63 Correct 96 ms 28404 KB Output is correct
64 Correct 50 ms 28204 KB Output is correct
65 Correct 81 ms 28480 KB Output is correct
66 Correct 92 ms 28404 KB Output is correct
67 Correct 83 ms 28376 KB Output is correct
68 Correct 87 ms 28332 KB Output is correct
69 Correct 85 ms 28252 KB Output is correct
70 Correct 82 ms 28400 KB Output is correct
71 Correct 457 ms 52856 KB Output is correct
72 Correct 488 ms 53112 KB Output is correct
73 Correct 811 ms 51632 KB Output is correct
74 Correct 1236 ms 51824 KB Output is correct
75 Correct 685 ms 53780 KB Output is correct
76 Correct 1516 ms 52044 KB Output is correct
77 Correct 1400 ms 52020 KB Output is correct
78 Correct 273 ms 55796 KB Output is correct
79 Correct 432 ms 49708 KB Output is correct
80 Correct 524 ms 53060 KB Output is correct
81 Correct 932 ms 52888 KB Output is correct
82 Correct 1459 ms 51916 KB Output is correct
83 Correct 642 ms 50868 KB Output is correct
84 Correct 1181 ms 51832 KB Output is correct
85 Correct 1410 ms 51812 KB Output is correct
86 Correct 273 ms 49616 KB Output is correct
87 Correct 422 ms 52720 KB Output is correct
88 Correct 447 ms 49784 KB Output is correct
89 Correct 848 ms 51252 KB Output is correct
90 Correct 1201 ms 51600 KB Output is correct
91 Correct 639 ms 51084 KB Output is correct
92 Correct 1682 ms 52164 KB Output is correct
93 Correct 1422 ms 51924 KB Output is correct
94 Correct 262 ms 49584 KB Output is correct
95 Correct 1179 ms 51824 KB Output is correct
96 Correct 1091 ms 51940 KB Output is correct
97 Correct 1085 ms 51956 KB Output is correct
98 Correct 1093 ms 51904 KB Output is correct
99 Correct 1118 ms 51696 KB Output is correct
100 Correct 1144 ms 51836 KB Output is correct