結果

問題 No.852 連続部分文字列
ユーザー phspls
提出日時 2023-01-03 23:20:53
言語 Rust
(1.83.0 + proconio)
結果
AC  
実行時間 105 ms / 3,153 ms
コード長 706 bytes
コンパイル時間 12,685 ms
コンパイル使用メモリ 383,996 KB
実行使用メモリ 19,616 KB
最終ジャッジ日時 2024-11-27 02:25:59
合計ジャッジ時間 15,830 ms
ジャッジサーバーID
(参考情報)
judge3 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 41
権限があれば一括ダウンロードができます
コンパイルメッセージ
warning: unused import: `std::collections::BTreeSet`
 --> src/main.rs:1:5
  |
1 | use std::collections::BTreeSet;
  |     ^^^^^^^^^^^^^^^^^^^^^^^^^^
  |
  = note: `#[warn(unused_imports)]` on by default

ソースコード

diff #

use std::collections::BTreeSet;


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 pattern = n * (n+1) / 2;
    let mut pos = vec![vec![]; 26];
    for i in 0..n {
        pos[s[i]].push(i);
    }
    let mut total = 0usize;
    for pos in pos.iter() {
        let mut idx = 0usize;
        for i in 0..n {
            if idx == pos.len() {
                break;
            }
            total += n - pos[idx];
            if pos[idx] == i {
                idx += 1;
            }
        }
    }
    println!("{}", total as f64 / pattern as f64);
}
0