結果

問題 No.1557 Binary Variable
ユーザー pengin_2000pengin_2000
提出日時 2022-01-18 17:02:09
言語 C
(gcc 12.3.0)
結果
AC  
実行時間 98 ms / 2,000 ms
コード長 1,158 bytes
コンパイル時間 508 ms
コンパイル使用メモリ 28,896 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-08-15 07:31:33
合計ジャッジ時間 7,616 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 67 ms
4,380 KB
testcase_01 AC 64 ms
4,380 KB
testcase_02 AC 1 ms
4,380 KB
testcase_03 AC 1 ms
4,380 KB
testcase_04 AC 75 ms
4,380 KB
testcase_05 AC 75 ms
4,380 KB
testcase_06 AC 72 ms
4,376 KB
testcase_07 AC 74 ms
4,380 KB
testcase_08 AC 80 ms
4,376 KB
testcase_09 AC 80 ms
4,380 KB
testcase_10 AC 86 ms
4,380 KB
testcase_11 AC 86 ms
4,376 KB
testcase_12 AC 79 ms
4,380 KB
testcase_13 AC 86 ms
4,380 KB
testcase_14 AC 89 ms
4,380 KB
testcase_15 AC 86 ms
4,380 KB
testcase_16 AC 90 ms
4,380 KB
testcase_17 AC 89 ms
4,376 KB
testcase_18 AC 89 ms
4,380 KB
testcase_19 AC 93 ms
4,380 KB
testcase_20 AC 92 ms
4,380 KB
testcase_21 AC 92 ms
4,384 KB
testcase_22 AC 92 ms
4,380 KB
testcase_23 AC 92 ms
4,376 KB
testcase_24 AC 95 ms
4,376 KB
testcase_25 AC 95 ms
4,380 KB
testcase_26 AC 94 ms
4,380 KB
testcase_27 AC 94 ms
4,384 KB
testcase_28 AC 95 ms
4,376 KB
testcase_29 AC 97 ms
4,380 KB
testcase_30 AC 98 ms
4,384 KB
testcase_31 AC 97 ms
4,380 KB
testcase_32 AC 97 ms
4,380 KB
testcase_33 AC 92 ms
4,380 KB
testcase_34 AC 1 ms
4,376 KB
testcase_35 AC 1 ms
4,376 KB
testcase_36 AC 0 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<stdio.h>
int l[200005], r[200005];
int h[200005], hl;
int comp_h(int a, int b)
{
	if (r[h[a]] > r[h[b]])
		return 1;
	else
		return -1;
}
void swap_h(int a, int b)
{
	int f = h[a];
	h[a] = h[b];
	h[b] = f;
	return;
}
void push(int ne)
{
	h[hl] = ne;
	int p = hl;
	hl++;
	for (; p > 0; p = (p - 1) / 2)
		if (comp_h((p - 1) / 2, p) > 0)
			swap_h((p - 1) / 2, p);
	return;
}
int pop()
{
	hl--;
	swap_h(0, hl);
	int p = 0;
	for (;;)
	{
		if (2 * p + 2 < hl)
		{
			if (comp_h(2 * p + 1, 2 * p + 2) > 0)
			{
				if (comp_h(p, 2 * p + 2) > 0)
					swap_h(p, 2 * p + 2);
				p = 2 * p + 2;
			}
			else
			{
				if (comp_h(p, 2 * p + 1) > 0)
					swap_h(p, 2 * p + 1);
				p = 2 * p + 1;
			}
		}
		else if (2 * p + 1 < hl)
		{
			if (comp_h(p, 2 * p + 1) > 0)
				swap_h(p, 2 * p + 1);
			p = 2 * p + 1;
		}
		else
			break;
	}
	return h[hl];
}
int main()
{
	int n, m;
	scanf("%d %d", &n, &m);
	int i;
	for (i = 0; i < m; i++)
		scanf("%d %d", &l[i], &r[i]);
	hl = 0;
	for (i = 0; i < m; i++)
		push(i);
	int max = 0;
	int ans = n;
	while (hl > 0)
	{
		i = pop();
		if (max < l[i])
		{
			ans--;
			max = r[i];
		}
	}
	printf("%d\n", ans);
	return 0;
}
0