# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
1277761 | wedonttalkanymore | The Kingdom of JOIOI (JOI17_joioi) | C++20 | 1 ms | 332 KiB |
#include <bits/stdc++.h>
/*
Brute to win
*/
using namespace std;
using ll = long long;
#define int long long
#define pii pair<ll, ll>
#define fi first
#define se second
const ll N = 2e3 + 5, inf = 1e18, mod = 1e9 + 7, block = 320, lim = 19;
int h, w, a[N][N], b[N][N];
int minn = inf;
void rolate() {
for (int i = 1; i <= h; i++) {
for (int j = 1; j <= w; j++) {
b[i][j] = a[w - j + 1][i];
}
}
swap(h, w);
for (int i = 1; i <= h; i++) {
for (int j = 1; j <= w; j++) {
a[i][j] = b[i][j];
}
}
}
bool check(int mid) {
int vmax = 0, vmin = inf, last = w;
for (int i = 1; i <= h; i++) {
for (int j = 1; j <= last; j++) {
if (a[i][j] - minn > mid) {
last = j - 1;
break;
}
}
for (int j = last + 1; j <= w; j++) {
vmin = min(vmin, a[i][j]);
vmax = max(vmax, a[i][j]);
}
}
return vmax - vmin <= mid;
}
signed main() {
ios::sync_with_stdio(false);
cin.tie(0);
if (fopen(".inp", "r")) {
freopen(".inp", "r", stdin);
freopen(".out", "w", stdout);
}
cin >> h >> w;
for (int i = 1; i <= h; i++) {
for (int j = 1; j <= w; j++) {
cin >> a[i][j];
minn = min(minn, a[i][j]);
}
}
int ans = inf;
for (int i = 1; i <= 4; i++) {
int l = 1, r = 1e9, res = inf;
while(l <= r) {
int mid = (l + r) / 2;
if (check(mid)) {
res = mid;
r = mid - 1;
}
else l = mid + 1;
}
ans = min(ans, res);
rolate();
}
cout << ans;
return 0;
}
컴파일 시 표준 에러 (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... |