結果

問題 No.1053 ゲーミング棒
ユーザー tabataba
提出日時 2024-08-05 17:16:38
言語 Rust
(1.77.0)
結果
WA  
実行時間 -
コード長 875 bytes
コンパイル時間 11,753 ms
コンパイル使用メモリ 395,564 KB
実行使用メモリ 6,944 KB
最終ジャッジ日時 2024-08-05 17:16:54
合計ジャッジ時間 13,122 ms
ジャッジサーバーID
(参考情報)
judge2 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
6,816 KB
testcase_01 AC 1 ms
6,816 KB
testcase_02 AC 1 ms
6,820 KB
testcase_03 WA -
testcase_04 WA -
testcase_05 AC 1 ms
6,944 KB
testcase_06 AC 1 ms
6,940 KB
testcase_07 AC 1 ms
6,940 KB
testcase_08 AC 1 ms
6,944 KB
testcase_09 AC 1 ms
6,944 KB
testcase_10 AC 1 ms
6,944 KB
testcase_11 WA -
testcase_12 WA -
testcase_13 AC 1 ms
6,940 KB
testcase_14 AC 1 ms
6,940 KB
testcase_15 AC 1 ms
6,940 KB
testcase_16 AC 1 ms
6,940 KB
testcase_17 AC 1 ms
6,944 KB
testcase_18 AC 1 ms
6,940 KB
testcase_19 AC 1 ms
6,940 KB
testcase_20 AC 1 ms
6,944 KB
testcase_21 AC 1 ms
6,940 KB
testcase_22 AC 1 ms
6,940 KB
testcase_23 AC 5 ms
6,944 KB
testcase_24 AC 6 ms
6,944 KB
testcase_25 AC 5 ms
6,940 KB
testcase_26 WA -
testcase_27 AC 1 ms
6,940 KB
testcase_28 AC 1 ms
6,944 KB
testcase_29 AC 1 ms
6,940 KB
testcase_30 AC 3 ms
6,944 KB
testcase_31 AC 3 ms
6,940 KB
testcase_32 AC 3 ms
6,944 KB
testcase_33 AC 2 ms
6,944 KB
testcase_34 AC 3 ms
6,944 KB
testcase_35 AC 4 ms
6,940 KB
testcase_36 AC 4 ms
6,944 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
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;
        }
    }
    let mut count = vec![0; 100000 + 1];
    a.iter().for_each(|x| count[*x as usize] += 1);
    let mut count_2 = 0;
    for c in count {
        if c == 2 {
            count_2 += 1;
        } else if c > 2 {
            println!("-1");
            return;
        }
    }
    if count_2 == 0 {
        println!("0");
    } else if count_2 == 1 {
        println!("1");
    } else {
        println!("-1");
    }
}
0