Submission #1299176

#TimeUsernameProblemLanguageResultExecution timeMemory
1299176am_aadvikExamination 2 (JOI24_examination2)C++20
0 / 100
2095 ms5164 KiB
#include <iostream> #include<string> #include<algorithm> #include<vector> using namespace std; string nbsolve(string s, int x, int l, int r) {//no brackets string c, ns; for (int i = l; i <= r; ++i) c += s[i]; s = c; int n = s.length(); //Round 3: ! for (int i = n - 1; i >= 0; --i) if (s[i] == '!') ns.back() = (ns.back() == '0' ? '1' : '0'); else ns += s[i]; reverse(ns.begin(), ns.end()); //Round 4: & s = ns; ns = ""; n = s.length(); for (int i = 0; i < n; ++i) if (s[i] == '&') s[i + 1] = ((s[i + 1] == '1') && (ns.back() == '1') ? '1' : '0'), ns.pop_back(); else ns += s[i]; //Round 5: x s = ns; ns = ""; n = s.length(); for (int i = 0; i < n; ++i) if (s[i] == 'x') s[i + 1] = ((s[i + 1] != ns.back()) ? '1' : '0'), ns.pop_back(); else ns += s[i]; //Round 6: | s = ns; ns = ""; n = s.length(); for (int i = 0; i < n; ++i) if (s[i] == '|') s[i + 1] = ((s[i + 1] == '1') || (ns.back() == '1') ? '1' : '0'), ns.pop_back(); else ns += s[i]; return ns; } int matoi(string& cur) { int val = 0, m = 1; for (int i = cur.length() - 1; i >= 0; --i) val += (cur[i] - '0') * m, m *= 10; return val; } int main() { ios_base::sync_with_stdio(false); cin.tie(nullptr); int n, q; cin >> n >> q; string s,cs; cin >> s; for(int i = 0; i < s.length(); ++i) if((!i) || (s[i-1] != 'x')) if(!((((int)s[i]) > 0) && (((int)s[i]) < 10000))) cs+='x'; else cs += s[i]; else cs += s[i]; s = ""; for(int i = 0; i < cs.length(); ++i) if((cs[i] != 'x') || (!s.length()) || (s.back() != 'x')) s += cs[i]; string os = s; while (q--) { int x; cin >> x; string ns; for (int i = 0; i < n; ) { //Round 1: [] string cur; int oi = i; while ((i < n) && (s[i] >= '0') && (s[i] <= '9')) cur += s[i], ++i; if (cur.length()) { int val = matoi(cur); ns.pop_back(); ns += (x >= val ? '1' : '0'), ++i; } else ns += s[i], ++i; } vector<int> o, no; s = ns; ns = "", n = s.length(); //Round 2: () for (int i = 0; i < n; ++i) { if (s[i] == ')') { int l = no.back() + 1; int r = ns.length() - 1; auto res = nbsolve(ns, x, l, r); while (ns.size() && (ns.back() != '(')) ns.pop_back(); ns.pop_back(); no.pop_back(); for (auto x : res) ns += x; } else if (s[i] == '(') o.push_back(i), no.push_back(ns.length()), ns += '('; else ns += s[i]; } ns = nbsolve(ns, x, 0, ns.length()); if (ns[0] == '1') cout << "True" << endl; else cout << "False" << endl; s = os; n = s.length(); } }
#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...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...