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

Submission #4063818

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> > (x + 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 <= x; 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 >= x) sum = x - j;
                        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 >= x) sum = x - j;
                        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 >= x) sum = x - j;
                    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;

    cout << dp[n][x][0] << endl;
    return 0;
}

Submission

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

Test case

Set

Set name Score得点 / Max score Cases
Sample - sample_01.txt,sample_02.txt
All 20 / 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 1 ms 256 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 AC 3 ms 1920 KB
subtask1_06.txt AC 9 ms 11648 KB
subtask1_07.txt AC 5 ms 4608 KB
subtask1_08.txt AC 9 ms 8576 KB
subtask1_09.txt AC 4 ms 2944 KB
subtask1_10.txt AC 2 ms 1152 KB
subtask1_11.txt AC 6 ms 6016 KB
subtask1_12.txt AC 103 ms 131328 KB
subtask1_13.txt AC 6 ms 6016 KB
subtask1_14.txt AC 104 ms 131328 KB
subtask1_15.txt AC 119 ms 131328 KB
subtask1_16.txt AC 120 ms 131328 KB
subtask1_17.txt AC 194 ms 131328 KB
subtask1_18.txt AC 103 ms 131328 KB
subtask1_19.txt AC 140 ms 131328 KB
subtask1_20.txt AC 120 ms 131328 KB
subtask1_21.txt AC 2 ms 768 KB
subtask1_22.txt AC 2 ms 768 KB