結果

問題 No.844 split game
ユーザー 双六双六
提出日時 2020-07-15 23:08:51
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 1,350 bytes
コンパイル時間 389 ms
コンパイル使用メモリ 82,140 KB
実行使用メモリ 93,736 KB
最終ジャッジ日時 2024-05-02 05:04:20
合計ジャッジ時間 20,867 ms
ジャッジサーバーID
(参考情報)
judge4 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 WA -
testcase_02 WA -
testcase_03 WA -
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
testcase_22 WA -
testcase_23 WA -
testcase_24 WA -
testcase_25 WA -
testcase_26 WA -
testcase_27 WA -
testcase_28 WA -
testcase_29 WA -
testcase_30 WA -
testcase_31 WA -
testcase_32 WA -
testcase_33 AC 191 ms
79,212 KB
testcase_34 WA -
testcase_35 AC 189 ms
79,268 KB
testcase_36 AC 160 ms
78,080 KB
testcase_37 AC 221 ms
80,128 KB
testcase_38 AC 254 ms
82,284 KB
testcase_39 AC 624 ms
88,768 KB
testcase_40 AC 196 ms
80,768 KB
testcase_41 WA -
testcase_42 AC 49 ms
53,888 KB
testcase_43 AC 47 ms
53,504 KB
testcase_44 AC 50 ms
54,016 KB
testcase_45 WA -
testcase_46 AC 46 ms
53,632 KB
testcase_47 WA -
testcase_48 AC 44 ms
53,468 KB
testcase_49 WA -
testcase_50 WA -
testcase_51 WA -
testcase_52 WA -
testcase_53 WA -
testcase_54 WA -
testcase_55 AC 44 ms
53,616 KB
testcase_56 AC 44 ms
53,760 KB
testcase_57 AC 45 ms
54,144 KB
testcase_58 AC 43 ms
54,016 KB
testcase_59 AC 45 ms
54,016 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 = [0] * (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 = 0
		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)
	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