Submission #376542

# Submission time Handle Problem Language Result Execution time Memory
376542 2021-03-11T16:31:18 Z smjleo The Kingdom of JOIOI (JOI17_joioi) C++14
15 / 100
12 ms 1516 KB
#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
#pragma GCC target("avx,avx2,fma")
using namespace std;
#define int long long
#define nl '\n'
#define io ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0)
const int mod = 1000000007, mod2 = 998244353;

// change this
const int N = 2005;

int n, m, arr[N][N], k, mini = INT_MAX, maxi = INT_MIN;

bool can() {
    int ffp = 1e9;
    // confirm leftmost corner
    for (int i=0; i<n; i++) {
        // find first place where element > mini+k
        int fp = n;
        for (int j=0; j<m; j++) {
            if (arr[i][j] > mini + k) {
                fp = j;
                break;
            }
        }
        ffp = min(ffp, fp);
        // find last place where element < maxi-k
        int lp = -1;
        for (int j=m-1; j>=0; j--) {
            if (arr[i][j] < maxi - k) {
                lp = j;
                break;
            }
        }
        if (ffp < lp+1) return false;
    }
    return true;
}

void flipr() {
    for (int i=0; i<n; i++) reverse(arr[i], arr[i]+m);
}

void flipc() {
    for (int i=0; i<m; i++) {
        for (int j=0; j<n/2; j++) swap(arr[j][i], arr[n-j-1][i]);
    }
}

int verify(int kk) {
    k = kk;

    bool res = false;

    for (bool _ : {0, 0}) {
        res |= can();
        flipr();
        res |= can();
        flipc();
    }
    
    return res;
}

signed main() {
    io;
    cin >> n >> m;
    for (int i=0; i<n; i++) {
        for (int j=0; j<m; j++) {
            cin >> arr[i][j];
            mini = min(mini, arr[i][j]);
            maxi = max(maxi, arr[i][j]);
        }
    }

    int l = 0, r = 1e9+5;
    while (l<r) {
        int mid = (l+r)/2;
        if (verify(mid)) r = mid;
        else l = mid+1;
    }
    cout << l << nl;
}

Compilation message

joioi.cpp: In function 'long long int verify(long long int)':
joioi.cpp:56:15: warning: unused variable '_' [-Wunused-variable]
   56 |     for (bool _ : {0, 0}) {
      |               ^
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 1 ms 364 KB Output is correct
6 Correct 1 ms 384 KB Output is correct
7 Correct 1 ms 364 KB Output is correct
8 Correct 1 ms 384 KB Output is correct
9 Correct 1 ms 364 KB Output is correct
10 Correct 1 ms 364 KB Output is correct
11 Correct 1 ms 364 KB Output is correct
12 Correct 1 ms 364 KB Output is correct
13 Correct 1 ms 384 KB Output is correct
14 Correct 1 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 1 ms 364 KB Output is correct
6 Correct 1 ms 384 KB Output is correct
7 Correct 1 ms 364 KB Output is correct
8 Correct 1 ms 384 KB Output is correct
9 Correct 1 ms 364 KB Output is correct
10 Correct 1 ms 364 KB Output is correct
11 Correct 1 ms 364 KB Output is correct
12 Correct 1 ms 364 KB Output is correct
13 Correct 1 ms 384 KB Output is correct
14 Correct 1 ms 384 KB Output is correct
15 Correct 1 ms 376 KB Output is correct
16 Correct 12 ms 1388 KB Output is correct
17 Correct 12 ms 1516 KB Output is correct
18 Correct 10 ms 1516 KB Output is correct
19 Correct 10 ms 1516 KB Output is correct
20 Incorrect 11 ms 1388 KB Output isn't correct
21 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 1 ms 364 KB Output is correct
6 Correct 1 ms 384 KB Output is correct
7 Correct 1 ms 364 KB Output is correct
8 Correct 1 ms 384 KB Output is correct
9 Correct 1 ms 364 KB Output is correct
10 Correct 1 ms 364 KB Output is correct
11 Correct 1 ms 364 KB Output is correct
12 Correct 1 ms 364 KB Output is correct
13 Correct 1 ms 384 KB Output is correct
14 Correct 1 ms 384 KB Output is correct
15 Correct 1 ms 376 KB Output is correct
16 Correct 12 ms 1388 KB Output is correct
17 Correct 12 ms 1516 KB Output is correct
18 Correct 10 ms 1516 KB Output is correct
19 Correct 10 ms 1516 KB Output is correct
20 Incorrect 11 ms 1388 KB Output isn't correct
21 Halted 0 ms 0 KB -