#include "koala.h"
#include <bits/stdc++.h>
#define pb push_back
#define bg begin
using namespace std;
int B[100], R[100];
bool cmp(int a, int b, int N, int W) {
fill(B, B + N, 0);
B[a] = B[b] = W;
playRound(B, R);
return (R[b] > W);
}
vector<int> mgs(vector<int> v, int N, int W) {
if (v.size() == 1) return v;
vector<int> a, b;
a.insert(a.bg(), v.bg(), v.bg() + (v.size() + 1) / 2);
b.insert(b.bg(), v.bg() + (v.size() + 1) / 2, v.end());
a = mgs(a, N, W), b = mgs(b, N, W);
vector<int> st;
int aptr = 0, bptr = 0;
while (aptr < a.size() && bptr < b.size()) {
if (cmp(a[aptr], b[bptr], N, W)) st.pb(a[aptr++]);
else st.pb(b[bptr++]);
}
st.insert(st.end(), a.bg() + aptr, a.end());
st.insert(st.end(), b.bg() + bptr, b.end());
return st;
}
void sp(vector<int> v, int N, int W, int* P, int l = 1, int r = 100) {
if (l == r) P[v[0]] = l;
else {
int x = min((int)sqrt(2 * l), W / (r - l + 1));
fill(B, B + N, 0);
for (int i : v) B[i] = x;
playRound(B, R);
vector<int> ll, gg;
for (int i : v) if (R[i] > x) gg.pb(i);
else ll.pb(i);
sp(ll, N, W, P, l, l + ll.size() - 1);
sp(gg, N, W, P, r - gg.size() + 1, r);
}
}
int minValue(int N, int W) {
fill(B, B + N, 0);
B[0] = 1;
playRound(B, R);
if (R[0] < 2) return 0;
else for (int i = 1; i < N; i++) if (!R[i]) return i;
}
int maxValue(int N, int W) {
vector<int> v;
for (int i = 0; i < N; i++) v.pb(i);
while (v.size() != 1) {
int k = W / v.size();
fill(B, B + N, 0);
for (int i : v) B[i] = k;
playRound(B, R);
v.clear();
for (int i = 0; i < N; i++) if (R[i] > k) v.pb(i);
}
return v[0];
}
int greaterValue(int N, int W) {
int l = 1, r = 9;
while (l != r) {
int mid = (l + r) / 2;
B[0] = B[1] = mid;
playRound(B, R);
if (R[0] > mid && R[1] > mid) l = mid + 1;
else if (R[0] <= mid && R[1] <= mid) r = mid - 1;
else return (R[0] < R[1]);
}
B[0] = B[1] = l;
playRound(B, R);
return (R[0] < R[1]);
}
void allValues(int N, int W, int *P) {
if (W == 2 * N) {
vector<int> v;
for (int i = 0; i < N; i++) v.pb(i);
vector<int> st = mgs(v, N, W / 2);
for (int i = 0; i < N; i++) P[st[i]] = i + 1;
} else {
vector<int> v;
for (int i = 0; i < N; i++) v.pb(i);
sp(v, N, W, P);
}
}
Compilation message
koala.cpp: In function 'std::vector<int> mgs(std::vector<int>, int, int)':
koala.cpp:25:17: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
while (aptr < a.size() && bptr < b.size()) {
~~~~~^~~~~~~~~~
koala.cpp:25:36: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
while (aptr < a.size() && bptr < b.size()) {
~~~~~^~~~~~~~~~
koala.cpp: In function 'int minValue(int, int)':
koala.cpp:59:1: warning: control reaches end of non-void function [-Wreturn-type]
}
^
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
6 ms |
376 KB |
Output is correct |
2 |
Correct |
6 ms |
376 KB |
Output is correct |
3 |
Correct |
6 ms |
376 KB |
Output is correct |
4 |
Correct |
6 ms |
376 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
16 ms |
376 KB |
Output is correct |
2 |
Correct |
16 ms |
380 KB |
Output is correct |
3 |
Correct |
16 ms |
376 KB |
Output is correct |
4 |
Correct |
16 ms |
376 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
61 ms |
548 KB |
Output is correct |
2 |
Correct |
70 ms |
376 KB |
Output is correct |
3 |
Correct |
60 ms |
564 KB |
Output is correct |
4 |
Correct |
59 ms |
504 KB |
Output is correct |
5 |
Correct |
60 ms |
556 KB |
Output is correct |
6 |
Correct |
61 ms |
380 KB |
Output is correct |
7 |
Correct |
60 ms |
376 KB |
Output is correct |
8 |
Correct |
61 ms |
376 KB |
Output is correct |
9 |
Correct |
62 ms |
504 KB |
Output is correct |
10 |
Correct |
59 ms |
376 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
22 ms |
376 KB |
Output is correct |
2 |
Correct |
37 ms |
348 KB |
Output is correct |
3 |
Correct |
35 ms |
504 KB |
Output is correct |
4 |
Correct |
35 ms |
376 KB |
Output is correct |
5 |
Correct |
34 ms |
376 KB |
Output is correct |
6 |
Correct |
35 ms |
376 KB |
Output is correct |
7 |
Correct |
34 ms |
504 KB |
Output is correct |
8 |
Correct |
33 ms |
376 KB |
Output is correct |
9 |
Correct |
35 ms |
380 KB |
Output is correct |
10 |
Correct |
33 ms |
380 KB |
Output is correct |
11 |
Correct |
34 ms |
380 KB |
Output is correct |
12 |
Correct |
20 ms |
376 KB |
Output is correct |
13 |
Correct |
37 ms |
420 KB |
Output is correct |
14 |
Correct |
31 ms |
376 KB |
Output is correct |
15 |
Correct |
31 ms |
376 KB |
Output is correct |
16 |
Correct |
29 ms |
376 KB |
Output is correct |
17 |
Correct |
29 ms |
376 KB |
Output is correct |
18 |
Correct |
31 ms |
376 KB |
Output is correct |
19 |
Correct |
30 ms |
376 KB |
Output is correct |
20 |
Correct |
31 ms |
508 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
376 KB |
Output is correct |
2 |
Correct |
5 ms |
376 KB |
Output is correct |
3 |
Correct |
5 ms |
504 KB |
Output is correct |
4 |
Correct |
5 ms |
376 KB |
Output is correct |
5 |
Correct |
5 ms |
376 KB |
Output is correct |
6 |
Correct |
5 ms |
376 KB |
Output is correct |
7 |
Correct |
5 ms |
376 KB |
Output is correct |
8 |
Correct |
5 ms |
376 KB |
Output is correct |
9 |
Correct |
5 ms |
376 KB |
Output is correct |
10 |
Correct |
9 ms |
376 KB |
Output is correct |
11 |
Correct |
6 ms |
376 KB |
Output is correct |
12 |
Correct |
5 ms |
376 KB |
Output is correct |
13 |
Correct |
5 ms |
380 KB |
Output is correct |
14 |
Correct |
5 ms |
376 KB |
Output is correct |
15 |
Correct |
5 ms |
376 KB |
Output is correct |
16 |
Correct |
5 ms |
380 KB |
Output is correct |
17 |
Correct |
5 ms |
376 KB |
Output is correct |
18 |
Correct |
5 ms |
376 KB |
Output is correct |
19 |
Correct |
5 ms |
376 KB |
Output is correct |
20 |
Correct |
5 ms |
376 KB |
Output is correct |
21 |
Correct |
5 ms |
376 KB |
Output is correct |
22 |
Correct |
5 ms |
376 KB |
Output is correct |
23 |
Correct |
5 ms |
376 KB |
Output is correct |
24 |
Correct |
5 ms |
376 KB |
Output is correct |
25 |
Correct |
5 ms |
376 KB |
Output is correct |
26 |
Correct |
5 ms |
376 KB |
Output is correct |
27 |
Correct |
5 ms |
376 KB |
Output is correct |
28 |
Correct |
5 ms |
376 KB |
Output is correct |
29 |
Correct |
5 ms |
376 KB |
Output is correct |
30 |
Correct |
5 ms |
376 KB |
Output is correct |
31 |
Correct |
5 ms |
376 KB |
Output is correct |
32 |
Correct |
5 ms |
376 KB |
Output is correct |
33 |
Correct |
5 ms |
376 KB |
Output is correct |
34 |
Correct |
5 ms |
376 KB |
Output is correct |
35 |
Correct |
5 ms |
380 KB |
Output is correct |
36 |
Correct |
5 ms |
376 KB |
Output is correct |
37 |
Correct |
5 ms |
376 KB |
Output is correct |
38 |
Correct |
5 ms |
376 KB |
Output is correct |
39 |
Correct |
5 ms |
376 KB |
Output is correct |
40 |
Correct |
5 ms |
376 KB |
Output is correct |