제출 #987606

#제출 시각아이디문제언어결과실행 시간메모리
987606Otalp순열 (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; }

컴파일 시 표준 에러 (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...