結果

問題 No.2806 Cornflake Man
ユーザー Yukino DX.Yukino DX.
提出日時 2024-07-16 21:04:36
言語 Rust
(1.77.0)
結果
AC  
実行時間 59 ms / 2,000 ms
コード長 841 bytes
コンパイル時間 14,495 ms
コンパイル使用メモリ 385,596 KB
実行使用メモリ 12,936 KB
最終ジャッジ日時 2024-07-17 20:28:36
合計ジャッジ時間 15,254 ms
ジャッジサーバーID
(参考情報)
judge5 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 25 ms
7,640 KB
testcase_01 AC 42 ms
11,704 KB
testcase_02 AC 6 ms
6,940 KB
testcase_03 AC 45 ms
11,796 KB
testcase_04 AC 6 ms
6,944 KB
testcase_05 AC 9 ms
6,944 KB
testcase_06 AC 17 ms
6,940 KB
testcase_07 AC 51 ms
12,156 KB
testcase_08 AC 15 ms
6,944 KB
testcase_09 AC 27 ms
7,156 KB
testcase_10 AC 17 ms
6,940 KB
testcase_11 AC 3 ms
6,944 KB
testcase_12 AC 22 ms
6,944 KB
testcase_13 AC 44 ms
11,124 KB
testcase_14 AC 9 ms
6,940 KB
testcase_15 AC 59 ms
12,936 KB
testcase_16 AC 1 ms
6,944 KB
testcase_17 AC 1 ms
6,940 KB
testcase_18 AC 1 ms
6,940 KB
testcase_19 AC 1 ms
6,940 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

use std::collections::HashMap;

use proconio::input;

fn main() {
    input! {
        n:usize,
        m:usize,
        mut a:[usize;n],
    }

    a.sort();
    let mut poss = HashMap::new();
    for i in 0..n {
        poss.insert(a[i], i);
    }

    let mut seen = vec![false; n];
    seen[0] = true;
    let mut ans = vec![];
    for i in 1..n {
        if seen[i] {
            continue;
        }

        if m / a[i] > n {
            println!("-1");
            return;
        }

        for j in (1..).take_while(|&j| j * a[i] <= m) {
            let Some(pos)=poss.get(&(j*a[i]))else{
                println!("-1");
                return;
            };

            seen[*pos] = true;
        }
        ans.push(a[i]);
    }

    println!("{}", ans.len());
    for i in ans {
        print!("{} ", i);
    }
    println!()
}
0