結果

問題 No.33 アメーバがたくさん
ユーザー cielciel
提出日時 2015-10-29 01:47:19
言語 PyPy2
(7.3.15)
結果
AC  
実行時間 78 ms / 5,000 ms
コード長 1,295 bytes
コンパイル時間 1,516 ms
コンパイル使用メモリ 77,148 KB
実行使用メモリ 77,972 KB
最終ジャッジ日時 2023-10-24 17:54:34
合計ジャッジ時間 3,009 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 76 ms
77,972 KB
testcase_01 AC 77 ms
77,972 KB
testcase_02 AC 76 ms
77,972 KB
testcase_03 AC 76 ms
77,972 KB
testcase_04 AC 76 ms
77,972 KB
testcase_05 AC 76 ms
77,972 KB
testcase_06 AC 76 ms
77,972 KB
testcase_07 AC 76 ms
77,972 KB
testcase_08 AC 78 ms
77,972 KB
testcase_09 AC 77 ms
77,972 KB
testcase_10 AC 78 ms
77,972 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
    if sys.version_info[0]>=3: raw_input=input
    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)//d-t,(e)//d+t))
    print(sum(checkio(v) for k,v in dic.items()))
0