Submission #1011758

#TimeUsernameProblemLanguageResultExecution timeMemory
1011758dimashhhPermutation (APIO22_perm)C++17
0 / 100
1 ms344 KiB
#include "perm.h" #include <bits/stdc++.h> using namespace std; typedef long long ll; ll dp[150],val[150]; ll K; ll calc(vector<int> x){ ll S = 1; for(int i = 0;i < (int)x.size();i++){ val[i] = 0; } for(int i = 0;i < (int)x.size();i++){ dp[i] = 1; for(int j = 0;j < x[i];j++){ dp[i] += val[j]; if(dp[i] > K) return K + 1; } S += dp[i]; if(S > K) return K + 1; val[x[i]] = dp[i]; } return S; } vector<int> ins(vector<int> &x,int a){ vector<int> ret = x; for(int i = 0;i < (int)ret.size();i++){ if(ret[i] >= a){ ret[i]++; } } ret.push_back(a); return ret; } vector<int> solve(ll k,ll G,vector<int> a){ ll it = 3; while(G * it <= k){ G *= it; int m = (int)a.size(); for(int j = m + it - 2;j >= m;j--){ a.push_back(j); } } while(G != k){ ll mx = -1; int pos; vector<pair<int,int>> tt; vector<int> t; for(int j = 0;j < (int)a.size();j++){ tt.push_back({a[j],j}); t.push_back(a[j] + 1); } sort(tt.begin(),tt.end()); t.push_back(0); for(int i = 0;i <= (int)a.size();i++){ ll val = calc(t); if(val <= k){ if(val > mx){ mx = val; pos = i; } } t.pop_back(); t.push_back(i + 1); if(i != (int)a.size()){ t[tt[i].second]--; } } G = mx; a = ins(a,pos); } return a; } vector<int> construct_permutation(long long k) { K = k; vector<int> ret; if(k == 1) return ret; auto upd = [&](vector<int> f){ if((int)ret.size() > (int)f.size()){ ret = f; } }; ret = solve(k,1ll,vector<int>()); if(k >= 3)upd(solve(k,3,{1,0})); if(k >= 8) upd(solve(k,8,{0,1})); return ret; }

Compilation message (stderr)

perm.cpp: In function 'std::vector<int> solve(ll, ll, std::vector<int>)':
perm.cpp:71:16: warning: 'pos' may be used uninitialized in this function [-Wmaybe-uninitialized]
   71 |   a = ins(a,pos);
      |                ^
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...