#include "bartender.h"
#include <bits/stdc++.h>
using namespace std;
int f[35], used[35], pos[35];
std::vector<int> BlendWines(int K, std::vector<int> R){
int N = R.size();
if(K >= N) return R;
vector <int> v(N), v2(N);
for(int i = 0; i < N ; ++i) pos[R[i]] = i;
///bag crescator
int free = 0;
int NR = K / 2 + K % 2, ram = N;
for(int val = N; val >= 1 && NR >= 1 ; --val){
if(used[val]) continue ;
--NR;
int i = val;
while(i >= 1){
--ram;
used[i] = 1;
v[pos[i]] = K;
if(pos[i] < pos[i - 1]) break ;
--i;
}
--K;
}
free = N - ram;
int sz = ram / K, rest = ram % K;
for(int i = ram; i >= 1 && K >= 1 ; --i, --K){
int j = i - sz + 1;
if(rest > 0) --j, --rest;
for(int t = j; t <= i ; ++t) v[pos[t]] = K;
i = j;
}
///bag descrescator
return v;
}
#include "taster.h"
#include <bits/stdc++.h>
using namespace std;
map<int, int> mp[35];
int myCompare(int x, int y)
{
if(mp[x].count(y)) return mp[x][y];
int ans = Compare(x, y);
mp[x][y] = (ans == -1 ? 1 : 0);
mp[y][x] = (ans == 1 ? 1 : 0);
return mp[x][y];
}
std::vector<int> SortWines(int K, std::vector<int> A) {
int N = A.size();
if(N <= K) return A;
vector <int> v(N);
int cnt = K / 2 + K % 2, NR = N;
while(cnt--){
for(int i = A.size() - 1; i >= 0 ; --i) if(A[i] == K) v[i] = NR--;
--K;
}
vector<int> pos[35];
for(int i = 0; i < N; i++)
if(A[i] <= K) pos[ A[i] ].push_back(i);
mt19937 g(chrono::high_resolution_clock::now().time_since_epoch().count());
for(int i = 1; i <= K; i++)
shuffle(pos[i].begin(), pos[i].end(), g);
for(int i = 1; i <= K; i++)
sort(pos[i].begin(), pos[i].end(),
[&](int a, int b) { return myCompare(a, b); } );
int no = 0;
for(int i = 1; i <= K ; ++i){
for(auto it : pos[i])
v[it] = ++no;
}
return v;
}
/**
sort(pos[i].begin(), pos[i].end(),
[&](int a, int b) { return myCompare(a, b); } );
**/
Compilation message
bartender.cpp: In function 'std::vector<int> BlendWines(int, std::vector<int>)':
bartender.cpp:14:6: warning: variable 'free' set but not used [-Wunused-but-set-variable]
int free = 0;
^~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
9 ms |
772 KB |
Correct |
2 |
Correct |
9 ms |
772 KB |
Correct |
3 |
Correct |
10 ms |
772 KB |
Correct |
4 |
Correct |
10 ms |
772 KB |
Correct |
5 |
Correct |
8 ms |
772 KB |
Correct |
6 |
Correct |
10 ms |
772 KB |
Correct |
7 |
Correct |
12 ms |
1020 KB |
Correct |
8 |
Correct |
10 ms |
772 KB |
Correct |
9 |
Correct |
10 ms |
884 KB |
Correct |
10 |
Correct |
10 ms |
644 KB |
Correct |
11 |
Correct |
10 ms |
908 KB |
Correct |
12 |
Correct |
10 ms |
772 KB |
Correct |
13 |
Correct |
10 ms |
908 KB |
Correct |
14 |
Correct |
11 ms |
908 KB |
Correct |
15 |
Correct |
11 ms |
804 KB |
Correct |
16 |
Correct |
10 ms |
772 KB |
Correct |
17 |
Correct |
12 ms |
844 KB |
Correct |
18 |
Correct |
10 ms |
772 KB |
Correct |
19 |
Correct |
10 ms |
908 KB |
Correct |
20 |
Correct |
10 ms |
772 KB |
Correct |
21 |
Correct |
10 ms |
908 KB |
Correct |
22 |
Correct |
9 ms |
908 KB |
Correct |
23 |
Correct |
9 ms |
772 KB |
Correct |
24 |
Correct |
10 ms |
772 KB |
Correct |
25 |
Correct |
9 ms |
772 KB |
Correct |
26 |
Correct |
9 ms |
724 KB |
Correct |
27 |
Correct |
10 ms |
732 KB |
Correct |
28 |
Correct |
8 ms |
908 KB |
Correct |
29 |
Correct |
9 ms |
772 KB |
Correct |
30 |
Correct |
10 ms |
772 KB |
Correct |
31 |
Correct |
9 ms |
1024 KB |
Correct |
32 |
Correct |
10 ms |
772 KB |
Correct |
33 |
Correct |
9 ms |
772 KB |
Correct |
34 |
Correct |
9 ms |
644 KB |
Correct |
35 |
Correct |
10 ms |
772 KB |
Correct |
36 |
Correct |
10 ms |
752 KB |
Correct |
37 |
Correct |
10 ms |
644 KB |
Correct |
38 |
Correct |
10 ms |
732 KB |
Correct |
39 |
Correct |
11 ms |
644 KB |
Correct |
40 |
Correct |
10 ms |
644 KB |
Correct |
41 |
Correct |
10 ms |
820 KB |
Correct |
42 |
Correct |
9 ms |
772 KB |
Correct |
43 |
Correct |
9 ms |
772 KB |
Correct |
44 |
Correct |
9 ms |
780 KB |
Correct |
45 |
Correct |
9 ms |
772 KB |
Correct |
46 |
Correct |
8 ms |
644 KB |
Correct |
47 |
Correct |
9 ms |
772 KB |
Correct |
48 |
Correct |
10 ms |
644 KB |
Correct |
49 |
Correct |
11 ms |
772 KB |
Correct |
50 |
Correct |
9 ms |
772 KB |
Correct |
51 |
Correct |
10 ms |
772 KB |
Correct |
52 |
Correct |
10 ms |
908 KB |
Correct |
53 |
Correct |
10 ms |
940 KB |
Correct |
54 |
Correct |
11 ms |
956 KB |
Correct |
55 |
Correct |
10 ms |
908 KB |
Correct |
56 |
Correct |
10 ms |
656 KB |
Correct |
57 |
Correct |
10 ms |
908 KB |
Correct |
58 |
Correct |
11 ms |
908 KB |
Correct |
59 |
Correct |
10 ms |
908 KB |
Correct |
60 |
Correct |
10 ms |
772 KB |
Correct |
61 |
Correct |
8 ms |
644 KB |
Correct |
62 |
Correct |
10 ms |
772 KB |
Correct |
63 |
Correct |
8 ms |
772 KB |
Correct |
64 |
Correct |
10 ms |
908 KB |
Correct |
65 |
Correct |
9 ms |
792 KB |
Correct |
66 |
Correct |
10 ms |
772 KB |
Correct |
67 |
Correct |
9 ms |
772 KB |
Correct |
68 |
Correct |
10 ms |
1016 KB |
Correct |
69 |
Correct |
10 ms |
772 KB |
Correct |
70 |
Correct |
10 ms |
908 KB |
Correct |
71 |
Correct |
9 ms |
772 KB |
Correct |
72 |
Correct |
10 ms |
1024 KB |
Correct |
73 |
Correct |
9 ms |
780 KB |
Correct |
74 |
Correct |
10 ms |
772 KB |
Correct |
75 |
Correct |
10 ms |
884 KB |
Correct |
76 |
Correct |
10 ms |
1024 KB |
Correct |
77 |
Correct |
9 ms |
788 KB |
Correct |
78 |
Correct |
9 ms |
1012 KB |
Correct |
79 |
Correct |
10 ms |
908 KB |
Correct |
80 |
Correct |
10 ms |
780 KB |
Correct |
81 |
Correct |
10 ms |
908 KB |
Correct |
82 |
Partially correct |
9 ms |
908 KB |
Wrong |
83 |
Correct |
10 ms |
772 KB |
Correct |
84 |
Partially correct |
12 ms |
772 KB |
Wrong |
85 |
Partially correct |
10 ms |
772 KB |
Wrong |
86 |
Correct |
10 ms |
860 KB |
Correct |
87 |
Correct |
10 ms |
772 KB |
Correct |
88 |
Correct |
10 ms |
732 KB |
Correct |
89 |
Correct |
10 ms |
872 KB |
Correct |
90 |
Correct |
10 ms |
756 KB |
Correct |
91 |
Correct |
10 ms |
920 KB |
Correct |
92 |
Correct |
11 ms |
788 KB |
Correct |
93 |
Correct |
10 ms |
908 KB |
Correct |
94 |
Partially correct |
11 ms |
772 KB |
Wrong |
95 |
Correct |
10 ms |
904 KB |
Correct |
96 |
Partially correct |
10 ms |
784 KB |
Wrong |
97 |
Partially correct |
10 ms |
772 KB |
Wrong |
98 |
Partially correct |
9 ms |
644 KB |
Wrong |
99 |
Partially correct |
9 ms |
644 KB |
Wrong |
100 |
Partially correct |
9 ms |
784 KB |
Wrong |
101 |
Correct |
9 ms |
644 KB |
Correct |
102 |
Correct |
10 ms |
908 KB |
Correct |
103 |
Correct |
9 ms |
1012 KB |
Correct |
104 |
Correct |
9 ms |
908 KB |
Correct |
105 |
Correct |
11 ms |
772 KB |
Correct |
106 |
Correct |
9 ms |
908 KB |
Correct |
107 |
Correct |
10 ms |
880 KB |
Correct |
108 |
Correct |
10 ms |
1012 KB |
Correct |
109 |
Partially correct |
11 ms |
1060 KB |
Wrong |
110 |
Partially correct |
10 ms |
644 KB |
Wrong |
111 |
Partially correct |
9 ms |
772 KB |
Wrong |
112 |
Partially correct |
10 ms |
772 KB |
Wrong |
113 |
Partially correct |
11 ms |
784 KB |
Wrong |
114 |
Partially correct |
12 ms |
788 KB |
Wrong |
115 |
Partially correct |
10 ms |
772 KB |
Wrong |
116 |
Partially correct |
10 ms |
772 KB |
Wrong |
117 |
Correct |
10 ms |
920 KB |
Correct |
118 |
Partially correct |
11 ms |
772 KB |
Wrong |
119 |
Partially correct |
9 ms |
908 KB |
Wrong |
120 |
Partially correct |
10 ms |
836 KB |
Wrong |