結果
| 問題 | No.3685 ワロングアンサーやんけ! |
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2026-09-05 14:56:52 |
| 言語 | C++23 (gcc 15.3.0 + boost 1.92.0) |
| 結果 |
AC
|
| 実行時間 | 21 ms / 2,000 ms |
| + 166µs | |
| コード長 | 3,375 bytes |
| 記録 | |
| コンパイル時間 | 5,988 ms |
| コンパイル使用メモリ | 336,616 KB |
| 実行使用メモリ | 6,272 KB |
| 最終ジャッジ日時 | 2026-09-05 14:57:05 |
| 合計ジャッジ時間 | 5,883 ms |
|
ジャッジサーバーID (参考情報) |
judge4_0 / judge2_1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 1 |
| other | AC * 32 |
ソースコード
#ifndef ONLINE_JUDGE
#define _GLIBCXX_DEBUG
#endif
#include <bits/stdc++.h>
using namespace std;
// #include <atcoder/all>
// using namespace atcoder;
using ll = long long; // 2^63-1まで 負の値は可
// using ull = unsigned long long; // 0 <= ull <=2^64-1の範囲 負の値は不可
using vl = vector<ll>;
// using vvl = vector<vl>;
// using P = pair<ll, ll>;
template <typename T>
using MNPQ = priority_queue<T, vector<T>, greater<T>>;
template <typename T>
using MXPQ = priority_queue<T, vector<T>, less<T>>;
#define overload(a, b, c, d, e, ...) e
#define FOR1(i, n) for (int i = 0; i < n; i++)
#define FOR2(i, s, n) for (int i = s; i < n; i++)
#define FOR3(i, s, n, a) for (int i = s; i < n; i += a)
#define rep(...) overload(__VA_ARGS__, FOR3, FOR2, FOR1)(__VA_ARGS__)
#define FOR1_R(i, n) for (int i = n - 1; i >= 0; i--)
#define FOR2_R(i, s, n) for (int i = s - 1; i >= n; i--)
#define FOR3_R(i, s, n, a) for (int i = s - 1; i >= n; i += a)
#define rrep(...) overload(__VA_ARGS__, FOR3_R, FOR2_R, FOR1_R)(__VA_ARGS__)
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
#define nall(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define YN(flg) cout << (flg ? "Yes" : "No") << "\n"
#define out_grid(x, y, h, w) !(0 <= x && x < h && 0 <= y && y < w)
#define debug(x) cerr << #x << " = " << x << endl;
const long long INF = 4e18;
template <typename T>
istream& operator>>(istream& is, vector<T>& a) {
for (auto& x : a) is >> x;
return is;
}
template <typename T>
ostream& operator<<(ostream& os, vector<T>& a) {
for (int i = 0; i < (int)a.size(); i++) os << a[i] << " ";
return os;
}
template <typename T1, typename T2>
ostream& operator<<(ostream& os, pair<T1, T2>& p) {
os << "{" << p.first << "," << p.second << "}";
return os;
}
template <typename K, typename V>
ostream& operator<<(ostream& os, map<K, V>& a) {
for (auto& [k, v] : a) os << "{key:" << k << ", item:" << v << "} ";
return os;
}
void solve() {
string r, s;
cin >> r >> s;
ll k;
cin >> k;
if (s == "Warong") {
rep(i, k) if (r[i] == '?') r[i] = 'A';
if (count(nall(r), 'W') == 0 && count(nall(r), '?') == 1) {
for (auto& c : r)
if (c == '?') c = 'W';
}
} else {
int w_less = 0, q_less = 0;
int w_geq = 0;
rep(i, k) {
if (r[i] == 'W') w_less++;
if (r[i] == '?') q_less++;
}
for (int i = k; i < (int)r.size(); i++) {
if (r[i] == 'W') w_geq++;
}
if (w_less == 0) {
if (w_geq >= 1) {
// K文字目以降にWが存在するため「全てA」の条件は満たせない
// よって最初のK文字にWが必要。?が1つならWに確定する
if (q_less == 1) {
rep(i, k) if (r[i] == '?') r[i] = 'W';
}
} else {
// Wが全く存在しない場合、最初のK文字が全てAなら全体も全てAで確定する
if (q_less == 0) {
for (auto& c : r) if (c == '?') c = 'A';
}
}
}
}
cout << r << "\n";
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
ll t;
cin >> t;
while (t--) solve();
return 0;
}