結果

問題 No.2623 Room Allocation
ユーザー 👑 ygussanyygussany
提出日時 2024-02-09 21:36:19
言語 C
(gcc 12.3.0)
結果
WA  
実行時間 -
コード長 1,326 bytes
コンパイル時間 211 ms
コンパイル使用メモリ 30,592 KB
実行使用メモリ 6,548 KB
最終ジャッジ日時 2024-02-09 21:36:22
合計ジャッジ時間 1,974 ms
ジャッジサーバーID
(参考情報)
judge11 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
6,548 KB
testcase_01 AC 1 ms
6,548 KB
testcase_02 AC 1 ms
6,548 KB
testcase_03 AC 1 ms
6,548 KB
testcase_04 AC 1 ms
6,548 KB
testcase_05 WA -
testcase_06 AC 23 ms
6,548 KB
testcase_07 AC 23 ms
6,548 KB
testcase_08 AC 26 ms
6,548 KB
testcase_09 AC 24 ms
6,548 KB
testcase_10 AC 1 ms
6,548 KB
testcase_11 WA -
testcase_12 AC 1 ms
6,548 KB
testcase_13 AC 2 ms
6,548 KB
testcase_14 WA -
testcase_15 AC 27 ms
6,548 KB
testcase_16 AC 7 ms
6,548 KB
testcase_17 AC 1 ms
6,548 KB
testcase_18 AC 28 ms
6,548 KB
testcase_19 AC 26 ms
6,548 KB
testcase_20 AC 32 ms
6,548 KB
testcase_21 AC 32 ms
6,548 KB
testcase_22 AC 21 ms
6,548 KB
testcase_23 AC 12 ms
6,548 KB
testcase_24 AC 27 ms
6,548 KB
testcase_25 AC 23 ms
6,548 KB
testcase_26 AC 3 ms
6,548 KB
testcase_27 WA -
testcase_28 WA -
testcase_29 WA -
testcase_30 WA -
testcase_31 WA -
testcase_32 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <stdio.h>

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

typedef struct {
	data obj[200001];
	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, N, X, Y, P[200001];
	char c[200001];
	scanf("%d %d %d", &N, &X, &Y);
	for (i = 1; i <= N; i++) scanf("%d %c", &(P[i]), &(c[i]));
	
	int j;
	long long ans = 0, tmp[2];
	max_heap h;
	data d;
	h.size = 0;
	for (i = 1; i <= N && i <= X + Y; i++) {
		for (j = i, tmp[0] = 0, tmp[1] = 0; j <= N; j += X + Y) {
			if (c[j] == 'A') tmp[0] += P[j];
			else tmp[1] += P[j];
		}
		d.key = tmp[0] - tmp[1];
		push(&h, d);
		ans += tmp[1];
	}
	while (X > 0 && h.size > 0) {
		X--;
		d = pop(&h);
		ans += d.key;
	}
	printf("%lld\n", ans);
	fflush(stdout);
	return 0;
}
0