Submission #93192

# Submission time Handle Problem Language Result Execution time Memory
93192 2019-01-07T06:05:54 Z abood101 Pancake (NOI12_pancake) C++17
12 / 25
8 ms 376 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;

int solve(int idx,int ke=0){
    if(idx==n)return ke;
    if(v[idx]==o[idx])return solve(idx+1,ke);
    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,ke)+1+(j!=n-1));
        reverse(v.begin()+idx,v.end());        
        reverse(v.begin()+j,v.end());
        
    }
    if(!ke){
        reverse(o.begin()+idx,o.end());
        mn=min(mn,solve(idx,1));
        reverse(o.begin()+idx,o.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());
        int an=solve(0);
        cout<<an<<'\n';
    }
    return 0;
}

# Verdict Execution time Memory Grader output
1 Correct 2 ms 256 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 Correct 2 ms 376 KB Output is correct
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 256 KB Output isn't correct
# Verdict Execution time Memory Grader output
1 Incorrect 8 ms 376 KB Output isn't correct