結果

問題 No.2232 Miser's Gift
ユーザー タコイモタコイモ
提出日時 2023-03-03 21:29:38
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 1,434 bytes
コンパイル時間 988 ms
コンパイル使用メモリ 81,332 KB
実行使用メモリ 81,140 KB
最終ジャッジ日時 2023-10-18 01:23:04
合計ジャッジ時間 9,451 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 43 ms
55,296 KB
testcase_01 AC 43 ms
55,296 KB
testcase_02 AC 44 ms
55,296 KB
testcase_03 WA -
testcase_04 AC 135 ms
81,140 KB
testcase_05 WA -
testcase_06 AC 43 ms
55,396 KB
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 WA -
testcase_20 WA -
testcase_21 WA -
testcase_22 WA -
testcase_23 WA -
testcase_24 WA -
testcase_25 WA -
testcase_26 WA -
testcase_27 WA -
testcase_28 WA -
testcase_29 WA -
testcase_30 WA -
testcase_31 WA -
testcase_32 WA -
testcase_33 WA -
testcase_34 WA -
testcase_35 WA -
testcase_36 WA -
testcase_37 WA -
testcase_38 WA -
testcase_39 WA -
testcase_40 WA -
testcase_41 WA -
testcase_42 WA -
testcase_43 WA -
testcase_44 WA -
testcase_45 WA -
testcase_46 WA -
testcase_47 WA -
testcase_48 WA -
testcase_49 WA -
testcase_50 WA -
testcase_51 WA -
testcase_52 WA -
testcase_53 WA -
testcase_54 WA -
testcase_55 WA -
testcase_56 WA -
testcase_57 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
#sys.setrecursionlimit(500000)
def I(): return int(sys.stdin.readline().rstrip())
def MI(): return map(int,sys.stdin.readline().rstrip().split())
def TI(): return tuple(map(int,sys.stdin.readline().rstrip().split()))
def LI(): return list(map(int,sys.stdin.readline().rstrip().split()))
def S(): return sys.stdin.readline().rstrip()
def LS(): return list(sys.stdin.readline().rstrip())
#for i, pi in enumerate(p):
from collections import defaultdict,deque
import bisect
import itertools
dic = defaultdict(int)
d = deque()
YN = ['No','Yes']

N,W = MI()
dp = [-1]*(W+1) #for _ in range(N)]
dp[0] = 0
for _ in range(N):
  w,v = MI()
  for i in range(W-w,-1,-1):
    if dp[i] == -1:
      continue
    dp[i+w] = max(dp[i]+v,dp[i+w])
#https://aotamasaki.hatenablog.com/entry/meguru_bisect
def is_ok(arg,x):
  return  dp[W] < dp[W-x]+arg
   # return #満たすべき条件a<b等
#ngは必ず答えにならない値
def meguru_bisect(ng, ok,x):
    '''
    初期値のng,okを受け取り,is_okを満たす最小(最大)のokを返す
    まずis_okを定義すべし
    ng ok は  とり得る最小の値-1 とり得る最大の値+1
    最大最小が逆の場合はよしなにひっくり返す
    '''
    while (abs(ok - ng) > 1):
        mid = (ok + ng) // 2
        if is_ok(mid,x):
            ok = mid
        else:
            ng = mid
    return ok
for x in range(1,W+1):
  print(meguru_bisect(0, 10**10,x))
    
0