結果
| 問題 |
No.1740 Alone 'a'
|
| コンテスト | |
| ユーザー |
umezo
|
| 提出日時 | 2021-11-12 22:43:08 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 100 ms / 2,000 ms |
| コード長 | 761 bytes |
| コンパイル時間 | 1,847 ms |
| コンパイル使用メモリ | 195,200 KB |
| 最終ジャッジ日時 | 2025-01-25 17:14:09 |
|
ジャッジサーバーID (参考情報) |
judge4 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 38 |
ソースコード
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define ALL(v) v.begin(),v.end()
typedef long long ll;
#include<bits/stdc++.h>
using namespace std;
const int MOD=998244353;
ll dp[200200][2][2];
int main() {
ios::sync_with_stdio(false);
std::cin.tie(nullptr);
string s;
int n;
cin>>n>>s;
int cnt=0;
rep(i,n){
if(s[i]=='a') cnt++;
}
dp[0][0][0]=1;
rep(i,n){
int Ni=s[i]-'a';
rep(j,2) rep(k,2) rep(x,26){
int j2=j,k2=k;
if(x==0) ++j2;
if(j2>1) continue;
if(!k && (x>Ni)) continue;
if(x<Ni) k2=1;
dp[i+1][j2][k2]=(dp[i+1][j2][k2]+dp[i][j][k])%MOD;
}
}
if(cnt==1) cout<<(dp[n][1][0]+dp[n][1][1]-1+MOD)%MOD<<endl;
else cout<<(dp[n][1][0]+dp[n][1][1])%MOD<<endl;
return 0;
}
umezo