結果
| 問題 |
No.503 配列コレクション
|
| コンテスト | |
| ユーザー |
btk
|
| 提出日時 | 2017-04-19 13:39:37 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 45 ms / 2,000 ms |
| コード長 | 1,746 bytes |
| コンパイル時間 | 1,563 ms |
| コンパイル使用メモリ | 166,800 KB |
| 実行使用メモリ | 26,880 KB |
| 最終ジャッジ日時 | 2024-07-19 09:25:12 |
| 合計ジャッジ時間 | 3,284 ms |
|
ジャッジサーバーID (参考情報) |
judge4 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 25 |
ソースコード
#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
#define CIN_ONLY if(1)
struct cww{cww(){
CIN_ONLY{
ios::sync_with_stdio(false);cin.tie(0);
}
}}star;
#define fin "\n"
#define FOR(i,bg,ed) for(int i=(bg);i<(ed);i++)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) (v).begin(),(v).end()
#define fi first
#define se second
#define pb push_back
#define DEBUG if(0)
#define REC(ret, ...) std::function<ret (__VA_ARGS__)>
template <typename T>inline bool chmin(T &l,T r)
{bool a=l>r;if(a)l=r;return a;}
template <typename T>inline bool chmax(T &l,T r)
{bool a=l<r;if(a)l=r;return a;}
template <typename T>
istream& operator>>(istream &is,vector<T> &v){
for(auto &it:v)is>>it;
return is;
}
const int mod=1e9+7;
// a x + b y = gcd(a, b)
// O(log (a+b) )
LL extgcd(LL a, LL b, LL &x, LL &y) {
LL g = a; x = 1; y = 0;
if (b != 0) g = extgcd(b, a % b, y, x), y -= (a / b) * x;
return g;
}
// 階乗
// O(n)
#define SZ 3000010
LL fact[SZ];
struct fact_{
fact_(){
fact[0]=1;
for(int i=1;i<SZ;i++)
fact[i]=fact[i-1]*i%mod;
}
}fact_init;
// mを法とするaの逆元
// O(log a)
LL invMod(LL a) {
LL x, y;
if (extgcd(a, mod, x, y) == 1)return (x + mod) % mod;
else return 0; // unsolvable
}
LL H(LL a,LL b){
LL u=fact[a+b-1];
LL d=fact[a-1]*fact[b]%mod;
return u*invMod(d)%mod;
}
int main(){
LL N,K,D;
cin>>N>>K>>D;
LL d=(N-1)/(K-1);
LL M=N-d*(K-1);
LL res=0;
LL dd=1;
REP(i,d+1){
res+=(dd*M%mod)*H(M-1,d-i)%mod;
res%=mod;
dd=dd*D%mod;
}
if(D==1)
cout<<M<<endl;
else if(M==1){
cout<<dd*invMod(D)%mod<<endl;
}
else
cout<<res<<endl;
return 0;
}
btk