Submission #93190

# Submission time Handle Problem Language Result Execution time Memory
93190 2019-01-07T05:37:19 Z abood101 Pancake (NOI12_pancake) C++17
12 / 25
6 ms 504 KB
#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 time Memory Grader output
1 Correct 2 ms 480 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 504 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 504 KB Output isn't correct
# Verdict Execution time Memory Grader output
1 Incorrect 6 ms 504 KB Output isn't correct