結果
| 問題 | No.3587 Too Good to Swap |
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2026-05-26 11:37:41 |
| 言語 | C++17 (gcc 15.2.0 + boost 1.90.0) |
| 結果 |
TLE
|
| 実行時間 | - |
| コード長 | 1,019 bytes |
| 記録 | |
| コンパイル時間 | 1,336 ms |
| コンパイル使用メモリ | 223,816 KB |
| 実行使用メモリ | 7,336 KB |
| 最終ジャッジ日時 | 2026-07-10 20:52:51 |
| 合計ジャッジ時間 | 5,443 ms |
|
ジャッジサーバーID (参考情報) |
judge1_0 / judge2_1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 1 |
| other | AC * 8 TLE * 1 -- * 40 |
ソースコード
#include <bits/stdc++.h>
using namespace std;
bool is_good_string(const string& s) {
return s.find("good") != string::npos;
}
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
int Q;
cin >> Q;
while (Q--) {
string S, T;
cin >> S >> T;
queue<string> que;
set<string> seen;
que.push(S);
seen.insert(S);
bool ok = false;
while (!que.empty()) {
string cur = que.front();
que.pop();
if (cur == T) {
ok = true;
break;
}
int n = (int)cur.size();
for (int i = 0; i + 1 < n; i++) {
string nxt = cur;
swap(nxt[i], nxt[i + 1]);
if (is_good_string(nxt)) continue;
if (seen.count(nxt)) continue;
seen.insert(nxt);
que.push(nxt);
}
}
cout << (ok ? "Yes" : "No") << '\n';
}
return 0;
}