結果

問題 No.503 配列コレクション
ユーザー Kmcode1Kmcode1
提出日時 2017-04-07 22:59:08
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 298 ms / 2,000 ms
コード長 1,602 bytes
コンパイル時間 1,184 ms
コンパイル使用メモリ 147,672 KB
実行使用メモリ 42,452 KB
最終ジャッジ日時 2023-09-23 02:29:44
合計ジャッジ時間 9,972 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 297 ms
42,232 KB
testcase_01 AC 297 ms
42,076 KB
testcase_02 AC 297 ms
42,052 KB
testcase_03 AC 297 ms
42,080 KB
testcase_04 AC 297 ms
42,080 KB
testcase_05 AC 297 ms
42,196 KB
testcase_06 AC 298 ms
42,280 KB
testcase_07 AC 297 ms
42,184 KB
testcase_08 AC 297 ms
42,216 KB
testcase_09 AC 298 ms
42,080 KB
testcase_10 AC 297 ms
42,152 KB
testcase_11 AC 297 ms
42,088 KB
testcase_12 AC 297 ms
42,156 KB
testcase_13 AC 296 ms
42,452 KB
testcase_14 AC 298 ms
42,220 KB
testcase_15 AC 298 ms
42,172 KB
testcase_16 AC 297 ms
42,448 KB
testcase_17 AC 297 ms
42,060 KB
testcase_18 AC 298 ms
42,156 KB
testcase_19 AC 298 ms
42,128 KB
testcase_20 AC 296 ms
42,016 KB
testcase_21 AC 297 ms
42,012 KB
testcase_22 AC 298 ms
42,076 KB
testcase_23 AC 297 ms
42,232 KB
testcase_24 AC 298 ms
42,152 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
#include<unordered_set>
#include<unordered_map>
using namespace std;


#define MAX 1000002

int n;
int k;
int d;

#define MOD 1000000007

long long int p[MAX];



class Combination{
	long long int ppow(long long int i, long long int j){
		long long int res = 1LL;
		while (j){
			if ((j & 1LL)){
				res *= i;
				if (res >= MOD){
					res %= MOD;
				}
			}
			j >>= 1;
			i *= i;
			if (i >= MOD){
				i %= MOD;
			}
		}
		return res;
	}
public:
	vector<long long int> k;
	vector<long long int> r;
	void resize(int N){
		k.resize(N + 2);
		r.resize(N + 2);
		k[0] = 1;
		for (int i = 1; i < k.size(); i++){
			k[i] = k[i - 1];
			k[i] *= i;
			if (k[i] >= MOD)k[i] %= MOD;
		}
		for (int i = 0; i < r.size(); i++){
			r[i] = ppow(k[i], MOD - 2);
		}
	}
	long long int C(int a, int b){
		if (a < b)return 0;
		long long int up = k[a];
		long long int dw = r[b] * r[a - b];
		dw %= MOD;
		up *= dw;
		up %= MOD;
		return up;
	}
	long long int H(int a, int b){
		if (a == 0)return 1;
		if (b == 0)return 1;
		return C(a + b - 1, b);
	}
} c;

int main(){
	c.resize(MAX * 2);
	cin >> n >> k >> d;
	p[0] = 1;
	for (int i = 1; i < MAX; i++){
		p[i] = p[i - 1];
		p[i] *= d;
		p[i] %= MOD;
	}
	int op = 0;
	while (n >= k){
		n -= k - 1;
		op++;
	}
	if (d == 1){
		cout << n << endl;
		return 0;
	}
	long long int ans = 0;
	for (int i = 1; i <= 1; i++){
		for (int j = 0; j <= op; j++){
			if (n - 1 == 0){
				j = op;
			}
			long long int w = c.H(n - 1, op-j);
			w *= p[j];
			w %= MOD;
			w *= n;
			w %= MOD;
			ans += w;
			ans %= MOD;
		}
	}
	printf("%lld\n", ans);
	return 0;
}
0