結果

問題 No.3798 algo to goal
ユーザー HoyHoyCharhang
提出日時 2026-11-13 22:59:31
言語 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  
実行時間 247 ms / 2,000 ms
+ 307µs
コード長 2,700 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 3,031 ms
コンパイル使用メモリ 341,588 KB
実行使用メモリ 9,720 KB
最終ジャッジ日時 2026-11-13 22:59:44
合計ジャッジ時間 11,091 ms
ジャッジサーバーID
(参考情報)
judge2_0 / judge5_0
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 1
other AC * 40
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

#include <bits/stdc++.h>
#define fi first
#define se second
#define rep(i,s,n) for (int i = (s); i < (n); ++i)
#define rrep(i,g,n) for (int i = (n)-1; i >= (g); --i)
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define len(x) (int)(x).size()
#define dup(x,y) (((x)+(y)-1)/(y))
#define pb push_back
#define eb emplace_back
#define Field(T) vector<vector<T>>
using namespace std;
using ll = long long;
using ull = unsigned long long;
template<typename T> using pq = priority_queue<T,vector<T>,greater<T>>;
using P = pair<int,int>;
template<class T>bool chmax(T&a,T b){if(a<b){a=b;return 1;}return 0;}
template<class T>bool chmin(T&a,T b){if(b<a){a=b;return 1;}return 0;}

void solve() {
  string s, t;
  cin >> s >> t;
  int n = len(s);
  string s0, s1, t0, t1;
  rep(i,0,n) {
    if (i%2 == 0) s0 += s[i], t0 += t[i];
    else s1 += s[i], t1 += t[i];
  }
  vector<int> cnt0(26), cnt1(26);
  for (int c : s0) ++cnt0[c-'a'];
  for (int c : t0) --cnt0[c-'a'];
  for (int c : s1) ++cnt1[c-'a'];
  for (int c : t1) --cnt1[c-'a'];
  rep(i,0,26) {
    if (cnt0[i] != 0 || cnt1[i] != 0) {
      cout << "No" << endl;
      return;
    }
  }
  for (int c : s0) ++cnt0[c-'a'];
  for (int c : s1) ++cnt1[c-'a'];
  int x0 = 0, x1 = 0, y0 = 0, y1 = 0;
  rep(i,0,26) {
    if (cnt0[i] >= 2) x0 = x1 = 1;
    if (cnt1[i] >= 2) y0 = y1 = 1;
  }
  if (!x0) {
    int bit = 0;
    int vs = 0, vt = 0;
    for (char c : s0) {
      vs += __builtin_popcount(bit>>(c-'a'));
      bit |= (1<<(c-'a'));
    }
    bit = 0;
    for (char c : t0) {
      vt += __builtin_popcount(bit>>(c-'a'));
      bit |= (1<<(c-'a'));
    }
    vs %= 2, vt %= 2;
    if (vs == vt) x0 = 1;
    else x1 = 1;
  }
  if (!y0) {
    int bit = 0;
    int vs = 0, vt = 0;
    for (char c : s1) {
      vs += __builtin_popcount(bit>>(c-'a'));
      bit |= (1<<(c-'a'));
    }
    bit = 0;
    for (char c : t1) {
      vt += __builtin_popcount(bit>>(c-'a'));
      bit |= (1<<(c-'a'));
    }
    vs %= 2, vt %= 2;
    if (vs == vt) y0 = 1;
    else y1 = 1;
  }
  if ((x0 && y0) || (x1 && y1)) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }
}

int main() {
  // string s = "abcdefg";
  // set<string> st;
  // queue<string> que;
  // st.emplace(s);
  // que.emplace(s);
  // while(!que.empty()) {
  //   string t = que.front();
  //   que.pop();
  //   rep(i,0,len(s)-3) {
  //     swap(t[i], t[i+2]), swap(t[i+1], t[i+3]);
  //     if (!st.contains(t)) {
  //       st.emplace(t);
  //       que.emplace(t);
  //     }
  //     swap(t[i], t[i+2]), swap(t[i+1], t[i+3]);
  //   }
  // }
  // for (string t : st) {
  //   cout << t << endl;
  // }
  int t;
  cin >> t;
  while(t--) solve();
  return 0;
}
0