結果

問題 No.852 連続部分文字列
ユーザー phsplsphspls
提出日時 2022-12-13 10:05:38
言語 Rust
(1.83.0 + proconio)
結果
AC  
実行時間 60 ms / 3,153 ms
コード長 647 bytes
コンパイル時間 13,237 ms
コンパイル使用メモリ 377,868 KB
実行使用メモリ 12,320 KB
最終ジャッジ日時 2024-11-07 06:08:28
合計ジャッジ時間 16,784 ms
ジャッジサーバーID
(参考情報)
judge1 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 41
権限があれば一括ダウンロードができます

ソースコード

diff #

fn main() {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    let s = s.trim().chars().map(|c| c as usize - 'a' as usize).collect::<Vec<_>>();

    let n = s.len();
    let total = n * (n + 1) / 2;
    let mut cnts = 0usize;
    for i in 0..26 {
        let mut indices = (0..n).filter(|&j| s[j] == i).map(|j| j as isize).collect::<Vec<_>>();
        indices.insert(0, -1);
        for j in 0..indices.len()-1 {
            let start = indices[j]+1;
            let end = indices[j+1];
            cnts += (end-start+1) as usize * (n - end as usize);
        }
    }
    println!("{}", cnts as f64 / total as f64);
}
0