結果

問題 No.3587 Too Good to Swap
コンテスト
ユーザー askr58
提出日時 2026-07-10 23:15:22
言語 C++23(gnu拡張gcc16)
(gcc 16.1.0 + boost 1.90.0)
コンパイル:
g++-16 -O2 -lm -std=gnu++23 -Wuninitialized -DONLINE_JUDGE -o a.out _filename_
実行:
./a.out
結果
AC  
実行時間 30 ms / 2,000 ms
コード長 943 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 4,807 ms
コンパイル使用メモリ 362,660 KB
実行使用メモリ 5,888 KB
最終ジャッジ日時 2026-07-10 23:15:30
合計ジャッジ時間 4,974 ms
ジャッジサーバーID
(参考情報)
judge2_0 / judge3_0
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 1
other AC * 49
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

#include <bits/stdc++.h>
using namespace std;
using ll=long long;
int main(){
	cin.tie(nullptr);
	ios::sync_with_stdio(false);
	int ttt;
	cin>>ttt;
	while(ttt--){
		string s,t;
		cin>>s>>t;
		if(s==t){
			cout<<"Yes"<<endl;
			continue;
		}
		{
			string x=s,y=t;
			ranges::sort(x);
			ranges::sort(y);
			if(x!=y){
				cout<<"No"<<endl;
				continue;
			}
		}
		int n=s.size();
		int ld=n,rg=-1;
		for(int i=0;i<n;i++){
			if(s[i]=='g')rg=i;
			if(s[n-1-i]=='d')ld=n-1-i;
		}
		if(rg==-1||ld==n){
			cout<<"Yes"<<endl;
			continue;
		}
		if(rg+3<ld){
			int rg2=-1,ld2=n;
			for(int i=0;i<n;i++){
				if(t[i]=='g')rg2=i;
				if(t[n-1-i]=='d')ld2=n-1-i;
			}
			if(rg2+3>=ld2){
				cout<<"No"<<endl;
			}else{
				cout<<"Yes"<<endl;
			}
			continue;
		}else{
			int rg2=-1,ld2=n;
			for(int i=0;i<n;i++){
				if(t[i]=='g')rg2=i;
				if(t[n-1-i]=='d')ld2=n-1-i;
			}
			if(rg2+3<ld2)cout<<"No"<<endl;
			else cout<<"Yes"<<endl;
		}
	}
}
				
0