結果
| 問題 | No.3798 algo to goal |
| ユーザー |
|
| 提出日時 | 2026-11-08 02:30:21 |
| 言語 | C++17 (gcc 15.3.0 + boost 1.92.0 + ACL) |
| 結果 |
AC
不安定
|
| 実行時間 | 16 ms / 2,000 ms |
| + 557µs | |
| コード長 | 1,458 bytes |
| 記録 | |
| コンパイル時間 | 1,594 ms |
| コンパイル使用メモリ | 216,148 KB |
| 実行使用メモリ | 6,400 KB |
| 最終ジャッジ日時 | 2026-11-13 22:03:19 |
| 合計ジャッジ時間 | 5,285 ms |
|
ジャッジサーバーID (参考情報) |
judge2_0 / judge5_0 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 1 |
| other | AC * 40 |
ソースコード
#include <bits/stdc++.h>
using namespace std;
// x[p], x[p+2], x[p+4], ... からなる部分列の転倒数の偶奇
// 前提: その部分列の文字はすべて相異なる(よって長さ 26 以下)
static int invParity(const string& x, int p) {
unsigned seen = 0;
int par = 0;
for (int i = p; i < (int)x.size(); i += 2) {
int c = x[i] - 'a';
par ^= __builtin_parity(seen >> (c + 1)); // 既出で c より大きい文字数の偶奇
seen |= 1u << c;
}
return par;
}
static bool judge(const string& S, const string& T) {
int cs[2][26] = {}, ct[2][26] = {};
for (int i = 0; i < (int)S.size(); i++) {
cs[i & 1][S[i] - 'a']++;
ct[i & 1][T[i] - 'a']++;
}
bool dup = false;
for (int p = 0; p < 2; p++) {
for (int c = 0; c < 26; c++) {
if (cs[p][c] != ct[p][c]) return false; // クラス別多重集合の不一致
if (cs[p][c] >= 2) dup = true; // クラス内重複 → 符号を自由に調整可能
}
}
if (dup) return true;
int par = invParity(S, 0) ^ invParity(S, 1) ^ invParity(T, 0) ^ invParity(T, 1);
return par == 0;
}
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
int Q;
cin >> Q;
string S, T, out;
out.reserve((size_t)Q * 4);
while (Q--) {
cin >> S >> T;
out += judge(S, T) ? "Yes\n" : "No\n";
}
cout << out;
return 0;
}