Submission #709745

#TimeUsernameProblemLanguageResultExecution timeMemory
709745gun_ganPermutation (APIO22_perm)C++17
81.31 / 100
8 ms936 KiB
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;

static long long MX=1e18;

vector<int> construct_permutation(long long k) {
	vector<vector<int>> ans;

	int last = 0;
	ll temp = 1;
	for(int i = 59; i > 4; i -= 5) {
		ll cur = 0;
		for(int j = i, z = 4; j > i - 5; j--, z--) {
			cur += (k >> j & 1) << z;
		}

		if(cur > 0) {
			ans.push_back({});
			for(int j = 0; j < i - 4; j++) {
				ans.back().push_back(last);
				last++;
			}

			for(int j = 0; j < cur - 1; j++) {
				ans.back().push_back(last + cur - j - 2);
			}

			temp += (1LL << (i - 4)) * cur - 1;

			last += cur - 1;
		}	
	}

	for(int i = 0; i < k - temp; i++) {
		ans.push_back({last});
		last++;
	}

	vector<int> ret;
	reverse(ans.begin(), ans.end());

	for(auto x : ans) {
		for(auto i : x) ret.push_back(i);
	}
	
	return ret;
}

/*
long long count_increasing(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;
}

int main() {
	cin.tie(0); ios_base::sync_with_stdio(0);
 
 	for(int i = 2; i <= 100000; i++) {
 		auto v = construct_permutation(i);
 		if(count_increasing(v) != i) {
 			cout << i << " keluarnya " << count_increasing(v) << '\n';
 			cout << bitset<7>(i) << '\n';
 		}
 	}
}
*/

Compilation message (stderr)

perm.cpp:5:18: warning: 'MX' defined but not used [-Wunused-variable]
    5 | static long long MX=1e18;
      |                  ^~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...