# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
477810 | sumit_kk10 | Pancake (NOI12_pancake) | C++14 | 293 ms | 12016 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>
#define fast ios_base::sync_with_stdio(0);cin.tie(NULL);cout.tie(NULL)
#define ll long long int
#define ld long double
using namespace std;
const int N = 1e6 + 5;
const int MOD = 1e9 + 7;
int n;
map<vector<int>, int> ans;
map<vector<int>, bool> vis;
void solve(){
cin >> n;
vector<pair<int, int> > a(n);
for(int i = 0; i < n; ++i){
cin >> a[i].first;
a[i].second = i;
}
sort(a.begin(), a.end());
int ct = 0;
vector<int> v(n);
for(int i = 0; i < a.size(); ++i)
v[a[i].second] = ++ct;
reverse(v.begin(), v.end());
cout << ans[v] << "\n";
}
int main(){
fast;
vector<int> cur;
queue<pair<vector<int>, int> > q;
for(int i = 1; i <= 8; ++i){
cur.push_back(i);
q.push({cur, 0});
}
while(!q.empty()){
vector<int> temp = q.front().first;
int dis = q.front().second;
q.pop();
vis[temp] = true;
ans[temp] = dis;
for(int i = 1; i < temp.size(); ++i){
// flipping 0..i;
vector<int> gar;
for(int j = i; j >= 0; --j)
gar.push_back(temp[j]);
for(int j = i + 1; j < temp.size(); ++j)
gar.push_back(temp[j]);
if(vis[gar]) continue;
vis[gar] = true;
q.push({gar, dis + 1});
}
}
int t = 1;
cin >> t;
while(t--)
solve();
return 0;
}
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... |