結果

問題 No.1740 Alone 'a'
ユーザー 沙耶花
提出日時 2021-11-12 21:33:51
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 75 ms / 2,000 ms
コード長 650 bytes
コンパイル時間 4,475 ms
コンパイル使用メモリ 254,232 KB
最終ジャッジ日時 2025-01-25 15:55:25
ジャッジサーバーID
(参考情報)
judge1 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 38
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <stdio.h>
#include <bits/stdc++.h>
#include <atcoder/all>
using namespace atcoder;
using mint = modint998244353;
using namespace std;
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define Inf 1000000001


int main(){
	int n;
	cin>>n;
	string s;
	cin>>s;
	
	vector dp(2,vector<mint>(2,0));
	dp[0][0] = 1;
	
	rep(i,n){
		vector ndp(2,vector<mint>(2,0));
		int t = s[i] - 'a';
		rep(j,2){
			rep(k,2){
				rep(l,26){
					int nj = j,nk = k;
					if(j&&l==0)continue;
					if(l==0)nj = 1;
					if(k==0&&l>t)continue;
					if(l<t)nk = 1;
					ndp[nj][nk] += dp[j][k];
				}
			}
		}
		swap(dp,ndp);
	}
	
	cout<<dp[1][1].val()<<endl;
	return 0;
}
0