Submission #939241

# Submission time Handle Problem Language Result Execution time Memory
939241 2024-03-06T07:23:45 Z qwe1rt1yuiop1 The Kingdom of JOIOI (JOI17_joioi) C++14
0 / 100
0 ms 348 KB
#include <bits/stdc++.h>
// #define int long long
using namespace std;

void solve()
{
    int n, m;
    cin >> n >> m;
    vector<vector<int>> v(n, vector<int>(m));
    for (auto &i : v)
        for (auto &j : i)
            cin >> j;

    int l = 0, r = 1000000005;
    while (l < r)
    {
        int mid = (l + r) >> 1, ok = 1;

        vector<int> a(n), b(n);

        for (int i = 0; i < n; ++i)
        {
            int mx = v[i][0], mn = mx;
            for (a[i] = 0; a[i] < m; ++a[i])
            {
                mx = max(mx, v[i][a[i]]);
                mn = min(mn, v[i][a[i]]);
                if (mx - mn > mid)
                    break;
            }
            --a[i];
        }
        for (int i = 0; i < n; ++i)
        {
            int mx = v[i][m - 1], mn = mx;
            for (b[i] = m - 1; b[i] >= 0; --b[i])
            {
                mx = max(mx, v[i][b[i]]);
                mn = min(mn, v[i][b[i]]);
                if (mx - mn > mid)
                    break;
            }
            ++b[i];
            if (b[i] > a[i] + 1)
            {
                ok = 0;
                break;
            }
        }
        
        if (ok == 0)
        {
            l = mid + 1;
            continue;
        }

        int mn = a[0];
        for (int i = 1; i < n; ++i)
        {
            mn = min(mn, a[i]);
            if (b[i] > mn + 1)
            {
                ok = 0;
                break;
            }
        }
        if (ok)
        {
            r = mid;
            continue;
        }
        int mx = b[0];
        for (int i = 1; i < n; ++i)
        {
            mx = max(mx, b[i]);
            if (mx > a[i] + 1)
            {
                ok = 0;
                break;
            }
        }

        if (ok)
            r = mid;
        else
            l = mid + 1;
    }
    cout << l << '\n';
}

/*
4 4
1 12 6 11
11 10 2 14
10 1 9 20
4 17 19 10

 */

signed main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);

    solve();

    return 0;
}
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 348 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 348 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 348 KB Output isn't correct
2 Halted 0 ms 0 KB -