Submission #1034995

#TimeUsernameProblemLanguageResultExecution timeMemory
1034995pccHomework (CEOI22_homework)C++17
100 / 100
247 ms151104 KiB
#include <bits/stdc++.h> using namespace std; #pragma GCC optimize("O3,unroll-loops") const int mxn = 1e6+10; vector<int> tree[mxn*2]; int val[mxn*2],dp[mxn*2]; int vcnt = 0; int N; string s; int rt; void dfs(int now){ for(auto nxt:tree[now])dfs(nxt); dp[now] = 0; if(val[now] == -1)dp[now] = min(dp[tree[now][0]],dp[tree[now][1]]); else if(val[now] == -2)dp[now] = dp[tree[now][0]]+dp[tree[now][1]]+1; return; } int main(){ ios::sync_with_stdio(0);cin.tie(0);cout.tie(0); cin>>s; for(int i = 0;i<s.size();i++)N += s[i] == '?'; { int pt = 0; vector<int> v,stk; while(pt<s.size()){ if(s[pt] == 'm'){ if(s.substr(pt,3) == "min"){ v.push_back(-1); } else{ v.push_back(-2); } pt += 3; } else if(s[pt] == '?'){ v.push_back(++vcnt); pt++; } else pt++; } vcnt = N; for(auto &i:v){ stk.push_back(i); while(stk.size()>=2&&stk.end()[-1]>0&&stk.end()[-2]>0){ int a = stk.end()[-1],b = stk.end()[-2]; stk.pop_back();stk.pop_back(); int c = ++vcnt; tree[c].push_back(a); tree[c].push_back(b); assert(stk.back()<0); val[c] = stk.back(); stk.pop_back(); rt = c; stk.push_back(c); } } } /* for(int i = 1;i<=vcnt;i++){ if(val[i])cerr<<i<<' '<<val[i]<<":"<<tree[i][0]<<','<<tree[i][1]<<endl; } */ dfs(rt); int l = dp[rt]; //for(int i = 1;i<=vcnt;i++)cerr<<dp[i]<<',';cerr<<endl; for(int i = 1;i<=vcnt;i++)if(val[i] < 0)val[i] = (val[i] == -2?-1:-2); /* for(int i = 1;i<=vcnt;i++){ if(val[i])cerr<<i<<' '<<val[i]<<":"<<tree[i][0]<<','<<tree[i][1]<<endl; } */ dfs(rt); //for(int i = 1;i<=vcnt;i++)cerr<<dp[i]<<',';cerr<<endl; int r = N-dp[rt]-1; cout<<max(0,r-l+1)<<'\n'; return 0; }

Compilation message (stderr)

Main.cpp: In function 'int main()':
Main.cpp:25:17: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   25 |  for(int i = 0;i<s.size();i++)N += s[i] == '?';
      |                ~^~~~~~~~~
Main.cpp:29:11: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   29 |   while(pt<s.size()){
      |         ~~^~~~~~~~~
#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...