結果

問題 No.1651 Removing Cards
ユーザー pengin_2000pengin_2000
提出日時 2021-08-20 22:59:54
言語 C
(gcc 12.3.0)
結果
AC  
実行時間 69 ms / 2,000 ms
コード長 1,591 bytes
コンパイル時間 939 ms
コンパイル使用メモリ 29,176 KB
実行使用メモリ 4,388 KB
最終ジャッジ日時 2023-08-04 09:09:18
合計ジャッジ時間 6,293 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 4 ms
4,384 KB
testcase_03 AC 1 ms
4,376 KB
testcase_04 AC 1 ms
4,380 KB
testcase_05 AC 1 ms
4,380 KB
testcase_06 AC 0 ms
4,380 KB
testcase_07 AC 0 ms
4,380 KB
testcase_08 AC 1 ms
4,380 KB
testcase_09 AC 54 ms
4,380 KB
testcase_10 AC 54 ms
4,380 KB
testcase_11 AC 54 ms
4,380 KB
testcase_12 AC 55 ms
4,380 KB
testcase_13 AC 55 ms
4,380 KB
testcase_14 AC 54 ms
4,380 KB
testcase_15 AC 67 ms
4,376 KB
testcase_16 AC 67 ms
4,380 KB
testcase_17 AC 68 ms
4,380 KB
testcase_18 AC 67 ms
4,384 KB
testcase_19 AC 67 ms
4,384 KB
testcase_20 AC 67 ms
4,380 KB
testcase_21 AC 67 ms
4,380 KB
testcase_22 AC 67 ms
4,380 KB
testcase_23 AC 55 ms
4,384 KB
testcase_24 AC 44 ms
4,376 KB
testcase_25 AC 50 ms
4,380 KB
testcase_26 AC 51 ms
4,376 KB
testcase_27 AC 69 ms
4,380 KB
testcase_28 AC 68 ms
4,380 KB
testcase_29 AC 65 ms
4,380 KB
testcase_30 AC 66 ms
4,376 KB
testcase_31 AC 66 ms
4,388 KB
testcase_32 AC 46 ms
4,376 KB
testcase_33 AC 48 ms
4,376 KB
testcase_34 AC 47 ms
4,384 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<stdio.h>
long long int n[100005];
long long int h[100005], l;
int comp_h(long long int a, long long int b)
{
	if (n[h[a]] > n[h[b]])
		return 1;
	else
		return -1;
}
void swap_h(long long int a, long long int b)
{
	long long int f = h[a];
	h[a] = h[b];
	h[b] = f;
	return;
}
void push(long long int ne)
{
	h[l] = ne;
	long long int p = l;
	l++;
	for (; p > 0; p = (p - 1) / 2)
		if (comp_h((p - 1) / 2, p) > 0)
			swap_h((p - 1) / 2, p);
	return;
}
long long int pop()
{
	l--;
	swap_h(0, l);
	long long 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 main()
{
	long long int k, Q;
	scanf("%lld %lld", &k, &Q);
	long long int i, p, q, x;
	for (i = 0; i < Q; i++)
		scanf("%lld", &n[i]);
	for (i = 0; i < Q; i++)
		push(i);
	for (i = 0; i < 1000000000000000018;)
	{
		p = (i + 1) / (k - 1);
		q = (i + 1) % (k - 1);
		if (q == 0)
		{
			p--;
			q += k - 1;
		}
		i = k * p + q;
	}
	x = 0;
	long long int ans[100005];
	while (l > 0)
	{
		i = pop();
		while (x < n[i])
		{
			p = (x + 1) / (k - 1);
			q = (x + 1) % (k - 1);
			if (q == 0)
			{
				p--;
				q += k - 1;
			}
			x = k * p + q;
		}
		x -= x / k + 1;
		ans[i] = x + 1;
	}
	for (i = 0; i < Q; i++)
		printf("%lld\n", ans[i]);
	return 0;
}
0