#include "bartender.h"
#include <bits/stdc++.h>
using namespace std;
const int LARGESTS_FILLED_UNTIL = 6;
int fill_largests(int K, vector<int>& R, vector<int>& magic, vector<int>& A, int pos[]) {
int N = R.size();
int cur_num = N;
int cur_fill = K;
int prv_magic = -1;
while (cur_fill >= LARGESTS_FILLED_UNTIL && cur_num >= 1) {
if (magic[pos[cur_num]] >= prv_magic) {
A[pos[cur_num]] = cur_fill;
prv_magic = magic[pos[cur_num]];
cur_num--;
} else {
prv_magic = magic[pos[cur_num]];
cur_fill--;
}
}
return cur_num;
}
vector<int> BlendWines(int K, vector<int> R) {
srand(882);
int N = R.size();
int pos[35] = {};
for (int i = 0; i < N; i++) {
pos[R[i]] = i;
}
vector<int> magic;
for (int i = 0; i < N; i++) {
magic.push_back(i);
}
random_shuffle(magic.begin(), magic.end());
vector<int> A(N, 0);
int unfilled_n = fill_largests(K, R, magic, A, pos);
int filled_until = 0;
for (int i = 1; i < LARGESTS_FILLED_UNTIL; i++) {
int unfilled_cnt = (unfilled_n - filled_until);
int group_size = min(unfilled_cnt, 5);
if ((6 - i) * 4 >= unfilled_cnt) {
group_size = min(group_size, 4);
}
for (int j = filled_until + 1; j <= filled_until + group_size; j++) {
A[pos[j]] = i;
}
filled_until += group_size;
}
/*
for (int i = 0; i < N; i++) {
printf("%2d ", A[i]);
}
printf("\n");
*/
return A;
}
#include "taster.h"
#include <bits/stdc++.h>
using namespace std;
const int LARGESTS_FILLED_UNTIL = 6;
int handle_largests(int K, vector<int>& A, vector<int>& magic, vector<int>& R) {
int N = A.size();
int next_num = N;
for (int filled_as = K; filled_as >= LARGESTS_FILLED_UNTIL; filled_as--) {
vector<pair<int, int> > filled_bingo;
for (int i = 0; i < N; i++) {
if (A[i] == filled_as) {
filled_bingo.push_back(make_pair(magic[i], i));
}
}
sort(filled_bingo.begin(), filled_bingo.end());
for (int i = 0; i < filled_bingo.size(); i++) {
R[filled_bingo[i].second] = next_num--;
}
}
return next_num;
}
bool cmp(int u, int v) {
return Compare(u, v) == -1;
}
void handle_smallests(vector<int>& A, vector<int>& R) {
int N = A.size();
int next_num = 1;
for (int filled_as = 1; filled_as < LARGESTS_FILLED_UNTIL; filled_as++) {
vector<int> filled_bingo;
for (int i = 0; i < N; i++) {
if (A[i] == filled_as) {
filled_bingo.push_back(i);
}
}
stable_sort(filled_bingo.begin(), filled_bingo.end(), cmp);
for (int i = 0; i < filled_bingo.size(); i++) {
R[filled_bingo[i]] = next_num++;
}
}
}
vector<int> SortWines(int K, vector<int> A) {
srand(882);
int N = A.size();
vector<int> magic;
for (int i = 0; i < N; i++) {
magic.push_back(i);
}
random_shuffle(magic.begin(), magic.end());
vector<int> R(N, 0);
handle_largests(K, A, magic, R);
handle_smallests(A, R);
/*
for (int i = 0; i < N; i++) {
printf("%2d ", R[i]);
}
printf("\n");
*/
return R;
}
Compilation message
taster.cpp: In function 'int handle_largests(int, std::vector<int>&, std::vector<int>&, std::vector<int>&)':
taster.cpp:19:21: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for (int i = 0; i < filled_bingo.size(); i++) {
~~^~~~~~~~~~~~~~~~~~~~~
taster.cpp: In function 'void handle_smallests(std::vector<int>&, std::vector<int>&)':
taster.cpp:44:21: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for (int i = 0; i < filled_bingo.size(); i++) {
~~^~~~~~~~~~~~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
10 ms |
772 KB |
Correct |
2 |
Correct |
9 ms |
772 KB |
Correct |
3 |
Correct |
9 ms |
780 KB |
Correct |
4 |
Correct |
10 ms |
908 KB |
Correct |
5 |
Correct |
10 ms |
1012 KB |
Correct |
6 |
Correct |
9 ms |
772 KB |
Correct |
7 |
Correct |
8 ms |
644 KB |
Correct |
8 |
Correct |
9 ms |
908 KB |
Correct |
9 |
Correct |
9 ms |
784 KB |
Correct |
10 |
Correct |
10 ms |
772 KB |
Correct |
11 |
Correct |
10 ms |
908 KB |
Correct |
12 |
Correct |
10 ms |
908 KB |
Correct |
13 |
Correct |
9 ms |
644 KB |
Correct |
14 |
Correct |
10 ms |
772 KB |
Correct |
15 |
Correct |
10 ms |
772 KB |
Correct |
16 |
Correct |
9 ms |
908 KB |
Correct |
17 |
Correct |
9 ms |
644 KB |
Correct |
18 |
Correct |
9 ms |
908 KB |
Correct |
19 |
Correct |
9 ms |
772 KB |
Correct |
20 |
Correct |
10 ms |
884 KB |
Correct |
21 |
Correct |
9 ms |
1044 KB |
Correct |
22 |
Correct |
10 ms |
772 KB |
Correct |
23 |
Correct |
10 ms |
908 KB |
Correct |
24 |
Correct |
9 ms |
772 KB |
Correct |
25 |
Correct |
10 ms |
644 KB |
Correct |
26 |
Correct |
9 ms |
772 KB |
Correct |
27 |
Correct |
9 ms |
856 KB |
Correct |
28 |
Correct |
10 ms |
908 KB |
Correct |
29 |
Correct |
10 ms |
772 KB |
Correct |
30 |
Correct |
9 ms |
772 KB |
Correct |
31 |
Correct |
10 ms |
772 KB |
Correct |
32 |
Correct |
10 ms |
772 KB |
Correct |
33 |
Correct |
8 ms |
908 KB |
Correct |
34 |
Correct |
9 ms |
772 KB |
Correct |
35 |
Correct |
9 ms |
908 KB |
Correct |
36 |
Correct |
8 ms |
772 KB |
Correct |
37 |
Correct |
10 ms |
780 KB |
Correct |
38 |
Correct |
8 ms |
888 KB |
Correct |
39 |
Correct |
9 ms |
772 KB |
Correct |
40 |
Correct |
10 ms |
908 KB |
Correct |
41 |
Correct |
9 ms |
772 KB |
Correct |
42 |
Correct |
9 ms |
644 KB |
Correct |
43 |
Correct |
9 ms |
772 KB |
Correct |
44 |
Correct |
9 ms |
908 KB |
Correct |
45 |
Correct |
9 ms |
772 KB |
Correct |
46 |
Correct |
9 ms |
772 KB |
Correct |
47 |
Correct |
9 ms |
772 KB |
Correct |
48 |
Correct |
10 ms |
908 KB |
Correct |
49 |
Correct |
10 ms |
772 KB |
Correct |
50 |
Correct |
9 ms |
884 KB |
Correct |
51 |
Correct |
8 ms |
644 KB |
Correct |
52 |
Correct |
9 ms |
772 KB |
Correct |
53 |
Correct |
10 ms |
772 KB |
Correct |
54 |
Correct |
10 ms |
772 KB |
Correct |
55 |
Correct |
9 ms |
772 KB |
Correct |
56 |
Correct |
10 ms |
772 KB |
Correct |
57 |
Correct |
9 ms |
772 KB |
Correct |
58 |
Correct |
10 ms |
644 KB |
Correct |
59 |
Correct |
9 ms |
772 KB |
Correct |
60 |
Correct |
10 ms |
908 KB |
Correct |
61 |
Correct |
9 ms |
772 KB |
Correct |
62 |
Correct |
9 ms |
644 KB |
Correct |
63 |
Correct |
9 ms |
908 KB |
Correct |
64 |
Correct |
9 ms |
908 KB |
Correct |
65 |
Correct |
8 ms |
644 KB |
Correct |
66 |
Correct |
10 ms |
908 KB |
Correct |
67 |
Correct |
10 ms |
772 KB |
Correct |
68 |
Correct |
10 ms |
908 KB |
Correct |
69 |
Correct |
10 ms |
772 KB |
Correct |
70 |
Correct |
9 ms |
804 KB |
Correct |
71 |
Correct |
9 ms |
644 KB |
Correct |
72 |
Correct |
10 ms |
908 KB |
Correct |
73 |
Partially correct |
10 ms |
908 KB |
Wrong |
74 |
Partially correct |
9 ms |
772 KB |
Wrong |
75 |
Partially correct |
10 ms |
780 KB |
Wrong |
76 |
Correct |
10 ms |
908 KB |
Correct |
77 |
Correct |
9 ms |
772 KB |
Correct |
78 |
Correct |
9 ms |
908 KB |
Correct |
79 |
Correct |
9 ms |
644 KB |
Correct |
80 |
Correct |
9 ms |
780 KB |
Correct |
81 |
Correct |
8 ms |
772 KB |
Correct |
82 |
Partially correct |
9 ms |
908 KB |
Wrong |
83 |
Partially correct |
10 ms |
644 KB |
Wrong |
84 |
Partially correct |
8 ms |
772 KB |
Wrong |
85 |
Partially correct |
9 ms |
772 KB |
Wrong |
86 |
Partially correct |
9 ms |
772 KB |
Wrong |
87 |
Partially correct |
9 ms |
908 KB |
Wrong |
88 |
Correct |
9 ms |
772 KB |
Correct |
89 |
Correct |
10 ms |
772 KB |
Correct |
90 |
Correct |
9 ms |
772 KB |
Correct |
91 |
Correct |
9 ms |
664 KB |
Correct |
92 |
Correct |
9 ms |
772 KB |
Correct |
93 |
Correct |
10 ms |
772 KB |
Correct |
94 |
Partially correct |
10 ms |
908 KB |
Wrong |
95 |
Partially correct |
10 ms |
772 KB |
Wrong |
96 |
Partially correct |
9 ms |
780 KB |
Wrong |
97 |
Partially correct |
10 ms |
772 KB |
Wrong |
98 |
Partially correct |
9 ms |
772 KB |
Wrong |
99 |
Partially correct |
9 ms |
772 KB |
Wrong |
100 |
Partially correct |
8 ms |
980 KB |
Wrong |
101 |
Partially correct |
10 ms |
772 KB |
Wrong |
102 |
Partially correct |
10 ms |
780 KB |
Wrong |
103 |
Correct |
10 ms |
780 KB |
Correct |
104 |
Correct |
10 ms |
772 KB |
Correct |
105 |
Correct |
10 ms |
668 KB |
Correct |
106 |
Correct |
10 ms |
1064 KB |
Correct |
107 |
Partially correct |
10 ms |
644 KB |
Wrong |
108 |
Partially correct |
9 ms |
780 KB |
Wrong |
109 |
Partially correct |
9 ms |
772 KB |
Wrong |
110 |
Partially correct |
10 ms |
772 KB |
Wrong |
111 |
Partially correct |
9 ms |
872 KB |
Wrong |
112 |
Partially correct |
9 ms |
804 KB |
Wrong |
113 |
Partially correct |
9 ms |
780 KB |
Wrong |
114 |
Partially correct |
9 ms |
644 KB |
Wrong |
115 |
Partially correct |
11 ms |
772 KB |
Wrong |
116 |
Partially correct |
11 ms |
772 KB |
Wrong |
117 |
Partially correct |
10 ms |
772 KB |
Wrong |
118 |
Partially correct |
10 ms |
812 KB |
Wrong |
119 |
Partially correct |
10 ms |
960 KB |
Wrong |
120 |
Partially correct |
8 ms |
644 KB |
Wrong |