結果

問題 No.2226 Hello, Forgotten World!
ユーザー maguroflymagurofly
提出日時 2023-02-24 21:36:50
言語 Rust
(1.77.0)
結果
AC  
実行時間 11 ms / 2,000 ms
コード長 1,677 bytes
コンパイル時間 1,029 ms
コンパイル使用メモリ 153,256 KB
実行使用メモリ 4,352 KB
最終ジャッジ日時 2023-10-11 05:56:57
合計ジャッジ時間 1,734 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#![allow(dead_code, unused_imports, unused_macros, non_snake_case)]

fn main() {
    let T = read_line().parse::<usize>().unwrap();
    let helloworld = "helloworld".chars().collect::<Vec<_>>();
    for _ in 0 .. T {
        let N = read_line().parse::<usize>().unwrap();
        let S = read_line().chars().collect::<Vec<_>>();
        
        let mut ans = None::<Vec<char>>;
        
        for i in 0 ..= N - 10 {
            if !(0 .. 10).all(|j| S[i + j] == helloworld[j] || S[i + j] == '?' ) {
                continue;
            }
            
            let mut s = S.clone();
            for j in 0 .. 10 {
                s[i + j] = helloworld[j];
            }
            for j in 0 .. N {
                if s[j] == '?' {
                    s[j] = 'a';
                }
            }
            if let Some(a) = &ans {
                if a.cmp(&s).is_gt() {
                    ans = Some(s);
                }
            } else {
                ans = Some(s);
            }
        }
        
        if let Some(a) = ans {
            println!("{}", a.into_iter().collect::<String>());
        } else {
            println!("-1");
        }
    }
}

type Int = i64;
const MOD: Int = 1_000_000_007;
const INF: Int = 1_000_000_000;
const YESNO: [&'static str; 2] = ["Yes", "No"];

fn read_line() -> String { let mut buf = String::new(); std::io::stdin().read_line(&mut buf).ok(); buf.trim().to_string() }
fn read_words() -> Vec<String> { read_line().split_whitespace().map(str::to_string).collect() }

fn yes() { println!("{}", YESNO[0]); }
fn no() { println!("{}", YESNO[1]); }
fn yesno(c: bool) { println!("{}", if c { YESNO[0] } else { YESNO[1] }); }
0