結果

問題 No.2419 MMA文字列2
ユーザー NakLon131NakLon131
提出日時 2023-08-13 15:44:50
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 228 ms / 2,000 ms
コード長 528 bytes
コンパイル時間 3,431 ms
コンパイル使用メモリ 82,108 KB
実行使用メモリ 126,128 KB
最終ジャッジ日時 2024-05-01 08:31:23
合計ジャッジ時間 5,225 ms
ジャッジサーバーID
(参考情報)
judge4 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 36 ms
52,032 KB
testcase_01 AC 37 ms
52,792 KB
testcase_02 AC 37 ms
53,120 KB
testcase_03 AC 44 ms
60,424 KB
testcase_04 AC 43 ms
60,760 KB
testcase_05 AC 38 ms
52,964 KB
testcase_06 AC 35 ms
53,192 KB
testcase_07 AC 36 ms
52,932 KB
testcase_08 AC 37 ms
52,468 KB
testcase_09 AC 36 ms
52,252 KB
testcase_10 AC 37 ms
53,484 KB
testcase_11 AC 43 ms
60,504 KB
testcase_12 AC 79 ms
74,584 KB
testcase_13 AC 50 ms
64,408 KB
testcase_14 AC 123 ms
87,384 KB
testcase_15 AC 85 ms
77,816 KB
testcase_16 AC 118 ms
89,212 KB
testcase_17 AC 64 ms
69,064 KB
testcase_18 AC 119 ms
89,664 KB
testcase_19 AC 121 ms
91,484 KB
testcase_20 AC 66 ms
70,840 KB
testcase_21 AC 72 ms
66,992 KB
testcase_22 AC 228 ms
126,040 KB
testcase_23 AC 222 ms
125,916 KB
testcase_24 AC 220 ms
126,056 KB
testcase_25 AC 210 ms
125,876 KB
testcase_26 AC 71 ms
67,612 KB
testcase_27 AC 211 ms
125,928 KB
testcase_28 AC 211 ms
126,128 KB
testcase_29 AC 220 ms
125,792 KB
testcase_30 AC 211 ms
125,864 KB
testcase_31 AC 212 ms
125,896 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

s = list(input())
len_s = len(s)

# DP
# dp[アルファベット文字][i個目まで] = 出現個数
dp = [[0 for j in range(len_s + 1)] for i in range(26)]

ans = 0
# 1文字ずつ見る
for i in range(len_s):
	# 今の文字を取得
	pos = ord(s[i]) - ord('A')
	dp[pos][i+1] += 1
	# A~Zをチェック
	for j in range(26):
		# 累積和をとるためコピー
		if i > 0: dp[j][i+1] += dp[j][i]
		# 作れる総数を更新(同じ文字でないこと)
		if pos != j: ans += ((dp[j][i+1]) * (dp[j][i+1]-1) // 2)
print(ans)
0