結果
問題 | No.2718 Best Consonance |
ユーザー | 👑 emthrm |
提出日時 | 2024-04-05 22:28:51 |
言語 | C++23 (gcc 13.3.0 + boost 1.87.0) |
結果 |
TLE
(最新)
AC
(最初)
|
実行時間 | - |
コード長 | 3,194 bytes |
コンパイル時間 | 3,482 ms |
コンパイル使用メモリ | 275,964 KB |
実行使用メモリ | 290,416 KB |
最終ジャッジ日時 | 2024-10-01 04:11:13 |
合計ジャッジ時間 | 31,758 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge1 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 8 ms
13,520 KB |
testcase_01 | AC | 9 ms
13,428 KB |
testcase_02 | AC | 8 ms
13,528 KB |
testcase_03 | AC | 8 ms
13,516 KB |
testcase_04 | AC | 9 ms
13,548 KB |
testcase_05 | AC | 7 ms
13,500 KB |
testcase_06 | AC | 9 ms
13,532 KB |
testcase_07 | AC | 8 ms
13,548 KB |
testcase_08 | AC | 8 ms
13,360 KB |
testcase_09 | AC | 10 ms
13,556 KB |
testcase_10 | AC | 11 ms
13,456 KB |
testcase_11 | AC | 11 ms
13,428 KB |
testcase_12 | AC | 11 ms
13,520 KB |
testcase_13 | AC | 10 ms
13,384 KB |
testcase_14 | AC | 896 ms
40,916 KB |
testcase_15 | AC | 641 ms
35,360 KB |
testcase_16 | AC | 727 ms
36,888 KB |
testcase_17 | AC | 537 ms
32,356 KB |
testcase_18 | AC | 751 ms
38,384 KB |
testcase_19 | AC | 579 ms
34,404 KB |
testcase_20 | AC | 925 ms
41,076 KB |
testcase_21 | AC | 836 ms
39,880 KB |
testcase_22 | AC | 823 ms
40,184 KB |
testcase_23 | AC | 420 ms
30,528 KB |
testcase_24 | AC | 1,616 ms
43,044 KB |
testcase_25 | AC | 1,181 ms
43,076 KB |
testcase_26 | AC | 982 ms
43,140 KB |
testcase_27 | AC | 1,157 ms
43,324 KB |
testcase_28 | AC | 1,196 ms
43,120 KB |
testcase_29 | AC | 1,110 ms
43,056 KB |
testcase_30 | AC | 1,205 ms
43,128 KB |
testcase_31 | AC | 1,612 ms
43,064 KB |
testcase_32 | AC | 1,218 ms
43,124 KB |
testcase_33 | AC | 1,096 ms
43,172 KB |
testcase_34 | AC | 10 ms
13,532 KB |
testcase_35 | AC | 7 ms
13,532 KB |
testcase_36 | AC | 1,632 ms
85,888 KB |
testcase_37 | AC | 10 ms
13,428 KB |
testcase_38 | TLE | - |
testcase_39 | -- | - |
ソースコード
#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)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 <bool GETS_ONLY_PRIME>std::vector<int> prime_sieve(const int n) {std::vector<int> smallest_prime_factor(n + 1), prime;std::iota(smallest_prime_factor.begin(), smallest_prime_factor.end(), 0);for (int i = 2; i <= n; ++i) {if (smallest_prime_factor[i] == i) [[unlikely]] prime.emplace_back(i);for (const int p : prime) {if (i * p > n || p > smallest_prime_factor[i]) break;smallest_prime_factor[i * p] = p;}}return GETS_ONLY_PRIME ? prime : smallest_prime_factor;}struct Divisor {const std::vector<int> smallest_prime_factor;explicit Divisor(const int n): smallest_prime_factor(prime_sieve<false>(n)) {}std::vector<int> query(int n) const {std::vector<int> res{1};while (n > 1) {const int prime_factor = smallest_prime_factor[n], d = res.size();int tmp = 1;for (; n % prime_factor == 0; n /= prime_factor) {tmp *= prime_factor;for (int i = 0; i < d; ++i) {res.emplace_back(res[i] * tmp);}}}// std::sort(res.begin(), res.end());return res;}};int main() {constexpr int A = 200000;const Divisor divisor(A);int n; cin >> n;vector<int> a(n), b(n); REP(i, n) cin >> a[i] >> b[i];array<vector<int>, A + 1> ar1{}, ar2{};REP(i, n) for (const int g : divisor.query(a[i])) ar1[g].emplace_back(i);vector<int> gs;REP(g, A + 1) {if (ar1[g].size() >= 2) {ranges::sort(ar1[g], {}, [&b](const int i) -> int { return b[i]; });ar2[g].reserve(ar1[g].size());ranges::copy(ar1[g], back_inserter(ar2[g]));ranges::sort(ar2[g], {}, [&a](const int i) -> int { return a[i]; });gs.emplace_back(g);}}int lb = 0, ub = ranges::max(b) + 1;while (ub - lb > 1) {const int f = midpoint(lb, ub);(ranges::any_of(gs, [&](const int g) -> bool {int j = 0;set<pair<ll, int>> st;for (const int i : ar1[g]) {for (; j < ar2[g].size() && ll{a[ar2[g][j]]} * f <= ll{b[i]} * g; ++j) {st.emplace(ll{b[ar2[g][j]]} * g, ar2[g][j]);if (st.size() >= 3) st.erase(st.begin());}for (const auto& [gb, id] : st) {if (id != i && gb >= ll{a[i]} * f) return true;}}return false;}) ? lb : ub) = f;}cout << lb << '\n';return 0;}