結果

問題 No.2419 MMA文字列2
ユーザー 👑 KA37RIKA37RI
提出日時 2023-08-12 15:09:27
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 183 ms / 2,000 ms
コード長 360 bytes
コンパイル時間 201 ms
コンパイル使用メモリ 12,672 KB
実行使用メモリ 11,264 KB
最終ジャッジ日時 2024-04-30 08:12:21
合計ジャッジ時間 3,656 ms
ジャッジサーバーID
(参考情報)
judge5 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 25 ms
10,752 KB
testcase_01 AC 25 ms
10,752 KB
testcase_02 AC 25 ms
10,624 KB
testcase_03 AC 25 ms
10,624 KB
testcase_04 AC 24 ms
10,624 KB
testcase_05 AC 25 ms
10,624 KB
testcase_06 AC 25 ms
10,624 KB
testcase_07 AC 25 ms
10,752 KB
testcase_08 AC 26 ms
10,624 KB
testcase_09 AC 26 ms
10,624 KB
testcase_10 AC 25 ms
10,752 KB
testcase_11 AC 26 ms
10,752 KB
testcase_12 AC 59 ms
10,880 KB
testcase_13 AC 29 ms
10,624 KB
testcase_14 AC 89 ms
10,752 KB
testcase_15 AC 66 ms
10,752 KB
testcase_16 AC 94 ms
10,880 KB
testcase_17 AC 45 ms
10,624 KB
testcase_18 AC 96 ms
10,880 KB
testcase_19 AC 98 ms
10,880 KB
testcase_20 AC 47 ms
10,752 KB
testcase_21 AC 39 ms
10,624 KB
testcase_22 AC 180 ms
11,136 KB
testcase_23 AC 183 ms
11,264 KB
testcase_24 AC 180 ms
11,136 KB
testcase_25 AC 183 ms
11,136 KB
testcase_26 AC 43 ms
10,752 KB
testcase_27 AC 164 ms
11,136 KB
testcase_28 AC 183 ms
11,136 KB
testcase_29 AC 178 ms
11,136 KB
testcase_30 AC 180 ms
11,136 KB
testcase_31 AC 177 ms
11,136 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

def solve(S):
  ans = 0
  ch = {c: 0 for c in "ABCDEFGHIJKLMNOPQRSTUVWXYZ"}
  ch_back = {c: 0 for c in "ABCDEFGHIJKLMNOPQRSTUVWXYZ"}
  for c in S: ch_back[c] += 1
  N = len(S)
  for i in range(N):
    ch[S[i]] += 1
    ch_back[S[i]] -= 1
    if ch[S[i]] >= 2:
      ans += (ch[S[i]] - 1) * (N - i - 1 - ch_back[S[i]])
  return ans

S = input()

print(solve(S))
0