結果

問題 No.844 split game
ユーザー 双六双六
提出日時 2020-07-15 23:12:16
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 1,021 ms / 2,000 ms
コード長 1,374 bytes
コンパイル時間 742 ms
コンパイル使用メモリ 82,432 KB
実行使用メモリ 98,976 KB
最終ジャッジ日時 2024-05-02 05:09:55
合計ジャッジ時間 23,149 ms
ジャッジサーバーID
(参考情報)
judge1 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 494 ms
85,012 KB
testcase_01 AC 386 ms
84,924 KB
testcase_02 AC 723 ms
91,932 KB
testcase_03 AC 575 ms
88,200 KB
testcase_04 AC 433 ms
84,220 KB
testcase_05 AC 998 ms
98,976 KB
testcase_06 AC 410 ms
84,224 KB
testcase_07 AC 317 ms
84,580 KB
testcase_08 AC 239 ms
81,716 KB
testcase_09 AC 616 ms
88,832 KB
testcase_10 AC 864 ms
93,312 KB
testcase_11 AC 1,021 ms
98,884 KB
testcase_12 AC 612 ms
88,540 KB
testcase_13 AC 488 ms
85,120 KB
testcase_14 AC 453 ms
83,808 KB
testcase_15 AC 859 ms
93,508 KB
testcase_16 AC 974 ms
96,744 KB
testcase_17 AC 793 ms
96,464 KB
testcase_18 AC 804 ms
93,504 KB
testcase_19 AC 832 ms
94,736 KB
testcase_20 AC 785 ms
94,016 KB
testcase_21 AC 858 ms
95,168 KB
testcase_22 AC 824 ms
95,600 KB
testcase_23 AC 132 ms
77,696 KB
testcase_24 AC 203 ms
79,512 KB
testcase_25 AC 147 ms
77,952 KB
testcase_26 AC 112 ms
78,000 KB
testcase_27 AC 168 ms
79,292 KB
testcase_28 AC 84 ms
76,544 KB
testcase_29 AC 164 ms
78,848 KB
testcase_30 AC 190 ms
79,744 KB
testcase_31 AC 170 ms
79,232 KB
testcase_32 AC 95 ms
76,784 KB
testcase_33 AC 170 ms
78,352 KB
testcase_34 AC 138 ms
78,764 KB
testcase_35 AC 177 ms
79,488 KB
testcase_36 AC 155 ms
78,364 KB
testcase_37 AC 221 ms
79,836 KB
testcase_38 AC 381 ms
83,472 KB
testcase_39 AC 654 ms
89,400 KB
testcase_40 AC 318 ms
82,088 KB
testcase_41 AC 43 ms
53,504 KB
testcase_42 AC 44 ms
54,136 KB
testcase_43 AC 43 ms
54,016 KB
testcase_44 AC 45 ms
53,504 KB
testcase_45 AC 44 ms
53,760 KB
testcase_46 AC 47 ms
53,760 KB
testcase_47 AC 45 ms
53,820 KB
testcase_48 AC 47 ms
53,376 KB
testcase_49 AC 49 ms
53,760 KB
testcase_50 AC 45 ms
54,144 KB
testcase_51 AC 48 ms
53,632 KB
testcase_52 AC 48 ms
54,272 KB
testcase_53 AC 49 ms
53,760 KB
testcase_54 AC 45 ms
53,760 KB
testcase_55 AC 46 ms
54,272 KB
testcase_56 AC 48 ms
53,632 KB
testcase_57 AC 47 ms
54,240 KB
testcase_58 AC 44 ms
54,272 KB
testcase_59 AC 44 ms
54,272 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys; input = sys.stdin.buffer.readline
sys.setrecursionlimit(10**7)
from collections import defaultdict
con = 10 ** 9 + 7; INF = float("inf")

def getlist():
	return list(map(int, input().split()))

class SegmentTree(object):
	#N:処理する区間の長さ
	def __init__(self, N):
		self.N0 = 2 ** (N - 1).bit_length()
		self.data = [-INF] * (2 * self.N0)

	#k番目の値をxに更新
	def update(self, k, x):
		k += self.N0 - 1
		self.data[k] = x
		while k > 0:
			k = (k - 1) // 2
			self.data[k] = max(self.data[2 * k + 1], self.data[2 * k + 2])

	#区間[l, r]の最大値
	def query(self, l, r):
		L = l + self.N0; R = r + self.N0 + 1
		m = -INF
		while L < R:
			if R & 1:
				R -= 1
				m = max(m, self.data[R - 1])
			if L & 1:
				m = max(m, self.data[L - 1])
				L += 1
			L >>= 1; R >>= 1

		return m

#処理内容
def main():
	N, M, A = getlist()
	line = []
	for i in range(M):
		l, r, p = getlist()
		line.append([r, l, p])
	line.sort()
	
	# セグ木でDP
	Seg = SegmentTree(N + 2)
	Seg.update(0, 0)
	for i in range(M):
		r, l, p = line[i]
		if r != N:
			newScore = max(Seg.query(0, l - 1) - 2 * A + p, Seg.query(l - 1, l - 1) - A + p, Seg.query(r, r))
		else:
			newScore = max(Seg.query(0, l - 1) - A + p, Seg.query(l - 1, l - 1) + p, Seg.query(r, r))
		Seg.update(r, newScore)

	ans = max(Seg.data)
	print(ans)

if __name__ == '__main__':
	main()
0