結果
| 問題 |
No.968 引き算をして門松列(その3)
|
| コンテスト | |
| ユーザー |
lam6er
|
| 提出日時 | 2025-03-20 20:51:46 |
| 言語 | PyPy3 (7.3.15) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 1,653 bytes |
| コンパイル時間 | 166 ms |
| コンパイル使用メモリ | 82,296 KB |
| 実行使用メモリ | 84,812 KB |
| 最終ジャッジ日時 | 2025-03-20 20:51:59 |
| 合計ジャッジ時間 | 4,525 ms |
|
ジャッジサーバーID (参考情報) |
judge4 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 2 |
| other | WA * 1 TLE * 1 -- * 8 |
ソースコード
import sys
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 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
# Check initial condition
if is_kadomatsu(A, B, C):
print(0)
continue
min_cost = float('inf')
# Check possible operations up to 200 steps (adjust if necessary)
max_steps = 200
for m in range(max_steps+1):
for n in range(max_steps+1):
for p in range(max_steps+1):
a_new = A - m - p
b_new = B - m - n
c_new = C - n - p
if a_new <1 or b_new <1 or c_new <1:
continue
if a_new == b_new or b_new == c_new or a_new == c_new:
continue
sorted_vals = sorted([a_new, b_new, c_new])
mid = sorted_vals[1]
if mid == a_new or mid == c_new:
cost = X * m + Y * n + Z * p
if cost < min_cost:
min_cost = cost
if min_cost != float('inf'):
print(min_cost)
else:
print(-1)
if __name__ == '__main__':
main()
lam6er