結果
| 問題 | No.968 引き算をして門松列(その3) | 
| コンテスト | |
| ユーザー |  gew1fw | 
| 提出日時 | 2025-06-12 20:05:46 | 
| 言語 | PyPy3 (7.3.15) | 
| 結果 | 
                                WA
                                 
                             | 
| 実行時間 | - | 
| コード長 | 1,715 bytes | 
| コンパイル時間 | 223 ms | 
| コンパイル使用メモリ | 82,220 KB | 
| 実行使用メモリ | 83,584 KB | 
| 最終ジャッジ日時 | 2025-06-12 20:12:35 | 
| 合計ジャッジ時間 | 3,260 ms | 
| ジャッジサーバーID (参考情報) | judge5 / judge1 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| sample | AC * 2 | 
| other | AC * 1 WA * 9 | 
ソースコード
import sys
def is_kadomatsu(a, b, c):
    if a == b or b == c or a == c:
        return False
    sorted_nums = sorted([a, b, c])
    second = sorted_nums[1]
    return second == a or second == c
def compute_min_cost(A, B, C, X, Y, Z):
    if is_kadomatsu(A, B, C):
        return 0
    min_cost = float('inf')
    
    # Generate possible values for A', B', C' by considering up to 2 reductions each
    # This is a heuristic approach to limit the search space
    for a_red in range(0, 3):
        for b_red in range(0, 3):
            for c_red in range(0, 3):
                for k in range(0, a_red + 1):
                    for m in range(0, b_red + 1):
                        for n in range(0, c_red + 1):
                            A_new = A - k - n
                            B_new = B - k - m
                            C_new = C - m - n
                            if A_new <= 0 or B_new <= 0 or C_new <= 0:
                                continue
                            if is_kadomatsu(A_new, B_new, C_new):
                                cost = k * X + m * Y + n * Z
                                if cost < min_cost:
                                    min_cost = cost
    return min_cost if min_cost != float('inf') else -1
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
        result = compute_min_cost(A, B, C, X, Y, Z)
        print(result if result != float('inf') else -1)
if __name__ == '__main__':
    main()
            
            
            
        