結果

問題 No.997 Jumping Kangaroo
ユーザー 37zigen37zigen
提出日時 2020-02-22 00:12:16
言語 Java19
(openjdk 21)
結果
AC  
実行時間 144 ms / 2,000 ms
コード長 1,480 bytes
コンパイル時間 4,024 ms
コンパイル使用メモリ 74,208 KB
実行使用メモリ 56,044 KB
最終ジャッジ日時 2023-07-30 08:51:58
合計ジャッジ時間 9,771 ms
ジャッジサーバーID
(参考情報)
judge14 / judge13
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 127 ms
53,552 KB
testcase_01 AC 137 ms
55,676 KB
testcase_02 AC 130 ms
55,672 KB
testcase_03 AC 127 ms
55,568 KB
testcase_04 AC 126 ms
55,908 KB
testcase_05 AC 126 ms
55,904 KB
testcase_06 AC 129 ms
55,768 KB
testcase_07 AC 126 ms
55,680 KB
testcase_08 AC 128 ms
55,708 KB
testcase_09 AC 131 ms
55,688 KB
testcase_10 AC 126 ms
55,668 KB
testcase_11 AC 128 ms
55,908 KB
testcase_12 AC 126 ms
55,660 KB
testcase_13 AC 126 ms
55,672 KB
testcase_14 AC 128 ms
55,764 KB
testcase_15 AC 133 ms
55,668 KB
testcase_16 AC 144 ms
55,796 KB
testcase_17 AC 129 ms
55,712 KB
testcase_18 AC 133 ms
55,664 KB
testcase_19 AC 130 ms
55,672 KB
testcase_20 AC 136 ms
55,988 KB
testcase_21 AC 127 ms
55,652 KB
testcase_22 AC 135 ms
55,768 KB
testcase_23 AC 136 ms
55,464 KB
testcase_24 AC 126 ms
55,832 KB
testcase_25 AC 127 ms
56,044 KB
testcase_26 AC 125 ms
55,688 KB
testcase_27 AC 127 ms
55,632 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.io.PrintWriter;
import java.util.Arrays;
import java.util.HashMap;
import java.util.Scanner;
import java.math.*;

class Main {
	public static void main(String[] args) throws Exception {
		new Main().run();
	}
	
	long[][] mul(long[][] a,long[][] b){
		long[][] ret=new long[a.length][b[0].length];
		for(int i=0;i<a.length;++i){
			for(int j=0;j<b[i].length;++j){
				for(int k=0;k<a[i].length;++k){
					ret[i][j]+=a[i][k]*b[k][j]%M;
					ret[i][j]%=M;
				}
			}
		}
		return ret;
	}
	
	long[][] pow_mat(long[][] a,long n){
		long[][] ret=new long[a.length][a.length];
		ret[0][0]=ret[1][1]=1;
		for(;n>0;n>>=1,a=mul(a,a))if(n%2==1)ret=mul(ret,a);
		return ret;
	}
	
	long pow(long a,long n){
		long ret=1;
		for(;n>0;n>>=1,a=a*a%M)if(n%2==1)ret=ret*a%M;
		return ret;
	}
	
	long inv(long a){
		return pow(a,M-2);
	}
	
	final long M=(long)1e9+7;
	
	void run() {
		Scanner sc=new Scanner(System.in);
		int N=sc.nextInt();
		int W=sc.nextInt();
		long K=sc.nextLong();
		int[] A=new int[N];
		for(int i=0;i<N;++i){
			A[i]=sc.nextInt();
		}
		long[] a=new long[2*W+1];
		a[0]=1;
		for(int i=0;i<a.length;++i){
			for(int j=0;j<A.length;++j){
				if(i+A[j]<a.length){
					a[i+A[j]]+=a[i];
					a[i+A[j]]%=M;
				}
			}
		}
		long u=a[W];
		long v=a[2*W]-u*u%M;
		long[][] mat={{u,v},{1,0}};
		mat=pow_mat(mat,K);
		long ans=mat[0][0];
		System.out.println((ans%M+M)%M);
	}

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

}
0