답안 #366414

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
366414 2021-02-14T07:16:04 Z dolphingarlic The Kingdom of JOIOI (JOI17_joioi) C++14
0 / 100
1 ms 364 KB
#include <bits/stdc++.h>
typedef long long ll;
using namespace std;

int n, m, mx, grid[2000][2000], tmp[2000][2000];

void rotate() {
    for (int i = 0; i < n; i++) for (int j = 0; j < m; j++)
        tmp[i][j] = grid[j][n - i - 1];
    swap(n, m);
    for (int i = 0; i < n; i++) for (int j = 0; j < m; j++)
        grid[i][j] = tmp[i][j];
}

bool check(int diff) {
    for (int _ : {0,0,0,0}) {
        int lmx = 0, lmn = mx, lst = m;
        for (int i = 0; i < n; i++) {
            for (int j = 0; j < lst; j++) if (grid[i][j] < mx - diff) {
                lst = j;
                break;
            }
            for (int j = lst; j < m; j++) lmx = max(lmx, grid[i][j]), lmn = min(lmn, grid[i][j]);
        }
        if (lmx - lmn <= diff) return true;
        rotate();
    }
    return false;
}

int main() {
    cin.tie(0)->sync_with_stdio(0);
    cin >> n >> m;
    for (int i = 0; i < n; i++) for (int j = 0; j < m; j++) {
        cin >> grid[i][j];
        mx = max(mx, grid[i][j]);
    }
    int l = 0, r = mx;
    while (l != r) {
        int mid = (l + r) / 2;
        if (check(mid)) r = mid;
        else l = mid + 1;
    }
    cout << l;
    return 0;
}

Compilation message

joioi.cpp: In function 'bool check(int)':
joioi.cpp:16:14: warning: unused variable '_' [-Wunused-variable]
   16 |     for (int _ : {0,0,0,0}) {
      |              ^
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 364 KB Output is correct
2 Incorrect 1 ms 364 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 364 KB Output is correct
2 Incorrect 1 ms 364 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 364 KB Output is correct
2 Incorrect 1 ms 364 KB Output isn't correct
3 Halted 0 ms 0 KB -