pb_jiang

CF2162E

Oct 17th, 2025
475
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.61 KB | None | 0 0
  1. // Problem: E. Beautiful Palindromes
  2. // Contest: Codeforces - Codeforces Round 1059 (Div. 3)
  3. // URL: https://codeforces.com/contest/2162/problem/E
  4. // Memory Limit: 256 MB
  5. // Time Limit: 2000 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, k;
  25.     cin >> n >> k;
  26.     vl a(n);
  27.     for (auto &x : a)
  28.         cin >> x;
  29.     set<ll> ss(a.begin(), a.end());
  30.     vl opts;
  31.     if (ss.size() + 2 <= n) {
  32.         for (ll i = 1; i <= n && opts.size() < 3; ++i)
  33.             if (ss.count(i) == 0)
  34.                 opts.push_back(i);
  35.         if (opts.size() != 3)
  36.             opts.push_back(a.back());
  37.         dbg(opts);
  38.     } else if (ss.size() + 1 == n) {
  39.         ll x = -1, y = -1, z = a.back();
  40.         for (ll i = 1; i <= n; ++i)
  41.             if (ss.count(i) == 0)
  42.                 x = i;
  43.         y = a[n - 1] == a[n - 2] ? a[n - 3] : a[n - 2];
  44.         opts = vl{x, y, z};
  45.         dbg(opts);
  46.     } else {
  47.         opts = vl{a[n - 3], a[n - 2], a[n - 1]};
  48.         dbg(opts);
  49.     }
  50.  
  51.     // cout << k << '\n';
  52.     for (ll i = 0; i < k; ++i)
  53.         cout << opts[i % 3] << ' ';
  54.     cout << '\n';
  55. }
  56.  
  57. int main(int argc, char **argv)
  58. {
  59.     std::ios::sync_with_stdio(false);
  60.     std::cin.tie(nullptr);
  61.  
  62.     ll t = 1;
  63.     cin >> t;
  64.     while (t--)
  65.         solve();
  66.  
  67.     return 0;
  68. };
  69.  
Advertisement
Add Comment
Please, Sign In to add comment