This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <stdio.h>
#include <stack>
std::stack<int> s1;
std::stack<int> s2;
int arr[600001];
int idx[300001][2];
char res[600002];
int main()
{
int n,x,i,j;
scanf("%d",&n);
for(i=1;i<=2*n;i++)
{
scanf("%d",&arr[i]);
idx[arr[i]][!!idx[arr[i]][0]]=i;
}
s1.push(2*n+1);
s2.push(2*n+1);
for(i=1;i<=2*n;i++)
{
if(s1.top()==i)
s1.pop();
if(s2.top()==i)
s2.pop();
if(res[i])
continue;
x=idx[arr[i]][1];
if(x<s1.top())
{
s1.push(x);
res[i]=res[x]='^';
}
else if(x<s2.top())
{
s2.push(x);
res[i]=res[x]='v';
}
else
{
printf("IMPOSSIBLE");
return 0;
}
}
printf("%s",res+1);
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |