Submission #234393

# Submission time Handle Problem Language Result Execution time Memory
234393 2020-05-24T06:54:20 Z rama_pang Koala Game (APIO17_koala) C++14
64 / 100
61 ms 384 KB
#include "koala.h"
#include <bits/stdc++.h>
using namespace std;

const int MAXN = 100;

int B[MAXN], R[MAXN];

void Reset() {
  for (int i = 0; i < MAXN; i++) {
    B[i] = R[i] = 0;
  }
}

int Compare(int a, int b) {
  int lo = 1, hi = 9;
  while (lo <= hi) {
    int k = (lo + hi) / 2;
    Reset();
    B[a] = B[b] = k;
    playRound(B, R);
    bool pick[2] = {R[a] > k, R[b] > k};
    if (pick[0] == pick[1]) {
      if (pick[0]) {
        hi = k - 1;
      } else {
        lo = k + 1;
      }
    } else {
      if (pick[0]) {
        return 0;
      } else {
        return 1;
      }
    }
  }
  return 0;
}

int minValue(int N, int W) {
  Reset();
  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) {
  vector<int> large(N);
  iota(begin(large), end(large), 0);
  while (large.size() > 1) {
    int k = min(9, W / (int) large.size());
    Reset();
    for (auto i : large) {
      B[i] = k;
    }
    playRound(B, R);
    large.clear();
    for (int i = 0; i < N; i++) {
      if (R[i] > k) {
        large.emplace_back(i);
      }
    }
  }
  return large[0];
}

int greaterValue(int N, int W) {
  return Compare(0, 1);
}

void Solve(int N, int W, int *P, vector<int> v, int l, int r) {
  if (l > r) return;
  if (l == r) return void(P[v[0]] = l);
  int k = min({(int) sqrt(2 * l), W / (r - l + 1), 8});
  
  Reset();
  for (auto i : v) {
    B[i] = k;
  }
  playRound(B, R);

  vector<int> ls, gr;
  for (auto i : v) {
    if (R[i] > k) {
      gr.emplace_back(i);
    } else {
      ls.emplace_back(i);
    }
  }

  Solve(N, W, P, ls, l, l + int(ls.size()) - 1);
  Solve(N, W, P, gr, r - int(gr.size()) + 1, r);
}

void allValues(int N, int W, int *P) {
  if (W == 2 * N) {
    vector<int> v(N);
    iota(begin(v), end(v), 0);
    stable_sort(begin(v), end(v), [&](int a, int b) { return Compare(a, b); });
    for (int i = 0; i < N; i++) {
      P[v[i]] = i + 1;
    }
  } else {
    vector<int> v(N);
    iota(begin(v), end(v), 0);
    return Solve(N, W, P, v, 1, N);
  }
}
# Verdict Execution time Memory Grader output
1 Correct 9 ms 384 KB Output is correct
2 Correct 9 ms 384 KB Output is correct
3 Correct 9 ms 384 KB Output is correct
4 Correct 9 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Partially correct 26 ms 384 KB Output is partially correct
2 Partially correct 28 ms 384 KB Output is partially correct
3 Partially correct 26 ms 384 KB Output is partially correct
4 Partially correct 25 ms 384 KB Output is partially correct
# Verdict Execution time Memory Grader output
1 Incorrect 5 ms 384 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 61 ms 384 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 9 ms 384 KB Output is correct
2 Correct 9 ms 384 KB Output is correct
3 Correct 8 ms 384 KB Output is correct
4 Correct 8 ms 384 KB Output is correct
5 Correct 8 ms 384 KB Output is correct
6 Correct 9 ms 384 KB Output is correct
7 Correct 8 ms 384 KB Output is correct
8 Correct 9 ms 384 KB Output is correct
9 Correct 8 ms 384 KB Output is correct
10 Correct 8 ms 384 KB Output is correct
11 Correct 8 ms 384 KB Output is correct
12 Correct 8 ms 384 KB Output is correct
13 Correct 8 ms 384 KB Output is correct
14 Correct 8 ms 384 KB Output is correct
15 Correct 9 ms 384 KB Output is correct
16 Correct 9 ms 384 KB Output is correct
17 Correct 9 ms 384 KB Output is correct
18 Correct 8 ms 384 KB Output is correct
19 Correct 8 ms 384 KB Output is correct
20 Correct 8 ms 384 KB Output is correct
21 Correct 8 ms 384 KB Output is correct
22 Correct 9 ms 384 KB Output is correct
23 Correct 9 ms 384 KB Output is correct
24 Correct 9 ms 384 KB Output is correct
25 Correct 9 ms 384 KB Output is correct
26 Correct 8 ms 308 KB Output is correct
27 Correct 8 ms 384 KB Output is correct
28 Correct 8 ms 384 KB Output is correct
29 Correct 8 ms 384 KB Output is correct
30 Correct 8 ms 384 KB Output is correct
31 Correct 9 ms 384 KB Output is correct
32 Correct 9 ms 384 KB Output is correct
33 Correct 8 ms 384 KB Output is correct
34 Correct 8 ms 384 KB Output is correct
35 Correct 8 ms 384 KB Output is correct
36 Correct 8 ms 384 KB Output is correct
37 Correct 8 ms 384 KB Output is correct
38 Correct 8 ms 384 KB Output is correct
39 Correct 8 ms 384 KB Output is correct
40 Correct 8 ms 384 KB Output is correct