結果

問題 No.2102 [Cherry Alpha *] Conditional Reflection
ユーザー ei1333333ei1333333
提出日時 2022-10-14 21:33:30
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 1,020 ms / 3,000 ms
コード長 4,795 bytes
コンパイル時間 2,185 ms
コンパイル使用メモリ 210,092 KB
実行使用メモリ 64,712 KB
最終ジャッジ日時 2023-09-08 20:26:56
合計ジャッジ時間 50,608 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 341 ms
20,304 KB
testcase_03 AC 529 ms
29,636 KB
testcase_04 AC 331 ms
19,396 KB
testcase_05 AC 149 ms
10,172 KB
testcase_06 AC 380 ms
20,480 KB
testcase_07 AC 849 ms
44,100 KB
testcase_08 AC 35 ms
4,380 KB
testcase_09 AC 613 ms
34,368 KB
testcase_10 AC 95 ms
8,000 KB
testcase_11 AC 144 ms
13,948 KB
testcase_12 AC 291 ms
19,376 KB
testcase_13 AC 706 ms
38,456 KB
testcase_14 AC 228 ms
14,812 KB
testcase_15 AC 384 ms
21,428 KB
testcase_16 AC 831 ms
37,036 KB
testcase_17 AC 507 ms
29,632 KB
testcase_18 AC 852 ms
43,320 KB
testcase_19 AC 166 ms
12,316 KB
testcase_20 AC 820 ms
41,048 KB
testcase_21 AC 63 ms
4,384 KB
testcase_22 AC 937 ms
43,048 KB
testcase_23 AC 902 ms
42,928 KB
testcase_24 AC 935 ms
42,916 KB
testcase_25 AC 936 ms
42,920 KB
testcase_26 AC 881 ms
42,992 KB
testcase_27 AC 924 ms
42,840 KB
testcase_28 AC 955 ms
42,992 KB
testcase_29 AC 907 ms
43,068 KB
testcase_30 AC 929 ms
42,928 KB
testcase_31 AC 945 ms
42,952 KB
testcase_32 AC 915 ms
42,824 KB
testcase_33 AC 914 ms
43,128 KB
testcase_34 AC 925 ms
43,104 KB
testcase_35 AC 925 ms
43,028 KB
testcase_36 AC 964 ms
42,836 KB
testcase_37 AC 951 ms
43,028 KB
testcase_38 AC 939 ms
42,892 KB
testcase_39 AC 963 ms
43,096 KB
testcase_40 AC 942 ms
43,084 KB
testcase_41 AC 958 ms
43,036 KB
testcase_42 AC 569 ms
16,988 KB
testcase_43 AC 533 ms
17,024 KB
testcase_44 AC 545 ms
17,132 KB
testcase_45 AC 564 ms
16,928 KB
testcase_46 AC 557 ms
17,132 KB
testcase_47 AC 988 ms
50,088 KB
testcase_48 AC 1,010 ms
50,296 KB
testcase_49 AC 1,014 ms
50,084 KB
testcase_50 AC 995 ms
50,352 KB
testcase_51 AC 960 ms
50,204 KB
testcase_52 AC 928 ms
64,656 KB
testcase_53 AC 963 ms
64,680 KB
testcase_54 AC 947 ms
64,712 KB
testcase_55 AC 963 ms
48,460 KB
testcase_56 AC 1,020 ms
48,492 KB
testcase_57 AC 899 ms
48,328 KB
testcase_58 AC 61 ms
11,852 KB
testcase_59 AC 958 ms
47,160 KB
testcase_60 AC 28 ms
4,376 KB
testcase_61 AC 884 ms
48,336 KB
testcase_62 AC 8 ms
4,380 KB
testcase_63 AC 137 ms
4,380 KB
testcase_64 AC 119 ms
4,376 KB
testcase_65 AC 162 ms
4,380 KB
testcase_66 AC 891 ms
47,952 KB
testcase_67 AC 74 ms
4,380 KB
testcase_68 AC 68 ms
4,380 KB
testcase_69 AC 65 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>

using namespace std;

using int64 = long long;

const int mod = 998244353;

const int64 infll = (1LL << 62) - 1;

const int inf = (1 << 30) - 1;

struct IoSetup {
  IoSetup() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(10);
    cerr << fixed << setprecision(10);
  }
} iosetup;

template< typename T1, typename T2 >
ostream &operator<<(ostream &os, const pair< T1, T2 > &p) {
  os << p.first << " " << p.second;
  return os;
}

template< typename T1, typename T2 >
istream &operator>>(istream &is, pair< T1, T2 > &p) {
  is >> p.first >> p.second;
  return is;
}

template< typename T >
ostream &operator<<(ostream &os, const vector< T > &v) {
  for (int i = 0; i < (int) v.size(); i++) {
    os << v[i] << (i + 1 != v.size() ? " " : "");
  }
  return os;
}

template< typename T >
istream &operator>>(istream &is, vector< T > &v) {
  for (T &in: v) is >> in;
  return is;
}

template< typename T1, typename T2 >
inline bool chmax(T1 &a, T2 b) { return a < b && (a = b, true); }

template< typename T1, typename T2 >
inline bool chmin(T1 &a, T2 b) { return a > b && (a = b, true); }

template< typename T = int64 >
vector< T > make_v(size_t a) {
  return vector< T >(a);
}

template< typename T, typename... Ts >
auto make_v(size_t a, Ts... ts) {
  return vector< decltype(make_v< T >(ts...)) >(a, make_v< T >(ts...));
}

template< typename T, typename V >
typename enable_if< is_class< T >::value == 0 >::type fill_v(T &t, const V &v) {
  t = v;
}

template< typename T, typename V >
typename enable_if< is_class< T >::value != 0 >::type fill_v(T &t, const V &v) {
  for (auto &e: t) fill_v(e, v);
}

template< typename F >
struct FixPoint: F {
  explicit FixPoint(F &&f): F(forward< F >(f)) {}

  template< typename... Args >
  decltype(auto) operator()(Args &&... args) const {
    return F::operator()(*this, forward< Args >(args)...);
  }
};

template< typename F >
inline decltype(auto) MFP(F &&f) {
  return FixPoint< F >{forward< F >(f)};
}

/**
 * @brief Rolling-Hash(ローリングハッシュ)
 * @see https://qiita.com/keymoon/items/11fac5627672a6d6a9f6
 * @docs docs/rolling-hash.md
 */
struct RollingHash {
  static const uint64_t mod = (1ull << 61ull) - 1;
  using uint128_t = __uint128_t;
  vector< uint64_t > power;
  const uint64_t base;

  static inline uint64_t add(uint64_t a, uint64_t b) {
    if((a += b) >= mod) a -= mod;
    return a;
  }

  static inline uint64_t mul(uint64_t a, uint64_t b) {
    uint128_t c = (uint128_t) a * b;
    return add(c >> 61, c & mod);
  }

  static inline uint64_t generate_base() {
    mt19937_64 mt(chrono::steady_clock::now().time_since_epoch().count());
    uniform_int_distribution< uint64_t > rand(1, RollingHash::mod - 1);
    return rand(mt);
  }

  inline void expand(size_t sz) {
    if(power.size() < sz + 1) {
      int pre_sz = (int) power.size();
      power.resize(sz + 1);
      for(int i = pre_sz - 1; i < sz; i++) {
        power[i + 1] = mul(power[i], base);
      }
    }
  }

  explicit RollingHash(uint64_t base = generate_base()) : base(base), power{1} {}

  vector< uint64_t > build(const string &s) const {
    int sz = s.size();
    vector< uint64_t > hashed(sz + 1);
    for(int i = 0; i < sz; i++) {
      hashed[i + 1] = add(mul(hashed[i], base), s[i]);
    }
    return hashed;
  }

  template< typename T >
  vector< uint64_t > build(const vector< T > &s) const {
    int sz = s.size();
    vector< uint64_t > hashed(sz + 1);
    for(int i = 0; i < sz; i++) {
      hashed[i + 1] = add(mul(hashed[i], base), s[i]);
    }
    return hashed;
  }

  uint64_t query(const vector< uint64_t > &s, int l, int r) {
    expand(r - l);
    return add(s[r], mod - mul(s[l], power[r - l]));
  }

  uint64_t combine(uint64_t h1, uint64_t h2, size_t h2len) {
    expand(h2len);
    return add(mul(h1, power[h2len]), h2);
  }

  int lcp(const vector< uint64_t > &a, int l1, int r1, const vector< uint64_t > &b, int l2, int r2) {
    int len = min(r1 - l1, r2 - l2);
    int low = 0, high = len + 1;
    while(high - low > 1) {
      int mid = (low + high) / 2;
      if(query(a, l1, l1 + mid) == query(b, l2, l2 + mid)) low = mid;
      else high = mid;
    }
    return low;
  }
};


int main() {
  int N;
  cin >> N;
  RollingHash hash;
  set< uint64_t > st;
  while(N--) {
    string s;
    cin >> s;
    auto v = hash.build(s);
    if(st.count(v.back())) cout << "Yes\n";
    else cout << "No\n";
    st.emplace(v.back());
    for(int i = 1; i < (int) s.size(); i++) {
      auto A = hash.query(v, 0, i - 1);
      auto B = hash.query(v, i - 1, i);
      auto C = hash.query(v, i, i + 1);
      auto D = hash.query(v, i + 1, (int) s.size());
      st.emplace(hash.combine(hash.combine(hash.combine(A,C,1),B,1),D,(int)s.size()-(i+1)));
    }
  }
}
0