結果
| 問題 |
No.1646 Avoid Palindrome
|
| コンテスト | |
| ユーザー |
srjywrdnprkt
|
| 提出日時 | 2023-06-08 00:47:37 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 2,351 bytes |
| コンパイル時間 | 870 ms |
| コンパイル使用メモリ | 105,696 KB |
| 最終ジャッジ日時 | 2025-02-13 23:21:31 |
|
ジャッジサーバーID (参考情報) |
judge5 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 4 |
| other | AC * 9 WA * 31 |
ソースコード
#include <iostream>
#include <vector>
#include <cmath>
#include <map>
#include <set>
#include <iomanip>
#include <queue>
#include <algorithm>
#include <numeric>
#include <deque>
#include <complex>
#include <cassert>
using namespace std;
using ll = long long;
const ll modc = 998244353;
class mint {
ll x;
public:
mint(ll x=0) : x((x%modc+modc)%modc) {}
mint operator-() const {
return mint(-x);
}
mint& operator+=(const mint& a) {
if ((x += a.x) >= modc) x -= modc;
return *this;
}
mint& operator-=(const mint& a) {
if ((x += modc-a.x) >= modc) x -= modc;
return *this;
}
mint& operator*=(const mint& a) {
(x *= a.x) %= modc;
return *this;
}
mint operator+(const mint& a) const {
mint res(*this);
return res+=a;
}
mint operator-(const mint& a) const {
mint res(*this);
return res-=a;
}
mint operator*(const mint& a) const {
mint res(*this);
return res*=a;
}
mint pow(ll t) const {
if (!t) return 1;
mint a = pow(t>>1);
a *= a;
if (t&1) a *= *this;
return a;
}
mint inv() const {
return pow(modc-2);
}
mint& operator/=(const mint& a) {
return (*this) *= a.inv();
}
mint operator/(const mint& a) const {
mint res(*this);
return res/=a;
}
bool operator == (const mint& a) const{
return x == a.x;
}
friend ostream& operator<<(ostream& os, const mint& m){
os << m.x;
return os;
}
friend istream& operator>>(istream& ip, mint &m) {
ll t;
ip >> t;
m = mint(t);
return ip;
}
};
int main(){
int N;
string S;
cin >> N >> S;
mint ans=1;
for (int i=0; i<N-1; i++){
if (S[i] != '?' && S[i] == S[i+1]){
cout << 0 << endl;
return 0;
}
}
for (int i=0; i<N-2; i++){
if (S[i] != '?' && S[i] == S[i+2]){
cout << 0 << endl;
return 0;
}
}
for (int i=0; i<N; i++){
if (S[i] == '?'){
ll x=26;
for (int j=1; j<=2; j++) if (i-j>=0) x--;
for (int j=1; j<=2; j++) if (i+j<N && S[i+j] != '?') x--;
ans *= x;
}
}
cout << ans << endl;
}
srjywrdnprkt