結果

問題 No.444 旨味の相乗効果
ユーザー 37zigen37zigen
提出日時 2016-11-12 02:34:50
言語 Java21
(openjdk 21)
結果
AC  
実行時間 350 ms / 2,500 ms
コード長 1,589 bytes
コンパイル時間 3,363 ms
コンパイル使用メモリ 75,700 KB
実行使用メモリ 59,124 KB
最終ジャッジ日時 2023-09-07 02:15:00
合計ジャッジ時間 9,304 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 125 ms
56,328 KB
testcase_01 AC 125 ms
55,980 KB
testcase_02 AC 125 ms
56,196 KB
testcase_03 AC 126 ms
55,876 KB
testcase_04 AC 346 ms
59,124 KB
testcase_05 AC 125 ms
56,192 KB
testcase_06 AC 123 ms
56,040 KB
testcase_07 AC 168 ms
56,348 KB
testcase_08 AC 154 ms
54,044 KB
testcase_09 AC 153 ms
55,808 KB
testcase_10 AC 127 ms
56,112 KB
testcase_11 AC 149 ms
55,892 KB
testcase_12 AC 256 ms
58,272 KB
testcase_13 AC 214 ms
57,952 KB
testcase_14 AC 151 ms
56,516 KB
testcase_15 AC 125 ms
56,040 KB
testcase_16 AC 350 ms
58,268 KB
testcase_17 AC 126 ms
55,796 KB
testcase_18 AC 131 ms
55,688 KB
testcase_19 AC 176 ms
55,868 KB
testcase_20 AC 335 ms
58,444 KB
testcase_21 AC 123 ms
55,816 KB
testcase_22 AC 126 ms
55,720 KB
testcase_23 AC 125 ms
55,760 KB
testcase_24 AC 157 ms
55,868 KB
testcase_25 AC 125 ms
56,080 KB
testcase_26 AC 126 ms
56,088 KB
testcase_27 AC 127 ms
55,732 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 = (ans - pow(a[i], c % (MODULO - 1)) + MODULO) % 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;
					ret[i][j] %= MODULO;
				}
			}
		}
		return ret;
	}

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