結果
| 問題 | No.3798 algo to goal |
| ユーザー |
|
| 提出日時 | 2026-11-08 02:21:58 |
| 言語 | C++17 (gcc 15.3.0 + boost 1.92.0 + ACL) |
| 結果 |
TLE
不安定
|
| 実行時間 | - |
| コード長 | 1,319 bytes |
| 記録 | |
| コンパイル時間 | 1,860 ms |
| コンパイル使用メモリ | 232,140 KB |
| 実行使用メモリ | 15,764 KB |
| 最終ジャッジ日時 | 2026-11-13 22:02:27 |
| 合計ジャッジ時間 | 9,918 ms |
|
ジャッジサーバーID (参考情報) |
judge5_0 / judge4_0 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 1 |
| other | AC * 12 TLE * 1 -- * 27 |
ソースコード
#include <bits/stdc++.h>
using namespace std;
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
const int C = 26;
int Q;
cin >> Q;
while (Q--) {
string S, T;
cin >> S >> T;
int N = (int)S.size();
vector<vector<int>> A(2, vector<int>(C));
vector<vector<int>> B(2, vector<int>(C));
for (int i = 0; i < N; i++) {
A[i % 2][S[i] - 'a']++;
B[i % 2][T[i] - 'a']++;
}
if (A != B) {
cout << "No\n";
continue;
}
if (N > 52) {
cout << "Yes\n";
continue;
}
queue<string> que;
unordered_set<string> seen;
seen.insert(S);
que.push(S);
bool ok = false;
int steps = 0;
while (!que.empty() && steps < 1000) {
string U = que.front();
que.pop();
steps++;
if (U == T) {
ok = true;
break;
}
for (int i = 0; i + 3 < N; i++) {
string V = U;
swap(V[i], V[i + 2]);
swap(V[i + 1], V[i + 3]);
if (seen.insert(V).second) que.push(V);
}
}
cout << (ok ? "Yes" : "No") << '\n';
}
return 0;
}