結果

問題 No.3234 Infinite Propagation
ユーザー SnowBeenDiding
提出日時 2025-08-15 21:46:27
言語 C++23
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 17 ms / 2,000 ms
コード長 1,275 bytes
コンパイル時間 5,408 ms
コンパイル使用メモリ 334,872 KB
実行使用メモリ 9,572 KB
最終ジャッジ日時 2025-08-15 21:51:47
合計ジャッジ時間 6,399 ms
ジャッジサーバーID
(参考情報)
judge5 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 1
other AC * 18
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>

#include <atcoder/all>
#define rep(i, a, b) for (ll i = (ll)(a); i < (ll)(b); i++)
using namespace atcoder;
using namespace std;

typedef long long ll;

vector<pair<char, int>> run_length_str(string &a) {
    int n = a.size();
    vector<pair<char, int>> ret;
    int now = 1;
    rep(i, 0, n - 1) {
        if (a[i] == a[i + 1])
            now++;
        else {
            ret.push_back(make_pair(a[i], now));
            now = 1;
        }
    }
    ret.push_back(make_pair(a.back(), now));
    return ret;
}

void solve() {
    int n;
    cin >> n;
    vector<string> s(n), t(n);
    rep(i, 0, n) cin >> s[i] >> t[i];
    int mx = -1;
    rep(i, 0, n) {
        if (s[i] == "a" && (t[i].find('a') != string::npos)) {
            cout << "Yes\n";
            return;
        } else if (s[i] == "a") {
            mx = max(mx, (int)t[i].size());
        }
    }
    rep(i, 0, n) {
        auto rls = run_length_str(s[i]);
        if (rls.size() == 1 && rls[0].first == 'b' && rls[0].second <= mx) {
            cout << "Yes\n";
            return;
        }
    }
    cout << "No\n";
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout << fixed << setprecision(12);
    int t;
    cin >> t;
    while (t--) solve();
}
0