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>
int N, A[600001], Check[300001], S[600001], Top;
int M, Down[600001], Ans[300001];
int main(void) {
int i, j;
scanf("%d",&N);
for(i=1 ; i<=2*N ; i++)
scanf("%d",&A[i]);
for(i=1 ; i<=2*N ; i++) {
if(Check[A[i]]>0) {
Ans[A[i]]=1;
for(j=Check[A[i]]+1 ; j<=Top ; j++) {
Check[S[j]]=-1;
Down[++M]=S[j];
}
Top=Check[A[i]]-1;
Check[A[i]]=0;
}
else if(Check[A[i]]==0) {
S[++Top]=A[i];
Check[A[i]]=Top;
}
else {
Check[A[i]]=0;
Down[++M]=A[i];
}
}
Top=0;
for(i=1 ; i<=M ; i++) {
if(Check[Down[i]]) {
if(S[Top]!=Down[i]) {
printf("IMPOSSIBLE");
return 0;
}
Top--;
}
else {
Check[Down[i]]=1;
S[++Top]=Down[i];
}
}
for(i=1 ; i<=2*N ; i++) {
if(Ans[A[i]])
printf("^");
else
printf("v");
}
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... |