# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
169157 | itgl | Money (IZhO17_money) | C++14 | 2 ms | 376 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#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)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |