結果
| 問題 |
No.968 引き算をして門松列(その3)
|
| コンテスト | |
| ユーザー |
lam6er
|
| 提出日時 | 2025-03-26 15:58:35 |
| 言語 | PyPy3 (7.3.15) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 3,368 bytes |
| コンパイル時間 | 181 ms |
| コンパイル使用メモリ | 82,244 KB |
| 実行使用メモリ | 83,688 KB |
| 最終ジャッジ日時 | 2025-03-26 15:59:32 |
| 合計ジャッジ時間 | 2,232 ms |
|
ジャッジサーバーID (参考情報) |
judge5 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 2 |
| other | WA * 10 |
ソースコード
import sys
def solve():
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
min_cost = float('inf')
# Case 1: B' is the maximum
# Check if current B is already larger than A and C, and A != C
if A < B and C < B and A != C:
min_cost = min(min_cost, 0)
# Try to reduce B by 1 (a + b = 1)
B_prime = B - 1
if B_prime > 0:
# Now, B' = B - 1, which could be the new maximum
# Check if A' < B' and C' < B' and A' != C'
for a in [0, 1]:
b = 1 - a
# A' = A - a - c
# C' = C - b - c
# B' = B - 1
# Need A' < B' and C' < B'
# => A - a - c < B - 1
# => C - b - c < B - 1
# => c > A - a - (B - 1)
# => c > C - b - (B - 1)
min_c = max(A - a - (B_prime) + 1, C - b - (B_prime) + 1, 0)
max_c_A = A - a - 1 # A' > 0
max_c_C = C - b - 1 # C' > 0
max_c = min(max_c_A, max_c_C)
if min_c > max_c:
continue
# Check if A' != C'
# A - a - c != C - b - c => A - a != C - b
if (A - a) == (C - b):
continue
# Find the minimal c
c = min_c
cost = X * a + Y * b + Z * c
if cost < min_cost:
min_cost = cost
# Case 2: B' is the minimum
# Check if current B is smaller than A and C, and A != C
if B < A and B < C and A != C:
min_cost = min(min_cost, 0)
# Try to reduce B by 1 (B' = B - 1)
if B > 1:
B_prime = B - 1
# Need A' > B' and C' > B' and A' != C'
for a in [0, 1]:
b = 1 - a
# A' = A - a - c > B_prime
# C' = C - b - c > B_prime
# => a + c < A - B_prime
# => b + c < C - B_prime
max_c_A = (A - B_prime) - a - 1
max_c_C = (C - B_prime) - b - 1
if max_c_A < 0 or max_c_C < 0:
continue
max_c = min(max_c_A, max_c_C)
if max_c < 0:
continue
# Check if A - a - c != C - b - c
# A - a != C - b
if (A - a) == (C - b):
continue
# Minimal c is 0
c = 0
# Check if A' and C' are valid
if (A - a - c) <= B_prime or (C - b - c) <= B_prime:
continue
cost = X * a + Y * b + Z * c
if cost < min_cost:
min_cost = cost
# Check other possibilities where B' is reduced by 2 or more (could be needed in some cases)
# But for efficiency, we skip further checks and rely on the above
if min_cost == float('inf'):
print(-1)
else:
print(min_cost)
solve()
lam6er