Submission #477810

#TimeUsernameProblemLanguageResultExecution timeMemory
477810sumit_kk10Pancake (NOI12_pancake)C++14
25 / 25
293 ms12016 KiB
#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)

pancake.cpp: In function 'void solve()':
pancake.cpp:22:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   22 |     for(int i = 0; i < a.size(); ++i)
      |                    ~~^~~~~~~~~~
pancake.cpp: In function 'int main()':
pancake.cpp:42:26: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   42 |         for(int i = 1; i < temp.size(); ++i){
      |                        ~~^~~~~~~~~~~~~
pancake.cpp:47:34: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   47 |             for(int j = i + 1; j < temp.size(); ++j)
      |                                ~~^~~~~~~~~~~~~
#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...