답안 #698931

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
698931 2023-02-14T22:02:23 Z finn__ Snake Escaping (JOI18_snake_escaping) C++17
100 / 100
605 ms 25264 KB
#include <bits/stdc++.h>
using namespace std;

#pragma GCC optimize("O3")
#pragma GCC target("avx2")

#define popcount(x) __builtin_popcount(x)

char snakes[1 << 20];
unsigned v[1 << 20], super[1 << 20], sub[1 << 20];

int main()
{
    size_t l, q;
    scanf("%zu %zu %s", &l, &q, snakes);

    for (unsigned i = 0; i < 1U << l; i++)
        super[i] = sub[i] = v[i] = snakes[i] - '0';

    for (unsigned i = 0; i < l; i++)
        for (unsigned j = 0; j < 1U << l; j++)
            if (j & (1 << i))
                sub[j] += sub[j ^ (1 << i)];
            else
                super[j] += super[j ^ (1 << i)];

    while (q--)
    {
        char s[20];
        scanf("%s", s);
        unsigned a = 0, b = 0, c = 0, ans = 0;
        for (unsigned i = 0; i < l; i++)
        {
            a <<= 1, b <<= 1, c <<= 1;
            a |= s[i] == '0', b |= s[i] == '1', c |= s[i] == '?';
        }

        if (popcount(a) <= popcount(b) && popcount(a) <= popcount(c))
        {
            ans = super[b];
            for (unsigned i = a; i; i = (i - 1) & a)
                ans += super[b | i] * ((popcount(i) & 1) ? -1 : 1);
        }
        else if (popcount(b) <= popcount(a) && popcount(b) <= popcount(c))
        {
            ans = sub[c | b];
            for (unsigned i = b; i; i = (i - 1) & b)
                ans += sub[c | (b ^ i)] * ((popcount(i) & 1) ? -1 : 1);
        }
        else
        {
            ans = v[b];
            for (unsigned i = c; i; i = (i - 1) & c)
                ans += v[b | i];
        }

        printf("%u\n", ans);
    }
}

Compilation message

snake_escaping.cpp: In function 'int main()':
snake_escaping.cpp:15:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   15 |     scanf("%zu %zu %s", &l, &q, snakes);
      |     ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
snake_escaping.cpp:30:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   30 |         scanf("%s", s);
      |         ~~~~~^~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 316 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 312 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 316 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 312 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 172 ms 15016 KB Output is correct
12 Correct 198 ms 14652 KB Output is correct
13 Correct 190 ms 13996 KB Output is correct
14 Correct 188 ms 14028 KB Output is correct
15 Correct 193 ms 15000 KB Output is correct
16 Correct 188 ms 14160 KB Output is correct
17 Correct 198 ms 14112 KB Output is correct
18 Correct 175 ms 16060 KB Output is correct
19 Correct 178 ms 13024 KB Output is correct
20 Correct 183 ms 14628 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 316 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 312 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 172 ms 15016 KB Output is correct
12 Correct 198 ms 14652 KB Output is correct
13 Correct 190 ms 13996 KB Output is correct
14 Correct 188 ms 14028 KB Output is correct
15 Correct 193 ms 15000 KB Output is correct
16 Correct 188 ms 14160 KB Output is correct
17 Correct 198 ms 14112 KB Output is correct
18 Correct 175 ms 16060 KB Output is correct
19 Correct 178 ms 13024 KB Output is correct
20 Correct 183 ms 14628 KB Output is correct
21 Correct 191 ms 18148 KB Output is correct
22 Correct 201 ms 18240 KB Output is correct
23 Correct 217 ms 17352 KB Output is correct
24 Correct 220 ms 17052 KB Output is correct
25 Correct 210 ms 19064 KB Output is correct
26 Correct 227 ms 17580 KB Output is correct
27 Correct 248 ms 17492 KB Output is correct
28 Correct 196 ms 20084 KB Output is correct
29 Correct 188 ms 16080 KB Output is correct
30 Correct 202 ms 18152 KB Output is correct
31 Correct 206 ms 18092 KB Output is correct
32 Correct 202 ms 18076 KB Output is correct
33 Correct 205 ms 16928 KB Output is correct
34 Correct 216 ms 17048 KB Output is correct
35 Correct 218 ms 17528 KB Output is correct
36 Correct 188 ms 16080 KB Output is correct
37 Correct 194 ms 18128 KB Output is correct
38 Correct 205 ms 15996 KB Output is correct
39 Correct 219 ms 17220 KB Output is correct
40 Correct 210 ms 17096 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 316 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 312 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 42 ms 15888 KB Output is correct
12 Correct 41 ms 15912 KB Output is correct
13 Correct 44 ms 15824 KB Output is correct
14 Correct 46 ms 15764 KB Output is correct
15 Correct 45 ms 15924 KB Output is correct
16 Correct 54 ms 15788 KB Output is correct
17 Correct 51 ms 15764 KB Output is correct
18 Correct 38 ms 16032 KB Output is correct
19 Correct 43 ms 15756 KB Output is correct
20 Correct 41 ms 15880 KB Output is correct
21 Correct 42 ms 15880 KB Output is correct
22 Correct 47 ms 15784 KB Output is correct
23 Correct 40 ms 15788 KB Output is correct
24 Correct 60 ms 15752 KB Output is correct
25 Correct 52 ms 15820 KB Output is correct
26 Correct 39 ms 15692 KB Output is correct
27 Correct 39 ms 15904 KB Output is correct
28 Correct 40 ms 15668 KB Output is correct
29 Correct 43 ms 15824 KB Output is correct
30 Correct 43 ms 15800 KB Output is correct
31 Correct 40 ms 15756 KB Output is correct
32 Correct 52 ms 15876 KB Output is correct
33 Correct 58 ms 15940 KB Output is correct
34 Correct 38 ms 15756 KB Output is correct
35 Correct 47 ms 15880 KB Output is correct
36 Correct 49 ms 15796 KB Output is correct
37 Correct 48 ms 15820 KB Output is correct
38 Correct 50 ms 15868 KB Output is correct
39 Correct 47 ms 15816 KB Output is correct
40 Correct 58 ms 15820 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 316 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 312 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 172 ms 15016 KB Output is correct
12 Correct 198 ms 14652 KB Output is correct
13 Correct 190 ms 13996 KB Output is correct
14 Correct 188 ms 14028 KB Output is correct
15 Correct 193 ms 15000 KB Output is correct
16 Correct 188 ms 14160 KB Output is correct
17 Correct 198 ms 14112 KB Output is correct
18 Correct 175 ms 16060 KB Output is correct
19 Correct 178 ms 13024 KB Output is correct
20 Correct 183 ms 14628 KB Output is correct
21 Correct 191 ms 18148 KB Output is correct
22 Correct 201 ms 18240 KB Output is correct
23 Correct 217 ms 17352 KB Output is correct
24 Correct 220 ms 17052 KB Output is correct
25 Correct 210 ms 19064 KB Output is correct
26 Correct 227 ms 17580 KB Output is correct
27 Correct 248 ms 17492 KB Output is correct
28 Correct 196 ms 20084 KB Output is correct
29 Correct 188 ms 16080 KB Output is correct
30 Correct 202 ms 18152 KB Output is correct
31 Correct 206 ms 18092 KB Output is correct
32 Correct 202 ms 18076 KB Output is correct
33 Correct 205 ms 16928 KB Output is correct
34 Correct 216 ms 17048 KB Output is correct
35 Correct 218 ms 17528 KB Output is correct
36 Correct 188 ms 16080 KB Output is correct
37 Correct 194 ms 18128 KB Output is correct
38 Correct 205 ms 15996 KB Output is correct
39 Correct 219 ms 17220 KB Output is correct
40 Correct 210 ms 17096 KB Output is correct
41 Correct 42 ms 15888 KB Output is correct
42 Correct 41 ms 15912 KB Output is correct
43 Correct 44 ms 15824 KB Output is correct
44 Correct 46 ms 15764 KB Output is correct
45 Correct 45 ms 15924 KB Output is correct
46 Correct 54 ms 15788 KB Output is correct
47 Correct 51 ms 15764 KB Output is correct
48 Correct 38 ms 16032 KB Output is correct
49 Correct 43 ms 15756 KB Output is correct
50 Correct 41 ms 15880 KB Output is correct
51 Correct 42 ms 15880 KB Output is correct
52 Correct 47 ms 15784 KB Output is correct
53 Correct 40 ms 15788 KB Output is correct
54 Correct 60 ms 15752 KB Output is correct
55 Correct 52 ms 15820 KB Output is correct
56 Correct 39 ms 15692 KB Output is correct
57 Correct 39 ms 15904 KB Output is correct
58 Correct 40 ms 15668 KB Output is correct
59 Correct 43 ms 15824 KB Output is correct
60 Correct 43 ms 15800 KB Output is correct
61 Correct 40 ms 15756 KB Output is correct
62 Correct 52 ms 15876 KB Output is correct
63 Correct 58 ms 15940 KB Output is correct
64 Correct 38 ms 15756 KB Output is correct
65 Correct 47 ms 15880 KB Output is correct
66 Correct 49 ms 15796 KB Output is correct
67 Correct 48 ms 15820 KB Output is correct
68 Correct 50 ms 15868 KB Output is correct
69 Correct 47 ms 15816 KB Output is correct
70 Correct 58 ms 15820 KB Output is correct
71 Correct 295 ms 22384 KB Output is correct
72 Correct 310 ms 22436 KB Output is correct
73 Correct 383 ms 20968 KB Output is correct
74 Correct 470 ms 21268 KB Output is correct
75 Correct 317 ms 23376 KB Output is correct
76 Correct 508 ms 21520 KB Output is correct
77 Correct 516 ms 21480 KB Output is correct
78 Correct 265 ms 25264 KB Output is correct
79 Correct 278 ms 19140 KB Output is correct
80 Correct 321 ms 22380 KB Output is correct
81 Correct 386 ms 22184 KB Output is correct
82 Correct 390 ms 21236 KB Output is correct
83 Correct 308 ms 20336 KB Output is correct
84 Correct 605 ms 21200 KB Output is correct
85 Correct 554 ms 21300 KB Output is correct
86 Correct 259 ms 19100 KB Output is correct
87 Correct 278 ms 22260 KB Output is correct
88 Correct 296 ms 19020 KB Output is correct
89 Correct 367 ms 20748 KB Output is correct
90 Correct 359 ms 21032 KB Output is correct
91 Correct 305 ms 20224 KB Output is correct
92 Correct 599 ms 21364 KB Output is correct
93 Correct 524 ms 20836 KB Output is correct
94 Correct 253 ms 18608 KB Output is correct
95 Correct 449 ms 20744 KB Output is correct
96 Correct 481 ms 20640 KB Output is correct
97 Correct 460 ms 20684 KB Output is correct
98 Correct 440 ms 20384 KB Output is correct
99 Correct 455 ms 20448 KB Output is correct
100 Correct 458 ms 20116 KB Output is correct