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

Submission #4063613

Source codeソースコード

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

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, 0)));
    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++){
                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][j][k];
                        dp[i + 1][j][k + 1] %= MOD;
                    }else{
                        int num = k / 2;
                        int sum = ((1 + num) * num) / 2;
                        if(j + sum <= x){
                            dp[i + 1][j + sum][1] += dp[i][j][k];
                            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][j][k];
                        dp[i + 1][j][k + 1] %= MOD;
                    }else{
                        int num = k / 2;
                        int sum = ((1 + num) * num) / 2;
                        if(j + sum <= x){
                            dp[i + 1][j + sum][0] += dp[i][j][k];
                            dp[i + 1][j + sum][0] %= MOD;
                        }
                    }
                }
                
                if((s[i] != '2' && s[i] != '5') || s[i] == '?'){
                    int val = 1;
                    if(s[i] == '?') val = 8;
                    
                    int num = k / 2;
                    int sum = ((1 + num) * num) / 2;
                    
                    if(j + sum <= x){
                        dp[i + 1][j + sum][0] += dp[i][j][k] * val;
                        dp[i + 1][j + sum][0] %= MOD;
                    }
                    //cout << i << " " << j << " " << k << " " << num << " " << sum << endl;
                }
            }
        }
    }

    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状態 WA
Score得点 0
Source lengthソースコード長 2418 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 WA
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 WA
subtask1_06.txt AC 9 ms 11648 KB
subtask1_07.txt WA
subtask1_08.txt WA
subtask1_09.txt WA
subtask1_10.txt WA
subtask1_11.txt WA
subtask1_12.txt AC 98 ms 131328 KB
subtask1_13.txt WA
subtask1_14.txt AC 101 ms 131328 KB
subtask1_15.txt WA
subtask1_16.txt WA
subtask1_17.txt WA
subtask1_18.txt AC 98 ms 131328 KB
subtask1_19.txt WA
subtask1_20.txt WA
subtask1_21.txt WA
subtask1_22.txt WA