結果

問題 No.444 旨味の相乗効果
ユーザー 37zigen37zigen
提出日時 2016-11-12 02:53:33
言語 Java21
(openjdk 21)
結果
AC  
実行時間 345 ms / 2,500 ms
コード長 1,622 bytes
コンパイル時間 3,664 ms
コンパイル使用メモリ 79,388 KB
実行使用メモリ 58,892 KB
最終ジャッジ日時 2023-09-07 02:16:59
合計ジャッジ時間 9,788 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 126 ms
55,796 KB
testcase_01 AC 124 ms
55,704 KB
testcase_02 AC 126 ms
55,920 KB
testcase_03 AC 126 ms
55,968 KB
testcase_04 AC 339 ms
58,740 KB
testcase_05 AC 130 ms
56,020 KB
testcase_06 AC 128 ms
55,552 KB
testcase_07 AC 166 ms
55,796 KB
testcase_08 AC 155 ms
55,776 KB
testcase_09 AC 146 ms
55,944 KB
testcase_10 AC 131 ms
56,052 KB
testcase_11 AC 147 ms
55,896 KB
testcase_12 AC 228 ms
58,076 KB
testcase_13 AC 206 ms
58,000 KB
testcase_14 AC 146 ms
55,872 KB
testcase_15 AC 126 ms
55,952 KB
testcase_16 AC 345 ms
58,892 KB
testcase_17 AC 134 ms
55,804 KB
testcase_18 AC 146 ms
55,788 KB
testcase_19 AC 176 ms
53,648 KB
testcase_20 AC 295 ms
58,156 KB
testcase_21 AC 128 ms
55,784 KB
testcase_22 AC 125 ms
55,588 KB
testcase_23 AC 128 ms
55,792 KB
testcase_24 AC 150 ms
55,584 KB
testcase_25 AC 130 ms
55,784 KB
testcase_26 AC 125 ms
55,648 KB
testcase_27 AC 128 ms
56,036 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

package yukicoder;

import java.util.*;

public class Q444 {
	static final long MODULO = 1_000_000_000 + 7;

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		long c = sc.nextLong();
		long[] a = new long[n];
		for (int i = 0; i < n; ++i) {
			a[i] = sc.nextLong() % MODULO;
		}
		long[][] vec = new long[n][1];
		for (int i = 0; i < n; ++i) {
			vec[i][0] = 1;
		}
		long[][] mx = new long[n][n];
		for (int i = 0; i < n; ++i) {
			for (int j = 0; j <= i; ++j) {
				mx[i][j] = a[j];
			}
		}
		vec = pow(mx, vec, c);
		long ans = vec[n - 1][0];
		for (int i = 0; i < n; ++i) {
			ans -= pow(a[i], c % (MODULO - 1));
		}
		while(ans<0)ans+=MODULO;
		System.out.println(ans);
	}

	static long[][] pow(long[][] mx, long[][] vec, long n) {
		for (; n > 0; n >>= 1, mx = mul(mx, mx)) {
			if (n % 2 == 1) {
				vec = mul(mx, vec);
			}
		}
		return vec;
	}

	static long pow(long a, long n) {
		long ret = 1;
		for (; n > 0; n >>= 1, a = (a * a) % MODULO) {
			if (n % 2 == 1) {
				ret = (ret * a) % MODULO;
			}
		}
		return ret;
	}

	static long[][] mul(long[][] A, long[][] B) {
		if (A[0].length != B.length)
			throw new AssertionError();
		int mid = A[0].length;
		long[][] ret = new long[A.length][B[0].length];
		for (int i = 0; i < A.length; ++i) {
			for (int j = 0; j < B[0].length; ++j) {
				for (int k = 0; k < mid; ++k) {
					ret[i][j] += A[i][k] * B[k][j] % MODULO;
					if (ret[i][j] >= MODULO)
						ret[i][j] -= MODULO;
				}
			}
		}
		return ret;
	}

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