QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#667687 | #677. Koala Game | makrav | Compile Error | / | / | C++20 | 7.7kb | 2024-10-23 02:29:24 | 2024-10-23 02:29:24 |
Judging History
This is the latest submission verdict.
- [2024-10-23 02:29:24]
- Judged
- Verdict: Compile Error
- Time: 0ms
- Memory: 0kb
- [2024-10-23 02:29:24]
- Submitted
answer
#include <stdio.h>
#include <stdlib.h>
#include <bits/stdc++.h>
using namespace std;
#define all(x) (x).begin(), (x).end()
#define pb push_back
#define sz(x) (int) (x).size()
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];
}
}
int minValue(int N, int W) {
int R[100], B[100];
for (int i = 0; i < 100; i++) B[i] = 0;
B[0] = 1;
playRound(B, R);
for (int i = 0; i < N; i++) {
if (R[i] == 0) return i;
}
return 0;
}
int maxValue(int N, int W) {
int B[100], R[100];
for (int i = 0; i < N; i++) {
B[i] = 1;
}
playRound(B, R);
vector<int> ps;
for (int i = 0; i < N; i++) {
if (R[i] == 2) ps.push_back(i);
}
for (int i = 0; i < N; i++) B[i] = 0;
for (int i = 0; i < 50; i++) B[ps[i]] = 2;
playRound(B, R);
ps.clear();
for (int i = 0; i < N; i++) {
if (R[i] == 3) ps.push_back(i);
}
for (int i = 0; i < N; i++) B[i] = 0;
for (int i = 0; i < 25; i++) B[ps[i]] = 4;
playRound(B, R);
ps.clear();
for (int i = 0; i < N; i++) {
if (R[i] == 5) ps.push_back(i);
}
for (int i = 0; i < N; i++) B[i] = 0;
for (int i = 0; i < ps.size(); i++) B[ps[i]] = 11;
playRound(B, R);
for (int i = 0; i < N; i++) {
if (R[i] == 12) return i;
}
return 0;
}
mt19937 rnd(time(NULL));
int greaterValue(int N, int W) {
int B[100], R[100];
for (int i = 0; i < 100; i++) B[i] = 1;
playRound(B, R);
vector<int> sh, fh;
for (int i = 0; i < 100; i++) {
if (R[i] > B[i]) sh.pb(i);
else fh.pb(i);
}
if (R[0] > B[0] && R[1] < B[1]) {
return 0;
}
if (R[1] > B[1] && R[0] < B[0]) return 1;
if (R[0] < B[0]) {
// both in first half
B[0] = 0; B[1] = 0; B[sh[rnd() % 50]] = 0;
playRound(B, R);
if (R[0] > B[0]) return 0;
return 1;
}
int psmin = minValue(N, W);
for (int i = 0; i < N; i++) {
B[i] = 1;
}
B[psmin] = 0;
B[sh[0]] = 2;
playRound(B, R);
int psmax = -1;
for (int poss : fh) {
if (R[poss] > B[poss]) psmax = poss;
}
for (int i = 0; i < N; i++) {
B[i] = 1;
}
B[psmax] = 0; B[psmin] = 0; B[0] = 2; B[1] =2;
playRound(B, R);
if (R[0] > B[0]) return 0;
return 1;
}
struct xd {
pair<int, int> vals_seg;
vector<int> poss;
};
void allValues(int N, int W, int *P) {
int B[100], R[100];
// if (W == 2*N) {
// // TODO: Implement Subtask 4 solution here.
// // You may leave this block unmodified if you are not attempting this
// // subtask.
// } else {
vector<xd> lol;
vector<int> ap(N);
iota(all(ap), 0);
lol.pb({{1, N}, ap});
while (lol.size() < N) {
//cout << "yep" << endl;
vector<xd> new_lol;
for (int i = 0; i < sz(lol); i++) {
if (lol[i].poss.size() == 1) {
new_lol.pb(lol[i]);
continue;
}
int l = lol[i].vals_seg.first, r = lol[i].vals_seg.second;
int sm = 0;
for (int j = l; j <= r; j++) sm += j;
bool good = false;
pair<int, int> cs;
for (int cost = 1; cost * (r - l + 1) <= W; cost++) {
if (good) break;
for (int c2 = 0; c2 * (l - 1) + cost * (r - l + 1) <= W && (l != 1 || c2 <= 0); c2++) {
if (good) break;
int cntif0 = min(l - 1, (W - (N - r)) / (c2 + 1));
int cntifall = min(l - 1, max(0, ((W - (N - r)) - (cost + 1) * (r - l + 1)) / (c2 + 1)));
int currans = max((2 * l - 1 - cntif0) * cntif0 / 2, sm + (2 * l - 1 - cntifall) * cntifall / 2);
if ((r - l + 1) * (cost + 1) + N - r > W) {
currans = (2 * l - 1 - cntif0) * cntif0 / 2;
}
for (int newcnt = 1; newcnt < r - l + 1; newcnt++) {
int curcnt = min(l - 1, max(0, ((W - (N - r)) - newcnt * (cost + 1)) / (c2 + 1)));
if (currans < (2 * r - newcnt + 1) * newcnt / 2 + (2 * l - 1 - curcnt) * curcnt / 2) {
cs = {cost, c2};
//cout << cost << ' ' << c2 << ' ';
good = true;
break;
}
}
}
}
for (int j = 0; j < 100; j++) {
B[j] = 0;
}
for (int j = 0; j < i; j++) {
for (int pos : lol[j].poss) B[pos] = cs.second;
}
for (int pos : lol[i].poss) B[pos] = cs.first;
playRound(B, R);
vector<int> highs, lows;
for (int pos : lol[i].poss) {
if (R[pos] > B[pos]) highs.pb(pos);
else lows.pb(pos);
}
new_lol.pb({{lol[i].vals_seg.first, lol[i].vals_seg.first + lows.size() - 1}, lows});
new_lol.pb({{lol[i].vals_seg.first + lows.size(), lol[i].vals_seg.second}, highs});
}
swap(new_lol, lol);
}
for (int i = 0; i < N; i++) {
P[lol[i].poss[0]] = i + 1;
}
//}
}
static void runGame(int F) {
int i;
scanf("%d %d",&N,&W);
for (i=0;i<N;++i) {
scanf("%d",&P[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]);
}
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);
}
}
Details
implementer.cpp: In function ‘void grader()’: implementer.cpp:138:11: warning: ignoring return value of ‘int fscanf(FILE*, const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result] 138 | fscanf(fin, "%d %d %d",&F,&G,&maxQueries); | ~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ implementer.cpp: In function ‘void runGame(int)’: implementer.cpp:89:11: warning: ignoring return value of ‘int fscanf(FILE*, const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result] 89 | fscanf(fin,"%d %d",&N,&W); | ~~~~~~^~~~~~~~~~~~~~~~~~~ implementer.cpp:91:15: warning: ignoring return value of ‘int fscanf(FILE*, const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result] 91 | fscanf(fin,"%d",&P[i]); | ~~~~~~^~~~~~~~~~~~~~~~ answer.code: In function ‘void grader()’: answer.code:281:10: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result] 281 | scanf("%d %d",&F,&G); | ~~~~~^~~~~~~~~~~~~~~ answer.code: In function ‘void runGame(int)’: answer.code:254:10: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result] 254 | scanf("%d %d",&N,&W); | ~~~~~^~~~~~~~~~~~~~~ answer.code:256:14: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result] 256 | scanf("%d",&P[i]); | ~~~~~^~~~~~~~~~~~ In file included from /usr/include/c++/13/algorithm:60, from /usr/include/x86_64-linux-gnu/c++/13/bits/stdc++.h:51, from answer.code:3: In static member function ‘static constexpr _Up* std::__copy_move<_IsMove, true, std::random_access_iterator_tag>::__copy_m(_Tp*, _Tp*, _Up*) [with _Tp = const int; _Up = int; bool _IsMove = false]’, inlined from ‘constexpr _OI std::__copy_move_a2(_II, _II, _OI) [with bool _IsMove = false; _II = const int*; _OI = int*]’ at /usr/include/c++/13/bits/stl_algobase.h:506:30, inlined from ‘constexpr _OI std::__copy_move_a1(_II, _II, _OI) [with bool _IsMove = false; _II = const int*; _OI = int*]’ at /usr/include/c++/13/bits/stl_algobase.h:533:42, inlined from ‘constexpr _OI std::__copy_move_a(_II, _II, _OI) [with bool _IsMove = false; _II = __gnu_cxx::__normal_iterator<const int*, vector<int> >; _OI = int*]’ at /usr/include/c++/13/bits/stl_algobase.h:540:31, inlined from ‘constexpr _OI std::copy(_II, _II, _OI) [with _II = __gnu_cxx::__normal_iterator<const int*, vector<int> >; _OI = int*]’ at /usr/include/c++/13/bits/stl_algobase.h:633:7, inlined from ‘static _ForwardIterator std::__uninitialized_copy<true>::__uninit_copy(_InputIterator, _InputIterator, _ForwardIterator) [with _InputIterator = __gnu_cxx::__normal_iterator<const int*, std::vector<int> >; _ForwardIterator = int*]’ at /usr/include/c++/13/bits/stl_uninitialized.h:147:27, inlined from ‘_ForwardIterator std::uninitialized_copy(_InputIterator, _InputIterator, _ForwardIterator) [with _InputIterator = __gnu_cxx::__normal_iterator<const int*, vector<int> >; _ForwardIterator = int*]’ at /usr/include/c++/13/bits/stl_uninitialized.h:185:15, inlined from ‘constexpr _ForwardIterator std::__uninitialized_copy_a(_InputIterator, _InputIterator, _ForwardIterator, allocator<_Tp>&) [with _InputIterator = __gnu_cxx::__normal_iterator<const int*, vector<int> >; _ForwardIterator = int*; _Tp = int]’ at /usr/include/c++/13/bits/stl_uninitialized.h:373:37, inlined from ‘constexpr std::vector<_Tp, _Alloc>::vector(const std::vector<_Tp, _Alloc>&) [with _Tp = int; _Alloc = std::allocator<int>]’ at /usr/include/c++/13/bits/stl_vector.h:603:31, inlined from ‘constexpr xd::xd(const xd&)’ at answer.code:173:8, inlined from ‘constexpr decltype (::new(void*(0)) _Tp) std::construct_at(_Tp*, _Args&& ...) [with _Tp = xd; _Args = {const xd&}]’ at /usr/include/c++/13/bits/stl_construct.h:97:14, inlined from ‘static constexpr void std::allocator_traits<std::allocator<_CharT> >::construct(allocator_type&, _Up*, _Args&& ...) [with _Up = xd; _Args = {const xd&}; _Tp = xd]’ at /usr/include/c++/13/bits/alloc_traits.h:539:21, inlined from ‘constexpr void std::vector<_Tp, _Alloc>::push_back(const value_type&) [with _Tp = xd; _Alloc = std::allocator<xd>]’ at /usr/include/c++/13/bits/stl_vector.h:1283:30, inlined from ‘void allValues(int, int, int*)’ at answer.code:194:31: /usr/include/c++/13/bits/stl_algobase.h:437:30: warning: ‘void* __builtin_memmove(void*, const void*, long unsigned int)’ writing between 5 and 9223372036854775807 bytes into a region of size 4 overflows the destination [-Wstringop-overflow=] 437 | __builtin_memmove(__result, __first, sizeof(_Tp) * _Num); | ~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ In file included from /usr/include/x86_64-linux-gnu/c++/13/bits/c++allocator.h:3...