結果

問題 No.52 よくある文字列の問題
ユーザー phsplsphspls
提出日時 2020-05-24 12:56:29
言語 Rust
(1.77.0)
結果
AC  
実行時間 2 ms / 5,000 ms
コード長 750 bytes
コンパイル時間 2,049 ms
コンパイル使用メモリ 180,916 KB
実行使用メモリ 6,944 KB
最終ジャッジ日時 2024-04-19 12:12:07
合計ジャッジ時間 2,695 ms
ジャッジサーバーID
(参考情報)
judge4 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
6,812 KB
testcase_01 AC 1 ms
6,944 KB
testcase_02 AC 1 ms
6,940 KB
testcase_03 AC 1 ms
6,944 KB
testcase_04 AC 2 ms
6,940 KB
testcase_05 AC 1 ms
6,940 KB
testcase_06 AC 2 ms
6,944 KB
testcase_07 AC 1 ms
6,944 KB
testcase_08 AC 1 ms
6,940 KB
testcase_09 AC 1 ms
6,940 KB
testcase_10 AC 1 ms
6,940 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

use std::collections::HashSet;

fn dfs(s: &mut Vec<char>, result: &mut HashSet<String>, sidx: usize, eidx: usize, orgs: &str) {
    if sidx == eidx {
        result.insert(s.iter().map(|c| c.to_string()).collect::<Vec<String>>().join(""));
        return;
    }
    s.push(orgs.chars().nth(sidx).unwrap());
    dfs(s, result, sidx+1, eidx, orgs);
    s.pop();
    s.push(orgs.chars().nth(eidx).unwrap());
    dfs(s, result, sidx, eidx-1, orgs);
    s.pop();
}

fn main() {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    let s: &str = s.trim();
    let mut result: HashSet<String> = HashSet::new();
    let mut sc: Vec<char> = vec![];
    dfs(&mut sc, &mut result, 0, s.len()-1, s);
    println!("{}", result.len());
}
0