結果

問題 No.1053 ゲーミング棒
ユーザー taba
提出日時 2024-08-05 17:10:47
言語 Rust
(1.83.0 + proconio)
結果
TLE  
実行時間 -
コード長 686 bytes
コンパイル時間 13,059 ms
コンパイル使用メモリ 395,420 KB
実行使用メモリ 14,016 KB
最終ジャッジ日時 2024-08-05 17:11:14
合計ジャッジ時間 18,202 ms
ジャッジサーバーID
(参考情報)
judge5 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 20 TLE * 3 -- * 11
権限があれば一括ダウンロードができます
コンパイルメッセージ
warning: unused imports: `HashMap`, `HashSet`
 --> src/main.rs:1:24
  |
1 | use std::collections::{HashMap, HashSet};
  |                        ^^^^^^^  ^^^^^^^
  |
  = note: `#[warn(unused_imports)]` on by default

ソースコード

diff #

use std::collections::{HashMap, HashSet};

fn main() {
    proconio::input! {
        n: usize,
        mut a: [u32; n],
    }
    // remove duplicates
    loop {
        let a_len = a.len();
        a = a
            .iter()
            .copied()
            .enumerate()
            .filter(|(i, _)| *i == a.len() - 1 || a[*i] != a[*i + 1])
            .map(|x| x.1)
            .collect();
        if a.len() == a_len {
            break;
        }
    }
    eprintln!("{a:?}");
    match a.iter().map(|x| a.iter().filter(|&y| y == x).count()).max() {
        Some(1) => println!("0"),
        Some(2) if a[0] == a[a.len() - 1] => println!("1"),
        _ => println!("-1"),
    }
}
0