結果

問題 No.2419 MMA文字列2
ユーザー Kyoro IDKyoro ID
提出日時 2023-08-12 14:52:48
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 404 ms / 2,000 ms
コード長 814 bytes
コンパイル時間 159 ms
コンパイル使用メモリ 82,432 KB
実行使用メモリ 135,680 KB
最終ジャッジ日時 2024-04-30 07:24:39
合計ジャッジ時間 7,456 ms
ジャッジサーバーID
(参考情報)
judge1 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 72 ms
71,680 KB
testcase_01 AC 70 ms
71,680 KB
testcase_02 AC 77 ms
71,936 KB
testcase_03 AC 88 ms
79,052 KB
testcase_04 AC 79 ms
75,216 KB
testcase_05 AC 72 ms
71,424 KB
testcase_06 AC 87 ms
71,296 KB
testcase_07 AC 70 ms
71,424 KB
testcase_08 AC 72 ms
71,680 KB
testcase_09 AC 70 ms
71,680 KB
testcase_10 AC 72 ms
71,808 KB
testcase_11 AC 78 ms
75,392 KB
testcase_12 AC 165 ms
91,944 KB
testcase_13 AC 103 ms
79,616 KB
testcase_14 AC 223 ms
103,552 KB
testcase_15 AC 169 ms
94,180 KB
testcase_16 AC 228 ms
104,344 KB
testcase_17 AC 131 ms
87,040 KB
testcase_18 AC 232 ms
105,600 KB
testcase_19 AC 248 ms
106,472 KB
testcase_20 AC 141 ms
87,936 KB
testcase_21 AC 126 ms
85,344 KB
testcase_22 AC 375 ms
135,496 KB
testcase_23 AC 374 ms
135,540 KB
testcase_24 AC 347 ms
135,492 KB
testcase_25 AC 377 ms
135,464 KB
testcase_26 AC 119 ms
86,120 KB
testcase_27 AC 343 ms
135,236 KB
testcase_28 AC 384 ms
135,424 KB
testcase_29 AC 382 ms
135,480 KB
testcase_30 AC 376 ms
135,540 KB
testcase_31 AC 404 ms
135,680 KB
権限があれば一括ダウンロードができます

ソースコード

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