답안 #366415

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
366415 2021-02-14T07:17:12 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, mn = 1e9, 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 = 1e9, lst = m;
        for (int i = 0; i < n; i++) {
            for (int j = 0; j < lst; j++) if (grid[i][j] > mn + 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];
        mn = min(mn, grid[i][j]);
    }
    int l = 0, r = 1e9;
    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 Incorrect 1 ms 364 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 364 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 364 KB Output isn't correct
2 Halted 0 ms 0 KB -