結果

問題 No.33 アメーバがたくさん
ユーザー kohei2019kohei2019
提出日時 2021-02-13 11:23:48
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 41 ms / 5,000 ms
コード長 717 bytes
コンパイル時間 520 ms
コンパイル使用メモリ 82,304 KB
実行使用メモリ 54,016 KB
最終ジャッジ日時 2024-07-20 14:15:01
合計ジャッジ時間 1,436 ms
ジャッジサーバーID
(参考情報)
judge3 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 11
権限があれば一括ダウンロードができます

ソースコード

diff #

import collections
N,D,T = map(int,input().split())
lsx = list(map(int,input().split()))
#x-T*D,x+T*DにD置きに存在modDと範囲が分かれば答えが求まる
lsmod = [i%D for i in lsx]
dic = collections.defaultdict(lambda : [])
for i in range(N):
    dic[lsmod[i]].append(lsx[i])
ans = 0
for key in dic.keys():
    ls = dic[key]
    if len(ls) == 1:
        ans += 2*T+1
        continue
    ls.sort()
    l1 = ls[0]-T*D
    r1 = ls[0]+T*D
    lslr = [[l1,r1]]
    for i in range(1,len(ls)):
        l2 = ls[i]-T*D
        r2 = ls[i]+T*D
        if l2 <= lslr[-1][1]:
            lslr[-1][1] = r2
        else:
            lslr.append([l2,r2])
    for lr in lslr:
        ans += (lr[1]-lr[0])//D+1
print(ans)
0