Submission #996396

#TimeUsernameProblemLanguageResultExecution timeMemory
996396yanbSnake Escaping (JOI18_snake_escaping)C++14
22 / 100
352 ms32452 KiB
#include <bits/stdc++.h> using namespace std; #define int long long #define pii pair<long long, long long> #define t3i tuple<long long, long long, long long> int build(vector<int> &tri, vector<int> &ans, string &tox, int l, int q) { int v = 0; for (int i = 0; i < l; i++) { v *= 3; v += tri[i]; } if (ans[v] != -1) return ans[v]; bool ok = 0; for (int i = 0; i < l; i++) { if (tri[i] == 2) { int cans = 0; tri[i] = 0; cans += build(tri, ans, tox, l, q); tri[i] = 1; cans += build(tri, ans, tox, l, q); tri[i] = 2; ans[v] = cans; ok = 1; } } if (!ok) { int bin = 0; for (int i = 0; i < l; i++) { bin *= 2; bin += tri[i]; } ans[v] = tox[bin] - '0'; } return ans[v]; } signed main() { ios_base::sync_with_stdio(false); cin.tie(nullptr); int l, q; string tox; cin >> l >> q >> tox; vector<int> ans(pow(3, l) + 100, -1); vector<int> tri(l, 2); build(tri, ans, tox, l, q); while (q--) { string s; cin >> s; int v = 0; for (int i = 0; i < l; i++) { v *= 3; v += (s[i] == '?' ? 2 : s[i] - '0'); } cout << ans[v] << "\n"; } }
#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...