結果

問題 No.1740 Alone 'a'
ユーザー norikamenorikame
提出日時 2021-11-13 18:34:24
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 26 ms / 2,000 ms
コード長 997 bytes
コンパイル時間 2,029 ms
コンパイル使用メモリ 203,268 KB
実行使用メモリ 15,736 KB
最終ジャッジ日時 2023-08-18 12:26:42
合計ジャッジ時間 4,224 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 AC 1 ms
4,376 KB
testcase_02 AC 2 ms
4,376 KB
testcase_03 AC 26 ms
15,732 KB
testcase_04 AC 25 ms
15,736 KB
testcase_05 AC 3 ms
4,380 KB
testcase_06 AC 2 ms
4,380 KB
testcase_07 AC 2 ms
4,376 KB
testcase_08 AC 1 ms
4,380 KB
testcase_09 AC 1 ms
4,380 KB
testcase_10 AC 1 ms
4,376 KB
testcase_11 AC 6 ms
5,648 KB
testcase_12 AC 21 ms
13,248 KB
testcase_13 AC 21 ms
12,568 KB
testcase_14 AC 25 ms
14,980 KB
testcase_15 AC 2 ms
4,380 KB
testcase_16 AC 19 ms
12,396 KB
testcase_17 AC 2 ms
4,376 KB
testcase_18 AC 4 ms
4,624 KB
testcase_19 AC 21 ms
13,412 KB
testcase_20 AC 13 ms
8,440 KB
testcase_21 AC 17 ms
10,684 KB
testcase_22 AC 19 ms
11,916 KB
testcase_23 AC 19 ms
11,800 KB
testcase_24 AC 13 ms
8,436 KB
testcase_25 AC 13 ms
8,592 KB
testcase_26 AC 16 ms
10,164 KB
testcase_27 AC 18 ms
10,972 KB
testcase_28 AC 15 ms
9,392 KB
testcase_29 AC 25 ms
15,356 KB
testcase_30 AC 17 ms
10,496 KB
testcase_31 AC 19 ms
12,044 KB
testcase_32 AC 16 ms
9,608 KB
testcase_33 AC 18 ms
11,920 KB
testcase_34 AC 5 ms
4,880 KB
testcase_35 AC 15 ms
9,132 KB
testcase_36 AC 12 ms
8,284 KB
testcase_37 AC 5 ms
5,144 KB
testcase_38 AC 11 ms
7,252 KB
testcase_39 AC 3 ms
4,376 KB
testcase_40 AC 7 ms
5,672 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))
#define rep3(i, m, n) for (int i=(m); (i)<(int)(n); ++(i))
#define repr(i, n) for (int i=(int)(n)-1; (i)>=0; --(i))
#define rep3r(i, m, n) for (int i=(int)(n)-1; (i)>=(int)(m); --(i))
#define all(x) (x).begin(), (x).end()

const ll mod = 998244353LL;

int main() {
	int n;
	string s;
	cin >> n >> s;
	vector<vector<ll>> dp(n+1, vector<ll>(2));
	vector<ll> cpow25(n+1, 1);
	rep(i, n) cpow25[i+1] = cpow25[i] * 25 % mod;
	repr(i, n) {
		if (s[i] == 'a') dp[i][1] = (dp[i][1] + dp[i+1][0]) % mod;
		else {
			int len1 = s[i] - 'b';
			dp[i][1] = (dp[i][1] + cpow25[n-(i+1)]) % mod;
			if (n-(i+1)-1 >= 0) dp[i][1] = (dp[i][1] + len1 * cpow25[n-(i+1)-1] * (n-(i+1)) % mod) % mod;
			dp[i][1] = (dp[i][1] + dp[i+1][1]) % mod;
			dp[i][0] = (dp[i][0] + len1 * cpow25[n-(i+1)] % mod) % mod;
			dp[i][0] = (dp[i][0] + dp[i+1][0]) % mod;
		}
	}
	cout << dp[0][1] << endl;
	return 0;
}
0