結果

問題 No.1740 Alone 'a'
ユーザー mortal
提出日時 2022-01-17 20:50:50
言語 C++14
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 158 ms / 2,000 ms
コード長 557 bytes
コンパイル時間 1,502 ms
コンパイル使用メモリ 167,868 KB
実行使用メモリ 28,652 KB
最終ジャッジ日時 2024-11-23 12:59:55
合計ジャッジ時間 4,453 ms
ジャッジサーバーID
(参考情報)
judge3 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 38
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define mod 998244353
ll dp[200005][2][2];
string s;
int n;
ll solve(int pos,bool used,bool small){
	if(pos==n){
		return (ll)(used&&small);

	}
	if(dp[pos][used][small]!=-1)
		return dp[pos][used][small];
	ll ans=0;

	char r=small?'z':s[pos];
	char l='a';
	if(used)
		l++;
	for(char c=l;c<=r;c++){
		ans+=solve(pos+1,(c=='a')|used,small|(c<r));
		ans%=mod;
	}
	return dp[pos][used][small]=ans;



}

int main() {
	cin >> n >> s;
	
	memset(dp,-1,sizeof(dp));
	cout<<solve(0,0,0);
	
	
}
0