結果

問題 No.2102 [Cherry Alpha *] Conditional Reflection
ユーザー 👑 emthrmemthrm
提出日時 2022-10-14 22:25:15
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 1,141 ms / 3,000 ms
コード長 3,503 bytes
コンパイル時間 2,187 ms
コンパイル使用メモリ 217,248 KB
実行使用メモリ 82,340 KB
最終ジャッジ日時 2023-09-08 22:34:23
合計ジャッジ時間 55,748 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 393 ms
20,324 KB
testcase_03 AC 578 ms
29,472 KB
testcase_04 AC 398 ms
19,456 KB
testcase_05 AC 226 ms
10,176 KB
testcase_06 AC 457 ms
20,624 KB
testcase_07 AC 834 ms
44,204 KB
testcase_08 AC 68 ms
4,376 KB
testcase_09 AC 668 ms
34,620 KB
testcase_10 AC 148 ms
7,984 KB
testcase_11 AC 177 ms
14,132 KB
testcase_12 AC 362 ms
19,460 KB
testcase_13 AC 828 ms
38,656 KB
testcase_14 AC 329 ms
14,764 KB
testcase_15 AC 516 ms
21,396 KB
testcase_16 AC 843 ms
37,196 KB
testcase_17 AC 479 ms
29,844 KB
testcase_18 AC 894 ms
43,480 KB
testcase_19 AC 228 ms
12,528 KB
testcase_20 AC 915 ms
41,180 KB
testcase_21 AC 121 ms
4,480 KB
testcase_22 AC 1,027 ms
42,936 KB
testcase_23 AC 1,038 ms
43,228 KB
testcase_24 AC 1,059 ms
42,956 KB
testcase_25 AC 1,045 ms
42,900 KB
testcase_26 AC 1,074 ms
42,948 KB
testcase_27 AC 995 ms
42,932 KB
testcase_28 AC 1,065 ms
42,916 KB
testcase_29 AC 1,011 ms
43,056 KB
testcase_30 AC 1,036 ms
43,212 KB
testcase_31 AC 954 ms
42,996 KB
testcase_32 AC 991 ms
43,156 KB
testcase_33 AC 1,003 ms
43,080 KB
testcase_34 AC 1,010 ms
43,224 KB
testcase_35 AC 1,051 ms
42,940 KB
testcase_36 AC 1,079 ms
43,188 KB
testcase_37 AC 1,023 ms
43,040 KB
testcase_38 AC 1,022 ms
43,000 KB
testcase_39 AC 1,063 ms
43,096 KB
testcase_40 AC 1,017 ms
43,044 KB
testcase_41 AC 1,053 ms
42,940 KB
testcase_42 AC 813 ms
17,012 KB
testcase_43 AC 787 ms
17,116 KB
testcase_44 AC 712 ms
17,044 KB
testcase_45 AC 711 ms
17,036 KB
testcase_46 AC 685 ms
17,192 KB
testcase_47 AC 1,132 ms
50,304 KB
testcase_48 AC 1,067 ms
50,324 KB
testcase_49 AC 1,079 ms
50,244 KB
testcase_50 AC 1,141 ms
50,184 KB
testcase_51 AC 1,048 ms
50,356 KB
testcase_52 AC 955 ms
82,328 KB
testcase_53 AC 945 ms
82,340 KB
testcase_54 AC 942 ms
82,284 KB
testcase_55 AC 939 ms
48,508 KB
testcase_56 AC 947 ms
48,456 KB
testcase_57 AC 1,020 ms
48,452 KB
testcase_58 AC 123 ms
20,148 KB
testcase_59 AC 1,009 ms
46,964 KB
testcase_60 AC 68 ms
4,380 KB
testcase_61 AC 963 ms
48,464 KB
testcase_62 AC 12 ms
4,376 KB
testcase_63 AC 242 ms
4,376 KB
testcase_64 AC 216 ms
4,380 KB
testcase_65 AC 270 ms
4,380 KB
testcase_66 AC 953 ms
48,148 KB
testcase_67 AC 183 ms
4,380 KB
testcase_68 AC 122 ms
4,380 KB
testcase_69 AC 176 ms
4,380 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 MOD1 = 998244353;
constexpr int MOD2 = 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<pair<int, int>>> hashes;
  while (n--) {
    string s; cin >> s;
    RollingHash rh1(s, 10007, MOD1), rh2(s, 10007, MOD2);
    const int l = s.length(), hash1 = rh1.get(0, l), hash2 = rh2.get(0, l);
    cout << (hashes[l].count({hash1, hash2}) ? "Yes\n" : "No\n");
    hashes[l].emplace(hash1, hash2);
    FOR(i, 1, l) {
      ll nhash1 = hash1, nhash2 = hash2;
      nhash1 -= 1LL * rh1.power[l - 1 - (i - 1)] * s[i - 1];
      nhash1 -= 1LL * rh1.power[l - 1 - i] * s[i];
      nhash1 += 1LL * rh1.power[l - 1 - (i - 1)] * s[i];
      nhash1 += 1LL * rh1.power[l - 1 - i] * s[i - 1];
      nhash2 -= 1LL * rh2.power[l - 1 - (i - 1)] * s[i - 1];
      nhash2 -= 1LL * rh2.power[l - 1 - i] * s[i];
      nhash2 += 1LL * rh2.power[l - 1 - (i - 1)] * s[i];
      nhash2 += 1LL * rh2.power[l - 1 - i] * s[i - 1];
      hashes[l].emplace((nhash1 % MOD1 + MOD1) % MOD1, (nhash2 % MOD2 + MOD2) % MOD2);
    }
  }
  return 0;
}
0