Submission #434018

# Submission time Handle Problem Language Result Execution time Memory
434018 2021-06-20T13:58:59 Z KoD Hotter Colder (IOI10_hottercolder) C++17
75 / 100
362 ms 28620 KB
#include <bits/stdc++.h>
#include "grader.h"

char dp[501][501][501];
bool sel[501][501][501];

char dfs(const int l, const int r, const int x) {
   if (l == r) return 0;
   if (dp[l][r][x] != 0) return dp[l][r][x];
   char min = 100;
   if (l < x) {
      const int i = l;
      char max = 0;
      if ((i + x) / 2 + 1 <= r) {
         max = std::max(max, dfs(std::max(l, (i + x) / 2 + 1), r, i));
      }
      if (l <= (i + x - 1) / 2) {
         max = std::max(max, dfs(l, std::min((i + x - 1) / 2, r), i));
      }
      if (min > max) {
         min = max;
         sel[l][r][x] = false;
      }
   }
   if (x < r) {
      const int i = r;
      char max = 0;
      if ((i + x) / 2 + 1 <= r) {
         max = std::max(max, dfs(std::max(l, (i + x) / 2 + 1), r, i));
      }
      if (l <= (i + x - 1) / 2) {
         max = std::max(max, dfs(l, std::min((i + x - 1) / 2, r), i));
      }
      if (min > max) {
         min = max;
         sel[l][r][x] = true;
      }
   }
   return dp[l][r][x] = min + 1;
}

int HC(int N) {
   int l = 1, r = N, x = 1;
   Guess(x);
   while (l < r) {
      dfs(l, r, x);
      const int k = (sel[l][r][x] ? r : l);
      const int t = Guess(k);
      if (t == 0) {
         return (x + k) / 2;
      }
      if (t == 1) {
         if (k < x) {
            r = std::min(r, (k + x - 1) / 2);
         } else {
            l = std::max(l, (k + x) / 2 + 1);
         }
      } else {
         if (k < x) {
            l = std::max(l, (k + x) / 2 + 1);
         } else {
            r = std::min(r, (k + x - 1) / 2);
         }
      }
      x = k;
   }
   return l;
}
# Verdict Execution time Memory Grader output
1 Correct 88 ms 28616 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 102 ms 28620 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 88 ms 28616 KB Output is correct
# Verdict Execution time Memory Grader output
1 Runtime error 362 ms 16228 KB Execution killed with signal 11