#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, inf = 1e7;
int len, m, p[MAX_N], dp_max[MAX_N], dp_min[MAX_N], dis[MAX_N];
bool valid() {
DE(len, m);
if ((len ^ m++) & 1)
return false;
for (int i = 1;i <= m;++i)
dis[i] = p[i] - p[i-1] - 1;
dp_max[0] = dp_min[0] = 0;
DE(len, m);
debug(dis+1, dis+m+1);
for (int i = 1;i <= m;++i) {
int u = dp_max[i-1], d = dp_min[i-1], h = dis[i];
assert((u^d) % 2 == 0);
if (d > h)
return false;
if (h == 0) {
dp_max[i] = dp_min[i] = 0;
continue;
}
if (u == 0) {
dp_max[i] = h, dp_min[i] = h&1 ? 1 : 2;
continue;
}
dp_max[i] = h - d;
if (h % 2 == d % 2)
dp_min[i] = 0;
else
dp_min[i] = 1;
if (dp_max[i] < dp_min[i])
return false;
}
for (int i = 1;i <= m;++i)
DE(i, dp_min[i], dp_max[i]);
return dp_min[m] == 0;
}
void solve() {
cin >> len >> m;
for (int i = 1;i <= m;++i)
cin >> p[i];
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:14:17: warning: statement has no effect [-Wunused-value]
14 | #define DE(...) 0
| ^
del13.cpp:26:2: note: in expansion of macro 'DE'
26 | DE(len, m);
| ^~
del13.cpp:13:20: warning: statement has no effect [-Wunused-value]
13 | #define debug(...) 0
| ^
del13.cpp:27:2: note: in expansion of macro 'debug'
27 | debug(dis+1, dis+m+1);
| ^~~~~
del13.cpp:14:17: warning: statement has no effect [-Wunused-value]
14 | #define DE(...) 0
| ^
del13.cpp:55:3: note: in expansion of macro 'DE'
55 | DE(i, dp_min[i], dp_max[i]);
| ^~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
384 KB |
Output is partially correct |
2 |
Correct |
1 ms |
384 KB |
Output is partially correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
384 KB |
Output is partially correct |
2 |
Correct |
1 ms |
384 KB |
Output is partially correct |
3 |
Correct |
3 ms |
384 KB |
Output is partially correct |
4 |
Correct |
3 ms |
384 KB |
Output is partially correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
384 KB |
Output is partially correct |
2 |
Correct |
2 ms |
384 KB |
Output is partially correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
384 KB |
Output is partially correct |
2 |
Correct |
1 ms |
384 KB |
Output is partially correct |
3 |
Correct |
3 ms |
384 KB |
Output is partially correct |
4 |
Correct |
3 ms |
384 KB |
Output is partially correct |
5 |
Correct |
1 ms |
384 KB |
Output is partially correct |
6 |
Correct |
1 ms |
384 KB |
Output is partially correct |
7 |
Correct |
1 ms |
384 KB |
Output is partially correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
384 KB |
Output is partially correct |
2 |
Correct |
1 ms |
384 KB |
Output is partially correct |
3 |
Correct |
3 ms |
384 KB |
Output is partially correct |
4 |
Correct |
3 ms |
384 KB |
Output is partially correct |
5 |
Correct |
1 ms |
384 KB |
Output is partially correct |
6 |
Correct |
1 ms |
384 KB |
Output is partially correct |
7 |
Correct |
1 ms |
384 KB |
Output is partially correct |
8 |
Correct |
5 ms |
640 KB |
Output is partially correct |
9 |
Correct |
6 ms |
896 KB |
Output is partially correct |
10 |
Correct |
5 ms |
896 KB |
Output is partially correct |
11 |
Correct |
5 ms |
1280 KB |
Output is partially correct |