結果

問題 No.1846 Good Binary Matrix
ユーザー 👑 potato167potato167
提出日時 2024-02-16 13:56:21
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 404 ms / 2,000 ms
コード長 2,594 bytes
コンパイル時間 957 ms
コンパイル使用メモリ 78,008 KB
実行使用メモリ 18,932 KB
最終ジャッジ日時 2024-02-16 13:56:32
合計ジャッジ時間 7,146 ms
ジャッジサーバーID
(参考情報)
judge14 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,676 KB
testcase_01 AC 1 ms
6,676 KB
testcase_02 AC 2 ms
6,676 KB
testcase_03 AC 1 ms
6,676 KB
testcase_04 AC 2 ms
6,676 KB
testcase_05 AC 2 ms
6,676 KB
testcase_06 AC 2 ms
6,676 KB
testcase_07 AC 1 ms
6,676 KB
testcase_08 AC 1 ms
6,676 KB
testcase_09 AC 2 ms
6,676 KB
testcase_10 AC 2 ms
6,676 KB
testcase_11 AC 1 ms
6,676 KB
testcase_12 AC 1 ms
6,676 KB
testcase_13 AC 2 ms
6,676 KB
testcase_14 AC 1 ms
6,676 KB
testcase_15 AC 1 ms
6,676 KB
testcase_16 AC 404 ms
18,932 KB
testcase_17 AC 378 ms
18,380 KB
testcase_18 AC 372 ms
18,200 KB
testcase_19 AC 378 ms
18,200 KB
testcase_20 AC 377 ms
18,928 KB
testcase_21 AC 127 ms
7,296 KB
testcase_22 AC 137 ms
7,552 KB
testcase_23 AC 10 ms
7,424 KB
testcase_24 AC 7 ms
6,676 KB
testcase_25 AC 273 ms
15,664 KB
testcase_26 AC 198 ms
11,300 KB
testcase_27 AC 24 ms
11,028 KB
testcase_28 AC 45 ms
7,424 KB
testcase_29 AC 120 ms
10,260 KB
testcase_30 AC 288 ms
11,484 KB
testcase_31 AC 255 ms
9,992 KB
testcase_32 AC 335 ms
15,468 KB
testcase_33 AC 350 ms
11,896 KB
testcase_34 AC 2 ms
6,676 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<iostream>
#include<vector>
using ll = long long;


struct mint{
    static constexpr int  m = 1000000007;
    int x;
    mint() : x(0){}
    mint(ll x_):x(x_%m){if(x<0)x+=m;}
    int val(){return x;}
    mint &operator+=(mint b){if((x+=b.x)>=m)x-=m; return *this;}
    mint &operator-=(mint b){if((x-=b.x)<0)x+=m; return *this;}
    mint &operator*=(mint b){x=ll(x)*b.x%m; return *this;}
    mint pow(ll e) const {
        mint r = 1,b =*this;
        while(e){
            if(e&1) r*=b;
            b*=b;
            e>>=1;
        }
        return r;
    }
    mint inv(){return pow(m-2);}
    mint &operator/=(mint b){return *this*=b.pow(m-2);}
    friend mint operator+(mint a,mint b){return a+=b;}
    friend mint operator-(mint a,mint b){return a-=b;}
    friend mint operator/(mint a,mint b){return a/=b;}
    friend mint operator*(mint a,mint b){return a*=b;}
    friend bool operator==(mint a,mint b){return a.x==b.x;}
    friend bool operator!=(mint a,mint b){return a.x!=b.x;}
};


namespace po167{
template<class T>
struct Binomial{
    std::vector<T> fact_vec, fact_inv_vec;
    void extend(int m = -1){
        int n = fact_vec.size();
        if (m == -1) m = n * 2;
        if (n >= m) return;
        fact_vec.resize(m);
        fact_inv_vec.resize(m);
        for (int i = n; i < m; i++){
            fact_vec[i] = fact_vec[i - 1] * T(i);
        }
        fact_inv_vec[m - 1] = T(1) / fact_vec[m - 1];
        for (int i = m - 1; i > n; i--){
            fact_inv_vec[i - 1] = fact_inv_vec[i] * T(i);
        }
    }
    Binomial(int MAX = 2){
        fact_vec.resize(1, T(1));
        fact_inv_vec.resize(1, T(1));
        extend(MAX + 1);
    }

    T fact(int i){
        if (i < 0) return 0;
        while (int(fact_vec.size()) <= i) extend();
        return fact_vec[i];
    }
    T invfact(int i){
        if (i < 0) return 0;
        while (int(fact_inv_vec.size()) <= i) extend();
        return fact_inv_vec[i];
    }
    T C(int a, int b){
        if (a < b || b < 0) return 0;
        return fact(a) * invfact(b) * invfact(a -b);
    }
    T P(int a, int b){
        if (a < b || b < 0) return 0;
        return fact(a) * invfact(a - b);
    }
    T inv(int a){
        if (a < 0) return inv(-a) * T(-1);
        if (a == 0) return 1;
        return fact(a - 1) * invfact(a);
    }
};
}



int main(){
    int h,w;
    std::cin >> h >> w;
    po167::Binomial<mint> table(h + w);
    mint ans = 0;
    for(int i = 0; i <= h; i++){
        ans += mint(-1).pow(i) * table.C(h, i) * (mint(2).pow(h - i) - 1).pow(w);
    }
    std::cout << ans.val() << "\n";
}
0