結果
問題 | No.12 限定された素数 |
ユーザー | penguinshunya |
提出日時 | 2020-06-05 01:57:49 |
言語 | C++17 (gcc 12.3.0 + boost 1.83.0) |
結果 |
AC
|
実行時間 | 793 ms / 5,000 ms |
コード長 | 3,692 bytes |
コンパイル時間 | 2,506 ms |
コンパイル使用メモリ | 214,092 KB |
実行使用メモリ | 8,984 KB |
最終ジャッジ日時 | 2024-05-08 02:19:20 |
合計ジャッジ時間 | 16,872 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge2 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 472 ms
8,728 KB |
testcase_01 | AC | 470 ms
8,856 KB |
testcase_02 | AC | 468 ms
8,856 KB |
testcase_03 | AC | 793 ms
8,852 KB |
testcase_04 | AC | 470 ms
8,852 KB |
testcase_05 | AC | 479 ms
8,760 KB |
testcase_06 | AC | 528 ms
8,824 KB |
testcase_07 | AC | 513 ms
8,724 KB |
testcase_08 | AC | 509 ms
8,860 KB |
testcase_09 | AC | 476 ms
8,856 KB |
testcase_10 | AC | 478 ms
8,724 KB |
testcase_11 | AC | 540 ms
8,856 KB |
testcase_12 | AC | 508 ms
8,724 KB |
testcase_13 | AC | 495 ms
8,860 KB |
testcase_14 | AC | 477 ms
8,788 KB |
testcase_15 | AC | 489 ms
8,852 KB |
testcase_16 | AC | 507 ms
8,660 KB |
testcase_17 | AC | 480 ms
8,860 KB |
testcase_18 | AC | 471 ms
8,852 KB |
testcase_19 | AC | 469 ms
8,628 KB |
testcase_20 | AC | 475 ms
8,856 KB |
testcase_21 | AC | 486 ms
8,984 KB |
testcase_22 | AC | 469 ms
8,856 KB |
testcase_23 | AC | 469 ms
8,860 KB |
testcase_24 | AC | 469 ms
8,728 KB |
testcase_25 | AC | 481 ms
8,852 KB |
ソースコード
#include <bits/stdc++.h> #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 reps(i, n) for (int i = 1; i <= int(n); i++) #define rreps(i, n) for (int i = int(n); i >= 1; i--) #define repc(i, n) for (int i = 0; i <= int(n); i++) #define rrepc(i, n) for (int i = int(n); i >= 0; i--) #define repi(i, a, b) for (int i = int(a); i < int(b); i++) #define repic(i, a, b) for (int i = int(a); i <= int(b); i++) #define all(a) (a).begin(), (a).end() #define bit32(x) (1 << (x)) #define bit64(x) (1ll << (x)) #define sz(v) ((int) v.size()) using namespace std; using i64 = long long; using f80 = long double; using vi32 = vector<int>; using vi64 = vector<i64>; using vf80 = vector<f80>; using vstr = vector<string>; void yes() { cout << "Yes" << endl; exit(0); } void no() { cout << "No" << endl; exit(0); } template <typename T> class pqasc : public priority_queue<T, vector<T>, greater<T>> {}; template <typename T> class pqdesc : public priority_queue<T, vector<T>, less<T>> {}; template <typename T> void amax(T &x, T y) { x = max(x, y); } template <typename T> void amin(T &x, T y) { x = min(x, y); } template <typename T> T exp(T x, i64 n, T e = 1) { T r = e; while (n > 0) { if (n & 1) r *= x; x *= x; n >>= 1; } return r; } template <typename T> istream& operator>>(istream &is, vector<T> &v) { for (auto &x : v) is >> x; return is; } template <typename T> ostream& operator<<(ostream &os, vector<T> &v) { rep(i, v.size()) { if (i) os << ' '; os << v[i]; } return os; } void solve(); int main() { ios::sync_with_stdio(0); cin.tie(0); cout << fixed << setprecision(16); solve(); return 0; } const int INF = 1001001001; const int dx[] = {1, 0, -1, 0}; const int dy[] = {0, 1, 0, -1}; struct Prime { int n; vector<int> pri; Prime(int n) : n(n) { vector<bool> f(n, true); f[0] = f[1] = false; for (int i = 2; i < n; i++) { if (!f[i]) continue; pri.push_back(i); for (int j = i * 2; j < n; j += i) { f[j] = false; } } } map<int, int> factor(int k) { map<int, int> so; for (auto p : pri) { while (k % p == 0) k /= p, so[p]++; } if (k != 1) so[k] = 1; return so; } }; auto prime = Prime(5000001).pri; template <typename T> struct SegmentTree { vector<T> v; function<T(T, T)> f; T e; int n; SegmentTree(int size, function<T(T, T)> f, T e) : f(f), e(e) { n = 1; while (n < size) n <<= 1; v.resize(n * 2, e); } void set(int k, T x) { v[k + n] = x; } void build() { for (int i = n - 1; i > 0; i--) { v[i] = f(v[i * 2 + 0], v[i * 2 + 1]); } } void update(int k, T x) { v[k += n] = x; while (k >>= 1) v[k] = f(v[k * 2 + 0], v[k * 2 + 1]); } T query(int a, int b) { T l = e, r = e; for (a += n, b += n; a < b; a >>= 1, b >>= 1) { if (a & 1) l = f(l, v[a++]); if (b & 1) r = f(v[--b], r); } return f(l, r); } T operator[](int k) { return query(k, k + 1); } }; void solve() { int n; cin >> n; int bit = 0; rep(i, n) { int a; cin >> a; bit |= 1 << a; } n = sz(prime); SegmentTree<int> st(n, [](int a, int b) { return a | b; }, 0); rep(i, n) { int p = prime[i]; int b = 0; while (p) b |= 1 << (p % 10), p /= 10; st.set(i, b); } st.build(); int ans = -1; rep(k, n) { int ok = k - 1, ng = n + 1; while (abs(ok - ng) != 1) { int x = (ok + ng) / 2; (st.query(k, x) <= bit ? ok : ng) = x; } if (st.query(k, ok) == bit) { int l = k == 0 ? 1 : prime[k - 1] + 1; int r = ok == n ? 5000000 : prime[ok] - 1; amax(ans, r - l); } } cout << ans << endl; }