Submission #1130222

#TimeUsernameProblemLanguageResultExecution timeMemory
1130222am_aadvikSnake Escaping (JOI18_snake_escaping)C++20
0 / 100
1 ms320 KiB
#include <iostream> #include <vector> using namespace std; int n, q; string s; vector<int> arr, sub, sup; vector<int> a, b, c; int32_t main() { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); arr.resize(1 << n); sup.resize(1 << n); sub.resize(1 << n); cin >> n >> q >> s; for (int i = 0; i < (1 << n); ++i) arr[i] = (s[i] - '0'); vector<int> cur(1 << n), prv = arr; for (int x = 1; x <= n; ++x) { for (int m = 0; m < (1 << n); ++m) { cur[m] = prv[m]; if (m & (1 << (x - 1))) cur[m] += prv[m - (1 << (x - 1))]; } prv = cur; } sub = prv, prv = arr; for (int x = 1; x <= n; ++x) { for (int m = (1 << n) - 1; m >= 0; --m) { cur[m] = prv[m]; if (!(m & (1 << (x - 1)))) cur[m] += prv[m + (1 << (x - 1))]; } prv = cur; } sup = prv; while (q--) { cin >> s; for (int i = 0; i < n / 2; ++i) swap(s[i], s[n - i - 1]); for (int i = 0; i < n; ++i) if (s[i] == '?') c.push_back(i); else if (s[i] == '1') b.push_back(i); else a.push_back(i); if (c.size() <= 6) { int ans = 0, o = 0; for (auto x : b) o += (1 << x); for (int i = 0; i < (1 << c.size()); ++i) { int v = 0; for (int j = 0; j < c.size(); ++j) if (i & (1 << j)) v += (1 << c[j]); ans += arr[o + v]; } cout << ans << endl; } else if (a.size() <= 6) { int ans = 0, o = 0; for (auto x : b) o += (1 << x); for (int i = 0; i < (1 << a.size()); ++i) { int v = 0, sz = 0; for (int j = 0; j < a.size(); ++j) if (i & (1 << j)) v += (1 << a[j]), ++sz; ans += (sup[o | v] * ((sz & 1) ? -1 : 1)); } cout << ans << endl; } else { int ans = 0, o = 0; for (auto x : c) o += (1 << x); for (int i = 0; i < (1 << b.size()); ++i) { int v = 0, sz = 0; for (int j = 0; j < b.size(); ++j) if (i & (1 << j)) v += (1 << b[j]), ++sz; ans += (sub[o | v] * (((b.size() - sz) & 1) ? -1 : 1)); } cout << ans << endl; } a.clear(); b.clear(); c.clear(); } return 0; }
#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...