結果

問題 No.54 Happy Hallowe'en
ユーザー rpy3cpprpy3cpp
提出日時 2015-08-02 00:24:27
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
RE  
実行時間 -
コード長 1,147 bytes
コンパイル時間 308 ms
コンパイル使用メモリ 11,100 KB
実行使用メモリ 10,276 KB
最終ジャッジ日時 2023-09-25 00:28:50
合計ジャッジ時間 1,757 ms
ジャッジサーバーID
(参考情報)
judge14 / judge13
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 16 ms
7,896 KB
testcase_01 AC 17 ms
7,924 KB
testcase_02 AC 16 ms
7,784 KB
testcase_03 AC 16 ms
7,832 KB
testcase_04 AC 25 ms
8,708 KB
testcase_05 AC 29 ms
9,000 KB
testcase_06 AC 33 ms
9,280 KB
testcase_07 AC 38 ms
9,488 KB
testcase_08 AC 42 ms
9,820 KB
testcase_09 AC 47 ms
10,032 KB
testcase_10 AC 16 ms
7,832 KB
testcase_11 AC 16 ms
7,856 KB
testcase_12 RE -
testcase_13 AC 42 ms
10,072 KB
testcase_14 AC 16 ms
7,824 KB
testcase_15 AC 16 ms
7,800 KB
testcase_16 AC 16 ms
7,900 KB
testcase_17 WA -
testcase_18 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

def read_data():
    N = int(input())
    VT = []
    for n in range(N):
        v, t = map(int, input().split())
        VT.append((v + t, v, t))
    return N, VT

def solve(N, VT):
    VT.sort(reverse=True)
    upper = min(VT[0][0], sum(v for vt, v, t in VT) + 1)
    lower = 1
    while lower + 1 < upper:
        mid = (upper + lower) // 2
        if is_valid(mid, VT):
            lower = mid
        else:
            upper = mid
    return lower

def is_valid(val, VT):
    used = [False] * len(VT)
    lower = val
    upper = float('inf')
    return dfs(lower, upper, VT, used)

def dfs(lower, upper, VT, used):
    '''VTのうち、used でないものを使って、lower 以上、upper 未満の選び方をできるかを返す。
    '''
    for i, (val, v, t) in enumerate(VT):
        if val < lower:
            return False
        if used[i] or v >= upper:
            continue
        if v >= lower:
            return True
        used[i] = True
        result = dfs(lower - v, min(upper, t), VT, used)
        used[i] = False
        if result:
            return True
    return False

N, VT = read_data()
print(solve(N, VT))
0