結果

問題 No.1994 Confusing Name
ユーザー phspls
提出日時 2022-09-20 00:41:03
言語 Rust
(1.83.0 + proconio)
結果
AC  
実行時間 390 ms / 2,000 ms
コード長 1,240 bytes
コンパイル時間 14,406 ms
コンパイル使用メモリ 379,300 KB
実行使用メモリ 33,224 KB
最終ジャッジ日時 2024-12-22 02:58:54
合計ジャッジ時間 20,380 ms
ジャッジサーバーID
(参考情報)
judge5 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 28
権限があれば一括ダウンロードができます
コンパイルメッセージ
warning: unused import: `fmt::format`
 --> src/main.rs:1:33
  |
1 | use std::{collections::HashMap, fmt::format};
  |                                 ^^^^^^^^^^^
  |
  = note: `#[warn(unused_imports)]` on by default

ソースコード

diff #

use std::{collections::HashMap, fmt::format};


fn main() {
    let mut n = String::new();
    std::io::stdin().read_line(&mut n).ok();
    let n: usize = n.trim().parse().unwrap();
    let words = (0..n).map(|_| {
            let mut temp = String::new();
            std::io::stdin().read_line(&mut temp).ok();
            let temp = temp.trim();
            temp.to_string()
        })
        .collect::<Vec<String>>();

    let one_cnts = words.iter().filter(|&v| v.len() == 1).count();
    let mut candmap = HashMap::new();
    for i in 0..n {
        if words[i].len() == 1 { continue; }
        let limit = words[i].len();
        for j in 0..limit {
            *candmap.entry(j).or_insert(HashMap::new()).entry(format!("{}{}", &words[i][..j], &words[i][j+1..])).or_insert(0usize) += 1;
        }
    }
    for i in 0..n {
        if words[i].len() == 1 {
            println!("{}", one_cnts-1);
        } else {
            let limit = words[i].len();
            let result = (0..limit).map(|j| {
                    candmap.get(&j).unwrap().get(&format!("{}{}", &words[i][..j], &words[i][j+1..])).unwrap()
                })
                .sum::<usize>() - words[i].len();
            println!("{}", result);
        }
    }
}
0