結果
問題 | No.526 フィボナッチ数列の第N項をMで割った余りを求める |
ユーザー | kei |
提出日時 | 2019-08-06 16:07:44 |
言語 | Rust (1.77.0 + proconio) |
結果 |
AC
|
実行時間 | 1 ms / 2,000 ms |
コード長 | 4,783 bytes |
コンパイル時間 | 12,212 ms |
コンパイル使用メモリ | 382,200 KB |
実行使用メモリ | 6,944 KB |
最終ジャッジ日時 | 2024-07-18 14:05:00 |
合計ジャッジ時間 | 13,135 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge4 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 1 ms
6,812 KB |
testcase_01 | AC | 0 ms
6,812 KB |
testcase_02 | AC | 1 ms
6,812 KB |
testcase_03 | AC | 1 ms
6,816 KB |
testcase_04 | AC | 1 ms
6,940 KB |
testcase_05 | AC | 1 ms
6,940 KB |
testcase_06 | AC | 1 ms
6,940 KB |
testcase_07 | AC | 1 ms
6,940 KB |
testcase_08 | AC | 1 ms
6,940 KB |
testcase_09 | AC | 1 ms
6,940 KB |
testcase_10 | AC | 1 ms
6,940 KB |
testcase_11 | AC | 1 ms
6,944 KB |
testcase_12 | AC | 1 ms
6,940 KB |
testcase_13 | AC | 1 ms
6,944 KB |
testcase_14 | AC | 1 ms
6,940 KB |
コンパイルメッセージ
warning: unused variable: `i` --> src/main.rs:35:9 | 35 | for i in 0usize..A.len() { | ^ help: if this is intentional, prefix it with an underscore: `_i` | = note: `#[warn(unused_variables)]` on by default warning: unused variable: `v` --> src/main.rs:36:57 | 36 | let mut c: Vec<i64> = (0usize..B[0].len()).map(|v| 0i64).collect(); | ^ help: if this is intentional, prefix it with an underscore: `_v` warning: unused variable: `i` --> src/main.rs:61:9 | 61 | for i in 0usize..A.len() { | ^ help: if this is intentional, prefix it with an underscore: `_i` warning: unused variable: `v` --> src/main.rs:62:54 | 62 | let mut b: Vec<i64> = (0usize..A.len()).map(|v| 0i64).collect(); | ^ help: if this is intentional, prefix it with an underscore: `_v`
ソースコード
#![allow(unused_mut, non_snake_case, unused_imports, dead_code,unused_macros)] use std::iter; use std::cmp::{max, min, Ordering}; use std::mem::swap; use std::collections::{HashMap, BTreeMap, HashSet, BTreeSet, BinaryHeap, VecDeque}; use std::iter::FromIterator; // 高速 EOF要 //macro_rules! input {(source = $s:expr, $($r:tt)*) => {let mut iter = $s.split_whitespace();input_inner!{iter, $($r)*}};($($r:tt)*) => {let mut s = {use std::io::Read;let mut s = String::new();std::io::stdin().read_to_string(&mut s).unwrap();s};let mut iter = s.split_whitespace();input_inner!{iter, $($r)*}};} //macro_rules! input_inner {($iter:expr) => {};($iter:expr, ) => {};($iter:expr, $var:ident : $t:tt $($r:tt)*) => {let $var = read_value!($iter, $t);input_inner!{$iter $($r)*}};} //macro_rules! read_value {($iter:expr, ( $($t:tt),* )) => {( $(read_value!($iter, $t)),* )};($iter:expr, [ $t:tt ; $len:expr ]) => {(0..$len).map(|_| read_value!($iter, $t)).collect::<Vec<_>>()};($iter:expr, chars) => {read_value!($iter, String).chars().collect::<Vec<char>>()};($iter:expr, usize1) => {read_value!($iter, usize) - 1};($iter:expr, $t:ty) => {$iter.next().unwrap().parse::<$t>().expect("Parse error")};} // 低速 EOF不要 macro_rules! input {(source = $s:expr, $($r:tt)*) => {let mut iter = $s.split_whitespace();let mut next = || { iter.next().unwrap() };input_inner!{next, $($r)*}};($($r:tt)*) => {let stdin = std::io::stdin();let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));let mut next = move || -> String{bytes.by_ref().map(|r|r.unwrap() as char).skip_while(|c|c.is_whitespace()).take_while(|c|!c.is_whitespace()).collect()};input_inner!{next, $($r)*}};} macro_rules! mut_input {(source = $s:expr, $($r:tt)*) => {let mut iter = $s.split_whitespace();let mut next = || { iter.next().unwrap() };mut_input_inner!{next, $($r)*}};($($r:tt)*) => {let stdin = std::io::stdin();let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));let mut next = move || -> String{bytes.by_ref().map(|r|r.unwrap() as char).skip_while(|c|c.is_whitespace()).take_while(|c|!c.is_whitespace()).collect()};mut_input_inner!{next, $($r)*}};} macro_rules! input_inner {($next:expr) => {};($next:expr, ) => {};($next:expr, $var:ident : $t:tt $($r:tt)*) => {let $var = read_value!($next, $t);input_inner!{$next $($r)*}};} macro_rules! mut_input_inner {($next:expr) => {};($next:expr, ) => {};($next:expr, $var:ident : $t:tt $($r:tt)*) => {let mut $var = read_value!($next, $t);mut_input_inner!{$next $($r)*}};} macro_rules! read_value {($next:expr, ( $($t:tt),* )) => {( $(read_value!($next, $t)),* )};($next:expr, [ $t:tt ; $len:expr ]) => {(0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()};($next:expr, chars) => {read_value!($next, String).chars().collect::<Vec<char>>()};($next:expr, usize1) => {read_value!($next, usize) - 1};($next:expr, $t:ty) => {$next().parse::<$t>().expect("Parse error")};} // 非常時 fn read_line() -> String { let mut s = String::new(); std::io::stdin().read_line(&mut s).unwrap(); s.trim().to_string() } fn read_vec<T: std::str::FromStr>() -> Vec<T> { let mut s = String::new(); std::io::stdin().read_line(&mut s).ok(); s.trim().split_whitespace() .map(|e| e.parse().ok().unwrap()).collect() } fn mul(A: &Vec<Vec<i64>>, B: &Vec<Vec<i64>>, _MOD: i64) -> Vec<Vec<i64>> { let mut C: Vec<Vec<i64>> = Vec::new(); for i in 0usize..A.len() { let mut c: Vec<i64> = (0usize..B[0].len()).map(|v| 0i64).collect(); //iter::repeat(0i64).take(B[0].len()).collect()?? // vec![0i64;B[0].len()]; ?? C.push(c); } for i in 0usize..A.len() { for k in 0usize..B.len() { if A[i][k] == 0 { continue; } for j in 0usize..B[0].len() { C[i][j] += A[i][k] * B[k][j]; C[i][j] %= _MOD; } } } C } fn pow(A: &Vec<Vec<i64>>, n: i64, _MOD: i64) -> Vec<Vec<i64>> { let mut A = A.clone(); let mut n = n.clone(); let mut B: Vec<Vec<i64>> = Vec::new(); for i in 0usize..A.len() { let mut b: Vec<i64> = (0usize..A.len()).map(|v| 0i64).collect(); B.push(b); } for i in 0usize..A.len() { B[i][i] = 1; } while n > 0 { if n % 2 == 1 { B = mul(&B, &A, _MOD); } A = mul(&A, &A, _MOD); n >>= 1; } B } fn solve(){ input!(n:i64,m:i64); let mut A:Vec<Vec<i64>> = vec![vec![0;2];2]; A[0][0] = 1; A[0][1] = 1; A[1][0] = 1; println!("{}",pow(&A,n,m)[1][1]); } fn main() { let stack_size = 104_857_600; // 100 MB let thd = std::thread::Builder::new().stack_size(stack_size); thd.spawn(|| solve()).unwrap().join().unwrap(); }