結果

問題 No.3798 algo to goal
コンテスト
ユーザー Rumain831
提出日時 2026-11-16 01:24:43
言語 C++23(gcc16)
(gcc 16.2.0 + boost 1.92.0 + ACL)
コンパイル:
g++-16 -O2 -fplugin=/usr/lib/yukicoder/noavx512-gcc16.so -lm -std=c++23 -Wuninitialized -DONLINE_JUDGE -o a.out _filename_
実行:
./a.out
結果
AC  
実行時間 239 ms / 2,000 ms
+ 420µs
コード長 1,159 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 1,488 ms
コンパイル使用メモリ 189,420 KB
実行使用メモリ 9,924 KB
最終ジャッジ日時 2026-11-16 01:24:58
合計ジャッジ時間 11,757 ms
ジャッジサーバーID
(参考情報)
judge4_0 / judge5_0
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 1
other AC * 40
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
using ll = long long;


bool db(string& s){
  int n=s.size();
  int cnt[26]={};
  for(int i=0; i<n; i++){
    if(cnt[s[i]-'a']) return true;
    cnt[s[i]-'a']++;
  }
  return false;
}

int inv(string s, string t){
  int n=s.size();
  int id[26]={};
  int c=1;
  for(int i=0; i<n; i++) id[s[i]-'a']=c++;
  int x=0;
  for(int i=0; i<n-1; i++)for(int j=i+1; j<n; j++){
    if(id[t[i]-'a']>id[t[j]-'a']) x^=1;
  }
  return x;
}

void solve(){
  string s, t; cin >> s >> t;
  string se, so, te, to;
  int n=s.size();
  for(int i=0; i<n; i+=2) se+=s[i], te+=t[i];
  for(int i=1; i<n; i+=2) so+=s[i], to+=t[i];
  {
    string s0=se, t0=te;
    string s1=so, t1=to;
    sort(begin(s0), end(s0));
    sort(begin(t0), end(t0));
    sort(begin(s1), end(s1));
    sort(begin(t1), end(t1));
    if(s0!=t0||s1!=t1){
      cout << "No" << '\n'; return;
    }
  }
  if(db(se)||db(so)||db(te)||db(to)){
    cout << "Yes" << '\n'; return;
  }
  if(inv(se, te)==inv(so, to)) cout << "Yes" << '\n';
  else cout << "No" << '\n';
}

int main(void){
  int q; cin >> q;
  while(q--) solve();
  return 0; 
}
0