# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
477810 | 2021-10-04T01:35:57 Z | sumit_kk10 | Pancake (NOI12_pancake) | C++14 | 293 ms | 12016 KB |
#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
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 275 ms | 11852 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 262 ms | 11944 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 287 ms | 11848 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 293 ms | 11872 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 290 ms | 12016 KB | Output is correct |