#include "bartender.h"
#include <bits/stdc++.h>
namespace {
using namespace std;
using big = __int128_t;
const int FOUR = 13;
const int THREE = 13;
const int TWELVE = 0;
big ep(int n, vector<int> perm){
assert((int)perm.size() == n);
big res = 0;
for(int i = 0; i < n; i++){
res *= (n - i);
res += perm[i];
for(int j = i+1; j < n; j++){
if(perm[j] > perm[i]) perm[j] -= 1;
}
}
return res;
}
vector<int> dp(int n, big val){
vector<int> perm(n, 0);
for(int i = n-1; i >= 0; i--){
int ind = val % (n - i);
val /= (n - i);
perm[i] = ind;
for(int j = i + 1; j < n; j++){
if(perm[j] >= perm[i]) perm[j] += 1;
}
}
return perm;
}
vector<int> encode_permutation(vector<int> perm, int fours, int threes){
big a = 1;
for(int i = 1; i <= fours; i++) a *= big(i);
big c = 1;
for(int i = 0; i < fours; i++) c *= FOUR;
for(int i = 0; i < threes; i++) c *= THREE;
assert(a <= c);
assert(dp(fours, ep(fours, perm)) == perm);
big val = ep(fours, perm);
vector<int> z;
for(int i = 0; i < threes; i++){
z.push_back(int(val % THREE)); val /= THREE;
}
for(int i = 0; i < fours; i++){
z.push_back(int(val % FOUR)); val /= FOUR;
}
assert(val == 0);
reverse(z.begin(), z.end());
return z;
}
vector<int> decode_permutation(vector<int> info, int fours, int threes){
int n = (int)info.size();
assert(n == fours + threes);
big r = 0;
for(int i = 0; i < fours; i++) r = r * FOUR + info[i];
for(int i = 0; i < threes; i++) r = r * THREE + info[fours + i];
vector<int> perm = dp(fours, r);
assert(ep(fours, perm) == r);
return perm;
}
vector<int> blendwines(int k, vector<int> r){
for(int& x : r) x -= 1;
int n = (int)r.size();
int num_big = min(TWELVE, n); // num_big
int num_small = n - num_big;
vector<int> small_perm;
for(int a : r){
if(a < num_small) small_perm.push_back(a);
}
assert((int)small_perm.size() == num_small);
vector<int> info = encode_permutation(small_perm, num_small, num_big);
assert(decode_permutation(info, num_small, num_big) == small_perm);
int j = 0;
vector<int> a(n);
for(int i = 0; i < n; i++){
if(r[i] < num_small){
a[i] = THREE + 1 + info[j];
j += 1;
}
}
for(int i = 0; i < n; i++){
if(r[i] >= num_small){
a[i] = 1 + info[j];
j += 1;
}
}
return a;
}
vector<int> sortwines(int k, vector<int> a) {
int n = (int)a.size();
int num_big = min(TWELVE, n); // num_big
int num_small = n - num_big;
vector<int> info;
for(int i = 0; i < n; i++) if(a[i] > THREE) info.push_back(a[i] - THREE - 1);
assert((int)info.size() == num_small);
for(int i = 0; i < n; i++) if(a[i] <= THREE) info.push_back(a[i] - 1);
assert((int)info.size() == n);
vector<int> perm = decode_permutation(info, num_small, num_big);
assert(encode_permutation(perm, num_small, num_big) == info);
int j = 0;
vector<int> r(n, -1);
vector<int> unknowns;
for(int i = 0; i < n; i++){
if(a[i] > THREE){
r[i] = perm[j];
j += 1;
} else {
unknowns.push_back(i);
}
}
for(int& x : r) x += 1;
return r;
}
}
vector<int> BlendWines(int k, vector<int> r){
return blendwines(k, r);
}
#include "taster.h"
#include <bits/stdc++.h>
namespace {
using namespace std;
using big = __int128_t;
const int FOUR = 13;
const int THREE = 13;
const int TWELVE = 0;
big ep(int n, vector<int> perm){
assert((int)perm.size() == n);
big res = 0;
for(int i = 0; i < n; i++){
res *= (n - i);
res += perm[i];
for(int j = i+1; j < n; j++){
if(perm[j] > perm[i]) perm[j] -= 1;
}
}
return res;
}
vector<int> dp(int n, big val){
vector<int> perm(n, 0);
for(int i = n-1; i >= 0; i--){
int ind = val % (n - i);
val /= (n - i);
perm[i] = ind;
for(int j = i + 1; j < n; j++){
if(perm[j] >= perm[i]) perm[j] += 1;
}
}
return perm;
}
vector<int> encode_permutation(vector<int> perm, int fours, int threes){
big a = 1;
for(int i = 1; i <= fours; i++) a *= big(i);
big c = 1;
for(int i = 0; i < fours; i++) c *= FOUR;
for(int i = 0; i < threes; i++) c *= THREE;
assert(a <= c);
assert(dp(fours, ep(fours, perm)) == perm);
big val = ep(fours, perm);
vector<int> z;
for(int i = 0; i < threes; i++){
z.push_back(int(val % THREE)); val /= THREE;
}
for(int i = 0; i < fours; i++){
z.push_back(int(val % FOUR)); val /= FOUR;
}
assert(val == 0);
reverse(z.begin(), z.end());
return z;
}
vector<int> decode_permutation(vector<int> info, int fours, int threes){
int n = (int)info.size();
assert(n == fours + threes);
big r = 0;
for(int i = 0; i < fours; i++) r = r * FOUR + info[i];
for(int i = 0; i < threes; i++) r = r * THREE + info[fours + i];
vector<int> perm = dp(fours, r);
assert(ep(fours, perm) == r);
return perm;
}
vector<int> blendwines(int k, vector<int> r){
for(int& x : r) x -= 1;
int n = (int)r.size();
int num_big = min(TWELVE, n); // num_big
int num_small = n - num_big;
vector<int> small_perm;
for(int a : r){
if(a < num_small) small_perm.push_back(a);
}
assert((int)small_perm.size() == num_small);
vector<int> info = encode_permutation(small_perm, num_small, num_big);
assert(decode_permutation(info, num_small, num_big) == small_perm);
int j = 0;
vector<int> a(n);
for(int i = 0; i < n; i++){
if(r[i] < num_small){
a[i] = THREE + 1 + info[j];
j += 1;
}
}
for(int i = 0; i < n; i++){
if(r[i] >= num_small){
a[i] = 1 + info[j];
j += 1;
}
}
return a;
}
vector<int> sortwines(int k, vector<int> a) {
int n = (int)a.size();
int num_big = min(TWELVE, n); // num_big
int num_small = n - num_big;
vector<int> info;
for(int i = 0; i < n; i++) if(a[i] > THREE) info.push_back(a[i] - THREE - 1);
assert((int)info.size() == num_small);
for(int i = 0; i < n; i++) if(a[i] <= THREE) info.push_back(a[i] - 1);
assert((int)info.size() == n);
vector<int> perm = decode_permutation(info, num_small, num_big);
assert(encode_permutation(perm, num_small, num_big) == info);
int j = 0;
vector<int> r(n, -1);
vector<int> unknowns;
for(int i = 0; i < n; i++){
if(a[i] > THREE){
r[i] = perm[j];
j += 1;
} else {
unknowns.push_back(i);
}
}
for(int& x : r) x += 1;
return r;
}
}
vector<int> SortWines(int k, vector<int> r){
return sortwines(k, r);
}
Compilation message
bartender.cpp:107:13: warning: 'std::vector<int> {anonymous}::sortwines(int, std::vector<int>)' defined but not used [-Wunused-function]
vector<int> sortwines(int k, vector<int> a) {
^~~~~~~~~
taster.cpp:76:13: warning: 'std::vector<int> {anonymous}::blendwines(int, std::vector<int>)' defined but not used [-Wunused-function]
vector<int> blendwines(int k, vector<int> r){
^~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
10 ms |
908 KB |
Correct |
2 |
Correct |
10 ms |
772 KB |
Correct |
3 |
Correct |
10 ms |
772 KB |
Correct |
4 |
Correct |
8 ms |
644 KB |
Correct |
5 |
Correct |
10 ms |
780 KB |
Correct |
6 |
Correct |
9 ms |
692 KB |
Correct |
7 |
Correct |
11 ms |
908 KB |
Correct |
8 |
Correct |
11 ms |
772 KB |
Correct |
9 |
Correct |
10 ms |
784 KB |
Correct |
10 |
Correct |
9 ms |
772 KB |
Correct |
11 |
Correct |
9 ms |
820 KB |
Correct |
12 |
Correct |
9 ms |
788 KB |
Correct |
13 |
Correct |
10 ms |
772 KB |
Correct |
14 |
Correct |
10 ms |
772 KB |
Correct |
15 |
Correct |
10 ms |
972 KB |
Correct |
16 |
Correct |
10 ms |
804 KB |
Correct |
17 |
Correct |
10 ms |
772 KB |
Correct |
18 |
Correct |
10 ms |
772 KB |
Correct |
19 |
Correct |
10 ms |
772 KB |
Correct |
20 |
Correct |
10 ms |
908 KB |
Correct |
21 |
Correct |
10 ms |
772 KB |
Correct |
22 |
Correct |
10 ms |
644 KB |
Correct |
23 |
Correct |
9 ms |
908 KB |
Correct |
24 |
Correct |
9 ms |
804 KB |
Correct |
25 |
Correct |
9 ms |
772 KB |
Correct |
26 |
Correct |
10 ms |
772 KB |
Correct |
27 |
Correct |
10 ms |
772 KB |
Correct |
28 |
Partially correct |
10 ms |
808 KB |
Wrong |
29 |
Correct |
9 ms |
772 KB |
Correct |
30 |
Partially correct |
10 ms |
780 KB |
Wrong |
31 |
Partially correct |
8 ms |
772 KB |
Wrong |
32 |
Partially correct |
9 ms |
908 KB |
Wrong |
33 |
Partially correct |
10 ms |
820 KB |
Wrong |
34 |
Partially correct |
10 ms |
908 KB |
Wrong |
35 |
Partially correct |
10 ms |
772 KB |
Wrong |
36 |
Partially correct |
10 ms |
616 KB |
Wrong |
37 |
Partially correct |
10 ms |
780 KB |
Wrong |
38 |
Partially correct |
10 ms |
772 KB |
Wrong |
39 |
Partially correct |
9 ms |
908 KB |
Wrong |
40 |
Partially correct |
10 ms |
780 KB |
Wrong |
41 |
Partially correct |
10 ms |
924 KB |
Wrong |
42 |
Partially correct |
10 ms |
780 KB |
Wrong |
43 |
Partially correct |
9 ms |
772 KB |
Wrong |
44 |
Partially correct |
9 ms |
772 KB |
Wrong |
45 |
Partially correct |
10 ms |
644 KB |
Wrong |
46 |
Partially correct |
9 ms |
772 KB |
Wrong |
47 |
Partially correct |
10 ms |
780 KB |
Wrong |
48 |
Partially correct |
9 ms |
772 KB |
Wrong |
49 |
Partially correct |
10 ms |
804 KB |
Wrong |
50 |
Partially correct |
9 ms |
772 KB |
Wrong |
51 |
Partially correct |
11 ms |
908 KB |
Wrong |
52 |
Partially correct |
8 ms |
772 KB |
Wrong |
53 |
Partially correct |
9 ms |
908 KB |
Wrong |
54 |
Partially correct |
9 ms |
772 KB |
Wrong |
55 |
Partially correct |
10 ms |
908 KB |
Wrong |
56 |
Partially correct |
9 ms |
908 KB |
Wrong |
57 |
Partially correct |
9 ms |
884 KB |
Wrong |
58 |
Partially correct |
10 ms |
772 KB |
Wrong |
59 |
Partially correct |
8 ms |
772 KB |
Wrong |
60 |
Partially correct |
9 ms |
644 KB |
Wrong |
61 |
Partially correct |
10 ms |
908 KB |
Wrong |
62 |
Partially correct |
9 ms |
772 KB |
Wrong |
63 |
Partially correct |
10 ms |
772 KB |
Wrong |
64 |
Partially correct |
9 ms |
772 KB |
Wrong |
65 |
Partially correct |
10 ms |
940 KB |
Wrong |
66 |
Partially correct |
10 ms |
772 KB |
Wrong |
67 |
Partially correct |
10 ms |
908 KB |
Wrong |
68 |
Partially correct |
10 ms |
732 KB |
Wrong |
69 |
Partially correct |
10 ms |
772 KB |
Wrong |
70 |
Partially correct |
10 ms |
908 KB |
Wrong |
71 |
Partially correct |
10 ms |
772 KB |
Wrong |
72 |
Partially correct |
10 ms |
1024 KB |
Wrong |
73 |
Partially correct |
9 ms |
844 KB |
Wrong |
74 |
Partially correct |
8 ms |
772 KB |
Wrong |
75 |
Partially correct |
11 ms |
1028 KB |
Wrong |
76 |
Partially correct |
9 ms |
948 KB |
Wrong |
77 |
Partially correct |
10 ms |
772 KB |
Wrong |
78 |
Partially correct |
9 ms |
772 KB |
Wrong |
79 |
Partially correct |
8 ms |
1020 KB |
Wrong |
80 |
Partially correct |
9 ms |
836 KB |
Wrong |
81 |
Partially correct |
11 ms |
872 KB |
Wrong |
82 |
Partially correct |
11 ms |
664 KB |
Wrong |
83 |
Partially correct |
10 ms |
676 KB |
Wrong |
84 |
Partially correct |
8 ms |
772 KB |
Wrong |
85 |
Partially correct |
9 ms |
772 KB |
Wrong |
86 |
Partially correct |
8 ms |
644 KB |
Wrong |
87 |
Partially correct |
10 ms |
956 KB |
Wrong |
88 |
Partially correct |
9 ms |
772 KB |
Wrong |
89 |
Partially correct |
9 ms |
908 KB |
Wrong |
90 |
Partially correct |
8 ms |
780 KB |
Wrong |
91 |
Partially correct |
10 ms |
772 KB |
Wrong |
92 |
Partially correct |
9 ms |
772 KB |
Wrong |
93 |
Partially correct |
10 ms |
780 KB |
Wrong |
94 |
Partially correct |
9 ms |
908 KB |
Wrong |
95 |
Partially correct |
10 ms |
844 KB |
Wrong |
96 |
Partially correct |
8 ms |
772 KB |
Wrong |
97 |
Partially correct |
10 ms |
772 KB |
Wrong |
98 |
Partially correct |
10 ms |
908 KB |
Wrong |
99 |
Partially correct |
9 ms |
732 KB |
Wrong |
100 |
Partially correct |
10 ms |
780 KB |
Wrong |
101 |
Partially correct |
9 ms |
772 KB |
Wrong |
102 |
Partially correct |
10 ms |
908 KB |
Wrong |
103 |
Partially correct |
10 ms |
992 KB |
Wrong |
104 |
Partially correct |
9 ms |
644 KB |
Wrong |
105 |
Partially correct |
10 ms |
908 KB |
Wrong |
106 |
Partially correct |
9 ms |
784 KB |
Wrong |
107 |
Partially correct |
10 ms |
804 KB |
Wrong |
108 |
Partially correct |
10 ms |
772 KB |
Wrong |
109 |
Partially correct |
9 ms |
772 KB |
Wrong |
110 |
Partially correct |
10 ms |
864 KB |
Wrong |
111 |
Partially correct |
10 ms |
804 KB |
Wrong |
112 |
Partially correct |
9 ms |
884 KB |
Wrong |
113 |
Partially correct |
10 ms |
908 KB |
Wrong |
114 |
Partially correct |
10 ms |
772 KB |
Wrong |
115 |
Partially correct |
10 ms |
772 KB |
Wrong |
116 |
Partially correct |
9 ms |
772 KB |
Wrong |
117 |
Partially correct |
10 ms |
820 KB |
Wrong |
118 |
Partially correct |
11 ms |
644 KB |
Wrong |
119 |
Partially correct |
10 ms |
772 KB |
Wrong |
120 |
Partially correct |
10 ms |
772 KB |
Wrong |