답안 #98339

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
98339 2019-02-22T15:49:05 Z tmwilliamlin168 DEL13 (info1cup18_del13) C++14
100 / 100
17 ms 1988 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, j=0; ~i; j=dp[i+1][j], --i)
			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]
     if((a[i+1]-a[i]-1-j)&1^1) {
        ~~~~~~~~~~~~~~~~~^~
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 384 KB Output is correct
2 Correct 4 ms 384 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 384 KB Output is correct
2 Correct 4 ms 384 KB Output is correct
3 Correct 7 ms 484 KB Output is correct
4 Correct 6 ms 512 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 9 ms 640 KB Output is correct
2 Correct 2 ms 512 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 384 KB Output is correct
2 Correct 4 ms 384 KB Output is correct
3 Correct 7 ms 484 KB Output is correct
4 Correct 6 ms 512 KB Output is correct
5 Correct 0 ms 384 KB Output is correct
6 Correct 3 ms 384 KB Output is correct
7 Correct 6 ms 384 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 384 KB Output is correct
2 Correct 4 ms 384 KB Output is correct
3 Correct 7 ms 484 KB Output is correct
4 Correct 6 ms 512 KB Output is correct
5 Correct 0 ms 384 KB Output is correct
6 Correct 3 ms 384 KB Output is correct
7 Correct 6 ms 384 KB Output is correct
8 Correct 9 ms 868 KB Output is correct
9 Correct 10 ms 1024 KB Output is correct
10 Correct 11 ms 1152 KB Output is correct
11 Correct 17 ms 1988 KB Output is correct