結果

問題 No.3234 Infinite Propagation
ユーザー fken_prime_57
提出日時 2025-08-15 21:59:21
言語 C++23
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 33 ms / 2,000 ms
コード長 3,208 bytes
コンパイル時間 5,258 ms
コンパイル使用メモリ 335,032 KB
実行使用メモリ 11,052 KB
最終ジャッジ日時 2025-08-15 22:00:32
合計ジャッジ時間 6,443 ms
ジャッジサーバーID
(参考情報)
judge4 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 1
other AC * 18
権限があれば一括ダウンロードができます

ソースコード

diff #

//#define //_GLIBCXX_DEBUG
#include <bits/stdc++.h>
#include <deque>
#include <atcoder/all>
using namespace std;
using namespace atcoder;
using ll = long long;
using ull = unsigned long long;
using vll=vector<ll>;
using vvll=vector<vector<ll>>;
using Graph=vvll;
using Edgegraph=vector<vector<pair<ll,ll>>>;
using vch=vector<char>;
using vvch=vector<vector<char>>;
using P=pair<ll,ll>;
using vP=vector<P>;
using tup=tuple<ll,ll,ll>;
using vbl=vector<bool>;
using vvbl=vector<vbl>;
using vs=vector<string>;
using vvs=vector<vs>;
using vd=vector<double>;
using vvd=vector<vd>;
using mint = atcoder::modint998244353;
const int infint = 1073741823;
const ll inf = 1LL << 60;
template <class T> inline bool chmax(T& a,T b){if (a<b){a=b;return 1;}return 0;}
template <class T> inline bool chmin(T& a,T b){if (a>b){a=b;return 1;}return 0;}
#define rep(i,x,lim) for(ll i = (x);i < (ll)(lim);i++)
#define rep2(j,x,lim) for(int j = (x);j < (int)(lim);j++)
const ll big=(1e+9)+7;
const ll big2=998244353;

ll dx[8]={1,-1,0,0,1,1,-1,-1};
ll dy[8]={0,0,1,-1,1,-1,1,-1};

int modpow(ll x,ll n,ll m){
    if(n==0) return 1%m;
    x=((x%m)+m)%m;
    if(n%2==0){
        ll r=modpow(x,n/2,m);
        return r*r%m;
    }
    else{
        ll r=modpow(x,n/2,m);
        return r*r%m*x%m;
    }
}
//pは素数でなければならない。
int revmod(ll x,ll p){return modpow(x,p-2,p);}
//99 のRを高速に求める
int modp(ll p,ll q){
    ll gc=gcd(p,q);
    p/=gc;q/=gc;
    ll rev=revmod(p,big2);
    return (rev*q)%big2;
}
//nCrを求める modbig2
int nCr(ll n,ll r){
     ll ans=1;
    rep(i,1,n+1) ans=(ans*i)%big2;
    rep(i,1,r+1) ans=(ans*modpow(i,big2-2,big2))%big2;
    rep(i,1,n-r+1) ans=(ans*modpow(i,big2-2,big2))%big2;
    return ans;
}
ll op(ll a,ll b){return max(a,b);}
ll opmin(ll a,ll b){return min(a,b);}
ll e(){return 0;}

template<class T> size_t HashCombine(const size_t seed,const T &v){
    return seed^(std::hash<T>()(v)+0x9e3779b9+(seed<<6)+(seed>>2));
}
/* pair用 */
template<class T,class S> struct std::hash<std::pair<T,S>>{
    size_t operator()(const std::pair<T,S> &keyval) const noexcept {
        return HashCombine(std::hash<T>()(keyval.first), keyval.second);
    }
};

int main(){
    ll T;
    cin >> T;
    while(T--){
        ll N;
        cin >> N;
        vs X(N),Y(N);
        rep(i,0,N) cin >> X[i] >> Y[i];
        vll XA(N),YA(N);
        rep(i,0,N){
            rep(j,0,X[i].size()) {
                if(X[i][j]=='a') XA[i]++;
            }
            rep(j,0,Y[i].size()){
                if(Y[i][j]=='a') YA[i]++;
            }    
        }
        ll flag=0;
        ll ans=0;
        ll temb=0;
        rep(i,0,N){
            if(XA[i]==1&&X[i].size()==1){
                if(YA[i]!=0){
                    ans=2;
                }
                else{
                    flag=1;
                    chmax(temb,(ll)Y[i].size());
                }
            }
        }
        if(flag==0&&ans!=2) ans=1;
        else if(flag==1&&ans==0){
            rep(i,0,N){
                if(XA[i]==0&&X[i].size()<=temb){
                    ans=2;
                }
            }
        }
        if(ans==2) cout << "Yes" << '\n';
        else cout << "No" << '\n';
    }
}
0