# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
360096 |
2021-01-27T12:54:41 Z |
Mlxa |
DEL13 (info1cup18_del13) |
C++14 |
|
14 ms |
1716 KB |
#include <bits/stdc++.h>
using namespace std;
const int mxN=1e5;
int t, n, q, a[mxN+2], dp[mxN+2][3];
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
cin >> t;
while(t--) {
cin >> n >> q;
for(int i=1; i<=q; ++i)
cin >> a[i];
a[q+1]=n+1;
memset(dp, -1, (q+2)*sizeof(dp[0]));
dp[0][0]=-2;
for(int i=0; i<=q; ++i) {
for(int j=0; j<3; ++j) {
if(dp[i][j]==-1||a[i+1]-a[i]-1-j<0)
continue;
if((a[i+1]-a[i]-1-j)&1^1) {
if(!(a[i+1]-a[i]-1-j)||j)
dp[i+1][0]=j;
if(a[i+1]-a[i]-1-j)
dp[i+1][2]=j;
} else
dp[i+1][1]=j;
}
}
if(dp[q+1][0]==-1) {
cout << "-1\n";
continue;
}
vector<int> ans;
for(int i=q+1, j=0; i--; j=dp[i+1][j])
for(int k=a[i+1]-a[i]-1-j-dp[i+1][j]; k; k-=2)
ans.push_back((a[i]+a[i+1])/2);
for(int i=q, j=0; ~i; j=dp[i+1][j], --i)
for(int k=j; k; --k)
ans.push_back(a[i+1]);
cout << ans.size() << "\n";
for(int ai : ans)
cout << ai << " ";
cout << "\n";
}
}
Compilation message
del13.cpp: In function 'int main()':
del13.cpp:23:25: warning: suggest parentheses around arithmetic in operand of '^' [-Wparentheses]
23 | if((a[i+1]-a[i]-1-j)&1^1) {
| ~~~~~~~~~~~~~~~~~^~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
364 KB |
Output is correct |
2 |
Correct |
1 ms |
364 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
364 KB |
Output is correct |
2 |
Correct |
1 ms |
364 KB |
Output is correct |
3 |
Correct |
4 ms |
364 KB |
Output is correct |
4 |
Correct |
4 ms |
364 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
492 KB |
Output is correct |
2 |
Correct |
1 ms |
364 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
364 KB |
Output is correct |
2 |
Correct |
1 ms |
364 KB |
Output is correct |
3 |
Correct |
4 ms |
364 KB |
Output is correct |
4 |
Correct |
4 ms |
364 KB |
Output is correct |
5 |
Correct |
1 ms |
364 KB |
Output is correct |
6 |
Correct |
1 ms |
364 KB |
Output is correct |
7 |
Correct |
1 ms |
364 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
364 KB |
Output is correct |
2 |
Correct |
1 ms |
364 KB |
Output is correct |
3 |
Correct |
4 ms |
364 KB |
Output is correct |
4 |
Correct |
4 ms |
364 KB |
Output is correct |
5 |
Correct |
1 ms |
364 KB |
Output is correct |
6 |
Correct |
1 ms |
364 KB |
Output is correct |
7 |
Correct |
1 ms |
364 KB |
Output is correct |
8 |
Correct |
7 ms |
620 KB |
Output is correct |
9 |
Correct |
8 ms |
748 KB |
Output is correct |
10 |
Correct |
7 ms |
1004 KB |
Output is correct |
11 |
Correct |
14 ms |
1716 KB |
Output is correct |