Submission #1100790

#TimeUsernameProblemLanguageResultExecution timeMemory
1100790Kirill22DEL13 (info1cup18_del13)C++17
0 / 100
7 ms1872 KiB
#include "bits/stdc++.h" using namespace std; void solve() { int n, m; cin >> n >> m; if (!m) { cout << -1 << '\n'; return; } vector<int> a(n); for (int i = 0; i < m; i++) { int x; cin >> x; x--; a[x] = 1; } vector<int> ans, tmp, used(n); for (int i = 0; i < n; ) { if (a[i] == 1) { i++; continue; } int j = i; while (j < n && a[j] == 0) { j++; } for (int v = i; v < j; v++) { tmp.push_back(v); } while ((int) tmp.size() >= 5) { ans.push_back(tmp.end()[-2]); used[tmp.end()[-1]] = used[tmp.end()[-3]] = 1; tmp.pop_back(); tmp.pop_back(); tmp.pop_back(); tmp.push_back(ans.back()); } tmp.clear(); i = j; } int want = 0; for (int i = 0; i < n; i++) { if (used[i]) { continue; } if (a[i] == 1) { if (want) { cout << -1 << '\n'; return; } while ((int) tmp.size() >= 3) { ans.push_back(tmp.end()[-2]); tmp.pop_back(); tmp.pop_back(); tmp.pop_back(); tmp.push_back(ans.back()); } want = (int) tmp.size(); tmp.clear(); for (int j = 0; j < want; j++) { ans.push_back(i); } } else { if (want) { want--; } else { tmp.push_back(i); } } } if (!tmp.empty() || want) { cout << -1 << '\n'; return; } cout << (int) ans.size() << '\n'; for (auto& i : ans) { cout << i + 1 << " "; } cout << '\n'; } int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); int t = 1; cin >> t; while (t--) { solve(); } }
#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...