답안 #68600

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
68600 2018-08-17T13:16:56 Z aome popa (BOI18_popa) C++17
100 / 100
127 ms 692 KB
#include <bits/stdc++.h>

#include "popa.h"

using namespace std;

const int N = 1005;

// int a[N], L[N], R[N];
int par[N];

// int get(int l, int r) {
// 	int gcd = 0;
// 	for (int i = l; i <= r; ++i) gcd = __gcd(gcd, a[i]);
// 	return gcd;
// }

// int query(int a, int b, int c, int d) {
// 	return get(a, b) == get(c, d);
// }

int solve(int n, int* L, int* R) {
	memset(par, -1, sizeof par);
	L[0] = R[0] = -1;
	for (int i = 1; i < n; ++i) {
		int cur = i - 1;
		L[i] = R[i] = -1;
		while (1) {
			if (query(cur, i, i, i)) {
				if (par[cur] == -1) {
					par[cur] = i, L[i] = cur; break;
				}
				else cur = par[cur];
			}
			else {
				if (R[cur] == -1) R[cur] = i, par[i] = cur;
				else par[R[cur]] = i, par[i] = cur, L[i] = R[cur], R[cur] = i;
				break;
			}
		}
	}
	int root = 0;
	for (int i = 0; i < n; ++i) if (par[i] == -1) root = i;
	return root;
}

// int main() {
// 	int n; cin >> n;
// 	for (int i = 0; i < n; ++i) cin >> a[i];
// 	solve(n, L, R);
// 	for (int i = 0; i < n; ++i) cout << L[i] << ' '; cout << '\n';
// 	for (int i = 0; i < n; ++i) cout << R[i] << ' '; cout << '\n';
// }
# 결과 실행 시간 메모리 Grader output
1 Correct 8 ms 376 KB Output is correct
2 Correct 9 ms 440 KB Output is correct
3 Correct 6 ms 440 KB Output is correct
4 Correct 11 ms 440 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 120 ms 492 KB Output is correct
2 Correct 93 ms 556 KB Output is correct
3 Correct 64 ms 556 KB Output is correct
4 Correct 127 ms 636 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 87 ms 692 KB Output is correct
2 Correct 90 ms 692 KB Output is correct
3 Correct 63 ms 692 KB Output is correct
4 Correct 83 ms 692 KB Output is correct