제출 #977564

#제출 시각아이디문제언어결과실행 시간메모리
977564siewjh코알라 (APIO17_koala)C++17
90 / 100
53 ms596 KiB
#include "koala.h" #include <bits/stdc++.h> using namespace std; const int MAXN = 105; int qa[MAXN], ra[MAXN], cmpa[MAXN][MAXN]; int minValue(int N, int W){ // N = 100, W = 100, 2 times qa[0] = 1; for (int i = 1; i < N; i++) qa[i] = 0; playRound(qa, ra); if (ra[0] <= 1) return 0; for (int i = 1; i < N; i++) if (ra[i] == 0) return i; } int maxValue(int N, int W){ // N = 100, W = 100, 4 times vector<int> loc; for (int i = 0; i < N; i++) loc.push_back(i); while (loc.size() > 1){ // 100, 50, 25, 9, 1 int amt = W / loc.size(); for (int i = 0; i < N; i++) qa[i] = 0; for (int x : loc) qa[x] = amt; playRound(qa, ra); vector<int> ori; swap(ori, loc); for (int x : ori) if (ra[x] > amt) loc.push_back(x); } return loc[0]; } int greaterValue(int N, int W){ // N = 100, W = 100, 3 times for (int i = 0; i < N; i++) qa[i] = 0; int lo = 0, hi = 4; int amt[] = {1, 2, 4, 6, 8}; while (lo <= hi){ int m = (lo + hi) >> 1; qa[0] = qa[1] = amt[m]; playRound(qa, ra); if (ra[0] > amt[m] != ra[1] > amt[m]) return ra[1] > amt[m]; else if (ra[0] > amt[m]) lo = m + 1; else hi = m - 1; } } void dnc(int l, int r, vector<int> &vind, int *P){ if (l == r){ P[vind[0]] = l; return; } int sz = r - l + 1, lo = 1, hi = 100 / sz, sh = -1; vector<int> rem; for (int i = 1; i < l; i++) rem.push_back(i); for (int i = r + 1; i <= 100; i++) rem.push_back(i); while (lo <= hi){ int m = (lo + hi) >> 1, stone = sz, ind = 0, choose = 0; for (int x = r; x >= l; x--){ int sum = 0; for (int i = 0; i <= m; i++){ if (stone) stone--; else if (ind != rem.size()){ sum += rem[ind]; ind++; } else{ sum = 1e9; break; } } if (sum > x) break; else if (sum == x){ if (choose) choose++; break; } else choose++; } if (choose == 0) hi = m - 1; else if (choose == sz) lo = m + 1; else{ sh = m; break; } } vector<int> lv, rv; for (int i = 0; i < 100; i++) qa[i] = 0; for (int x : vind) qa[x] = sh; playRound(qa, ra); for (int x : vind){ if (ra[x] > sh) rv.push_back(x); else lv.push_back(x); } dnc(l, l + lv.size() - 1, lv, P); dnc(l + lv.size(), r, rv, P); } bool cmp(int a, int b){ if (cmpa[a][b] != -1) return cmpa[a][b]; qa[a] = qa[b] = 100; playRound(qa, ra); qa[a] = qa[b] = 0; cmpa[a][b] = ra[a] > 100; cmpa[b][a] = 1 - cmpa[a][b]; return cmpa[a][b]; } void allValues(int N, int W, int *P){ if (W == 100){ // N = 100, W = 100, 100 times vector<int> vind(100); for (int i = 0; i < 100; i++) vind[i] = i; dnc(1, 100, vind, P); } else{ // N = 100, W = 200, 700 times memset(cmpa, -1, sizeof(cmpa)); for (int i = 0; i < 100; i++) qa[i] = 0; for (int i = 0; i < 100; i++) P[i] = i + 1; stable_sort(P, P + 100, cmp); } }

컴파일 시 표준 에러 (stderr) 메시지

koala.cpp: In function 'int greaterValue(int, int)':
koala.cpp:42:13: warning: suggest parentheses around comparison in operand of '!=' [-Wparentheses]
   42 |   if (ra[0] > amt[m] != ra[1] > amt[m]) return ra[1] > amt[m];
      |       ~~~~~~^~~~~~~~
koala.cpp: In function 'void dnc(int, int, std::vector<int>&, int*)':
koala.cpp:63:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   63 |     else if (ind != rem.size()){
      |              ~~~~^~~~~~~~~~~~~
koala.cpp: In function 'int minValue(int, int)':
koala.cpp:16:1: warning: control reaches end of non-void function [-Wreturn-type]
   16 | }
      | ^
koala.cpp: In function 'int greaterValue(int, int)':
koala.cpp:46:1: warning: control reaches end of non-void function [-Wreturn-type]
   46 | }
      | ^
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...