結果
問題 | No.90 品物の並び替え |
ユーザー |
![]() |
提出日時 | 2022-12-21 19:27:39 |
言語 | Rust (1.83.0 + proconio) |
結果 |
AC
|
実行時間 | 51 ms / 5,000 ms |
コード長 | 1,269 bytes |
コンパイル時間 | 12,301 ms |
コンパイル使用メモリ | 402,832 KB |
実行使用メモリ | 6,820 KB |
最終ジャッジ日時 | 2024-11-18 02:57:43 |
合計ジャッジ時間 | 13,233 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 1 |
other | AC * 9 |
ソースコード
trait NextPermutation {fn next_permutation(&mut self) -> bool;}impl<T: PartialOrd> NextPermutation for Vec<T> {fn next_permutation(&mut self) -> bool {self.windows(2).rposition(|x| x[0] < x[1]).map_or(false, |i| {let j = self.iter().rposition(|x| x > &self[i]).unwrap();self.swap(i, j);self[i + 1..].reverse();true})}}fn main() {let mut xx = String::new();std::io::Read::read_to_string(&mut std::io::stdin(), &mut xx).ok();let xx: Vec<usize> = xx.split_whitespace().flat_map(str::parse).collect();let n = xx[0];let mut scores = vec![];for x in xx[2..].chunks(3) {scores.push((x[0], x[1], x[2]));}let mut items: Vec<usize> = (0..n).collect();let mut max = 0;loop {let mut idx = vec![0; n];for (i, &item) in items.iter().enumerate() {idx[item] = i;}let mut score = 0;for &(i, j, s) in &scores {if idx[i] < idx[j] {score += s;}}max = max.max(score);if !items.next_permutation() {break;}}println!("{max}");}