답안 #494739

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
494739 2021-12-16T04:57:44 Z syl123456 DEL13 (info1cup18_del13) C++17
0 / 100
18 ms 1512 KB
#pragma GCC diagnostic ignored "-Wunused-parameter"
#pragma GCC diagnostic ignored "-Wunused-variable"
#pragma GCC diagnostic ignored "-Wparentheses"
#include <bits/stdc++.h>
#define all(i) (i).begin(), (i).end()
#define random random_device rd; mt19937 rng(rd())
using namespace std;
template<typename T1, typename T2>
ostream& operator << (ostream &i, pair<T1, T2> j) {
    return i << j.first << ' ' << j.second;
}
template<typename T>
ostream& operator << (ostream &i, vector<T> j) {
    i << '{' << j.size() << ':';
    for (T ii : j) i << ' ' << ii;
    return i << '}';
}
void Debug(bool _split) {}
template<typename T1, typename ...T2>
void Debug(bool _split, T1 x, T2 ...args) {
    if (_split)
        cerr << ", ";
    cerr << x, Debug(true, args...);
}
template<typename T>
void Debuga(T *i, int n) {
    cerr << '[';
    for (int j = 0; j < n; ++j) cerr << i[j] << " ]"[j == n - 1];
    cerr << endl;
}
#ifdef SYL
#define debug(args...) cerr << "Line(" << __LINE__ << ") -> [" << #args << "] is [", Debug(false, args), cerr << ']' << endl
#define debuga(i) cerr << "Line(" << __LINE__ << ") -> [" << #i << "] is ", Debuga(i, sizeof(i) / sizeof(typeid(*i).name()))
#else
#define debug(args...) void(0)
#define debuga(i) void(0)
#endif
typedef long long ll;
typedef pair<int, int> pi;
const int inf = 0x3f3f3f3f, lg = 20;
const ll mod = 1e9 + 7, INF = 0x3f3f3f3f3f3f3f3f;

signed main() {
    ios::sync_with_stdio(0), cin.tie(0);
    int t;
    cin >> t;
    while (t--) {
        int n, m;
        cin >> n >> m;
        int a[m + 1];
        for (int i = 0; i < m; ++i)
            cin >> a[i], --a[i];
        a[m] = n;
        if (n == m)
            cout << "0\n\n";
        if (m == 0 || n - m & 1) {
            cout << "-1\n";
            continue;
        }
        ++m;
        int dp[m];
        bool is[m], is2[m], fail = false;
        dp[0] = a[0];
        is[0] = a[0] == 0;
        is2[0] = false;
        for (int i = 1; i < m; ++i) {
            int x = a[i] - 1 - a[i - 1];
            if (is[i - 1])
                dp[i] = x;
            else
                dp[i] = x - (dp[i - 1] & 1 ? 1 : 2);
            if (dp[i] < 0) {
                fail = true;
                break;
            }
            if (dp[i] == 0)
                is[i] = true, is2[i] = false;
            else if (dp[i] & 1)
                is[i] = false;
            else if (dp[i] < x)
                is[i] = true, is2[i] = true;
            else if (is2[i - 1])
                is[i] = true, is2[i] = true;
            else
                is[i] = false;
        }
        if (fail || !is[m - 1]) {
            cout << "-1\n";
            continue;
        }
        cout << (n - m + 1 >> 1) << '\n';
        int cnt[m];
        cnt[m - 1] = 0;
        for (int i = m - 1; i; --i) {
            int x = a[i] - 1 - a[i - 1];
            if (!cnt[i]) {
                if (!x)
                    cnt[i - 1] = 0;
                else
                    cnt[i - 1] = x & 1 ? 1 : 2;
            }
            else {
                x -= cnt[i];
                if (is[i - 1])
                    cnt[i - 1] = 0;
                else
                    cnt[i - 1] = x & 1 ? 1 : 2;
            }
        }
        for (int i = 0; i < m; ++i) {
            int x = i ? a[i - 1] + 3 : 2;
            int tmp = a[i] - 1 - (i ? a[i - 1] : -1);
            tmp -= cnt[i] + (i ? cnt[i - 1] : 0);
            for (int j = 0; j < tmp >> 1; ++j)
                cout << x << ' ', x += 2;
        }
        for (int i = 0; i < m; ++i)
            for (int j = 0; j < cnt[i]; ++j)
                cout << a[i] + 1 << ' ';
        cout << '\n';
    }
}
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 344 KB Output isn't correct
2 Incorrect 1 ms 204 KB Output isn't correct
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 344 KB Output isn't correct
2 Incorrect 1 ms 204 KB Output isn't correct
3 Correct 4 ms 332 KB Output is correct
4 Correct 4 ms 332 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Incorrect 9 ms 460 KB Output isn't correct
2 Incorrect 2 ms 332 KB Output isn't correct
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 344 KB Output isn't correct
2 Incorrect 1 ms 204 KB Output isn't correct
3 Correct 4 ms 332 KB Output is correct
4 Correct 4 ms 332 KB Output is correct
5 Incorrect 2 ms 204 KB Output isn't correct
6 Incorrect 1 ms 204 KB Output isn't correct
7 Incorrect 1 ms 316 KB Output isn't correct
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 344 KB Output isn't correct
2 Incorrect 1 ms 204 KB Output isn't correct
3 Correct 4 ms 332 KB Output is correct
4 Correct 4 ms 332 KB Output is correct
5 Incorrect 2 ms 204 KB Output isn't correct
6 Incorrect 1 ms 204 KB Output isn't correct
7 Incorrect 1 ms 316 KB Output isn't correct
8 Correct 6 ms 728 KB Output is correct
9 Correct 11 ms 844 KB Output is correct
10 Incorrect 6 ms 844 KB Integer 88 violates the range [1, 87]
11 Correct 18 ms 1512 KB Output is correct