Submission #93364

# Submission time Handle Problem Language Result Execution time Memory
93364 2019-01-07T18:42:09 Z abood101 Pancake (NOI12_pancake) C++17
25 / 25
699 ms 27244 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 > o;
int n;
map<vector<int > ,int > dp[10];
int rec(int dep,vector<int > v){
    if(v==o)return dep;
    if(dep>n)return oo;
    if(dp[dep].find(v)!=dp[dep].end())return dp[dep][v];
    int ret=oo;
    for(int i=0;i<n-1;i++){
        reverse(v.begin()+i,v.end());
        ret=min(ret,rec(dep+1,v));
        reverse(v.begin()+i,v.end());
    }
    return dp[dep][v]=ret;
}
int main(){
    ios::sync_with_stdio(0);
    cin.tie(0);
    int t;
    cin>>t;
    while(t--){
        cin>>n;
        vector<int > a(n);
        for(int i=0;i<n;i++)cin>>a[i];
        o=a;
        sort(o.begin(),o.end());
        reverse(o.begin(),o.end());
        cout<<rec(0,a)<<'\n';
    }
    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 356 ms 13404 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 462 ms 15520 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 699 ms 27244 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 313 ms 13628 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 455 ms 19252 KB Output is correct