結果

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

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define mod 998244353
ll dp[100005][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