結果
| 問題 | No.3798 algo to goal |
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2026-11-25 00:58:36 |
| 言語 | C++23(gcc16) (gcc 16.2.0 + boost 1.92.0 + ACL) |
| 結果 |
AC
不安定
|
| 実行時間 | 107 ms / 2,000 ms |
| + 252µs | |
| コード長 | 1,607 bytes |
| 記録 | |
| コンパイル時間 | 3,041 ms |
| コンパイル使用メモリ | 365,872 KB |
| 実行使用メモリ | 10,188 KB |
| 最終ジャッジ日時 | 2026-11-25 00:58:46 |
| 合計ジャッジ時間 | 8,588 ms |
|
ジャッジサーバーID (参考情報) |
judge5_0 / judge2_0 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 1 |
| other | AC * 40 |
ソースコード
#include <bits/stdc++.h>
#define inf 0x3f3f3f3f
#define All(x) x.begin(),x.end()
#define PRC(b,a) fixed<<setprecision(a)<<b
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
using namespace std;
using ll=long long;
ll count_inv(string &s,int l,int r){
if(l>=r) return 0;
int mid=(l+r)>>1;
ll ans=count_inv(s,l,mid)+count_inv(s,mid+1,r);
string tmp;
int i=l,j=mid+1;
while(i<=mid&&j<=r){
if(s[i]<=s[j])
tmp+=s[i++];
else{
tmp+=s[j++];
ans+=mid-i+1;
}
}
while(i<=mid) tmp+=s[i++];
while(j<=r) tmp+=s[j++];
for(int k=l;k<=r;++k)
s[k]=tmp[k-l];
return ans;
}
void solve(){
int len;
string s,t,ods,evs,odt,evt;
cin>>s>>t;
for(int i=0;i<s.size();++i){
if(i&1) evs.push_back(s[i]),evt.push_back(t[i]);
else ods.push_back(s[i]),odt.push_back(t[i]);
}
string ss,st;
ss=evs,st=evt;
sort(All(ss)),sort(All(st));
if(ss!=st){
cout<<"No\n";
return ;
}
ss=ods,st=odt;
sort(All(ss)),sort(All(st));
if(ss!=st){
cout<<"No\n";
return ;
}
string a=ods,b=evs;
sort(All(a)),sort(All(b));
if(adjacent_find(All(a))!=a.end()||adjacent_find(All(b))!=b.end())
cout<<"Yes\n";
else if((count_inv(evs,0,evs.size()-1)+count_inv(evt,0,evt.size()-1))%2 !=
(count_inv(ods,0,ods.size()-1)+count_inv(odt,0,odt.size()-1))%2)
cout<<"No\n";
else cout<<"Yes\n";
}
signed main(){
IOS
int T;
cin>>T;
for(int kase=1;kase<=T;++kase)
solve();
}