結果

問題 No.2182 KODOKU Stone
ユーザー 👑 ygussanyygussany
提出日時 2023-01-07 00:05:53
言語 C
(gcc 12.3.0)
結果
AC  
実行時間 78 ms / 2,000 ms
コード長 2,110 bytes
コンパイル時間 233 ms
コンパイル使用メモリ 31,180 KB
実行使用メモリ 8,044 KB
最終ジャッジ日時 2023-08-20 17:38:52
合計ジャッジ時間 2,997 ms
ジャッジサーバーID
(参考情報)
judge15 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 1 ms
4,380 KB
testcase_03 AC 1 ms
4,376 KB
testcase_04 AC 1 ms
4,380 KB
testcase_05 AC 1 ms
4,380 KB
testcase_06 AC 1 ms
4,376 KB
testcase_07 AC 1 ms
4,380 KB
testcase_08 AC 1 ms
4,376 KB
testcase_09 AC 1 ms
4,376 KB
testcase_10 AC 2 ms
4,380 KB
testcase_11 AC 55 ms
7,360 KB
testcase_12 AC 75 ms
8,044 KB
testcase_13 AC 16 ms
4,376 KB
testcase_14 AC 17 ms
4,380 KB
testcase_15 AC 78 ms
7,636 KB
testcase_16 AC 53 ms
7,792 KB
testcase_17 AC 18 ms
4,376 KB
testcase_18 AC 50 ms
6,388 KB
testcase_19 AC 40 ms
4,376 KB
testcase_20 AC 50 ms
5,592 KB
testcase_21 AC 19 ms
4,376 KB
testcase_22 AC 16 ms
4,376 KB
testcase_23 AC 33 ms
5,112 KB
testcase_24 AC 25 ms
4,380 KB
testcase_25 AC 14 ms
4,384 KB
testcase_26 AC 14 ms
4,380 KB
testcase_27 AC 14 ms
4,380 KB
testcase_28 AC 41 ms
5,384 KB
testcase_29 AC 47 ms
6,256 KB
testcase_30 AC 51 ms
7,208 KB
testcase_31 AC 42 ms
5,280 KB
testcase_32 AC 43 ms
5,004 KB
testcase_33 AC 44 ms
6,856 KB
testcase_34 AC 22 ms
4,380 KB
testcase_35 AC 47 ms
5,940 KB
testcase_36 AC 13 ms
4,380 KB
testcase_37 AC 51 ms
6,820 KB
testcase_38 AC 1 ms
4,376 KB
testcase_39 AC 1 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <stdio.h>
#include <stdlib.h>

typedef struct {
	int key, id;
} data;

typedef struct {
	data obj[100001];
	int size;
} max_heap;

void push(max_heap* h, data x)
{
	int i = ++(h->size), j = i >> 1;
	data tmp;
	h->obj[i] = x;
	while (j > 0) {
		if (h->obj[i].key > h->obj[j].key) {
			tmp = h->obj[j];
			h->obj[j] = h->obj[i];
			h->obj[i] = tmp;
			i = j;
			j >>= 1;
		} else break;
	}
}

data pop(max_heap* h)
{
	int i = 1, j = 2;
	data output = h->obj[1], tmp;
	h->obj[1] = h->obj[(h->size)--];
	while (j <= h->size) {
		if (j < h->size && h->obj[j^1].key > h->obj[j].key) j ^= 1;
		if (h->obj[j].key > h->obj[i].key) {
			tmp = h->obj[j];
			h->obj[j] = h->obj[i];
			h->obj[i] = tmp;
			i = j;
			j <<= 1;
		} else break;
	}
	return output;
}

int main()
{
	int i, j, N, K[100001], T[100001], *A[100001], l = 1, r = 1000000000, m;
	scanf("%d", &N);
	for (i = 1; i <= N; i++) scanf("%d", &(K[i]));
	for (i = 1; i <= N; i++) {
		scanf("%d", &(T[i]));
		A[i] = (int*)malloc(sizeof(int) * (T[i] + 1));
		for (j = 1; j <= T[i]; j++) scanf("%d", &(A[i][j]));
	}
	
	data d;
	max_heap h[2];
	int k, max[2];
	while (l < r) {
		m = (l + r + 1) / 2;
		h[0].size = 0;
		h[1].size = 0;
		for (i = 1; i <= N; i++) {
			for (j = 1, k = 0; j <= T[i]; j++) if (A[i][j] >= m) k++;
			d.key = k;
			if (k == T[i]) push(&(h[0]), d);
			else push(&(h[1]), d);
		}
		if (h[0].size > 0) max[0] = h[0].obj[1].key;
		else max[0] = -1;

		if (h[1].size > 0) max[1] = h[1].obj[1].key;
		else max[1] = -1;		
		for (i = N; i >= N - h[0].size; i--) if (max[1] >= K[i]) break;
		if (i >= N - h[0].size) {
			l = m;
			continue;
		}
		
		for (i = N, j = N - h[0].size; i >= 1; i--) {
			if (h[0].size == 0) max[0] = -1;
			if (h[1].size > 0) max[1] = h[1].obj[1].key;
			else max[1] = -1;
			if (max[0] >= K[i] || max[1] >= K[i] || (i == 1 && max[0] >= 0) || (j >= 1 && max[1] >= K[j])) break;
			
			if (max[1] == K[i] - 1) {
				pop(&(h[1]));
				j--;
			} else if (max[0] >= 0) pop(&(h[0]));
			else {
				i = 0;
				break;
			}
		}
		if (i >= 1) l = m;
		else r = m - 1;
	}
	printf("%d\n", l);
	fflush(stdout);
	return 0;
}
0