結果

問題 No.978 Fibonacci Convolution Easy
ユーザー 37zigen37zigen
提出日時 2020-01-31 21:57:07
言語 Java21
(openjdk 21)
結果
RE  
実行時間 -
コード長 788 bytes
コンパイル時間 4,497 ms
コンパイル使用メモリ 77,308 KB
実行使用メモリ 91,544 KB
最終ジャッジ日時 2023-10-17 09:35:59
合計ジャッジ時間 7,527 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 126 ms
57,768 KB
testcase_01 AC 163 ms
72,832 KB
testcase_02 AC 148 ms
62,076 KB
testcase_03 AC 193 ms
89,572 KB
testcase_04 AC 156 ms
64,036 KB
testcase_05 AC 141 ms
59,792 KB
testcase_06 AC 161 ms
70,860 KB
testcase_07 AC 175 ms
79,076 KB
testcase_08 AC 161 ms
72,520 KB
testcase_09 AC 181 ms
83,348 KB
testcase_10 AC 189 ms
91,544 KB
testcase_11 AC 133 ms
67,700 KB
testcase_12 AC 134 ms
59,900 KB
testcase_13 AC 154 ms
70,744 KB
testcase_14 AC 127 ms
58,836 KB
testcase_15 AC 155 ms
72,880 KB
testcase_16 AC 180 ms
90,668 KB
testcase_17 AC 186 ms
91,440 KB
testcase_18 RE -
testcase_19 AC 98 ms
55,732 KB
testcase_20 AC 117 ms
57,364 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.*;
import java.io.*;

// This file is a "Hello, world!" in Java language by OpenJDK for wandbox.

class Main
{
	public static void main(String[] args)
	{
		new Main().run();
	}
	
	final long m=(long)1e9+7;
	
	void run(){
		Scanner sc=new Scanner(System.in);
		int N=sc.nextInt();
		long p=sc.nextLong();
		long[] a=new long[N+1];
		long[] s=new long[N+1];
		a[1]=0;
		a[2]=1;
		for(int i=3;i<a.length;++i)a[i]=(p*a[i-1]%m+a[i-2])%m;
		for(int i=1;i<a.length;++i)s[i]=(s[i-1]+a[i])%m;
		long ans=0;
		for(int i=1;i<=N;++i){
			ans=(ans+s[i]*a[i]%m)%m;
		}
		System.out.println(ans);
	}
	
	void tr(Object...o){System.out.println(Arrays.deepToString(o));}
}
// OpenJDK reference:
//   http://openjdk.java.net/

// Java language references:
//   http://docs.oracle.com/javase
0