Submission #12165

# Submission time Handle Problem Language Result Execution time Memory
12165 2014-12-21T13:15:27 Z xhae 전선 연결하기 (GA9_wire) C++14
0 / 100
4 ms 11204 KB
#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 time Memory Grader output
1 Correct 0 ms 11204 KB Output is correct
2 Correct 4 ms 11204 KB Output is correct
3 Incorrect 0 ms 11204 KB Output isn't correct
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Halted 0 ms 0 KB -