結果

問題 No.1171 Runs in Subsequences
ユーザー KudeKude
提出日時 2020-08-14 22:18:18
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 441 ms / 2,000 ms
コード長 2,097 bytes
コンパイル時間 1,755 ms
コンパイル使用メモリ 166,528 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-04-18 22:08:36
合計ジャッジ時間 5,238 ms
ジャッジサーバーID
(参考情報)
judge2 / judge5
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
5,248 KB
testcase_01 AC 2 ms
5,376 KB
testcase_02 AC 2 ms
5,376 KB
testcase_03 AC 2 ms
5,376 KB
testcase_04 AC 2 ms
5,376 KB
testcase_05 AC 2 ms
5,376 KB
testcase_06 AC 2 ms
5,376 KB
testcase_07 AC 2 ms
5,376 KB
testcase_08 AC 2 ms
5,376 KB
testcase_09 AC 1 ms
5,376 KB
testcase_10 AC 3 ms
5,376 KB
testcase_11 AC 3 ms
5,376 KB
testcase_12 AC 3 ms
5,376 KB
testcase_13 AC 3 ms
5,376 KB
testcase_14 AC 3 ms
5,376 KB
testcase_15 AC 422 ms
5,376 KB
testcase_16 AC 406 ms
5,376 KB
testcase_17 AC 428 ms
5,376 KB
testcase_18 AC 439 ms
5,376 KB
testcase_19 AC 441 ms
5,376 KB
testcase_20 AC 438 ms
5,376 KB
testcase_21 AC 430 ms
5,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define chmax(a, b) a = max(a, b);
#define chmin(a, b) a = min(a, b);
using namespace std;
using ll = long long;
using P = pair<int,int>;
using VI = vector<int>;
using VVI = vector<VI>;

#define MOD 1000000007
//#define MOD 998244353
struct mint {
	int i;
	mint() : i(0) {}
	mint(int x) {
		i = int(x % MOD);
		if (i < 0) i += MOD;
	}
	template<class T> mint(T x) {
		i = int(x % MOD);
		if (i < 0) i += MOD;
	}
	mint operator+(const mint x) const {return i + x.i;}
	mint operator-(const mint x) const {return i - x.i;}
	mint operator*(const mint x) const {return (long long)i * x.i;}
	mint operator/(const mint x) const {return (long long)i * x.pow(MOD - 2).i;}
	mint inv() {return pow(MOD - 2);}
	template<class T> mint pow(T p) const {
		long long r = 1;
		long long t = i;
		for(; p > 0; p >>= 1) {
			if (p & 1) r = r * t % MOD;
			t = t * t % MOD;
		}
		return r;
	}
	template<class T1, class T2> static mint pow(T1 a, T2 b) {
		long long r = 1;
		long long t = (long long)(a % MOD);
		for(; b > 0; b >>= 1) {
			if (b & 1) r = r * t % MOD;
			t = t * t % MOD;
		}
		return r;
	}
	mint& operator+=(const mint x) {
		i = (i + x.i) % MOD;
		return *this;
	}
	mint& operator-=(const mint x) {
		i = i - x.i;
		if (i < 0) i += MOD;
		return *this;
	}
	mint& operator*=(const mint x) {
		i = (int)((long long)i * x.i % MOD);
		return *this;
	}
	mint& operator/=(const mint x) {
		i = (long long)i * x.pow(MOD - 2).i % MOD;
		return *this;
	}
};

std::ostream& operator<<(std::ostream& os, const mint& m) {
	return os << m.i;
}


int main() {
    string s;
    cin >> s;
    vector<mint> dp(27);
    dp[26] = 1;
    mint ans = 0;
    rep(z, s.size()) {
        int x = s[z] - 'a';
        vector<mint> ndp(27);
        rep(i, 27) {
            if (i == x) {
                ndp[x] += dp[i] * 2;
            } else {
                ndp[x] += dp[i];
                ndp[i] += dp[i];
                ans += dp[i] * mint(2).pow(s.size() - 1 - z);
            }
        }
        dp = move(ndp);
    }
    cout << ans << endl;
}
0