結果

問題 No.33 アメーバがたくさん
ユーザー cielciel
提出日時 2014-11-28 15:22:46
言語 Python2
(2.7.18)
結果
AC  
実行時間 12 ms / 5,000 ms
コード長 1,105 bytes
コンパイル時間 540 ms
コンパイル使用メモリ 7,100 KB
実行使用メモリ 6,800 KB
最終ジャッジ日時 2023-10-24 17:42:52
合計ジャッジ時間 1,326 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 12 ms
6,800 KB
testcase_01 AC 12 ms
6,800 KB
testcase_02 AC 12 ms
6,800 KB
testcase_03 AC 12 ms
6,800 KB
testcase_04 AC 11 ms
6,800 KB
testcase_05 AC 12 ms
6,800 KB
testcase_06 AC 11 ms
6,800 KB
testcase_07 AC 11 ms
6,800 KB
testcase_08 AC 11 ms
6,800 KB
testcase_09 AC 12 ms
6,800 KB
testcase_10 AC 12 ms
6,800 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#!/usr/bin/python
#coding:utf-8
#derived from checkio painting-wall (presented by me)
#http://www.checkio.org/mission/painting-wall/share/8a0e0061de3ff95664776d904d309e57/
import bisect

def checkio(data):
	ret_idx=0
	result=0
	se=[]
	for l,r in data:
		ret_idx+=1
		right_idx=bisect.bisect_left(se,(l,0)) #l <= se[right_idx][0]
		if right_idx!=0:
			left_idx=right_idx-1
			if l<=se[left_idx][1]: # overlap with left
				l=se[left_idx][0]
				r=max(r,se[left_idx][1])
				result-=se[left_idx][1]-se[left_idx][0]+1
				se.pop(left_idx)
				right_idx-=1
		while right_idx<len(se) and se[right_idx][0]<=r: # overlap with right
			r=max(r,se[right_idx][1])
			result-=se[right_idx][1]-se[right_idx][0]+1
			se.pop(right_idx)
		result+=r-l+1
		se.insert(right_idx,(l,r))
	return result

if __name__ == '__main__':
	from collections import defaultdict
	import sys
	dic=defaultdict(list)
	n,d,t=[int(e) for e in raw_input().split()]
	for e in map(int,raw_input().split()):
		mod=e%d
		dic[mod].append(((e-mod)/d-t,(e-mod)/d+t))
	print(sum(checkio(v) for k,v in dic.items()))
0