結果
問題 | No.2102 [Cherry Alpha *] Conditional Reflection |
ユーザー | Kude |
提出日時 | 2022-10-14 22:50:11 |
言語 | C++17 (gcc 12.3.0 + boost 1.83.0) |
結果 |
AC
|
実行時間 | 138 ms / 3,000 ms |
コード長 | 3,139 bytes |
コンパイル時間 | 2,505 ms |
コンパイル使用メモリ | 234,000 KB |
実行使用メモリ | 20,512 KB |
最終ジャッジ日時 | 2024-06-26 16:31:09 |
合計ジャッジ時間 | 12,384 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge3 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 7 ms
11,136 KB |
testcase_01 | AC | 8 ms
11,008 KB |
testcase_02 | AC | 73 ms
15,920 KB |
testcase_03 | AC | 86 ms
16,156 KB |
testcase_04 | AC | 75 ms
15,852 KB |
testcase_05 | AC | 52 ms
13,440 KB |
testcase_06 | AC | 80 ms
15,788 KB |
testcase_07 | AC | 75 ms
13,484 KB |
testcase_08 | AC | 22 ms
11,504 KB |
testcase_09 | AC | 82 ms
15,916 KB |
testcase_10 | AC | 36 ms
12,544 KB |
testcase_11 | AC | 36 ms
13,440 KB |
testcase_12 | AC | 63 ms
14,380 KB |
testcase_13 | AC | 98 ms
16,416 KB |
testcase_14 | AC | 62 ms
13,872 KB |
testcase_15 | AC | 89 ms
15,788 KB |
testcase_16 | AC | 115 ms
17,188 KB |
testcase_17 | AC | 52 ms
13,440 KB |
testcase_18 | AC | 84 ms
14,384 KB |
testcase_19 | AC | 46 ms
13,484 KB |
testcase_20 | AC | 107 ms
16,672 KB |
testcase_21 | AC | 34 ms
11,776 KB |
testcase_22 | AC | 134 ms
17,692 KB |
testcase_23 | AC | 135 ms
17,692 KB |
testcase_24 | AC | 131 ms
17,696 KB |
testcase_25 | AC | 128 ms
17,696 KB |
testcase_26 | AC | 130 ms
17,692 KB |
testcase_27 | AC | 129 ms
17,568 KB |
testcase_28 | AC | 133 ms
17,696 KB |
testcase_29 | AC | 130 ms
17,568 KB |
testcase_30 | AC | 130 ms
17,572 KB |
testcase_31 | AC | 130 ms
17,572 KB |
testcase_32 | AC | 129 ms
17,692 KB |
testcase_33 | AC | 130 ms
17,568 KB |
testcase_34 | AC | 131 ms
17,568 KB |
testcase_35 | AC | 131 ms
17,700 KB |
testcase_36 | AC | 138 ms
17,700 KB |
testcase_37 | AC | 130 ms
17,568 KB |
testcase_38 | AC | 131 ms
17,568 KB |
testcase_39 | AC | 136 ms
17,692 KB |
testcase_40 | AC | 132 ms
17,696 KB |
testcase_41 | AC | 128 ms
17,568 KB |
testcase_42 | AC | 98 ms
15,908 KB |
testcase_43 | AC | 98 ms
16,032 KB |
testcase_44 | AC | 101 ms
16,032 KB |
testcase_45 | AC | 99 ms
16,000 KB |
testcase_46 | AC | 98 ms
16,028 KB |
testcase_47 | AC | 82 ms
13,996 KB |
testcase_48 | AC | 83 ms
13,868 KB |
testcase_49 | AC | 82 ms
13,868 KB |
testcase_50 | AC | 81 ms
13,864 KB |
testcase_51 | AC | 81 ms
13,992 KB |
testcase_52 | AC | 24 ms
12,260 KB |
testcase_53 | AC | 24 ms
12,128 KB |
testcase_54 | AC | 23 ms
12,132 KB |
testcase_55 | AC | 52 ms
11,264 KB |
testcase_56 | AC | 52 ms
11,264 KB |
testcase_57 | AC | 52 ms
11,264 KB |
testcase_58 | AC | 29 ms
12,000 KB |
testcase_59 | AC | 136 ms
20,512 KB |
testcase_60 | AC | 24 ms
11,264 KB |
testcase_61 | AC | 50 ms
11,220 KB |
testcase_62 | AC | 11 ms
11,520 KB |
testcase_63 | AC | 52 ms
11,008 KB |
testcase_64 | AC | 52 ms
11,264 KB |
testcase_65 | AC | 55 ms
11,488 KB |
testcase_66 | AC | 52 ms
11,392 KB |
testcase_67 | AC | 44 ms
11,264 KB |
testcase_68 | AC | 38 ms
11,136 KB |
testcase_69 | AC | 45 ms
11,136 KB |
ソースコード
#include<bits/stdc++.h> namespace { #pragma GCC diagnostic push #pragma GCC diagnostic ignored "-Wunused-function" #include<atcoder/all> #pragma GCC diagnostic pop using namespace std; using namespace atcoder; #define rep(i,n) for(int i = 0; i < (int)(n); i++) #define rrep(i,n) for(int i = (int)(n) - 1; i >= 0; i--) #define all(x) begin(x), end(x) #define rall(x) rbegin(x), rend(x) template<class T> bool chmax(T& a, const T& b) { if (a < b) { a = b; return true; } else return false; } template<class T> bool chmin(T& a, const T& b) { if (b < a) { a = b; return true; } else return false; } using ll = long long; using P = pair<int,int>; using VI = vector<int>; using VVI = vector<VI>; using VL = vector<ll>; using VVL = vector<VL>; class mint61 { using ull = unsigned long long; using ui128 = __uint128_t; public: static constexpr unsigned long long mod = (1ULL << 61) - 1; ull v = 0; explicit constexpr mint61() {} explicit constexpr mint61(ull x) { v = (x >> 61) + (x & mod); if (v >= mod) v -= mod; } static constexpr mint61 raw(ull x) { mint61 res; res.v = x; return res; } friend constexpr mint61 operator+(mint61 lhs, mint61 rhs) { auto res = lhs.v + rhs.v; return raw(res < mod ? res : res - mod); } friend constexpr mint61 operator-(mint61 lhs, mint61 rhs) { return raw(lhs.v >= rhs.v ? lhs.v - rhs.v : mod + lhs.v - rhs.v); } static constexpr ull multiply_loose_mod(mint61 lhs, mint61 rhs) { // ab = q(m+1)+r = qm+q+r // q+r = ab-qm = ab-floor(ab/(m+1))m < ab-(ab/(m+1)-1)m = ab/(m+1)+m <= (m-1)^2/(m+1)+m = 2m-1-2/(m+1) auto mul = ui128(lhs.v) * rhs.v; return ull(mul >> 61) + ull(mul & mod); } friend constexpr mint61 operator*(mint61 lhs, mint61 rhs) { auto res = multiply_loose_mod(lhs, rhs); return raw(res < mod ? res : res - mod); } mint61& operator+=(mint61 rhs) { return *this = *this + rhs; } mint61& operator-=(mint61 rhs) { return *this = *this - rhs; } mint61& operator*=(mint61 rhs) { return *this = *this * rhs; } friend ostream& operator<<(ostream& os, mint61 x) { return os << x.v; } }; static auto RNG = std::mt19937(std::chrono::system_clock::now().time_since_epoch().count()); static auto Distribution = std::uniform_int_distribution<unsigned long long>(1, mint61::mod - 1); const auto B = mint61::raw(Distribution(RNG)); constexpr int MX = 1000100; mint61 powB[1000100]; } int main() { ios::sync_with_stdio(false); cin.tie(0); powB[0] = mint61::raw(1); rep(i, MX - 1) powB[i + 1] = powB[i] * B; using ull = unsigned long long; unordered_set<ull> seen; int n; cin >> n; rep(_, n) { string s; cin >> s; mint61 hash; int sz = s.size(); rep(i, sz) hash += powB[i] * mint61(s[i]); bool ok = false; if (seen.count(hash.v)) ok = true; rep(i, sz - 1) { mint61 v0 = mint61(s[i]), v1 = mint61(s[i+1]); mint61 d = v1 - v0; hash += powB[i] * d; hash -= powB[i+1] * d; if (seen.count(hash.v)) ok = true; hash -= powB[i] * d; hash += powB[i+1] * d; } cout << (ok ? "Yes\n" : "No\n"); seen.insert(hash.v); } }