Submission #709760

# Submission time Handle Problem Language Result Execution time Memory
709760 2023-03-14T11:39:26 Z gun_gan Permutation (APIO22_perm) C++17
91.3333 / 100
3 ms 352 KB
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;

const ll MX = 1e18;

vector<int> construct_permutation(ll k) {
	ll b = 63 - __builtin_clzll(k);
	ll c = 0;

	vector<int> V;

	for(int i = 0; i < b; i++) {
		c += 100;
		V.push_back(c);
	}

	vector<int> v;
	for(int i = 0; i < b; i++) {
		if(!(k >> i & 1)) continue;
		int k = i;
		for(int j = (int)V.size() - 1; j >= 0 && k >= 0; j--, k--)  {
			if(k == 0) v.push_back(i + 1 + V[j]);
		}
	}

	for(auto x : V) v.push_back(x);

	vector<int> vals;
	for(auto x : v) vals.push_back(x);
	sort(vals.begin(), vals.end());

	vector<int> ret;	
	for(auto x : v) {
		for(int i = 0; i < vals.size(); i++) {
			if(vals[i] == x) {
				ret.push_back(i);
				break;
			}
		}
	}

	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);

	// auto v = construct_permutation(6);
	// for(auto x : v) {
	// 	cout << x << " ";
	// }
	// cout << '\n';

	// cout << count_increasing(v) << '\n';
 
 	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

perm.cpp: In function 'std::vector<int> construct_permutation(ll)':
perm.cpp:35:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   35 |   for(int i = 0; i < vals.size(); i++) {
      |                  ~~^~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 296 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Partially correct 2 ms 352 KB Partially correct
6 Correct 2 ms 340 KB Output is correct
7 Correct 2 ms 340 KB Output is correct
8 Partially correct 2 ms 340 KB Partially correct
9 Correct 2 ms 300 KB Output is correct
10 Partially correct 3 ms 340 KB Partially correct
11 Partially correct 2 ms 300 KB Partially correct
12 Partially correct 2 ms 340 KB Partially correct
13 Partially correct 2 ms 340 KB Partially correct