結果

問題 No.1646 Avoid Palindrome
ユーザー kotatsugamekotatsugame
提出日時 2021-08-13 21:39:18
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 113 ms / 3,000 ms
コード長 957 bytes
コンパイル時間 840 ms
コンパイル使用メモリ 68,592 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-04-26 02:35:40
合計ジャッジ時間 5,130 ms
ジャッジサーバーID
(参考情報)
judge3 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,248 KB
testcase_01 AC 2 ms
5,376 KB
testcase_02 AC 2 ms
5,376 KB
testcase_03 AC 2 ms
5,376 KB
testcase_04 AC 85 ms
5,376 KB
testcase_05 AC 84 ms
5,376 KB
testcase_06 AC 81 ms
5,376 KB
testcase_07 AC 86 ms
5,376 KB
testcase_08 AC 85 ms
5,376 KB
testcase_09 AC 81 ms
5,376 KB
testcase_10 AC 83 ms
5,376 KB
testcase_11 AC 81 ms
5,376 KB
testcase_12 AC 84 ms
5,376 KB
testcase_13 AC 85 ms
5,376 KB
testcase_14 AC 103 ms
5,376 KB
testcase_15 AC 106 ms
5,376 KB
testcase_16 AC 102 ms
5,376 KB
testcase_17 AC 106 ms
5,376 KB
testcase_18 AC 104 ms
5,376 KB
testcase_19 AC 105 ms
5,376 KB
testcase_20 AC 106 ms
5,376 KB
testcase_21 AC 106 ms
5,376 KB
testcase_22 AC 104 ms
5,376 KB
testcase_23 AC 107 ms
5,376 KB
testcase_24 AC 111 ms
5,376 KB
testcase_25 AC 112 ms
5,376 KB
testcase_26 AC 112 ms
5,376 KB
testcase_27 AC 113 ms
5,376 KB
testcase_28 AC 111 ms
5,376 KB
testcase_29 AC 76 ms
5,376 KB
testcase_30 AC 75 ms
5,376 KB
testcase_31 AC 75 ms
5,376 KB
testcase_32 AC 75 ms
5,376 KB
testcase_33 AC 76 ms
5,376 KB
testcase_34 AC 113 ms
5,376 KB
testcase_35 AC 1 ms
5,376 KB
testcase_36 AC 2 ms
5,376 KB
testcase_37 AC 2 ms
5,376 KB
testcase_38 AC 2 ms
5,376 KB
testcase_39 AC 2 ms
5,376 KB
testcase_40 AC 2 ms
5,376 KB
testcase_41 AC 2 ms
5,376 KB
testcase_42 AC 2 ms
5,376 KB
testcase_43 AC 75 ms
5,376 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp:8:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
    8 | main()
      | ^~~~

ソースコード

diff #

#include<iostream>
#include<atcoder/modint>
using namespace std;
using mint=atcoder::modint998244353;
int N;
string S;
mint dp[2][26][26];
main()
{
	cin>>N>>S;
	if(N==1)
	{
		if(S[0]=='?')cout<<26<<endl;
		else cout<<1<<endl;
		return 0;
	}
	int now=0;
	for(int i=0;i<26;i++)if(S[0]=='?'||S[0]-'a'==i)
	{
		for(int j=0;j<26;j++)if(S[1]=='?'||S[1]-'a'==j)if(i!=j)
		{
			dp[now][i][j]=1;
		}
	}
	for(int i=2;i<N;i++)
	{
		char c=S[i];
		int nxt=1-now;
		for(int i=0;i<26;i++)for(int j=0;j<26;j++)dp[nxt][i][j]=0;
		if(c=='?')
		{
			for(int j=0;j<26;j++)
			{
				mint s=0;
				for(int i=0;i<26;i++)s+=dp[now][i][j];
				for(int i=0;i<26;i++)if(i!=j)
				{
					dp[nxt][j][i]+=s-dp[now][i][j];
				}
			}
		}
		else
		{
			for(int i=0;i<26;i++)if(c-'a'!=i)for(int j=0;j<26;j++)if(c-'a'!=j)
			{
				dp[nxt][j][c-'a']+=dp[now][i][j];
			}
		}
		now=nxt;
	}
	mint ans=0;
	for(int i=0;i<26;i++)for(int j=0;j<26;j++)ans+=dp[now][i][j];
	cout<<ans.val()<<endl;
}
0