提出 #76658607
ソースコード 拡げる
n, d = map(int, input().split())
events = []
for _ in range(n):
s, t = map(int, input().split())
l = s
r = t - d
if l <= r:
events.append((l, 1))
events.append((r + 1, -1))
events.sort()
ans = 0
cur_c = 0
i = 0
events_num = len(events)
while i < events_num:
j = i
while j < events_num and events[j][0] == events[i][0]:
cur_c += events[j][1]
j += 1
if j < events_num:
length = events[j][0] - events[i][0]
if cur_c >= 2:
pairs = cur_c * (cur_c - 1) // 2
ans += length * pairs
i = j
print(ans)
提出情報
| 提出日時 | |
|---|---|
| 問題 | D - Accomplice |
| ユーザ | gett |
| 言語 | Python (PyPy 3.11-v7.3.20) |
| 得点 | 400 |
| コード長 | 671 Byte |
| 結果 | AC |
| 実行時間 | 857 ms |
| メモリ | 137052 KiB |
ジャッジ結果
| セット名 | Sample | All | ||||
|---|---|---|---|---|---|---|
| 得点 / 配点 | 0 / 0 | 400 / 400 | ||||
| 結果 |
|
|
| セット名 | テストケース |
|---|---|
| Sample | sample-01.txt, sample-02.txt, sample-03.txt |
| All | 04.txt, 05.txt, 06.txt, 07.txt, 08.txt, 09.txt, 10.txt, 11.txt, 12.txt, 13.txt, 14.txt, 15.txt, 16.txt, 17.txt, 18.txt, 19.txt, 20.txt, 21.txt, 22.txt, 23.txt, sample-01.txt, sample-02.txt, sample-03.txt |
| ケース名 | 結果 | 実行時間 | メモリ |
|---|---|---|---|
| 04.txt | AC | 56 ms | 79088 KiB |
| 05.txt | AC | 56 ms | 79132 KiB |
| 06.txt | AC | 419 ms | 133160 KiB |
| 07.txt | AC | 419 ms | 133044 KiB |
| 08.txt | AC | 255 ms | 108144 KiB |
| 09.txt | AC | 256 ms | 108316 KiB |
| 10.txt | AC | 252 ms | 108304 KiB |
| 11.txt | AC | 56 ms | 79620 KiB |
| 12.txt | AC | 69 ms | 92276 KiB |
| 13.txt | AC | 91 ms | 108668 KiB |
| 14.txt | AC | 235 ms | 112652 KiB |
| 15.txt | AC | 584 ms | 125496 KiB |
| 16.txt | AC | 309 ms | 110824 KiB |
| 17.txt | AC | 857 ms | 135088 KiB |
| 18.txt | AC | 856 ms | 135080 KiB |
| 19.txt | AC | 264 ms | 108088 KiB |
| 20.txt | AC | 825 ms | 134452 KiB |
| 21.txt | AC | 819 ms | 134868 KiB |
| 22.txt | AC | 816 ms | 137052 KiB |
| 23.txt | AC | 800 ms | 132784 KiB |
| sample-01.txt | AC | 56 ms | 79088 KiB |
| sample-02.txt | AC | 56 ms | 79088 KiB |
| sample-03.txt | AC | 55 ms | 78920 KiB |