結果

問題 No.2419 MMA文字列2
ユーザー SuzuxSuzux
提出日時 2023-08-12 14:24:21
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 261 ms / 2,000 ms
コード長 411 bytes
コンパイル時間 151 ms
コンパイル使用メモリ 82,324 KB
実行使用メモリ 185,600 KB
最終ジャッジ日時 2024-04-30 05:59:12
合計ジャッジ時間 4,851 ms
ジャッジサーバーID
(参考情報)
judge2 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 36 ms
51,712 KB
testcase_01 AC 38 ms
52,224 KB
testcase_02 AC 36 ms
52,316 KB
testcase_03 AC 41 ms
59,520 KB
testcase_04 AC 39 ms
59,348 KB
testcase_05 AC 35 ms
51,712 KB
testcase_06 AC 34 ms
51,968 KB
testcase_07 AC 35 ms
51,712 KB
testcase_08 AC 34 ms
52,608 KB
testcase_09 AC 35 ms
52,096 KB
testcase_10 AC 36 ms
51,712 KB
testcase_11 AC 44 ms
59,436 KB
testcase_12 AC 86 ms
88,860 KB
testcase_13 AC 49 ms
65,920 KB
testcase_14 AC 122 ms
107,520 KB
testcase_15 AC 92 ms
90,440 KB
testcase_16 AC 147 ms
124,836 KB
testcase_17 AC 69 ms
83,968 KB
testcase_18 AC 143 ms
125,344 KB
testcase_19 AC 158 ms
125,140 KB
testcase_20 AC 76 ms
84,596 KB
testcase_21 AC 69 ms
82,092 KB
testcase_22 AC 239 ms
167,668 KB
testcase_23 AC 240 ms
167,600 KB
testcase_24 AC 259 ms
185,592 KB
testcase_25 AC 261 ms
185,600 KB
testcase_26 AC 63 ms
82,892 KB
testcase_27 AC 219 ms
170,324 KB
testcase_28 AC 250 ms
181,888 KB
testcase_29 AC 253 ms
181,888 KB
testcase_30 AC 250 ms
181,700 KB
testcase_31 AC 250 ms
169,492 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

s = input()
n = len(s)
dp = [[0] * 26 for _ in range(n)]

# print(ord("a"), ord("A"))

dp[0][ord(s[0])-65] += 1
dp[1] = dp[0].copy()
dp[1][ord(s[1])-65] += 1

ans = 0
for i in range(2, n):
    dp[i] = dp[i-1].copy()
    dp[i][ord(s[i])-65] += 1
    dpi = dp[i]
    ordi = ord(s[i])-65
    for j in range(26):
        if dpi[j] >= 2 and ordi != j:
            ans += dpi[j]*(dpi[j]-1)//2
# print(dp)
print(ans)

0