Submission #169157

#TimeUsernameProblemLanguageResultExecution timeMemory
169157itglMoney (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[i]){ mrgvec.pb(mn[i]); i++; if(k!=1) ans++; k=1; }else{ mrgvec.pb(vec[j]); j++; if(k!=2) ans++; k=2; } } while(i<s1){ mrgvec.pb(mn[i]); i++; if(k!=1){ ans++; k=1; } } while(j<s2){ mrgvec.pb(vec[j]); j++; if(k!=2){ ans++; k=2; } } return ans; } int main(){ int n; cin >> n; for(int i=1;i<=n;i++) cin >> a[i]; a[n+1]=1e6+7; 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:51: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...