dwangoプログラミングコンテスト

Submission #4063777

Source codeソースコード

#include<bits/stdc++.h>
using namespace std;
#define int long long
const int MOD = 1000000007LL;

signed main(){

    int n, x; cin >> n >> x;
    string s; cin >> s;
    //番兵
    s.push_back('m');
    n = (int)s.size();
    vector<vector<vector<int> > > dp(n + 2, vector<vector<int> > (n * n + 1, vector<int> (n + 1, 0LL)));
    dp[0][0][0] = 1LL;

    for(int i = 0; i <= n; i++){

        //cout << s[i] << endl;
        for(int j = 0; j <= n * n; j++){
            for(int k = 0; k <= n; k++){
                
                //cout << "dp[" << i << "][" << j << "][" << k << "] = " << dp[i][j][k] << endl; 
                if(i == n) continue;
                if(dp[i][j][k] == 0) continue;

                if(s[i] == '2' || s[i] == '?'){
                    if(k % 2 == 0){
                        dp[i + 1][j][k + 1] = (dp[i + 1][j][k + 1] + dp[i][j][k]) % MOD;
                        dp[i + 1][j][k + 1] %= MOD;
                    }else{
                        int num = k / 2;
                        int sum = ((1 + num) * num) / 2;
                        if(j + sum <= n * n){
                            dp[i + 1][j + sum][1] = (dp[i + 1][j + sum][1] + dp[i][j][k]) % MOD;
                            dp[i + 1][j + sum][1] %= MOD;
                        }   
                    }
                }
                
                if(s[i] == '5' || s[i] == '?'){
                    if(k % 2 == 1){
                        dp[i + 1][j][k + 1] = (dp[i + 1][j][k + 1] + dp[i][j][k]) % MOD;
                        dp[i + 1][j][k + 1] %= MOD;
                    }else{
                        int num = k / 2;
                        int sum = ((1 + num) * num) / 2;
                        if(j + sum <= n * n){
                            dp[i + 1][j + sum][0] = (dp[i + 1][j + sum][0] + dp[i][j][k]) % MOD;
                            dp[i + 1][j + sum][0] %= MOD;
                        }
                    }
                }
                
                if((s[i] != '2' && s[i] != '5') || s[i] == '?'){
                    int val = 1LL;
                    if(s[i] == '?') val = 8LL;
                    
                    int num = k / 2;
                    int sum = ((1 + num) * num) / 2;
                    if(j + sum <= n * n){
                        dp[i + 1][j + sum][0] = (dp[i + 1][j + sum][0] + dp[i][j][k] * val) % MOD;
                        dp[i + 1][j + sum][0] %= MOD;
                    }
                }
            }
        }
    }

    int ans = 0LL;
    for(int j = x; j <= n * n; j++){
        ans += dp[n][j][0];
        ans %= MOD;
    }

    cout << ans % MOD << endl;
    return 0;
}

Submission

Task問題 A - ニコニコ文字列2
User nameユーザ名 monkukui
Created time投稿日時
Language言語 C++14 (GCC 5.4.1)
Status状態 TLE
Score得点 0
Source lengthソースコード長 2730 Byte
File nameファイル名
Exec time実行時間 ms
Memory usageメモリ使用量 -

Test case

Set

Set name Score得点 / Max score Cases
Sample - sample_01.txt,sample_02.txt
All 0 / 20 sample_01.txt,sample_02.txt,subtask1_01.txt,subtask1_02.txt,subtask1_03.txt,subtask1_04.txt,subtask1_05.txt,subtask1_06.txt,subtask1_07.txt,subtask1_08.txt,subtask1_09.txt,subtask1_10.txt,subtask1_11.txt,subtask1_12.txt,subtask1_13.txt,subtask1_14.txt,subtask1_15.txt,subtask1_16.txt,subtask1_17.txt,subtask1_18.txt,subtask1_19.txt,subtask1_20.txt,subtask1_21.txt,subtask1_22.txt

Test case

Case name Status状態 Exec time実行時間 Memory usageメモリ使用量
sample_01.txt AC 1 ms 256 KB
sample_02.txt AC 2 ms 1024 KB
subtask1_01.txt AC 1 ms 256 KB
subtask1_02.txt AC 1 ms 256 KB
subtask1_03.txt AC 1 ms 256 KB
subtask1_04.txt AC 1 ms 256 KB
subtask1_05.txt TLE
subtask1_06.txt TLE
subtask1_07.txt TLE
subtask1_08.txt AC 154 ms 159616 KB
subtask1_09.txt AC 128 ms 141440 KB
subtask1_10.txt AC 23 ms 22784 KB
subtask1_11.txt TLE
subtask1_12.txt TLE
subtask1_13.txt TLE
subtask1_14.txt TLE
subtask1_15.txt TLE
subtask1_16.txt TLE
subtask1_17.txt TLE
subtask1_18.txt TLE
subtask1_19.txt TLE
subtask1_20.txt TLE
subtask1_21.txt TLE
subtask1_22.txt TLE