結果

問題 No.52 よくある文字列の問題
ユーザー nak3nak3
提出日時 2017-11-25 18:34:27
言語 Rust
(1.77.0)
結果
AC  
実行時間 1 ms / 5,000 ms
コード長 1,305 bytes
コンパイル時間 6,696 ms
コンパイル使用メモリ 183,384 KB
実行使用メモリ 4,348 KB
最終ジャッジ日時 2023-10-22 04:11:49
合計ジャッジ時間 7,346 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,348 KB
testcase_01 AC 1 ms
4,348 KB
testcase_02 AC 1 ms
4,348 KB
testcase_03 AC 1 ms
4,348 KB
testcase_04 AC 1 ms
4,348 KB
testcase_05 AC 1 ms
4,348 KB
testcase_06 AC 1 ms
4,348 KB
testcase_07 AC 1 ms
4,348 KB
testcase_08 AC 1 ms
4,348 KB
testcase_09 AC 1 ms
4,348 KB
testcase_10 AC 1 ms
4,348 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
warning: variable does not need to be mutable
  --> Main.rs:19:31
   |
19 | fn dfs(a: String, b: &String, mut hs: &mut HashSet<String>) {
   |                               ----^^
   |                               |
   |                               help: remove this `mut`
   |
   = note: `#[warn(unused_mut)]` on by default

warning: constant `MOD` is never used
 --> Main.rs:4:7
  |
4 | const MOD: i32 = 1000000007;
  |       ^^^
  |
  = note: `#[warn(dead_code)]` on by default

warning: 2 warnings emitted

ソースコード

diff #

use std::io::*;
use std::str::*;

const MOD: i32 = 1000000007;

fn read<T: FromStr>() -> Option<T> {
    let stdin = stdin();
    let s = stdin
        .bytes()
        .map(|c| c.unwrap() as char)
        .take_while(|c| !c.is_whitespace())
        .collect::<String>();
    s.parse::<T>().ok()
}
use std::collections::HashSet;



fn dfs(a: String, b: &String, mut hs: &mut HashSet<String>) {
    //    println!("a:{} b:{}", a, b);
    if a.len() == 1 {
        let s = b.to_string() + &a;
        //        println!("inserting .. {}", s);
        hs.insert(s);
        return;
    }

    let front = b.to_string() + &a[0..1].to_string();
    let back = b.to_string() + &a[a.len() - 1..a.len()].to_string();

    // println!("front : {}", front);
    // println!("back  : {}", back);

    dfs(a[1..(a.len())].to_string(), &front, hs);
    dfs(a[0..(a.len() - 1)].to_string(), &back, hs);
}



fn main() {
    let mut hs: HashSet<String> = HashSet::new();
    let s: String = read().unwrap();
    if s.len() == 1 {
        println!("1");
        return;
    }
    if s.len() == 2 {
        if s.chars().nth(0) == s.chars().nth(1) {
            println!("1");
            return;
        }
        println!("2");
        return;
    }
    dfs(s, &"".to_string(), &mut hs);
    println!("{}", hs.len());

}
0