Submission #749972

# Submission time Handle Problem Language Result Execution time Memory
749972 2023-05-29T02:37:47 Z Pring The Kingdom of JOIOI (JOI17_joioi) C++14
0 / 100
1 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;
set<int> S;

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 (x * 2 >= big) { // 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 (r - 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];
        S.insert(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:22: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]
   22 |         for (int i = 1; i < v.size(); i++) {
      |                         ~~^~~~~~~~~~
joioi.cpp:38: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]
   38 |         for (int i = 1; i < v.size(); i++) {
      |                         ~~^~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Incorrect 1 ms 340 KB Output isn't correct
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Incorrect 1 ms 340 KB Output isn't correct
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Incorrect 1 ms 340 KB Output isn't correct
4 Halted 0 ms 0 KB -