結果

問題 No.2102 [Cherry Alpha *] Conditional Reflection
ユーザー ruthen71
提出日時 2022-10-15 00:03:18
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 420 ms / 3,000 ms
コード長 1,702 bytes
コンパイル時間 2,067 ms
コンパイル使用メモリ 208,156 KB
最終ジャッジ日時 2025-02-08 05:15:22
ジャッジサーバーID
(参考情報)
judge5 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 70
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;

#ifdef _RUTHEN
#include <debug.hpp>
#else
#define show(...) true
#endif

using ll = long long;
#define rep(i, n) for (int i = 0; i < (n); i++)
template <class T> using V = vector<T>;

#include <atcoder/modint>
using mint1 = atcoder::modint1000000007;
using mint2 = atcoder::modint998244353;
ostream &operator<<(ostream &os, const mint1 &p) { return os << p.val(); }
ostream &operator<<(ostream &os, const mint2 &p) { return os << p.val(); }

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int N;
    cin >> N;
    set<pair<unsigned int, unsigned int>> st;
    mint1 B1 = 100007;
    mint2 B2 = 100007;
    rep(i, N) {
        string S;
        cin >> S;
        int M = (int)S.size();
        V<mint1> h1(M + 1), p1(M + 1, 1);
        V<mint2> h2(M + 1), p2(M + 1, 1);
        rep(i, M) {
            h1[i + 1] = h1[i] * B1 + S[i];
            h2[i + 1] = h2[i] * B2 + S[i];
            p1[i + 1] = p1[i] * B1;
            p2[i + 1] = p2[i] * B2;
        }
        int seen = 0;
        if (st.find({h1[M].val(), h2[M].val()}) != st.end()) seen = 1;
        rep(i, M - 1) {
            mint1 ch1 = h1[M];
            ch1 -= h1[i + 2] * p1[M - 2 - i];
            ch1 += h1[i] * p1[M - i];
            ch1 += S[i + 1] * p1[M - i - 1] + S[i] * p1[M - 2 - i];
            mint2 ch2 = h2[M];
            ch2 -= h2[i + 2] * p2[M - 2 - i];
            ch2 += h2[i] * p2[M - i];
            ch2 += S[i + 1] * p2[M - i - 1] + S[i] * p2[M - 2 - i];
            if (st.find({ch1.val(), ch2.val()}) != st.end()) seen = 1;
        }
        cout << (seen ? "Yes" : "No") << '\n';
        st.insert({h1[M].val(), h2[M].val()});
    }
    return 0;
}
0