답안 #975670

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
975670 2024-05-05T17:12:06 Z ShaShi 순열 (APIO22_perm) C++17
91.3333 / 100
2 ms 600 KB
#include "perm.h"
#include <bits/stdc++.h>
#define F first
#define S second
#define all(x) x.begin(), x.end()
#define pb push_back
#define mp make_pair
#define pii pair<int, int>



using namespace std;

typedef long long ll;


const int MAXN = (int)1e6 + 7;
const int LG = 60;



vector<int> solve1(ll k) {
	vector<int> res;

	bool flag = 0;

	for (int i=LG-1; i>=0; i--) {
		if (!(k&(1ll<<i))) continue;

		if (!flag) {
			for (int j=1; j<=i; j++) res.pb(j);
			flag = 1;

			continue;
		}

		for (int j=0; j<res.size(); j++) if (res[j] >= i+1) res[j]++;
		res.pb(i+1);
	}

	for (int i=0; i<res.size(); i++) res[i]--;

	return res;
}


vector<int> solve2(ll k) {
	vector<int> res;

	if (k == 0) return res;

	if (k&1ll) {
		res = solve2((k-1)/2);

		int mx = 0;
		for (int i=0; i<res.size(); i++) mx = max(mx, res[i]);

		res.pb(mx+1);
	} else {
		res = solve2(k/2-1);

		int mx = 1;
		for (int i=0; i<res.size(); i++) mx = max(mx, ++res[i]);

		res.pb(mx+1); res.pb(1);
	}

	return res;
}


vector<int> construct_permutation(ll k) {
	vector<int> res1 = solve1(k);

	if (res1.size() <= 90) return res1;

	res1 = solve2(k-1);
	for (int i=0; i<res1.size(); i++) res1[i]--;

	return res1;
}



// int main() {
// 	vector<int> res = construct_permutation(10);

// 	for (int i:res) cout << i << " ";


// 	return 0;
// }

Compilation message

perm.cpp: In function 'std::vector<int> solve1(ll)':
perm.cpp:37:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   37 |   for (int j=0; j<res.size(); j++) if (res[j] >= i+1) res[j]++;
      |                 ~^~~~~~~~~~~
perm.cpp:41:17: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   41 |  for (int i=0; i<res.size(); i++) res[i]--;
      |                ~^~~~~~~~~~~
perm.cpp: In function 'std::vector<int> solve2(ll)':
perm.cpp:56:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   56 |   for (int i=0; i<res.size(); i++) mx = max(mx, res[i]);
      |                 ~^~~~~~~~~~~
perm.cpp:63:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   63 |   for (int i=0; i<res.size(); i++) mx = max(mx, ++res[i]);
      |                 ~^~~~~~~~~~~
perm.cpp: In function 'std::vector<int> construct_permutation(ll)':
perm.cpp:78:17: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   78 |  for (int i=0; i<res1.size(); i++) res1[i]--;
      |                ~^~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 496 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 496 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Partially correct 1 ms 600 KB Partially correct
6 Correct 1 ms 348 KB Output is correct
7 Correct 1 ms 348 KB Output is correct
8 Partially correct 2 ms 348 KB Partially correct
9 Correct 1 ms 348 KB Output is correct
10 Partially correct 2 ms 348 KB Partially correct
11 Partially correct 2 ms 348 KB Partially correct
12 Partially correct 1 ms 348 KB Partially correct
13 Partially correct 2 ms 348 KB Partially correct