Submission #1016778

#TimeUsernameProblemLanguageResultExecution timeMemory
1016778amine_arouaHomework (CEOI22_homework)C++17
53 / 100
326 ms524288 KiB
#include <bits/stdc++.h> using namespace std; int n; map<string , int> comma; tuple<int , int , int> solve(string s) { int mn = 1e9 , mx = -1e9 , sz = 0; if(s[0] == '?') { return {1 , 1 , 1}; } int pos = comma[s]; string a = s.substr(4, pos - 4); string b = s.substr(pos + 1 , (int)s.size() - 2 - pos); auto [am , aM , as] = solve(a) ; auto [bm , bM , bs] = solve(b); sz = as + bs; if(s[1] == 'a') { mn = am + bm; mx = max(aM + bs , as + bM); } else { mn = min(am , bm); mx = aM + bM - 1; } return {mn , mx , sz}; } int main() { string s; cin>>s; n = 0; for(auto c : s) n+=c=='?'; stack<int> st; vector<int> pos((int)s.size()); for(int i = 0 ; i < (int)s.size() ; i++) { if(s[i] == '(') st.push(i); if(s[i] == ',') { pos[st.top()] = i - st.top() + 3; } if(s[i] == ')') { string t = s.substr(st.top() - 3 , i - st.top() + 4); comma[t] = pos[st.top()]; st.pop(); } } auto [a , b , c] = solve(s); cout<<b - a + 1<<'\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...