#include "bartender.h"
using namespace std;
vector<int> BlendWines(int K, vector<int> R){
int N = R.size();
vector<int> A(N);
if(N <= 5){
for(int i = 0; i < N; i++) A[i] = (R[i] - 1) % 9 + 1;
return A;
}
for(int i = 0; i < N; i++) A[i] = (R[i] == N-1 ? 10 : (R[i]-1) % 9 + 1);
return A;
}
#include "taster.h"
#include <bits/stdc++.h>
#define all(v) (v).begin(),(v).end()
using namespace std;
vector<int> g[31];
vector<int> alc;
int cmp[31][31], N;
vector<int> bf(){
for(int i = 0; i < N; i++){
for(int j = i + 1; j < N; j++){
cmp[i][j] = Compare(i, j);
cmp[j][i] = -cmp[i][j];
}
}
vector<int> R(N), I(N);
iota(all(I), 0);
sort(all(I), [](int u, int v){return cmp[u][v] == -1;});
for(int i = 0; i < N; i++){
R[I[i]] = i + 1;
}
return R;
}
vector<int> SortWines(int K, vector<int> A) {
//cout << "asdf\n";
N = A.size();
alc = A;
vector<int> R(N);
for(int i = 0; i < N; i++) g[A[i]].push_back(i);
if(N <= 5){
return bf();
}
vector<vector<int>> Pms;
vector<int> P[3];
vector<int> gmr;
int r = 0;
for(int i = 0; i < 3; i++){
P[i].resize(g[i+1].size());
r += g[i+1].size();
iota(all(P[i]), 0);
copy(all(g[i+1]), back_inserter(gmr));
}
//for(int u : gmr) cout << u << ' '; cout << '\n';
do{
do{
do{
Pms.emplace_back();
for(int i = 0; i < 3; i++){
for(int j = 0; j < P[i].size(); j++) Pms.back().push_back(P[i][j] * 1000 + i);
}
}while(next_permutation(all(P[2])));
}while(next_permutation(all(P[1])));
}while(next_permutation(all(P[0])));
//cout << "permdict " << Pms.size() << "\n";
vector<vector<int>> sel[2];
int dep = 0;
while(Pms.size() > 1){
int diff = INT_MAX, di, dj;
for(int i = 0; i < r; i++){
for(int j = i + 1; j < r; j++){
int ldiff = 0;
for(vector<int> &p : Pms){
if(p[i] < p[j]) ldiff += 1;
else ldiff -= 1;
}
if(abs(ldiff) < diff){
diff = abs(ldiff);
di = i;
dj = j;
}
}
}
sel[0].clear();
sel[1].clear();
for(vector<int>& p : Pms){
sel[p[di] < p[dj]].push_back(p);
}
++dep;
//cout << "decision tree " << dep << " : " << sel[0].size() << ' ' << sel[1].size() << '\n';
bool s = (Compare(gmr[di], gmr[dj]) == -1);
Pms = sel[s];
sel[!s].clear();
}
for(int &q : Pms.back()) q /= 1000;
int cur = 0;
for(int i = 1; i <= 3; i++){
vector<int> tmp(g[i].size());
for(int j = 0; j < g[i].size(); j++) tmp[Pms.back()[cur + j]] = g[i][j];
g[i] = tmp;
cur += g[i].size();
}
for(int i = 4; i <= K; i++){
vector<vector<int>> ps;
int r = g[i].size();
vector<int> U(r);
iota(all(U), 0);
do{
vector<int> cU = U;
ps.push_back(cU);
}while(next_permutation(all(U)));
vector<vector<int>> sel[2];
int dep = 0;
while(ps.size() > 1){
int diff = INT_MAX, di, dj;
for(int i = 0; i < r; i++){
for(int j = 1; j < r; j++){
int ldiff = 0;
for(vector<int> &p : ps){
if(p[i] < j) ldiff += 1;
else ldiff -= 1;
}
if(abs(ldiff) < diff){
diff = abs(ldiff);
di = i;
dj = j;
}
}
}
sel[0].clear();
sel[1].clear();
for(vector<int>& p : ps){
sel[p[di] < dj].push_back(p);
}
++dep;
//cout << "decision tree " << dep << " : " << sel[0].size() << ' ' << sel[1].size() << '\n';
bool s = (Compare(g[i][di], g[1][dj]) == -1);
ps = sel[s];
sel[!s].clear();
}
vector<int> tmp(r);
for(int j = 0; j < r; j++) tmp[ps.back()[j]] = g[i][j];
g[i] = tmp;
}
for(int i = 1; i <= K; i++){
for(int j = 0; j < g[i].size(); j++){
R[g[i][j]] = j * 9 + i;
}
}
if(g[10].size()) R[g[10][0]] = N-1;
return R;
}
Compilation message
taster.cpp: In function 'std::vector<int> SortWines(int, std::vector<int>)':
taster.cpp:51:23: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for(int j = 0; j < P[i].size(); j++) Pms.back().push_back(P[i][j] * 1000 + i);
~~^~~~~~~~~~~~~
taster.cpp:92:20: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for(int j = 0; j < g[i].size(); j++) tmp[Pms.back()[cur + j]] = g[i][j];
~~^~~~~~~~~~~~~
taster.cpp:139:20: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for(int j = 0; j < g[i].size(); j++){
~~^~~~~~~~~~~~~
taster.cpp:126:15: warning: 'dj' may be used uninitialized in this function [-Wmaybe-uninitialized]
sel[p[di] < dj].push_back(p);
taster.cpp:108:24: warning: 'di' may be used uninitialized in this function [-Wmaybe-uninitialized]
int diff = INT_MAX, di, dj;
^~
taster.cpp:61:27: warning: 'dj' may be used uninitialized in this function [-Wmaybe-uninitialized]
int diff = INT_MAX, di, dj;
^~
taster.cpp:61:23: warning: 'di' may be used uninitialized in this function [-Wmaybe-uninitialized]
int diff = INT_MAX, di, dj;
^~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
10 ms |
772 KB |
Correct |
2 |
Correct |
9 ms |
644 KB |
Correct |
3 |
Correct |
8 ms |
908 KB |
Correct |
4 |
Correct |
8 ms |
772 KB |
Correct |
5 |
Correct |
8 ms |
772 KB |
Correct |
6 |
Correct |
9 ms |
644 KB |
Correct |
7 |
Correct |
11 ms |
1412 KB |
Correct |
8 |
Correct |
11 ms |
1412 KB |
Correct |
9 |
Correct |
11 ms |
1412 KB |
Correct |
10 |
Correct |
12 ms |
1412 KB |
Correct |
11 |
Correct |
12 ms |
1412 KB |
Correct |
12 |
Correct |
12 ms |
1284 KB |
Correct |
13 |
Correct |
12 ms |
1412 KB |
Correct |
14 |
Correct |
12 ms |
1420 KB |
Correct |
15 |
Correct |
12 ms |
1372 KB |
Correct |
16 |
Correct |
12 ms |
1548 KB |
Correct |
17 |
Correct |
11 ms |
1432 KB |
Correct |
18 |
Correct |
12 ms |
1548 KB |
Correct |
19 |
Correct |
11 ms |
1412 KB |
Correct |
20 |
Correct |
13 ms |
1548 KB |
Correct |
21 |
Correct |
12 ms |
1412 KB |
Correct |
22 |
Correct |
12 ms |
1548 KB |
Correct |
23 |
Correct |
11 ms |
1412 KB |
Correct |
24 |
Correct |
12 ms |
1420 KB |
Correct |
25 |
Correct |
11 ms |
1412 KB |
Correct |
26 |
Correct |
11 ms |
1548 KB |
Correct |
27 |
Correct |
12 ms |
1412 KB |
Correct |
28 |
Correct |
11 ms |
1412 KB |
Correct |
29 |
Correct |
11 ms |
1700 KB |
Correct |
30 |
Correct |
11 ms |
1412 KB |
Correct |
31 |
Correct |
11 ms |
1412 KB |
Correct |
32 |
Correct |
11 ms |
1284 KB |
Correct |
33 |
Correct |
11 ms |
1284 KB |
Correct |
34 |
Correct |
11 ms |
1412 KB |
Correct |
35 |
Correct |
11 ms |
1284 KB |
Correct |
36 |
Correct |
11 ms |
1548 KB |
Correct |
37 |
Correct |
11 ms |
1472 KB |
Correct |
38 |
Correct |
11 ms |
1540 KB |
Correct |
39 |
Correct |
11 ms |
1412 KB |
Correct |
40 |
Correct |
12 ms |
1412 KB |
Correct |
41 |
Correct |
11 ms |
1412 KB |
Correct |
42 |
Correct |
12 ms |
1412 KB |
Correct |
43 |
Correct |
11 ms |
1284 KB |
Correct |
44 |
Correct |
11 ms |
1284 KB |
Correct |
45 |
Correct |
12 ms |
1412 KB |
Correct |
46 |
Correct |
11 ms |
1412 KB |
Correct |
47 |
Correct |
12 ms |
1284 KB |
Correct |
48 |
Correct |
12 ms |
1412 KB |
Correct |
49 |
Correct |
11 ms |
1524 KB |
Correct |
50 |
Correct |
12 ms |
1412 KB |
Correct |
51 |
Correct |
12 ms |
1412 KB |
Correct |
52 |
Correct |
12 ms |
1412 KB |
Correct |
53 |
Correct |
11 ms |
1548 KB |
Correct |
54 |
Correct |
12 ms |
1412 KB |
Correct |
55 |
Correct |
12 ms |
1540 KB |
Correct |
56 |
Correct |
11 ms |
1420 KB |
Correct |
57 |
Correct |
13 ms |
1412 KB |
Correct |
58 |
Correct |
12 ms |
1412 KB |
Correct |
59 |
Correct |
12 ms |
1548 KB |
Correct |
60 |
Correct |
11 ms |
1412 KB |
Correct |
61 |
Correct |
11 ms |
1412 KB |
Correct |
62 |
Correct |
12 ms |
1508 KB |
Correct |
63 |
Correct |
11 ms |
1412 KB |
Correct |
64 |
Correct |
11 ms |
1548 KB |
Correct |
65 |
Correct |
11 ms |
1548 KB |
Correct |
66 |
Correct |
12 ms |
1412 KB |
Correct |
67 |
Correct |
11 ms |
1372 KB |
Correct |
68 |
Correct |
12 ms |
1412 KB |
Correct |
69 |
Correct |
11 ms |
1548 KB |
Correct |
70 |
Correct |
12 ms |
1412 KB |
Correct |
71 |
Correct |
12 ms |
1548 KB |
Correct |
72 |
Correct |
12 ms |
1548 KB |
Correct |
73 |
Correct |
11 ms |
1284 KB |
Correct |
74 |
Correct |
13 ms |
1440 KB |
Correct |
75 |
Correct |
11 ms |
1284 KB |
Correct |
76 |
Correct |
9 ms |
1028 KB |
Correct |
77 |
Correct |
9 ms |
908 KB |
Correct |
78 |
Correct |
9 ms |
804 KB |
Correct |
79 |
Partially correct |
10 ms |
644 KB |
Wrong |
80 |
Partially correct |
8 ms |
908 KB |
Wrong |
81 |
Partially correct |
9 ms |
836 KB |
Wrong |
82 |
Partially correct |
9 ms |
780 KB |
Wrong |
83 |
Partially correct |
8 ms |
644 KB |
Wrong |
84 |
Partially correct |
9 ms |
644 KB |
Wrong |
85 |
Partially correct |
8 ms |
908 KB |
Wrong |
86 |
Partially correct |
10 ms |
772 KB |
Wrong |
87 |
Partially correct |
8 ms |
644 KB |
Wrong |
88 |
Correct |
9 ms |
804 KB |
Correct |
89 |
Correct |
10 ms |
732 KB |
Correct |
90 |
Partially correct |
8 ms |
772 KB |
Wrong |
91 |
Partially correct |
10 ms |
772 KB |
Wrong |
92 |
Partially correct |
9 ms |
908 KB |
Wrong |
93 |
Partially correct |
10 ms |
908 KB |
Wrong |
94 |
Partially correct |
9 ms |
848 KB |
Wrong |
95 |
Partially correct |
9 ms |
772 KB |
Wrong |
96 |
Partially correct |
8 ms |
772 KB |
Wrong |
97 |
Partially correct |
10 ms |
908 KB |
Wrong |
98 |
Partially correct |
10 ms |
772 KB |
Wrong |
99 |
Partially correct |
10 ms |
772 KB |
Wrong |
100 |
Partially correct |
9 ms |
900 KB |
Wrong |
101 |
Partially correct |
10 ms |
772 KB |
Wrong |
102 |
Partially correct |
9 ms |
772 KB |
Wrong |
103 |
Correct |
9 ms |
908 KB |
Correct |
104 |
Correct |
9 ms |
772 KB |
Correct |
105 |
Partially correct |
9 ms |
772 KB |
Wrong |
106 |
Partially correct |
10 ms |
772 KB |
Wrong |
107 |
Partially correct |
8 ms |
796 KB |
Wrong |
108 |
Partially correct |
9 ms |
772 KB |
Wrong |
109 |
Partially correct |
9 ms |
1028 KB |
Wrong |
110 |
Partially correct |
10 ms |
644 KB |
Wrong |
111 |
Partially correct |
9 ms |
908 KB |
Wrong |
112 |
Partially correct |
9 ms |
772 KB |
Wrong |
113 |
Partially correct |
9 ms |
900 KB |
Wrong |
114 |
Partially correct |
8 ms |
644 KB |
Wrong |
115 |
Partially correct |
9 ms |
800 KB |
Wrong |
116 |
Partially correct |
8 ms |
908 KB |
Wrong |
117 |
Partially correct |
10 ms |
1060 KB |
Wrong |
118 |
Partially correct |
9 ms |
772 KB |
Wrong |
119 |
Partially correct |
10 ms |
772 KB |
Wrong |
120 |
Partially correct |
9 ms |
884 KB |
Wrong |