結果

問題 No.2157 崖
ユーザー ygd.ygd.
提出日時 2022-12-14 23:44:52
言語 PyPy3
(7.3.15)
結果
TLE  
実行時間 -
コード長 3,240 bytes
コンパイル時間 400 ms
コンパイル使用メモリ 82,304 KB
実行使用メモリ 218,752 KB
最終ジャッジ日時 2024-11-08 16:14:15
合計ジャッジ時間 11,348 ms
ジャッジサーバーID
(参考情報)
judge1 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 47 ms
54,528 KB
testcase_01 AC 50 ms
55,552 KB
testcase_02 AC 47 ms
54,912 KB
testcase_03 AC 57 ms
62,976 KB
testcase_04 AC 46 ms
55,040 KB
testcase_05 AC 68 ms
66,944 KB
testcase_06 AC 49 ms
54,912 KB
testcase_07 AC 96 ms
76,416 KB
testcase_08 AC 50 ms
55,424 KB
testcase_09 AC 58 ms
63,104 KB
testcase_10 AC 48 ms
54,656 KB
testcase_11 AC 82 ms
71,680 KB
testcase_12 AC 48 ms
55,168 KB
testcase_13 TLE -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
testcase_20 -- -
testcase_21 -- -
testcase_22 -- -
testcase_23 -- -
testcase_24 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #
プレゼンテーションモードにする

import sys
#input = sys.stdin.readline
#input = sys.stdin.buffer.readline #
sys.setrecursionlimit(1000000)
import math
import bisect
#import itertools
#import random
#from heapq import heapify, heappop, heappush
from collections import defaultdict
from collections import deque
#import copy #DeepCopy: hoge = [_[:] for _ in hogehoge]
#from functools import lru_cache
#@lru_cache(maxsize=None)
#MOD = pow(10,9) + 7
MOD = 998244353
#dx = [1,0,-1,0]
#dy = [0,1,0,-1]
#dx8 = [1,1,0,-1,-1,-1,0,1]
#dy8 = [0,1,1,1,0,-1,-1,-1]
class SegmentTree(object):
def __init__(self, A, dot, unit):
n = 1 << (len(A) - 1).bit_length()
tree = [unit] * (2 * n)
for i, v in enumerate(A):
tree[i + n] = v
for i in range(n - 1, 0, -1):
tree[i] = dot(tree[i << 1], tree[i << 1 | 1])
self._n = n
self._tree = tree
self._dot = dot
self._unit = unit
def __getitem__(self, i):
return self._tree[i + self._n]
def update(self, i, v):
i += self._n
self._tree[i] = v
while i != 1:
i >>= 1
self._tree[i] = self._dot(self._tree[i << 1], self._tree[i << 1 | 1])
def add(self, i, v):
self.update(i, self[i] + v)
def sum(self, l, r): #[l,r)
l += self._n
r += self._n
l_val = r_val = self._unit
while l < r:
if l & 1:
l_val = self._dot(l_val, self._tree[l])
l += 1
if r & 1:
r -= 1
r_val = self._dot(self._tree[r], r_val)
l >>= 1
r >>= 1
return self._dot(l_val, r_val)
def main():
N,M = map(int,input().split()); INF = 1<<60
D = [list(map(int,input().split())) for _ in range(N)]
for i in range(N):
D[i].sort()
def check(x):
Tree = SegmentTree([x]*M,min,INF)
for i in range(1,N):
# output
# output = [Tree[j] for j in range(M)]
# print("output",output)
NTree = SegmentTree([INF]*M,min,INF)
preDi = [-INF] + D[i-1]
# print(preDi)
left = 0; right = 0
for j in range(M):
# left = bisect.bisect_left(preDi,D[i][j] - x)
# right = bisect.bisect_right(preDi,D[i][j])
while left < M+1 and preDi[left] < D[i][j] - x:
left += 1
while right < M+1 and preDi[right] <= D[i][j]:
right += 1
val = Tree.sum(left-1, right-1)
# print(left,right,val)
if val <= x:
NTree.update(j,x)
NTree,Tree = Tree,NTree
# output = [Tree[j] for j in range(M)]
# print("output",output)
# print("handan",Tree.sum(0,M))
if Tree.sum(0,M) <= x:
return True
else:
return False
ok = pow(10,9)
ng = -1
while abs(ok-ng) > 1:
mid = (ok+ng)//2
if check(mid):
ok = mid
else:
ng = mid
if ok == pow(10,9):
print(-1)
else:
print(ok)
if __name__ == '__main__':
main()
הההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההה
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
0