Submission #12773

#TimeUsernameProblemLanguageResultExecution timeMemory
12773Qwaz전선 연결하기 (GA9_wire)C++14
0 / 100
0 ms7068 KiB
#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 timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...