結果

問題 No.2102 [Cherry Alpha *] Conditional Reflection
ユーザー 👑 emthrmemthrm
提出日時 2022-10-14 21:52:50
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 3,202 bytes
コンパイル時間 2,473 ms
コンパイル使用メモリ 213,828 KB
実行使用メモリ 65,796 KB
最終ジャッジ日時 2023-09-08 20:55:34
合計ジャッジ時間 55,443 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 WA -
testcase_03 WA -
testcase_04 WA -
testcase_05 AC 191 ms
10,164 KB
testcase_06 WA -
testcase_07 AC 831 ms
44,032 KB
testcase_08 AC 48 ms
4,376 KB
testcase_09 WA -
testcase_10 AC 112 ms
8,244 KB
testcase_11 AC 157 ms
14,004 KB
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 AC 489 ms
29,868 KB
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
testcase_21 AC 85 ms
4,664 KB
testcase_22 WA -
testcase_23 WA -
testcase_24 WA -
testcase_25 WA -
testcase_26 WA -
testcase_27 WA -
testcase_28 WA -
testcase_29 WA -
testcase_30 WA -
testcase_31 WA -
testcase_32 WA -
testcase_33 WA -
testcase_34 WA -
testcase_35 WA -
testcase_36 WA -
testcase_37 WA -
testcase_38 WA -
testcase_39 WA -
testcase_40 WA -
testcase_41 WA -
testcase_42 WA -
testcase_43 WA -
testcase_44 WA -
testcase_45 AC 706 ms
17,288 KB
testcase_46 WA -
testcase_47 WA -
testcase_48 WA -
testcase_49 WA -
testcase_50 WA -
testcase_51 WA -
testcase_52 AC 1,060 ms
65,792 KB
testcase_53 AC 1,055 ms
65,796 KB
testcase_54 AC 1,024 ms
65,792 KB
testcase_55 WA -
testcase_56 WA -
testcase_57 AC 1,029 ms
48,612 KB
testcase_58 AC 77 ms
12,016 KB
testcase_59 WA -
testcase_60 AC 44 ms
4,380 KB
testcase_61 AC 1,054 ms
48,536 KB
testcase_62 AC 10 ms
4,380 KB
testcase_63 AC 163 ms
4,380 KB
testcase_64 AC 149 ms
4,376 KB
testcase_65 AC 189 ms
4,380 KB
testcase_66 WA -
testcase_67 AC 116 ms
4,376 KB
testcase_68 AC 88 ms
4,376 KB
testcase_69 AC 108 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,m,n) for(int i=(m);i<(n);++i)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) (v).begin(),(v).end()
using ll = long long;
constexpr int INF = 0x3f3f3f3f;
constexpr long long LINF = 0x3f3f3f3f3f3f3f3fLL;
constexpr double EPS = 1e-8;
constexpr int MOD = 998244353;
// constexpr int MOD = 1000000007;
constexpr int DY4[]{1, 0, -1, 0}, DX4[]{0, -1, 0, 1};
constexpr int DY8[]{1, 1, 0, -1, -1, -1, 0, 1};
constexpr int DX8[]{0, -1, -1, -1, 0, 1, 1, 1};
template <typename T, typename U>
inline bool chmax(T& a, U b) { return a < b ? (a = b, true) : false; }
template <typename T, typename U>
inline bool chmin(T& a, U b) { return a > b ? (a = b, true) : false; }
struct IOSetup {
  IOSetup() {
    std::cin.tie(nullptr);
    std::ios_base::sync_with_stdio(false);
    std::cout << fixed << setprecision(20);
  }
} iosetup;

template <typename T = std::string>
struct RollingHash {
  T s;

  explicit RollingHash(const T& s, const int base = 10007,
                       const int mod = 1000000007)
      : base(base), mod(mod), hash({0}), power({1}) {
    const int n = s.size();
    this->s.reserve(n);
    hash.reserve(n + 1);
    power.reserve(n + 1);
    add(s);
  }

  long long get(const int left, const int right) const {
    const long long res =
        hash[right] - hash[left] * power[right - left] % mod;
    return res < 0 ? res + mod : res;
  }

  void add(const T& t) {
    for (const auto c : t) {
      s.push_back(c);
      const int hash_nxt = (hash.back() * base % mod + c) % mod;
      hash.emplace_back(hash_nxt);
      const int power_nxt = power.back() * base % mod;
      power.emplace_back(power_nxt);
    }
  }

  int longest_common_prefix(const int i, const int j) const {
    const int n = s.size();
    int lb = 0, ub = n + 1 - std::max(i, j);
    while (ub - lb > 1) {
      const int mid = (lb + ub) >> 1;
      (get(i, i + mid) == get(j, j + mid) ? lb : ub) = mid;
    }
    return lb;
  }

  template <typename U>
  int longest_common_prefix(const RollingHash<U>& t,
                            const int i, const int j) const {
    int lb = 0;
    int ub = std::min(static_cast<int>(s.size()) - i,
                      static_cast<int>(t.s.size()) - j)
             + 1;
    while (ub - lb > 1) {
      const int mid = (lb + ub) >> 1;
      (get(i, i + mid) == t.get(j, j + mid) ? lb : ub) = mid;
    }
    return lb;
  }

  std::vector<long long> power;
 private:
  const int base, mod;
  std::vector<long long> hash;
};

int main() {
  int n; cin >> n;
  map<int, set<int>> hashes;
  while (n--) {
    string s; cin >> s;
    RollingHash rolling_hash(s, 10007, MOD);
    const int l = s.length(), hash = rolling_hash.get(0, l);
    cout << (hashes[l].count(hash) ? "Yes\n" : "No\n");
    hashes[l].emplace(hash);
    FOR(i, 1, l) {
      ll nhash = hash;
      nhash -= 1LL * rolling_hash.power[l - 1 - (i - 1)] * s[i - 1];
      nhash -= 1LL * rolling_hash.power[l - 1 - i] * s[i];
      nhash += 1LL * rolling_hash.power[l - 1 - (i - 1)] * s[i];
      nhash += 1LL * rolling_hash.power[l - 1 - i] * s[i - 1];
      hashes[l].emplace((nhash % MOD + MOD) % MOD);
    }
  }
  return 0;
}
0