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<vector>
#define top(v) (v.size()?v[v.size()-1]:2*n)
using namespace std;
int n, ba[600060], ix2[300030];
bool chk[300030];
vector<int> stk[2];
int main(){
int i;
scanf("%d", &n);
for(i=0; i<2*n; i++){
scanf("%d", &ba[i]);
ix2[ba[i]]=i;
}
for(i=0; i<2*n; i++){
if(ix2[ba[i]]==i)stk[chk[ba[i]]].pop_back();
else{
if(ix2[ba[i]]<top(stk[0]))chk[ba[i]]=0, stk[0].push_back(ix2[ba[i]]);
else if(ix2[ba[i]]<top(stk[1]))chk[ba[i]]=1, stk[1].push_back(ix2[ba[i]]);
else{
puts("IMPOSSIBLE");
return 0;
}
}
}
for(i=0; i<2*n; i++)printf("%c", chk[ba[i]]?'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... |