結果
| 問題 | No.3587 Too Good to Swap |
| コンテスト | |
| ユーザー |
Rubikun
|
| 提出日時 | 2026-07-10 22:47:15 |
| 言語 | C++17 (gcc 15.2.0 + boost 1.90.0) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 2,534 bytes |
| 記録 | |
| コンパイル時間 | 1,363 ms |
| コンパイル使用メモリ | 224,404 KB |
| 実行使用メモリ | 6,276 KB |
| 最終ジャッジ日時 | 2026-07-10 22:47:19 |
| 合計ジャッジ時間 | 3,558 ms |
|
ジャッジサーバーID (参考情報) |
judge2_0 / judge3_0 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 1 |
| other | AC * 27 WA * 22 |
ソースコード
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return true; } return false; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return true; } return false; }
#define vi vector<int>
#define vl vector<ll>
#define vii vector<pair<int,int>>
#define vll vector<pair<ll,ll>>
#define vvi vector<vector<int>>
#define vvl vector<vector<ll>>
#define vvii vector<vector<pair<int,int>>>
#define vvll vector<vector<pair<ll,ll>>>
#define vst vector<string>
#define pii pair<int,int>
#define pll pair<ll,ll>
#define pb push_back
#define all(x) (x).begin(),(x).end()
#define mkunique(x) sort(all(x));(x).erase(unique(all(x)),(x).end())
#define fi first
#define se second
#define mp make_pair
#define si(x) int(x.size())
const int mod=998244353,MAX=300005,INF=15<<26;
bool solve(){
string S,T;cin>>S>>T;
int N=si(S);
vi CN(3);
for(char c:S){
if(c=='g') CN[0]++;
if(c=='o') CN[1]++;
if(c=='d') CN[2]++;
}
for(int i=0;i<3;i++){
CN[i]*=-1;
}
for(char c:T){
if(c=='g') CN[0]++;
if(c=='o') CN[1]++;
if(c=='d') CN[2]++;
}
for(int i=0;i<3;i++){
if(CN[i]!=0){
return false;
}
}
for(int q=0;q<2;q++){
int a=0,b=0;
vii X;
for(int i=0;i<N;i++){
if(S[i]=='g'){
a++;
}
if(S[i]=='d'){
b++;
}
if(S[i]=='o'){
if(i&&S[i-1]=='o'){
X.pb(mp(a-1,b));
}
}
}
mkunique(X);
vi U,V,rui(N+1);
for(int i=0;i<N;i++){
rui[i+1]=rui[i];
if(T[i]=='g'){
U.pb(i);
}
if(T[i]=='d'){
V.pb(i);
}
if(T[i]=='o'){
rui[i+1]++;
}
}
for(auto [x,y]:X){
if(x>=0&&x<si(U)&&y>=0&&y<si(V)){
int aa=U[x],bb=V[y];
if(rui[bb+1]-rui[aa]>=2){
}else{
return false;
}
}
}
swap(S,T);
}
return true;
}
int main(){
std::ifstream in("text.txt");
std::cin.rdbuf(in.rdbuf());
cin.tie(0);
ios::sync_with_stdio(false);
int Q;cin>>Q;
while(Q--){
if(solve()) cout<<"Yes\n";
else cout<<"No\n";
}
}
Rubikun