結果

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

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
5,248 KB
testcase_01 AC 1 ms
5,248 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 1 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 54 ms
7,296 KB
testcase_12 AC 69 ms
8,064 KB
testcase_13 AC 16 ms
5,376 KB
testcase_14 AC 15 ms
5,376 KB
testcase_15 AC 69 ms
7,680 KB
testcase_16 AC 51 ms
7,680 KB
testcase_17 AC 16 ms
5,376 KB
testcase_18 AC 47 ms
6,400 KB
testcase_19 AC 38 ms
5,376 KB
testcase_20 AC 47 ms
5,504 KB
testcase_21 AC 18 ms
5,376 KB
testcase_22 AC 16 ms
5,376 KB
testcase_23 WA -
testcase_24 AC 23 ms
5,376 KB
testcase_25 AC 13 ms
5,376 KB
testcase_26 AC 13 ms
5,376 KB
testcase_27 AC 13 ms
5,376 KB
testcase_28 AC 38 ms
5,376 KB
testcase_29 AC 45 ms
6,272 KB
testcase_30 AC 49 ms
6,912 KB
testcase_31 AC 39 ms
5,376 KB
testcase_32 AC 41 ms
5,376 KB
testcase_33 AC 43 ms
6,016 KB
testcase_34 AC 21 ms
5,376 KB
testcase_35 AC 45 ms
5,888 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[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;
		
		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] || (i == 1 && max[0] >= 0)) 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("%d\n", l);
	fflush(stdout);
	return 0;
}
0