結果

問題 No.1077 Noelちゃんと星々4
ユーザー 双六双六
提出日時 2020-08-26 08:50:13
言語 PyPy3
(7.3.15)
結果
TLE  
実行時間 -
コード長 1,416 bytes
コンパイル時間 167 ms
コンパイル使用メモリ 82,432 KB
実行使用メモリ 109,824 KB
最終ジャッジ日時 2024-04-24 14:38:35
合計ジャッジ時間 25,693 ms
ジャッジサーバーID
(参考情報)
judge5 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 99 ms
76,672 KB
testcase_01 AC 114 ms
77,312 KB
testcase_02 AC 1,692 ms
100,864 KB
testcase_03 TLE -
testcase_04 AC 726 ms
85,632 KB
testcase_05 AC 569 ms
82,304 KB
testcase_06 AC 904 ms
89,856 KB
testcase_07 AC 1,095 ms
92,032 KB
testcase_08 AC 788 ms
87,040 KB
testcase_09 AC 676 ms
84,480 KB
testcase_10 TLE -
testcase_11 AC 1,413 ms
97,920 KB
testcase_12 AC 1,184 ms
94,976 KB
testcase_13 AC 529 ms
82,048 KB
testcase_14 TLE -
testcase_15 AC 1,174 ms
94,720 KB
testcase_16 AC 796 ms
87,424 KB
testcase_17 AC 1,285 ms
96,256 KB
testcase_18 TLE -
testcase_19 AC 524 ms
81,536 KB
testcase_20 AC 60 ms
67,456 KB
testcase_21 TLE -
権限があれば一括ダウンロードができます

ソースコード

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):
	def __init__(self, N):
		self.N = N
		self.N0 = 2 ** (N - 1).bit_length()
		self.initVal = INF
		self.data = [self.initVal] * (2 * self.N0)

	def calc(self, a, b):
		return min(a, b)

	def initialize(self, A):
		for i in range(self.N):
			self.data[self.N0 - 1 + i] = A[i]
		for i in range(self.N0 - 2, -1, -1):
			self.data[i] = self.calc(self.data[2 * i + 1], self.data[2 * i + 2])

	def update(self, k, x):
		k += self.N0 - 1
		self.data[k] = x
		while k > 0:
			k = (k - 1) // 2
			self.data[k] = self.calc(self.data[2 * k + 1], self.data[2 * k + 2])

	def query(self, l, r):
		L = l + self.N0; R = r + self.N0 + 1
		m = self.initVal
		while L < R:
			if R & 1:
				R -= 1
				m = self.calc(m, self.data[R - 1])
			if L & 1:
				m = self.calc(m, self.data[L - 1])
				L += 1
			L >>= 1; R >>= 1

		return m

#処理内容
def main():
	N = int(input())
	Y = getlist()
	Seg = SegmentTree(10001)
	for i in range(Y[0] + 1):
		Seg.update(i, Y[0] - i)

	for i in range(1, N):
		DP = [INF] * 10001
		y = Y[i]
		for j in range(10001):
			DP[j] = Seg.query(0, j) + abs(y - j)
		# print(DP)

		Seg.initialize(DP)

	ans = Seg.query(0, 10001)
	print(ans)

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