結果

問題 No.2667 Constrained Permutation
ユーザー 👑 ygussanyygussany
提出日時 2024-02-18 10:17:28
言語 C
(gcc 12.3.0)
結果
WA  
実行時間 -
コード長 1,397 bytes
コンパイル時間 248 ms
コンパイル使用メモリ 31,104 KB
実行使用メモリ 6,676 KB
最終ジャッジ日時 2024-02-18 10:17:34
合計ジャッジ時間 4,725 ms
ジャッジサーバーID
(参考情報)
judge14 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,676 KB
testcase_01 AC 1 ms
6,676 KB
testcase_02 AC 1 ms
6,676 KB
testcase_03 AC 2 ms
6,676 KB
testcase_04 AC 1 ms
6,676 KB
testcase_05 AC 1 ms
6,676 KB
testcase_06 AC 1 ms
6,676 KB
testcase_07 AC 2 ms
6,676 KB
testcase_08 AC 2 ms
6,676 KB
testcase_09 AC 2 ms
6,676 KB
testcase_10 AC 1 ms
6,676 KB
testcase_11 AC 1 ms
6,676 KB
testcase_12 AC 30 ms
6,676 KB
testcase_13 AC 2 ms
6,676 KB
testcase_14 AC 89 ms
6,676 KB
testcase_15 AC 72 ms
6,676 KB
testcase_16 AC 55 ms
6,676 KB
testcase_17 AC 16 ms
6,676 KB
testcase_18 AC 102 ms
6,676 KB
testcase_19 AC 95 ms
6,676 KB
testcase_20 AC 98 ms
6,676 KB
testcase_21 AC 94 ms
6,676 KB
testcase_22 AC 104 ms
6,676 KB
testcase_23 AC 94 ms
6,676 KB
testcase_24 AC 40 ms
6,676 KB
testcase_25 AC 78 ms
6,676 KB
testcase_26 AC 100 ms
6,676 KB
testcase_27 AC 98 ms
6,676 KB
testcase_28 AC 72 ms
6,676 KB
testcase_29 AC 64 ms
6,676 KB
testcase_30 AC 76 ms
6,676 KB
testcase_31 AC 44 ms
6,676 KB
testcase_32 AC 9 ms
6,676 KB
testcase_33 WA -
testcase_34 AC 48 ms
6,676 KB
testcase_35 WA -
testcase_36 WA -
testcase_37 WA -
testcase_38 AC 70 ms
6,676 KB
testcase_39 AC 2 ms
6,676 KB
testcase_40 AC 48 ms
6,676 KB
testcase_41 AC 79 ms
6,676 KB
testcase_42 AC 53 ms
6,676 KB
testcase_43 AC 70 ms
6,676 KB
testcase_44 AC 31 ms
6,676 KB
testcase_45 AC 2 ms
6,676 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <stdio.h>

typedef struct {
	int key, id;
} data;

typedef struct {
	data obj[200001];
	int size;
} min_heap;

void push(min_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(min_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;
}

void chmin(int *a, int b)
{
	if (*a > b) *a = b;
}

void chmax(int *a, int b)
{
	if (*a < b) *a = b;
}

int main()
{
	int i, n, l[200001], r[200001];
	scanf("%d", &n);
	for (i = 1; i <= n; i++) scanf("%d %d", &(l[i]), &(r[i]));
	
	int k, L = 0, R = 1000000000;
	min_heap h[2];
	data d;
	h[0].size = 0;
	h[1].size = 0;
	for (i = 1; i <= n; i++) {
		d.key = l[i];
		d.id = i;
		push(&(h[0]), d);
		d.key = r[i];
		d.id = i;
		push(&(h[1]), d);
	}
	for (i = 1; i <= n; i++) {
		d = pop(&(h[0]));
		chmax(&L, d.key - i);
		d = pop(&(h[1]));
		chmin(&R, d.key - i);
	}
	if (R - L >= 0) printf("%d\n", R - L + 1);
	else printf("0\n");
	fflush(stdout);
	return 0;
}
0