結果
問題 | No.968 引き算をして門松列(その3) |
ユーザー |
![]() |
提出日時 | 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 sysdef solve():input = sys.stdin.read().split()idx = 0T = int(input[idx])idx += 1for _ 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 +=6min_cost = float('inf')# Case 1: B' is the maximum# Check if current B is already larger than A and C, and A != Cif 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 - 1if 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' > 0max_c_C = C - b - 1 # C' > 0max_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 - bif (A - a) == (C - b):continue# Find the minimal cc = min_ccost = X * a + Y * b + Z * cif cost < min_cost:min_cost = cost# Case 2: B' is the minimum# Check if current B is smaller than A and C, and A != Cif 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_primemax_c_A = (A - B_prime) - a - 1max_c_C = (C - B_prime) - b - 1if max_c_A < 0 or max_c_C < 0:continuemax_c = min(max_c_A, max_c_C)if max_c < 0:continue# Check if A - a - c != C - b - c# A - a != C - bif (A - a) == (C - b):continue# Minimal c is 0c = 0# Check if A' and C' are validif (A - a - c) <= B_prime or (C - b - c) <= B_prime:continuecost = X * a + Y * b + Z * cif 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 aboveif min_cost == float('inf'):print(-1)else:print(min_cost)solve()