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;
#define finish(x) return cout << x << endl, 0
#define ll long long
void solve(){
int n, k;
cin >> n >> k;
vector <int> a;
for(int i = 0 ; i < k ; i++){
int x;
cin >> x;
a.push_back(x);
}
a.push_back(0);
a.push_back(n + 1);
sort(a.begin(), a.end());
vector <int> b;
for(int i = 1 ; i < (int)a.size() ; i++)
b.push_back(a[i] - a[i - 1] - 1);
for(auto &i : b)
while(i >= 3)
i -= 2;
for(int i = 0 ; i < (int)b.size() ; i++){
if(b[i] == 0) continue;
if(i + 1 >= (int)b.size() || b[i] != b[i + 1]){
cout << -1 << endl;
return;
}
i++;
}
cout << 0 << endl << endl;
}
int main(){
ios_base::sync_with_stdio(0);
cin.tie(0);
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... |