Submission #191341

# Submission time Handle Problem Language Result Execution time Memory
191341 2020-01-14T17:39:15 Z Akashi The Kingdom of JOIOI (JOI17_joioi) C++14
100 / 100
1193 ms 54208 KB
#include <bits/stdc++.h>
using namespace std;

int n, m;
int Min, Max;
int a[2005][2005];

inline bool check(int dif, bool dir1, bool dir2){
    int i, j = 1;

    int adc = 1, adl = 1, Last = n;
    if(dir1 == 1) adc = -1, j = m;
    if(dir2 == 1) adl = -1, Last = 1;

    int mx = 0, mn = 1e9;
    while(j <= m && j >= 1){
        i = 1;
        if(dir2) i = n;

        while(Min + dif >= a[i][j] && (Last - i) * adl >= 0) i += adl;

        Last = i - adl;
        while(i <= n && i >= 1){
            mx = max(mx, a[i][j]);
            mn = min(mn, a[i][j]);
            i += adl;
        }
        if(mx - mn > dif) return 0;

        j += adc;
    }

    return 1;
}

inline int solve(){
    int st = 0, dr = Max - Min;
    while(st <= dr){
        int mij = (st + dr) / 2;

        bool ok = false;
        for(int dir1 = 0; dir1 < 2 && !ok ; ++dir1)
            for(int dir2 = 0; dir2 < 2 && !ok ; ++dir2)
                ok |= check(mij, dir1, dir2);

        if(ok) dr = mij - 1;
        else st = mij + 1;
    }

    return st;
}

int main()
{
    scanf("%d%d", &n, &m);

    Min = 1e9; Max = 0;
    for(int i = 1; i <= n ; ++i){
        for(int j = 1; j <= m ; ++j){
            scanf("%d", &a[i][j]);
            Min = min(Min, a[i][j]);
            Max = max(Max, a[i][j]);
        }
    }

    int Sol = solve();
    printf("%d", Sol);

    return 0;
}

Compilation message

joioi.cpp: In function 'int main()':
joioi.cpp:55:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d%d", &n, &m);
     ~~~~~^~~~~~~~~~~~~~~~
joioi.cpp:60:18: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
             scanf("%d", &a[i][j]);
             ~~~~~^~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 2 ms 380 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 3 ms 376 KB Output is correct
4 Correct 2 ms 404 KB Output is correct
5 Correct 2 ms 376 KB Output is correct
6 Correct 2 ms 376 KB Output is correct
7 Correct 2 ms 376 KB Output is correct
8 Correct 2 ms 376 KB Output is correct
9 Correct 2 ms 376 KB Output is correct
10 Correct 2 ms 376 KB Output is correct
11 Correct 2 ms 376 KB Output is correct
12 Correct 2 ms 376 KB Output is correct
13 Correct 2 ms 376 KB Output is correct
14 Correct 2 ms 376 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 380 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 3 ms 376 KB Output is correct
4 Correct 2 ms 404 KB Output is correct
5 Correct 2 ms 376 KB Output is correct
6 Correct 2 ms 376 KB Output is correct
7 Correct 2 ms 376 KB Output is correct
8 Correct 2 ms 376 KB Output is correct
9 Correct 2 ms 376 KB Output is correct
10 Correct 2 ms 376 KB Output is correct
11 Correct 2 ms 376 KB Output is correct
12 Correct 2 ms 376 KB Output is correct
13 Correct 2 ms 376 KB Output is correct
14 Correct 2 ms 376 KB Output is correct
15 Correct 2 ms 376 KB Output is correct
16 Correct 7 ms 1400 KB Output is correct
17 Correct 10 ms 1528 KB Output is correct
18 Correct 9 ms 1500 KB Output is correct
19 Correct 10 ms 1580 KB Output is correct
20 Correct 8 ms 1400 KB Output is correct
21 Correct 12 ms 1656 KB Output is correct
22 Correct 11 ms 1784 KB Output is correct
23 Correct 11 ms 1656 KB Output is correct
24 Correct 10 ms 1528 KB Output is correct
25 Correct 11 ms 1656 KB Output is correct
26 Correct 11 ms 1656 KB Output is correct
27 Correct 16 ms 1656 KB Output is correct
28 Correct 12 ms 1656 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 380 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 3 ms 376 KB Output is correct
4 Correct 2 ms 404 KB Output is correct
5 Correct 2 ms 376 KB Output is correct
6 Correct 2 ms 376 KB Output is correct
7 Correct 2 ms 376 KB Output is correct
8 Correct 2 ms 376 KB Output is correct
9 Correct 2 ms 376 KB Output is correct
10 Correct 2 ms 376 KB Output is correct
11 Correct 2 ms 376 KB Output is correct
12 Correct 2 ms 376 KB Output is correct
13 Correct 2 ms 376 KB Output is correct
14 Correct 2 ms 376 KB Output is correct
15 Correct 2 ms 376 KB Output is correct
16 Correct 7 ms 1400 KB Output is correct
17 Correct 10 ms 1528 KB Output is correct
18 Correct 9 ms 1500 KB Output is correct
19 Correct 10 ms 1580 KB Output is correct
20 Correct 8 ms 1400 KB Output is correct
21 Correct 12 ms 1656 KB Output is correct
22 Correct 11 ms 1784 KB Output is correct
23 Correct 11 ms 1656 KB Output is correct
24 Correct 10 ms 1528 KB Output is correct
25 Correct 11 ms 1656 KB Output is correct
26 Correct 11 ms 1656 KB Output is correct
27 Correct 16 ms 1656 KB Output is correct
28 Correct 12 ms 1656 KB Output is correct
29 Correct 674 ms 19808 KB Output is correct
30 Correct 761 ms 20984 KB Output is correct
31 Correct 777 ms 21108 KB Output is correct
32 Correct 662 ms 20984 KB Output is correct
33 Correct 700 ms 18296 KB Output is correct
34 Correct 743 ms 20728 KB Output is correct
35 Correct 1122 ms 24096 KB Output is correct
36 Correct 1004 ms 49880 KB Output is correct
37 Correct 1193 ms 54208 KB Output is correct