結果
| 問題 | No.115 遠足のおやつ |
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2026-02-11 14:25:17 |
| 言語 | Rust (1.93.0 + proconio + num + itertools) |
| 結果 |
AC
|
| 実行時間 | 15 ms / 5,000 ms |
| コード長 | 1,748 bytes |
| 記録 | |
| コンパイル時間 | 1,642 ms |
| コンパイル使用メモリ | 207,436 KB |
| 実行使用メモリ | 7,844 KB |
| 最終ジャッジ日時 | 2026-02-11 14:25:22 |
| 合計ジャッジ時間 | 4,193 ms |
|
ジャッジサーバーID (参考情報) |
judge5 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 40 |
ソースコード
fn main() {
let stdin = std::io::read_to_string(std::io::stdin().lock()).unwrap();
let mut stdin = stdin.split_ascii_whitespace();
let n: usize = stdin.next().unwrap().parse().unwrap();
let d: usize = stdin.next().unwrap().parse().unwrap();
let k: usize = stdin.next().unwrap().parse().unwrap();
use std::io::Write;
std::io::stdout()
.lock()
.write_all(output(solve(n, d, k)).as_bytes())
.unwrap();
}
fn solve(n: usize, d: usize, k: usize) -> Option<Vec<u16>> {
let mut dp = vec![vec![0_u16; d + 1]; n + 1];
dp[n][d] = 1 << k;
(1..=n).rev().for_each(|i| {
let (dp_former, dp_latter) = dp.split_at_mut(i);
let (dp_next, dp_cur) = (dp_former.last_mut().unwrap(), dp_latter.first().unwrap());
dp_next.copy_from_slice(dp_cur);
(i..=d).for_each(|j| dp_next[j - i] |= dp_cur[j] >> 1);
});
if dp[0][0] & 1 == 0 {
return None;
}
let mut d = 0;
let mut k = 0;
Some(
dp.into_iter()
.enumerate()
.skip(1)
.filter_map(|(i, dp)| match dp.get(d + i) {
Some(&s) => match (s >> (k + 1)) & 1 {
0 => None,
1 => {
d += i;
k += 1;
Some(i as u16)
}
_ => unreachable!(),
},
None => None,
})
.collect(),
)
}
fn output(ans: Option<Vec<u16>>) -> String {
match ans {
Some(ans) => ans
.into_iter()
.map(|x| x.to_string())
.collect::<Vec<_>>()
.join(" ") + "\n",
None => String::from("-1\n"),
}
}