結果

問題 No.1816 MUL-DIV Game
ユーザー 👑 ygussanyygussany
提出日時 2022-01-21 21:29:33
言語 C
(gcc 12.3.0)
結果
AC  
実行時間 45 ms / 2,000 ms
コード長 3,479 bytes
コンパイル時間 733 ms
コンパイル使用メモリ 30,500 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-08-17 04:59:57
合計ジャッジ時間 3,255 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 AC 1 ms
4,376 KB
testcase_02 AC 0 ms
4,376 KB
testcase_03 AC 0 ms
4,376 KB
testcase_04 AC 1 ms
4,380 KB
testcase_05 AC 1 ms
4,376 KB
testcase_06 AC 1 ms
4,376 KB
testcase_07 AC 1 ms
4,376 KB
testcase_08 AC 0 ms
4,376 KB
testcase_09 AC 4 ms
4,380 KB
testcase_10 AC 19 ms
4,380 KB
testcase_11 AC 17 ms
4,376 KB
testcase_12 AC 13 ms
4,376 KB
testcase_13 AC 27 ms
4,380 KB
testcase_14 AC 15 ms
4,376 KB
testcase_15 AC 19 ms
4,376 KB
testcase_16 AC 5 ms
4,376 KB
testcase_17 AC 36 ms
4,376 KB
testcase_18 AC 35 ms
4,376 KB
testcase_19 AC 17 ms
4,376 KB
testcase_20 AC 38 ms
4,380 KB
testcase_21 AC 13 ms
4,376 KB
testcase_22 AC 10 ms
4,376 KB
testcase_23 AC 1 ms
4,376 KB
testcase_24 AC 0 ms
4,380 KB
testcase_25 AC 45 ms
4,376 KB
testcase_26 AC 45 ms
4,376 KB
testcase_27 AC 45 ms
4,376 KB
testcase_28 AC 45 ms
4,380 KB
testcase_29 AC 45 ms
4,384 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <stdio.h>

typedef struct {
	long long key;
	int id;
} data;

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

long long get_min(min_max_heap* h)
{
	return h->obj[0].key;
}

int get_argmin(min_max_heap* h)
{
	return h->obj[0].id;
}

long long get_max(min_max_heap* h)
{
	if (h->size == 1) return h->obj[0].key;
	else return h->obj[1].key;
}

int get_argmax(min_max_heap* h)
{
	if (h->size == 1) return h->obj[0].id;
	else return h->obj[1].id;
}
 
void push(min_max_heap* h, data x)
{
	int i = (h->size)++;
	data tmp;
	if ((i & 1) != 0 && x.key < h->obj[i^1].key) {
		h->obj[i] = h->obj[i^1];
		h->obj[i^1] = x;
		i ^= 1;
	} else h->obj[i] = x;
	
	int j, k = ((i >> 1) + 1) >> 1;
	if (k == 0) return;
	j = (k - 1) << 1;
	if (h->obj[i].key < h->obj[j].key) {
		while (k > 0) {
			if (h->obj[i].key < h->obj[j].key) {
				tmp = h->obj[j];
				h->obj[j] = h->obj[i];
				h->obj[i] = tmp;
				k >>= 1;
				i = j;
				j = (k - 1) << 1;
			} else break;
		}
	} else if (h->obj[i].key > h->obj[j^1].key) {
		j ^= 1;
		while (k > 0) {
			if (h->obj[i].key > h->obj[j].key) {
				tmp = h->obj[j];
				h->obj[j] = h->obj[i];
				h->obj[i] = tmp;
				k >>= 1;
				i = j;
				j = ((k - 1) << 1) ^ 1;
			} else break;
		}
	}
}

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

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

int main()
{
	int i, N;
	data d;
	min_max_heap h;
	h.size = 0;
	scanf("%d", &N);
	for (i = 1; i <= N; i++) {
		scanf("%d", &(d.key));
		push(&h, d);
	}
	
	for (i = 1; i < N; i++) {
		if (i % 2 == 0) {
			pop_max(&h);
			pop_max(&h);
			d.key = 1;
			push(&h, d);
		} else {
			d = pop_min(&h);
			d.key *= pop_min(&h).key;
			push(&h, d);
		}
	}
	printf("%lld\n", get_max(&h));
	fflush(stdout);
	return 0;
}
0