結果

問題 No.1171 Runs in Subsequences
ユーザー optopt
提出日時 2020-07-15 15:10:08
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 1,263 ms / 2,000 ms
コード長 1,271 bytes
コンパイル時間 2,142 ms
コンパイル使用メモリ 203,108 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-08-14 04:15:08
合計ジャッジ時間 11,738 ms
ジャッジサーバーID
(参考情報)
judge14 / judge12
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 2 ms
4,380 KB
testcase_03 AC 1 ms
4,376 KB
testcase_04 AC 2 ms
4,380 KB
testcase_05 AC 1 ms
4,380 KB
testcase_06 AC 1 ms
4,376 KB
testcase_07 AC 2 ms
4,384 KB
testcase_08 AC 2 ms
4,380 KB
testcase_09 AC 1 ms
4,380 KB
testcase_10 AC 5 ms
4,380 KB
testcase_11 AC 6 ms
4,376 KB
testcase_12 AC 6 ms
4,376 KB
testcase_13 AC 5 ms
4,376 KB
testcase_14 AC 6 ms
4,380 KB
testcase_15 AC 1,216 ms
4,376 KB
testcase_16 AC 1,198 ms
4,384 KB
testcase_17 AC 1,261 ms
4,376 KB
testcase_18 AC 1,263 ms
4,380 KB
testcase_19 AC 1,262 ms
4,376 KB
testcase_20 AC 1,261 ms
4,376 KB
testcase_21 AC 1,262 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, n) for(int i=0; i<int(n); ++i)
const int MOD  = int(1e9)+7;


struct mint {
  ll x;
  mint(ll x=0) : x((x%MOD+MOD)%MOD) {}
  mint operator-() const { return mint(-x);}
  mint& operator+=(const mint a) { if ((x += a.x) >= MOD) x -= MOD; return *this; }
  mint& operator-=(const mint a) { if ((x -= a.x) < 0) x += MOD; return *this; }
  mint& operator*=(const mint a) { (x *= a.x) %= MOD; return *this; }
  mint operator+(const mint a) const { return mint(*this) += a; }
  mint operator-(const mint a) const { return mint(*this) -= a; }
  mint operator*(const mint a) const { return mint(*this) *= a; }
  mint pow(ll t) const {
    if (!t) return 1;
    mint a = pow(t>>1);
    a *= a;
    if (t&1) a *= *this;
    return a;
  }
};
ostream& operator<<(ostream& os, const mint& a) { return os << a.x; }
using Vm = vector<mint>;


int main() {
  const int M = 26;
  string s; cin >> s;
  int n = s.size();

  Vm dp(M+1);
  dp[M] = 1;

  mint ans = mint(2).pow(n) - 1;
  rep(i, n) {
    Vm _dp = dp;
    int x = s[i] - 'a';
    rep(j, M+1) {
      _dp[x] += dp[j];
      if (x != j && j < M) ans += dp[j] * mint(2).pow(n-1-i);
    }
    swap(dp, _dp);
  }
  cout << ans << "\n";
  return 0;
}
0