結果
| 問題 |
No.346 チワワ数え上げ問題
|
| コンテスト | |
| ユーザー |
lam6er
|
| 提出日時 | 2025-03-20 21:08:24 |
| 言語 | PyPy3 (7.3.15) |
| 結果 |
AC
|
| 実行時間 | 44 ms / 2,000 ms |
| コード長 | 384 bytes |
| コンパイル時間 | 152 ms |
| コンパイル使用メモリ | 83,036 KB |
| 実行使用メモリ | 63,932 KB |
| 最終ジャッジ日時 | 2025-03-20 21:09:12 |
| 合計ジャッジ時間 | 2,024 ms |
|
ジャッジサーバーID (参考情報) |
judge5 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 23 |
ソースコード
s = input().strip()
n = len(s)
count_w = [0] * n
current = 0
# Precompute the number of 'w's to the right of each position
for i in reversed(range(n)):
count_w[i] = current
if s[i] == 'w':
current += 1
ans = 0
# Calculate the number of valid "cww" subsequences
for i in range(n):
if s[i] == 'c':
k = count_w[i]
ans += k * (k - 1) // 2
print(ans)
lam6er