| # | Time | Username | Problem | Language | Result | Execution time | Memory |
|---|---|---|---|---|---|---|---|
| 1299161 | daotuankhoi | The Kingdom of JOIOI (JOI17_joioi) | C++20 | 1622 ms | 31832 KiB |
#include <bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define ll long long
#ifdef LOCAL
#include "algo/debug.h"
#else
#define debug(...) 42
#endif
template <class T> bool ckmax(T &a, T b) { return a < b ? (a = b, true) : false; }
template <class T> bool ckmin(T &a, T b) { return a > b ? (a = b, true) : false; }
const int MAXN = 2005;
int a[MAXN][MAXN], b[MAXN][MAXN], lim = 0, h, w;
void flip() {
for (int i = 1; i <= h; i++) {
for (int j = 1; j <= w; j++) {
b[j][h - i + 1] = a[i][j];
}
}
swap(h, w);
for (int i = 1; i <= h; i++) {
for (int j = 1; j <= w; j++) {
a[i][j] = b[i][j];
}
}
}
bool ok(int val) {
int curMax = 0, mx = 0, mn = 1e9, pos = w;
for (int i = 1; i <= h; i++) {
for (int j = 1; j <= pos; j++) {
if (lim - a[i][j] > val) {
pos = j - 1;
break;
}
ckmax(curMax, a[i][j]);
}
for (int j = pos + 1; j <= w; j++) {
ckmax(mx, a[i][j]);
ckmin(mn, a[i][j]);
}
}
return (curMax == lim && mx - mn <= val);
}
bool check(int val) {
for (int i = 0; i < 4; i++) {
if (ok(val)) return 1;
flip();
}
return 0;
}
int main() {
#define NAME "test"
if (fopen(NAME".inp", "r")) {
freopen(NAME".inp", "r", stdin);
freopen(NAME".out", "w", stdout);
}
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
cin >> h >> w;
for (int i = 1; i <= h; i++) {
for (int j = 1; j <= w; j++) {
cin >> a[i][j];
ckmax(lim, a[i][j]);
}
}
int l = 0, r = 1e9, ans;
while (l <= r) {
int mid = (l + r) >> 1;
if (check(mid)) r = (ans = mid) - 1;
else l = mid + 1;
}
cout << ans << '\n';
return 0;
}
Compilation message (stderr)
| # | Verdict | Execution time | Memory | Grader output |
|---|---|---|---|---|
| Fetching results... | ||||
| # | Verdict | Execution time | Memory | Grader output |
|---|---|---|---|---|
| Fetching results... | ||||
| # | Verdict | Execution time | Memory | Grader output |
|---|---|---|---|---|
| Fetching results... | ||||
