結果
| 問題 |
No.966 引き算をして門松列(その1)
|
| コンテスト | |
| ユーザー |
lam6er
|
| 提出日時 | 2025-03-20 18:52:40 |
| 言語 | PyPy3 (7.3.15) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 2,724 bytes |
| コンパイル時間 | 189 ms |
| コンパイル使用メモリ | 82,232 KB |
| 実行使用メモリ | 80,808 KB |
| 最終ジャッジ日時 | 2025-03-20 18:53:39 |
| 合計ジャッジ時間 | 1,627 ms |
|
ジャッジサーバーID (参考情報) |
judge1 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 2 |
| other | AC * 1 WA * 4 |
ソースコード
import sys
def pattern1(A, B, C):
a = 0
A_prime = A - a
if A_prime <= 0:
return float('inf')
C_prime_max = min(C, A_prime - 1)
if C_prime_max <= 0:
return float('inf')
B_prime_max = min(B - 1, C_prime_max - 1)
if B_prime_max <= 0:
return float('inf')
if A_prime > C_prime_max and C_prime_max > B_prime_max:
cost = (B - B_prime_max) + (C - C_prime_max) + a
return cost
return float('inf')
def pattern2(A, B, C):
c = 0
C_prime = C - c
if C_prime <= 0:
return float('inf')
A_prime_max = min(A, C_prime - 1)
if A_prime_max <= 0:
return float('inf')
B_prime_max = min(B - 1, A_prime_max - 1)
if B_prime_max <= 0:
return float('inf')
if C_prime > A_prime_max and A_prime_max > B_prime_max:
cost = (B - B_prime_max) + (A - A_prime_max) + c
return cost
return float('inf')
def pattern4(B_prime_base, C_prime_base, A_prime_base):
b = 0
B_prime = B_prime_base - b
if B_prime <= 0:
return float('inf')
C_prime_max = min(C_prime_base, B_prime - 1)
if C_prime_max <= 0:
return float('inf')
A_prime_max = min(A_prime_base, C_prime_max - 1)
if A_prime_max <= 0:
return float('inf')
if B_prime > C_prime_max and C_prime_max > A_prime_max:
cost = (A_prime_base - A_prime_max) + (C_prime_base - C_prime_max) + b
return cost
return float('inf')
def pattern5(B_prime_base, A_prime_base, C_prime_base):
b = 0
B_prime = B_prime_base - b
if B_prime <= 0:
return float('inf')
A_prime_max = min(A_prime_base, B_prime - 1)
if A_prime_max <= 0:
return float('inf')
C_prime_max = min(C_prime_base, A_prime_max - 1)
if C_prime_max <= 0:
return float('inf')
if B_prime > A_prime_max and A_prime_max > C_prime_max:
cost = (C_prime_base - C_prime_max) + (A_prime_base - A_prime_max) + b
return cost
return float('inf')
def compute_min_cost(A, B, C):
min_cost = float('inf')
cost = pattern1(A, B, C)
if cost < min_cost:
min_cost = cost
cost = pattern2(A, B, C)
if cost < min_cost:
min_cost = cost
cost = pattern4(B, C, A)
if cost < min_cost:
min_cost = cost
cost = pattern5(B, A, C)
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])
idx +=3
print(compute_min_cost(A, B, C))
if __name__ == "__main__":
main()
lam6er