# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
731766 | 2023-04-27T23:40:32 Z | Trunkty | Pancake (NOI12_pancake) | C++14 | 169 ms | 11860 KB |
#include <bits/extc++.h> using namespace std; typedef long long ll; #define int ll int t; map<vector<int>,int> best; int arr[9]; signed main(){ ios_base::sync_with_stdio(false); cin.tie(NULL); for(int i=1;i<=8;i++){ vector<int> v; for(int j=i;j>=1;j--){ v.push_back(j); } best[v] = 1; vector<vector<int>> bfs = {v}; for(int j=0;j<bfs.size();j++){ vector<int> x = bfs[j]; for(int k=0;k<i-1;k++){ reverse(x.begin()+k,x.begin()+i); if(!best[x]){ best[x] = best[bfs[j]]+1; bfs.push_back(x); } reverse(x.begin()+k,x.begin()+i); } } } cin >> t; for(int e=1;e<=t;e++){ int n; cin >> n; vector<int> v; map<int,int> mp; for(int i=1;i<=n;i++){ cin >> arr[i]; v.push_back(arr[i]); } sort(v.begin(),v.end()); for(int i=0;i<v.size();i++){ mp[v[i]] = i+1; } vector<int> v2; for(int i=1;i<=n;i++){ v2.push_back(mp[arr[i]]); } cout << best[v2]-1LL << "\n"; } return 0; }
Compilation message
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 130 ms | 11820 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 134 ms | 11860 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 169 ms | 11760 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 142 ms | 11812 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 149 ms | 11768 KB | Output is correct |