結果

問題 No.2102 [Cherry Alpha *] Conditional Reflection
ユーザー ei1333333ei1333333
提出日時 2022-10-14 21:33:30
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 1,015 ms / 3,000 ms
コード長 4,795 bytes
コンパイル時間 2,556 ms
コンパイル使用メモリ 213,264 KB
実行使用メモリ 64,984 KB
最終ジャッジ日時 2024-06-26 13:19:50
合計ジャッジ時間 51,721 ms
ジャッジサーバーID
(参考情報)
judge1 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,248 KB
testcase_01 AC 2 ms
5,376 KB
testcase_02 AC 381 ms
20,480 KB
testcase_03 AC 566 ms
29,568 KB
testcase_04 AC 371 ms
19,584 KB
testcase_05 AC 170 ms
10,240 KB
testcase_06 AC 399 ms
20,736 KB
testcase_07 AC 868 ms
44,032 KB
testcase_08 AC 32 ms
5,376 KB
testcase_09 AC 636 ms
34,432 KB
testcase_10 AC 100 ms
7,936 KB
testcase_11 AC 163 ms
14,208 KB
testcase_12 AC 323 ms
19,712 KB
testcase_13 AC 777 ms
38,656 KB
testcase_14 AC 254 ms
14,848 KB
testcase_15 AC 448 ms
21,504 KB
testcase_16 AC 811 ms
37,120 KB
testcase_17 AC 488 ms
29,824 KB
testcase_18 AC 863 ms
43,392 KB
testcase_19 AC 170 ms
12,416 KB
testcase_20 AC 837 ms
41,088 KB
testcase_21 AC 60 ms
5,376 KB
testcase_22 AC 986 ms
43,008 KB
testcase_23 AC 960 ms
43,136 KB
testcase_24 AC 968 ms
42,880 KB
testcase_25 AC 982 ms
43,008 KB
testcase_26 AC 957 ms
43,008 KB
testcase_27 AC 959 ms
43,008 KB
testcase_28 AC 950 ms
42,880 KB
testcase_29 AC 948 ms
43,008 KB
testcase_30 AC 952 ms
43,008 KB
testcase_31 AC 954 ms
43,008 KB
testcase_32 AC 955 ms
43,008 KB
testcase_33 AC 964 ms
43,136 KB
testcase_34 AC 948 ms
43,136 KB
testcase_35 AC 929 ms
43,008 KB
testcase_36 AC 948 ms
43,008 KB
testcase_37 AC 965 ms
43,136 KB
testcase_38 AC 961 ms
43,008 KB
testcase_39 AC 958 ms
43,008 KB
testcase_40 AC 971 ms
43,008 KB
testcase_41 AC 942 ms
43,008 KB
testcase_42 AC 619 ms
17,024 KB
testcase_43 AC 614 ms
17,152 KB
testcase_44 AC 612 ms
17,152 KB
testcase_45 AC 620 ms
17,024 KB
testcase_46 AC 619 ms
17,024 KB
testcase_47 AC 1,005 ms
50,304 KB
testcase_48 AC 1,011 ms
50,560 KB
testcase_49 AC 999 ms
50,432 KB
testcase_50 AC 1,007 ms
50,176 KB
testcase_51 AC 1,015 ms
50,304 KB
testcase_52 AC 958 ms
64,984 KB
testcase_53 AC 955 ms
64,856 KB
testcase_54 AC 958 ms
64,980 KB
testcase_55 AC 943 ms
48,512 KB
testcase_56 AC 948 ms
48,640 KB
testcase_57 AC 963 ms
48,512 KB
testcase_58 AC 61 ms
12,188 KB
testcase_59 AC 988 ms
46,976 KB
testcase_60 AC 26 ms
5,376 KB
testcase_61 AC 947 ms
48,640 KB
testcase_62 AC 8 ms
5,376 KB
testcase_63 AC 136 ms
5,376 KB
testcase_64 AC 120 ms
5,376 KB
testcase_65 AC 163 ms
5,376 KB
testcase_66 AC 933 ms
48,256 KB
testcase_67 AC 72 ms
5,376 KB
testcase_68 AC 70 ms
5,376 KB
testcase_69 AC 65 ms
5,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