結果
| 問題 |
No.968 引き算をして門松列(その3)
|
| コンテスト | |
| ユーザー |
gew1fw
|
| 提出日時 | 2025-06-12 15:10:15 |
| 言語 | PyPy3 (7.3.15) |
| 結果 |
TLE
|
| 実行時間 | - |
| コード長 | 1,762 bytes |
| コンパイル時間 | 223 ms |
| コンパイル使用メモリ | 82,432 KB |
| 実行使用メモリ | 52,480 KB |
| 最終ジャッジ日時 | 2025-06-12 15:10:29 |
| 合計ジャッジ時間 | 3,819 ms |
|
ジャッジサーバーID (参考情報) |
judge1 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 2 |
| other | TLE * 1 -- * 9 |
ソースコード
import sys
def compute_min_cost(A, B, C, X, Y, Z):
min_cost = float('inf')
# 情况一:B'是最大的
# 我们需要 B' > A' 和 B' > C',同时 A' != C'
# 尝试让 A' 和 C' 尽可能小,同时 B' 尽可能大
for k1 in range(0, max(A, C) + 1):
for k2 in range(0, B + 1):
for k3 in range(0, max(C, A) + 1):
a = A - k1 - k3
b = B - k1 - k2
c = C - k2 - k3
if a <= 0 or b <= 0 or c <= 0:
continue
if b > a and b > c and a != c:
cost = X * k1 + Y * k2 + Z * k3
if cost < min_cost:
min_cost = cost
# 情况二:B'是最小的
# 我们需要 B' < A' 和 B' < C',同时 A' != C'
for k1 in range(0, B + 1):
for k2 in range(0, C + 1):
for k3 in range(0, A + 1):
a = A - k1 - k3
b = B - k1 - k2
c = C - k2 - k3
if a <= 0 or b <= 0 or c <= 0:
continue
if b < a and b < c and a != c:
cost = X * k1 + Y * k2 + Z * k3
if cost < min_cost:
min_cost = cost
if min_cost == float('inf'):
return -1
else:
return min_cost
def main():
input = sys.stdin.read().split()
idx = 0
T = int(input[idx])
idx += 1
for _ in range(T):
A = int(input[idx])
B = int(input[idx+1])
C = int(input[idx+2])
X = int(input[idx+3])
Y = int(input[idx+4])
Z = int(input[idx+5])
idx +=6
res = compute_min_cost(A, B, C, X, Y, Z)
print(res)
if __name__ == "__main__":
main()
gew1fw