結果
| 問題 |
No.1646 Avoid Palindrome
|
| コンテスト | |
| ユーザー |
titia
|
| 提出日時 | 2021-08-14 00:20:01 |
| 言語 | Python3 (3.13.1 + numpy 2.2.1 + scipy 1.14.1) |
| 結果 |
TLE
|
| 実行時間 | - |
| コード長 | 717 bytes |
| コンパイル時間 | 170 ms |
| コンパイル使用メモリ | 12,672 KB |
| 実行使用メモリ | 18,852 KB |
| 最終ジャッジ日時 | 2024-10-04 01:17:03 |
| 合計ジャッジ時間 | 5,154 ms |
|
ジャッジサーバーID (参考情報) |
judge5 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 4 |
| other | TLE * 1 -- * 39 |
ソースコード
import sys
input = sys.stdin.readline
mod=998244353
N=int(input())
S=list(input().strip())
for i in range(N):
S[i]=ord(S[i])-97
if N==1:
print(1)
exit()
DP=[0]*(26*26)
for i in range(26):
for j in range(26):
if i==j:
continue
if (i==S[0] or -34==S[0]) and (j==S[1] or -34==S[1]):
DP[i*26+j]=1
#print(DP)
for stind in range(2,N):
NDP=[0]*(26*26)
x=S[stind]
for i in range(26):
for j in range(26):
kake=DP[i*26+j]
for k in range(26):
if (x==k or x==-34) and i!=k and j!=k:
NDP[j*26+k]+=kake
NDP[j*26+k]%=mod
DP=NDP
print(sum(DP)%mod)
titia