結果

問題 No.2102 [Cherry Alpha *] Conditional Reflection
ユーザー tnakao0123tnakao0123
提出日時 2022-10-15 13:41:07
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 2,767 bytes
コンパイル時間 609 ms
コンパイル使用メモリ 56,564 KB
実行使用メモリ 20,128 KB
最終ジャッジ日時 2023-09-09 02:33:27
合計ジャッジ時間 17,982 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 10 ms
10,788 KB
testcase_01 AC 10 ms
10,852 KB
testcase_02 AC 141 ms
15,036 KB
testcase_03 WA -
testcase_04 AC 145 ms
14,808 KB
testcase_05 AC 85 ms
13,004 KB
testcase_06 AC 157 ms
15,168 KB
testcase_07 WA -
testcase_08 AC 30 ms
10,936 KB
testcase_09 WA -
testcase_10 AC 58 ms
12,288 KB
testcase_11 AC 68 ms
12,880 KB
testcase_12 WA -
testcase_13 WA -
testcase_14 AC 113 ms
13,920 KB
testcase_15 AC 177 ms
15,428 KB
testcase_16 AC 279 ms
17,892 KB
testcase_17 AC 121 ms
12,764 KB
testcase_18 WA -
testcase_19 AC 82 ms
13,328 KB
testcase_20 WA -
testcase_21 AC 45 ms
11,360 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 WA -
testcase_46 WA -
testcase_47 WA -
testcase_48 WA -
testcase_49 WA -
testcase_50 WA -
testcase_51 WA -
testcase_52 AC 30 ms
11,796 KB
testcase_53 AC 30 ms
11,796 KB
testcase_54 AC 30 ms
11,792 KB
testcase_55 AC 104 ms
10,744 KB
testcase_56 WA -
testcase_57 AC 103 ms
10,828 KB
testcase_58 AC 31 ms
11,300 KB
testcase_59 AC 391 ms
20,128 KB
testcase_60 AC 23 ms
10,792 KB
testcase_61 AC 104 ms
10,876 KB
testcase_62 AC 13 ms
11,076 KB
testcase_63 AC 25 ms
10,828 KB
testcase_64 AC 24 ms
10,840 KB
testcase_65 AC 28 ms
10,856 KB
testcase_66 AC 98 ms
10,868 KB
testcase_67 AC 34 ms
10,796 KB
testcase_68 AC 44 ms
10,836 KB
testcase_69 AC 33 ms
10,720 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

/* -*- coding: utf-8 -*-
 *
 * 2102.cc:  No.2102 [Cherry Alpha *] Conditional Reflection - yukicoder
 */

#include<cstdio>
#include<cstring>
#include<set>
#include<algorithm>
#include<utility>
 
using namespace std;

/* constant */

const int MAX_N = 200000;
const int MAX_L = 1000000;
const int P = 4079;
const int MOD = 1000000033;

/* typedef */

/* typedef */

template<const int MOD>
struct MI {
  int v;
  MI(): v() {}
  MI(int _v): v(_v % MOD) {}
  MI(long long _v): v(_v % MOD) {}

  MI operator+(const MI m) const { return MI(v + m.v); }
  MI operator-(const MI m) const { return MI(v + MOD - m.v); }
  MI operator*(const MI m) const { return MI((long long)v * m.v); }

  MI &operator+=(const MI m) { return (*this = *this + m); }
  MI &operator-=(const MI m) { return (*this = *this - m); }
  MI &operator*=(const MI m) { return (*this = *this * m); }

  bool operator==(const MI m) const { return v == m.v; }
  bool operator!=(const MI m) const { return v != m.v; }
  bool operator<(const MI m) const { return v < m.v; }

  MI pow(int n) const {  // a^n % MOD
    MI pm = 1, a = *this;
    while (n > 0) {
      if (n & 1) pm *= a;
      a *= a;
      n >>= 1;
    }
    return pm;
  }

  MI inv() const { return pow(MOD - 2); }
  MI operator/(const MI m) const { return *this * m.inv(); }
  MI &operator/=(const MI m) { return (*this = *this / m); }
};

typedef MI<MOD> mi;

typedef pair<int,mi> pimi;
typedef set<pimi> spimi;

/* global variables */

mi pes[MAX_L + 1], invpes[MAX_L + 1];
char s[MAX_L + 4];

/* subroutines */

inline void prep_rhash(int n) {
  pes[0] = invpes[0] = 1;
  pes[1] = P;
  invpes[1] = pes[1].inv();
  for (int i = 2; i <= n; i++) {
    pes[i] = pes[i - 1] * P;
    invpes[i] = invpes[i - 1] * invpes[1];
  }
}

inline int s2rh(mi rh[], const char s[]) {
  int k = 0;
  for (; s[k]; k++)
    rh[k + 1] = rh[k] + pes[k] * s[k];
  return k;
}

inline mi s2h(const char s[]) {
  mi h = 0;
  for (int k = 0; s[k]; k++) h += pes[k] * s[k];
  return h;
}

inline mi rhash(mi rh[], int i, int j) {
  return (rh[j] - rh[i]) * invpes[i];
}

inline mi replh(mi h, char s[], int i, int j) {
  h -= pes[i] * s[i] + pes[j] * s[j];
  h += pes[i] * s[j] + pes[j] * s[i];
  return h;
}

/* main */

int main() {
  prep_rhash(MAX_L);

  int n;
  scanf("%d", &n);

  spimi gs;
  for (int i = 0; i < n; i++) {
    scanf("%s", s);
    int l = strlen(s);
    mi hi = s2h(s);
    //printf("%d: %s = %d,%d\n", i, s, l, hi.v);

    if (gs.find(pimi(l, hi)) != gs.end()) { puts("Yes"); continue; }

    bool ok = false;
    for (int j = 0; ! ok && j + 1 < l; j++) {
      mi hj = replh(hi, s, j, j + 1);
      ok = (gs.find(pimi(l, hj)) != gs.end());
    }

    gs.insert(pimi(l, hi));

    if (ok) puts("Yes");
    else puts("No");
  }
  return 0;
}
0