結果

問題 No.2419 MMA文字列2
ユーザー Kyoro ID
提出日時 2023-08-12 14:52:48
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 416 ms / 2,000 ms
コード長 814 bytes
コンパイル時間 192 ms
コンパイル使用メモリ 82,260 KB
実行使用メモリ 135,316 KB
最終ジャッジ日時 2024-11-19 21:59:38
合計ジャッジ時間 7,775 ms
ジャッジサーバーID
(参考情報)
judge2 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2
other AC * 30
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
import logging
import math
input = sys.stdin.readline
logger = logging.getLogger(__name__)


def read():
    S = input().strip()
    return S,


def nC2(n):
    return n * (n-1) // 2


def solve(S):
    N = len(S)
    count = [[0 for j in range(26)] for i in range(N)]
    for i in range(N):
        s = ord(S[i]) - ord('A')
        for j in range(26):
            count[i][j] = count[i-1][j]
        count[i][s] += 1
    
    ans = 0
    for i in range(1, N):
        s = ord(S[i]) - ord('A')
        for j in range(26):
            if j == s:
                continue
            if count[i-1][j] >= 2:
                ans += nC2(count[i-1][j])
    return ans


if __name__ == "__main__":
    inputs = read()
    outputs = solve(*inputs)
    if outputs is not None:
        print("%s" % str(outputs))
0