結果

問題 No.2182 KODOKU Stone
ユーザー 👑 ygussanyygussany
提出日時 2023-01-06 23:45:09
言語 C
(gcc 12.3.0)
結果
WA  
実行時間 -
コード長 1,915 bytes
コンパイル時間 152 ms
コンパイル使用メモリ 31,872 KB
実行使用メモリ 8,192 KB
最終ジャッジ日時 2024-05-07 23:44:22
合計ジャッジ時間 2,584 ms
ジャッジサーバーID
(参考情報)
judge1 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
5,248 KB
testcase_01 AC 1 ms
5,376 KB
testcase_02 AC 1 ms
5,376 KB
testcase_03 AC 1 ms
5,376 KB
testcase_04 AC 1 ms
5,376 KB
testcase_05 AC 1 ms
5,376 KB
testcase_06 AC 1 ms
5,376 KB
testcase_07 AC 2 ms
5,376 KB
testcase_08 AC 1 ms
5,376 KB
testcase_09 AC 1 ms
5,376 KB
testcase_10 AC 1 ms
5,376 KB
testcase_11 AC 47 ms
7,424 KB
testcase_12 AC 73 ms
8,192 KB
testcase_13 AC 14 ms
5,376 KB
testcase_14 AC 15 ms
5,376 KB
testcase_15 AC 75 ms
7,808 KB
testcase_16 AC 50 ms
7,680 KB
testcase_17 AC 16 ms
5,376 KB
testcase_18 AC 49 ms
6,400 KB
testcase_19 AC 40 ms
5,376 KB
testcase_20 AC 49 ms
5,504 KB
testcase_21 AC 18 ms
5,376 KB
testcase_22 AC 15 ms
5,376 KB
testcase_23 WA -
testcase_24 AC 25 ms
5,376 KB
testcase_25 AC 12 ms
5,376 KB
testcase_26 AC 11 ms
5,376 KB
testcase_27 AC 11 ms
5,376 KB
testcase_28 AC 39 ms
5,504 KB
testcase_29 AC 46 ms
6,272 KB
testcase_30 AC 49 ms
6,784 KB
testcase_31 AC 41 ms
5,376 KB
testcase_32 AC 42 ms
5,376 KB
testcase_33 AC 43 ms
6,016 KB
testcase_34 AC 21 ms
5,376 KB
testcase_35 AC 46 ms
6,144 KB
testcase_36 AC 12 ms
5,376 KB
testcase_37 AC 49 ms
6,784 KB
testcase_38 WA -
testcase_39 AC 1 ms
5,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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

typedef struct {
	int key, id;
} data;

typedef struct {
	data obj[300003];
	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[300003], T[300003], *A[300003];
	unsigned int l = 2000000003, r = 0, 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]));
			if (l > A[i][j]) l = A[i][j];
			if (r < A[i][j]) r = 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;
		
		for (i = N; 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]) break;
			
			if (max[1] == K[i] - 1) pop(&(h[1]));
			else if (max[0] >= 0) pop(&(h[0]));
			else {
				i = 0;
				break;
			}
		}
		if (i >= 1) l = m;
		else r = m - 1;
	}
	printf("%u\n", l);
	fflush(stdout);
	return 0;
}
0