Submission #932702

#TimeUsernameProblemLanguageResultExecution timeMemory
932702nguyentunglamPermutation (APIO22_perm)C++17
100 / 100
6 ms460 KiB
#include<bits/stdc++.h> #define fi first #define se second #define endl "\n" #define ii pair<int, int> using namespace std; const long long inf = 2e18; long long calc (vector<int> a) { vector<long long> f(a.size()); long long ret = 1; for(int i = 0; i < a.size(); i++) { f[i] = 1; for(int j = 0; j < i; j++) if (a[j] < a[i]) f[i] = min(inf, f[i] + f[j]); ret += f[i]; } return ret; } vector<int> get (vector<int> p) { vector<int> rrh = p; sort(rrh.begin(), rrh.end()); rrh.resize(unique(rrh.begin(), rrh.end()) - rrh.begin()); auto get = [&] (int x) { return lower_bound(rrh.begin(), rrh.end(), x) - rrh.begin(); }; for(auto &j : p) j = get(j); return p; } vector<int> construct_permutation(long long k) { vector<int> a; while (k >= 4) { a.push_back(k % 4); k /= 4; } reverse(a.begin(), a.end()); vector<int> p; if (k == 2) p = {0}; if (k == 3) p = {1, 0}; for(int &j : a) { int mx = p.size(); if (j == 0) { p.push_back(mx); p.push_back(mx + 1); } if (j == 1) { p.push_back(mx); p.push_back(mx + 1); p.push_back(-1); } if (j == 2) { p.push_back(mx); p.push_back(-1); p.push_back(mx + 1); } if (j == 3) { int x = -1; for(auto &j : p) if (j == 0 || j == 1) { x = j; break; } if (p.size() >= 2 && x == 1) { p.push_back(mx); p.push_back(mx + 1); for(int &j : p) if (j >= 2) j++; p.push_back(2); } else { p.push_back(mx); p.push_back(-1); p.push_back(mx + 1); p.push_back(-2); } } p = get(p); } return p; } #ifdef ngu int main() { freopen ("task.inp", "r", stdin); freopen ("task.out", "w", stdout); long long k; cin >> k; vector<int> ans = construct_permutation(k); for(int &j : ans) cout << j << " "; cout << endl; cerr << ans.size() << endl; assert(calc(ans) == k); } #endif // ngu

Compilation message (stderr)

perm.cpp: In function 'long long int calc(std::vector<int>)':
perm.cpp:13:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   13 |   for(int i = 0; i < a.size(); i++) {
      |                  ~~^~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...