제출 #958291

#제출 시각아이디문제언어결과실행 시간메모리
958291pragmatistPermutation (APIO22_perm)C++17
10 / 100
1096 ms704 KiB
#include "perm.h"
#include<bits/stdc++.h>
 
using namespace std;
 
long long dp[6000];
int a[6000];
int mn;
vector<int> ans;

void go(long long k, int n, int p[]) {
	for(int i = 1; i <= n; ++i) {
		a[i] = p[i-1];
	}
	long long cur = 1;
	for(int i = 1; i <= n; ++i) {
		dp[i] = 1;
		for(int j = 1; j < i; ++j) {
			if(a[j]<a[i]) {
				dp[i] += dp[j];
			}
		}
		cur += dp[i];
	}
	if(cur>k) {
		return;
	}
	int old = n;
	while(cur<k) {
		vector<pair<int, long long> > b;
		for(int i = 1; i <= n; ++i) {
			b.push_back({a[i], dp[i]});
		}
		sort(b.begin(), b.end());
		long long add = 1, need = k-cur;
		int nxt = 0;
		for(auto [x, y] : b) {
			if(add+y<=need) {
				nxt = x+1;
				add += y;								
			} else {
				break;
			}
		}
		for(int i = 0; i <= n; ++i) {
			if(a[i] >= nxt) {
				a[i]++;
			}
		}			
		a[++n] = nxt;
		dp[n] = add;
		cur += add;
	}
	assert(n<=200);
	vector<int> res;
	for(int i = 1; i <= n; ++i) {
		res.push_back(a[i]);
	}
	if(n<mn) {
		mn = n;
		ans = res;
	}
}

std::vector<int> construct_permutation(long long k) {
	mn = 1e9;
	int p[6];
	for(int n = 1; n <= 5; ++n) {
		for(int i = 0; i < n; ++i) {
			p[i] = i;
		} 
		do {
			go(k, n, p);	
		} while(next_permutation(p, p+n));
	}                
    return ans;
}

컴파일 시 표준 에러 (stderr) 메시지

perm.cpp: In function 'void go(long long int, int, int*)':
perm.cpp:28:6: warning: unused variable 'old' [-Wunused-variable]
   28 |  int old = n;
      |      ^~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...