結果

問題 No.3685 ワロングアンサーやんけ!
コンテスト
ユーザー Mikan04y
提出日時 2026-07-10 19:16:55
言語 C++23(gcc16)
(gcc 16.1.0 + boost 1.92.0)
コンパイル:
g++-16 -O2 -lm -std=c++23 -Wuninitialized -DONLINE_JUDGE -o a.out _filename_
実行:
./a.out
結果
WA  
実行時間 -
コード長 2,024 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 2,276 ms
コンパイル使用メモリ 355,288 KB
実行使用メモリ 6,272 KB
最終ジャッジ日時 2026-09-05 12:33:42
合計ジャッジ時間 5,467 ms
ジャッジサーバーID
(参考情報)
judge3_0 / judge1_0
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample WA * 1
other WA * 17 RE * 15
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, a, b) for (ll i = (a); i < (ll)(b); i++)
#define all(x) x.begin(), x.end()

void solve() {
    int N, M;
    cin >> N >> M;
    string S, T;
    cin >> S >> T;

    string ans = S;

    // Warong
    if (T.compare("Warong") == 0) {
        // Sample: all 'A'
        rep(i, 0, M) {
            ans[i] = 'A';
        }

        // Testcase: 'W' が 0 個で '?' が 1 個のときのみ確定
        int wcnt = 0, ncnt = 0;
        rep(i, M, N) {
            wcnt += (S[i] == 'W' ? 1 : 0);
            ncnt += (S[i] == '?' ? 1 : 0);
        }
        if (wcnt == 0 && ncnt == 1) {
            rep(i, M, N) {
                if (S[i] == '?') ans[i] = 'W';
            }
        }
        cout << ans << '\n';
        return;
    }

    // NotWarong
    int acnt1 = 0, acnt2 = 0, wcnt1 = 0, wcnt2 = 0, ncnt1 = 0, ncnt2 = 0;
    rep(i, 0, M) {
        acnt1 += (S[i] == 'A' ? 1 : 0);
        wcnt1 += (S[i] == 'W' ? 1 : 0);
        ncnt1 += (S[i] == '?' ? 1 : 0);
    }
    rep(i, M, N) {
        acnt2 += (S[i] == 'A' ? 1 : 0);
        wcnt2 += (S[i] == 'W' ? 1 : 0);
        ncnt2 += (S[i] == '?' ? 1 : 0);
    }

    // Sample が全部 'A' のとき、AC
    if (acnt1 == M) {
        rep(i, 0, N) {
            ans[i] = 'A';
        }
        cout << ans << '\n';
        return;
    }

    // WA
    // Testcase が全部 'A' のとき: Sample は 'W' を含む
    if (acnt2 == N - M && wcnt1 == 0 && ncnt1 == 1) {
        rep(i, 0, M) {
            if (S[i] == '?') ans[i] = 'W';
        }
        cout << ans << '\n';
        return;
    }
    // Testcase が 'W' を含むとき: Sample は 'W' を含む
    if (wcnt1 == 0 && wcnt2 > 0 && ncnt1 == 1 && ncnt2 == 0) {
        rep(i, M, N) {
            if (S[i] == '?') ans[i] = 'W';
        }
    }

    cout << ans << '\n';
    return;
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int T = 1;
    // cin >> T;
    while (T--) {
        solve();
    }
}
0