結果
問題 | No.968 引き算をして門松列(その3) |
ユーザー | kimiyuki |
提出日時 | 2020-01-13 21:20:15 |
言語 | PyPy3 (7.3.13) |
結果 |
AC
|
実行時間 | 626 ms / 2,000 ms |
コード長 | 974 bytes |
コンパイル時間 | 1,972 ms |
コンパイル使用メモリ | 86,848 KB |
実行使用メモリ | 80,292 KB |
最終ジャッジ日時 | 2023-08-24 14:08:47 |
合計ジャッジ時間 | 6,450 ms |
ジャッジサーバーID (参考情報) |
judge15 / judge14 |
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 73 ms
70,920 KB |
testcase_01 | AC | 74 ms
71,056 KB |
testcase_02 | AC | 90 ms
75,604 KB |
testcase_03 | AC | 329 ms
79,212 KB |
testcase_04 | AC | 324 ms
78,728 KB |
testcase_05 | AC | 328 ms
78,312 KB |
testcase_06 | AC | 322 ms
79,748 KB |
testcase_07 | AC | 322 ms
78,252 KB |
testcase_08 | AC | 407 ms
78,396 KB |
testcase_09 | AC | 555 ms
80,108 KB |
testcase_10 | AC | 594 ms
80,292 KB |
testcase_11 | AC | 626 ms
79,328 KB |
ソースコード
#!/usr/bin/env python3 import math def iterate(a, b, c): for a in range(a, a + 4): for b in range(b, b + 4): for c in range(c, c + 4): yield a, b, c yield max(b + 1, a), b, max(max(b + 1, a) + 1, c) yield max(max(b + 1, c) + 1, a), b, max(b + 1, c) yield a, max(max(a + 1, c) + 1, b), max(a + 1, c) yield max(c + 1, a), max(max(c + 1, a) + 1, b), c def solve(a, b, c, x, y, z): ans = math.inf for na, nb, nc in iterate(a, b, c): da = na - a db = nb - b dc = nc - c na, nb, nc = a - db - dc, b - dc - da, c - da - db if na != nc and ((na < nb and nb > nc) or (na > nb and nb < nc)): if na >= 1 and nb >= 1 and nc >= 1: ans = min(ans, y * da + z * db + x * dc) if math.isinf(ans): return -1 return ans for _ in range(int(input())): print(solve(*map(int, input().split())))