結果

問題 No.1238 選抜クラス
ユーザー carrot46carrot46
提出日時 2020-09-25 22:14:19
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 163 ms / 2,000 ms
コード長 2,965 bytes
コンパイル時間 1,744 ms
コンパイル使用メモリ 175,688 KB
実行使用メモリ 13,768 KB
最終ジャッジ日時 2023-09-10 15:29:39
合計ジャッジ時間 4,528 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,384 KB
testcase_01 AC 1 ms
4,376 KB
testcase_02 AC 1 ms
4,380 KB
testcase_03 AC 1 ms
4,380 KB
testcase_04 AC 1 ms
4,376 KB
testcase_05 AC 1 ms
4,376 KB
testcase_06 AC 1 ms
4,376 KB
testcase_07 AC 2 ms
4,380 KB
testcase_08 AC 2 ms
4,376 KB
testcase_09 AC 1 ms
4,380 KB
testcase_10 AC 2 ms
4,380 KB
testcase_11 AC 1 ms
4,376 KB
testcase_12 AC 2 ms
4,376 KB
testcase_13 AC 2 ms
4,380 KB
testcase_14 AC 1 ms
4,380 KB
testcase_15 AC 2 ms
4,376 KB
testcase_16 AC 2 ms
4,380 KB
testcase_17 AC 43 ms
5,152 KB
testcase_18 AC 112 ms
9,580 KB
testcase_19 AC 163 ms
13,200 KB
testcase_20 AC 13 ms
4,380 KB
testcase_21 AC 121 ms
11,292 KB
testcase_22 AC 1 ms
4,380 KB
testcase_23 AC 87 ms
10,924 KB
testcase_24 AC 1 ms
4,384 KB
testcase_25 AC 88 ms
11,032 KB
testcase_26 AC 1 ms
4,380 KB
testcase_27 AC 146 ms
13,768 KB
testcase_28 AC 136 ms
10,916 KB
testcase_29 AC 126 ms
10,828 KB
testcase_30 AC 4 ms
4,380 KB
testcase_31 AC 15 ms
4,380 KB
testcase_32 AC 72 ms
9,300 KB
testcase_33 AC 2 ms
4,376 KB
testcase_34 AC 66 ms
7,108 KB
testcase_35 AC 7 ms
4,376 KB
testcase_36 AC 2 ms
4,376 KB
testcase_37 AC 3 ms
4,376 KB
testcase_38 AC 117 ms
10,608 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
//#include <chrono>
//#pragma GCC optimize("Ofast")
using namespace std;
#define reps(i,s,n) for(int i = s; i < n; i++)
#define rep(i,n) reps(i,0,n)
#define Rreps(i,n,e) for(int i = n - 1; i >= e; --i)
#define Rrep(i,n) Rreps(i,n,0)
#define ALL(a) a.begin(), a.end()
#define fi first
#define se second

using ll = long long;
using vec = vector<ll>;
using mat = vector<vec>;

ll N,M,H,W,Q,K,A,B;
string S;
typedef pair<ll, ll> P;
const ll INF = (1LL<<58);

template <unsigned long long mod > class modint{
public:
    ll x;
    constexpr modint(){x = 0;}
    constexpr modint(ll _x) : x((_x < 0 ? ((_x += (LLONG_MAX / mod) * mod) < 0 ? _x + (LLONG_MAX / mod) * mod : _x) : _x)%mod){}
    constexpr void set_raw(ll _x){
        //_x in [0, mod)
        x = _x;
    }
    constexpr modint operator-(){
        return x == 0 ? 0 : mod - x;
    }
    constexpr modint& operator+=(const modint& a){
        if((x += a.x) >= mod) x -= mod;
        return *this;
    }
    constexpr modint operator+(const modint& a) const{
        return modint(*this) += a;
    }
    constexpr modint& operator-=(const modint& a){
        if((x -= a.x) < 0) x += mod;
        return *this;
    }
    constexpr modint operator-(const modint& a) const{
        return modint(*this) -= a;
    }
    constexpr modint& operator*=(const modint& a){
        (x *= a.x)%=mod;
        return *this;
    }
    constexpr modint operator*(const modint& a) const{
        return modint(*this) *= a;
    }
    constexpr modint pow(unsigned long long pw) const{
        modint res(1), comp(*this);
        while(pw){
            if(pw&1) res *= comp;
            comp *= comp;
            pw >>= 1;
        }
        return res;
    }
    //以下、modが素数のときのみ
    constexpr modint inv() const{
        return modint(*this).pow(mod - 2);
    }
    constexpr modint& operator/=(const modint &a){
        (x *= a.inv().x)%=mod;
        return *this;
    }
    constexpr modint operator/(const modint &a) const{
        return modint(*this) /= a;
    }
};
#define mod2 1000000007
using mint = modint<mod2>;

ostream& operator<<(ostream& os, const mint& a){
    os << a.x;
    return os;
}
using vm = vector<mint>;

int main() {
    cin>>N>>K;
    vector<int> a(N);
    rep(i, N) cin>>a[i];
    const int max_sum = K * N;
    vector<vm> dp(N + 1, vm(max_sum + 1, 0));
    dp[0][0] = 1;
    struct query{int j, k; mint a; query(int _j, int _k, mint _a) : j(_j), k(_k), a(_a){}};
    rep(i, N){
        queue<query> que;
        rep(j, N + 1){
            rep(k, max_sum + 1){
                if(dp[j][k].x != 0) que.emplace(j + 1, min(max_sum, k + a[i]), dp[j][k]);
            }
        }
        while(!que.empty()){
            query q = que.front(); que.pop();
            dp[q.j][q.k] += q.a;
        }
    }
    mint res(0);
    reps(j, 1, N + 1){
        rep(k, max_sum + 1){
            if(j * K <= k) res += dp[j][k];
        }
    }
    cout<<res<<endl;
}
0