#include <bits/stdc++.h>
#pragma GCC optimize("unroll-loops")
#pragma GCC optimize("Ofast")
#pragma GCC optimize("-O3")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
using namespace std;
#define pb push_back
#define fst first
#define snd second
#define all(c) (c).begin(), (c).end()
typedef long long ll;
typedef long double ld;
const ll INF64 = 1e18 + 228;
const int INF32 = 1e9 + 1337;
const int MOD = 1e9 + 7;
const ld eps = 1e-7;
const int N = 1e3 + 3;
signed main()
{
ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
int t;
cin >> t;
while(t--)
{
ll n, q;
cin >> n >> q;
vector<ll> a(q);
set<ll> aa;
vector<ll> pref(n, 0);
for(auto& it : a)
{
cin >> it;
it--;
aa.insert(it);
}
for(int i = 0; i < n; i++)
{
pref[i] = aa.count(i);
if(i) pref[i] += pref[i - 1];
}
int lst = -1;
vector< pair<ll, ll> > x;
for(auto& it : a)
{
if(lst + 1 == it)
{
lst = it;
continue;
}
x.pb({it - lst - 1, lst + 1});
lst = it;
}
if(lst != n - 1)
x.pb({n - 1 - lst, lst + 1});
vector<ll> ans;
for(auto& it : x)
{
if(it.fst > 2)
{
ll cnt = (it.fst - 1) / 2;
for(int i = 0; i < cnt; i++)
ans.pb(it.snd + it.fst / 2);
if(it.fst & 1)
it.fst = 1;
else
it.fst = 2;
}
}
bool bad = 0;
for(int i = 1; i < x.size(); i++)
{
if(pref[x[i].snd] - pref[x[i - 1].snd] > 1)
{
bad = 1;
break;
}
ll mn = min(x[i - 1].fst, x[i].fst);
if(x[i - 1].fst > mn)
{
bad = 1;
break;
}
x[i - 1].fst -= mn;
x[i].fst -= mn;
for(int j = 0; j < mn; j++)
{
ans.pb(x[i].snd - 1);
}
}
for(int i = 0; i < x.size(); i++)
bad |= x[i].fst;
if(bad)
cout << "-1\n";
else
{
cout << ans.size() << "\n";
for(auto& it : ans)
cout << it + 1 << " ";
cout << "\n";
}
}
return 0;
}
Compilation message
del13.cpp: In function 'int main()':
del13.cpp:71:26: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for(int i = 1; i < x.size(); i++)
~~^~~~~~~~~~
del13.cpp:91:26: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for(int i = 0; i < x.size(); i++)
~~^~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
3 ms |
376 KB |
Output isn't correct |
2 |
Incorrect |
3 ms |
376 KB |
Output isn't correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
3 ms |
376 KB |
Output isn't correct |
2 |
Incorrect |
3 ms |
376 KB |
Output isn't correct |
3 |
Incorrect |
8 ms |
376 KB |
Output isn't correct |
4 |
Incorrect |
8 ms |
376 KB |
Output isn't correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
11 ms |
632 KB |
Output is correct |
2 |
Correct |
9 ms |
1968 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
3 ms |
376 KB |
Output isn't correct |
2 |
Incorrect |
3 ms |
376 KB |
Output isn't correct |
3 |
Incorrect |
8 ms |
376 KB |
Output isn't correct |
4 |
Incorrect |
8 ms |
376 KB |
Output isn't correct |
5 |
Incorrect |
3 ms |
376 KB |
Output isn't correct |
6 |
Incorrect |
3 ms |
376 KB |
Output isn't correct |
7 |
Incorrect |
3 ms |
376 KB |
Output isn't correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
3 ms |
376 KB |
Output isn't correct |
2 |
Incorrect |
3 ms |
376 KB |
Output isn't correct |
3 |
Incorrect |
8 ms |
376 KB |
Output isn't correct |
4 |
Incorrect |
8 ms |
376 KB |
Output isn't correct |
5 |
Incorrect |
3 ms |
376 KB |
Output isn't correct |
6 |
Incorrect |
3 ms |
376 KB |
Output isn't correct |
7 |
Incorrect |
3 ms |
376 KB |
Output isn't correct |
8 |
Incorrect |
19 ms |
1820 KB |
Output isn't correct |
9 |
Incorrect |
26 ms |
2092 KB |
Output isn't correct |
10 |
Incorrect |
26 ms |
2580 KB |
Output isn't correct |
11 |
Incorrect |
33 ms |
4868 KB |
Output isn't correct |