-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathmortal.cpp
66 lines (61 loc) · 1.31 KB
/
mortal.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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
#include <bits/stdc++.h>
#define fastio \
ios_base::sync_with_stdio(false); \
cin.tie(NULL)
#define endl "\n"
#define llu unsigned long long int
#define ll long long int
#define fore(i, n) for(auto i = 0; i < n ; i++)
#define forb(i, n) for(auto i = n-1; i >= 0; i++)
#define pair(k, z) pair<k, z>
#define vec(k) vector<k>
#define map(k, z) map<k, z>
#define set(k) set<k>
#define gcd(a, b) __gcd(a,b)
#define lcm(a,b) a*b/__gcd(a,b)
#define pb push_back
#define ins insert
using namespace std;
int main()
{
fastio;
int t;
cin >> t;
while(t--)
{
ll n, x;
ll an = 0, f = 1, i;
cin >> n;
vec(ll) a;
ll c = 0;
for(ll i = 0; i < n; i++)
{
cin >> x;
a.pb(x);
}
if(n == 1)
{
if(a[0] == 1)
cout << '1' << "\n";
else
cout << "0\n";
}
else
{
if(a[0] == 1)
an = 1;
for(i = 1; i < n; i++)
{
if(a[i] == 1)
c++;
else
{
an = c/3 + an;
c = 0;
}
}
cout << an + c/3<< "\n";
}
}
return 0;
}