Submission #1070758

#TimeUsernameProblemLanguageResultExecution timeMemory
1070758AdamGSPermutation (APIO22_perm)C++17
100 / 100
329 ms8272 KiB
#include "perm.h" #include<bits/stdc++.h> using namespace std; typedef long long ll; #define rep(a, b) for(int a = 0; a < (b); ++a) #define st first #define nd second #define pb push_back #define all(a) a.begin(), a.end() const int LIM=1e6+7; ll dp[LIM]; bool pre=false; void prepro() { rep(i, LIM) dp[i]=LIM; dp[1]=0; dp[2]=1; for(int n=3; n<LIM; ++n) { for(int i=1; i<=20; ++i) if(n-i-1>0) dp[n]=min(dp[n], dp[n-i]+dp[i+1]); for(int i=2; i<=100; ++i) if(n%i==0) dp[n]=min(dp[n], dp[n/i]+dp[i]); } ll ans=0; for(int i=1; i<LIM; ++i) ans=max(ans, dp[i]); } vector<int>mnoz(vector<int>A, vector<int>B) { ll x=A.size(); for(auto i : B) A.pb(i+x); return A; } vector<int>dodaj(vector<int>A, vector<int>B) { rep(i, A.size()) A[i]+=B.size(); for(auto i : B) A.pb(i); return A; } vector<int>gendp(ll k) { if(k==1) return {}; if(k==2) return {0}; for(int i=1; i<=20; ++i) if(k-i-1>0 && dp[k]==dp[k-i]+dp[i+1]) { return dodaj(gendp(k-i), gendp(i+1)); } for(int i=2; i<=100; ++i) if(k%i==0 && dp[k]==dp[k/i]+dp[i]) { return mnoz(gendp(k/i), gendp(i)); } return {}; } vector<int>gen(ll k) { if(k<LIM) return gendp(k); for(ll i=20; i>=2; --i) { if(k%i>0) continue; return mnoz(gendp(i), gen(k/i)); } vector<int>ans={}; for(ll i=2; i<=3; ++i) { ll p=k%i; vector<int>P=dodaj(gendp(p+1), mnoz(gendp(i), gen(k/i))); if(ans.size()==0 || P.size()<ans.size()) ans=P; } return ans; } vector<int>construct_permutation(ll k) { if(!pre) { pre=true; prepro(); } return gen(k); }

Compilation message (stderr)

perm.cpp: In function 'std::vector<int> dodaj(std::vector<int>, std::vector<int>)':
perm.cpp:5:36: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
    5 | #define rep(a, b) for(int a = 0; a < (b); ++a)
      |                                    ^
perm.cpp:30:2: note: in expansion of macro 'rep'
   30 |  rep(i, A.size()) A[i]+=B.size();
      |  ^~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...