結果

問題 No.1238 選抜クラス
ユーザー beetbeet
提出日時 2020-09-25 21:26:24
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
RE  
実行時間 -
コード長 2,964 bytes
コンパイル時間 2,032 ms
コンパイル使用メモリ 205,844 KB
実行使用メモリ 11,156 KB
最終ジャッジ日時 2023-09-10 14:52:55
合計ジャッジ時間 7,837 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 2 ms
4,376 KB
testcase_03 RE -
testcase_04 RE -
testcase_05 AC 2 ms
4,376 KB
testcase_06 AC 2 ms
4,376 KB
testcase_07 AC 2 ms
4,376 KB
testcase_08 AC 1 ms
4,376 KB
testcase_09 AC 1 ms
4,380 KB
testcase_10 AC 2 ms
4,376 KB
testcase_11 AC 2 ms
4,380 KB
testcase_12 AC 1 ms
4,380 KB
testcase_13 AC 1 ms
4,380 KB
testcase_14 AC 1 ms
4,380 KB
testcase_15 AC 3 ms
4,376 KB
testcase_16 AC 2 ms
4,376 KB
testcase_17 AC 56 ms
4,428 KB
testcase_18 AC 183 ms
7,064 KB
testcase_19 AC 376 ms
10,684 KB
testcase_20 AC 23 ms
4,376 KB
testcase_21 AC 275 ms
9,220 KB
testcase_22 RE -
testcase_23 AC 416 ms
11,156 KB
testcase_24 RE -
testcase_25 AC 403 ms
10,988 KB
testcase_26 RE -
testcase_27 AC 418 ms
10,924 KB
testcase_28 AC 264 ms
8,384 KB
testcase_29 AC 250 ms
8,256 KB
testcase_30 AC 7 ms
4,376 KB
testcase_31 AC 21 ms
4,376 KB
testcase_32 AC 170 ms
7,776 KB
testcase_33 AC 2 ms
4,376 KB
testcase_34 AC 98 ms
5,560 KB
testcase_35 AC 13 ms
4,376 KB
testcase_36 AC 2 ms
4,376 KB
testcase_37 AC 3 ms
4,380 KB
testcase_38 AC 254 ms
8,648 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;

using Int = long long;
const char newl = '\n';

template<typename T1,typename T2> inline void chmin(T1 &a,T2 b){if(a>b) a=b;}
template<typename T1,typename T2> inline void chmax(T1 &a,T2 b){if(a<b) a=b;}
template<typename T> void drop(const T &x){cout<<x<<endl;exit(0);}
template<typename T=int>
vector<T> read(size_t n){
  vector<T> ts(n);
  for(size_t i=0;i<n;i++) cin>>ts[i];
  return ts;
}


template<typename T,T MOD = 1000000007>
struct Mint{
  static constexpr T mod = MOD;
  T v;
  Mint():v(0){}
  Mint(signed v):v(v){}
  Mint(long long t){v=t%MOD;if(v<0) v+=MOD;}

  Mint pow(long long k){
    Mint res(1),tmp(v);
    while(k){
      if(k&1) res*=tmp;
      tmp*=tmp;
      k>>=1;
    }
    return res;
  }

  static Mint add_identity(){return Mint(0);}
  static Mint mul_identity(){return Mint(1);}

  Mint inv(){return pow(MOD-2);}

  Mint& operator+=(Mint a){v+=a.v;if(v>=MOD)v-=MOD;return *this;}
  Mint& operator-=(Mint a){v+=MOD-a.v;if(v>=MOD)v-=MOD;return *this;}
  Mint& operator*=(Mint a){v=1LL*v*a.v%MOD;return *this;}
  Mint& operator/=(Mint a){return (*this)*=a.inv();}

  Mint operator+(Mint a) const{return Mint(v)+=a;}
  Mint operator-(Mint a) const{return Mint(v)-=a;}
  Mint operator*(Mint a) const{return Mint(v)*=a;}
  Mint operator/(Mint a) const{return Mint(v)/=a;}

  Mint operator-() const{return v?Mint(MOD-v):Mint(v);}

  bool operator==(const Mint a)const{return v==a.v;}
  bool operator!=(const Mint a)const{return v!=a.v;}
  bool operator <(const Mint a)const{return v <a.v;}

  static Mint comb(long long n,int k){
    Mint num(1),dom(1);
    for(int i=0;i<k;i++){
      num*=Mint(n-i);
      dom*=Mint(i+1);
    }
    return num/dom;
  }
};
template<typename T,T MOD> constexpr T Mint<T, MOD>::mod;
template<typename T,T MOD>
ostream& operator<<(ostream &os,Mint<T, MOD> m){os<<m.v;return os;}


template<typename T>
vector<T> make_v(size_t a){return vector<T>(a);}

template<typename T,typename... Ts>
auto make_v(size_t a,Ts... ts){
  return vector<decltype(make_v<T>(ts...))>(a,make_v<T>(ts...));
}

template<typename T,typename U,typename... V>
typename enable_if<is_same<T, U>::value!=0>::type
fill_v(U &u,const V... v){u=U(v...);}

template<typename T,typename U,typename... V>
typename enable_if<is_same<T, U>::value==0>::type
fill_v(U &u,const V... v){
  for(auto &e:u) fill_v<T>(e,v...);
}

//INSERT ABOVE HERE

signed main(){
  cin.tie(0);
  ios::sync_with_stdio(0);

  int n,k;
  cin>>n>>k;
  auto as=read(n);

  using M = Mint<int>;
  auto dp=make_v<M>(n+1,n*k);
  fill_v<M>(dp,0);
  dp[0][0]=M(1);
  for(int a:as){
    auto nx=make_v<M>(n+1,n*k);
    fill_v<M>(nx,0);

    for(int i=0;i<n;i++){
      for(int j=0;j<n*k;j++){
        nx[i][j]+=dp[i][j];
        if(j+a<n*k) nx[i+1][j+a]+=dp[i][j];
      }
    }

    swap(dp,nx);
  }

  M ans=M(2).pow(n)-M(1);
  for(int i=1;i<=n;i++)
    for(int j=0;j<i*k;j++)
      ans-=dp[i][j];
  cout<<ans<<newl;
  return 0;
}
0