結果
| 問題 | No.3587 Too Good to Swap |
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2026-05-26 13:46:09 |
| 言語 | C++17 (gcc 15.2.0 + boost 1.90.0) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 1,794 bytes |
| 記録 | |
| コンパイル時間 | 1,152 ms |
| コンパイル使用メモリ | 216,240 KB |
| 実行使用メモリ | 5,888 KB |
| 最終ジャッジ日時 | 2026-07-10 20:53:26 |
| 合計ジャッジ時間 | 6,101 ms |
|
ジャッジサーバーID (参考情報) |
judge3_0 / judge1_0 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | WA * 1 |
| other | AC * 11 WA * 28 TLE * 1 -- * 9 |
ソースコード
#include <bits/stdc++.h>
using namespace std;
bool is_good(const string& s) {
return s.find("good") != string::npos;
}
int score(const string& s, const string& t) {
int res = 0;
for (int i = 0; i < (int)s.size(); i++) {
if (s[i] != t[i]) res++;
}
return res;
}
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
int Q;
cin >> Q;
while (Q--) {
string S, T;
cin >> S >> T;
vector<int> cntS(3, 0), cntT(3, 0);
for (char c : S) {
if (c == 'd') cntS[0]++;
else if (c == 'o') cntS[1]++;
else cntS[2]++;
}
for (char c : T) {
if (c == 'd') cntT[0]++;
else if (c == 'o') cntT[1]++;
else cntT[2]++;
}
if (cntS != cntT) {
cout << "No\n";
continue;
}
int n = (int)S.size();
int limit = 20 * n + 100;
bool ok = false;
for (int step = 0; step < limit; step++) {
if (S == T) {
ok = true;
break;
}
int curScore = score(S, T);
int bestScore = curScore;
int bestPos = -1;
for (int i = 0; i + 1 < n; i++) {
if (S[i] == S[i + 1]) continue;
string U = S;
swap(U[i], U[i + 1]);
if (is_good(U)) continue;
int sc = score(U, T);
if (sc < bestScore) {
bestScore = sc;
bestPos = i;
}
}
if (bestPos == -1) {
break;
}
swap(S[bestPos], S[bestPos + 1]);
}
cout << (ok ? "Yes" : "No") << '\n';
}
return 0;
}