結果

問題 No.52 よくある文字列の問題
ユーザー kyotoku1483
提出日時 2025-03-27 12:23:55
言語 Rust
(1.83.0 + proconio)
結果
AC  
実行時間 2 ms / 5,000 ms
コード長 1,073 bytes
コンパイル時間 23,830 ms
コンパイル使用メモリ 377,036 KB
実行使用メモリ 5,888 KB
最終ジャッジ日時 2025-03-27 12:24:20
合計ジャッジ時間 14,796 ms
ジャッジサーバーID
(参考情報)
judge1 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 11
権限があれば一括ダウンロードができます

ソースコード

diff #

#[allow(unused)]
use proconio::{input, marker::Chars};
use std::collections::{HashSet, VecDeque};

fn main() {
    input! {
        s: String,
    }
    let mut t = s.chars().collect::<VecDeque<_>>();
    let mut h = HashSet::<String>::new();
    let mut w = Vec::<char>::new();
    println!("{}", new_string(&mut t, &mut h, &mut w))
}
fn new_string(t: &mut VecDeque<char>, h: &mut HashSet<String>, w: &mut Vec<char>) -> i64 {
    if t.is_empty() {
        let s = w.iter().collect::<String>();
        if !h.contains(&s) {
            h.insert(s);
            return 1;
        } else {
            return 0;
        }
    } else {
        let mut ret = 0;
        for &top in [true, false].iter() {
            if top {
                w.push(t.pop_front().unwrap());
            } else {
                w.push(t.pop_back().unwrap());
            }
            ret += new_string(t, h, w);
            if top {
                t.push_front(w.pop().unwrap());
            } else {
                t.push_back(w.pop().unwrap());
            }
        }
        ret
    }
}
0