Submission #1061309

#TimeUsernameProblemLanguageResultExecution timeMemory
1061309MuhammetPermutation (APIO22_perm)C++17
Compilation error
0 ms0 KiB
#include <bits/stdc++.h>
#include "perm.h"
#include "grader.cpp"

using namespace std;

#define ll long long
#define sz(s) (int)s.size()

const ll M = 1e18+1;

ll f(vector <int> v){
    int n = sz(v);
    vector <ll> dp(n+1,1);
    for(int i = 0; i < n; i++){
        for(int j = 0; j < i; j++){
            if(v[j] < v[i]){
            	if(M-dp[j] <= dp[i]) return M;
            	dp[i] += dp[j];
            }
        }
    }

    ll k = 0;
    for(int i = 0; i < n; i++){
        k += dp[i];
        k = min(k,M);
    }
    return k+1;
}

vector<int> construct_permutation(ll k){
	int x = -1;
	vector <int> v;
	int t = 1000;
	bool tr = 0;
	while(t--){
		x++;
		v.push_back(x);
		ll y = f(v);
		if(y == k){
			tr = 1;
			break;
		}
		if(y <= k) continue;
		for(int i = sz(v)-2; i >= 0; i--){
			swap(v[i],v[i+1]);
			y = f(v);
			if(y <= k) break;
		}
		if(y == k){
			tr = 1;
			break;
		}
	}
	return v;
}

Compilation message (stderr)

perm.cpp: In function 'std::vector<int> construct_permutation(long long int)':
perm.cpp:36:7: warning: variable 'tr' set but not used [-Wunused-but-set-variable]
   36 |  bool tr = 0;
      |       ^~
/usr/bin/ld: /tmp/ccAGvXz9.o: in function `main':
grader.cpp:(.text.startup+0x0): multiple definition of `main'; /tmp/ccGBNle9.o:perm.cpp:(.text.startup+0x0): first defined here
collect2: error: ld returned 1 exit status