Submission #1119009

#TimeUsernameProblemLanguageResultExecution timeMemory
1119009PieArmyHomework (CEOI22_homework)C++17
100 / 100
146 ms80868 KiB
typedef long long ll; ll pie(ll army){return (1ll<<army);} #include <bits/stdc++.h> #define fr first #define sc second #define pb push_back #define endl '\n' #define mid ((left+right)>>1) const ll inf=2000000000000000005; const int sonsuz=2000000005; using namespace std; ll fpow(ll x,ll y,ll m=0){if(y<0){cout<<"powError";return -1;}if(m)x%=m;ll res=1;while(y>0){if(y&1)res*=x;x*=x;if(m){x%=m;res%=m;}y>>=1;}return res;} int n; int tip[1000001],alt[1000001][2]; pair<int,int> dfs(int pos){ if(pos==0)return {0,0}; pair<int,int>a=dfs(alt[pos][0]),b=dfs(alt[pos][1]); pair<int,int>res; if(tip[pos]==-1){ res.fr=min(a.fr,b.fr); res.sc=a.sc+b.sc+1; } else{ res.fr=a.fr+b.fr+1; res.sc=min(a.sc,b.sc); } return res; } void code(){ string s;cin>>s; n=(s.size()+6)/7; int cur=1,child=0; vector<int>v={0}; for(char c:s){ if(c=='('||c==')'){ child=0; if(c==')'){ v.pop_back(); } } if(c==','){ child=1; } if(c=='x'||c=='n'){ if(c=='x'){ tip[cur]=1; } else tip[cur]=-1; alt[v.back()][child]=cur; v.pb(cur++); } } pair<int,int>ans=dfs(1); cout<<n-ans.fr-ans.sc; } int main(){ ios_base::sync_with_stdio(false);cin.tie(NULL); bool usaco=0;if(usaco){freopen(".in","r",stdin);freopen(".out","w",stdout);} int t=1; if(!t)cin>>t; while(t--){code();cout<<endl;} return 0; }

Compilation message (stderr)

Main.cpp: In function 'int main()':
Main.cpp:62:32: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   62 |  bool usaco=0;if(usaco){freopen(".in","r",stdin);freopen(".out","w",stdout);}
      |                         ~~~~~~~^~~~~~~~~~~~~~~~~
Main.cpp:62:57: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   62 |  bool usaco=0;if(usaco){freopen(".in","r",stdin);freopen(".out","w",stdout);}
      |                                                  ~~~~~~~^~~~~~~~~~~~~~~~~~~
#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...