Submission #1116467

# Submission time Handle Problem Language Result Execution time Memory
1116467 2024-11-21T16:53:42 Z Nipphitch Pancake (NOI12_pancake) C++14
20 / 25
1000 ms 12188 KB
#include <bits/stdc++.h>
#pragma GCC optimize("O3,unroll-loops")
#pragma GCC target("avx2,bmi,bmi2,lzcnt,popcnt")
using namespace std;
const int N=1e5+5;
const int INF=1e9+7;

int n;
vector <int> a,b;
map <vector <int>,int> dp[10];

int rec(int d,vector <int> v){
    if(v==b) return d;
    if(d>n) return INF;
    if(dp[d].find(v)!=dp[d].end()) return dp[d][v];
    int res=INF;
    for(int i=0;i<n-1;i++){
        reverse(v.begin()+i,v.end());
        res=min(res,rec(d+1,v));
        reverse(v.begin()+i,v.end());
    }
    return dp[d][v]=res;
}

void slove(){
    a.clear();
    b.clear();
    for(int i=0;i<10;i++) dp[i].clear();
    cin >> n;
    for(int i=1;i<=n;i++){
        int x;
        cin >> x;
        a.push_back(x);
        b.push_back(x);
    }
    sort(b.begin(),b.end(),greater <int>());
    cout << rec(0,a) << "\n";
}

signed main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    int tc;
    cin >> tc;
    while(tc--) slove();
}
# Verdict Execution time Memory Grader output
1 Correct 184 ms 11848 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 397 ms 11992 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 586 ms 12108 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 203 ms 12104 KB Output is correct
# Verdict Execution time Memory Grader output
1 Execution timed out 1056 ms 12188 KB Time limit exceeded
2 Halted 0 ms 0 KB -