-
Notifications
You must be signed in to change notification settings - Fork 0
/
dontknowwhat.cpp
85 lines (85 loc) · 1.75 KB
/
dontknowwhat.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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
#include <iostream>
#include <cstdlib>
#include <cstring>
#include <vector>
#include <queue>
#include <stack>
#define MAXN 1005
#define INF 0x7f7f7f7f
#define B 1
#define min(a,b) (a)<(b)?(a):(b)
using namespace std;
int n;
int a[MAXN],f[MAXN];
vector<int> e[MAXN];
int color[MAXN];
stack<int> s1,s2;
void bfs(int s)
{
queue<int> q;
q.push(s);
color[s]=B;
while(!q.empty())
{
int now=q.front();
for(int i=0; i<e[now].size(); ++i)
{
int next=e[now][i];
if(color[next]==-1)
{
color[next]=color[now]^1;
q.push(next);
}
else if(color[next]!=(color[now]^1))
{
cout<<0;
exit(0);
}
}
q.pop();
}
}
int main()
{
memset(color,-1,sizeof(color));
cin>>n;
for(int i=1; i<=n; ++i)cin>>a[i];
f[n+1]=INF;
for(int i=n; i>=1; --i)f[i]=min(f[i+1],a[i]);
for(int i=1; i<=n; ++i)
for(int j=i+1; j<=n; ++j)
if(a[i]>f[j+1] && a[i]<a[j])
e[i].push_back(j),e[j].push_back(i);
for(int i=1; i<=n; ++i)
if(color[i]==-1)
bfs(i);
int cnt=1;
for(int i=1; i<=n; ++i)
{
if(color[i]==B)
{
s1.push(a[i]);
cout<<"a ";
}
else
{
s2.push(a[i]);
cout<<"c ";
}
while((!s1.empty() && s1.top()==cnt) || (!s2.empty() && s2.top()==cnt))
{
if(!s1.empty() && s1.top()==cnt)
{
s1.pop();
cout<<"b ";
}
else
{
s2.pop();
cout<<"d ";
}
++cnt;
}
}
return 0;
}