結果

問題 No.1238 選抜クラス
ユーザー nawawannawawan
提出日時 2020-09-25 22:59:22
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
TLE  
実行時間 -
コード長 1,568 bytes
コンパイル時間 692 ms
コンパイル使用メモリ 75,592 KB
実行使用メモリ 67,456 KB
最終ジャッジ日時 2023-09-10 16:06:31
合計ジャッジ時間 4,580 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
8,756 KB
testcase_01 AC 1 ms
4,376 KB
testcase_02 AC 2 ms
4,380 KB
testcase_03 AC 1 ms
4,380 KB
testcase_04 AC 2 ms
4,376 KB
testcase_05 AC 1 ms
4,376 KB
testcase_06 AC 1 ms
4,376 KB
testcase_07 AC 1 ms
4,380 KB
testcase_08 AC 2 ms
4,380 KB
testcase_09 AC 2 ms
4,380 KB
testcase_10 AC 2 ms
4,380 KB
testcase_11 AC 3 ms
4,376 KB
testcase_12 AC 2 ms
4,380 KB
testcase_13 AC 2 ms
4,380 KB
testcase_14 AC 3 ms
4,380 KB
testcase_15 AC 7 ms
4,376 KB
testcase_16 AC 3 ms
4,376 KB
testcase_17 TLE -
testcase_18 -- -
testcase_19 -- -
testcase_20 -- -
testcase_21 -- -
testcase_22 -- -
testcase_23 -- -
testcase_24 -- -
testcase_25 -- -
testcase_26 -- -
testcase_27 -- -
testcase_28 -- -
testcase_29 -- -
testcase_30 -- -
testcase_31 -- -
testcase_32 -- -
testcase_33 -- -
testcase_34 -- -
testcase_35 -- -
testcase_36 -- -
testcase_37 -- -
testcase_38 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <vector>
using namespace std;
const int MOD = 1e9 + 7;
int main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int N, K;
    cin >> N >> K;
    vector<int> A(N);
    for(int i = 0; i < N; i++) cin >> A[i];
    int num = 1;
    int ans = 0;
    while(1){
        vector<vector<vector<int>>> dp(num + 1, vector<vector<int>>(N + 1, vector<int>(K * num + 1, -1)));
        dp[0][0][0] = 1;
        for(int i = 0; i <= num; i++){
            for(int j = 0; j < N; j++){
                for(int k = 0; k < K * num + 1; k++){
                    if(dp[i][j + 1][k] == -1) dp[i][j + 1][k] = dp[i][j][k];
                    else if(dp[i][j][k] != -1) dp[i][j + 1][k] = (dp[i][j][k] + dp[i][j + 1][k]) % MOD;
                    if(i == num) continue;
                    if(k + A[j] <= K * num && dp[i][j][k] != -1) {
                        if(dp[i + 1][j + 1][k + A[j]] == -1) dp[i + 1][j + 1][k + A[j]] = dp[i][j][k];
                        else dp[i + 1][j + 1][k + A[j]] = (dp[i][j][k] + dp[i + 1][j + 1][k + A[j]]) % MOD;
                    }
                    else if(k + A[j] > K * num && dp[i][j][k] != -1){
                        if(dp[i + 1][j + 1][K * num] == -1) dp[i + 1][j + 1][K * num] = dp[i][j][k];
                        else dp[i + 1][j + 1][K * num] = (dp[i][j][k] + dp[i + 1][j + 1][K* num]) % MOD;
                    }
                }
            }
        }
        if(dp[num][N][K * num] == -1) break;
        ans = (ans + dp[num][N][K * num]) % MOD;
        num++;
    }
    cout << ans << endl;
}
0