結果

問題 No.3685 ワロングアンサーやんけ!
コンテスト
ユーザー 抹茶フォルマッジ
提出日時 2026-09-05 15:06:50
言語 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
結果
AC  
実行時間 165 ms / 2,000 ms
+ 984µs
コード長 3,910 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 5,298 ms
コンパイル使用メモリ 388,024 KB
実行使用メモリ 6,272 KB
最終ジャッジ日時 2026-09-05 15:07:07
合計ジャッジ時間 8,356 ms
ジャッジサーバーID
(参考情報)
judge1_0 / judge3_0
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 1
other AC * 32
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

#include <bits/stdc++.h>
#include <atcoder/all>
using namespace std;
using namespace atcoder;

using ll = long long;
using ull = unsigned long long;
using ld = long double;

using mint = modint998244353;
// using mint = modint1000000007;

constexpr ll INF = (1LL << 60);
constexpr int INF32 = (1 << 30);

template<typename T> using vc = vector<T>;
template<typename T> using vv = vector<vector<T>>;

using vi = vc<int>;
using vvi = vv<int>;
using vl = vc<ll>;
using vvl = vv<ll>;
using vs = vc<string>;
using vvs = vv<string>;
using vb = vc<bool>;
using vvb = vv<bool>;
using vmint = vc<mint>;
using vvmint = vv<mint>;
using pii = pair<int,int>;
using pll = pair<ll,ll>;

#define rep(i,n) for(ll i=0; i<(ll)(n); i++)
#define drep(i,n) for(ll i=(ll)(n)-1; i>=0; i--)
#define rrep(i,n) for(ll i=1; i<=(ll)(n); i++)
#define nfor(i,a,b) for(ll i=(ll)(a); i<(ll)(b); i++)
#define dfor(i,a,b) for(ll i=(ll)(a)-1; i>=(ll)(b); i--)

#define nall(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()

template<class T>
istream& operator>>(istream& is, vector<T>& v) {
    for (auto& x : v) is >> x;
    return is;
}

template<class T, class U>
istream& operator>>(istream& is, pair<T,U>& p) {
    return is >> p.first >> p.second;
}

template<class T>
bool chmax(T& a, const T& b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}

template<class T>
bool chmin(T& a, const T& b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}

void YES() { cout << "Yes\n"; }
void NO()  { cout << "No\n"; }

void yn(bool ok) {
    cout << (ok ? "Yes" : "No") << '\n';
}

template<class T>
void print(const vector<T>& v) {
    for (int i = 0; i < (int)v.size(); i++) {
        if (i) cout << ' ';
        cout << v[i];
    }
    cout << '\n';
}

template<class T>
void print(const vector<vector<T>>& v) {
    for (const auto& row : v) {
        print(row);
    }
}

void print(ld x) {
    cout << fixed << setprecision(20) << x << '\n';
}

int main() {
    int T;
    cin >> T;
    rep(t,T) {
        string R, S;
        cin >> R >> S;
        int K;
        cin >> K;
        string X = R;
        int N = R.size();
        if(S=="Warong") {
            rep(i,K) X[i] = 'A';
            int qpos = -1;
            int qcnt = 0;
            int isw = 0;
            nfor(i, K, N) {
                if(R[i]=='?') {
                    qpos = i;
                    qcnt++;
                }
                if(R[i]=='W') {
                    isw = 1;
                }
            }
            if(isw==0 && qcnt==1) {
                X[qpos] = 'W';
            }
        } else {
            int precnta = 0;
            int preisw = 0;
            int precntq = 0;
            int sufcntq = 0;
            int sufisw = 0;
            int preposq = -1;
            int sufposq = -1;
            rep(i,R.size()) {
                if(i<K) {
                    if(R[i]=='A') {
                        precnta++;
                    }
                    if(R[i]=='W') {
                        preisw = 1;
                    }
                    if(R[i]=='?') {
                        precntq++;
                        preposq = i;
                    }          
                } else {
                    if(R[i]=='W') {
                        sufisw = 1;
                    }
                    if(R[i]=='?') {
                        sufcntq++;
                        sufposq = i;
                    }                              
                }
            }
            if(preisw==1||sufisw==1) {
                if(preisw!=1 && precntq==1) {
                        X[preposq] = 'W';
                }
            } else {
                if(precntq==0) {
                    rep(i,N) {
                        if(X[i]=='?') X[i] = 'A';
                    }
                }
            }
        }
        cout << X << endl;
    }
}
0