結果

問題 No.1171 Runs in Subsequences
ユーザー 00 Sakuda00 Sakuda
提出日時 2024-04-02 22:35:06
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 39 ms / 2,000 ms
コード長 558 bytes
コンパイル時間 2,387 ms
コンパイル使用メモリ 206,052 KB
実行使用メモリ 6,676 KB
最終ジャッジ日時 2024-04-02 22:35:10
合計ジャッジ時間 4,140 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <bits/stdc++.h>
#include <atcoder/modint>
using namespace std;
using ll = long long;
using namespace atcoder;
using mint = modint;
int main() {
	mint::set_mod((ll)1e9 + 7);
	string S;cin >> S;
	int N = S.size();
	vector<mint> dp(N + 1, 0);
	mint ans = 0;
	vector<mint> T(26, 0);
	vector<mint> U(26, 0);
	for (int i = 1;i <= N;i++) {
		dp[i]++;
		int now = S[i - 1] - 'a';
		for (int c = 0;c < 26;c++) {
			dp[i] += T[c] + (c == now ? 0 : U[c]);
		}
		T[now] += dp[i];
		U[now] += mint(2).pow(i - 1);
		ans += dp[i];
	}
	cout << ans.val() << endl;
}
0