답안 #590407

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
590407 2022-07-05T22:21:29 Z dnialh The Kingdom of JOIOI (JOI17_joioi) PyPy 3
60 / 100
1154 ms 262144 KB
import sys as sus
input = sus.stdin.readline

from bisect import bisect_right as bi

h, w = map(int, input().split())

'''
def rot(b):
    bb = b[::-1]

    nb = []
    for i in range(len(bb[0])):
        curr = []
        for l in bb:
            curr.append(l[i])
        nb.append(curr)
        
    global w, h
    w, h = h, w
    
    return nb'''

board = [list(map(int, input().split())) for _ in range(h)]

smol = min(min(l) for l in board)

for l in board:
    for i in range(w):
        l[i] -= smol

tol = max(max(l) for l in board)

#


out = []
for _ in range(4):
    lo = -1
    hi = tol

    pref_max = []
    suff_min = []
    
    for i in range(h):
        pf = [0]
        for j in range(w):
            if _ == 0:
                v = board[i][j]
            elif _ == 1:
                v = board[~i][j]
            elif _ == 2:
                v = board[~i][~j]
            else:
                v = board[i][~j]
            pf.append(max(pf[-1], v))
        pref_max.append(pf)

        suff = [1000000000]
        for j in range(w - 1, -1, -1):
            if _ == 0:
                v = board[i][j]
            elif _ == 1:
                v = board[~i][j]
            elif _ == 2:
                v = board[~i][~j]
            else:
                v = board[i][~j]
            suff.append(min(suff[-1], v))
        suff_min.append(suff)
            
    
    while hi - lo > 1:
        test = (lo + hi) // 2
        
        far = w
        good = True
        
        for i in range(h):
            ind = bi(pref_max[i], test) - 1
            far = min(ind, far)
            ot = suff_min[i][w - far]
            
            #if test == 8:
            #    print(i, ind, far, ot)
            
            if ot < tol - test:
                good = False
                break

        if good:
            hi = test
        else:
            lo = test

    out.append(hi)

    #board = rot(board)
    #w, h = h, w

print(min(out))
# 결과 실행 시간 메모리 Grader output
1 Correct 39 ms 18216 KB Output is correct
2 Correct 35 ms 18184 KB Output is correct
3 Correct 42 ms 18736 KB Output is correct
4 Correct 41 ms 18724 KB Output is correct
5 Correct 42 ms 18988 KB Output is correct
6 Correct 43 ms 18796 KB Output is correct
7 Correct 43 ms 18948 KB Output is correct
8 Correct 42 ms 18812 KB Output is correct
9 Correct 42 ms 18744 KB Output is correct
10 Correct 41 ms 18800 KB Output is correct
11 Correct 42 ms 18876 KB Output is correct
12 Correct 42 ms 18900 KB Output is correct
13 Correct 45 ms 19000 KB Output is correct
14 Correct 48 ms 18832 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 39 ms 18216 KB Output is correct
2 Correct 35 ms 18184 KB Output is correct
3 Correct 42 ms 18736 KB Output is correct
4 Correct 41 ms 18724 KB Output is correct
5 Correct 42 ms 18988 KB Output is correct
6 Correct 43 ms 18796 KB Output is correct
7 Correct 43 ms 18948 KB Output is correct
8 Correct 42 ms 18812 KB Output is correct
9 Correct 42 ms 18744 KB Output is correct
10 Correct 41 ms 18800 KB Output is correct
11 Correct 42 ms 18876 KB Output is correct
12 Correct 42 ms 18900 KB Output is correct
13 Correct 45 ms 19000 KB Output is correct
14 Correct 48 ms 18832 KB Output is correct
15 Correct 68 ms 21448 KB Output is correct
16 Correct 94 ms 25176 KB Output is correct
17 Correct 116 ms 26556 KB Output is correct
18 Correct 126 ms 26224 KB Output is correct
19 Correct 136 ms 26224 KB Output is correct
20 Correct 121 ms 26620 KB Output is correct
21 Correct 123 ms 25868 KB Output is correct
22 Correct 126 ms 26156 KB Output is correct
23 Correct 134 ms 26192 KB Output is correct
24 Correct 132 ms 26536 KB Output is correct
25 Correct 133 ms 26068 KB Output is correct
26 Correct 127 ms 26124 KB Output is correct
27 Correct 123 ms 26012 KB Output is correct
28 Correct 121 ms 26616 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 39 ms 18216 KB Output is correct
2 Correct 35 ms 18184 KB Output is correct
3 Correct 42 ms 18736 KB Output is correct
4 Correct 41 ms 18724 KB Output is correct
5 Correct 42 ms 18988 KB Output is correct
6 Correct 43 ms 18796 KB Output is correct
7 Correct 43 ms 18948 KB Output is correct
8 Correct 42 ms 18812 KB Output is correct
9 Correct 42 ms 18744 KB Output is correct
10 Correct 41 ms 18800 KB Output is correct
11 Correct 42 ms 18876 KB Output is correct
12 Correct 42 ms 18900 KB Output is correct
13 Correct 45 ms 19000 KB Output is correct
14 Correct 48 ms 18832 KB Output is correct
15 Correct 68 ms 21448 KB Output is correct
16 Correct 94 ms 25176 KB Output is correct
17 Correct 116 ms 26556 KB Output is correct
18 Correct 126 ms 26224 KB Output is correct
19 Correct 136 ms 26224 KB Output is correct
20 Correct 121 ms 26620 KB Output is correct
21 Correct 123 ms 25868 KB Output is correct
22 Correct 126 ms 26156 KB Output is correct
23 Correct 134 ms 26192 KB Output is correct
24 Correct 132 ms 26536 KB Output is correct
25 Correct 133 ms 26068 KB Output is correct
26 Correct 127 ms 26124 KB Output is correct
27 Correct 123 ms 26012 KB Output is correct
28 Correct 121 ms 26616 KB Output is correct
29 Correct 934 ms 215524 KB Output is correct
30 Correct 899 ms 241832 KB Output is correct
31 Correct 1020 ms 240828 KB Output is correct
32 Correct 999 ms 248944 KB Output is correct
33 Correct 927 ms 254172 KB Output is correct
34 Correct 952 ms 243368 KB Output is correct
35 Correct 1154 ms 262144 KB Output is correct
36 Correct 985 ms 227944 KB Output is correct
37 Runtime error 1110 ms 262144 KB Execution killed with signal 9
38 Halted 0 ms 0 KB -