LoginSignup
1
1

More than 5 years have passed since last update.

POH!Liteでめちゃめちゃ素直に実装してチューニングした結果

Posted at

POH!Liteでめちゃめちゃ素直に実装してチューニングした結果

poh-lite.py
from itertools import starmap
m = input()
n = input()
cost = {0:0}
def update(x,y):
  s,t = q+x, r+y
  if not s in cost or cost[s]>t:
    return (s,t)
for i in range(n):
  q,r = map(int,raw_input().split())
  cost.update( filter(None,starmap(update,cost.iteritems())) )
print min( (cost[x] for x in cost.keys() if x>=m) )

TEST CASE 7で2.07秒
dict.updateに与えるシーケンスをfilterでリストにしているのがミソ

1
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
1