結果
| 問題 |
No.2542 Yokan for Two
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2023-11-25 14:34:43 |
| 言語 | D (dmd 2.109.1) |
| 結果 |
AC
|
| 実行時間 | 10 ms / 2,000 ms |
| コード長 | 1,076 bytes |
| コンパイル時間 | 5,654 ms |
| コンパイル使用メモリ | 174,080 KB |
| 実行使用メモリ | 5,376 KB |
| 最終ジャッジ日時 | 2024-09-26 10:45:01 |
| 合計ジャッジ時間 | 6,043 ms |
|
ジャッジサーバーID (参考情報) |
judge2 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 4 |
| other | AC * 40 |
ソースコード
import std;
void main () {
int L, N; readln.read(L, N);
int[] X = 0 ~ readln.split.to!(int[]) ~ L;
solve(L, N, X);
}
void solve (int L, int N, int[] X) {
/*
最初と最後だけとる人が固定だが、それら以外に関しては
実は好きなようにパーツを割り振ることができる(ここが難所)
あとは部分和問題でO(NL)
*/
bool[] dp = new bool[](L+1);
int[] lens = new int[](N+1);
foreach (i; 0..N+1) lens[i] = X[i+1] - X[i];
int[] A = lens[1..$-1];
dp[] = false;
dp[0] = true;
foreach (a; A) {
for (int i = L; 0 <= i; i--) {
if (dp[i] && i+a <= L) dp[i+a] = true;
}
}
int ans = 10^^7;
for (int i = 0; i <= L; i++) {
if (dp[i] && abs(L-(i+lens[0]) - (i+lens[0])) < abs(L-(ans+lens[0]) - (ans+lens[0]))) ans = i;
}
ans += lens[0];
writeln(abs(L-ans - ans));
}
void read (T...) (string S, ref T args) {
auto buf = S.split;
foreach (i, ref arg; args) {
arg = buf[i].to!(typeof(arg));
}
}