Submission #987606

#TimeUsernameProblemLanguageResultExecution timeMemory
987606OtalpPermutation (APIO22_perm)C++17
100 / 100
49 ms856 KiB
#include "perm.h" #include<bits/stdc++.h> using namespace std; #define ll long long #define pb push_back ll pref[200][200], suf[200][200]; ll a[200100]; ll n; void calc(){ for(int x=0; x<=n + 1; x++) pref[0][x] = 1; for(int i=1; i<=n; i++){ for(int x=0; x<=n + 1; x++){ pref[i][x] = pref[i - 1][x]; if(a[i] <= x){ pref[i][x] += pref[i-1][a[i]]; } } } for(int x=0; x<=n + 1; x++) suf[n + 1][x] = 1; for(int i=n; i>=1; i--){ for(int x=n + 1; x>=0; x--){ suf[i][x] = suf[i + 1][x]; if(a[i] >= x){ suf[i][x] += suf[i + 1][a[i]]; } } } } vector<int> construct_permutation(ll k){ n = 1; a[1] = 1; calc(); ll g = pref[n][n]; while(g != k){ ll d = 0; ll pos, x; for(int i=1; i<=n + 1; i++){ for(int j=1; j<=n+1; j++){ ll h = pref[i - 1][j - 1] * suf[i][j]; //cout<<i<<' '<<j<<'\n'; //cout<<h<<'\n'; if(h > d and h <= k - g){ d = h; x = j; pos = i; } } } //cout<<g<<' '<<pos<<' '<<x<<'\n'; vector<int> q; for(int i=1; i<pos; i++){ q.pb(a[i] + (a[i] >= x)); } q.pb(x); for(int i=pos; i<=n; i++){ q.pb(a[i] + (a[i] >= x)); } n ++; for(int i=1; i<=n; i++){ a[i] = q[i - 1]; } calc(); g = pref[n][n]; } vector<int> res; for(int i=1; i<=n; i++) res.pb(a[i]-1); //for(int d: res) cout<<d<<' '; //cout<<'\n'; return res; }

Compilation message (stderr)

perm.cpp: In function 'std::vector<int> construct_permutation(long long int)':
perm.cpp:41:12: warning: 'pos' may be used uninitialized in this function [-Wmaybe-uninitialized]
   41 |         ll pos, x;
      |            ^~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...