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

Submission #4063804

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;
    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状態 RE
Score得点 0
Source lengthソースコード長 2692 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 RE
sample_02.txt RE
subtask1_01.txt RE
subtask1_02.txt RE
subtask1_03.txt RE
subtask1_04.txt RE
subtask1_05.txt RE
subtask1_06.txt RE
subtask1_07.txt RE
subtask1_08.txt RE
subtask1_09.txt RE
subtask1_10.txt RE
subtask1_11.txt RE
subtask1_12.txt RE
subtask1_13.txt RE
subtask1_14.txt RE
subtask1_15.txt RE
subtask1_16.txt RE
subtask1_17.txt RE
subtask1_18.txt RE
subtask1_19.txt RE
subtask1_20.txt RE
subtask1_21.txt RE
subtask1_22.txt RE