Submission #12130

#TimeUsernameProblemLanguageResultExecution timeMemory
12130kriii전선 연결하기 (GA9_wire)C++14
24 / 100
1000 ms5344 KiB
#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 timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...