#include<bits/stdc++.h>
#define pb emplace_back
#define AI(i) begin(i), end(i)
using namespace std;
using ll = long long;
#ifdef KEV
#define DE(args...) kout("[ " + string(#args) + " ] : ", args)
void kout() { cerr << endl; }
template<class T, class ...U>
void kout(T a, U ...b) { cerr << a << ' ', kout(b...); }
void debug(auto L, auto R) { while (L != R) cerr << *L << " \n"[next(L) == R], ++L; }
#else
#define debug(...) 0
#define DE(...) 0
#endif
const int MAX_N = 300010;
int len, m, p[MAX_N];
bool valid() {
DE(len, m);
if ((len ^ m) & 1)
return false;
++m;
vector<int> dis;
for (int i = 1;i <= m;++i)
dis.pb(p[i]-p[i-1]-1);
vector<bool> dp{true, false, false};
auto ref = [&](int v) {
return v&1 ? 1 : min(2, v);
};
auto G = [&](int ind) {
return ind >= m || ind < 0 ? 0 : dis[ind];
};
debug(AI(dis));
int sum = 0;
for (int u : dis) {
vector<bool> ne{false, false, false};
if (u == 0) {
if (!dp[0]) return false;
dp = {true, false, false};
continue;
}
if (dp[0]) {
ne[ ref(u) ] = true;
if (u&1)
ne[1] = true;
}
if (dp[1]) {
if (u&1) {
ne[0] = true;
ne[2] = u > 2;
}
else {
ne[1] = true;
}
}
if (dp[2]) {
if (u&1) {
if (u > 2)
ne[1] = true;
}
else {
ne[0] = true;
ne[2] = u > 2;
}
}
swap(dp, ne);
}
return dp[0];
}
void solve() {
cin >> len >> m;
for (int i = 1;i <= m;++i)
cin >> p[i];
//cerr << "\n\n";
p[m+1] = len+1;
if (!valid())
return cout << -1 << '\n', void();
cout << 0 << '\n' << '\n' ;
}
int32_t main() {
ios_base::sync_with_stdio(0), cin.tie(0);
int T;
cin >> T;
while (T--)
solve();
}
Compilation message
del13.cpp: In function 'bool valid()':
del13.cpp:14:17: warning: statement has no effect [-Wunused-value]
14 | #define DE(...) 0
| ^
del13.cpp:19:2: note: in expansion of macro 'DE'
19 | DE(len, m);
| ^~
del13.cpp:13:20: warning: statement has no effect [-Wunused-value]
13 | #define debug(...) 0
| ^
del13.cpp:33:2: note: in expansion of macro 'debug'
33 | debug(AI(dis));
| ^~~~~
del13.cpp:30:7: warning: variable 'G' set but not used [-Wunused-but-set-variable]
30 | auto G = [&](int ind) {
| ^
del13.cpp:34:6: warning: unused variable 'sum' [-Wunused-variable]
34 | int sum = 0;
| ^~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
384 KB |
Output is partially correct |
2 |
Correct |
1 ms |
384 KB |
Output is partially correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
384 KB |
Output is partially correct |
2 |
Correct |
1 ms |
384 KB |
Output is partially correct |
3 |
Incorrect |
4 ms |
384 KB |
Output isn't correct |
4 |
Incorrect |
6 ms |
384 KB |
Output isn't correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
512 KB |
Output is partially correct |
2 |
Correct |
2 ms |
384 KB |
Output is partially correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
384 KB |
Output is partially correct |
2 |
Correct |
1 ms |
384 KB |
Output is partially correct |
3 |
Incorrect |
4 ms |
384 KB |
Output isn't correct |
4 |
Incorrect |
6 ms |
384 KB |
Output isn't correct |
5 |
Incorrect |
1 ms |
384 KB |
Output isn't correct |
6 |
Incorrect |
1 ms |
384 KB |
Output isn't correct |
7 |
Incorrect |
1 ms |
512 KB |
Output isn't correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
384 KB |
Output is partially correct |
2 |
Correct |
1 ms |
384 KB |
Output is partially correct |
3 |
Incorrect |
4 ms |
384 KB |
Output isn't correct |
4 |
Incorrect |
6 ms |
384 KB |
Output isn't correct |
5 |
Incorrect |
1 ms |
384 KB |
Output isn't correct |
6 |
Incorrect |
1 ms |
384 KB |
Output isn't correct |
7 |
Incorrect |
1 ms |
512 KB |
Output isn't correct |
8 |
Incorrect |
6 ms |
384 KB |
Output isn't correct |
9 |
Incorrect |
10 ms |
640 KB |
Output isn't correct |
10 |
Incorrect |
6 ms |
684 KB |
Output isn't correct |
11 |
Incorrect |
6 ms |
896 KB |
Output isn't correct |