結果
| 問題 |
No.852 連続部分文字列
|
| コンテスト | |
| ユーザー |
maspy
|
| 提出日時 | 2020-02-19 15:52:43 |
| 言語 | Python3 (3.13.1 + numpy 2.2.1 + scipy 1.14.1) |
| 結果 |
AC
|
| 実行時間 | 656 ms / 3,153 ms |
| コード長 | 447 bytes |
| コンパイル時間 | 182 ms |
| コンパイル使用メモリ | 12,288 KB |
| 実行使用メモリ | 49,704 KB |
| 最終ジャッジ日時 | 2024-10-08 03:03:25 |
| 合計ジャッジ時間 | 27,011 ms |
|
ジャッジサーバーID (参考情報) |
judge4 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 41 |
ソースコード
#!/usr/bin/env python3
# %%
stdin = open(0)
# %%
import numpy as np
# %%
S = np.frombuffer(stdin.buffer.read().rstrip(), 'S1')
# %%
n = len(S)
total = n * (n + 1) // 2
numerator = 0
for i in range(26):
alphabet = chr(ord('a') + i).encode()
ind = np.hstack([[-1], np.where(S == alphabet)[0], [n]])
gaps = ind[1:] - ind[:-1] - 1
numerator += total - (gaps * (gaps + 1) // 2).sum()
# %%
answer = numerator / total
print(answer)
maspy