結果
問題 |
No.2918 Divide Applicants Fairly
|
ユーザー |
|
提出日時 | 2024-10-10 12:52:16 |
言語 | Rust (1.83.0 + proconio) |
結果 |
WA
|
実行時間 | - |
コード長 | 740 bytes |
コンパイル時間 | 15,009 ms |
コンパイル使用メモリ | 378,464 KB |
実行使用メモリ | 564,816 KB |
最終ジャッジ日時 | 2024-10-10 12:52:35 |
合計ジャッジ時間 | 16,450 ms |
ジャッジサーバーID (参考情報) |
judge1 / 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 = (rating[.. n / 2].iter().sum::<i64>() - rating[n / 2 .. n - n % 2].iter().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 * 2 { add.push((x + 1, y + r)); } if (x - 1i32).abs() <= n as i32 / 2 && (y - r).abs() < ans * 2 { 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}"); }