結果
| 問題 |
No.2419 MMA文字列2
|
| コンテスト | |
| ユーザー |
lam6er
|
| 提出日時 | 2025-03-20 21:06:17 |
| 言語 | PyPy3 (7.3.15) |
| 結果 |
AC
|
| 実行時間 | 187 ms / 2,000 ms |
| コード長 | 941 bytes |
| コンパイル時間 | 167 ms |
| コンパイル使用メモリ | 82,472 KB |
| 実行使用メモリ | 132,996 KB |
| 最終ジャッジ日時 | 2025-03-20 21:06:24 |
| 合計ジャッジ時間 | 4,382 ms |
|
ジャッジサーバーID (参考情報) |
judge3 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 2 |
| other | AC * 30 |
ソースコード
S = input().strip()
n = len(S)
if n < 3:
print(0)
exit()
# Initialize suffix array where suffix[i][c] is the count of character c from position i to end
suffix = [[0] * 26 for _ in range(n + 2)] # suffix[n] and beyond are all zeros
for i in range(n-1, -1, -1):
current_char = S[i]
num = ord(current_char) - ord('A')
# Copy the suffix counts from i+1 to i
for k in range(26):
suffix[i][k] = suffix[i+1][k]
# Increment the current character count
suffix[i][num] += 1
prefix_counts = [0] * 26
total = 0
for j in range(n):
current_char = S[j]
num = ord(current_char) - ord('A')
a = prefix_counts[num]
# Calculate the number of valid Y characters after position j
if j + 1 < n:
y_count = (n - j - 1) - suffix[j + 1][num]
else:
y_count = 0
total += a * y_count
# Update the prefix count for the current character
prefix_counts[num] += 1
print(total)
lam6er