답안 #150578

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
150578 2019-09-01T08:40:14 Z 강한친구 대한육군(#3592, pichulia) 십자가 놓기 (FXCUP4_cross) C++17
100 / 100
265 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];
		ax[al++] = aa[i];
		bx[bl++] = bb[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];
				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 7 ms 2432 KB Output is correct
2 Correct 6 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 19 ms 3072 KB Output is correct
6 Correct 252 ms 12008 KB Output is correct
7 Correct 240 ms 11884 KB Output is correct
8 Correct 252 ms 12004 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 7 ms 2432 KB Output is correct
2 Correct 6 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 19 ms 3072 KB Output is correct
6 Correct 252 ms 12008 KB Output is correct
7 Correct 240 ms 11884 KB Output is correct
8 Correct 252 ms 12004 KB Output is correct
9 Correct 7 ms 2432 KB Output is correct
10 Correct 6 ms 2432 KB Output is correct
11 Correct 8 ms 2432 KB Output is correct
12 Correct 19 ms 3072 KB Output is correct
13 Correct 125 ms 7408 KB Output is correct
14 Correct 265 ms 12004 KB Output is correct
15 Correct 243 ms 12008 KB Output is correct
16 Correct 244 ms 12004 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 7 ms 2432 KB Output is correct
2 Correct 6 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 19 ms 3072 KB Output is correct
6 Correct 252 ms 12008 KB Output is correct
7 Correct 240 ms 11884 KB Output is correct
8 Correct 252 ms 12004 KB Output is correct
9 Correct 7 ms 2432 KB Output is correct
10 Correct 6 ms 2432 KB Output is correct
11 Correct 8 ms 2432 KB Output is correct
12 Correct 19 ms 3072 KB Output is correct
13 Correct 125 ms 7408 KB Output is correct
14 Correct 265 ms 12004 KB Output is correct
15 Correct 243 ms 12008 KB Output is correct
16 Correct 244 ms 12004 KB Output is correct
17 Correct 6 ms 2432 KB Output is correct
18 Correct 8 ms 2432 KB Output is correct
19 Correct 21 ms 3072 KB Output is correct
20 Correct 130 ms 7408 KB Output is correct
21 Correct 208 ms 9956 KB Output is correct
22 Correct 251 ms 12008 KB Output is correct
23 Correct 249 ms 11884 KB Output is correct
24 Correct 250 ms 11884 KB Output is correct
25 Correct 252 ms 12004 KB Output is correct
26 Correct 240 ms 12004 KB Output is correct