結果
問題 | No.545 ママの大事な二人の子供 |
ユーザー |
![]() |
提出日時 | 2023-01-11 00:13:59 |
言語 | D (dmd 2.109.1) |
結果 |
WA
|
実行時間 | - |
コード長 | 871 bytes |
コンパイル時間 | 1,903 ms |
コンパイル使用メモリ | 210,392 KB |
実行使用メモリ | 577,796 KB |
最終ジャッジ日時 | 2024-06-22 17:17:25 |
合計ジャッジ時間 | 6,079 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 7 WA * 11 MLE * 1 -- * 13 |
ソースコード
import std;void main() {long n;readf("%d\n", n);bool[long] L, R;L[0] = R[0] = true;foreach (i; 0 .. n) {long A, B;readf("%d %d\n", A, B);bool[long] nxt;if (i < n / 2) {foreach (l; L.byKey) {nxt[l+A] = nxt[l+B] = true;nxt[l-A] = nxt[l-B] = true;}L = nxt;}else {foreach (r; R.byKey) {nxt[r+A] = nxt[r+B] = true;nxt[r-A] = nxt[r-B] = true;}R = nxt;}}auto S = R.keys.sort;long res = long.max;foreach (l; L.byKey) {auto lb = S.lowerBound(l+1);if (!lb.empty) res = min(res, l-lb.back);auto ub = S.upperBound(l-1);if (!ub.empty) res = min(res, ub.front-l);}res.writeln;}