QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#407745#4252. Permutationzhaohaikun#10 470ms4056kbC++201.9kb2024-05-09 10:35:282024-05-09 10:35:28

Judging History

你现在查看的是最新测评结果

  • [2024-05-09 10:35:28]
  • 评测
  • 测评结果:10
  • 用时:470ms
  • 内存:4056kb
  • [2024-05-09 10:35:28]
  • 提交

answer

#include "perm.h"
// MagicDark
#include <bits/stdc++.h>
#define debug cerr << "\033[32m[" << __LINE__ << "]\033[0m "
#define SZ(x) ((int) x.size() - 1)
#define all(x) x.begin(), x.end()
#define ms(x, y) memset(x, y, sizeof x)
#define F(i, x, y) for (int i = (x); i <= (y); i++)
#define DF(i, x, y) for (int i = (x); i >= (y); i--)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
template <typename T> T& chkmax(T& x, T y) {return x = max(x, y);}
template <typename T> T& chkmin(T& x, T y) {return x = min(x, y);}
template <typename T> T& read(T &x) {
	x = 0; int f = 1; char c = getchar();
	for (; !isdigit(c); c = getchar()) if (c == '-') f = -f;
	for (; isdigit(c); c = getchar()) x = (x << 1) + (x << 3) + (c ^ 48);
	return x *= f;
}
mt19937 mrand(chrono::steady_clock::now().time_since_epoch().count());
inline int rnd(int l, int r) {return mrand() % (r - l + 1) + l;}
vector <int> solve(ll n) {
	vector <int> ans;
	DF(i, 60, 1) {
		ll w = (1ll << i) - 1;
		while (n >= w) {
			for (int& j: ans) j += i;
			F(j, 1, i) ans.push_back(j - 1);
			n -= w;
		}
	}
	return ans;
}
int dp[1010];
int calc(vector <int> x) {
	int s = 0;
	F(i, 0, SZ(x)) {
		dp[i] = 1;
		F(j, 0, i - 1) {
			if (x[j] < x[i]) {
				dp[i] += dp[j];
			}
		}
		s += dp[i];
	}
	return s;
}
std::vector<int> construct_permutation(long long n) {
	n--;
	vector <int> ans;
	// if (n <= 90) {
	// 	F(i, 1, n) ans.push_back(n - i);
	// 	return ans;
	// }
	ans = solve(n);
	F(i, 1, 7) {
		vector <int> t(i);
		F(j, 1, i) t[j - 1] = j - 1;
		do {
			int v = calc(t);
			// debug << v << endl;
			if (n >= v) {
				vector <int> w = solve(n - v);
				if (w.size() + i < ans.size()) {
					ans.clear();
					for (int j: t) ans.push_back(j + w.size());
					for (int j: w) ans.push_back(j);
				}
			}
		} while (next_permutation(all(t)));
	}
	return ans;
}

Details

Tip: Click on the bar to expand more detailed information

Subtask #1:

score: 10
Accepted

Test #1:

score: 10
Accepted
time: 111ms
memory: 3956kb

input:

a92b3f80-b312-8377-273c-3916024d7f2a
89
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90

output:

6cad0f33-b1bd-3a3e-1a8d-c4af23adfcbf
OK
1
0
2
1 0
2
0 1
3
1 2 0
3
0 2 1
4
2 3 0 1
3
0 1 2
4
1 2 3 0
4
0 2 3 1
5
2 3 4 0 1
4
0 1 3 2
5
1 2 4 3 0
5
0 2 4 3 1
5
1 0 3 4 2
4
0 1 2 3
5
1 2 3 4 0
5
0 2 1 4 3
6
2 3 4 5 0 1
5
0 1 3 4 2
6
1 2 4 5 3 0
6
0 2 4 5 3 1
6
1 2 4 0 5 3
5
0 1 2 4 3
6
1 2 3 5 4 0
6
0 ...

result:

ok 

Subtask #2:

score: 0
Time Limit Exceeded

Test #2:

score: 86
Acceptable Answer
time: 279ms
memory: 4056kb

input:

a92b3f80-b312-8377-273c-3916024d7f2a
100
39993
85709
48645
25391
15360
54084
28947
18808
86735
316
14357
82845
96210
16242
58466
43439
77462
70742
76176
20397
30314
22634
29622
81835
31904
81283
37072
36527
26764
55878
72762
5262
34915
63468
20595
66579
77373
36670
89340
83384
73268
31960
67318
3908...

output:

6cad0f33-b1bd-3a3e-1a8d-c4af23adfcbf
OK
56
49 50 52 51 54 55 53 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 22 23 24 25 26 27 28 29 30 31 32 33 11 12 13 14 15 16 17 18 19 20 21 1 2 3 4 5 6 7 8 9 10 0
76
69 70 71 72 74 75 73 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 39 40 41 42 43 44 45 46 47 ...

result:

points 0.95555555560

Test #3:

score: 75.4308
Acceptable Answer
time: 470ms
memory: 3996kb

input:

a92b3f80-b312-8377-273c-3916024d7f2a
100
2147483647
1073741823
536870911
268435455
134217727
67108863
33554431
16777215
8388607
4194303
2097151
1582
24319
38
463
7
1073741503
3
18
3
3780
2
24934
124910
65535
154
1069539071
209452285
1662
3
3
93
4070
131071
502986749
3164
268430159
247
21746
124927
1...

output:

6cad0f33-b1bd-3a3e-1a8d-c4af23adfcbf
OK
60
30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29
58
29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 ...

result:

points 0.83811965810

Test #4:

score: 0
Time Limit Exceeded

input:

a92b3f80-b312-8377-273c-3916024d7f2a
100
576460752303423487
288230376151711743
144115188075855871
72057594037927935
36028797018963967
18014398509481983
9007199254740991
4503599627370495
2251799813685247
1125899906842623
562949953421311
8166608599550
16508780543
33554427
43000192155799
62353919
71773...

output:

Unauthorized output

result: