Submission #12165

#TimeUsernameProblemLanguageResultExecution timeMemory
12165xhae전선 연결하기 (GA9_wire)C++14
0 / 100
4 ms11204 KiB
#include <cstdio> #include <algorithm> #include <stack> #include <vector> using namespace std; int n, data[600000]; vector<int> loc[300000]; stack<int> upper, lower; char ans[600001]; int main(void) { scanf("%d", &n); for(int i = 0; i < n * 2; i++) { scanf("%d", data + i); data[i]--; loc[data[i]].push_back(i); } for(int i = 0; i < n * 2; i++) { if(upper.size() > 0 && upper.top() == i) { upper.pop(); ans[i] = '^'; } else if(lower.size() > 0 && lower.top() == i) { lower.pop(); ans[i] = 'v'; } else { int v = data[i]; int end = loc[v][1]; if(upper.size() > 0 && lower.size() > 0) { if(upper.top() < lower.top()) { if(end < upper.top()) { ans[i] = '^'; upper.push(end); } else if(end < lower.top()) { ans[i] = 'v'; lower.push(end); } else { ans[0] = 0; break; } } else { if(end < lower.top()) { ans[i] = 'v'; lower.push(end); } else if(end < upper.top()) { ans[i] = '^'; upper.push(end); } else { ans[0] = 0; break; } } } else if(upper.size() > 0) { if(end < upper.top()) { ans[i] = '^'; upper.push(end); } else { ans[i] = 'v'; lower.push(end); } } else if(lower.size() > 0) { if(end < lower.top()) { ans[i] = 'v'; lower.push(end); } else { ans[i] = '^'; upper.push(end); } } else { upper.push(end); ans[i] = '^'; } } } if(ans[0] == 0) printf("IMPOSSIBLE\n"); else printf("%s\n", ans); 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...