-
Notifications
You must be signed in to change notification settings - Fork 59
/
Copy pathivv.cpp
68 lines (55 loc) · 1.35 KB
/
ivv.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
67
68
# include <cstdio>
# include <algorithm>
# include <cstring>
# define NR 10005
using namespace std;
int i,j,n,m,x,y;
int a[NR], A[3][NR], l[3][NR], ok[NR], OK[NR];
void adunare (int a[], int b[], int val) {
a[0]=max(a[0], b[0]);
int t=val;
for (int i=1; i<=a[0]; ++i) {
t=t + a[i] + b[i];
a[i]=t%10;
t=t/10;
}
while (t) a[++a[0]]=t%10, t=t/10;
}
void afisare (int k) {
for (int i=l[k][0]; i>=1; --i)
printf ("%d", l[k][i]);
}
int main ()
{
freopen ("ivv.in", "r", stdin);
freopen ("ivv.out", "w", stdout);
scanf ("%d", &n);
for (i=1; i<=n; ++i)
scanf ("%d", &a[i]);
// preprocesam aparitiile
for (i=1; i<=n; ++i) {
OK[i]=ok[a[i]];
ok[a[i]]=1;
}
l[0][0]=l[0][1]=1;
l[1][0]=l[1][1]=1;
for (i=n-1; i>=1; --i) {
adunare (A[0], l[0], 0);
adunare (A[1], l[1], 0);
if (a[i]!=a[i+1]) {
memset (l[a[i]], 0, sizeof(l[a[i]]));
adunare (l[a[i]], A[1-a[i]], 1);
adunare (l[1-a[i]], A[a[i]], 0);
}
else {
if (OK[i]) adunare (l[a[i]], l[1-a[i]], 0);
memset (l[1-a[i]], 0, sizeof(l[1-a[i]]));
adunare (l[1-a[i]], A[a[i]], 1);
}
printf ("%d : ", i);
afisare (a[i]);
printf ("\n");
}
afisare (a[1]);
return 0;
}