結果

問題 No.1702 count good string
ユーザー simansiman
提出日時 2023-02-23 09:56:09
言語 C++17(clang)
(17.0.6 + boost 1.87.0)
結果
AC  
実行時間 29 ms / 2,000 ms
コード長 897 bytes
コンパイル時間 2,806 ms
コンパイル使用メモリ 141,884 KB
実行使用メモリ 11,556 KB
最終ジャッジ日時 2024-07-23 07:23:39
合計ジャッジ時間 4,431 ms
ジャッジサーバーID
(参考情報)
judge5 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 47
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <cassert>
#include <cmath>
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <climits>
#include <map>
#include <queue>
#include <set>
#include <cstring>
#include <vector>

using namespace std;
typedef long long ll;

const ll MOD = 1000000007;
int N;
string S;

ll solver(string T) {
  ll dp[N + 1][10];
  memset(dp, 0, sizeof(dp));
  dp[0][0] = 1;

  for (int i = 1; i <= N; ++i) {
    char ch = S[i - 1];

    memcpy(dp[i], dp[i - 1], sizeof(dp[i]));

    for (int j = 1; j <= 9; ++j) {
      if (ch != T[j - 1]) continue;

      dp[i][j] += dp[i - 1][j - 1];
      dp[i][j] %= MOD;
    }
  }

  return dp[N][9];
}

int main() {
  cin >> N;
  cin >> S;
  string T = "yukicoder";

  ll ans = 0;
  ans += solver(T);

  for (int i = 0; i < 9; ++i) {
    string str = T;
    str[i] = '?';
    ans += solver(str);
    ans %= MOD;
  }

  cout << ans << endl;

  return 0;
}
0