Submission #400511

# Submission time Handle Problem Language Result Execution time Memory
400511 2021-05-08T08:36:36 Z dolphingarlic DEL13 (info1cup18_del13) C++14
0 / 100
93 ms 131076 KB
#include <bits/stdc++.h>
typedef long long ll;
using namespace std;

int p[100001];
bool isolated[100001], impossible;
vector<int> moves;

void solve(array<int, 3> seg) {
    if (seg[2] == seg[0]) return;
    if ((seg[2] - seg[0]) & 1) {
        impossible = true;
        return;
    }
    moves.push_back(seg[1]);
    if (seg[2] - seg[1] == seg[1] - seg[0])
        solve({seg[0] + 1, seg[1], seg[2] - 1});
    else if (seg[2] - seg[1] == 1)
        solve({seg[0], (seg[0] + seg[2] - 2) / 2, seg[2] - 2});
    else if (seg[1] - seg[0] == 1)
        solve({seg[0] + 2, (seg[0] + seg[2] + 2) / 2, seg[2]});
    else
        solve({seg[0] + 1, seg[1], seg[2] - 1});
}

int main() {
    cin.tie(0)->sync_with_stdio(0);
    int t;
    cin >> t;
    while (t--) {
        int n, m;
        cin >> n >> m;
        for (int i = 1; i <= m; i++) cin >> p[i];
        p[0] = 0, p[m + 1] = n + 1;
        for (int i = 1; i <= m; i++) {
            isolated[i] = p[i - 1] != p[i] - 1 && p[i + 1] != p[i] + 1;
        }

        impossible = false;
        if ((n - m) & 1) impossible = true;
        vector<array<int, 3>> segs;
        for (int i = 1; i <= m + 1; i++) {
            if (p[i - 1] != p[i] - 1 && !isolated[i] && !isolated[i - 1]) {
                impossible = true;
                break;
            }
            if (isolated[i]) {
                if (isolated[i - 1]) {
                    if (segs.back()[2] == p[i] - 1)
                        isolated[i] = false;
                    else if (isolated[i + 1]) {
                        int needed = 1 + (p[i] - segs.back()[2]) % 2;
                        segs.push_back({segs.back()[2] + 1, p[i], min(p[i] + needed, p[i + 1] - 1)});
                    } else
                        segs.push_back({segs.back()[2] + 1, p[i], p[i + 1] - 1});
                } else {
                    if (isolated[i + 1]) {
                        int needed = 1 + (p[i] - p[i - 1]) % 2;
                        segs.push_back({p[i - 1] + 1, p[i], min(p[i] + needed, p[i + 1] - 1)});
                    } else
                        segs.push_back({p[i - 1] + 1, p[i], p[i + 1] - 1});
                }
            }
        }

        moves.clear();
        for (auto i : segs) solve(i);
        if (impossible) cout << "-1\n";
        else {
            cout << moves.size() << '\n';
            while (moves.size()) {
                cout << moves.back() << ' ';
                moves.pop_back();
            }
            cout << '\n';
        }
    }
    return 0;
}
# Verdict Execution time Memory Grader output
1 Runtime error 82 ms 131076 KB Execution killed with signal 9
2 Runtime error 81 ms 131072 KB Execution killed with signal 9
# Verdict Execution time Memory Grader output
1 Runtime error 82 ms 131076 KB Execution killed with signal 9
2 Runtime error 81 ms 131072 KB Execution killed with signal 9
3 Runtime error 80 ms 131076 KB Execution killed with signal 9
4 Runtime error 79 ms 131072 KB Execution killed with signal 9
# Verdict Execution time Memory Grader output
1 Runtime error 77 ms 131076 KB Execution killed with signal 9
2 Correct 2 ms 388 KB Output is correct
# Verdict Execution time Memory Grader output
1 Runtime error 82 ms 131076 KB Execution killed with signal 9
2 Runtime error 81 ms 131072 KB Execution killed with signal 9
3 Runtime error 80 ms 131076 KB Execution killed with signal 9
4 Runtime error 79 ms 131072 KB Execution killed with signal 9
5 Runtime error 83 ms 131076 KB Execution killed with signal 9
6 Runtime error 86 ms 131076 KB Execution killed with signal 9
7 Runtime error 86 ms 131072 KB Execution killed with signal 9
# Verdict Execution time Memory Grader output
1 Runtime error 82 ms 131076 KB Execution killed with signal 9
2 Runtime error 81 ms 131072 KB Execution killed with signal 9
3 Runtime error 80 ms 131076 KB Execution killed with signal 9
4 Runtime error 79 ms 131072 KB Execution killed with signal 9
5 Runtime error 83 ms 131076 KB Execution killed with signal 9
6 Runtime error 86 ms 131076 KB Execution killed with signal 9
7 Runtime error 86 ms 131072 KB Execution killed with signal 9
8 Runtime error 83 ms 131076 KB Execution killed with signal 9
9 Runtime error 80 ms 131076 KB Execution killed with signal 9
10 Runtime error 93 ms 131076 KB Execution killed with signal 9
11 Runtime error 93 ms 131076 KB Execution killed with signal 9