pb_jiang

CF2164B

Nov 7th, 2025
424
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 3.11 KB | None | 0 0
  1. // Problem: B. Even Modulo Pair
  2. // Contest: Codeforces - Codeforces Global Round 30 (Div. 1 + Div. 2)
  3. // URL: https://codeforces.com/contest/2164/problem/B
  4. // Memory Limit: 256 MB
  5. // Time Limit: 1000 ms
  6. //
  7. // Powered by CP Editor (https://cpeditor.org)
  8.  
  9. #include <assert.h>
  10. #include <bits/stdc++.h>
  11. using namespace std;
  12. #ifndef __DEBUG__
  13. #define dbg(...) 42
  14. #endif
  15. template <class T> using mpq = priority_queue<T, vector<T>, greater<T>>;
  16.  
  17. namespace rngs = std::ranges;
  18. using ll = long long;
  19. using a2l = array<ll, 2>;
  20. using vl = vector<ll>;
  21.  
  22. void solve()
  23. {
  24.     ll n;
  25.     cin >> n;
  26.     vl a(n), ev, od;
  27.     for (auto &x : a) {
  28.         cin >> x;
  29.         (x % 2 ? od : ev).push_back(x);
  30.     }
  31.     if (ev.size() >= 2) {
  32.         cout << ev[0] << ' ' << ev[1] << '\n';
  33.         return;
  34.     }
  35.     if (ev.size() != 0) {
  36.         for (auto val : od) {
  37.             ll x = min(ev[0], val), y = max(ev[0], val);
  38.             if (y % x % 2 == 0) {
  39.                 cout << x << ' ' << y << '\n';
  40.                 return;
  41.             }
  42.         }
  43.     }
  44.     for (auto [x, y] : od | std::views::pairwise) {
  45.         if (y % x % 2 == 0) {
  46.             cout << x << ' ' << y << '\n';
  47.             return;
  48.         }
  49.     }
  50.     assert(od.size() < 40);
  51.     for (ll i = 0; i < od.size(); ++i) {
  52.         for (ll j = i + 1; j < od.size(); ++j) {
  53.             ll x = od[i], y = od[j];
  54.             if (y % x % 2 == 0) {
  55.                 cout << x << ' ' << y << '\n';
  56.                 return;
  57.             }
  58.         }
  59.     }
  60.     cout << -1 << '\n';
  61. }
  62.  
  63. void solve1()
  64. {
  65.     ll n, oc = 0;
  66.     cin >> n;
  67.     vl a(n);
  68.     for (auto &x : a)
  69.         cin >> x, oc += x % 2 == 0;
  70.  
  71.     if (oc >= 2) {
  72.         ll x = -1, y = -1;
  73.         for (ll i = 0; i < n; ++i)
  74.             if (a[i] % 2 == 0) {
  75.                 if (x == -1)
  76.                     x = a[i];
  77.                 else
  78.                     y = a[i];
  79.             }
  80.         cout << x << ' ' << y << '\n';
  81.         return;
  82.     }
  83.  
  84.     for (auto y : a) {
  85.         // 分块
  86.         for (auto x : a) {
  87.             if (x * x > y)
  88.                 break;
  89.             if (y != x && y % x % 2 == 0) {
  90.                 cout << x << ' ' << y << '\n';
  91.                 return;
  92.             }
  93.         }
  94.  
  95.         for (ll i = 1; i * i <= y; i += 1) {
  96.             if (y % 2 != i % 2)
  97.                 continue;
  98.             ll lb = y / (i + 1), ub = y / i;
  99.             auto it1 = lower_bound(a.begin(), a.end(), lb);
  100.             auto it2 = upper_bound(a.begin(), a.end(), ub);
  101.             if (it1 != a.end() && *it1 <= ub) {
  102.                 dbg(lb, ub, *it1);
  103.                 ll x = *it1;
  104.                 if (x > ub)
  105.                     continue;
  106.                 if (x == y)
  107.                     continue;
  108.                 if (y % x % 2 == 0) {
  109.                     cout << x << ' ' << y << '\n';
  110.                     return;
  111.                 }
  112.             }
  113.         }
  114.     }
  115.     cout << -1 << '\n';
  116. }
  117.  
  118. int main(int argc, char **argv)
  119. {
  120.     std::ios::sync_with_stdio(false);
  121.     std::cin.tie(nullptr);
  122.  
  123.     ll t = 1;
  124.     cin >> t;
  125.     while (t--)
  126.         solve();
  127.  
  128.     return 0;
  129. };
  130.  
Advertisement
Add Comment
Please, Sign In to add comment