結果

問題 No.2094 Symmetry
ユーザー pengin_2000pengin_2000
提出日時 2022-10-07 21:46:59
言語 C
(gcc 12.3.0)
結果
AC  
実行時間 91 ms / 2,000 ms
コード長 1,666 bytes
コンパイル時間 231 ms
コンパイル使用メモリ 30,512 KB
実行使用メモリ 6,088 KB
最終ジャッジ日時 2023-09-03 01:19:47
合計ジャッジ時間 3,959 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 1 ms
4,380 KB
testcase_03 AC 1 ms
4,376 KB
testcase_04 AC 1 ms
4,380 KB
testcase_05 AC 1 ms
4,376 KB
testcase_06 AC 1 ms
4,376 KB
testcase_07 AC 1 ms
4,380 KB
testcase_08 AC 1 ms
4,376 KB
testcase_09 AC 78 ms
6,036 KB
testcase_10 AC 71 ms
5,952 KB
testcase_11 AC 91 ms
5,992 KB
testcase_12 AC 80 ms
5,960 KB
testcase_13 AC 64 ms
5,892 KB
testcase_14 AC 80 ms
6,088 KB
testcase_15 AC 87 ms
5,988 KB
testcase_16 AC 74 ms
6,004 KB
testcase_17 AC 62 ms
6,020 KB
testcase_18 AC 70 ms
5,952 KB
testcase_19 AC 83 ms
5,892 KB
testcase_20 AC 83 ms
6,040 KB
testcase_21 AC 81 ms
5,908 KB
testcase_22 AC 73 ms
5,948 KB
testcase_23 AC 69 ms
5,944 KB
testcase_24 AC 69 ms
5,988 KB
testcase_25 AC 73 ms
5,960 KB
testcase_26 AC 74 ms
6,044 KB
testcase_27 AC 1 ms
4,380 KB
testcase_28 AC 46 ms
5,988 KB
testcase_29 AC 1 ms
4,376 KB
testcase_30 AC 46 ms
6,076 KB
testcase_31 AC 57 ms
5,956 KB
testcase_32 AC 59 ms
5,948 KB
testcase_33 AC 1 ms
4,380 KB
testcase_34 AC 51 ms
5,948 KB
testcase_35 AC 46 ms
5,956 KB
testcase_36 AC 63 ms
5,960 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<stdio.h>
long long int h[300005], l;
int comp_h(long long int a, long long int b)
{
	if (h[a] < 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);
	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[502][502];
long long int c[502][502];
int main()
{
	long long int n, k;
	scanf("%lld %lld", &n, &k);
	n *= 2;
	long long int i, j;
	for (i = 0; i < n; i++)
		scanf("%s", s[i]);
	for (i = 0; i < n; i++)
		for (j = 0; j < n; j++)
			scanf("%lld", &c[i][j]);
	l = 0;
	for (i = 0; i < n; i++)
		for (j = 0; j < n; j++)
			push(c[i][j]);
	long long int cnt = 0;
	for (i = 0; i < n; i++)
		for (j = 0; j < n; j++)
			if (s[i][j] == '#')
				cnt++;
	long long int ans = 0, v;
	for (i = 0; i < cnt; i++)
		ans += pop();
	if (cnt % 2 == 0)
	{
		l = 0;
		for (i = 0; i < n; i++)
			for (j = 0; j < n / 2; j++)
				push(c[i][j] + c[i][n - j - 1]);
		v = k;
		for (i = 0; i < cnt / 2; i++)
			v += pop();
		if (ans < v)
			ans = v;
	}
	printf("%lld\n", ans);
	return 0;
}
0