結果
| 問題 | No.3798 algo to goal |
| ユーザー |
|
| 提出日時 | 2026-11-13 22:59:51 |
| 言語 | C++23 (gcc 15.3.0 + boost 1.92.0 + ACL) |
| 結果 |
AC
不安定
|
| 実行時間 | 244 ms / 2,000 ms |
| + 266µs | |
| コード長 | 2,015 bytes |
| 記録 | |
| コンパイル時間 | 2,474 ms |
| コンパイル使用メモリ | 346,292 KB |
| 実行使用メモリ | 6,400 KB |
| 最終ジャッジ日時 | 2026-11-13 23:00:15 |
| 合計ジャッジ時間 | 9,588 ms |
|
ジャッジサーバーID (参考情報) |
judge3_0 / judge2_0 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 1 |
| other | AC * 40 |
ソースコード
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
int main() {
cin.tie(nullptr);
ios_base::sync_with_stdio(false);
int q;
cin >> q;
int m = 26;
while (q--) {
string s, t;
cin >> s >> t;
int n = s.size();
vector<int> c1(m, 0);
vector<int> c2(m, 0);
vector<int> c3(m, 0);
vector<int> c4(m, 0);
rep(i, n) {
if (i % 2) {
c1[s[i] - 'a']++;
c3[s[i] - 'a']++;
c1[t[i] - 'a']--;
} else {
c2[s[i] - 'a']++;
c4[s[i] - 'a']++;
c2[t[i] - 'a']--;
}
}
bool ok = true;
rep(i, m) {
if (c1[i] != 0)
ok = false;
if (c2[i] != 0)
ok = false;
}
if (!ok) {
cout << "No" << endl;
continue;
}
ok = false;
rep(i, m) {
if (c3[i] >= 2)
ok = true;
if (c4[i] >= 2)
ok = true;
}
if (ok) {
cout << "Yes" << endl;
continue;
}
auto f = [&](vector<int> v) {
int s = v.size();
int ans = 0;
rep(i, s) rep(j, s) {
if (i >= j)
continue;
if (v[i] > v[j])
ans++;
}
return ans;
};
vector<int> sv1;
vector<int> tv1;
vector<int> sv2;
vector<int> tv2;
rep(i, n) {
if (i % 2) {
sv1.push_back(s[i] - 'a');
tv1.push_back(t[i] - 'a');
} else {
sv2.push_back(s[i] - 'a');
tv2.push_back(t[i] - 'a');
}
}
int x = f(sv1) + f(sv2) + f(tv1) + f(tv2);
cout << (x % 2 == 0 ? "Yes" : "No") << endl;
}
return 0;
}