이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include "perm.h"
#include <bits/stdc++.h>
using namespace std;
const long long MX = 1e18;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
int randint(int l, int r){
return uniform_int_distribution <int> (l, r) (rng);
}
double randdouble(double l, double r){
return uniform_real_distribution <double> (l, r) (rng);
}
long long count_increasing(const vector<int>& v) {
vector<long long> dp(v.size() + 1, 0);
dp[0] = 1;
for (int x : v)
{
for (int i = 0; i <= x; i++)
{
dp[x+1] += dp[i];
dp[x+1] = min(dp[x+1],MX+1);
}
}
long long result = 0;
for (int i = 0; i <= (int)v.size(); i++){
result += dp[i];
result = min(result,MX+1);
}
return result;
}
vector <int> try_opt(long long k){
vector <int> ans;
for(int i = 0;; ++i){
vector <int> tmp;
int sz = i + 1;
if (ans.empty()) ans.push_back(i);
else {
int l = -1, r = sz;
while(l + 1 < r){
int p = (l + r) >> 1;
vector<int> cur = ans;
cur.insert(cur.begin() + p, i);
int v = count_increasing(cur);
if (v == k) return cur;
if (v <= k) l = p;
else r = p;
}
int ran = randint(0, 10);
if (ran <= 8) ran = 0;
else if (ran == 9) ran = 1;
else ran = 2;
l -= min(ran, l);
ans.insert(ans.begin() + l, i);
}
if (count_increasing(ans) == k){
break;
}
}
return ans;
}
std::vector<int> construct_permutation(long long k)
{
vector <int> ans;
//return ans;
for(int i = 0;; ++i){
vector <int> tmp;
int sz = i + 1;
if (ans.empty()) ans.push_back(i);
else {
int l = -1, r = sz;
while(l + 1 < r){
int p = (l + r) >> 1;
vector<int> cur = ans;
cur.insert(cur.begin() + p, i);
if (count_increasing(cur) <= k) l = p;
else r = p;
}
ans.insert(ans.begin() + l, i);
}
if (count_increasing(ans) == k){
break;
}
}
while (1.0 * clock() / CLOCKS_PER_SEC <= 0.7){
vector <int> ans1 = try_opt(k);
if (ans1.size() < ans.size()) ans = ans1;
}
return ans;
}
| # | Verdict | Execution time | Memory | Grader output |
|---|
| Fetching results... |
| # | Verdict | Execution time | Memory | Grader output |
|---|
| Fetching results... |