結果

問題 No.444 旨味の相乗効果
ユーザー hermione17hermione17
提出日時 2016-11-12 00:02:53
言語 Java21
(openjdk 21)
結果
WA  
(最新)
AC  
(最初)
実行時間 -
コード長 1,652 bytes
コンパイル時間 3,393 ms
コンパイル使用メモリ 74,740 KB
実行使用メモリ 59,576 KB
最終ジャッジ日時 2023-09-07 02:15:49
合計ジャッジ時間 19,816 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 191 ms
55,888 KB
testcase_01 AC 198 ms
55,860 KB
testcase_02 AC 198 ms
56,028 KB
testcase_03 AC 219 ms
58,696 KB
testcase_04 AC 1,021 ms
59,056 KB
testcase_05 AC 239 ms
58,204 KB
testcase_06 AC 199 ms
55,972 KB
testcase_07 AC 288 ms
58,220 KB
testcase_08 AC 293 ms
58,524 KB
testcase_09 AC 387 ms
58,628 KB
testcase_10 AC 383 ms
58,948 KB
testcase_11 AC 350 ms
58,620 KB
testcase_12 AC 609 ms
58,952 KB
testcase_13 AC 591 ms
58,576 KB
testcase_14 AC 590 ms
58,992 KB
testcase_15 AC 590 ms
58,704 KB
testcase_16 AC 1,022 ms
58,656 KB
testcase_17 AC 829 ms
58,988 KB
testcase_18 AC 858 ms
59,172 KB
testcase_19 AC 814 ms
58,500 KB
testcase_20 AC 844 ms
58,948 KB
testcase_21 AC 127 ms
56,124 KB
testcase_22 AC 127 ms
56,108 KB
testcase_23 AC 1,388 ms
58,724 KB
testcase_24 AC 135 ms
56,332 KB
testcase_25 AC 747 ms
59,040 KB
testcase_26 AC 716 ms
59,036 KB
testcase_27 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.io.PrintStream;
import java.util.Scanner;


public class Y444 {
	Scanner in = new Scanner(System.in);
	PrintStream out = new PrintStream(System.out);

	long MOD = 1000000007;
	
	
	Y444() throws Exception {
		int n = in.nextInt();
		long c = in.nextLong();
		int[] a = new int[n];
		for (int i = 0; i < n; i++) {
			a[i] = in.nextInt();
		}
		
		Matrix m = new Matrix();
		for (int i = 0; i < n; i++) {
			m.a[i][i] = a[i];
			m.a[i+n][i+n] = a[i];
			for (int j = 0; j < i; j++) {
				m.a[i+n][j] = a[i];
				m.a[i+n][j+n] = a[i];
			}
		}
				
		Matrix power = m.pow(c - 1);
		long ans = 0;
		for (int i = 0; i < n; i++) {
			for (int j = 0; j < n; j++) {
				ans += (a[j] * power.a[i+n][j]);
				if ((j & 7) == 7) {
					ans %= MOD;
				}
			}
		}

		ans %= MOD;
		out.println(ans);
	}

	public static void main(String argv[]) throws Exception {
		new Y444();
	}

	
	class Matrix {
		long[][] a = new long[160][160];

		Matrix mul(Matrix that) {
			Matrix ret = new Matrix();
			for (int i = 0; i < a.length; i++) {
				for (int j = 0; j < a.length; j++) {
					for (int k = 0; k < a.length; k++) {
						if (a[i][j] != 0 && that.a[j][k] != 0) {
							ret.a[i][k] += (a[i][j] * that.a[j][k]);
						}
					}
					
					if ((j & 7) == 7) {
						for (int k = 0; k < a.length; k++) {
							ret.a[i][k] %= MOD;
						}
					}
				}
			}
			return ret;
		}

		Matrix pow(long p) {
			Matrix ret = new Matrix();
			Matrix x = this;
			
			for (int i = 0; i < a.length; i++) {
				ret.a[i][i] = 1;
			}
			
			while (p > 0) {
				if ((p & 1) == 1) {
					ret = x.mul(ret);
				}
				x = x.mul(x);
				p >>= 1;
			}
			
			return ret;
		}
	}
}
0