結果

問題 No.2419 MMA文字列2
コンテスト
ユーザー lloyz
提出日時 2023-08-23 00:46:05
言語 PyPy3
(8.0.0 + ACL)
コンパイル:
pypy3 -mpy_compile _filename_
実行:
pypy3 _filename_
結果
AC  
実行時間 160 ms / 2,000 ms
+ 339µs
コード長 398 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 605 ms
コンパイル使用メモリ 82,416 KB
実行使用メモリ 147,916 KB
最終ジャッジ日時 2026-10-05 00:14:20
合計ジャッジ時間 5,569 ms
ジャッジサーバーID
(参考情報)
judge3_0 / judge1_0
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2
other AC * 30
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

S = list(input())

n = len(S)
DP = [[0 for _ in range(26)] for _ in range(n + 1)]
ans = 0
for i in range(n):
    idx = ord(S[i]) - ord('A')
    for j in range(26):
        if j == idx:
            DP[i + 1][j] = DP[i][j] + 1
        else:
            DP[i + 1][j] = DP[i][j]
    for j in range(26):
        if j == idx:
            continue
        ans += DP[i][j] * (DP[i][j] - 1) // 2
print(ans)
0