# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
676465 | penguin133 | Pancake (NOI12_pancake) | C++17 | 275 ms | 6900 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
using namespace std;
map<vector<int>, int> m;
map<int, int> m2;
int main(){
ios::sync_with_stdio(0);cin.tie(0);
for(int i=1;i<=8;i++){
vector<int>ans;
for(int j=i;j>=1;j--)ans.push_back(j);
m[ans] = 1;
queue<pair<int, vector<int> > >q;
q.push(make_pair(1, ans));
while(!q.empty()){
int x = q.front().first;
vector<int>tmp = q.front().second;
vector<int>ab = tmp;
q.pop();
vector<int>tmp2, tmp3;
while(!tmp.empty()){
int y = tmp.back();
tmp.pop_back();
tmp2.push_back(y);
tmp3 = tmp;
for(int i=0;i<tmp2.size();i++)tmp3.push_back(tmp2[i]);
if(!m[tmp3] || m[tmp3] > m[ab] + 1)m[tmp3] = m[ab] + 1, q.push(make_pair(x+1, tmp3));
}
}
}
int t;cin >> t;
while(t--){
int n,a;
cin >> n;
pair<int, int> A[9];
for(int i=1;i<=n;i++)cin >> A[i].first, A[i].second = i;
sort(A+1, A+n+1);
vector<int> v(n);
for(int i=1;i<=n;i++)v[A[i].second - 1] = i;
cout << m[v] - 1 << '\n';
}
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |