結果
| 問題 |
No.1646 Avoid Palindrome
|
| コンテスト | |
| ユーザー |
brthyyjp
|
| 提出日時 | 2022-01-20 15:37:53 |
| 言語 | PyPy3 (7.3.15) |
| 結果 |
TLE
|
| 実行時間 | - |
| コード長 | 1,829 bytes |
| コンパイル時間 | 291 ms |
| コンパイル使用メモリ | 82,432 KB |
| 実行使用メモリ | 157,696 KB |
| 最終ジャッジ日時 | 2024-11-23 20:29:28 |
| 合計ジャッジ時間 | 122,179 ms |
|
ジャッジサーバーID (参考情報) |
judge5 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 4 |
| other | AC * 12 WA * 2 TLE * 26 |
ソースコード
import sys
import io, os
input = sys.stdin.readline
mod = 998244353
def main():
n = int(input())
s = str(input().rstrip())
if n == 1:
if s[0] == '?':
print(26)
else:
print(1)
exit()
dp = [0]*(26*26)
if s[0] != '?' and s[1] != '?':
c0 = ord(s[0])-ord('a')
c1 = ord(s[0])-ord('a')
dp[c1*26+c0] = 1
elif s[0] != '?':
c0 = ord(s[0])-ord('a')
for c1 in range(26):
if c0 == c1:
continue
dp[c1*26+c0] = 1
elif s[1] != '?':
c1 = ord(s[1])-ord('a')
for c0 in range(26):
if c0 == c1:
continue
dp[c1*26+c0] = 1
else:
for c0 in range(26):
for c1 in range(26):
if c0 == c1:
continue
dp[c1*26+c0] = 1
for i in range(2, n):
nx = [0]*(26*26)
c = s[i]
if c == '?':
for c in range(26):
for c0 in range(26):
if c0 == c:
continue
for c1 in range(26):
if c1 == c:
continue
nx[c*26+c1] += dp[c1*26+c0]
nx[c*26+c1] %= mod
else:
c = ord(c)-ord('a')
for c0 in range(26):
if c0 == c:
continue
for c1 in range(26):
if c1 == c:
continue
nx[c*26+c1] += dp[c1*26+c0]
nx[c*26+c1] %= mod
dp = nx
ans = 0
for c0 in range(26):
for c1 in range(26):
ans += dp[c1*26+c0]
ans %= mod
print(ans)
if __name__ == '__main__':
main()
brthyyjp