Submission #932509

#TimeUsernameProblemLanguageResultExecution timeMemory
932509nguyentunglamPermutation (APIO22_perm)C++17
91.33 / 100
2 ms408 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> construct_permutation(long long k) { vector<int> p; int l = 0, r = 1e9; while (k != 1) { if (k % 2 == 0) p.push_back(--r); else { p.push_back(++l); p.push_back(--r); } k /= 2; } reverse(p.begin(), p.end()); vector<int> rrh = p; sort(rrh.begin(), rrh.end()); rrh.resize(unique(rrh.begin(), rrh.end()) - rrh.begin()); // for(int &j : rrh) cout << j << " "; cout << endl; auto get = [&] (int x) { return lower_bound(rrh.begin(), rrh.end(), x) - rrh.begin(); }; // cout << get(1); // cout << get(2) << endl; // cout << endl; for(int &j : p) j = get(j); 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; 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...