Submission #703826

# Submission time Handle Problem Language Result Execution time Memory
703826 2023-02-28T13:39:48 Z stevancv The Kingdom of JOIOI (JOI17_joioi) C++14
0 / 100
1 ms 212 KB
#include <bits/stdc++.h>
#define ll long long
#define ld long double
#define sp ' '
#define en '\n'
#define smin(a, b) a = min(a, b)
#define smax(a, b) a = max(a, b)
using namespace std;
const int N = 1e5 + 2;
const int inf = 2e9;
const int mod = 1e9 + 7;
int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    int n, m;
    cin >> n >> m;
    int mn = inf; int mx = 0;
    vector<vector<int>> a(n, vector<int>(m));
    for (int i = 0; i < n; i++) {
        for (int j = 0; j < m; j++) {
            cin >> a[i][j];
            smin(mn, a[i][j]);
            smax(mx, a[i][j]);
        }
    }
    auto Can = [&] (int x) {
        vector<int> v(n);
        int gde = m;
        for (int i = 0; i < n; i++) {
            for (int j = 0; j < gde; j++) {
                if (mn + x < a[i][j]) {
                    gde = j;
                    break;
                }
            }
            v[i] = gde;
        }
        int mini = inf; int maxi = 0;
        for (int i = 0; i < n; i++) {
            for (int j = v[i]; j < m; j++) {
                smin(mini, a[i][j]);
                smax(maxi, a[i][j]);
            }
        }
        return maxi - mini <= x;
    };
    auto Solve = [&] () {
        int l = (mx - mn + 1) / 2, r = mx - mn, ans = r;
        while (l <= r) {
            int mid = l + r >> 1;
            if (Can(mid)) {
                ans = mid;
                r = mid - 1;
            }
            else l = mid + 1;
        }
        return ans;
    };
    int ans = Solve();
    reverse(a.begin(), a.end());
    smin(ans, Solve());
    for (int i = 0; i < n; i++) reverse(a[i].begin(), a[i].end());
    smin(ans, Solve());
    reverse(a.begin(), a.end());
    smin(ans, Solve());
    cout << ans << en;
    return 0;
}

Compilation message

joioi.cpp: In lambda function:
joioi.cpp:51:25: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   51 |             int mid = l + r >> 1;
      |                       ~~^~~
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Incorrect 1 ms 212 KB Output isn't correct
5 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Incorrect 1 ms 212 KB Output isn't correct
5 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Incorrect 1 ms 212 KB Output isn't correct
5 Halted 0 ms 0 KB -