結果

問題 No.3587 Too Good to Swap
コンテスト
ユーザー GhostMFC
提出日時 2026-11-24 22:47:18
言語 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  
実行時間 9 ms / 2,000 ms
+ 439µs
コード長 774 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 5,853 ms
コンパイル使用メモリ 360,272 KB
実行使用メモリ 6,400 KB
最終ジャッジ日時 2026-11-24 22:47:28
合計ジャッジ時間 6,146 ms
ジャッジサーバーID
(参考情報)
judge1_0 / judge5_0
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 1
other AC * 49
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

#include <bits/stdc++.h>
#define All(x) x.begin(),x.end()
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
using namespace std;

using ll=long long;

bool in_trapped_set(const string &s){
    int n=s.size();
    int last_g=-1;
    int first_d=n;
    for(int i=0;i<n;++i){
        if(s[i]=='g') last_g=i;
        if(s[i]=='d'&&first_d==n) first_d=i;
    }

    if(last_g==-1||first_d==n) return false;
    return (first_d-last_g-1)>=3;
}

void solve(){
    string s,t;
    cin>>s>>t;
    string ss=s,st=t;
    sort(All(ss));
    sort(All(st));
    if(ss!=st){
        cout<<"No\n";
        return ;
    }

    cout<<(in_trapped_set(s)==in_trapped_set(t)?"Yes":"No")<<'\n';
}

signed main(){
    IOS
    int T;
    cin>>T;
    while(T--){
        solve();
    }
}
0