結果

問題 No.2419 MMA文字列2
ユーザー Seed57_cashSeed57_cash
提出日時 2023-06-22 09:55:58
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 99 ms / 2,000 ms
コード長 745 bytes
コンパイル時間 377 ms
コンパイル使用メモリ 87,292 KB
実行使用メモリ 79,156 KB
最終ジャッジ日時 2023-09-12 04:36:52
合計ジャッジ時間 5,523 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 72 ms
71,356 KB
testcase_01 AC 72 ms
71,392 KB
testcase_02 AC 70 ms
71,460 KB
testcase_03 AC 68 ms
71,604 KB
testcase_04 AC 70 ms
71,684 KB
testcase_05 AC 67 ms
71,388 KB
testcase_06 AC 71 ms
71,388 KB
testcase_07 AC 71 ms
71,576 KB
testcase_08 AC 71 ms
71,308 KB
testcase_09 AC 69 ms
71,356 KB
testcase_10 AC 69 ms
71,448 KB
testcase_11 AC 69 ms
71,588 KB
testcase_12 AC 79 ms
76,528 KB
testcase_13 AC 77 ms
76,536 KB
testcase_14 AC 84 ms
76,852 KB
testcase_15 AC 80 ms
76,636 KB
testcase_16 AC 85 ms
77,152 KB
testcase_17 AC 79 ms
76,600 KB
testcase_18 AC 84 ms
76,996 KB
testcase_19 AC 86 ms
77,124 KB
testcase_20 AC 79 ms
76,628 KB
testcase_21 AC 78 ms
76,492 KB
testcase_22 AC 94 ms
79,156 KB
testcase_23 AC 93 ms
78,788 KB
testcase_24 AC 93 ms
78,880 KB
testcase_25 AC 95 ms
78,900 KB
testcase_26 AC 77 ms
76,488 KB
testcase_27 AC 94 ms
78,924 KB
testcase_28 AC 99 ms
78,880 KB
testcase_29 AC 97 ms
78,784 KB
testcase_30 AC 96 ms
79,056 KB
testcase_31 AC 97 ms
78,872 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

# 2文字目を固定すると、(自分より前の同じ文字の個数)*(自分より後ろの自分以外の文字の数)
# というわけで、現時点の自分と同じ文字のカウントがあれば良さそう


S = input()
n = len(S)

alphabet = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
# assert len(alphabet) == len(set(list(alphabet))) == 26
ci_map = dict()

for i, c in enumerate(alphabet):
	ci_map[c] = i

# 自分より前の同じ文字の個数
counter = [0] * 26
same_before = [0] * n
for i, c in enumerate(S):
	j = ci_map[c]
	same_before[i] = counter[j]
	counter[j] += 1

res = 0
for i in range(n):
	before = same_before[i]
	c = S[i]
	j = ci_map[c]
	after = n - 1 - i - (counter[j] - before - 1)
	res += before * after

print(res)
0