結果

問題 No.1740 Alone 'a'
ユーザー lloyz
提出日時 2021-11-13 11:21:05
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 639 bytes
コンパイル時間 241 ms
コンパイル使用メモリ 82,332 KB
実行使用メモリ 70,696 KB
最終ジャッジ日時 2024-11-27 04:12:06
合計ジャッジ時間 3,343 ms
ジャッジサーバーID
(参考情報)
judge5 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 7 WA * 31
権限があれば一括ダウンロードができます

ソースコード

diff #

n = int(input())
S = list(input())
mod = 998244353

ans = 0
a_cnt = 0
for i in range(n - 1):
    if ord(S[i]) > ord('a'):
        if a_cnt == 0:
            ans += (ord(S[i]) - ord('b')) * (n - i - 1) * pow(25, n - i - 2, mod) % mod
            ans %= mod
            ans += pow(25, n - i - 1, mod)
            ans %= mod
        elif a_cnt == 1:
            ans += (ord(S[i]) - ord('b')) * pow(25, n - i - 1, mod)
    else:
        a_cnt += 1
        if a_cnt == 2:
            break
if a_cnt == 0 and S[-1] != 'a':
    ans += 1
    ans %= mod
elif a_cnt == 1 and S[-1] != 'a':
    ans += ord(S[-1]) - ord('b')
    ans %= mod
print(ans)

0