Submission #50284

# Submission time Handle Problem Language Result Execution time Memory
50284 2018-06-09T07:59:40 Z 강태규(#1282, imeimi2000) The Kingdom of JOIOI (JOI17_joioi) C++11
100 / 100
878 ms 47680 KB
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <unordered_map>
#include <functional>
#include <cstring>
#include <cmath>
#include <ctime>
#include <cstdlib>

using namespace std;
typedef long long llong;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<llong, llong> pll;

const int inf = 1e9 + 7;
int h, w, mx = -1, mn = inf;
int a[3001][3001];
int b[3001][3001];

int check(int g[3001][3001], int x) {
    int tmn, tmx, inc = -1, dec = w;
    for (int i = 0; i < h; ++i) {
        for (tmx = 0; tmx < w; ++tmx) {
            if (x < mx - g[i][tmx]) break;
        }
        --tmx;
        
        for (tmn = w; tmn--; ) {
            if (x < g[i][tmn] - mn) break;
        }
        
        
        if (tmx < tmn) return 0;
        
        if (inc != -2) {
            if (tmx < inc) inc = -2;
            else inc = max(inc, tmn);
        }
        
        if (dec != -2) {
            if (dec < tmn) dec = -2;
            else dec = min(dec, tmx);
        }
        
        if (inc == -2 && dec == -2) return 0;
    }
    return 1;
}

int main() {
    scanf("%d%d", &h, &w);
    for (int i = 0; i < h; ++i) {
        for (int j = 0; j < w; ++j) {
            scanf("%d", a[i] + j);
            b[i][w - j - 1] = a[i][j];
            mx = max(mx, a[i][j]);
            mn = min(mn, a[i][j]);
        }
    }
    int s = 0, e = mx - mn;
    for (int i = 0; i < h; ++i) {
        for (int j = 0; j < w; ++j) {
            s = max(s, min(mx - a[i][j], a[i][j] - mn));
        }
    }
    while (s < e) {
        int m = (s + e) / 2;
        if (check(a, m) || check(b, m)) e = m;
        else s = m + 1;
    }
    printf("%d\n", s);
	return 0;
}

Compilation message

joioi.cpp: In function 'int main()':
joioi.cpp:57:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d%d", &h, &w);
     ~~~~~^~~~~~~~~~~~~~~~
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 3 ms 376 KB Output is correct
2 Correct 3 ms 484 KB Output is correct
3 Correct 3 ms 560 KB Output is correct
4 Correct 3 ms 560 KB Output is correct
5 Correct 2 ms 664 KB Output is correct
6 Correct 2 ms 664 KB Output is correct
7 Correct 2 ms 664 KB Output is correct
8 Correct 2 ms 664 KB Output is correct
9 Correct 2 ms 664 KB Output is correct
10 Correct 2 ms 664 KB Output is correct
11 Correct 2 ms 676 KB Output is correct
12 Correct 2 ms 676 KB Output is correct
13 Correct 2 ms 676 KB Output is correct
14 Correct 2 ms 676 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 376 KB Output is correct
2 Correct 3 ms 484 KB Output is correct
3 Correct 3 ms 560 KB Output is correct
4 Correct 3 ms 560 KB Output is correct
5 Correct 2 ms 664 KB Output is correct
6 Correct 2 ms 664 KB Output is correct
7 Correct 2 ms 664 KB Output is correct
8 Correct 2 ms 664 KB Output is correct
9 Correct 2 ms 664 KB Output is correct
10 Correct 2 ms 664 KB Output is correct
11 Correct 2 ms 676 KB Output is correct
12 Correct 2 ms 676 KB Output is correct
13 Correct 2 ms 676 KB Output is correct
14 Correct 2 ms 676 KB Output is correct
15 Correct 2 ms 676 KB Output is correct
16 Correct 7 ms 2428 KB Output is correct
17 Correct 10 ms 2428 KB Output is correct
18 Correct 11 ms 2428 KB Output is correct
19 Correct 11 ms 2428 KB Output is correct
20 Correct 11 ms 2428 KB Output is correct
21 Correct 12 ms 2428 KB Output is correct
22 Correct 11 ms 2448 KB Output is correct
23 Correct 13 ms 2448 KB Output is correct
24 Correct 10 ms 2448 KB Output is correct
25 Correct 11 ms 2448 KB Output is correct
26 Correct 12 ms 2448 KB Output is correct
27 Correct 12 ms 2448 KB Output is correct
28 Correct 12 ms 2448 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 376 KB Output is correct
2 Correct 3 ms 484 KB Output is correct
3 Correct 3 ms 560 KB Output is correct
4 Correct 3 ms 560 KB Output is correct
5 Correct 2 ms 664 KB Output is correct
6 Correct 2 ms 664 KB Output is correct
7 Correct 2 ms 664 KB Output is correct
8 Correct 2 ms 664 KB Output is correct
9 Correct 2 ms 664 KB Output is correct
10 Correct 2 ms 664 KB Output is correct
11 Correct 2 ms 676 KB Output is correct
12 Correct 2 ms 676 KB Output is correct
13 Correct 2 ms 676 KB Output is correct
14 Correct 2 ms 676 KB Output is correct
15 Correct 2 ms 676 KB Output is correct
16 Correct 7 ms 2428 KB Output is correct
17 Correct 10 ms 2428 KB Output is correct
18 Correct 11 ms 2428 KB Output is correct
19 Correct 11 ms 2428 KB Output is correct
20 Correct 11 ms 2428 KB Output is correct
21 Correct 12 ms 2428 KB Output is correct
22 Correct 11 ms 2448 KB Output is correct
23 Correct 13 ms 2448 KB Output is correct
24 Correct 10 ms 2448 KB Output is correct
25 Correct 11 ms 2448 KB Output is correct
26 Correct 12 ms 2448 KB Output is correct
27 Correct 12 ms 2448 KB Output is correct
28 Correct 12 ms 2448 KB Output is correct
29 Correct 696 ms 45276 KB Output is correct
30 Correct 572 ms 45828 KB Output is correct
31 Correct 628 ms 47640 KB Output is correct
32 Correct 685 ms 47680 KB Output is correct
33 Correct 784 ms 47680 KB Output is correct
34 Correct 654 ms 47680 KB Output is correct
35 Correct 856 ms 47680 KB Output is correct
36 Correct 803 ms 47680 KB Output is correct
37 Correct 878 ms 47680 KB Output is correct