이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#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);
}
컴파일 시 표준 에러 (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 time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |