Submission #169163

#TimeUsernameProblemLanguageResultExecution timeMemory
169163itglMoney (IZhO17_money)C++14
0 / 100
2 ms376 KiB
#include<bits/stdc++.h> #define pb push_back using namespace std; int a[1000005]; vector<int> mn,vec,mrgvec; int mergesort(int ans){ int i=0,j=0; int s1=mn.size(); int s2=vec.size(); int k=0; while(i<s1&&j<s2){ if(mn[i]<=vec[j]){ //cout << "b" << endl; mrgvec.pb(mn[i]); i++; if(k!=1) ans++; k=1; }else{ //cout << "a"<<endl; mrgvec.pb(vec[j]); j++; if(k!=2) ans++; k=2; } } //cout << ans << '!' << endl; while(i<s1){ mrgvec.pb(mn[i]); i++; if(k!=2){ ans++; k=2; } } while(j<s2){ mrgvec.pb(vec[j]); j++; if(k!=1){ ans++; k=1; } } return ans; } int main(){ int n; cin >> n; for(int i=1;i<=n;i++) cin >> a[i]; a[n+1]=-1; int pos; for(int i=1;i<=n;i++){ if(a[i+1]>a[i]) mn.pb(a[i]); else{ pos=i+1; mn.pb(a[i]); break; } } int ans=0; for(int i=pos;i<=n;i++){ if(a[i+1]>a[i]){ vec.pb(a[i]); }else{ vec.pb(a[i]); ans = mergesort(ans); vec.clear(); mn.clear(); mn=mrgvec; mrgvec.clear(); } } cout << ans << '\n'; return 0; }

Compilation message (stderr)

money.cpp: In function 'int main()':
money.cpp:54:7: warning: 'pos' may be used uninitialized in this function [-Wmaybe-uninitialized]
   int pos;
       ^~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...