結果

問題 No.1029 JJOOII 3
ユーザー maspymaspy
提出日時 2020-04-17 23:37:14
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
WA  
実行時間 -
コード長 1,054 bytes
コンパイル時間 348 ms
コンパイル使用メモリ 12,928 KB
実行使用メモリ 13,184 KB
最終ジャッジ日時 2024-04-14 15:42:29
合計ジャッジ時間 3,291 ms
ジャッジサーバーID
(参考情報)
judge4 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 31 ms
10,880 KB
testcase_01 AC 30 ms
10,752 KB
testcase_02 AC 30 ms
10,752 KB
testcase_03 WA -
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 AC 32 ms
10,752 KB
testcase_20 AC 44 ms
10,752 KB
testcase_21 AC 42 ms
10,752 KB
testcase_22 AC 43 ms
10,752 KB
testcase_23 AC 41 ms
10,880 KB
testcase_24 AC 42 ms
10,752 KB
testcase_25 AC 43 ms
10,752 KB
testcase_26 AC 46 ms
10,880 KB
testcase_27 AC 53 ms
10,880 KB
testcase_28 AC 49 ms
10,880 KB
testcase_29 AC 45 ms
10,752 KB
testcase_30 AC 52 ms
10,880 KB
testcase_31 AC 50 ms
10,880 KB
testcase_32 WA -
testcase_33 WA -
testcase_34 WA -
testcase_35 WA -
testcase_36 WA -
testcase_37 AC 31 ms
10,624 KB
testcase_38 WA -
testcase_39 AC 30 ms
10,624 KB
testcase_40 AC 31 ms
10,752 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

N, K = map(int, readline().split())
S = []
C = []
for _ in range(N):
    x, y = readline().split()
    x = tuple(0 if x == 'J' else 1 if x == 'O' else 2 for x in x.decode())
    S.append(x)
    C.append(int(y))

INF = 10 ** 16
dp = [INF] * (K + K + K + 1)
dp[0] = 0

cnt = [0] * (N * 3)
for q in range(3):
    for i in range(N):
        cnt[3 * i + q] = sum(n == q for n in S[i])


def solve_small():
    def f(k, i):
        q, r = divmod(k, K)
        if k + cnt[3 * i + q] < K:
            return k + cnt[3 * i + q]
        for x in S[i]:
            if x == q:
                r += 1
                if r == K:
                    r = 0
                    q += 1
        return K * q + r

    for k in range(K + K + K):
        for i in range(N):
            next_k = f(k, i)
            dp[next_k] = min(dp[k] + C[i], dp[next_k])

    x = dp[-1]
    if x == INF:
        x = -1
    return x


if K <= 100:
    print(solve_small())
0