結果

問題 No.766 金魚すくい
ユーザー ngtkanangtkana
提出日時 2020-03-31 22:18:29
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 26 ms / 1,500 ms
コード長 5,504 bytes
コンパイル時間 2,093 ms
コンパイル使用メモリ 210,300 KB
実行使用メモリ 5,820 KB
最終ジャッジ日時 2023-09-07 12:58:28
合計ジャッジ時間 4,673 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 1 ms
4,380 KB
testcase_03 AC 2 ms
4,376 KB
testcase_04 AC 2 ms
4,376 KB
testcase_05 AC 1 ms
4,376 KB
testcase_06 AC 2 ms
4,380 KB
testcase_07 AC 1 ms
4,380 KB
testcase_08 AC 2 ms
4,376 KB
testcase_09 AC 1 ms
4,380 KB
testcase_10 AC 1 ms
4,380 KB
testcase_11 AC 2 ms
4,376 KB
testcase_12 AC 1 ms
4,380 KB
testcase_13 AC 2 ms
4,376 KB
testcase_14 AC 2 ms
4,380 KB
testcase_15 AC 2 ms
4,376 KB
testcase_16 AC 2 ms
4,376 KB
testcase_17 AC 2 ms
4,380 KB
testcase_18 AC 2 ms
4,380 KB
testcase_19 AC 2 ms
4,376 KB
testcase_20 AC 2 ms
4,376 KB
testcase_21 AC 2 ms
4,376 KB
testcase_22 AC 2 ms
4,380 KB
testcase_23 AC 24 ms
5,700 KB
testcase_24 AC 24 ms
5,724 KB
testcase_25 AC 26 ms
5,716 KB
testcase_26 AC 25 ms
5,708 KB
testcase_27 AC 26 ms
5,652 KB
testcase_28 AC 25 ms
5,716 KB
testcase_29 AC 25 ms
5,820 KB
testcase_30 AC 26 ms
5,720 KB
testcase_31 AC 26 ms
5,748 KB
testcase_32 AC 24 ms
5,652 KB
testcase_33 AC 23 ms
4,944 KB
testcase_34 AC 24 ms
4,976 KB
testcase_35 AC 4 ms
4,376 KB
testcase_36 AC 4 ms
4,376 KB
testcase_37 AC 26 ms
5,656 KB
testcase_38 AC 25 ms
5,732 KB
testcase_39 AC 26 ms
5,712 KB
testcase_40 AC 24 ms
5,644 KB
testcase_41 AC 15 ms
5,708 KB
testcase_42 AC 16 ms
5,616 KB
testcase_43 AC 1 ms
4,376 KB
testcase_44 AC 2 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
using lint=long long;
using real=long double;
template<class T>
T inverse(T a, T m){
    T u=0,v=1;
    while(a!=0){
        T t=m/a;
        m-=t*a;std::swap(a,m);
        u-=t*v;std::swap(u,v);
    }
    assert(m==1);
    return u;
}
template<class T>
class modular {
    public:
        int value;
        constexpr modular() = default;
        constexpr modular(const modular&) = default;
        constexpr modular(modular&&) = default;
        modular&operator=(const modular&) = default;
        modular&operator=(modular&&) = default;
        template<class U>modular(const U&x){value= normalize(x);}
        template<class U>
            static int normalize(const U& x){
                int v=static_cast<int>(-mod()<=x&&x<mod()?x:x%mod());
                if(v<0)v+=mod();
                return v;
            }
        template<class U>explicit operator U()const{return static_cast<U>(value);}
        constexpr static auto mod(){return T::value;}

        auto&operator+=(const modular&other) {if((value+=other.value)>=mod())value-=mod();return *this;}
        auto&operator-=(const modular& other){if((value-=other.value)<0)value+=mod();return *this;}
        template <class U>auto& operator+=(const U& other){return*this+=modular(other);}
        template <class U>auto& operator-=(const U& other){return*this-=modular(other);}
        auto operator-()const{return modular(-value);}
        auto&operator++(){return*this+=1;}
        auto&operator--(){return*this-=1;}
        auto operator++(int){modular result(*this);operator++();return result;}
        auto operator--(int){modular result(*this);operator--();return result;}

        template<class U=T>
            auto&operator*=(const modular&rhs){value=normalize(static_cast<std::int64_t>(value)*static_cast<std::int64_t>(rhs.value));return *this;}
        auto&operator/=(const modular&rhs){return*this*=modular(inverse(rhs.value, mod()));}
};
template<class T>struct is_modular:std::false_type{};
template<class T>struct is_modular <modular<T>>:std::true_type{};
template<class T>constexpr bool is_modular_v=is_modular<T>::value;
template<class t> bool operator==(const modular<t>& lhs, const modular<t>& rhs){return lhs()==rhs();}
template<class T,class U>bool operator==(const modular<T>& lhs, U rhs){return lhs==modular<T>(rhs);}
template<class T,class U>bool operator==(U lhs, const modular<T>& rhs){return modular<T>(lhs)==rhs;}
template<class T> bool operator!=(const modular<T>& lhs, const modular<T>& rhs){return !(lhs == rhs);}
template<class T,class U>bool operator!=(const modular<T>& lhs, U rhs){return !(lhs==rhs);}
template<class T,class U>bool operator!=(U lhs, const modular<T>& rhs){return !(lhs==rhs);}
template<class T> modular<T> operator+(const modular<T>& lhs, const modular<T>& rhs){return modular<T>(lhs)+=rhs;}
template<class T,class U>modular<T>operator+(const modular<T>& lhs,U rhs){return modular<T>(lhs)+=rhs;}
template<class T,class U>modular<T>operator+(U lhs,const modular<T>& rhs){return modular<T>(lhs)+=rhs;}
template<class T>modular<T>operator-(const modular<T>& lhs,const modular<T>& rhs){return modular<T>(lhs)-=rhs;}
template<class T,class U>modular<T>operator-(const modular<T>& lhs,U rhs){return modular<T>(lhs)-=rhs;}
template<class T,class U>modular<T>operator-(U lhs,const modular<T>& rhs){return modular<T>(lhs)-=rhs;}
template<class T>modular<T>operator*(const modular<T>& lhs,const modular<T>& rhs){return modular<T>(lhs)*=rhs;}
template<class T,class U>modular<T>operator*(const modular<T>& lhs,U rhs){return modular<T>(lhs)*=rhs;}
template<class T,class U>modular<T>operator*(U lhs,const modular<T>& rhs){return modular<T>(lhs)*=rhs;}
template<class T>modular<T>operator/(const modular<T>& lhs,const modular<T>& rhs){return modular<T>(lhs)/=rhs;}
template<class T,class U>modular<T>operator/(const modular<T>& lhs,U rhs){return modular<T>(lhs)/=rhs;}
template<class T,class U>modular<T>operator/(U lhs,const modular<T>& rhs){return modular<T>(lhs)/=rhs;}
template<class T,class U>
modular<T>power(const modular<T>&a,U b) {
    assert(b>=0);
    modular<T>x=a,ret=1;
    for (;b>0;b/=2){
        if(b%2==1)ret*=x;
        x*=x;
    }
    return ret;
}
template<class T>auto operator<<(std::ostream&os,const T&a)->std::enable_if_t<is_modular_v<T>,std::ostream&>{return os<<a.value;}
template<class T>auto operator>>(std::istream&is,T&a)->std::enable_if_t<is_modular_v<T>,std::istream&>{return is>>a.value;}
constexpr int mod=1'000'000'007;
using mint = modular<std::integral_constant<std::decay_t<decltype(mod)>, mod>>;
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,m;mint p;std::cin>>n>>m>>p;
    p=p/100;
    lint N=n+m;
    std::vector<mint>fact(N+1),finv(N+1);
    fact.at(0)=1;
    for(lint i=1;i<=N;i++)fact.at(i)=fact.at(i-1)*i;
    finv.at(N)=mint{1}/fact.at(N);
    for(lint i=N;i>=1;i--)finv.at(i-1)=finv.at(i)*i;
    auto binom=[&](lint n,lint k){return fact.at(n)*finv.at(k)*finv.at(n-k);};
    std::vector<mint>a(n+1);
    mint now=power(p,m);
    for(lint i=0;i<n;i++){
        a.at(i)=binom(m+i-1,i)*now;
        now*=1-p;
    }
    a.at(n)=1-std::accumulate(a.begin(),a.begin()+n,mint{0});
    std::vector<lint>b(n+1);
    for(lint i=1;i<=n;i++)std::cin>>b.at(i);
    std::sort(b.rbegin(),b.rend()-1);
    std::partial_sum(b.begin(),b.end(),b.begin());
    std::cout<<std::inner_product(a.begin(),a.end(),b.begin(),mint{0})<<'\n';
}
0