結果

問題 No.117 組み合わせの数
ユーザー hirayuu_ychirayuu_yc
提出日時 2024-04-28 11:50:59
言語 C++23(gcc13)
(gcc 13.2.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 12,715 bytes
コンパイル時間 3,946 ms
コンパイル使用メモリ 281,240 KB
実行使用メモリ 19,072 KB
最終ジャッジ日時 2024-11-17 03:09:11
合計ジャッジ時間 5,294 ms
ジャッジサーバーID
(参考情報)
judge2 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

#line 1 "Verify/verify-yuki/117.test.cpp"
#define PROBLEM "https://yukicoder.me/problems/no/117"
#line 2 "Template.hpp"
//https://tatyam.hatenablog.com/entry/2019/12/15/003634
#include<bits/stdc++.h>
using namespace std;
using ll=long long;
template<class T> using pq=priority_queue<T,vector<T>,greater<T>>;
using pll=pair<ll,ll>;
const ll LINF=1LL<<60;
#define _overload3(_1,_2,_3,name,...) name
#define _overload4(_1,_2,_3,_4,name,...) name
#define _rep1(i,n) for(ll i=0; i<(n); i++)
#define _rep2(i,a,b) for(ll i=(a); i<(b); i++)
#define _rep3(i,a,b,c) for(ll i=(a); i<(b); i+=(c))
#define rep(...) _overload4(__VA_ARGS__,_rep3,_rep2,_rep1)(__VA_ARGS__)
#define _rrep1(i,n) for(ll i=(n); i-->0;)
#define _rrep2(i,a,b) for(ll i=(b); i-->(a);)
#define rrep(...) _overload3(__VA_ARGS__,_rrep2,_rrep1)(__VA_ARGS__)
#define each(i,...) for(auto&& i:__VA_ARGS__)
#define all(i) begin(i),end(i)
#define rall(i) rbegin(i),rend(i)
template<class T> bool chmin(T &a,const T &b){if(a>b){a=b;return true;}else return false;}
template<class T> bool chmax(T &a,const T &b){if(a<b){a=b;return true;}else return false;}
template<class T> ll sum(const T &a){return accumulate(all(a),0LL);}
template<class T> auto min(const T &a){return *min_element(all(a));}
template<class T> auto max(const T &a){return *max_element(all(a));}
inline int scan(){ return getchar(); }
inline void scan(int &a){ scanf("%d", &a); }
inline void scan(unsigned &a){ scanf("%u", &a); }
inline void scan(long &a){ scanf("%ld", &a); }
inline void scan(long long &a){ scanf("%lld", &a); }
inline void scan(unsigned long long &a){ scanf("%llu", &a); }
inline void scan(char &a){ cin >> a; }
inline void scan(float &a){ scanf("%f", &a); }
inline void scan(double &a){ scanf("%lf", &a); }
inline void scan(long double &a){ scanf("%Lf", &a); }
inline void scan(vector<bool> &vec){ for(unsigned i = 0; i < vec.size(); i++) { int a; scan(a); vec[i] = a; } }
inline void scan(char a[]){ scanf("%s", a); }
inline void scan(string &a){ cin >> a; }
template<class T> inline void scan(vector<T> &vec);
template<class T, size_t size> inline void scan(array<T, size> &vec);
template<class T, class L> inline void scan(pair<T, L> &p);
template<class T, size_t size> inline void scan(T (&vec)[size]);
template<class T> inline void scan(vector<T> &vec){ for(auto &i : vec) scan(i); }
template<class T> inline void scan(deque<T> &vec){ for(auto &i : vec) scan(i); }
template<class T, size_t size> inline void scan(array<T, size> &vec){ for(auto &i : vec) scan(i); }
template<class T, class L> inline void scan(pair<T, L> &p){ scan(p.first); scan(p.second); }
template<class T, size_t size> inline void scan(T (&vec)[size]){ for(auto &i : vec) scan(i); }
template<class T> inline void scan(T &a){ cin >> a; }
inline void in(){}
template <class Head, class... Tail> inline void in(Head &head, Tail&... tail){ scan(head); in(tail...); }
inline void print(){ putchar(' '); }
inline void print(const bool &a){ printf("%d", a); }
inline void print(const int &a){ printf("%d", a); }
inline void print(const unsigned &a){ printf("%u", a); }
inline void print(const long &a){ printf("%ld", a); }
inline void print(const long long &a){ printf("%lld", a); }
inline void print(const unsigned long long &a){ printf("%llu", a); }
inline void print(const char &a){ printf("%c", a); }
inline void print(const char a[]){ printf("%s", a); }
inline void print(const float &a){ printf("%.15f", a); }
inline void print(const double &a){ printf("%.15f", a); }
inline void print(const long double &a){ printf("%.15Lf", a); }
inline void print(const string &a){ for(auto&& i : a) print(i); }
template<class T> inline void print(const vector<T> &vec);
template<class T, size_t size> inline void print(const array<T, size> &vec);
template<class T, class L> inline void print(const pair<T, L> &p);
template<class T, size_t size> inline void print(const T (&vec)[size]);
template<class T> inline void print(const vector<T> &vec){ if(vec.empty()) return; print(vec[0]); for(auto i = vec.begin(); ++i != vec.end(); ){ putchar(' '); print(*i); } }
template<class T> inline void print(const deque<T> &vec){ if(vec.empty()) return; print(vec[0]); for(auto i = vec.begin(); ++i != vec.end(); ){ putchar(' '); print(*i); } }
template<class T, size_t size> inline void print(const array<T, size> &vec){ print(vec[0]); for(auto i = vec.begin(); ++i != vec.end(); ){ putchar(' '); print(*i); } }
template<class T, class L> inline void print(const pair<T, L> &p){ print(p.first); putchar(' '); print(p.second); }
template<class T, size_t size> inline void print(const T (&vec)[size]){ print(vec[0]); for(auto i = vec; ++i != end(vec); ){ putchar(' '); print(*i); } }
template<class T> inline void print(const T &a){ cout << a; }
inline int out(){ putchar('\n'); return 0; }
template<class T> inline int out(const T &t){ print(t); putchar('\n'); return 0; }
template<class Head, class... Tail> inline int out(const Head &head, const Tail&... tail){ print(head); putchar(' '); out(tail...); return 0; }
using ld=long double;
using ull=unsigned long long;
using uint=unsigned int;
using pii=pair<int,int>;
using pdd=pair<ld,ld>;
using tuplis=array<ll,3>;
#define vec(type,name,...) vector<type> name(__VA_ARGS__);
#define vv(type,name,h,...)vector<vector<type>> name(h,vector<type>(__VA_ARGS__));
#define INT(...) int __VA_ARGS__; in(__VA_ARGS__)
#define LL(...) ll __VA_ARGS__; in(__VA_ARGS__)
#define ULL(...) ull __VA_ARGS__; in(__VA_ARGS__)
#define STR(...) string __VA_ARGS__; in(__VA_ARGS__)
#define CHR(...) char __VA_ARGS__; in(__VA_ARGS__)
#define LD(...) ld __VA_ARGS__; in(__VA_ARGS__)
#define VEC(type,name,size) vector<type> name(size); in(name)
#define VV(type, name, h, w) vector<vector<type>> name(h, vector<type>(w)); in(name)
template<class T> ld dsum(const T &a){return accumulate(all(a),0.0L);}
const int INF=INT_MAX>>1;
const ll MINF=1LL<<40;
const ld DINF=numeric_limits<ld>::infinity();
const int MODD=1000000007;
const int MOD=998244353;
const ld EPS=1e-9;
const ld PI=3.1415926535897932;
const ll four[]={0,1,0,-1,0};
const ll eight[]={0,1,1,0,-1,-1,1,-1,0};
ll intpow(ll a,ll b){ll ret=1;while(b){if(b&1)ret*=a;a*=a;b>>=1;}return ret;}
int Yes(bool i=true){return out(i?"Yes":"No");}
int No(bool i=true){return out(i?"No":"Yes");}
#define len(x) ((int)(x).size())
#define fi first
#define se second
#line 1 "Modint/Modint.hpp"
template<uint64_t Mod>
struct Modint{
    uint64_t x;
    constexpr Modint(){
        x=0;
    }
    constexpr Modint(int64_t val){
        x=(val<0?val%(int64_t)(Mod)+Mod:val%Mod);
    }
    inline uint64_t _get_mod(uint64_t val){
        const static uint64_t m_inv=(-1ULL)/Mod+1;
        uint64_t ret=((unsigned __int128)(val)*m_inv)>>64;
        uint64_t pro=ret*Mod;
        return (val-pro+(val<pro?Mod:0));
    }
    friend ostream &operator<<(ostream &os,Modint &b){
        return os<<b.x;
    }
    friend istream &operator>>(istream &is,Modint &b){
        return is>>b.x;
    }
    constexpr uint64_t val(){
        return x;
    }
    constexpr Modint operator+(){
        return (*this);
    }
    constexpr Modint operator-(){
        return Modint()-(*this);
    }
    constexpr Modint operator+(const Modint rhs){
        return Modint(*this)+=rhs;
    }
    constexpr Modint operator-(const Modint rhs){
        return Modint(*this)-=rhs;
    }
    constexpr Modint operator*(const Modint rhs){
        return Modint(*this)*=rhs;
    }
    constexpr Modint operator/(const Modint rhs){
        return Modint(*this)/=rhs;
    }
    constexpr Modint &operator+=(const Modint rhs){
        x+=rhs.x;
        if(x>=Mod)x-=Mod;
        return *this;
    }
    constexpr Modint &operator-=(const Modint rhs){
        if(x<rhs.x)x+=Mod;
        x-=rhs.x;
        return *this;
    }
    constexpr Modint &operator*=(const Modint rhs){
        x=_get_mod(x*rhs.x);
        return *this;
    }
    constexpr bool operator==(Modint rhs){
        return x==rhs.x;
    }
    constexpr bool operator!=(Modint rhs){
        return x!=rhs.x;
    }
    constexpr Modint &operator/=(Modint rhs){
        return (*this)*=rhs.inv();
    }
    constexpr Modint inv(){
        return (*this).pow(Mod-2);
    }
    constexpr Modint pow(uint64_t x){
        Modint ret=1;
        Modint bin=(*this);
        while(x){
            if(x&1)ret*=bin;
            bin*=bin;
            x>>=1;
        }
        return ret;
    }
    static uint64_t get_mod(){
        return Mod;
    }
};

template<int64_t id>
struct ArbitraryModint{
    uint64_t x;
    static uint64_t &mod(){
        static uint64_t Mod=0;
        return Mod;
    }
    constexpr ArbitraryModint(){
        x=0;
    }
    constexpr ArbitraryModint(int64_t val){
        x=(val<0?val%(int64_t)(get_mod())+get_mod():val%get_mod());
    }
    inline uint64_t _get_mod(uint64_t val){
        const static uint64_t m_inv=(-1ULL)/get_mod()+1;
        uint64_t ret=((unsigned __int128)(val)*m_inv)>>64;
        uint64_t pro=ret*get_mod();
        return (val-pro+(val<pro?get_mod():0));
    }
    friend ostream &operator<<(ostream &os,ArbitraryModint &b){
        return os<<b.x;
    }
    friend istream &operator>>(istream &is,ArbitraryModint &b){
        return is>>b.x;
    }
    constexpr uint64_t val(){
        return x;
    }
    constexpr ArbitraryModint operator+(){
        return (*this);
    }
    constexpr ArbitraryModint operator-(){
        return ArbitraryModint()-(*this);
    }
    constexpr ArbitraryModint operator+(const ArbitraryModint rhs){
        return ArbitraryModint(*this)+=rhs;
    }
    constexpr ArbitraryModint operator-(const ArbitraryModint rhs){
        return ArbitraryModint(*this)-=rhs;
    }
    constexpr ArbitraryModint operator*(const ArbitraryModint rhs){
        return ArbitraryModint(*this)*=rhs;
    }
    constexpr ArbitraryModint operator/(const ArbitraryModint rhs){
        return ArbitraryModint(*this)/=rhs;
    }
    constexpr ArbitraryModint &operator+=(const ArbitraryModint rhs){
        x+=rhs.x;
        if(x>=get_mod())x-=get_mod();
        return *this;
    }
    constexpr ArbitraryModint &operator-=(const ArbitraryModint rhs){
        if(x<rhs.x)x+=get_mod();
        x-=rhs.x;
        return *this;
    }
    constexpr ArbitraryModint &operator*=(const ArbitraryModint rhs){
        x=_get_mod(x*rhs.x);
        return *this;
    }
    constexpr ArbitraryModint &operator/=(ArbitraryModint rhs){
        return (*this)*=rhs.inv();
    }
    constexpr bool operator==(ArbitraryModint rhs){
        return x==rhs.x;
    }
    constexpr bool operator!=(ArbitraryModint rhs){
        return x!=rhs.x;
    }
    constexpr ArbitraryModint inv(){
        return (*this).pow(get_mod()-2);
    }
    constexpr ArbitraryModint pow(uint64_t x){
        ArbitraryModint ret=1;
        ArbitraryModint bin=(*this);
        while(x){
            if(x&1)ret*=bin;
            bin*=bin;
            x>>=1;
        }
        return ret;
    }
    static void set_mod(const uint64_t x){
        mod()=x;
    }
    static uint64_t get_mod(){
        return mod();
    }
};
#include<atcoder/modint>
template<uint64_t N> inline void print(Modint<N> a){cout << a;}
template<int64_t id> inline void print(ArbitraryModint<id> a){cout << a;}
#line 1 "Math/ModCombination.hpp"
template<typename T>
struct ModCombination{
    vector<T> fact={1},rev{1};
    void resize(uint32_t sz){
        sz++;
        if(fact.size()>=sz)return;
        uint32_t before=fact.size();
        fact.resize(sz);
        rev.resize(sz);
        for(uint32_t i=before; i<sz; i++){
            fact[i]=fact[i-1]*i;
            rev[i]=rev[i-1]/i;
        }
    }
    T comb(int32_t n,int32_t k){
        if(n<0||k<0||n<k)return 0;
        resize(n);
        return fact[n]*rev[n-k]*rev[k];
    }
    T perm(int32_t n,int32_t k){
        if(n<0||k<0||n<k)return 0;
        resize(n);
        return fact[n]*rev[n-k];
    }
    T multi_comb(int32_t n,int32_t k){
        return comb(n+k-1,k);
    }
};
#line 5 "Verify/verify-yuki/117.test.cpp"
using mint=atcoder::modint1000000007;
void solve(){
    LL(T);
    ModCombination<mint> comb;
    comb.resize(2000000);
    rep(i,T){
        STR(S);
        ll N=0,K=0;
        bool flg=false;
        each(j,S){
            if(0<=j-'0'&&j-'0'<=9){
                if(flg){
                    K*=10;
                    K+=j-'0';
                }
                else{
                    N*=10;
                    N+=j-'0';
                }
            }
            else if(j==','){
                flg=true;
            }
        }
        if(S[0]=='C')out(comb.comb(N,K).val());
        else if(S[0]=='P')out(comb.perm(N,K).val());
        else if(S[0]=='H')out(comb.multi_comb(N,K).val());
    }
}
int main(){
    solve();
    return 0;
}
0