結果

問題 No.1846 Good Binary Matrix
ユーザー 👑 potato167potato167
提出日時 2024-02-17 13:28:46
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 398 ms / 2,000 ms
コード長 2,587 bytes
コンパイル時間 903 ms
コンパイル使用メモリ 78,136 KB
実行使用メモリ 18,900 KB
最終ジャッジ日時 2024-02-17 13:28:54
合計ジャッジ時間 6,726 ms
ジャッジサーバーID
(参考情報)
judge14 / judge16
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,676 KB
testcase_01 AC 1 ms
6,676 KB
testcase_02 AC 1 ms
6,676 KB
testcase_03 AC 2 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 2 ms
6,676 KB
testcase_08 AC 2 ms
6,676 KB
testcase_09 AC 2 ms
6,676 KB
testcase_10 AC 1 ms
6,676 KB
testcase_11 AC 2 ms
6,676 KB
testcase_12 AC 2 ms
6,676 KB
testcase_13 AC 2 ms
6,676 KB
testcase_14 AC 2 ms
6,676 KB
testcase_15 AC 2 ms
6,676 KB
testcase_16 AC 373 ms
18,900 KB
testcase_17 AC 398 ms
18,900 KB
testcase_18 AC 363 ms
18,900 KB
testcase_19 AC 359 ms
18,900 KB
testcase_20 AC 397 ms
18,900 KB
testcase_21 AC 134 ms
11,216 KB
testcase_22 AC 141 ms
11,216 KB
testcase_23 AC 2 ms
6,676 KB
testcase_24 AC 2 ms
6,676 KB
testcase_25 AC 278 ms
11,216 KB
testcase_26 AC 178 ms
11,216 KB
testcase_27 AC 10 ms
6,676 KB
testcase_28 AC 39 ms
6,676 KB
testcase_29 AC 129 ms
7,376 KB
testcase_30 AC 304 ms
18,900 KB
testcase_31 AC 259 ms
11,216 KB
testcase_32 AC 317 ms
18,900 KB
testcase_33 AC 375 ms
18,900 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;
    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