結果
| 問題 | No.1569 Nixoracci's Number |
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2024-10-13 14:03:58 |
| 言語 | Rust (1.83.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 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 21 |
コンパイルメッセージ
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);
}