結果

問題 No.183 たのしい排他的論理和(EASY)
コンテスト
ユーザー gemmaro
提出日時 2020-11-04 09:49:13
言語 Rust
(1.94.0 + proconio + num + itertools)
コンパイル:
/usr/bin/rustc_custom
実行:
./target/release/main
結果
CE  
(最新)
AC  
(最初)
実行時間 -
コード長 789 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 1,189 ms
コンパイル使用メモリ 154,740 KB
最終ジャッジ日時 2026-04-03 08:28:59
合計ジャッジ時間 7,011 ms
ジャッジサーバーID
(参考情報)
judge4_0 / judge3_0
このコードへのチャレンジ
(要ログイン)
コンパイルエラー時のメッセージ・ソースコードは、提出者また管理者しか表示できないようにしております。(リジャッジ後のコンパイルエラーは公開されます)
ただし、clay言語の場合は開発者のデバッグのため、公開されます。

コンパイルメッセージ
error: cannot explicitly dereference within an implicitly-borrowing pattern
  --> src/main.rs:26:69
   |
26 |         for (i, _) in x_arry.clone().iter().enumerate().filter(|(_, &b)| b) {
   |                                                                     ^ reference pattern not allowed when implicitly borrowing
   |
   = note: for more information, see <https://doc.rust-lang.org/reference/patterns.html#binding-modes>
note: matching on a reference type with a non-reference pattern implicitly borrows the contents
  --> src/main.rs:26:65
   |
26 |         for (i, _) in x_arry.clone().iter().enumerate().filter(|(_, &b)| b) {
   |                                                                 ^^^^^^^ this non-reference pattern matches on a reference type `&_`
help: match on the reference with a reference pattern to avoid implicitly borrowing
   |
26 |         for (i, _) in x_arry.clone().iter().enumerate().filter(|&(_, &b)| b) {
   |                                                                 +

error: could not compile `main` (bin "main") due to 1 previous error

ソースコード

diff #
raw source code

use std::{convert::TryInto, io::stdin, ops::BitXor};

fn main() {
    let _n = {
        let mut buf = String::new();
        stdin().read_line(&mut buf).unwrap();
    };

    let a_arry = {
        let mut buf = String::new();
        stdin().read_line(&mut buf).unwrap();

        buf.split_whitespace()
            .map(|s| s.parse::<u16>().unwrap())
            .collect()
    };

    println!("{}", solve(a_arry));
}

fn solve(a_arry: Vec<u16>) -> u16 {
    let mut x_arry = [false; 2 << 14];
    x_arry[0] = true;

    for a in a_arry.iter() {
        for (i, _) in x_arry.clone().iter().enumerate().filter(|(_, &b)| b) {
            let i = (i as u16).bitxor(a);
            x_arry[i as usize] = true;
        }
    }

    x_arry.iter().filter(|&&x| x).count().try_into().unwrap()
}
0