| # | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
|---|---|---|---|---|---|---|---|
| 704745 | beaconmc | 순열 (APIO22_perm) | C++17 | 0 ms | 0 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
//#include "perm.h"
typedef long long ll;
#define FOR(i,x,y) for(ll i=x; i<y; i++)
using namespace std;
vector<int> perm(ll k, ll shi){
if (k==2){
return {(int)shi};
}
ll imp = k;
vector<ll> ops;
deque<ll> sus;
while (k>1){
bool flag = false;
FOR(i,2,min((ll)1000, (ll)k)){
if (k%i==0){
ops.push_back(i);
k /= i;
flag = true;
break;
}
}
if (flag) continue;
ops.push_back(1);
k -= 1;
}
ll cur = shi;
reverse(ops.begin(), ops.end());
for (auto&i : ops){
if (i==1) sus.push_front(cur++);
else{
ll temp = 0;
for (auto&j : perm(i, cur)){
temp++;
sus.push_back(j);
}
cur += temp;
}
}
vector<int> ans;
for (auto&i : sus) ans.push_back(i);
return ans;
}
vector<int> construct_permutation(long long k){
return perm(k, 0);
}
int main(){
vector<int> a = perm(1000000000000000000,0);
for (auto&i : a) cout << i << " ";
}
