結果
問題 | No.1740 Alone 'a' |
ユーザー |
👑 ![]() |
提出日時 | 2021-11-12 21:51:15 |
言語 | C++17(gcc12) (gcc 12.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 4 ms / 2,000 ms |
コード長 | 1,101 bytes |
コンパイル時間 | 1,766 ms |
コンパイル使用メモリ | 101,076 KB |
最終ジャッジ日時 | 2025-01-25 16:29:07 |
ジャッジサーバーID (参考情報) |
judge5 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 38 |
ソースコード
#include <iostream>#include <string>#include <vector>#include <algorithm>using namespace std;using i32 = int32_t;using u32 = uint32_t;using i64 = int64_t;using u64 = uint64_t;#define rep(i,n) for(int i=0; i<(n); i++)int main(){int N; cin >> N;string S; cin >> S;i64 dp[2][2] = {}; // [is same][used 'a']dp[1][0] = 1;for (char c : S) {i64 ci = c - 'a';i64 nxdp[2][2] = {};nxdp[0][0] += dp[0][0] * 25;nxdp[0][1] += dp[0][1] * 25;nxdp[0][1] += dp[0][0];if (ci == 0) {nxdp[1][1] += dp[1][0];}else {nxdp[1][0] += dp[1][0];nxdp[1][1] += dp[1][1];nxdp[0][0] += dp[1][0] * (ci - 1);nxdp[0][1] += dp[1][1] * (ci - 1);nxdp[0][1] += dp[1][0];}rep(s, 2) rep(t, 2) dp[s][t] = nxdp[s][t] % 998244353;}cout << dp[0][1] << endl;return 0;}struct ios_do_not_sync {ios_do_not_sync() {ios::sync_with_stdio(false);cin.tie(nullptr);}} ios_do_not_sync_instance;