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 <queue>
int n,s[300001],e[300001],c[300001];
char ans[600002];
int main()
{
scanf ("%d",&n);
for (int i=1;i<=2*n;i++){
int x; scanf ("%d",&x);
if (!s[x]) s[x] = i;
else e[x] = i;
}
for (int i=1;i<=n;i++) c[i] = -1;
for (int i=1;i<=n;i++) if (c[i] == -1){
std::queue<int> Q; Q.push(i);
c[i] = 0;
while (!Q.empty()){
int x = Q.front(); Q.pop();
for (int j=1;j<=n;j++) if (j != x){
bool a = s[x] < s[j] && s[j] < e[x];
bool b = s[x] < e[j] && e[j] < e[x];
if (a ^ b){
if (c[j] != -1){
if (c[j] == c[x]){
puts("IMPOSSIBLE");
return 0;
}
}
else{
c[j] = !c[x]; Q.push(j);
}
}
}
}
}
for (int i=1;i<=n;i++){
ans[s[i]] = ans[e[i]] = (c[i] == 0) ? '^' : 'v';
}
puts(ans+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... |