結果
| 問題 |
No.1646 Avoid Palindrome
|
| コンテスト | |
| ユーザー |
charmychachacha
|
| 提出日時 | 2021-08-13 22:11:19 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 384 ms / 3,000 ms |
| コード長 | 1,027 bytes |
| コンパイル時間 | 1,693 ms |
| コンパイル使用メモリ | 167,380 KB |
| 実行使用メモリ | 279,424 KB |
| 最終ジャッジ日時 | 2024-11-08 15:27:09 |
| 合計ジャッジ時間 | 16,886 ms |
|
ジャッジサーバーID (参考情報) |
judge5 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 4 |
| other | AC * 40 |
ソースコード
#include <bits/stdc++.h>
using namespace std;
int main(){
ios::sync_with_stdio(0);
cin.tie(0); cout.tie(0);
int N; string S;
cin >> N >> S;
if(N == 1 && S == "?"){
cout << 26 << "\n"; return 0;
}else if(N == 1){
cout << 1 << "\n"; return 0;
}
long long mod = 998244353;
long long dp[50010][680] = {};
long long ikkomae[50010][26] = {};
for(int i = 0; i < 676; i++){
char c1 = 'a' + (i / 26);
char c2 = 'a' + (i % 26);
if(c1 == c2) continue;
if(S[0] != '?' && S[0] != c1) continue;
if(S[1] != '?' && S[1] != c2) continue;
dp[1][i] = 1;
ikkomae[1][i % 26] ++;
}
for(int i = 2; i < N; i++){
for(int j = 0; j < 676; j++){
char c1 = 'a' + (j / 26);
char c2 = 'a' + (j % 26);
if(c1 == c2) continue;
if(S[i] != '?' && S[i] != c2) continue;
dp[i][j] = (mod + ikkomae[i-1][j/26] - dp[i-1][26*(j%26)+j/26]) % mod;
ikkomae[i][j%26] += dp[i][j];
ikkomae[i][j%26] %= mod;
}
}
long long ans = 0;
for(int i = 0; i < 676; i++) ans += dp[N-1][i];
cout << ans % mod << "\n";
}
charmychachacha