結果

問題 No.3798 algo to goal
ユーザー kwm_t
提出日時 2026-11-14 00:48:57
言語 C++23
(gcc 15.3.0 + boost 1.92.0 + ACL)
コンパイル:
g++-15 -O2 -fplugin=/usr/lib/yukicoder/noavx512-gcc15.so -lm -std=c++23 -Wuninitialized -DONLINE_JUDGE -o a.out _filename_
実行:
./a.out
結果
AC  
実行時間 246 ms / 2,000 ms
+ 544µs
コード長 2,347 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 2,464 ms
コンパイル使用メモリ 349,500 KB
実行使用メモリ 10,512 KB
最終ジャッジ日時 2026-11-14 00:49:09
合計ジャッジ時間 11,156 ms
ジャッジサーバーID
(参考情報)
judge3_0 / judge2_0
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 1
other AC * 40
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

#include <bits/stdc++.h>
//#include <atcoder/all>
using namespace std;
// using namespace atcoder;
// using mint = modint1000000007;
// const int mod = 1000000007;
// using mint = modint998244353;
// const int mod = 998244353;
// const int INF = 1e9;
// const long long LINF = 1e18;
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rep2(i, l, r) for (int i = (l); i < (r); ++i)
#define rrep(i, n) for (int i = (n)-1; i >= 0; --i)
#define rrep2(i, l, r) for (int i = (r)-1; i >= (l); --i)
#define all(x) (x).begin(), (x).end()
#define allR(x) (x).rbegin(), (x).rend()
#define P pair<int, int>
template<typename A, typename B> inline bool chmax(A& a, const B& b) { if (a < b) { a = b; return true; } return false; }
template<typename A, typename B> inline bool chmin(A& a, const B& b) { if (a > b) { a = b; return true; } return false; }

int main() {
	std::ios::sync_with_stdio(false);
	std::cin.tie(nullptr);
	int t; cin >> t;
	while (t--) {
		auto chk = [&](string s, string t) {
			string s0, s1, t0, t1;
			rep(i, s.size()) {
				if (i % 2 == 0)s0 += s[i];
				else s1 += s[i];
			}
			rep(i, t.size()) {
				if (i % 2 == 0)t0 += t[i];
				else t1 += t[i];
			}
			sort(all(s0));
			sort(all(s1));
			sort(all(t0));
			sort(all(t1));
			return s0 == t0 && s1 == t1;
		};
		string s, t; cin >> s >> t;
		if (!chk(s, t)) {
			cout << "No" << endl;
			continue;
		}
		auto chk1 = [&](string s) {
			vector<int>c0(26), c1(26);
			rep(i, s.size()) {
				if (i % 2 == 0)c0[s[i] - 'a']++;
				else c1[s[i] - 'a']++;
			}
			rep(i, 26)if (c0[i] > 1)return true;
			rep(i, 26)if (c1[i] > 1)return true;
			return false;
		};
		if (chk1(s) || chk1(t)) {
			cout << "Yes" << endl;
			continue;
		}
		auto chk2 = [&](string s)->P {
			vector<int>c0(26), c1(26);
			int x0 = 0, x1 = 0;
			rep(i, s.size()) {
				if (i % 2 == 0) {
					rep2(j, s[i] - 'a', 26)x0 += c0[j];
					c0[s[i] - 'a']++;
				}
				else {
					rep2(j, s[i] - 'a', 26)x1 += c1[j];
					c1[s[i] - 'a']++;
				}
				//rep(j, 26)cout << c0[j];
				//cout << endl;
				//rep(j, 26)cout << c1[j];
				//cout << endl;
				x0 %= 2;
				x1 %= 2;
			}
			//cout << x0 << "_" << x1 << endl;
			return { x0,x1 };
		};
		auto p0 = chk2(s);
		auto p1 = chk2(t);
		if ((p0.first + p0.second) % 2 == (p1.first + p1.second) % 2)cout << "Yes" << endl;
		else cout << "No" << endl;
	}
	return 0;
}
0