답안 #647091

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
647091 2022-10-01T14:49:22 Z georgievskiy popa (BOI18_popa) C++17
37 / 100
345 ms 312 KB
// #define LOCAL
#ifndef LOCAL
#include "popa.h"
#endif
#include <bits/stdc++.h>
using namespace std;

#ifdef LOCAL

int ARR[100], LEFT[100], RIGHT[100];
int f_gcd(int a, int b) {
	int g = 0;
	for (int i = a; i <= b; i++)
		g = __gcd(g, ARR[i]);
	return g;
}

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

#endif

int rec(int l, int r, int* left, int* right) {
	if (l >= r)
		return -1;
	if (l + 1 == r)
		return l;
	int root = -1;
	for (int i = l; i < r; i++) {
		if (query(l, r - 1, i, i)) {
			root = i;
			break;
		}
	}
	assert(root >= l && root < r);
	int l_c = rec(l, root, left, right);
	int r_c = rec(root + 1, r, left, right);
	left[root] = l_c, right[root] = r_c;
	return root;
}

int solve(int n, int* left, int* right) {
	fill(left, left + n, -1), fill(right, right + n, -1);
	return rec(0, n, left, right);
}

#ifdef LOCAL

int main() {
	int n;
	cin >> n;
	for (int i = 0; i < n; i++) cin >> ARR[i];
	solve(n, LEFT, RIGHT);
	for (int i = 0; i < n; i++)
		cout << LEFT[i] << " ";
	cout << "\n";
	for (int i = 0; i < n; i++)
		cout << RIGHT[i] << " ";
	cout << "\n";
	return 0;
}

#endif
# 결과 실행 시간 메모리 Grader output
1 Correct 73 ms 280 KB Output is correct
2 Correct 98 ms 300 KB Output is correct
3 Correct 16 ms 208 KB Output is correct
4 Correct 75 ms 208 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Incorrect 345 ms 312 KB too many queries
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 19 ms 208 KB too many queries
2 Halted 0 ms 0 KB -