結果

問題 No.2419 MMA文字列2
ユーザー pありpあり
提出日時 2023-08-12 13:58:24
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 101 ms / 2,000 ms
コード長 305 bytes
コンパイル時間 2,835 ms
コンパイル使用メモリ 82,156 KB
実行使用メモリ 75,916 KB
最終ジャッジ日時 2024-04-30 04:37:46
合計ジャッジ時間 3,857 ms
ジャッジサーバーID
(参考情報)
judge3 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 29 ms
52,976 KB
testcase_01 AC 30 ms
53,112 KB
testcase_02 AC 30 ms
52,484 KB
testcase_03 AC 31 ms
53,184 KB
testcase_04 AC 30 ms
52,732 KB
testcase_05 AC 31 ms
53,620 KB
testcase_06 AC 31 ms
52,492 KB
testcase_07 AC 41 ms
52,292 KB
testcase_08 AC 30 ms
52,060 KB
testcase_09 AC 30 ms
53,624 KB
testcase_10 AC 30 ms
52,968 KB
testcase_11 AC 30 ms
53,748 KB
testcase_12 AC 54 ms
75,364 KB
testcase_13 AC 40 ms
65,480 KB
testcase_14 AC 68 ms
75,508 KB
testcase_15 AC 59 ms
75,228 KB
testcase_16 AC 69 ms
75,652 KB
testcase_17 AC 52 ms
75,184 KB
testcase_18 AC 69 ms
75,332 KB
testcase_19 AC 72 ms
75,916 KB
testcase_20 AC 53 ms
75,320 KB
testcase_21 AC 48 ms
73,604 KB
testcase_22 AC 97 ms
75,892 KB
testcase_23 AC 95 ms
75,592 KB
testcase_24 AC 99 ms
75,536 KB
testcase_25 AC 96 ms
75,752 KB
testcase_26 AC 47 ms
73,728 KB
testcase_27 AC 93 ms
75,508 KB
testcase_28 AC 99 ms
75,812 KB
testcase_29 AC 99 ms
75,500 KB
testcase_30 AC 101 ms
75,592 KB
testcase_31 AC 101 ms
75,724 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

s = input()
n = len(s)

d = dict() 
d2 = dict()

for i in range(n):
  if(s[i] in d):
    d[s[i]]+=1
    d2[s[i]] += n-1-i
  else:
    d[s[i]] = 1
    d2[s[i]] = n-1-i
    
ans = 0
for i in range(n):
  d[s[i]]-=1
  d2[s[i]] -= n-1-i
  ans += d2[s[i]] - (d[s[i]]*(d[s[i]]-1))//2
  
print(ans)
  
  
  
  
  
0