Submission #678625

#TimeUsernameProblemLanguageResultExecution timeMemory
678625hollwo_pelwSnake Escaping (JOI18_snake_escaping)C++17
100 / 100
1244 ms26056 KiB
#include <bits/stdc++.h> // #include <ext/pb_ds/assoc_container.hpp> // #include <ext/pb_ds/trie_policy.hpp> // #include <ext/rope> using namespace std; // using namespace __gnu_cxx; // using namespace __gnu_pbds; void Hollwo_Pelw(); signed main(){ #ifndef hollwo_pelw_local if (fopen(".inp", "r")) assert(freopen(".inp", "r", stdin)), assert(freopen(".out", "w", stdout)); #else using namespace chrono; auto start = steady_clock::now(); #endif cin.tie(0), cout.tie(0) -> sync_with_stdio(0); int testcases = 1; // cin >> testcases; for (int test = 1; test <= testcases; test++){ // cout << "Case #" << test << ": "; Hollwo_Pelw(); } #ifdef hollwo_pelw_local auto end = steady_clock::now(); cout << "\nExecution time : " << duration_cast<milliseconds> (end - start).count() << "[ms]" << endl; #endif } int n, q, f0[1 << 20], f1[1 << 20], pc[1 << 20]; string s; void Hollwo_Pelw(){ cin >> n >> q >> s; for (int i = 0; i < 1 << n; i++) { f0[i] = f1[i] = s[i] - '0'; } for (int i = 0; i < 1 << n; i++) pc[i] = __builtin_popcount(i); for (int i = 0; i < n; i++) { for (int mask = 0; mask < 1 << n; mask++) { if (mask >> i & 1) { f0[mask ^ 1 << i] += f0[mask]; f1[mask] += f1[mask ^ 1 << i]; } } } for (string base; q --; ) { cin >> base; reverse(base.begin(), base.end()); int c0 = 0, c1 = 0, cq = 0; for (int i = 0; i < n; i++) { if (base[i] == '0') c0 |= 1 << i; if (base[i] == '1') c1 |= 1 << i; if (base[i] == '?') cq |= 1 << i; } if (pc[c0] <= 7) { int res = 0; for (int sub = c0; ; sub = (sub - 1) & c0) { res += (pc[c0] % 2 == pc[sub] % 2 ? 1 : -1) * f0[c0 ^ c1 ^ sub]; if (!sub) break; } cout << res << '\n'; continue; } if (pc[c1] <= 7) { int res = 0; for (int sub = c1; ; sub = (sub - 1) & c1) { res += (pc[c1] % 2 == pc[sub] % 2 ? 1 : -1) * f1[cq ^ sub]; if (!sub) break; } cout << res << '\n'; continue; } if (pc[cq] <= 7) { int res = 0; for (int sub = cq; ; sub = (sub - 1) & cq) { res += s[sub | c1] - '0'; if (!sub) break; } cout << res << '\n'; continue; } } }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...