結果

問題 No.2419 MMA文字列2
ユーザー koshihkarikoshihkari
提出日時 2023-08-12 15:22:03
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 71 ms / 2,000 ms
コード長 401 bytes
コンパイル時間 245 ms
コンパイル使用メモリ 82,372 KB
実行使用メモリ 76,016 KB
最終ジャッジ日時 2024-04-30 09:00:15
合計ジャッジ時間 2,629 ms
ジャッジサーバーID
(参考情報)
judge5 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 36 ms
53,312 KB
testcase_01 AC 32 ms
52,020 KB
testcase_02 AC 32 ms
52,640 KB
testcase_03 AC 34 ms
53,912 KB
testcase_04 AC 33 ms
52,988 KB
testcase_05 AC 31 ms
51,752 KB
testcase_06 AC 31 ms
52,496 KB
testcase_07 AC 35 ms
52,248 KB
testcase_08 AC 35 ms
53,216 KB
testcase_09 AC 35 ms
53,600 KB
testcase_10 AC 34 ms
53,492 KB
testcase_11 AC 34 ms
52,360 KB
testcase_12 AC 45 ms
63,896 KB
testcase_13 AC 38 ms
59,856 KB
testcase_14 AC 48 ms
66,608 KB
testcase_15 AC 44 ms
64,592 KB
testcase_16 AC 50 ms
68,084 KB
testcase_17 AC 41 ms
62,524 KB
testcase_18 AC 51 ms
66,996 KB
testcase_19 AC 52 ms
68,560 KB
testcase_20 AC 42 ms
62,512 KB
testcase_21 AC 41 ms
61,116 KB
testcase_22 AC 65 ms
75,920 KB
testcase_23 AC 66 ms
75,796 KB
testcase_24 AC 66 ms
75,776 KB
testcase_25 AC 65 ms
76,016 KB
testcase_26 AC 43 ms
59,572 KB
testcase_27 AC 58 ms
63,824 KB
testcase_28 AC 71 ms
75,980 KB
testcase_29 AC 70 ms
75,756 KB
testcase_30 AC 67 ms
75,860 KB
testcase_31 AC 68 ms
75,656 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

s = input()
counter = {}
base = ans = 0
length = len(s)
for i, char in enumerate(s):
    if not char in counter:
        counter[char] = 1
    else:
        counter[char] += 1
        
        if counter[char] > 2:
            ans -= (counter[char] - 1) * (counter[char] - 2) // 2
            ans += (counter[char] - 1) * (length - (i + 1))
        else:
            ans += length - (i + 1)
print(ans)
0