Submission #676465

# Submission time Handle Problem Language Result Execution time Memory
676465 2022-12-31T03:31:15 Z penguin133 Pancake (NOI12_pancake) C++17
25 / 25
275 ms 6900 KB
#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

pancake.cpp: In function 'int main()':
pancake.cpp:24:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   24 |     for(int i=0;i<tmp2.size();i++)tmp3.push_back(tmp2[i]);
      |                 ~^~~~~~~~~~~~
pancake.cpp:31:9: warning: unused variable 'a' [-Wunused-variable]
   31 |   int n,a;
      |         ^
# Verdict Execution time Memory Grader output
1 Correct 254 ms 6888 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 260 ms 6740 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 275 ms 6784 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 251 ms 6724 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 260 ms 6900 KB Output is correct