Submission #44827

#TimeUsernameProblemLanguageResultExecution timeMemory
44827aomeDEL13 (info1cup18_del13)C++17
100 / 100
23 ms1644 KiB
#include <bits/stdc++.h> using namespace std; const int N = 200005; bool ok; bool f[N][3]; vector<int> buf, res; int F(int x) { if (x == 0) return 0; if (x % 2 == 1) return 1; if (x % 2 == 0) return 2; } void calc(int pos) { if (buf.size() == 0) return; if (buf.size() == 1) { ok = 0; return; } reverse(buf.begin(), buf.end()); int sz = buf.size(); vector<int> end; for (int i = 0; i < sz; ++i) { end.push_back(pos), pos -= buf[i] + 1; } f[0][0] = 1; for (int i = 1; i <= sz; ++i) { f[i][0] = f[i][1] = f[i][2] = 0; } for (int i = 0; i < sz; ++i) { for (int j = 0; j < 3; ++j) { if (!f[i][j]) continue; if (buf[i] >= j) f[i + 1][F(buf[i] - j)] = 1; if (F(buf[i]) >= j) f[i + 1][F(buf[i]) - j] = 1; } } if (!f[sz][0]) { ok = 0; return; } int x = sz, y = 0; vector<int> tmp; while (x--) { for (int i = 0; i < 3; ++i) { if (!f[x][i]) continue; if (buf[x] >= i && F(buf[x] - i) == y) { y = i; int l = end[x] - buf[x] + 1, r = end[x]; buf[x] -= i; while (buf[x] > 2) { tmp.push_back(l + 1), l += 2, buf[x] -= 2; } while (i--) tmp.push_back(r + 1); break; } if (F(buf[x]) >= i && F(buf[x]) - i == y) { y = i; int l = end[x] - buf[x] + 1, r = end[x]; while (i--) tmp.push_back(r + 1); while (buf[x] > 2) { tmp.push_back(l + 1), l += 2, buf[x] -= 2; } break; } } } reverse(tmp.begin(), tmp.end()); for (auto i : tmp) res.push_back(i); } void solve() { int n, m; vector<int> a; cin >> n >> m; a.push_back(0); for (int i = 0; i < m; ++i) { int x; cin >> x, a.push_back(x); } a.push_back(n + 1); ok = 1, res.clear(); for (int i = 1; i <= m + 1; ++i) { if (a[i] == a[i - 1] + 1) { calc(a[i - 1] - 1), buf.clear(); continue; } buf.push_back(a[i] - a[i - 1] - 1); } calc(n), buf.clear(); if (!ok) { cout << "-1\n"; return; } cout << res.size() << '\n'; for (auto i : res) cout << i << ' '; cout << '\n'; } int main() { ios::sync_with_stdio(false); int t; cin >> t; while (t--) solve(); }

Compilation message (stderr)

del13.cpp: In function 'void solve()':
del13.cpp:89:2: warning: this 'for' clause does not guard... [-Wmisleading-indentation]
  for (auto i : res) cout << i << ' '; cout << '\n';
  ^~~
del13.cpp:89:39: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'for'
  for (auto i : res) cout << i << ' '; cout << '\n';
                                       ^~~~
del13.cpp: In function 'int F(int)':
del13.cpp:15:1: warning: control reaches end of non-void function [-Wreturn-type]
 }
 ^
#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...