結果

問題 No.1740 Alone 'a'
ユーザー H3PO4
提出日時 2021-11-12 22:13:30
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 52 ms / 2,000 ms
コード長 569 bytes
コンパイル時間 359 ms
コンパイル使用メモリ 82,200 KB
実行使用メモリ 75,264 KB
最終ジャッジ日時 2024-11-25 19:08:49
合計ジャッジ時間 3,263 ms
ジャッジサーバーID
(参考情報)
judge4 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 38
権限があれば一括ダウンロードができます

ソースコード

diff #

en2asc = lambda s: ord(s) - 97

N = int(input())
S = input()
MOD = 998244353

p25 = [1] * N
for i in range(1, N):
    p25[i] = p25[i - 1] * 25 % MOD

ct_a = 0
ans = 0
for i, s in enumerate(S):
    a = en2asc(s)
    if a:
        # s != "a"
        if ct_a == 0:
            if i != N - 1:
                ans += (a - 1) * (N - i - 1) * p25[N - i - 2]
            ans += p25[N - i - 1]
        elif ct_a == 1:
            ans += (a - 1) * p25[N - i - 1]
        ans %= MOD
    else:
        # s == "a"
        ct_a += 1
        if ct_a > 1:
            break
print(ans)
0