結果
問題 |
No.968 引き算をして門松列(その3)
|
ユーザー |
![]() |
提出日時 | 2025-06-12 13:34:58 |
言語 | PyPy3 (7.3.15) |
結果 |
WA
|
実行時間 | - |
コード長 | 3,612 bytes |
コンパイル時間 | 509 ms |
コンパイル使用メモリ | 82,240 KB |
実行使用メモリ | 83,672 KB |
最終ジャッジ日時 | 2025-06-12 13:40:54 |
合計ジャッジ時間 | 2,262 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 2 |
other | WA * 10 |
ソースコード
def is_kadomatsu(A, B, C): if A == B or B == C or A == C: return False sorted_vals = sorted([A, B, C]) second = sorted_vals[1] return second == A or second == C def solve(): import sys 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 if is_kadomatsu(A, B, C): print(0) continue min_cost = float('inf') # Try making B the maximum with different operations # Operation 2 (Y) once new_B = B - 1 new_A = A new_C = C - 1 if new_B > 0 and new_A > 0 and new_C > 0: if new_B > new_A and new_B > new_C and new_A != new_C: if is_kadomatsu(new_A, new_B, new_C): cost = Y min_cost = min(min_cost, cost) # Operation 1 (X) once new_B = B - 1 new_A = A - 1 new_C = C if new_B > 0 and new_A > 0 and new_C > 0: if new_B > new_A and new_B > new_C and new_A != new_C: if is_kadomatsu(new_A, new_B, new_C): cost = X min_cost = min(min_cost, cost) # Operation 3 (Z) once (only if A != C) if A != C: new_A = A - 1 new_C = C - 1 new_B = B if new_A > 0 and new_C > 0 and new_B > 0: if new_B > new_A and new_B > new_C and new_A != new_C: if is_kadomatsu(new_A, new_B, new_C): cost = Z min_cost = min(min_cost, cost) # Try making B the minimum with different operations # Operation 1 (X) once new_B = B - 1 new_A = A - 1 new_C = C if new_B > 0 and new_A > 0 and new_C > 0: if new_B < new_A and new_B < new_C and new_A != new_C: if is_kadomatsu(new_A, new_B, new_C): cost = X min_cost = min(min_cost, cost) # Operation 2 (Y) once new_B = B - 1 new_A = A new_C = C - 1 if new_B > 0 and new_A > 0 and new_C > 0: if new_B < new_A and new_B < new_C and new_A != new_C: if is_kadomatsu(new_A, new_B, new_C): cost = Y min_cost = min(min_cost, cost) # Operation 3 (Z) once (only if A != C) if A != C: new_A = A - 1 new_C = C - 1 new_B = B if new_A > 0 and new_C > 0 and new_B > 0: if new_B < new_A and new_B < new_C and new_A != new_C: if is_kadomatsu(new_A, new_B, new_C): cost = Z min_cost = min(min_cost, cost) # Try other combinations, like using operation 3 once new_A = A - 1 new_C = C - 1 new_B = B - 0 if new_A > 0 and new_C > 0 and new_B > 0: if (new_B > new_A and new_B > new_C) or (new_B < new_A and new_B < new_C): if new_A != new_C and is_kadomatsu(new_A, new_B, new_C): cost = Z * 1 min_cost = min(min_cost, cost) # Check if any of the operations worked if min_cost != float('inf'): print(min_cost) else: print(-1) if __name__ == "__main__": solve()