#include <bits/stdc++.h>
using namespace std;
#define lli long long int
#define mp make_pair
#define eb emplace_back
#define pb push_back
#define X first
#define Y second
#define pii pair<int,int>
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
void abc() {cout << endl;}
template <typename T, typename ...U> void abc(T i, U ...j) {
cout << i << ' ', abc(j...);
}
template <typename T> void printv(T l, T r) {
for (; l != r; ++l)
cout << *l << " \n"[l + 1 == r];
}
#ifdef Doludu
#define test(x...) abc("[" + string(#x) + "]", x);
#else
#define test(x...) void(0);
#endif
const int N = 1001;
int main () {
ios::sync_with_stdio(false);
cin.tie(0);
int t;
cin >> t;
while (t--) {
int n, m;
cin >> n >> m;
vector <int> a(m + 1, 0);
vector <int> rem;
for (int i = 1; i <= m; ++i) {
cin >> a[i];
rem.pb(a[i] - a[i - 1] - 1);
}
rem.pb(n - a[m]);
vector <int> move, fr;
vector <vector <int>> dp(m + 1, vector <int>(3, false));
dp[0][0] = true;
for (int i = 0; i < m; ++i) for (int f = 0; f <= 2; ++f) if (dp[i][f]) {
int left = rem[i] - f;
if (left < 0) {
continue;
}
if (left == 0) {
dp[i + 1][0] = true;
continue;
}
if (left & 1) {
// optimal 1
dp[i + 1][1] = true;
}
if (left & 1 ^ 1) {
if (f) {
// optimal 0 or 2
dp[i + 1][0] = dp[i + 1][2] = true;
} else {
// must 2
dp[i + 1][2] = true;
}
}
}
bool is = false;
for (int i = 0; i <= 2; ++i)
is |= dp[m][i] && rem[m] >= i;
if (is) {
cout << 0 << endl;
cout << endl;
} else {
cout << -1 << endl;
}
}
}
Compilation message
del13.cpp: In function 'int main()':
del13.cpp:58:13: warning: suggest parentheses around arithmetic in operand of '^' [-Wparentheses]
58 | if (left & 1 ^ 1) {
| ~~~~~^~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
2 ms |
204 KB |
Output isn't correct |
2 |
Incorrect |
2 ms |
204 KB |
Output isn't correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
2 ms |
204 KB |
Output isn't correct |
2 |
Incorrect |
2 ms |
204 KB |
Output isn't correct |
3 |
Incorrect |
13 ms |
204 KB |
Output isn't correct |
4 |
Incorrect |
12 ms |
324 KB |
Output isn't correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
4 ms |
332 KB |
Output isn't correct |
2 |
Incorrect |
2 ms |
460 KB |
Output isn't correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
2 ms |
204 KB |
Output isn't correct |
2 |
Incorrect |
2 ms |
204 KB |
Output isn't correct |
3 |
Incorrect |
13 ms |
204 KB |
Output isn't correct |
4 |
Incorrect |
12 ms |
324 KB |
Output isn't correct |
5 |
Correct |
1 ms |
204 KB |
Output is partially correct |
6 |
Incorrect |
1 ms |
204 KB |
Output isn't correct |
7 |
Incorrect |
1 ms |
204 KB |
Output isn't correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
2 ms |
204 KB |
Output isn't correct |
2 |
Incorrect |
2 ms |
204 KB |
Output isn't correct |
3 |
Incorrect |
13 ms |
204 KB |
Output isn't correct |
4 |
Incorrect |
12 ms |
324 KB |
Output isn't correct |
5 |
Correct |
1 ms |
204 KB |
Output is partially correct |
6 |
Incorrect |
1 ms |
204 KB |
Output isn't correct |
7 |
Incorrect |
1 ms |
204 KB |
Output isn't correct |
8 |
Correct |
10 ms |
716 KB |
Output is partially correct |
9 |
Correct |
8 ms |
1612 KB |
Output is partially correct |
10 |
Correct |
8 ms |
1676 KB |
Output is partially correct |
11 |
Correct |
7 ms |
3024 KB |
Output is partially correct |