結果
| 問題 | No.3587 Too Good to Swap |
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2026-05-28 13:30:59 |
| 言語 | C++17 (gcc 15.2.0 + boost 1.90.0) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 1,900 bytes |
| 記録 | |
| コンパイル時間 | 1,178 ms |
| コンパイル使用メモリ | 214,340 KB |
| 実行使用メモリ | 9,408 KB |
| 最終ジャッジ日時 | 2026-07-10 20:55:00 |
| 合計ジャッジ時間 | 6,152 ms |
|
ジャッジサーバーID (参考情報) |
judge1_0 / judge3_0 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | WA * 1 |
| other | AC * 27 WA * 12 TLE * 1 -- * 9 |
ソースコード
#include <bits/stdc++.h>
using namespace std;
int rank_char(char c) {
if (c == 'o') return 0;
if (c == 'g') return 1;
return 2; // d
}
vector<int> count_chars(const string& s) {
vector<int> cnt(3, 0); // d, o, g
for (char c : s) {
if (c == 'd') cnt[0]++;
else if (c == 'o') cnt[1]++;
else cnt[2]++;
}
return cnt;
}
bool has_good_around_after_swap(const string& s, int i) {
int n = (int)s.size();
auto get_char_after_swap = [&](int pos) -> char {
if (pos == i) return s[i + 1];
if (pos == i + 1) return s[i];
return s[pos];
};
for (int l = i - 3; l <= i; l++) {
if (l < 0 || l + 3 >= n) continue;
if (get_char_after_swap(l) == 'g' &&
get_char_after_swap(l + 1) == 'o' &&
get_char_after_swap(l + 2) == 'o' &&
get_char_after_swap(l + 3) == 'd') {
return true;
}
}
return false;
}
// 嘘の正規化:
// 左から見て、good を作らない隣接逆転を見つけたら即 swap。
// 差分だけ見て good 判定する。
string fake_normalize(string s) {
int n = (int)s.size();
while (true) {
bool changed = false;
for (int i = 0; i + 1 < n; i++) {
if (rank_char(s[i]) <= rank_char(s[i + 1])) continue;
if (has_good_around_after_swap(s, i)) continue;
swap(s[i], s[i + 1]);
changed = true;
break;
}
if (!changed) break;
}
return s;
}
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
int Q;
cin >> Q;
while (Q--) {
string S, T;
cin >> S >> T;
if (count_chars(S) != count_chars(T)) {
cout << "No\n";
continue;
}
cout << (fake_normalize(S) == fake_normalize(T) ? "Yes" : "No") << '\n';
}
return 0;
}