結果

問題 No.1171 Runs in Subsequences
ユーザー ohaini1123
提出日時 2020-08-15 12:50:29
言語 C++14
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 165 ms / 2,000 ms
コード長 1,104 bytes
コンパイル時間 1,909 ms
コンパイル使用メモリ 174,348 KB
実行使用メモリ 100,340 KB
最終ジャッジ日時 2024-10-10 17:41:09
合計ジャッジ時間 3,596 ms
ジャッジサーバーID
(参考情報)
judge5 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 4
other AC * 18
権限があれば一括ダウンロードができます

ソースコード

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