답안 #255168

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
255168 2020-07-31T13:18:53 Z Saboon popa (BOI18_popa) C++14
100 / 100
104 ms 520 KB
#include <bits/stdc++.h>
#include "popa.h"
using namespace std;

typedef long long ll;
const int maxn = 1000 + 10;
int l[maxn], r[maxn], a[maxn];

int solve(int n, int* Left, int* Right){
	stack<int> s;
	memset(l, -1, sizeof l);
	memset(r, -1, sizeof r);
	for (int i = 0; i < n; i++)
		Left[i] = Right[i] = -1;
	for (int i = 0; i < n; i++){
		while (!s.empty()){
			int k = s.top();
			if (query(k, i, i, i) == 1){
				r[k] = i;
				s.pop();
				continue;
			}
			l[i] = k;
			break;
		}
		s.push(i);
	}
	int root = 0;
	for (int i = 0; i < n; i++)
		if (l[i] == -1 and r[i] == -1)
			root = i;
	for (int i = 0; i < n; i++){
		if (i == root)
			continue;
		if (l[i] == -1)
			Left[r[i]] = i;
		else if (r[i] == -1)
			Right[l[i]] = i;
		else{
			if (r[l[i]] == r[i])
				Right[l[i]] = i;
			else
				Left[r[i]] = i;
		}
	}
	return root;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 8 ms 384 KB Output is correct
2 Correct 10 ms 384 KB Output is correct
3 Correct 12 ms 256 KB Output is correct
4 Correct 14 ms 256 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 104 ms 384 KB Output is correct
2 Correct 84 ms 384 KB Output is correct
3 Correct 59 ms 384 KB Output is correct
4 Correct 88 ms 384 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 92 ms 384 KB Output is correct
2 Correct 65 ms 388 KB Output is correct
3 Correct 90 ms 384 KB Output is correct
4 Correct 100 ms 520 KB Output is correct