結果
| 問題 | No.968 引き算をして門松列(その3) | 
| コンテスト | |
| ユーザー |  gew1fw | 
| 提出日時 | 2025-06-12 15:02:41 | 
| 言語 | PyPy3 (7.3.15) | 
| 結果 | 
                                WA
                                 
                             | 
| 実行時間 | - | 
| コード長 | 1,827 bytes | 
| コンパイル時間 | 268 ms | 
| コンパイル使用メモリ | 82,760 KB | 
| 実行使用メモリ | 78,184 KB | 
| 最終ジャッジ日時 | 2025-06-12 15:02:49 | 
| 合計ジャッジ時間 | 2,179 ms | 
| ジャッジサーバーID (参考情報) | judge5 / 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])
    mid = sorted_vals[1]
    return mid == A or mid == C
def compute_min_cost(A, B, C, X, Y, Z):
    if is_kadomatsu(A, B, C):
        return 0
    min_cost = float('inf')
    
    # Case 1a: b' < a' < c', x=0, y=0
    if A < C:
        max_z = min(A - B - 1, A - 1, C - 1)
        if max_z >= 0:
            a = A - max_z
            b = B
            c = C - max_z
            if b < a < c and a != b and a != c and b != c:
                cost = Z * max_z
                min_cost = min(min_cost, cost)
    
    # Case 1b: c' < a' < b', x=0, z=0
    lower_y = max(0, C - A + 1)
    upper_y = min(B - A - 1, B - 1, C - 1)
    if lower_y <= upper_y:
        y = lower_y
        a = A
        b = B - y
        c = C - y
        if c < a < b and a != b and a != c and b != c:
            cost = Y * y
            min_cost = min(min_cost, cost)
    
    # Case 2a: a' < c' < b', y=0, x=0
    if A < C and C < B:
        max_z = min(A - 1, C - 1)
        if max_z >= 0:
            a = A - max_z
            c = C - max_z
            b = B
            if a < c < b and a != b and a != c and b != c:
                cost = Z * max_z
                min_cost = min(min_cost, cost)
    
    # Case 2b: b' < c' < a', y=0, z=0
    lower_x = max(0, B - C + 1)
    upper_x = min(A - C - 1, A - 1, B - 1)
    if lower_x <= upper_x:
        x = lower_x
        a = A - x
        b = B - x
        c = C
        if b < c < a and a != b and a != c and b != c:
            cost = X * x
            min_cost = min(min_cost, cost)
    
    return min_cost if min_cost != float('inf') else -1
T = int(input())
for _ in range(T):
    A, B, C, X, Y, Z = map(int, input().split())
    print(compute_min_cost(A, B, C, X, Y, Z))
            
            
            
        