# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
169163 | 2019-12-18T18:26:46 Z | itgl | Money (IZhO17_money) | C++14 | 2 ms | 376 KB |
#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
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 2 ms | 376 KB | Output is correct |
2 | Incorrect | 2 ms | 376 KB | Output isn't correct |
3 | Halted | 0 ms | 0 KB | - |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 2 ms | 376 KB | Output is correct |
2 | Incorrect | 2 ms | 376 KB | Output isn't correct |
3 | Halted | 0 ms | 0 KB | - |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 2 ms | 376 KB | Output is correct |
2 | Incorrect | 2 ms | 376 KB | Output isn't correct |
3 | Halted | 0 ms | 0 KB | - |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 2 ms | 376 KB | Output is correct |
2 | Incorrect | 2 ms | 376 KB | Output isn't correct |
3 | Halted | 0 ms | 0 KB | - |