結果

問題 No.978 Fibonacci Convolution Easy
ユーザー fukafukatani
提出日時 2020-01-31 21:50:30
言語 Rust
(1.83.0 + proconio)
結果
RE  
実行時間 -
コード長 1,219 bytes
コンパイル時間 10,501 ms
コンパイル使用メモリ 402,632 KB
実行使用メモリ 33,100 KB
最終ジャッジ日時 2024-09-17 07:52:41
合計ジャッジ時間 11,789 ms
ジャッジサーバーID
(参考情報)
judge6 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 20 RE * 1
権限があれば一括ダウンロードができます

ソースコード

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]);
    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