結果

問題 No.1846 Good Binary Matrix
ユーザー 蜜蜂蜜蜂
提出日時 2022-02-18 23:02:35
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 451 ms / 2,000 ms
コード長 2,152 bytes
コンパイル時間 3,705 ms
コンパイル使用メモリ 228,020 KB
実行使用メモリ 39,096 KB
最終ジャッジ日時 2023-09-11 19:58:49
合計ジャッジ時間 11,016 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 57 ms
38,864 KB
testcase_01 AC 60 ms
39,056 KB
testcase_02 AC 61 ms
38,864 KB
testcase_03 AC 57 ms
38,808 KB
testcase_04 AC 54 ms
38,804 KB
testcase_05 AC 56 ms
38,804 KB
testcase_06 AC 58 ms
38,796 KB
testcase_07 AC 58 ms
38,808 KB
testcase_08 AC 56 ms
38,860 KB
testcase_09 AC 55 ms
38,872 KB
testcase_10 AC 55 ms
38,856 KB
testcase_11 AC 57 ms
38,792 KB
testcase_12 AC 53 ms
38,800 KB
testcase_13 AC 53 ms
38,804 KB
testcase_14 AC 59 ms
39,056 KB
testcase_15 AC 56 ms
38,796 KB
testcase_16 AC 441 ms
38,796 KB
testcase_17 AC 420 ms
38,808 KB
testcase_18 AC 423 ms
38,860 KB
testcase_19 AC 438 ms
38,864 KB
testcase_20 AC 451 ms
38,856 KB
testcase_21 AC 56 ms
38,856 KB
testcase_22 AC 59 ms
38,792 KB
testcase_23 AC 202 ms
39,096 KB
testcase_24 AC 133 ms
38,864 KB
testcase_25 AC 382 ms
38,856 KB
testcase_26 AC 260 ms
38,860 KB
testcase_27 AC 400 ms
38,804 KB
testcase_28 AC 203 ms
38,928 KB
testcase_29 AC 265 ms
38,852 KB
testcase_30 AC 150 ms
38,800 KB
testcase_31 AC 98 ms
38,924 KB
testcase_32 AC 333 ms
39,004 KB
testcase_33 AC 101 ms
38,808 KB
testcase_34 AC 55 ms
38,944 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

//g++ 1.cpp -std=c++14 -O2 -I .
#include <bits/stdc++.h>
using namespace std;

#include <atcoder/all>
using namespace atcoder;

using ll = long long;
using ld = long double;

using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using vld = vector<ld>;
using vvld = vector<vld>;
using vst = vector<string>;
using vvst = vector<vst>;

#define fi first
#define se second
#define pb push_back
#define eb emplace_back
#define pq_big(T) priority_queue<T,vector<T>,less<T>>
#define pq_small(T) priority_queue<T,vector<T>,greater<T>>
#define all(a) a.begin(),a.end()
#define rep(i,start,end) for(ll i=start;i<(ll)(end);i++)
#define per(i,start,end) for(ll i=start;i>=(ll)(end);i--)
#define uniq(a) sort(all(a));a.erase(unique(all(a)),a.end())

constexpr ll mod = 1e9+7;

bool ok(vvi &g){
  int n=g.size(),m=g[0].size();
  rep(i,0,n){
    bool flg=false;
    rep(j,0,m){
      if(g[i][j]==1){
        flg=true;
      }
    }

    if(flg==false){
      return flg;
    }
  }

  rep(j,0,m){
    bool flg=false;
    rep(i,0,n){
      if(g[i][j]==1){
        flg=true;
      }
    }

    if(flg==false){
      return flg;
    }
  }

  return true;
}

const int MAX=1510000;
const long long MOD=1000000007;

long long fac[MAX],finv[MAX],inv[MAX];

void COMinit(){
  fac[0]=fac[1]=1;
  finv[0]=finv[1]=1;
  inv[1]=1;
  for(int i=2;i<MAX;i++){
    fac[i]=fac[i-1]*i%MOD;
    inv[i]=MOD-inv[MOD%i]*(MOD/i)%MOD;
    finv[i]=finv[i-1]*inv[i]%MOD;
  }
}

long long COM(int n,int k){
  if(n<k) return 0;
  if(n<0||k<0) return 0;
  return fac[n]*(finv[k]*finv[n-k]%MOD)%MOD;
}

int main(){
  ios::sync_with_stdio(false);
  cin.tie(nullptr);

  int h,w;
  cin>>h>>w;

  /*
  int ans=0;
  vvi g(h,vi(w));

  rep(bit,0,(1<<(h*w))){
    rep(i,0,h){
      rep(j,0,w){
        g[i][j]=0;
        if(bit&(1<<(i*w+j))){
          g[i][j]=1;
        }
      }
    }

    ans+=ok(g);
  }

  cout<<ans<<endl;
  */

  COMinit();

  ll ans=0;
  rep(j,0,w+1){
    ll p=pow_mod(-1,j,mod);
    ll q=COM(w,j);
    ll r=pow_mod(2,w-j,mod)-1;
    r=pow_mod(r,h,mod);

    ans+=((p*q)%mod*r)%mod;
    ans=(ans%mod+mod)%mod;
  }

  cout<<ans<<endl;
}
0