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 <cstdio>
#include <stack>
using namespace std;
int n,a[600005];
int lp[300005], rp[300005];
char str[600005];
stack<int> up, dn;
int main(){
scanf("%d",&n);
for (int i=1; i<=2*n; i++) {
scanf("%d",&a[i]);
if(lp[a[i]] == 0) lp[a[i]] = i;
else rp[a[i]] = i;
}
for (int i=1; i<=2*n; i++) {
if(i == rp[a[i]]){
if(str[lp[a[i]] - 1] == '^') up.pop(), str[i-1] = '^';
else dn.pop(), str[i-1] = 'v';
}
else{
int up_cost = up.empty() ? 1e9 : rp[up.top()];
int dn_cost = dn.empty() ? 1e9 : rp[dn.top()];
int my_cost = rp[a[i]];
if(up_cost <= dn_cost){
if(my_cost < up_cost){
up.push(a[i]);
str[i-1] = '^';
}
else if(my_cost < dn_cost){
dn.push(a[i]);
str[i-1] = 'v';
}
else{
puts("IMPOSSIBLE");
return 0;
}
}
else{
if(my_cost < dn_cost){
dn.push(a[i]);
str[i-1] = 'v';
}
else if(my_cost < up_cost){
up.push(a[i]);
str[i-1] = '^';
}
else{
puts("IMPOSSIBLE");
return 0;
}
}
}
}
puts(str);
}
# | 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... |