結果

問題 No.3685 ワロングアンサーやんけ!
コンテスト
ユーザー norioc
提出日時 2026-09-05 17:13:34
言語 Rust
(1.97.1 + proconio + num + itertools)
コンパイル:
/usr/bin/rustc_custom
実行:
./target/release/main
結果
AC  
実行時間 158 ms / 2,000 ms
+ 804µs
コード長 2,326 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 9,332 ms
コンパイル使用メモリ 205,952 KB
実行使用メモリ 9,788 KB
最終ジャッジ日時 2026-09-05 17:13:47
合計ジャッジ時間 12,439 ms
ジャッジサーバーID
(参考情報)
judge5_0 / judge1_0
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 1
other AC * 32
権限があれば一括ダウンロードができます
コンパイルメッセージ
warning: unused variable: `suffix_all_a`
  --> src/main.rs:61:13
   |
61 |         let suffix_all_a = suffix_count('A') == R.len() - K;
   |             ^^^^^^^^^^^^ help: if this is intentional, prefix it with an underscore: `_suffix_all_a`
   |
   = note: `#[warn(unused_variables)]` (part of `#[warn(unused)]`) on by default

warning: unused variable: `prefix_has_w`
  --> src/main.rs:63:13
   |
63 |         let prefix_has_w = prefix_count('W') > 0;
   |             ^^^^^^^^^^^^ help: if this is intentional, prefix it with an underscore: `_prefix_has_w`

ソースコード

diff #
raw source code

#![allow(non_snake_case, unused_imports)]

use std::cmp::Reverse;
use std::collections::{BinaryHeap, HashMap, HashSet};
use proconio::{input, marker::Usize1, marker::Chars};
use itertools::Itertools;

#[allow(unused_macros)]
macro_rules! d {
    ( $( $x:expr ),* $(,)? ) => {
        eprintln!(
            concat!( $( stringify!($x), "={:?} " ),* ),
            $( $x ),*
        );
    };
}

#[allow(dead_code)]
fn yn(b: bool) -> &'static str {
    if b { "Yes" } else { "No" }
}

fn replace_first(s: &str, fm: char, to: &str) -> String {
    let mut res = String::new();

    let mut b = false;
    for c in s.chars() {
        if !b && c == fm {
            res.push_str(to);
            b = true;
        } else {
            res.push(c)
        }
    }
    res
}

fn solve() -> String {
    input! {
        R: String,
        S: String,
        K: usize,
    }

    let prefix_count = |c: char| -> usize {
        R.chars()
            .take(K)
            .filter(|&x| x == c)
            .count()
    };

    let suffix_count = |c: char| -> usize {
        R.chars()
            .skip(K)
            .filter(|&x| x == c)
            .count()
    };

    if S == "NotWarong" {
        let prefix_all_a = prefix_count('A') == K;
        let suffix_all_a = suffix_count('A') == R.len() - K;

        let prefix_has_w = prefix_count('W') > 0;
        let suffix_has_w = suffix_count('W') > 0;

        if prefix_all_a {
            return R.replace('?', "A");
        }

        if suffix_has_w {
            let a = prefix_count('A');
            let q = prefix_count('?');
            if a == K-1 && q == 1 {
                return replace_first(&R, '?', "W");
            }

            return R;
        }

        return R;
    }

    let freq = R.chars().skip(K as usize).counts();
    let qcnt = *freq.get(&'?').unwrap_or(&0);
    let wcnt = *freq.get(&'W').unwrap_or(&0);

    let mut s = String::new();
    for _ in 0..K {
        s.push('A');
    }

    let cs: Vec<char> = R.chars().collect();
    for i in K as usize..R.len() {
        if cs[i] == '?' && qcnt == 1 && wcnt == 0 {
            s.push('W');
        } else {
            s.push(cs[i]);
        }
    }

    s
}

fn main() {
    input! {
        T: usize,
    }

    for _ in 0..T {
        let ans = solve();
        println!("{}", ans);
    }
}
0