結果
| 問題 |
No.968 引き算をして門松列(その3)
|
| コンテスト | |
| ユーザー |
lam6er
|
| 提出日時 | 2025-03-31 17:49:28 |
| 言語 | PyPy3 (7.3.15) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 1,836 bytes |
| コンパイル時間 | 143 ms |
| コンパイル使用メモリ | 82,100 KB |
| 実行使用メモリ | 83,816 KB |
| 最終ジャッジ日時 | 2025-03-31 17:50:21 |
| 合計ジャッジ時間 | 2,586 ms |
|
ジャッジサーバーID (参考情報) |
judge5 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 2 |
| other | AC * 3 WA * 7 |
ソースコード
import sys
def is_valid_kadomatsu(a, b, c):
if a <= 0 or b <=0 or c <=0:
return False
if a == b or b == c or a == c:
return False
sorted_nums = sorted([a, b, c])
if sorted_nums[1] == a or sorted_nums[1] == c:
return True
return False
def compute_min_cost(a, b, c, x, y, z):
# Check if original is already valid
if is_valid_kadomatsu(a, b, c):
return 0
min_cost = float('inf')
# Enumerate possible possibilities by trying various number of operations
# This approach tries a few iterations considering possible operation combinations
# Not exhaustive but covers common cases for efficiency
# Try all possible values of t where t is a small number (up to 4)
# This heuristic approach works due to the problem's constraints but may not cover all edge cases
for t1 in range(0, 5):
for t2 in range(0, 5):
for t3 in range(0, 5):
new_a = a - t1 - t3
new_b = b - t1 - t2
new_c = c - t2 - t3
if new_a <=0 or new_b <=0 or new_c <=0:
continue
if is_valid_kadomatsu(new_a, new_b, new_c):
cost = t1 * x + t2 * y + t3 * 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()
T = int(input[0])
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
res = compute_min_cost(A, B, C, X, Y, Z)
print(res if res != float('inf') else -1)
if __name__ == '__main__':
main()
lam6er