結果
| 問題 |
No.966 引き算をして門松列(その1)
|
| コンテスト | |
| ユーザー |
はむ吉🐹
|
| 提出日時 | 2020-01-13 20:54:23 |
| 言語 | Python3 (3.13.1 + numpy 2.2.1 + scipy 1.14.1) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 1,290 bytes |
| コンパイル時間 | 147 ms |
| コンパイル使用メモリ | 12,672 KB |
| 実行使用メモリ | 10,752 KB |
| 最終ジャッジ日時 | 2024-12-21 17:06:02 |
| 合計ジャッジ時間 | 1,111 ms |
|
ジャッジサーバーID (参考情報) |
judge2 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 2 |
| other | AC * 2 WA * 3 |
ソースコード
#!/usr/bin/env python3
INF = 10 ** 9
def is_kado(a, b, c):
x = sorted((a, b, c))[1]
return a > 0 and b > 0 and c > 0 and a != b and b != c and c != a and (a == x or c == x)
def minimize_cost_a(a, b, c):
if is_kado(a, b, c):
return 0
cost = 0
if a >= c:
a, c = c, a
if c >= b:
cost += c - (b - 1)
c = b - 1
if a >= c:
cost += a - (c - 1)
a = c - 1
if is_kado(a, b, c):
return cost
else:
return None
def minimize_cost_b(a, b, c):
if is_kado(a, b, c):
return 0
cost = 0
if a >= c:
a, c = c, a
if b >= a:
cost += b - (a - 1)
b = a - 1
if a == c:
cost += a - (c - 1)
a -= 1
if is_kado(a, b, c):
return cost
else:
return None
def minimize_cost(a, b, c):
cost_a = minimize_cost_a(a, b, c)
if cost_a is None:
cost_a = INF
cost_b = minimize_cost_b(a, b, c)
if cost_b is None:
cost_b = INF
cost = min(cost_a, cost_b)
return cost if cost < INF else -1
def main():
t = int(input())
for _ in range(t):
a, b, c = (int(z) for z in input().split())
cost = minimize_cost(a, b, c)
print(cost)
if __name__ == "__main__":
main()
はむ吉🐹