# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
675739 | 2022-12-27T19:27:22 Z | MilosMilutinovic | Snake Escaping (JOI18_snake_escaping) | C++17 | 1269 ms | 9668 KB |
#include <iostream> #include <cstdio> #include <cstdlib> #include <algorithm> #include <cmath> #include <vector> #include <set> #include <map> #include <unordered_set> #include <unordered_map> #include <queue> #include <ctime> #include <cassert> #include <complex> #include <string> #include <cstring> #include <chrono> #include <random> #include <bitset> #include <array> using namespace std; #ifdef LOCAL #define eprintf(...) {fprintf(stderr, __VA_ARGS__);fflush(stderr);} #else #define eprintf(...) 42 #endif using ll = long long; using ld = long double; using uint = unsigned int; using ull = unsigned long long; template<typename T> using pair2 = pair<T, T>; using pii = pair<int, int>; using pli = pair<ll, int>; using pll = pair<ll, ll>; mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count()); ll myRand(ll B) { return (ull)rng() % B; } #define pb push_back #define mp make_pair #define all(x) (x).begin(),(x).end() #define fi first #define se second clock_t startTime; double getCurrentTime() { return (double)(clock() - startTime) / CLOCKS_PER_SEC; } const int N = (1 << 20); int n, q; char s[N]; char t[N]; int sub[N]; int sup[N]; int main() { startTime = clock(); // freopen("input.txt", "r", stdin); // freopen("output.txt", "w", stdout); scanf("%d%d", &n, &q); scanf("%s", s); for (int i = 0; i < (1 << n); i++) { sub[i] = (int)(s[i] - '0'); sup[i] = (int)(s[i] - '0'); } for (int i = 0; i < n; i++) for (int mask = 0; mask < (1 << n); mask++) if (mask >> i & 1) sub[mask] += sub[mask ^ (1 << i)]; for (int i = 0; i < n; i++) for (int mask = (1 << n) - 1; mask >= 0; mask--) if (!(mask >> i & 1)) sup[mask] += sup[mask ^ (1 << i)]; while(q--) { scanf("%s", t); reverse(t, t + n); vector<int> zero, one, qmark; for (int i = 0; i < n; i++) { if (t[i] == '0') zero.push_back(i); if (t[i] == '1') one.push_back(i); if (t[i] == '?') qmark.push_back(i); } int tmask = 0; for (int i = 0; i < n; i++) if (t[i] == '1') tmask += (1 << i); int ans = 0; if (qmark.size() <= 6) { int sz = qmark.size(); for (int mask = 0; mask < (1 << sz); mask++) { int nmask = tmask; for (int i = 0; i < sz; i++) if (mask >> i & 1) nmask += (1 << qmark[i]); ans += (int)(s[nmask] - '0'); } } else if (zero.size() <= 6) { int sz = zero.size(); for (int mask = 0; mask < (1 << sz); mask++) { int nmask = tmask; for (int i = 0; i < sz; i++) if (mask >> i & 1) nmask += (1 << zero[i]); ans += sup[nmask] * (__builtin_popcount(mask) % 2 == 0 ? 1 : -1); } } else { assert(one.size() <= 6); int sz = one.size(); tmask = 0; for (int i = 0; i < n; i++) if (t[i] == '?') tmask += (1 << i); for (int mask = 0; mask < (1 << sz); mask++) { int nmask = tmask; for (int i = 0; i < sz; i++) if (mask >> i & 1) nmask += (1 << one[i]); ans += sub[nmask] * ((sz - __builtin_popcount(mask)) % 2 == 0 ? 1 : -1); } } printf("%d\n", ans); } return 0; }
Compilation message
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 212 KB | Output is correct |
2 | Correct | 1 ms | 340 KB | Output is correct |
3 | Correct | 1 ms | 340 KB | Output is correct |
4 | Correct | 1 ms | 340 KB | Output is correct |
5 | Correct | 2 ms | 340 KB | Output is correct |
6 | Correct | 1 ms | 212 KB | Output is correct |
7 | Correct | 1 ms | 212 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 | 212 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 212 KB | Output is correct |
2 | Correct | 1 ms | 340 KB | Output is correct |
3 | Correct | 1 ms | 340 KB | Output is correct |
4 | Correct | 1 ms | 340 KB | Output is correct |
5 | Correct | 2 ms | 340 KB | Output is correct |
6 | Correct | 1 ms | 212 KB | Output is correct |
7 | Correct | 1 ms | 212 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 | 212 KB | Output is correct |
11 | Correct | 826 ms | 4320 KB | Output is correct |
12 | Correct | 734 ms | 3956 KB | Output is correct |
13 | Correct | 639 ms | 3172 KB | Output is correct |
14 | Correct | 656 ms | 3244 KB | Output is correct |
15 | Correct | 1192 ms | 4324 KB | Output is correct |
16 | Correct | 748 ms | 3508 KB | Output is correct |
17 | Correct | 763 ms | 3504 KB | Output is correct |
18 | Correct | 355 ms | 5248 KB | Output is correct |
19 | Correct | 524 ms | 2204 KB | Output is correct |
20 | Correct | 822 ms | 4116 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 212 KB | Output is correct |
2 | Correct | 1 ms | 340 KB | Output is correct |
3 | Correct | 1 ms | 340 KB | Output is correct |
4 | Correct | 1 ms | 340 KB | Output is correct |
5 | Correct | 2 ms | 340 KB | Output is correct |
6 | Correct | 1 ms | 212 KB | Output is correct |
7 | Correct | 1 ms | 212 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 | 212 KB | Output is correct |
11 | Correct | 826 ms | 4320 KB | Output is correct |
12 | Correct | 734 ms | 3956 KB | Output is correct |
13 | Correct | 639 ms | 3172 KB | Output is correct |
14 | Correct | 656 ms | 3244 KB | Output is correct |
15 | Correct | 1192 ms | 4324 KB | Output is correct |
16 | Correct | 748 ms | 3508 KB | Output is correct |
17 | Correct | 763 ms | 3504 KB | Output is correct |
18 | Correct | 355 ms | 5248 KB | Output is correct |
19 | Correct | 524 ms | 2204 KB | Output is correct |
20 | Correct | 822 ms | 4116 KB | Output is correct |
21 | Correct | 615 ms | 4396 KB | Output is correct |
22 | Correct | 973 ms | 4436 KB | Output is correct |
23 | Correct | 830 ms | 3508 KB | Output is correct |
24 | Correct | 789 ms | 3404 KB | Output is correct |
25 | Correct | 643 ms | 5404 KB | Output is correct |
26 | Correct | 930 ms | 3900 KB | Output is correct |
27 | Correct | 920 ms | 3824 KB | Output is correct |
28 | Correct | 406 ms | 6364 KB | Output is correct |
29 | Correct | 589 ms | 2380 KB | Output is correct |
30 | Correct | 835 ms | 4552 KB | Output is correct |
31 | Correct | 1269 ms | 4328 KB | Output is correct |
32 | Correct | 900 ms | 4284 KB | Output is correct |
33 | Correct | 658 ms | 3328 KB | Output is correct |
34 | Correct | 806 ms | 3396 KB | Output is correct |
35 | Correct | 953 ms | 3852 KB | Output is correct |
36 | Correct | 344 ms | 2280 KB | Output is correct |
37 | Correct | 1178 ms | 4372 KB | Output is correct |
38 | Correct | 610 ms | 2372 KB | Output is correct |
39 | Correct | 819 ms | 3544 KB | Output is correct |
40 | Correct | 789 ms | 3388 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 212 KB | Output is correct |
2 | Correct | 1 ms | 340 KB | Output is correct |
3 | Correct | 1 ms | 340 KB | Output is correct |
4 | Correct | 1 ms | 340 KB | Output is correct |
5 | Correct | 2 ms | 340 KB | Output is correct |
6 | Correct | 1 ms | 212 KB | Output is correct |
7 | Correct | 1 ms | 212 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 | 212 KB | Output is correct |
11 | Incorrect | 110 ms | 9668 KB | Output isn't correct |
12 | Halted | 0 ms | 0 KB | - |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 212 KB | Output is correct |
2 | Correct | 1 ms | 340 KB | Output is correct |
3 | Correct | 1 ms | 340 KB | Output is correct |
4 | Correct | 1 ms | 340 KB | Output is correct |
5 | Correct | 2 ms | 340 KB | Output is correct |
6 | Correct | 1 ms | 212 KB | Output is correct |
7 | Correct | 1 ms | 212 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 | 212 KB | Output is correct |
11 | Correct | 826 ms | 4320 KB | Output is correct |
12 | Correct | 734 ms | 3956 KB | Output is correct |
13 | Correct | 639 ms | 3172 KB | Output is correct |
14 | Correct | 656 ms | 3244 KB | Output is correct |
15 | Correct | 1192 ms | 4324 KB | Output is correct |
16 | Correct | 748 ms | 3508 KB | Output is correct |
17 | Correct | 763 ms | 3504 KB | Output is correct |
18 | Correct | 355 ms | 5248 KB | Output is correct |
19 | Correct | 524 ms | 2204 KB | Output is correct |
20 | Correct | 822 ms | 4116 KB | Output is correct |
21 | Correct | 615 ms | 4396 KB | Output is correct |
22 | Correct | 973 ms | 4436 KB | Output is correct |
23 | Correct | 830 ms | 3508 KB | Output is correct |
24 | Correct | 789 ms | 3404 KB | Output is correct |
25 | Correct | 643 ms | 5404 KB | Output is correct |
26 | Correct | 930 ms | 3900 KB | Output is correct |
27 | Correct | 920 ms | 3824 KB | Output is correct |
28 | Correct | 406 ms | 6364 KB | Output is correct |
29 | Correct | 589 ms | 2380 KB | Output is correct |
30 | Correct | 835 ms | 4552 KB | Output is correct |
31 | Correct | 1269 ms | 4328 KB | Output is correct |
32 | Correct | 900 ms | 4284 KB | Output is correct |
33 | Correct | 658 ms | 3328 KB | Output is correct |
34 | Correct | 806 ms | 3396 KB | Output is correct |
35 | Correct | 953 ms | 3852 KB | Output is correct |
36 | Correct | 344 ms | 2280 KB | Output is correct |
37 | Correct | 1178 ms | 4372 KB | Output is correct |
38 | Correct | 610 ms | 2372 KB | Output is correct |
39 | Correct | 819 ms | 3544 KB | Output is correct |
40 | Correct | 789 ms | 3388 KB | Output is correct |
41 | Incorrect | 110 ms | 9668 KB | Output isn't correct |
42 | Halted | 0 ms | 0 KB | - |