結果

問題 No.2268 NGワード回避
ユーザー haihamabossu
提出日時 2023-04-14 22:13:27
言語 Rust
(1.83.0 + proconio)
結果
AC  
実行時間 5 ms / 2,000 ms
コード長 1,829 bytes
コンパイル時間 13,035 ms
コンパイル使用メモリ 389,788 KB
実行使用メモリ 6,824 KB
最終ジャッジ日時 2024-10-10 13:03:15
合計ジャッジ時間 15,417 ms
ジャッジサーバーID
(参考情報)
judge5 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 52
権限があれば一括ダウンロードができます

ソースコード

diff #

use std::collections::BTreeSet;

fn solve(scanner: &mut Scanner) {
    let n: usize = scanner.next();
    let mut set = BTreeSet::<usize>::new();
    for _ in 0..n {
        let s: Vec<char> = scanner.next::<String>().chars().collect();
        let mut a = 0;
        for i in 0..(n.min(15)) {
            a <<= 1;
            if s[i] == 'b' {
                a += 1;
            }
        }
        set.insert(a);
    }
    for a in 0..=1010 {
        if set.contains(&a) {
            continue;
        }
        let mut ans: Vec<char> = vec![];
        let mut a = a;
        for _ in 0..(n.min(15)) {
            if (a & 1) == 1 {
                ans.push('b');
            } else {
                ans.push('a');
            }
            a >>= 1;
        }
        ans.reverse();
        for _ in (n.min(15))..n {
            ans.push('a');
        }
        let ans: String = ans
            .iter()
            .map(|a| a.to_string())
            .collect::<Vec<_>>()
            .join("");
        println!("{}", ans);
        return;
    }
}

fn main() {
    let mut scanner = Scanner::new();
    let t: usize = 1;
    for _ in 0..t {
        solve(&mut scanner);
    }
}

struct Scanner {
    buf: Vec<String>,
}

impl Scanner {
    fn new() -> Self {
        Self { buf: vec![] }
    }

    fn next<T: std::str::FromStr>(&mut self) -> T {
        loop {
            if let Some(x) = self.buf.pop() {
                return x.parse().ok().expect("");
            }
            let mut source = String::new();
            std::io::stdin().read_line(&mut source).expect("");
            self.buf = Self::split(source);
        }
    }

    fn split(source: String) -> Vec<String> {
        source
            .split_whitespace()
            .rev()
            .map(String::from)
            .collect::<Vec<_>>()
    }
}
0