結果
| 問題 |
No.158 奇妙なお使い
|
| コンテスト | |
| ユーザー |
rlangevin
|
| 提出日時 | 2023-09-07 12:30:28 |
| 言語 | Python3 (3.13.1 + numpy 2.2.1 + scipy 1.14.1) |
| 結果 |
TLE
|
| 実行時間 | - |
| コード長 | 2,041 bytes |
| コンパイル時間 | 91 ms |
| コンパイル使用メモリ | 13,184 KB |
| 実行使用メモリ | 127,872 KB |
| 最終ジャッジ日時 | 2024-06-25 06:35:16 |
| 合計ジャッジ時間 | 12,585 ms |
|
ジャッジサーバーID (参考情報) |
judge1 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | -- * 4 |
| other | TLE * 1 -- * 26 |
ソースコード
from collections import *
A = list(map(int, input().split()))
Db = int(input())
B = list(map(int, input().split()))
Dc = int(input())
C = list(map(int, input().split()))
num = [1000, 100, 1]
Sb, Sc = 0, 0
N = 0
for i in range(3):
N += num[i] * A[i]
Sb += num[i] * B[i]
Sc += num[i] * C[i]
Edge1 = []
for a in range(11):
now = num[0] * a
if now > Db:
break
for b in range(101):
now = num[0] * a + num[1] * b
if now > Db:
break
for c in range(10001):
now = num[0] * a + num[1] * b + num[2] * c
if now > Db:
break
if now == Db:
Edge1.append((a, b, c))
Edge2 = []
for a in range(11):
now = num[0] * a
if now > Dc:
break
for b in range(101):
now = num[0] * a + num[1] * b
if now > Dc:
break
for c in range(10001):
now = num[0] * a + num[1] * b + num[2] * c
if now > Dc:
break
if now == Dc:
Edge2.append((a, b, c))
L = [[] for i in range(N + 1)]
L[N].append(tuple(A))
inf = 10 ** 18
D = defaultdict(lambda: -inf)
D[tuple(A)] = 0
ans = 0
for i in range(N, -1, -1):
for a1, b1, c1 in L[i]:
for a2, b2, c2 in Edge1:
if a1 < a2 or b1 < b2 or c1 < c2:
continue
temp = max(D[(a1 - a2 + B[0], b1 - b2 + B[1], c1 - c2 + B[2])], D[(a1, b1, c1)] + 1)
ans = max(ans, temp)
D[(a1 - a2 + B[0], b1 - b2 + B[1], c1 - c2 + B[2])] = temp
L[i - Db + Sb].append((a1 - a2 + B[0], b1 - b2 + B[1], c1 - c2 + B[2]))
for a2, b2, c2 in Edge2:
if a1 < a2 or b1 < b2 or c1 < c2:
continue
temp = max(D[(a1 - a2 + C[0], b1 - b2 + C[1], c1 - c2 + C[2])], D[(a1, b1, c1)] + 1)
ans = max(ans, temp)
D[(a1 - a2 + C[0], b1 - b2 + C[1], c1 - c2 + C[2])] = temp
L[i - Dc + Sc].append((a1 - a2 + C[0], b1 - b2 + C[1], c1 - c2 + C[2]))
print(ans)
rlangevin