結果

問題 No.1646 Avoid Palindrome
ユーザー manjuuu_onsenmanjuuu_onsen
提出日時 2021-08-13 22:51:46
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
CE  
(最新)
AC  
(最初)
実行時間 -
コード長 1,581 bytes
コンパイル時間 2,543 ms
コンパイル使用メモリ 175,844 KB
最終ジャッジ日時 2024-04-26 03:24:42
合計ジャッジ時間 2,949 ms
ジャッジサーバーID
(参考情報)
judge4 / judge2
このコードへのチャレンジ
(要ログイン)
コンパイルエラー時のメッセージ・ソースコードは、提出者また管理者しか表示できないようにしております。(リジャッジ後のコンパイルエラーは公開されます)
ただし、clay言語の場合は開発者のデバッグのため、公開されます。

コンパイルメッセージ
In file included from /home/linuxbrew/.linuxbrew/Cellar/gcc/13.2.0/include/c++/13/string:43,
                 from /home/linuxbrew/.linuxbrew/Cellar/gcc/13.2.0/include/c++/13/bitset:52,
                 from /home/linuxbrew/.linuxbrew/Cellar/gcc/13.2.0/include/c++/13/x86_64-pc-linux-gnu/bits/stdc++.h:52,
                 from main.cpp:4:
/home/linuxbrew/.linuxbrew/Cellar/gcc/13.2.0/include/c++/13/bits/allocator.h: In destructor 'std::__cxx11::basic_string<char>::_Alloc_hider::~_Alloc_hider()':
/home/linuxbrew/.linuxbrew/Cellar/gcc/13.2.0/include/c++/13/bits/allocator.h:184:7: error: inlining failed in call to 'always_inline' 'std::allocator< <template-parameter-1-1> >::~allocator() noexcept [with _Tp = char]': target specific option mismatch
  184 |       ~allocator() _GLIBCXX_NOTHROW { }
      |       ^
In file included from /home/linuxbrew/.linuxbrew/Cellar/gcc/13.2.0/include/c++/13/string:54:
/home/linuxbrew/.linuxbrew/Cellar/gcc/13.2.0/include/c++/13/bits/basic_string.h:181:14: note: called from here
  181 |       struct _Alloc_hider : allocator_type // TODO check __is_final
      |              ^~~~~~~~~~~~

ソースコード

diff #

#pragma GCC target("avx2")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
#include<bits/stdc++.h>

using namespace std;
using ll = long long;
using pint = pair<int,int>;

#include"atcoder/modint"
using mint = atcoder::modint998244353; 
ostream &operator<<(std::ostream &os,const mint &p){return os << p.val();}
istream &operator>>(std::istream &is, mint &a){int64_t x;is >> x;a = mint(x);return (is);}


int main()
{
	int N; cin >> N;
	string s; cin >> s;

	if(N == 1) {
		if(s[0] == '?') cout << 26 << endl;
		else cout << 1 << endl;
		return 0;
	}

	constexpr int AL = 26;
	for(auto &i : s) {
		i = (i == '?' ? AL : i - 'a');
	}

	vector<vector<vector<mint>>> dp(N + 1, vector<vector<mint>>(AL, vector<mint>(AL)));
	for(int i = 0; i < AL; i++) {
		for(int j = 0; j < AL; j++) {
			dp[2][i][j] = (s[0] == i || s[0] == AL) && (s[1] == j || s[1] == AL);
			if(i == j)dp[2][i][j] = 0;
		}
	}

	for(int i = 2; i < N; i++) {
		for(int f = 0; f < AL; f++) {
			if(s[i - 2] != AL && s[i - 2] != f)continue;
			for(int p = 0; p < AL; p++) {
				if(s[i - 1] != AL && s[i - 1] != p)continue;
				if(s[i] != AL){
					if(f != s[i] && p != s[i])dp[i + 1][p][s[i]] += dp[i][f][p];
				}
				else {
					for(int j = 0; j < AL; j++) {
						
						if(f != j && p != j) {
							dp[i + 1][p][j] += dp[i][f][p];
						}
					}
				} 
			}
		}

	}


	mint sum = 0;
	for(int i = 0; i < AL; i++) {
		if(s[N - 2] != AL && s[N - 2] != i) continue;
		for(int j = 0; j < AL; j++) {
			if(s[N - 1] != AL && s[N - 1] != j) continue;

			sum += dp[N][i][j];
		}
	}	
	cout << sum << endl;

}
0