結果

問題 No.2102 [Cherry Alpha *] Conditional Reflection
ユーザー KudeKude
提出日時 2022-10-14 22:50:11
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 140 ms / 3,000 ms
コード長 3,139 bytes
コンパイル時間 2,408 ms
コンパイル使用メモリ 231,088 KB
実行使用メモリ 20,192 KB
最終ジャッジ日時 2023-09-08 23:10:57
合計ジャッジ時間 12,861 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 8 ms
11,180 KB
testcase_01 AC 9 ms
11,200 KB
testcase_02 AC 76 ms
15,652 KB
testcase_03 AC 89 ms
15,912 KB
testcase_04 AC 78 ms
15,676 KB
testcase_05 AC 55 ms
13,216 KB
testcase_06 AC 83 ms
15,512 KB
testcase_07 AC 76 ms
13,392 KB
testcase_08 AC 25 ms
11,532 KB
testcase_09 AC 84 ms
15,476 KB
testcase_10 AC 40 ms
12,228 KB
testcase_11 AC 36 ms
13,136 KB
testcase_12 AC 62 ms
13,872 KB
testcase_13 AC 100 ms
16,400 KB
testcase_14 AC 64 ms
13,656 KB
testcase_15 AC 90 ms
15,604 KB
testcase_16 AC 120 ms
16,848 KB
testcase_17 AC 54 ms
13,320 KB
testcase_18 AC 87 ms
13,928 KB
testcase_19 AC 49 ms
13,280 KB
testcase_20 AC 109 ms
16,628 KB
testcase_21 AC 38 ms
11,608 KB
testcase_22 AC 129 ms
17,408 KB
testcase_23 AC 132 ms
17,228 KB
testcase_24 AC 131 ms
17,444 KB
testcase_25 AC 129 ms
17,232 KB
testcase_26 AC 131 ms
17,312 KB
testcase_27 AC 133 ms
17,424 KB
testcase_28 AC 129 ms
17,444 KB
testcase_29 AC 132 ms
17,424 KB
testcase_30 AC 131 ms
17,444 KB
testcase_31 AC 130 ms
17,280 KB
testcase_32 AC 131 ms
17,248 KB
testcase_33 AC 131 ms
17,452 KB
testcase_34 AC 130 ms
17,416 KB
testcase_35 AC 131 ms
17,416 KB
testcase_36 AC 140 ms
17,416 KB
testcase_37 AC 132 ms
17,460 KB
testcase_38 AC 132 ms
17,492 KB
testcase_39 AC 132 ms
17,536 KB
testcase_40 AC 132 ms
17,516 KB
testcase_41 AC 130 ms
17,228 KB
testcase_42 AC 102 ms
15,760 KB
testcase_43 AC 103 ms
15,932 KB
testcase_44 AC 102 ms
15,696 KB
testcase_45 AC 104 ms
15,648 KB
testcase_46 AC 103 ms
15,928 KB
testcase_47 AC 85 ms
13,456 KB
testcase_48 AC 87 ms
13,688 KB
testcase_49 AC 86 ms
13,528 KB
testcase_50 AC 86 ms
13,360 KB
testcase_51 AC 86 ms
13,576 KB
testcase_52 AC 24 ms
11,892 KB
testcase_53 AC 24 ms
11,968 KB
testcase_54 AC 24 ms
11,892 KB
testcase_55 AC 53 ms
11,196 KB
testcase_56 AC 54 ms
11,288 KB
testcase_57 AC 54 ms
11,252 KB
testcase_58 AC 28 ms
12,084 KB
testcase_59 AC 135 ms
20,192 KB
testcase_60 AC 27 ms
11,120 KB
testcase_61 AC 53 ms
11,260 KB
testcase_62 AC 12 ms
11,248 KB
testcase_63 AC 52 ms
11,064 KB
testcase_64 AC 52 ms
11,192 KB
testcase_65 AC 58 ms
11,116 KB
testcase_66 AC 54 ms
11,248 KB
testcase_67 AC 50 ms
11,236 KB
testcase_68 AC 40 ms
11,272 KB
testcase_69 AC 50 ms
11,180 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
namespace {
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wunused-function"
#include<atcoder/all>
#pragma GCC diagnostic pop
using namespace std;
using namespace atcoder;
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define rrep(i,n) for(int i = (int)(n) - 1; i >= 0; i--)
#define all(x) begin(x), end(x)
#define rall(x) rbegin(x), rend(x)
template<class T> bool chmax(T& a, const T& b) { if (a < b) { a = b; return true; } else return false; }
template<class T> bool chmin(T& a, const T& b) { if (b < a) { a = b; return true; } else return false; }
using ll = long long;
using P = pair<int,int>;
using VI = vector<int>;
using VVI = vector<VI>;
using VL = vector<ll>;
using VVL = vector<VL>;

class mint61 {
  using ull = unsigned long long;
  using ui128 = __uint128_t;
 public:
  static constexpr unsigned long long mod = (1ULL << 61) - 1;
  ull v = 0;
  explicit constexpr mint61() {}
  explicit constexpr mint61(ull x) {
    v = (x >> 61) + (x & mod);
    if (v >= mod) v -= mod;
  }
  static constexpr mint61 raw(ull x) {
    mint61 res;
    res.v = x;
    return res;
  }
  friend constexpr mint61 operator+(mint61 lhs, mint61 rhs) {
    auto res = lhs.v + rhs.v;
    return raw(res < mod ? res : res - mod);
  }
  friend constexpr mint61 operator-(mint61 lhs, mint61 rhs) {
    return raw(lhs.v >= rhs.v ? lhs.v - rhs.v : mod + lhs.v - rhs.v);
  }
  static constexpr ull multiply_loose_mod(mint61 lhs, mint61 rhs) {
    // ab = q(m+1)+r = qm+q+r
    // q+r = ab-qm = ab-floor(ab/(m+1))m < ab-(ab/(m+1)-1)m = ab/(m+1)+m <= (m-1)^2/(m+1)+m = 2m-1-2/(m+1)
    auto mul = ui128(lhs.v) * rhs.v;
    return ull(mul >> 61) + ull(mul & mod);
  }
  friend constexpr mint61 operator*(mint61 lhs, mint61 rhs) {
    auto res = multiply_loose_mod(lhs, rhs);
    return raw(res < mod ? res : res - mod);
  }
  mint61& operator+=(mint61 rhs) { return *this = *this + rhs; }
  mint61& operator-=(mint61 rhs) { return *this = *this - rhs; }
  mint61& operator*=(mint61 rhs) { return *this = *this * rhs; }
  friend ostream& operator<<(ostream& os, mint61 x) { return os << x.v; }
};

static auto RNG = std::mt19937(std::chrono::system_clock::now().time_since_epoch().count());
static auto Distribution = std::uniform_int_distribution<unsigned long long>(1, mint61::mod - 1);
const  auto B = mint61::raw(Distribution(RNG));

constexpr int MX = 1000100;
mint61 powB[1000100];

} int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  powB[0] = mint61::raw(1);
  rep(i, MX - 1) powB[i + 1] = powB[i] * B;
  using ull = unsigned long long;
  unordered_set<ull> seen;
  int n;
  cin >> n;
  rep(_, n) {
    string s;
    cin >> s;
    mint61 hash;
    int sz = s.size();
    rep(i, sz) hash += powB[i] * mint61(s[i]);
    bool ok = false;
    if (seen.count(hash.v)) ok = true;
    rep(i, sz - 1) {
      mint61 v0 = mint61(s[i]), v1 = mint61(s[i+1]);
      mint61 d = v1 - v0;
      hash += powB[i] * d;
      hash -= powB[i+1] * d;
      if (seen.count(hash.v)) ok = true;
      hash -= powB[i] * d;
      hash += powB[i+1] * d;
    }
    cout << (ok ? "Yes\n" : "No\n");
    seen.insert(hash.v);
  }
}
0