Submission #676465

#TimeUsernameProblemLanguageResultExecution timeMemory
676465penguin133Pancake (NOI12_pancake)C++17
25 / 25
275 ms6900 KiB
#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)

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 timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...