Submission #93190

#TimeUsernameProblemLanguageResultExecution timeMemory
93190abood101Pancake (NOI12_pancake)C++17
12 / 25
6 ms504 KiB
#include <bits/stdc++.h> using namespace std; typedef pair<int,int > pp; typedef long long ll; int const N=3e5+10,oo=1e9,M=1e6+2; ll const OO=1e18; double const eps=1e-6,PI=acos(-1); int mod=oo+7; vector<int > v,o; int n,cnt; int solve(int idx){ cnt++; if(idx==n)return 0; if(v[idx]==o[idx])return solve(idx+1); int mn=oo; for(int j=idx+1;j<n;j++)if(v[j]==o[idx]){ reverse(v.begin()+j,v.end()); reverse(v.begin()+idx,v.end()); mn=min(mn,solve(idx+1)+1+(j!=n-1)); reverse(v.begin()+idx,v.end()); reverse(v.begin()+j,v.end()); } return mn; } int main(){ ios::sync_with_stdio(0); cin.tie(0); int t; cin>>t; while(t--){ cin>>n; v.clear(); v.resize(n); for(int i=0;i<n;i++)cin>>v[i]; o=v; sort(o.begin(),o.end()); reverse(o.begin(),o.end()); cout<<solve(0)<<'\n'; } return 0; }
#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...