結果

問題 No.978 Fibonacci Convolution Easy
ユーザー fukafukatanifukafukatani
提出日時 2020-01-31 21:52:13
言語 Rust
(1.72.1)
結果
AC  
実行時間 42 ms / 2,000 ms
コード長 1,280 bytes
コンパイル時間 749 ms
コンパイル使用メモリ 169,744 KB
実行使用メモリ 33,192 KB
最終ジャッジ日時 2023-10-19 01:00:24
合計ジャッジ時間 1,899 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,348 KB
testcase_01 AC 18 ms
14,004 KB
testcase_02 AC 11 ms
7,872 KB
testcase_03 AC 41 ms
31,872 KB
testcase_04 AC 12 ms
9,388 KB
testcase_05 AC 4 ms
4,348 KB
testcase_06 AC 17 ms
12,224 KB
testcase_07 AC 26 ms
21,124 KB
testcase_08 AC 19 ms
15,256 KB
testcase_09 AC 30 ms
24,224 KB
testcase_10 AC 42 ms
32,928 KB
testcase_11 AC 15 ms
10,708 KB
testcase_12 AC 3 ms
4,348 KB
testcase_13 AC 15 ms
12,224 KB
testcase_14 AC 6 ms
4,772 KB
testcase_15 AC 18 ms
13,740 KB
testcase_16 AC 42 ms
33,192 KB
testcase_17 AC 41 ms
32,928 KB
testcase_18 AC 1 ms
4,348 KB
testcase_19 AC 0 ms
4,348 KB
testcase_20 AC 1 ms
4,348 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#![allow(unused_imports)]
#![allow(non_snake_case)]
use std::cmp::*;
use std::collections::*;
use std::io::Write;

#[allow(unused_macros)]
macro_rules! debug {
    ($($e:expr),*) => {
        #[cfg(debug_assertions)]
        $({
            let (e, mut err) = (stringify!($e), std::io::stderr());
            writeln!(err, "{} = {:?}", e, $e).unwrap()
        })*
    };
}

fn main() {
    let v = read_vec::<i64>();
    let (n, p) = (v[0] as usize, v[1]);
    if n == 1 {
        println!("0");
        return;
    }
    let big_int = 1000_000_000 + 7;
    let mut a = vec![0; n + 1];
    a[2] = 1;
    for i in 3..n + 1 {
        a[i] = p * a[i - 1] + a[i - 2];
        a[i] %= big_int;
    }
    let mut sum = vec![0; n + 1];
    for i in 1..n + 1 {
        sum[i] = a[i] + sum[i - 1];
        sum[i] %= big_int;
    }
    let mut ans = 0;
    for i in 0..n + 1 {
        ans += (a[i] * sum[i]) % big_int;
        ans %= big_int;
    }
    println!("{}", ans);
}

fn read<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().parse().ok().unwrap()
}

fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    read::<String>()
        .split_whitespace()
        .map(|e| e.parse().ok().unwrap())
        .collect()
}
0