이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include<bits/stdc++.h>
#ifndef LOCAL
#include "koala.h"
#endif // LOCAL
using namespace std;
#define pb push_back
#ifdef LOCAL
mt19937 rnd(51);
static int N, W;
static int P[105];
static int maxQueries = 3200;
static int numQueries;
static void runGame(int F);
static void grader();
int main() {
grader();
return 0;
}
void playRound(int *B, int *R) {
int i, j;
int S = 0;
for (i=0;i<N;++i) {
if ( !(B[i] >= 0 && B[i] <= W) ) {
printf("Invalid query.\n");
exit(0);
}
S += B[i];
}
if (S > W) {
printf("Invalid query.\n");
exit(0);
}
numQueries++;
if (numQueries > maxQueries) {
printf("Too many queries.\n");
exit(0);
}
int cache[2][205];
int num[2][205];
char taken[105][205];
for (i=0;i<205;++i) {
cache[1][i] = 0;
num[1][i] = 0;
}
for (i=0;i<N;++i) {
int v = B[i]+1;
int ii = i&1;
int o = ii^1;
for (j=0;j<=W;++j) {
cache[ii][j] = cache[o][j];
num[ii][j] = num[o][j];
taken[i][j] = 0;
}
for (j=W;j>=v;--j) {
int h = cache[o][j-v] + P[i];
int hn = num[o][j-v] + 1;
if (h > cache[ii][j] || (h == cache[ii][j] && hn > num[ii][j])) {
cache[ii][j] = h;
num[ii][j] = hn;
taken[i][j] = 1;
} else {
taken[i][j] = 0;
}
}
}
int cur = W;
for (i=N-1;i>=0;--i) {
R[i] = taken[i][cur] ? (B[i] + 1) : 0;
cur -= R[i];
}
}
#endif
int minValue(int N, int W) {
return 0;
}
int maxValue(int n, int w) {
vector<int> arr(n);
iota(arr.begin(), arr.end(), 0);
while (arr.size() > 1) {
int sz = arr.size();
int can = w / sz;
int b[n], r[n];
for (int i = 0; i < n; i++) b[i] = 0;
for (auto to : arr) {
b[to] = can;
}
playRound(b, r);
vector<int> nw;
for (auto to : arr) {
if (b[to] == can && r[to] > can) {
nw.pb(to);
}
}
swap(arr, nw);
}
return arr[0];
}
int greaterValue(int N, int W) {
return 0;
}
void allValues(int n, int w, int *p) {
int cnt = 0;
for (int i = 0; i < n; i++) p[i] = -1;
for (int i = 0; i < n; i++) {
vector<int> arr;
for (int j = 0; j < n; j++) {
if (p[j] == -1) {
arr.pb(j);
}
}
int now = (w == 2 * n ? 2 : 1);
while (arr.size() > 1) {
int sz = arr.size();
int b[n], r[n];
if (w == 2 * n) now = w / sz;
for (int j = 0; j < n; j++) b[j] = 0;
for (auto to : arr) {
b[to] = now;
}
playRound(b, r);
vector<int> nw;
for (auto to : arr) {
if (b[to] == now && r[to] > now) {
nw.pb(to);
}
}
if (nw.size() == 0) {
now--;
} else if (arr.size() == nw.size()) {
now++;
} else {
swap(arr, nw);
now *= 2;
}
}
p[arr[0]] = n - i;
}
}
#ifdef LOCAL
static void runGame(int F) {
int i;
N = 100;
W = 100;
for (i=0;i<N;++i) {
P[i] = i;
}
numQueries = 0;
if (F == 1) {
printf("%d\n", minValue(N, W));
} else if (F == 2) {
printf("%d\n", maxValue(N, W));
} else if (F == 3) {
printf("%d\n", greaterValue(N, W));
} else if (F == 4) {
int userP[105];
allValues(N, W, userP);
for (i=0;i<N;i++) {
printf("%d ",userP[i]);
assert(userP[i] == P[i]);
}
printf("\n");
}
printf("Made %d calls to playRound.\n", numQueries);
}
static void grader() {
int i;
int F, G;
scanf("%d %d",&F,&G);
for (i=0;i<G;i++) {
runGame(F);
}
}
#endif
컴파일 시 표준 에러 (stderr) 메시지
koala.cpp: In function 'void allValues(int, int, int*)':
koala.cpp:122:9: warning: unused variable 'cnt' [-Wunused-variable]
122 | int cnt = 0;
| ^~~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |