結果

問題 No.503 配列コレクション
ユーザー btkbtk
提出日時 2017-04-19 13:32:13
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,683 bytes
コンパイル時間 1,560 ms
コンパイル使用メモリ 166,112 KB
実行使用メモリ 27,092 KB
最終ジャッジ日時 2023-09-26 15:17:41
合計ジャッジ時間 3,616 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 23 ms
26,804 KB
testcase_01 AC 23 ms
26,936 KB
testcase_02 AC 24 ms
26,764 KB
testcase_03 AC 24 ms
26,812 KB
testcase_04 WA -
testcase_05 AC 24 ms
26,836 KB
testcase_06 AC 24 ms
26,952 KB
testcase_07 AC 23 ms
26,872 KB
testcase_08 AC 24 ms
26,768 KB
testcase_09 AC 24 ms
26,816 KB
testcase_10 AC 23 ms
26,792 KB
testcase_11 AC 24 ms
26,828 KB
testcase_12 AC 24 ms
26,776 KB
testcase_13 AC 24 ms
26,764 KB
testcase_14 AC 24 ms
26,904 KB
testcase_15 AC 24 ms
26,952 KB
testcase_16 AC 24 ms
27,024 KB
testcase_17 AC 24 ms
26,772 KB
testcase_18 AC 23 ms
26,804 KB
testcase_19 WA -
testcase_20 AC 24 ms
26,904 KB
testcase_21 WA -
testcase_22 AC 23 ms
26,936 KB
testcase_23 AC 23 ms
26,808 KB
testcase_24 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

#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
        cout<<res<<endl;
    return 0;
}
0