提出 #29623918
ソースコード 拡げる
use proconio::input;
type Matrix = Vec<Vec<usize>>;
fn mul(a: Matrix, b: Matrix) -> Matrix {
let h = a.len();
let w = b[0].len();
if a[0].len() != b.len() {
unreachable!();
}
let len = b.len();
let mut ab = vec![vec![0; w]; h];
for r in 0..h {
for c in 0..w {
for i in 0..len {
ab[r][c] += a[r][i] * b[i][c];
ab[r][c] %= 1_000_000_000;
}
}
}
ab
}
fn pow(a: Matrix, n: usize) -> Matrix {
let mut p = vec![vec![1, 0], vec![0, 1]];
let mut q = a;
for i in 0..60 {
if (n & (1 << i)) != 0 {
p = mul(p, q.clone());
}
q = mul(q.clone(), q);
}
p
}
fn resolve(n: usize) -> usize {
let m = vec![vec![1, 1], vec![1, 0]];
let x = pow(m, n - 1);
(x[1][0] + x[1][1]) % 1_000_000_000
}
fn main() {
input! {
n: usize,
};
let ans = resolve(n);
println!("{}", ans);
}
提出情報
ジャッジ結果
| セット名 |
Sample |
All |
| 得点 / 配点 |
0 / 0 |
1000 / 1000 |
| 結果 |
|
|
| セット名 |
テストケース |
| Sample |
sample_01.txt, sample_02.txt |
| All |
sample_01.txt, sample_02.txt, test_01.txt, test_02.txt, test_03.txt, test_04.txt, test_05.txt, test_06.txt, test_07.txt, test_08.txt |
| ケース名 |
結果 |
実行時間 |
メモリ |
| sample_01.txt |
AC |
7 ms |
2124 KiB |
| sample_02.txt |
AC |
3 ms |
2128 KiB |
| test_01.txt |
AC |
2 ms |
2036 KiB |
| test_02.txt |
AC |
1 ms |
1976 KiB |
| test_03.txt |
AC |
2 ms |
2116 KiB |
| test_04.txt |
AC |
2 ms |
1984 KiB |
| test_05.txt |
AC |
2 ms |
2056 KiB |
| test_06.txt |
AC |
1 ms |
2100 KiB |
| test_07.txt |
AC |
2 ms |
2128 KiB |
| test_08.txt |
AC |
2 ms |
2044 KiB |