結果
問題 |
No.2918 Divide Applicants Fairly
|
ユーザー |
|
提出日時 | 2024-10-10 20:13:02 |
言語 | Rust (1.83.0 + proconio) |
結果 |
WA
|
実行時間 | - |
コード長 | 716 bytes |
コンパイル時間 | 13,101 ms |
コンパイル使用メモリ | 391,596 KB |
実行使用メモリ | 549,348 KB |
最終ジャッジ日時 | 2024-10-10 20:13:26 |
合計ジャッジ時間 | 17,071 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 1 WA * 2 |
other | MLE * 1 -- * 60 |
ソースコード
use proconio::input; use std::collections::HashSet; fn main() { input! { n: usize, rating: [i64; n], } let mut ans = (0 .. n / 2).map(|i| rating[i * 2] - rating[i * 2 + 1] ).sum::<i64>().abs(); let mut dp = HashSet::<(i32, i64)>::new(); let mut add = vec![]; for &r in &rating { add.push((1i32, r)); add.push((-1i32, -r)); for &(x, y) in &dp { if (x + 1i32).abs() <= n as i32 / 2 && (y + r).abs() <= ans { add.push((x + 1, y + r)); } if (x - 1i32).abs() <= n as i32 / 2 && (y - r).abs() <= ans { add.push((x - 1, y - r)); } } for x in add.drain(..) { dp.insert(x); } } for (x, y) in dp { if x == 0 { ans = ans.min(y.abs()); } } println!("{ans}"); }