結果
| 問題 |
No.966 引き算をして門松列(その1)
|
| コンテスト | |
| ユーザー |
👑 SPD_9X2
|
| 提出日時 | 2020-01-13 21:15:52 |
| 言語 | Python3 (3.13.1 + numpy 2.2.1 + scipy 1.14.1) |
| 結果 |
AC
|
| 実行時間 | 122 ms / 2,000 ms |
| コード長 | 1,849 bytes |
| コンパイル時間 | 106 ms |
| コンパイル使用メモリ | 12,800 KB |
| 実行使用メモリ | 10,880 KB |
| 最終ジャッジ日時 | 2024-12-22 21:19:25 |
| 合計ジャッジ時間 | 1,057 ms |
|
ジャッジサーバーID (参考情報) |
judge3 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 2 |
| other | AC * 5 |
ソースコード
T = int(input())
for i in range(T):
A,B,C= map(int,input().split())
X = 1
Y = 1
Z = 1
if A==B and B==C:
if A < 3:
print (-1)
else:
print (min(X+Z*2,X*2+Z,Y*2+X,Y*2+Z))
elif A==B or B==C:
if B == 1:
print (-1)
elif abs(A-C) == 1: #1 2 2 or 2 2 3
#A=Bにする
if B==C:
t = C
C = A
A = t
s = X
X = Z
Z = s
if min(A,B,C) == 1:
print (-1)
elif min(A,B,C) < B: #4 4 3など
print (min(X*2,Y*2))
else:
print (min(X,Y))
else: #9 9 3
#A=Bにする
if B==C:
t = C
C = A
A = t
s = X
X = Z
Z = s
print (X)
elif A == C:
if A != 1 and B != A-1: #2 3 2
print (min(X,Z))
elif A != 1 and B == A-1 and A-2 > 0: #3 2 3
print (min(X*2,Z*2))
else:
print (-1)
else: #9 2 1
ans = float("inf")
if min(A,B,C) == B or max(A,B,C) == B:
print (0)
else:
ans = float("inf")
if A < C: #A>B>Cにする
t = C
C = A
A = t
s = X
X = Z
Z = s
na = B-1
if na != C and na > 0:
ans = min(ans,(A-na)*X)
nb = C-1
if nb > 0:
ans = min(ans,(B-nb)*Y)
if ans == float("inf"):
print (-1)
else:
print (ans)
SPD_9X2