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 <queue>
#include <algorithm>
using namespace std;
typedef pair < int, int > pii;
const int MAX = 300020;
int n, data[MAX*2];
void input(){
scanf("%d", &n);
for(int i = 0; i < 2*n; i++)
scanf("%d", &data[i]);
}
pii upStack[MAX];
int top, status[MAX];
priority_queue < pii > down;
void solve(){
for(int i = 0; i < 2*n; i++){
int now = data[i];
if(status[now] == 0){
status[now] = 1;
upStack[top++] = pii(i, now);
} else if(status[now] == 1){
for(; upStack[top-1].second != now; top--){
status[upStack[top-1].second] = 2;
down.push(upStack[top-1]);
}
top--;
} else {
if(down.top().second != now){
puts("IMPOSSIBLE");
return;
} else
down.pop();
}
}
for(int i = 0; i < 2*n; i++){
if(status[data[i]] == 1) putchar('^');
else putchar('v');
}
puts("");
}
int main(){
input();
solve();
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... |