結果

問題 No.3311 フィルター
コンテスト
ユーザー pengin_2000
提出日時 2025-10-24 23:15:50
言語 C
(gcc 13.3.0)
結果
AC  
実行時間 47 ms / 2,000 ms
コード長 1,714 bytes
コンパイル時間 267 ms
コンパイル使用メモリ 27,600 KB
実行使用メモリ 7,720 KB
最終ジャッジ日時 2025-10-25 12:57:44
合計ジャッジ時間 1,398 ms
ジャッジサーバーID
(参考情報)
judge3 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 21
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.c: In function ‘main’:
main.c:64:9: warning: ignoring return value of ‘scanf’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   64 |         scanf("%d %d", &n, &m);
      |         ^~~~~~~~~~~~~~~~~~~~~~
main.c:68:17: warning: ignoring return value of ‘scanf’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   68 |                 scanf("%s", s);
      |                 ^~~~~~~~~~~~~~

ソースコード

diff #

#include<stdio.h>
int h[100005], l;
int comp_h(int a, int b)
{
	if (h[a] > 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[l] = ne;
	int p = l++;
	for (; p > 0; p = (p - 1) / 2)
		if (comp_h((p - 1) / 2, p) > 0)
			swap_h((p - 1) / 2, p);
	return;
}
int pop()
{
	swap_h(0, --l);
	int p = 0;
	for (;;)
	{
		if (2 * p + 2 < l)
		{
			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 < l)
		{
			if (comp_h(p, 2 * p + 1) > 0)
				swap_h(p, 2 * p + 1);
			p = 2 * p + 1;
		}
		else
			break;
	}
	return h[l];
}
char s[22];
int a[100005];
int v[100005];
int main()
{
	int n, m;
	scanf("%d %d", &n, &m);
	int i, j;
	for (i = 0; i < m; i++)
	{
		scanf("%s", s);
		a[i] = 0;
		for (j = 0; j < n; j++)
			a[i] = 2 * a[i] + s[j] - '0';
	}
	l = 0;
	for (i = 0; i < m; i++)
		push(a[i]);
	for (i = 0; i < m; i++)
		a[i] = pop();
	if (a[0] == 0)
	{
		printf("No\n");
		return 0;
	}
	for (i = 0; i < m; i++)
		v[i] = 0;
	int min, mid, max, f;
	a[m] = -1;
	for (i = 0; i < m; i++)
	{
		for (j = 0; j < n; j++)
		{
			if (((a[i] >> j) & 1) > 0)
				continue;
			f = (a[i] | (1 << j));
			min = -1;
			max = m;
			while (max - min > 1)
			{
				mid = (max + min) / 2;
				if (a[mid] < f)
					min = mid;
				else
					max = mid;
			}
			if (a[max] != f)
			{
				printf("No\n");
				return 0;
			}
			v[max]++;
		}
	}
	for (i = 1; i < m; i++)
	{
		if (v[i] == 0)
		{
			printf("No\n");
			return 0;
		}
	}
	printf("Yes\n");
	return 0;
}
0