結果
問題 | No.1569 Nixoracci's Number |
ユーザー | flippergo |
提出日時 | 2024-10-13 14:03:58 |
言語 | Rust (1.77.0 + proconio) |
結果 |
AC
|
実行時間 | 148 ms / 2,000 ms |
コード長 | 1,824 bytes |
コンパイル時間 | 19,851 ms |
コンパイル使用メモリ | 376,236 KB |
実行使用メモリ | 5,248 KB |
最終ジャッジ日時 | 2024-10-13 14:04:21 |
合計ジャッジ時間 | 16,083 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge5 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 1 ms
5,248 KB |
testcase_01 | AC | 1 ms
5,248 KB |
testcase_02 | AC | 1 ms
5,248 KB |
testcase_03 | AC | 1 ms
5,248 KB |
testcase_04 | AC | 75 ms
5,248 KB |
testcase_05 | AC | 6 ms
5,248 KB |
testcase_06 | AC | 148 ms
5,248 KB |
testcase_07 | AC | 1 ms
5,248 KB |
testcase_08 | AC | 16 ms
5,248 KB |
testcase_09 | AC | 1 ms
5,248 KB |
testcase_10 | AC | 6 ms
5,248 KB |
testcase_11 | AC | 17 ms
5,248 KB |
testcase_12 | AC | 52 ms
5,248 KB |
testcase_13 | AC | 76 ms
5,248 KB |
testcase_14 | AC | 10 ms
5,248 KB |
testcase_15 | AC | 89 ms
5,248 KB |
testcase_16 | AC | 14 ms
5,248 KB |
testcase_17 | AC | 6 ms
5,248 KB |
testcase_18 | AC | 27 ms
5,248 KB |
testcase_19 | AC | 3 ms
5,248 KB |
testcase_20 | AC | 34 ms
5,248 KB |
testcase_21 | AC | 56 ms
5,248 KB |
testcase_22 | AC | 16 ms
5,248 KB |
testcase_23 | AC | 94 ms
5,248 KB |
コンパイルメッセージ
warning: variable `X` should have a snake case name --> src/main.rs:3:11 | 3 | fn matmul(X: &Vec<Vec<i64>>, Y: &Vec<Vec<i64>>, N: usize) -> Vec<Vec<i64>> { | ^ 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<i64>>, Y: &Vec<Vec<i64>>, N: usize) -> Vec<Vec<i64>> { | ^ 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<i64>>, Y: &Vec<Vec<i64>>, N: usize) -> Vec<Vec<i64>> { | ^ 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<i64>>, k: i64, N: usize) -> Vec<Vec<i64>> { | ^ 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<i64>>, k: i64, N: usize) -> Vec<Vec<i64>> { | ^ 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
ソースコード
use std::io; fn matmul(X: &Vec<Vec<i64>>, Y: &Vec<Vec<i64>>, N: usize) -> Vec<Vec<i64>> { 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<i64>>, k: i64, N: usize) -> Vec<Vec<i64>> { 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().expect("Failed to parse N"); let K: i64 = input_iter.next().unwrap().parse().expect("Failed to parse K"); 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::<i64>().expect("Failed to parse A element")); } let T = N + 1; let M = (K - 1) % T as i64; 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); }