結果

問題 No.997 Jumping Kangaroo
ユーザー ngtkanangtkana
提出日時 2020-04-10 01:11:38
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 2 ms / 2,000 ms
コード長 7,109 bytes
コンパイル時間 2,543 ms
コンパイル使用メモリ 212,588 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-09-14 04:12:09
合計ジャッジ時間 3,513 ms
ジャッジサーバーID
(参考情報)
judge4 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,248 KB
testcase_01 AC 2 ms
5,376 KB
testcase_02 AC 2 ms
5,376 KB
testcase_03 AC 2 ms
5,376 KB
testcase_04 AC 2 ms
5,376 KB
testcase_05 AC 2 ms
5,376 KB
testcase_06 AC 2 ms
5,376 KB
testcase_07 AC 2 ms
5,376 KB
testcase_08 AC 2 ms
5,376 KB
testcase_09 AC 2 ms
5,376 KB
testcase_10 AC 2 ms
5,376 KB
testcase_11 AC 2 ms
5,376 KB
testcase_12 AC 2 ms
5,376 KB
testcase_13 AC 2 ms
5,376 KB
testcase_14 AC 2 ms
5,376 KB
testcase_15 AC 2 ms
5,376 KB
testcase_16 AC 2 ms
5,376 KB
testcase_17 AC 2 ms
5,376 KB
testcase_18 AC 2 ms
5,376 KB
testcase_19 AC 2 ms
5,376 KB
testcase_20 AC 2 ms
5,376 KB
testcase_21 AC 2 ms
5,376 KB
testcase_22 AC 2 ms
5,376 KB
testcase_23 AC 2 ms
5,376 KB
testcase_24 AC 2 ms
5,376 KB
testcase_25 AC 2 ms
5,376 KB
testcase_26 AC 2 ms
5,376 KB
testcase_27 AC 2 ms
5,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
#define ALL(v) std::begin(v),std::end(v)
using lint=long long;
using ld=long double;
#define ENABLE_DEBUG 0
#ifdef NGTKANA
#include<debug.hpp>
#else
#define DEBUG(...)(void)0
#endif
lint mod=1'000'000'007;
lint inverse(lint x){
    DEBUG(x);
    assert(x%mod);
    lint y=1,u=mod,v=0;
    while(x){lint q=u/x;u-=q*x;std::swap(u,x);v-=q*y;std::swap(v,y);}
    assert(x==0&&std::abs(u)==1&&std::abs(y)==mod&&std::abs(v)<mod);
    return v<0?v+mod:v;
}
lint normalized(lint x){if(x<=-mod||mod<=x)x%=mod;if(x<0)x+=mod;return x;}
struct mint{
    lint value;
    mint()=default;
    mint(lint x):value(normalized(x)){}
};
std::ostream&operator<<(std::ostream&os,mint x){return os<<x.value;}
mint operator+(mint x,mint y){lint z=x.value+y.value;if(mod<=z)z-=mod;return mint{z};}
mint operator-(mint x,mint y){lint z=x.value-y.value;if(z<0)z+=mod;return mint{z};}
mint operator*(mint x,mint y){return mint{x.value*y.value%mod};}
mint operator/(mint x,mint y){return mint{x.value*inverse(y.value)%mod};}
mint&operator+=(mint&x,mint y){return x=x+y;}
mint&operator-=(mint&x,mint y){return x=x-y;}
mint&operator*=(mint&x,mint y){return x=x*y;}
mint&operator/=(mint&x,mint y){return x=x/y;}
bool operator==(mint x,mint y){return x.value==y.value;}
bool operator!=(mint x,mint y){return x.value!=y.value;}
mint power(mint x,lint y){mint z=1;for(;y;y>>=1){if(y&1)z*=x;x*=x;}return z;}
mint operator-(mint x){return mint(-x.value);}
using poly_t=std::vector<mint>;
struct resring{
    poly_t mod, qd, qinv;
    lint deg;
    resring()=default;
    resring(poly_t v):mod([&v]{while(!v.empty()&&v.back()==0)v.pop_back();return v;}()),
        qd([v=v]()mutable{mint x=1/v.back();v.pop_back();for(mint&y:v)y*=-x;return v;}()),
        qinv([v=v]()mutable{v.erase(v.begin());for(mint&x:v)x=-x;return v;}()),
        deg(v.size()-1){assert(deg);}
    poly_t&normalize(poly_t&a)const{
        for(;deg<(lint)a.size();a.pop_back()){
            for(lint i=0;i<deg;i++){
                a.at(a.size()-1-deg+i)+=a.back()*qd.at(i);
            }
        }
        return a;
    }
    poly_t mul(poly_t a, poly_t b)const{
        normalize(a),normalize(b);
        lint l=a.size(),m=b.size();
        poly_t c(l+m-1);
        for(lint i=0;i<l;i++)for(lint j=0;j<m;j++)c.at(i+j)+=a.at(i)*b.at(j);
        return normalize(c);
    }
    poly_t&mul_assign(poly_t&a, poly_t b)const{return a=mul(a,b);}
    poly_t pow(poly_t a, lint b)const{poly_t ans{1};for(;b;b>>=1){if(b&1)mul_assign(ans,a);mul_assign(a,a);}return ans;}
};
mint bruteforce(lint w,lint k,std::vector<lint> a){
    std::vector<mint>dp(w*k+1);
    dp.at(0)=1;
    for(lint i=0;i<=w*k;i++){
        for(lint x:a){
            if(w*k<i+x)continue;
            dp.at(i+x)+=dp.at(i);
        }
    }
    return dp.at(w*k);
}
int main(){
    std::cin.tie(nullptr);std::ios_base::sync_with_stdio(false);
    std::cout.setf(std::ios_base::fixed);std::cout.precision(15);
    lint n,w,k;std::cin>>n>>w>>k;
    std::vector<mint>dp(w+w+1);
    dp.at(0)=1;
    std::vector<lint>a(n);
    for(lint&x:a)std::cin>>x;
    for(lint i=0;i<=w+w;i++){
        for(lint x:a){
            if(w+w<i+x)continue;
            dp.at(i+x)+=dp.at(i);
        }
    }
    mint x=dp.at(w),y=dp.at(w+w)-dp.at(w)*dp.at(w);
    if(x==0&&y==0){
        std::cout<<0<<'\n';
        return 0;
    }
    DEBUG(x,y);
    resring res(poly_t{1,-x,-y});
    DEBUG(dmap(res.mod,[](mint x){return guess(x);}));
    DEBUG(dmap(res.qd,[](mint x){return guess(x)a#include<bits/stdc++.h>
#define ALL(v) std::begin(v),std::end(v)
using lint=long long;
using ld=long double;
#define ENABLE_DEBUG 0
#ifdef NGTKANA
#include<debug.hpp>
#else
#define DEBUG(...)(void)0
#endif
lint mod=1'000'000'007;
lint inverse(lint x){
    assert(x%mod);
    lint y=1,u=mod,v=0;
    while(x){lint q=u/x;u-=q*x;std::swap(u,x);v-=q*y;std::swap(v,y);}
    assert(x==0&&std::abs(u)==1&&std::abs(y)==mod&&std::abs(v)<mod);
    return v<0?v+mod:v;
}
lint normalized(lint x){if(x<=-mod||mod<=x)x%=mod;if(x<0)x+=mod;return x;}
struct mint{
    lint value;
    mint()=default;
    mint(lint x):value(normalized(x)){}
};
std::ostream&operator<<(std::ostream&os,mint x){return os<<x.value;}
mint operator+(mint x,mint y){lint z=x.value+y.value;if(mod<=z)z-=mod;return mint{z};}
mint operator-(mint x,mint y){lint z=x.value-y.value;if(z<0)z+=mod;return mint{z};}
mint operator*(mint x,mint y){return mint{x.value*y.value%mod};}
mint operator/(mint x,mint y){return mint{x.value*inverse(y.value)%mod};}
mint&operator+=(mint&x,mint y){return x=x+y;}
mint&operator-=(mint&x,mint y){return x=x-y;}
mint&operator*=(mint&x,mint y){return x=x*y;}
mint&operator/=(mint&x,mint y){return x=x/y;}
bool operator==(mint x,mint y){return x.value==y.value;}
bool operator!=(mint x,mint y){return x.value!=y.value;}
mint power(mint x,lint y){mint z=1;for(;y;y>>=1){if(y&1)z*=x;x*=x;}return z;}
mint operator-(mint x){return mint(-x.value);}

using poly_t=std::vector<mint>;
namespace moly_utils {
    static poly_t mod, qd, qinv;
    static lint deg;
    static void generate(poly_t v){
        mod=([&v]{while(!v.empty()&&v.back()==0)v.pop_back();return v;}());
        qd=mod;mint t=1/qd.back();qd.pop_back();for(mint&x:qd)x*=-t;
        qinv=mod;qinv.erase(qinv.begin());for(mint&x:qinv)x=-x;
        deg=v.size()-1;
        assert(deg);
    }
    static poly_t&normalize(poly_t&a){
        for(;deg<(lint)a.size();a.pop_back()){
            for(lint i=0;i<deg;i++){
                a.at(a.size()-1-deg+i)+=a.back()*qd.at(i);
            }
        }
        return a;
    }
}
struct moly{
    poly_t value;
    moly()=default;
    moly(poly_t v):value(moly_utils::normalize(v)){}
    moly(std::initializer_list<mint>il):value(il){}
    mint const&at(std::size_t i)const&{return value.at(i);}
    mint&at(std::size_t i)&{return value.at(i);}
    std::size_t size()const&{return value.size();}
    static moly qd(){return moly_utils::qd;}
    static moly qinv(){return moly_utils::qinv;}
};
std::ostream&operator<<(std::ostream&os,moly const&a){return os<<a.value;}
moly operator*(moly a, moly b){
    lint l=a.size(),m=b.size();
    poly_t c(l+m-1);
    for(lint i=0;i<l;i++)for(lint j=0;j<m;j++)c.at(i+j)+=a.at(i)*b.at(j);
    return moly_utils::normalize(c);
}
moly&operator*=(moly&a,moly b){return a=a*b;}
moly pow(moly a, lint b){moly ans{1};for(;b;b>>=1){if(b&1)ans*=a;a*=a;}return ans;}

int main(){
    std::cin.tie(nullptr);std::ios_base::sync_with_stdio(false);
    std::cout.setf(std::ios_base::fixed);std::cout.precision(15);
    lint n,w,k;std::cin>>n>>w>>k;
    std::vector<mint>dp(w+w+1);
    dp.at(0)=1;
    std::vector<lint>a(n);
    for(lint&x:a)std::cin>>x;
    for(lint i=0;i<=w+w;i++){
        for(lint x:a){
            if(w+w<i+x)continue;
            dp.at(i+x)+=dp.at(i);
        }
    }
    mint x=dp.at(w),y=dp.at(w+w)-dp.at(w)*dp.at(w);
    if(x==0&&y==0){
        std::cout<<0<<'\n';
        return 0;
    }
    moly_utils::generate(poly_t{1,-x,-y});
    std::cout<<pow(moly::qinv(),k).at(0)<<'\n';
}
;}));
    DEBUG(dmap(res.qinv,[](mint x){return guess(x);}));
    std::cout<<res.pow(res.qinv,k).at(0)<<'\n';
}
0