結果

問題 No.1489 Repeat Cumulative Sum
ユーザー 👑 ygussanyygussany
提出日時 2021-04-23 22:20:46
言語 C
(gcc 12.3.0)
結果
AC  
実行時間 49 ms / 2,000 ms
コード長 634 bytes
コンパイル時間 580 ms
コンパイル使用メモリ 29,076 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-09-17 12:29:42
合計ジャッジ時間 2,355 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 0 ms
4,380 KB
testcase_03 AC 38 ms
4,380 KB
testcase_04 AC 34 ms
4,376 KB
testcase_05 AC 38 ms
4,376 KB
testcase_06 AC 31 ms
4,376 KB
testcase_07 AC 20 ms
4,376 KB
testcase_08 AC 12 ms
4,376 KB
testcase_09 AC 44 ms
4,376 KB
testcase_10 AC 37 ms
4,376 KB
testcase_11 AC 30 ms
4,376 KB
testcase_12 AC 2 ms
4,380 KB
testcase_13 AC 27 ms
4,376 KB
testcase_14 AC 48 ms
4,380 KB
testcase_15 AC 45 ms
4,376 KB
testcase_16 AC 23 ms
4,376 KB
testcase_17 AC 25 ms
4,376 KB
testcase_18 AC 19 ms
4,380 KB
testcase_19 AC 11 ms
4,376 KB
testcase_20 AC 16 ms
4,376 KB
testcase_21 AC 31 ms
4,380 KB
testcase_22 AC 2 ms
4,380 KB
testcase_23 AC 10 ms
4,380 KB
testcase_24 AC 0 ms
4,380 KB
testcase_25 AC 6 ms
4,380 KB
testcase_26 AC 49 ms
4,380 KB
testcase_27 AC 29 ms
4,376 KB
testcase_28 AC 2 ms
4,376 KB
testcase_29 AC 19 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <stdio.h>

const int Mod = 1000000007;

long long div_mod(long long x, long long y, long long z)
{
	if (x % y == 0) return x / y;
	else return (div_mod((1 + x / y) * y - x, (z % y), y) * z + x) / y;
}

int main()
{
	int i, N, A[100001];
	long long M;
	scanf("%d %lld", &N, &M);
	for (i = 2; i <= N; i++) scanf("%d", &(A[i]));
	M %= Mod;
	
	long long tmp = M - 1, tmpp = M - 1, ans = 0;
	for (i = N; i >= 2; i--) {
		ans += A[i] * (tmpp + 1) % Mod;
		tmp = tmp * (M - i + N) % Mod * div_mod(1, N - i + 2, Mod) % Mod;
		tmpp += tmp;
		if (tmpp >= Mod) tmpp -= Mod;
	}
	printf("%lld\n", ans % Mod);
	fflush(stdout);
	return 0;
}
0