Submission #1114825

#TimeUsernameProblemLanguageResultExecution timeMemory
1114825NipphitchPancake (NOI12_pancake)C++14
12 / 25
4 ms336 KiB
#include <bits/stdc++.h> using namespace std; #define int long long void slove(){ int n,tmp=0,ans=0; vector <int> a,b; cin >> n; for(int i=0;i<n;i++){ int x; cin >> x; a.push_back(x); b.push_back(x); } sort(b.begin(),b.end(),greater <int>()); for(int i=0;i<n && tmp<n;i++){ if(a[tmp]==b[tmp]) tmp++; else if(a[n-1]==b[tmp]){ reverse(a.begin()+tmp,a.end()); ans++; tmp++; } else{ for(int j=tmp+1;j<n-1;j++){ if(a[j]==b[tmp]){ reverse(a.begin()+j,a.end()); ans++; reverse(a.begin()+tmp,a.end()); ans++; tmp++; } } } } cout << ans << "\n"; } signed main() { ios::sync_with_stdio(0); cin.tie(0); int tc=1; cin >> tc; while(tc--) slove(); }
#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...