Submission #749979

# Submission time Handle Problem Language Result Execution time Memory
749979 2023-05-29T02:44:05 Z Pring The Kingdom of JOIOI (JOI17_joioi) C++14
0 / 100
0 ms 340 KB
#include <bits/stdc++.h>
using namespace std;

#define int long long
typedef pair<int, int> pii;

const int MXN = 2005;
int n, m, a[MXN][MXN], b[MXN][MXN];
int big = 0, small = LLONG_MAX;
int l, r;

bool CHECK() {
    vector<int> v;
    int f = 0;
    for (int i = 0; i < n; i++) {
        v.clear();
        for (int j = 0; j < m; j++) {
            if (b[i][j] != 0) v.push_back(b[i][j]);
        }
        int C = 0;
        for (int i = 1; i < v.size(); i++) {
            if (v[i] != v[i - 1]) {
                if (++C == 2) return false;
            }
        }
        if (C == 0) continue;
        if (f == 0) f = v[0];
        else if (f != v[0]) return false;
    }
    f = 0;
    for (int i = 0; i < m; i++) {
        v.clear();
        for (int j = 0; j < n; j++) {
            if (b[j][i] != 0) v.push_back(b[j][i]);
        }
        int C = 0;
        for (int i = 1; i < v.size(); i++) {
            if (v[i] != v[i - 1]) {
                if (++C == 2) return false;
            }
        }
        if (C == 0) continue;
        if (f == 0) f = v[0];
        else if (f != v[0]) return false;
    }
    return true;
}

bool check(int x) {
    if (big - 2 * x < 1) { // cross
        for (int i = 0; i < n; i++) {
            for (int j = 0; j < m; j++) {
                if (a[i][j] < big - x) b[i][j] = 1;
                else if (x < a[i][j]) b[i][j] = 2;
                else b[i][j] = 0;
            }
        }
    } else { // not cross
        for (int i = 0; i < n; i++) {
            for (int j = 0; j < m; j++) {
                if (a[i][j] <= x) b[i][j] = 1;
                else if (big - x <= a[i][j]) b[i][j] = 2;
                else return false;
            }
        }
    }
    return CHECK();
}

int32_t main() {
    cin.tie(0) -> sync_with_stdio(false);
    cin >> n >> m;
    for (int i = 0; i < n; i++) for (int j = 0; j < m; j++) {
        cin >> a[i][j];
        big = max(big, a[i][j]);
        small = min(small, a[i][j]);
    }
    for (int i = 0; i < n; i++) for (int j = 0; j < m; j++) {
        a[i][j] -= small;
    }
    big -= small;
    int l = -1, r = big;
    while (l + 1 < r) {
        int mid = (l + r) >> 1;
        (check(mid) ? r : l) = mid;
    }
    cout << r << endl;
    return 0;
}

Compilation message

joioi.cpp: In function 'bool CHECK()':
joioi.cpp:21:27: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   21 |         for (int i = 1; i < v.size(); i++) {
      |                         ~~^~~~~~~~~~
joioi.cpp:37:27: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   37 |         for (int i = 1; i < v.size(); i++) {
      |                         ~~^~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 0 ms 340 KB Output is correct
2 Correct 0 ms 340 KB Output is correct
3 Incorrect 0 ms 340 KB Output isn't correct
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 340 KB Output is correct
2 Correct 0 ms 340 KB Output is correct
3 Incorrect 0 ms 340 KB Output isn't correct
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 340 KB Output is correct
2 Correct 0 ms 340 KB Output is correct
3 Incorrect 0 ms 340 KB Output isn't correct
4 Halted 0 ms 0 KB -