結果

問題 No.5001 排他的論理和でランニング
ユーザー ジョギングジョギング
提出日時 2018-03-17 01:07:17
言語 Rust
(1.77.0)
結果
AC  
実行時間 77 ms / 1,500 ms
コード長 1,430 bytes
コンパイル時間 1,188 ms
実行使用メモリ 24,796 KB
スコア 25,033,575
最終ジャッジ日時 2020-03-12 19:49:05
ジャッジサーバーID
(参考情報)
judge8 /
純コード判定しない問題か言語
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 71 ms
24,408 KB
testcase_01 AC 11 ms
6,148 KB
testcase_02 AC 18 ms
7,604 KB
testcase_03 AC 37 ms
12,836 KB
testcase_04 AC 77 ms
24,796 KB
testcase_05 AC 28 ms
9,456 KB
testcase_06 AC 44 ms
16,956 KB
testcase_07 AC 51 ms
18,748 KB
testcase_08 AC 71 ms
20,724 KB
testcase_09 AC 2 ms
5,380 KB
testcase_10 AC 24 ms
7,916 KB
testcase_11 AC 33 ms
10,824 KB
testcase_12 AC 22 ms
9,036 KB
testcase_13 AC 69 ms
21,324 KB
testcase_14 AC 44 ms
14,852 KB
testcase_15 AC 26 ms
9,684 KB
testcase_16 AC 12 ms
5,480 KB
testcase_17 AC 19 ms
7,072 KB
testcase_18 AC 42 ms
13,728 KB
testcase_19 AC 30 ms
11,164 KB
testcase_20 AC 21 ms
8,088 KB
testcase_21 AC 21 ms
7,552 KB
testcase_22 AC 8 ms
5,380 KB
testcase_23 AC 6 ms
5,384 KB
testcase_24 AC 26 ms
10,956 KB
testcase_25 AC 57 ms
22,152 KB
testcase_26 AC 48 ms
19,124 KB
testcase_27 AC 31 ms
12,804 KB
testcase_28 AC 51 ms
17,604 KB
testcase_29 AC 58 ms
20,840 KB
testcase_30 AC 10 ms
5,380 KB
testcase_31 AC 46 ms
15,776 KB
testcase_32 AC 21 ms
7,932 KB
testcase_33 AC 74 ms
22,876 KB
testcase_34 AC 76 ms
24,724 KB
testcase_35 AC 48 ms
16,840 KB
testcase_36 AC 69 ms
23,220 KB
testcase_37 AC 51 ms
19,316 KB
testcase_38 AC 21 ms
8,356 KB
testcase_39 AC 28 ms
9,508 KB
testcase_40 AC 35 ms
12,956 KB
testcase_41 AC 10 ms
5,380 KB
testcase_42 AC 32 ms
10,928 KB
testcase_43 AC 37 ms
12,660 KB
testcase_44 AC 60 ms
21,048 KB
testcase_45 AC 65 ms
22,848 KB
testcase_46 AC 62 ms
23,020 KB
testcase_47 AC 30 ms
10,752 KB
testcase_48 AC 22 ms
8,472 KB
testcase_49 AC 63 ms
18,716 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
warning: variable `v` is assigned to, but never used
  --> Main.rs:28:13
   |
28 |     let mut v = 0;
   |             ^
   |
   = note: `#[warn(unused_variables)]` on by default
   = note: consider using `_v` instead

ソースコード

diff #

use std::io::{stdin, Read};

fn main() {
    let mut buf = String::new();
    stdin().read_to_string(&mut buf).unwrap();
    let mut buf = buf.split_whitespace();
    let mut get = || buf.next().unwrap().parse::<i32>().unwrap();
    
    let n = get() as usize;
    let m = get() as usize;
    let mut xs = vec![];
    let mut ys = vec![vec![]; 32];
    let mut zs = vec![vec![]; n];
    for _ in 0..n { xs.push(get()); }
    xs.sort();
    for j in 0..n {
        let x = xs[j];
        for i in 0..32 {
            if (x & (1 << i)) > 0 {
                ys[i].push(j);
                zs[j].push(i);
            }
        }
    }
    let mut fs = vec![false; n];
    let mut bs = vec![0; 32];
    let mut ans = vec![];
    let mut v = 0;
    for i in 0..32 {
        let i = 31 - i;
        for &j in ys[i].iter() {
            if fs[j] { continue; }
            let x = xs[j];
            fs[j] = true;
            v |= x;
            ans.push(x);
            for &k in zs[j].iter() {
                bs[k] += 1;
            }
        }
    }
    for i in 0..n {
        if fs[i] { continue; }
        let x = xs[i];
        fs[i] = true;
        v |= x;
        ans.push(x);
        for &k in zs[i].iter() {
            bs[k] += 1;
        }
    }
    
    output(m, &ans);
}
fn output(m: usize, ans: &Vec<i32>) {
    for i in 0..m {
        if i > 0 { print!(" "); }
        print!("{}", ans[i]);
    }
    println!();   
}
0