結果
問題 | No.1122 Plane Tickets |
ユーザー |
![]() |
提出日時 | 2020-07-22 23:44:12 |
言語 | Python3 (3.13.1 + numpy 2.2.1 + scipy 1.14.1) |
結果 |
TLE
|
実行時間 | - |
コード長 | 1,138 bytes |
コンパイル時間 | 302 ms |
コンパイル使用メモリ | 12,928 KB |
実行使用メモリ | 55,436 KB |
最終ジャッジ日時 | 2024-06-23 01:52:24 |
合計ジャッジ時間 | 4,790 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | TLE * 1 -- * 1 |
other | -- * 55 |
ソースコード
import sys import numpy as np import itertools read = sys.stdin.buffer.read readline = sys.stdin.buffer.readline readlines = sys.stdin.buffer.readlines a, b, c, d, e = map(int, read().split()) A = np.array([ [1,0,0,0,0], [0,1,0,0,0], [0,0,1,0,0], [0,0,0,1,0], [0,0,0,0,1], [1,1,0,0,1], [1,1,1,0,0], [0,1,1,1,0], [0,0,1,1,1], [1,0,0,1,1], ], np.int64) v = np.array([0,0,0,0,0,a,b,c,d,e]) cand = [] for s in itertools.combinations(range(10), 5): A1 = np.concatenate([A[i] for i in s]).reshape(5,5) v1 = np.array([v[i] for i in s]) D = np.linalg.det(A1) if D == 0.0: continue x = np.linalg.solve(A1, v1) if np.any(x < -2): continue cand.append(x.astype(np.int64)) ans = 0 nums = (a,b,c,d,e) for x in cand: for eps in itertools.product(range(-2,3), repeat=5): y = x + np.array(eps) if np.any(y < 0): continue ok = True for i in range(5): if y[i] + y[(i-1)%5] + y[(i+1)%5] > nums[i]: ok = False break if ok: ans = max(ans, y.sum()) print(ans)