結果

問題 No.1702 count good string
ユーザー srjywrdnprktsrjywrdnprkt
提出日時 2023-06-03 15:58:07
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 119 ms / 2,000 ms
コード長 2,279 bytes
コンパイル時間 1,179 ms
コンパイル使用メモリ 114,832 KB
実行使用メモリ 61,912 KB
最終ジャッジ日時 2023-08-28 07:57:50
合計ジャッジ時間 7,340 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 1 ms
4,376 KB
testcase_02 AC 1 ms
4,376 KB
testcase_03 AC 1 ms
4,380 KB
testcase_04 AC 2 ms
4,380 KB
testcase_05 AC 1 ms
4,380 KB
testcase_06 AC 2 ms
4,380 KB
testcase_07 AC 2 ms
4,380 KB
testcase_08 AC 1 ms
4,376 KB
testcase_09 AC 1 ms
4,376 KB
testcase_10 AC 2 ms
4,376 KB
testcase_11 AC 2 ms
4,376 KB
testcase_12 AC 2 ms
4,376 KB
testcase_13 AC 119 ms
61,692 KB
testcase_14 AC 117 ms
61,636 KB
testcase_15 AC 118 ms
61,672 KB
testcase_16 AC 117 ms
61,864 KB
testcase_17 AC 119 ms
61,648 KB
testcase_18 AC 116 ms
61,676 KB
testcase_19 AC 115 ms
61,864 KB
testcase_20 AC 116 ms
61,860 KB
testcase_21 AC 117 ms
61,868 KB
testcase_22 AC 115 ms
61,684 KB
testcase_23 AC 2 ms
4,376 KB
testcase_24 AC 3 ms
4,380 KB
testcase_25 AC 3 ms
4,376 KB
testcase_26 AC 2 ms
4,376 KB
testcase_27 AC 2 ms
4,376 KB
testcase_28 AC 2 ms
4,376 KB
testcase_29 AC 2 ms
4,376 KB
testcase_30 AC 2 ms
4,380 KB
testcase_31 AC 3 ms
4,376 KB
testcase_32 AC 3 ms
4,380 KB
testcase_33 AC 116 ms
61,624 KB
testcase_34 AC 118 ms
61,672 KB
testcase_35 AC 115 ms
61,696 KB
testcase_36 AC 118 ms
61,688 KB
testcase_37 AC 116 ms
61,912 KB
testcase_38 AC 116 ms
61,692 KB
testcase_39 AC 116 ms
61,612 KB
testcase_40 AC 117 ms
61,688 KB
testcase_41 AC 116 ms
61,688 KB
testcase_42 AC 116 ms
61,844 KB
testcase_43 AC 119 ms
61,628 KB
testcase_44 AC 117 ms
61,648 KB
testcase_45 AC 1 ms
4,380 KB
testcase_46 AC 1 ms
4,376 KB
testcase_47 AC 2 ms
4,380 KB
testcase_48 AC 1 ms
4,376 KB
testcase_49 AC 1 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <vector>
#include <cmath>
#include <map>
#include <set>
#include <iomanip>
#include <queue>
#include <algorithm>
#include <numeric>
#include <deque>
#include <complex>
#include <cassert>

using namespace std;
using ll = long long;

const ll modc = 1e9+7;
class mint {
    ll x;
public:
    mint(ll x=0) : x((x%modc+modc)%modc) {}
    mint operator-() const {
      return mint(-x);
    }
    mint& operator+=(const mint& a) {
        if ((x += a.x) >= modc) x -= modc;
        return *this;
    }
    mint& operator-=(const mint& a) {
        if ((x += modc-a.x) >= modc) x -= modc;
        return *this;
    }
    mint& operator*=(const  mint& a) {
        (x *= a.x) %= modc;
        return *this;
    }
    mint operator+(const mint& a) const {
        mint res(*this);
        return res+=a;
    }
    mint operator-(const mint& a) const {
        mint res(*this);
        return res-=a;
    }
    mint operator*(const mint& a) const {
        mint res(*this);
        return res*=a;
    }
    mint pow(ll t) const {
        if (!t) return 1;
        mint a = pow(t>>1);
        a *= a;
        if (t&1) a *= *this;
        return a;
    }
    mint inv() const {
        return pow(modc-2);
    }
    mint& operator/=(const mint& a) {
        return (*this) *= a.inv();
    }
    mint operator/(const mint& a) const {
        mint res(*this);
        return res/=a;
    }
    bool operator == (const mint& a) const{
        return x == a.x;
    }
    friend ostream& operator<<(ostream& os, const mint& m){
        os << m.x;
        return os;
    }
    friend istream& operator>>(istream& ip, mint&m) {
        ip >> m.x;
        return ip;
    }
};

int main(){

    ll N;
    string S, T="yukicoder";
    cin >> N >> S;
    vector<vector<vector<mint>>> dp(N+1, vector(10, vector<mint>(2)));
    dp[0][0][0] = 1;
    for (int i=1; i<=N; i++){
        for (int j=0; j<10; j++){
            dp[i][j][0] += dp[i-1][j][0];
            dp[i][j][1] += dp[i-1][j][1];
            if (j && S[i-1] == T[j-1]){
                dp[i][j][0] += dp[i-1][j-1][0];
                dp[i][j][1] += dp[i-1][j-1][1];
            }
            if (j && S[i-1] == '?') dp[i][j][1] += dp[i-1][j-1][0];
        }
    }

    cout << dp[N][9][0]+dp[N][9][1] << endl;
}
0