Submission #1268159

#TimeUsernameProblemLanguageResultExecution timeMemory
1268159chfHomework (CEOI22_homework)C++20
0 / 100
188 ms226316 KiB
#include <bits/stdc++.h> using namespace std; string s; int pos,n; struct Node { bool isq; bool ismin; Node* l; Node* r; int size; int L,R; }; Node* parse() { if(s[pos]=='?') { Node* t=new Node(); t->isq=1; t->size=1; pos++; return t; } string op; while(isalpha(s[pos])) op+=s[pos++]; pos++; Node* a=parse(); pos++; Node* b=parse(); pos++; Node* t=new Node(); t->isq=0; t->ismin=(op=="min"); t->l=a; t->r=b; t->size=a->size+b->size; return t; } void solve(Node* t) { if(t->isq) { t->L=1; t->R=n; return; } solve(t->l); solve(t->r); if(t->ismin) { t->L=1; t->R=t->size; } else { t->L=n-t->size+1; t->R=n; } } int main() { ios::sync_with_stdio(0); cin.tie(0); cin>>s; pos=0; Node* root=parse(); n=root->size; solve(root); cout<<root->R-root->L+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...