This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
using namespace std;
const int N = 1e5+1;
int d[N], rm[N];
void solve() {
int n, q; cin>>n>>q;
for (int i=0; i<=n; ++i) d[i]=rm[i]=0;
vector<int> v;
for (int i=0; i<q; ++i) {
int p; cin>>p;
v.push_back(p);
}
for (int i=1; i<q; ++i) d[i]=v[i]-v[i-1]-1;
for (int i=1; i<q-1; ++i) {
if (d[i] <= 0) continue;
if (d[i]%2) --d[i], --d[i+1], ++rm[i], ++rm[i+1];
else if (rm[i] == 0) d[i]-=2, d[i+1]-=2, rm[i]+=2, rm[i+1]+=2;
}
bool ok=true;
for (int i=1; i<q; ++i) {
if ((d[i]&1) || d[i] < 0) ok=false;
if (d[i]%2 == 0 && d[i] > 0 && rm[i] == 0) ok=false;
}
if (!ok) {
cout<<-1<<"\n";
return;
} else {
cout<<0<<"\n\n";
}
}
int main() {
int t; cin>>t;
while (t--) solve();
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |