제출 #96172

#제출 시각아이디문제언어결과실행 시간메모리
96172alextodoranDEL13 (info1cup18_del13)C++14
15 / 100
13 ms1656 KiB
#include <bits/stdc++.h>

#define NM 100002

using namespace std;

int t;

int n, q;

int p[NM];
int x[NM], y[NM];

deque <int> op;

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    cin >> t;
    while(t--)
    {
        cin >> n >> q;
        for(int i = 1; i <= q; i++)
            cin >> p[i];
        p[q + 1] = n + 1;
        while(!op.empty())
            op.pop_front();
        for(int i = 0; i <= q; i++)
            x[i] = y[i] = p[i + 1] - p[i] - 1;
        for(int i = 1; i <= q; i++)
            while(x[i] && x[i - 1])
            {
                x[i]--;
                x[i - 1]--;
                op.push_back(p[i]);
            }
        for(int i = 0; i <= q; i++)
        {
            if(y[i] - x[i] == 0)
                continue;
            int mid = p[i] + (y[i] + 1) / 2;
            while(x[i] > 1)
            {
                op.push_front(mid);
                x[i] -= 2;
            }
        }
        bool ok = 1;
        for(int i = 0; i <= q; i++)
            if(x[i] > 0)
            {
                ok = 0;
                break;
            }
        if(ok)
        {
            cout << op.size() << "\n";
            while(!op.empty())
            {
                cout << op.front() << " ";
                op.pop_front();
            }
            cout << "\n";
        }
        else
            cout << "-1\n";
    }
    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...