-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathA_Ahahahahahahahaha.cpp
51 lines (49 loc) · 1.02 KB
/
A_Ahahahahahahahaha.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
#include <iostream>
#include <bits/stdc++.h>
#define fastio ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define ll long long
using namespace std;
int main() {
fastio;
int t;cin>>t;
while(t--){
int num;
cin>>num;
int a[num];
vector<int>v;
for(int i=0;i<num;i++){
cin>>a[i];
}
int ones=0;
int size=0;
for(int i=0;i<num;i++){
if(a[i]==1){
ones++;
}
else if(a[i]==0){
if(ones>0) {
v.push_back(ones-ones%2);
size+=(ones-ones%2);
}
ones=0;
v.push_back(-1);
size++;
}
}
if(ones>0) {
v.push_back(ones-ones%2);
size+=(ones-ones%2);
}
cout<<size<<endl;
for(int i=0;i<v.size();i++){
if(v[i]==-1) cout<<"0 ";
else{
for(int j=0;j<v[i];j++){
cout<<"1 ";
}
}
}
cout<<endl;
}
return 0;
}