結果

問題 No.980 Fibonacci Convolution Hard
ユーザー 37zigen37zigen
提出日時 2020-01-31 22:28:27
言語 Java21
(openjdk 21)
結果
AC  
実行時間 1,224 ms / 2,000 ms
コード長 787 bytes
コンパイル時間 4,243 ms
コンパイル使用メモリ 77,420 KB
実行使用メモリ 114,888 KB
最終ジャッジ日時 2023-10-17 13:39:13
合計ジャッジ時間 28,365 ms
ジャッジサーバーID
(参考情報)
judge11 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1,200 ms
113,696 KB
testcase_01 AC 1,209 ms
114,452 KB
testcase_02 AC 1,224 ms
103,704 KB
testcase_03 AC 1,194 ms
112,080 KB
testcase_04 AC 1,185 ms
112,220 KB
testcase_05 AC 1,209 ms
113,356 KB
testcase_06 AC 1,179 ms
112,696 KB
testcase_07 AC 1,221 ms
114,140 KB
testcase_08 AC 1,187 ms
114,260 KB
testcase_09 AC 1,206 ms
111,024 KB
testcase_10 AC 1,198 ms
111,552 KB
testcase_11 AC 1,186 ms
111,860 KB
testcase_12 AC 1,207 ms
111,660 KB
testcase_13 AC 1,217 ms
113,776 KB
testcase_14 AC 1,196 ms
112,400 KB
testcase_15 AC 1,177 ms
112,120 KB
testcase_16 AC 1,160 ms
114,888 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.Arrays;
import java.util.Scanner;
import java.io.*;

class Main {
	public static void main(String[] args) {
		new Main().run();
	}

	long MOD = (long) 1e9 + 7;

	void run() {
		Scanner sc = new Scanner(System.in);
		long p=sc.nextLong();
		int Q=sc.nextInt();
		int[] q=new int[Q];
		long[] a=new long[(int)2e6+1];
		long[] b=new long[(int)2e6+1];
		a[2]=1;
		b[4]=1;
		for(int i=3;i<a.length;++i)a[i]=(p*a[i-1]%MOD+a[i-2])%MOD;
		for(int i=5;i<b.length;++i)b[i]=(2*p*b[i-1]%MOD+(2-p*p%MOD)*b[i-2]%MOD-2*p%MOD*b[i-3]%MOD-b[i-4])%MOD;
		PrintWriter pw=new PrintWriter(System.out);
		for(int i=0;i<Q;++i){
			q[i]=sc.nextInt();
			pw.println((b[q[i]]+MOD)%MOD);
		}
		pw.close();
	}

	void tr(Object... objects) {
		System.out.println(Arrays.deepToString(objects));
	}

}
0