結果

問題 No.3325 陰陽師
コンテスト
ユーザー pengin_2000
提出日時 2025-11-01 16:14:06
言語 C
(gcc 13.3.0)
結果
WA  
実行時間 -
コード長 1,672 bytes
コンパイル時間 414 ms
コンパイル使用メモリ 27,600 KB
実行使用メモリ 7,720 KB
最終ジャッジ日時 2025-11-01 16:14:22
合計ジャッジ時間 15,110 ms
ジャッジサーバーID
(参考情報)
judge3 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 29 WA * 1
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.c: In function ‘main’:
main.c:63:9: warning: ignoring return value of ‘scanf’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   63 |         scanf("%d %d", &n, &m);
      |         ^~~~~~~~~~~~~~~~~~~~~~
main.c:66:17: warning: ignoring return value of ‘scanf’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   66 |                 scanf("%d", &s[i]);
      |                 ^~~~~~~~~~~~~~~~~~
main.c:68:17: warning: ignoring return value of ‘scanf’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   68 |                 scanf("%d", &t[i]);
      |                 ^~~~~~~~~~~~~~~~~~

ソースコード

diff #

#include<stdio.h>
int h[200005], 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];
}
int s[200005], t[200005];
int tt[200005];
int main()
{
	int n, m;
	scanf("%d %d", &n, &m);
	int i, j;
	for (i = 0; i < n; i++)
		scanf("%d", &s[i]);
	for (i = 0; i < m; i++)
		scanf("%d", &t[i]);
	l = 0;
	for (i = 0; i < n; i++)
		push(s[i]);
	for (i = 0; i < n; i++)
		s[i] = pop();
	int min, mid, max;
	int f;
	min = 0;
	max = m + 1;
	while (max - min > 1)
	{
		mid = (max + min) / 2;
		l = 0;
		for (i = 0; i < mid; i++)
			push(t[i]);
		for (i = 0; i < mid; i++)
			tt[i] = pop();
		f = 0;
		for (i = 0; i < mid; i++)
			if (s[i] < tt[i])
				f++;
		if (f > 0)
			max = mid;
		else
			min = mid;
	}
	l = 0;
	for (i = 0; i < min; i++)
		push(t[i]);
	for (i = 0; i < min; i++)
		tt[i] = pop();
	int ans = 0;
	for (i = n, j = min; j >= 0; i--, j--)
	{
		while (s[i] < tt[j])
			i--;
		if (ans < s[i] - tt[j])
			ans = s[i] - tt[j];
	}
	printf("%d\n", ans);
	return 0;
}
0