結果

問題 No.1171 Runs in Subsequences
ユーザー ohaini1123ohaini1123
提出日時 2020-08-15 12:50:29
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 162 ms / 2,000 ms
コード長 1,104 bytes
コンパイル時間 2,066 ms
コンパイル使用メモリ 170,112 KB
実行使用メモリ 100,392 KB
最終ジャッジ日時 2023-08-01 01:16:35
合計ジャッジ時間 4,007 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 1 ms
4,376 KB
testcase_03 AC 2 ms
4,376 KB
testcase_04 AC 1 ms
4,376 KB
testcase_05 AC 1 ms
4,380 KB
testcase_06 AC 1 ms
4,376 KB
testcase_07 AC 1 ms
4,376 KB
testcase_08 AC 1 ms
4,380 KB
testcase_09 AC 1 ms
4,376 KB
testcase_10 AC 2 ms
4,380 KB
testcase_11 AC 2 ms
4,380 KB
testcase_12 AC 2 ms
4,376 KB
testcase_13 AC 2 ms
4,376 KB
testcase_14 AC 3 ms
4,380 KB
testcase_15 AC 157 ms
96,472 KB
testcase_16 AC 154 ms
95,368 KB
testcase_17 AC 160 ms
100,392 KB
testcase_18 AC 161 ms
100,164 KB
testcase_19 AC 160 ms
100,256 KB
testcase_20 AC 162 ms
100,156 KB
testcase_21 AC 160 ms
100,120 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;

template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }

using ll = long long;
using P = pair<ll,ll>;
using graph = vector<vector<int>>;

const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
const ll INF = 1LL<<60;
const ll mod = 1000000007LL;

#define rep(i, n) for (int i = 0; i < (int)(n); i++)

int main() {
  string S;
  cin>>S;
  ll N = S.size();
  vector<vector<ll>> dp(N+1,vector<ll>(26,0LL)),dpp(N+1,vector<ll>(26,0LL));
  rep(i,N){
    int t = S[i] - 'a';
      rep(j,26) dp[i+1][j]=dp[i][j];
      rep(j,26) {
        if(j!=t) dp[i+1][t]=(dp[i+1][t]+dp[i][j]+dpp[i][j])%mod;
        if(j==t) dp[i+1][t]=(dp[i+1][t]+dp[i][j])%mod;
      }
      rep(j,26){
        dpp[i+1][j]=(dpp[i+1][j]+dpp[i][j])%mod;
        dpp[i+1][t]=(dpp[i+1][t]+dpp[i][j])%mod;
      }
      dp[i+1][t]=(dp[i+1][t]+1)%mod;
      dpp[i+1][t]=(dpp[i+1][t]+1)%mod;
  }
  ll ans = 0;
  rep(i,26) ans = (ans+dp[N][i])%mod;
  cout<<ans<<endl;
}
0