結果
| 問題 | No.2629 A replace B replace C | 
| コンテスト | |
| ユーザー |  | 
| 提出日時 | 2024-02-17 00:10:45 | 
| 言語 | C++17(gcc12) (gcc 12.3.0 + boost 1.87.0) | 
| 結果 | 
                                AC
                                 
                             | 
| 実行時間 | 25 ms / 2,000 ms | 
| コード長 | 1,046 bytes | 
| コンパイル時間 | 22,708 ms | 
| コンパイル使用メモリ | 356,940 KB | 
| 最終ジャッジ日時 | 2025-02-19 15:12:15 | 
| ジャッジサーバーID (参考情報) | judge5 / judge5 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| sample | AC * 5 | 
| other | AC * 61 | 
ソースコード
#pragma GCC target("avx2")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
#include<bits/stdc++.h>
#include<atcoder/all>
using namespace std;
using namespace atcoder;
using ll=long long;
using P=pair<ll,ll>;
void IO(){
  ios::sync_with_stdio(false);
  std::cin.tie(nullptr);
}
int main(){
  IO();
  ll n;
  cin>>n;
  string s;
  cin>>s;
  string t;
  cin>>t;
  set<P> ab,bc;
  for(ll i=0;i<n;i++){
    if(s[i]=='A'&&t[i]!='A'){
      ab.insert(P(t[i]-s[i],i));
    }else if(s[i]=='B'&&t[i]=='C'){
      bc.insert(P(t[i]-s[i],i));
    }
  }
  
  while(ab.size()&&bc.size()){
    auto itr1=prev(ab.end());
    auto itr2=prev(bc.end());
    ll idx1=(*itr1).second;
    ll idx2=(*itr2).second;
    s[idx1]='B';
    s[idx2]='C';
    ab.erase(itr1);
    bc.erase(itr2);
    if(s[idx1]!=t[idx1]){
      bc.insert(P(1,idx1));
    }
  }
  bool ok=true;
  for(ll i=0;i<n;i++){
    if(s[i]!=t[i]){
      ok=false;
    }
  }
  if(ab.size()||bc.size()){
    ok=false;
  }
  if(ok){
    cout<<"Yes"<<endl;
  }else{
    cout<<"No"<<endl;
  }
}
            
            
            
        