結果

問題 No.444 旨味の相乗効果
ユーザー 37zigen37zigen
提出日時 2016-11-12 02:23:24
言語 Java21
(openjdk 21)
結果
AC  
実行時間 354 ms / 2,500 ms
コード長 1,574 bytes
コンパイル時間 3,882 ms
コンパイル使用メモリ 78,844 KB
実行使用メモリ 58,700 KB
最終ジャッジ日時 2023-09-07 02:14:16
合計ジャッジ時間 10,146 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 129 ms
55,752 KB
testcase_01 AC 129 ms
55,688 KB
testcase_02 AC 130 ms
55,744 KB
testcase_03 AC 127 ms
55,948 KB
testcase_04 AC 354 ms
58,700 KB
testcase_05 AC 130 ms
55,880 KB
testcase_06 AC 129 ms
55,460 KB
testcase_07 AC 174 ms
56,280 KB
testcase_08 AC 161 ms
56,096 KB
testcase_09 AC 156 ms
56,168 KB
testcase_10 AC 129 ms
55,888 KB
testcase_11 AC 151 ms
56,252 KB
testcase_12 AC 258 ms
56,680 KB
testcase_13 AC 218 ms
58,032 KB
testcase_14 AC 153 ms
56,152 KB
testcase_15 AC 130 ms
55,656 KB
testcase_16 AC 353 ms
58,536 KB
testcase_17 AC 127 ms
55,796 KB
testcase_18 AC 135 ms
56,168 KB
testcase_19 AC 179 ms
56,280 KB
testcase_20 AC 340 ms
58,468 KB
testcase_21 AC 127 ms
55,852 KB
testcase_22 AC 126 ms
55,788 KB
testcase_23 AC 127 ms
55,700 KB
testcase_24 AC 159 ms
55,788 KB
testcase_25 AC 128 ms
56,104 KB
testcase_26 AC 128 ms
55,732 KB
testcase_27 AC 130 ms
56,184 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) % 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