-
Notifications
You must be signed in to change notification settings - Fork 59
/
Copy pathstiva1.cpp
56 lines (47 loc) · 1.31 KB
/
stiva1.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
# include <cstdio>
# include <cstring>
# include <algorithm>
# define inf 2000000005
# define NR 50005
using namespace std;
int i,j,n,m,minn,maxx,maxst,VV,ST,P,ok,poz;
int a[NR], st[NR], perm[NR], ap[NR];
int main ()
{
freopen ("stiva1.in", "r", stdin);
freopen ("stiva1.out", "w", stdout);
scanf ("%d", &n);
for (int t=1; t<=5; ++t) {
minn=inf;
for (i=1; i<=n; ++i) {
scanf ("%d", &a[i]);
minn=min(minn, a[i]);
}
maxst=0; maxx=0; memset (ap, 0, sizeof(ap));
for (i=1; i<=n; ++i) {
a[i]=a[i]-minn+1;
ap[a[i]]=1;
if (! ap[1]) maxst=max(maxst, a[i]);
maxx=max(maxx, a[i]);
}
VV=0; memset (perm, 0, sizeof(perm));
for (i=1; i<=maxst; ++i)
if (! ap[i]) perm[++VV]=i;
for (i=1; i<=n; ++i)
perm[++VV]=a[i];
for (i=maxx; i>=1; --i)
if (! ap[i]) perm[++VV]=i;
// acum simulez sa verific
ok=1; ST=0; memset (st, 0, sizeof(st)); poz=1; P=0;
for (i=1; i<=2*maxx && ok; ++i) {
if (st[ST]==perm[poz]) {st[ST]=0; --ST; ++poz;}
else if (P!=maxx) {
++P;
st[++ST]=P;
}
else ok=0;
}
printf ("%d\n", ok);
}
return 0;
}