Submission #923044

#TimeUsernameProblemLanguageResultExecution timeMemory
923044IanisDEL13 (info1cup18_del13)C++17
15 / 100
8 ms2528 KiB
#ifdef LOCAL #include <iostream> #include <fstream> #include <iomanip> #include <cassert> #include <random> #include <vector> #include <queue> #include <stack> #include <set> #include <map> #else #pragma GCC optimize("Ofast,unroll-loops") #include <bits/stdc++.h> #define cerr if (false) cerr #define endl '\n' #endif #define fi first #define se second #define sz(a) ((int)(a).size()) #define all(a) (a).begin(), (a).end() #define lsb(x) (x & (-x)) #define bit(mask, i) (((mask) >> (i)) & 1) #define popcount(x) __builtin_popcount(x) #define YES cout << "YES" << endl #define NO cout << "NO" << endl using namespace std; template <typename T> bool ckmax(T &a, T b) { return a < b ? a = b, true : false; } template <typename T> bool ckmin(T &a, T b) { return a > b ? a = b, true : false; } using ll = long long; using pii = pair<int, int>; const int NMAX = 1e5+5; struct Node { bool removed; int l, r; }; int n, q; Node a[NMAX]; vector<int> ans; bool ap[NMAX]; void node_remove(int u) { a[u].removed = true; int l = a[u].l, r = a[u].r; a[l].r = r; a[r].l = l; } void read() { cin >> n >> q; fill(ap, ap + n + 1, 0); for (int i = 1, x; i <= q; i++) { cin >> x; ap[x] = 1; } } void solve() { if ((n - q) % 2 == 1) { cout << -1 << endl; return; } ap[0] = ap[n + 1] = 1; for (int i = 1; i <= n; i++) a[i] = { 0, i - 1, i + 1 }; ans.clear(); for (int i = 1; i <= n; i++) { if (ap[i] || a[i].removed) continue; while (!ap[a[i].l] && !ap[a[i].r]) { node_remove(a[i].l); node_remove(a[i].r); ans.push_back(i); } } for (int i = 1; i <= n; i++) { if (a[i].removed) continue; while (!ap[a[i].l] && !ap[a[i].r]) { node_remove(a[i].l); node_remove(a[i].r); ans.push_back(i); } } if (int(ans.size()) != (n - q) / 2) { cout << -1 << endl; return; } cout << ans.size() << endl; for (auto &it : ans) cout << it << ' '; cout << endl; } signed main() { #ifdef LOCAL freopen("input.txt", "r", stdin); #endif ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); int t = 1; cin >> t; while (t--) { read(); solve(); } return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...