結果
問題 |
No.1110 好きな歌
|
ユーザー |
👑 ![]() |
提出日時 | 2020-07-10 21:49:13 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 308 ms / 5,000 ms |
コード長 | 827 bytes |
コンパイル時間 | 259 ms |
コンパイル使用メモリ | 82,220 KB |
実行使用メモリ | 84,904 KB |
最終ジャッジ日時 | 2024-10-11 08:50:07 |
合計ジャッジ時間 | 10,844 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 51 |
ソースコード
def Binary_Search_Count(A,x,sort=True,equal=False): """2分探索によって,x未満の要素の個数を調べる. A:リスト x:調べる要素 sort:ソートをする必要があるかどうか(Trueで必要) equal:Trueのときはx"未満"がx"以下"になる """ if sort: A.sort() N=len(A) if A[-1]<=x: return N elif x<A[0] or (not equal and x==A[0]): return 0 L,R=0,N while R-L>1: C=L+(R-L)//2 if x<A[C] or (not equal and x==A[C]): R=C else: L=C return R #-------------------------------------------------------------- N,D=map(int,input().split()) A=[] for _ in range(N): A.append(int(input())) B=sorted(A) for a in A: print(Binary_Search_Count(B,a-D,sort=False,equal=True))