結果
| 問題 |
No.158 奇妙なお使い
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2015-06-02 18:05:21 |
| 言語 | Python3 (3.13.1 + numpy 2.2.1 + scipy 1.14.1) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 1,724 bytes |
| コンパイル時間 | 174 ms |
| コンパイル使用メモリ | 12,928 KB |
| 実行使用メモリ | 75,048 KB |
| 最終ジャッジ日時 | 2024-07-06 13:44:12 |
| 合計ジャッジ時間 | 4,343 ms |
|
ジャッジサーバーID (参考情報) |
judge4 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 4 |
| other | AC * 23 WA * 4 |
ソースコード
import sys
sys.setrecursionlimit(10**6)
def read_data():
a3, a2, a1 = map(int, input().split())
db = int(input())
b3, b2, b1 = map(int, input().split())
dc = int(input())
c3, c2, c1 = map(int, input().split())
return a3, a2, a1, b3, b2, b1, c3, c2, c1, db, dc
def solve(a3, a2, a1, b3, b2, b1, c3, c2, c1, db, dc):
memo = dict()
dif_b = db - b3*1000 - b2*100 - b1
dif_c = dc - c3*1000 - c2*100 - c1
dif = min(dif_b, dif_c)
record = 0
def dfs(a3, a2, a1, depth):
nonlocal record
nonlocal memo
if (a3, a2, a1) in memo:
return memo[a3, a2, a1]
if (a3 * 1000 + a2 * 100 + a1) // dif < record - depth:
return 0
tmp = 0
d3, d2, d1 = generate_payment_patterns(a3, a2, a1, db)
if d3 or d2 or d1:
t = dfs(a3-d3+b3, a2-d2+b2, a1-d1+b1, depth+1)
if t > tmp:
tmp = t
d3, d2, d1 = generate_payment_patterns(a3, a2, a1, dc)
if d3 or d2 or d1:
t = dfs(a3-d3+c3, a2-d2+c2, a1-d1+c1, depth+1)
if t > tmp:
tmp = t
memo[a3, a2, a1] = tmp
if depth + tmp > record:
record = depth + tmp
return tmp
dfs(a3, a2, a1, 0)
return record
def generate_payment_patterns(a3, a2, a1, d):
for d3 in range(d//1000, -1, -1):
if d3 > a3:
continue
for d2 in range((d - d3*1000)//100, -1, -1):
if d2 > a2:
continue
d1 = d - d3*1000 - d2*100
if d1 > a1:
continue
return d3, d2, d1
return 0, 0, 0
if __name__ == '__main__':
param = read_data()
print(solve(*param))