#include <algorithm>
#include "grader.h"
char dp[501][501][501];
short 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;
for (int i = l; i < x; ++i) {
char max = std::max(dfs(std::max(l, (i + x) / 2 + 1), std::min(r, x), i), dfs(std::max(l, i), std::min((i + x - 1) / 2, r), i));
if (min > max) {
min = max;
sel[l][r][x] = i;
}
}
for (int i = x + 1; i <= r; ++i) {
char max = std::max(dfs(std::max(l, (i + x) / 2 + 1), std::min(i, r), i), dfs(std::max(l, x), std::min((i + x - 1) / 2, r), i));
if (min > max) {
min = max;
sel[l][r][x] = i;
}
}
return dp[l][r][x] = min + 1;
}
int HC(int N) {
int l = 1, r = N, x = 1;
for (int i = 1; i <= r; ++i) {
dfs(l, r, i);
if (dp[l][r][i] < dp[l][r][x]) {
x = i;
}
}
Guess(x);
while (l < r) {
dfs(l, r, x);
const int k = sel[l][r][x];
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 |
Execution timed out |
10027 ms |
165992 KB |
Time limit exceeded |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
10020 ms |
165972 KB |
Time limit exceeded |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
10088 ms |
165872 KB |
Time limit exceeded |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
362 ms |
16308 KB |
Execution killed with signal 11 |