結果

問題 No.1489 Repeat Cumulative Sum
ユーザー ks2mks2m
提出日時 2021-04-23 23:03:25
言語 Java19
(openjdk 21)
結果
AC  
実行時間 251 ms / 2,000 ms
コード長 1,031 bytes
コンパイル時間 3,124 ms
コンパイル使用メモリ 73,312 KB
実行使用メモリ 61,504 KB
最終ジャッジ日時 2023-09-17 12:59:44
合計ジャッジ時間 9,763 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 43 ms
49,384 KB
testcase_01 AC 45 ms
47,496 KB
testcase_02 AC 44 ms
49,304 KB
testcase_03 AC 230 ms
60,440 KB
testcase_04 AC 240 ms
60,620 KB
testcase_05 AC 240 ms
61,084 KB
testcase_06 AC 244 ms
60,540 KB
testcase_07 AC 192 ms
57,644 KB
testcase_08 AC 148 ms
55,088 KB
testcase_09 AC 239 ms
60,764 KB
testcase_10 AC 227 ms
60,220 KB
testcase_11 AC 236 ms
56,184 KB
testcase_12 AC 66 ms
50,964 KB
testcase_13 AC 215 ms
55,868 KB
testcase_14 AC 248 ms
61,504 KB
testcase_15 AC 249 ms
60,604 KB
testcase_16 AC 195 ms
57,844 KB
testcase_17 AC 206 ms
58,108 KB
testcase_18 AC 188 ms
57,764 KB
testcase_19 AC 144 ms
54,480 KB
testcase_20 AC 168 ms
57,800 KB
testcase_21 AC 228 ms
60,576 KB
testcase_22 AC 88 ms
52,324 KB
testcase_23 AC 135 ms
55,568 KB
testcase_24 AC 44 ms
49,320 KB
testcase_25 AC 113 ms
50,552 KB
testcase_26 AC 251 ms
60,660 KB
testcase_27 AC 220 ms
55,724 KB
testcase_28 AC 76 ms
51,716 KB
testcase_29 AC 184 ms
57,608 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.io.BufferedReader;
import java.io.InputStreamReader;

public class Main {
	public static void main(String[] args) throws Exception {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String[] sa = br.readLine().split(" ");
		int n = Integer.parseInt(sa[0]);
		long m = Long.parseLong(sa[1]);
		sa = br.readLine().split(" ");
		int[] a = new int[n];
		for (int i = 0; i < n - 1; i++) {
			a[i + 1] = Integer.parseInt(sa[i]);
		}
		br.close();

		int mod = 1000000007;
		long ans = 0;
		long val = 1;
		long m2 = m;
		for (int i = 1; i < n; i++) {
			val = val * (m2 % mod) % mod;
			val = val * modinv(i, mod) % mod;
			ans += val * a[n - i] % mod;
			m2++;
		}
		ans %= mod;
		System.out.println(ans);
	}

	static long modinv(long a, int m) {
		long b = m;
		long u = 1;
		long v = 0;
		long tmp = 0;

		while (b > 0) {
			long t = a / b;
			a -= t * b;
			tmp = a;
			a = b;
			b = tmp;

			u -= t * v;
			tmp = u;
			u = v;
			v = tmp;
		}

		u %= m;
		if (u < 0) u += m;
		return u;
	}
}
0