Submission #58722015


Source Code Expand

Copy
s = input()
idx_table = {}
for i in range(26):
idx_table[chr(ord('A')+i)] = []
for i in range(len(s)):
idx_table[s[i]].append(i)
ans = 0
for lst in idx_table.values():
lst.sort()
l = len(lst)
lst_up_sum = [0 for _ in range(l)]
cur_sum = 0
for i in reversed(range(l)):
lst_up_sum[i] = cur_sum
cur_sum += lst[i]
for i in range(l-1):
ans += lst_up_sum[i] - (lst[i]+1)*(l-i-1)
 
הההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההה
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
s = input()

idx_table = {}
for i in range(26):
    idx_table[chr(ord('A')+i)] = []

for i in range(len(s)):
    idx_table[s[i]].append(i)

ans = 0
for lst in idx_table.values():
    lst.sort()
    l = len(lst)
    lst_up_sum = [0 for _ in range(l)]
    cur_sum = 0
    for i in reversed(range(l)):
        lst_up_sum[i] = cur_sum
        cur_sum += lst[i]
    for i in range(l-1):
        ans += lst_up_sum[i] - (lst[i]+1)*(l-i-1)

print(ans)

Submission Info

Submission Time
Task D - ABA
User kengchong
Language Python (PyPy 3.10-v7.3.12)
Score 400
Code Size 464 Byte
Status AC
Exec Time 76 ms
Memory 96940 KB

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 400 / 400
Status
AC × 3
AC × 34
Set Name Test Cases
Sample sample00.txt, sample01.txt, sample02.txt
All sample00.txt, sample01.txt, sample02.txt, testcase00.txt, testcase01.txt, testcase02.txt, testcase03.txt, testcase04.txt, testcase05.txt, testcase06.txt, testcase07.txt, testcase08.txt, testcase09.txt, testcase10.txt, testcase11.txt, testcase12.txt, testcase13.txt, testcase14.txt, testcase15.txt, testcase16.txt, testcase17.txt, testcase18.txt, testcase19.txt, testcase20.txt, testcase21.txt, testcase22.txt, testcase23.txt, testcase24.txt, testcase25.txt, testcase26.txt, testcase27.txt, testcase28.txt, testcase29.txt, testcase30.txt
Case Name Status Exec Time Memory
sample00.txt AC 56 ms 76780 KB
sample01.txt AC 55 ms 76600 KB
sample02.txt AC 55 ms 76624 KB
testcase00.txt AC 55 ms 76496 KB
testcase01.txt AC 55 ms 76816 KB
testcase02.txt AC 55 ms 76624 KB
testcase03.txt AC 61 ms 83564 KB
testcase04.txt AC 73 ms 96940 KB
testcase05.txt AC 63 ms 83084 KB
testcase06.txt AC 73 ms 96072 KB
testcase07.txt AC 62 ms 81596 KB
testcase08.txt AC 76 ms 96132 KB
testcase09.txt AC 62 ms 81832 KB
testcase10.txt AC 75 ms 93540 KB
testcase11.txt AC 62 ms 81712 KB
testcase12.txt AC 74 ms 91348 KB
testcase13.txt AC 62 ms 81492 KB
testcase14.txt AC 73 ms 87868 KB
testcase15.txt AC 71 ms 84040 KB
testcase16.txt AC 72 ms 85644 KB
testcase17.txt AC 62 ms 81428 KB
testcase18.txt AC 71 ms 84228 KB
testcase19.txt AC 65 ms 81788 KB
testcase20.txt AC 72 ms 83988 KB
testcase21.txt AC 64 ms 81776 KB
testcase22.txt AC 73 ms 83812 KB
testcase23.txt AC 66 ms 81812 KB
testcase24.txt AC 72 ms 84036 KB
testcase25.txt AC 65 ms 81796 KB
testcase26.txt AC 73 ms 83992 KB
testcase27.txt AC 71 ms 84336 KB
testcase28.txt AC 73 ms 84184 KB
testcase29.txt AC 64 ms 81572 KB
testcase30.txt AC 74 ms 84296 KB


2025-04-26 (Sat)
03:07:42 +00:00