結果

問題 No.852 連続部分文字列
ユーザー phsplsphspls
提出日時 2023-01-03 23:20:53
言語 Rust
(1.77.0)
結果
AC  
実行時間 108 ms / 3,153 ms
コード長 706 bytes
コンパイル時間 1,087 ms
コンパイル使用メモリ 143,000 KB
実行使用メモリ 19,556 KB
最終ジャッジ日時 2023-08-18 00:48:27
合計ジャッジ時間 5,139 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 AC 1 ms
4,376 KB
testcase_02 AC 1 ms
4,380 KB
testcase_03 AC 1 ms
4,380 KB
testcase_04 AC 1 ms
4,380 KB
testcase_05 AC 1 ms
4,376 KB
testcase_06 AC 1 ms
4,376 KB
testcase_07 AC 1 ms
4,380 KB
testcase_08 AC 1 ms
4,376 KB
testcase_09 AC 1 ms
4,376 KB
testcase_10 AC 1 ms
4,380 KB
testcase_11 AC 1 ms
4,376 KB
testcase_12 AC 1 ms
4,380 KB
testcase_13 AC 3 ms
4,376 KB
testcase_14 AC 1 ms
4,380 KB
testcase_15 AC 4 ms
4,376 KB
testcase_16 AC 3 ms
4,376 KB
testcase_17 AC 3 ms
4,380 KB
testcase_18 AC 4 ms
4,376 KB
testcase_19 AC 1 ms
4,376 KB
testcase_20 AC 2 ms
4,380 KB
testcase_21 AC 4 ms
4,376 KB
testcase_22 AC 2 ms
4,376 KB
testcase_23 AC 3 ms
4,380 KB
testcase_24 AC 2 ms
4,376 KB
testcase_25 AC 3 ms
4,380 KB
testcase_26 AC 4 ms
4,376 KB
testcase_27 AC 3 ms
4,380 KB
testcase_28 AC 4 ms
4,376 KB
testcase_29 AC 4 ms
4,376 KB
testcase_30 AC 1 ms
4,380 KB
testcase_31 AC 4 ms
4,380 KB
testcase_32 AC 4 ms
4,376 KB
testcase_33 AC 103 ms
19,172 KB
testcase_34 AC 103 ms
19,412 KB
testcase_35 AC 104 ms
19,096 KB
testcase_36 AC 104 ms
19,272 KB
testcase_37 AC 105 ms
19,176 KB
testcase_38 AC 105 ms
19,260 KB
testcase_39 AC 104 ms
19,048 KB
testcase_40 AC 104 ms
19,132 KB
testcase_41 AC 104 ms
19,260 KB
testcase_42 AC 108 ms
19,556 KB
testcase_43 AC 103 ms
18,588 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
warning: unused import: `std::collections::BTreeSet`
 --> Main.rs:1:5
  |
1 | use std::collections::BTreeSet;
  |     ^^^^^^^^^^^^^^^^^^^^^^^^^^
  |
  = note: `#[warn(unused_imports)]` on by default

warning: 1 warning emitted

ソースコード

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