結果

問題 No.448 ゆきこーだーの雨と雪 (3)
ユーザー tktk_snsntktk_snsn
提出日時 2021-02-25 00:55:12
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 1,637 bytes
コンパイル時間 173 ms
コンパイル使用メモリ 81,824 KB
実行使用メモリ 183,484 KB
最終ジャッジ日時 2023-10-25 06:18:31
合計ジャッジ時間 14,517 ms
ジャッジサーバーID
(参考情報)
judge15 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 40 ms
53,588 KB
testcase_01 AC 40 ms
53,588 KB
testcase_02 AC 40 ms
53,588 KB
testcase_03 AC 40 ms
53,588 KB
testcase_04 AC 52 ms
64,080 KB
testcase_05 AC 53 ms
64,084 KB
testcase_06 AC 59 ms
68,184 KB
testcase_07 AC 53 ms
64,084 KB
testcase_08 WA -
testcase_09 AC 56 ms
66,132 KB
testcase_10 AC 48 ms
62,012 KB
testcase_11 AC 56 ms
66,132 KB
testcase_12 WA -
testcase_13 AC 221 ms
89,812 KB
testcase_14 AC 192 ms
94,424 KB
testcase_15 AC 305 ms
126,524 KB
testcase_16 WA -
testcase_17 AC 342 ms
160,664 KB
testcase_18 AC 172 ms
85,004 KB
testcase_19 WA -
testcase_20 AC 256 ms
114,792 KB
testcase_21 AC 518 ms
177,416 KB
testcase_22 AC 282 ms
115,876 KB
testcase_23 AC 553 ms
177,676 KB
testcase_24 WA -
testcase_25 AC 517 ms
175,620 KB
testcase_26 WA -
testcase_27 AC 459 ms
158,988 KB
testcase_28 WA -
testcase_29 AC 300 ms
121,696 KB
testcase_30 WA -
testcase_31 AC 171 ms
89,724 KB
testcase_32 AC 158 ms
93,956 KB
testcase_33 WA -
testcase_34 AC 531 ms
183,356 KB
testcase_35 WA -
testcase_36 AC 431 ms
183,228 KB
testcase_37 WA -
testcase_38 AC 523 ms
183,296 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

from operator import add
import bisect
from itertools import accumulate
import sys
input = sys.stdin.buffer.readline
sys.setrecursionlimit(10 ** 7)
inf = 10**18


class SparseTable:
    def __init__(self, N, arr, op, u):
        self.N = N
        self.depth = N.bit_length()
        self.op = op
        self.arr = tuple(arr)
        self.u = u
        self._build()

    def __call__(self, s, t):
        """
        [s, t)区間(0-indexed)での値を返す
        """
        if s == t:
            return self.u
        i = (t - s).bit_length() - 1
        L = self.table[i][s]
        R = self.table[i][t - (1 << i)]
        return self.op(L, R)

    def _build(self):
        self.table = []
        self.table.append(self.arr)
        N = self.N
        for i in range(self.depth - 1):
            shift = 1 << i
            N -= shift
            t = tuple(self.op(self.table[-1][j], self.table[-1][j+shift])
                      for j in range(N))
            self.table.append(t)



N, K = map(int, input().split())
T = [0] * N
D = [0] * N
for i in range(N):
    T[i], D[i] = map(int, input().split())
Dmax = SparseTable(N, D, max, 0)
Dacc = [0] + list(accumulate(D))
Dsum = lambda s, t: Dacc[t] - Dacc[s]

dp = [(inf, inf) for _ in range(N + 1)]
dp[0] = (0, 0)
for i in range(N):
    a, b = dp[i]

    #自分で処理
    na = max(a, D[i])
    nb = add(b, D[i])
    if dp[i + 1] > (na, nb):
        dp[i + 1] = (na, nb)

    #姉が処理
    to = bisect.bisect_left(T, T[i] + K)
    na = max(a, Dmax(i+1, to))
    nb = add(b, Dsum(i+1, to))
    if dp[to] > (na, nb):
        dp[to] = (na, nb)

print(*dp[N], sep="\n")
0