結果

問題 No.1569 Nixoracci's Number
ユーザー flippergoflippergo
提出日時 2024-10-13 14:01:09
言語 Rust
(1.77.0 + proconio)
結果
RE  
実行時間 -
コード長 1,759 bytes
コンパイル時間 11,579 ms
コンパイル使用メモリ 386,416 KB
実行使用メモリ 6,824 KB
最終ジャッジ日時 2024-10-13 14:01:24
合計ジャッジ時間 12,789 ms
ジャッジサーバーID
(参考情報)
judge4 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
5,248 KB
testcase_01 AC 1 ms
5,248 KB
testcase_02 AC 0 ms
5,248 KB
testcase_03 RE -
testcase_04 RE -
testcase_05 RE -
testcase_06 RE -
testcase_07 RE -
testcase_08 RE -
testcase_09 RE -
testcase_10 RE -
testcase_11 RE -
testcase_12 RE -
testcase_13 RE -
testcase_14 RE -
testcase_15 RE -
testcase_16 RE -
testcase_17 RE -
testcase_18 RE -
testcase_19 RE -
testcase_20 RE -
testcase_21 RE -
testcase_22 RE -
testcase_23 RE -
権限があれば一括ダウンロードができます
コンパイルメッセージ
warning: variable `X` should have a snake case name
 --> src/main.rs:3:11
  |
3 | fn matmul(X: &Vec<Vec<i32>>, Y: &Vec<Vec<i32>>, N: usize) -> Vec<Vec<i32>> {
  |           ^ help: convert the identifier to snake case (notice the capitalization): `x`
  |
  = note: `#[warn(non_snake_case)]` on by default

warning: variable `Y` should have a snake case name
 --> src/main.rs:3:30
  |
3 | fn matmul(X: &Vec<Vec<i32>>, Y: &Vec<Vec<i32>>, N: usize) -> Vec<Vec<i32>> {
  |                              ^ help: convert the identifier to snake case (notice the capitalization): `y`

warning: variable `N` should have a snake case name
 --> src/main.rs:3:49
  |
3 | fn matmul(X: &Vec<Vec<i32>>, Y: &Vec<Vec<i32>>, N: usize) -> Vec<Vec<i32>> {
  |                                                 ^ help: convert the identifier to snake case: `n`

warning: variable `Z` should have a snake case name
 --> src/main.rs:4:13
  |
4 |     let mut Z = vec![vec![0; N]; N];
  |             ^ help: convert the identifier to snake case (notice the capitalization): `z`

warning: variable `X` should have a snake case name
  --> src/main.rs:15:11
   |
15 | fn matpow(X: &Vec<Vec<i32>>, k: i32, N: usize) -> Vec<Vec<i32>> {
   |           ^ help: convert the identifier to snake case (notice the capitalization): `x`

warning: variable `N` should have a snake case name
  --> src/main.rs:15:38
   |
15 | fn matpow(X: &Vec<Vec<i32>>, k: i32, N: usize) -> Vec<Vec<i32>> {
   |                                      ^ help: convert the identifier to snake case: `n`

warning: variable `I` should have a snake case name
  --> src/main.rs:16:13
   |
16 |     let mut I = vec![vec![0; N]; N];
   |             ^ help: convert the identifier to snake case (notice the capitalization): `i`

warning: variable `Y` should have a snake case name
  --> src/main.rs:32:13
   |
32 |         let Y = matmul(&half_pow, &half_pow, N);
   |             ^ help: convert the identifier to snake case (notice the capitalization): `y`

warnin

ソースコード

diff #

use std::io;

fn matmul(X: &Vec<Vec<i32>>, Y: &Vec<Vec<i32>>, N: usize) -> Vec<Vec<i32>> {
    let mut Z = vec![vec![0; N]; N];
    for i in 0..N {
        for j in 0..N {
            for k in 0..N {
                Z[i][j] ^= X[i][k] * Y[k][j];  // XOR 演算
            }
        }
    }
    Z
}

fn matpow(X: &Vec<Vec<i32>>, k: i32, N: usize) -> Vec<Vec<i32>> {
    let mut I = vec![vec![0; N]; N];
    for i in 0..N {
        I[i][i] = 1;  // 単位行列
    }

    if k == 0 {
        return I;
    } else if k == 1 {
        return X.clone();
    }

    if k % 2 == 0 {
        let half_pow = matpow(X, k / 2, N);
        return matmul(&half_pow, &half_pow, N);
    } else {
        let half_pow = matpow(X, (k - 1) / 2, N);
        let Y = matmul(&half_pow, &half_pow, N);
        return matmul(X, &Y, N);
    }
}

fn main() {
    let mut input = String::new();
    io::stdin().read_line(&mut input).expect("Failed to read line");
    let mut input_iter = input.split_whitespace();
    let N: usize = input_iter.next().unwrap().parse().unwrap();
    let K: i32 = input_iter.next().unwrap().parse().unwrap();

    let mut A = vec![];
    input.clear();
    io::stdin().read_line(&mut input).expect("Failed to read line");
    for num in input.split_whitespace() {
        A.push(num.parse::<i32>().unwrap());
    }

    let T = N + 1;
    let M = (K - 1) % T as i32;

    let mut A1 = vec![vec![0; N]; N];

    // A1行列の初期化
    for i in 0..(N - 1) {
        A1[i][i + 1] = 1;
    }
    for j in 0..N {
        A1[N - 1][j] = 1;
    }

    // A1をM回累乗した行列を計算
    let B = matpow(&A1, M, N);

    // 答えを計算
    let mut ans = 0;
    for i in 0..N {
        ans ^= B[0][i] * A[i];
    }

    println!("{}", ans);
}
0