답안 #150553

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
150553 2019-09-01T08:38:01 Z 강한친구 대한육군(#3592, pichulia) 십자가 놓기 (FXCUP4_cross) C++17
8 / 100
257 ms 12008 KB
#include "cross.h"
#include<algorithm>
#define I 262144
using namespace std;
typedef pair<long long, long long> pll;
int n;
pll a[200009];
long long int ax[200009];
long long int bx[200009];
int al;
int bl;
int ms[2 * I];
void update(int i, int v)
{
	i = i + I;
	ms[i] += v;
	i /= 2;
	while (i > 0) {
		ms[i] = ms[i * 2] + ms[i * 2 + 1];
		i /= 2;
	}
}
int find_min(int dep, int m, int ll, int rr) {
	if (dep >= I) return ll;
	if (ms[dep * 2 + 1] >= m) return find_min(dep * 2 + 1, m, (ll + rr) / 2 + 1, rr);
	return find_min(dep * 2, m - ms[dep * 2 + 1], ll, (ll + rr) / 2);
}
long long SelectCross(int m, std::vector<int> aa, std::vector<int> bb) {
	n = aa.size();
	al = bl = 0;
	int i, j, k;
	for (i = 0; i < n; i++) {
		a[i].first = aa[i];
		a[i].second = bb[i] - aa[i];
		ax[al++] = aa[i];
		bx[bl++] = bb[i] - aa[i];
	}
	bx[bl++] = -999999999;
	sort(ax, ax + al); al = unique(ax, ax + al) - ax;
	sort(bx, bx + bl); bl = unique(bx, bx + bl) - bx;
	for (i = 0; i < n; i++) {
		a[i].first = lower_bound(ax, ax + al, a[i].first) - ax;
		a[i].second = lower_bound(bx, bx + bl, a[i].second) - bx;
	}
	sort(a, a + n);
	for (i = 0; i < 2 * I; i++)ms[i] = 0;

	i = n - 1;
	j = 0;
	long long int res = 0;
	for (k = al - 1; k >= 0; k--)
	{
		//printf("%d %d -->\n", k, i);
		while (i >= 0 && a[i].first == k)
		{
			//printf("%lld , update %lld\n", ax[k], a[i].second);
			update(a[i].second, 1);
			i--;
		}
		if (ms[1] >= m)
		{
			j = find_min(1, m, 0, I - 1);
			//printf("%d , %d\n", ms[1], j);
			if (j > 0) {
				long long int x = ax[k];
				long long int y = bx[j] + x;
				long long int cur = 2 * x * y - x * x;
				//printf("%lld %lld  %lld %lld\n", x, y, cur, res);
				res = max(res, cur);
			}
		}
	}

	return res;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 6 ms 2432 KB Output is correct
2 Correct 8 ms 2432 KB Output is correct
3 Correct 7 ms 2432 KB Output is correct
4 Correct 8 ms 2432 KB Output is correct
5 Correct 20 ms 3072 KB Output is correct
6 Correct 257 ms 12008 KB Output is correct
7 Correct 233 ms 12008 KB Output is correct
8 Correct 232 ms 12008 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 6 ms 2432 KB Output is correct
2 Correct 8 ms 2432 KB Output is correct
3 Correct 7 ms 2432 KB Output is correct
4 Correct 8 ms 2432 KB Output is correct
5 Correct 20 ms 3072 KB Output is correct
6 Correct 257 ms 12008 KB Output is correct
7 Correct 233 ms 12008 KB Output is correct
8 Correct 232 ms 12008 KB Output is correct
9 Incorrect 7 ms 2432 KB Output isn't correct
10 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 6 ms 2432 KB Output is correct
2 Correct 8 ms 2432 KB Output is correct
3 Correct 7 ms 2432 KB Output is correct
4 Correct 8 ms 2432 KB Output is correct
5 Correct 20 ms 3072 KB Output is correct
6 Correct 257 ms 12008 KB Output is correct
7 Correct 233 ms 12008 KB Output is correct
8 Correct 232 ms 12008 KB Output is correct
9 Incorrect 7 ms 2432 KB Output isn't correct
10 Halted 0 ms 0 KB -