結果

問題 No.2463 ストレートフラッシュ
ユーザー 👑 ygussanyygussany
提出日時 2023-09-08 21:52:19
言語 C
(gcc 12.3.0)
結果
AC  
実行時間 78 ms / 2,000 ms
コード長 1,290 bytes
コンパイル時間 1,134 ms
コンパイル使用メモリ 30,304 KB
実行使用メモリ 4,844 KB
最終ジャッジ日時 2023-09-08 21:52:25
合計ジャッジ時間 2,753 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 0 ms
4,376 KB
testcase_02 AC 1 ms
4,376 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,380 KB
testcase_07 AC 1 ms
4,380 KB
testcase_08 AC 1 ms
4,380 KB
testcase_09 AC 1 ms
4,380 KB
testcase_10 AC 1 ms
4,376 KB
testcase_11 AC 1 ms
4,376 KB
testcase_12 AC 1 ms
4,376 KB
testcase_13 AC 56 ms
4,380 KB
testcase_14 AC 61 ms
4,824 KB
testcase_15 AC 57 ms
4,376 KB
testcase_16 AC 61 ms
4,720 KB
testcase_17 AC 72 ms
4,484 KB
testcase_18 AC 78 ms
4,756 KB
testcase_19 AC 78 ms
4,708 KB
testcase_20 AC 77 ms
4,760 KB
testcase_21 AC 70 ms
4,844 KB
testcase_22 AC 71 ms
4,728 KB
testcase_23 AC 71 ms
4,816 KB
testcase_24 AC 71 ms
4,844 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <stdio.h>

void chmin(int *a, int b)
{
	if (*a > b) *a = b;
}

void merge_sort(int n, int x[])
{
	static int y[6] = {};
	if (n <= 1) return;
	merge_sort(n / 2, &(x[0]));
	merge_sort((n + 1) / 2, &(x[n/2]));
	
	int i, p, q;
	for (i = 0, p = 0, q = n / 2; i < n; i++) {
		if (p >= n / 2) y[i] = x[q++];
		else if (q >= n) y[i] = x[p++];
		else y[i] = (x[p] < x[q])? x[p++]: x[q++];
	}
	for (i = 0; i < n; i++) x[i] = y[i];
}

int solve(int x[])
{
	merge_sort(5, x);
	
	int i, j, k, ans = 0;
	for (i = 5, k = 0; k < 5 && x[k] <= i; k++);
	while (k < 5) {
		j = (x[k] - i + (5 - k) - 1) / (5 - k);
		ans += j;
		i += j * (5 - k);
		for (; k < 5 && x[k] <= i; k++);
	}
	return ans;
}

int main()
{
	int i, N, M, n[250001], m[250001], pos[501][501];
	scanf("%d %d", &N, &M);
	for (i = 1; i <= N * M; i++) {
		scanf("%d %d", &(n[i]), &(m[i]));
		pos[m[i]][n[i]] = i;
	}
	
	int j, x[6], ans = N * M;
	for (i = 1; i <= M; i++) {
		for (j = 1; j <= N - 4; j++) {
			x[0] = pos[i][j];
			x[1] = pos[i][j+1];
			x[2] = pos[i][j+2];
			x[3] = pos[i][j+3];
			x[4] = pos[i][j+4];
			chmin(&ans, solve(x));
		}
		x[0] = pos[i][N-3];
		x[1] = pos[i][N-2];
		x[2] = pos[i][N-1];
		x[3] = pos[i][N];
		x[4] = pos[i][1];
		chmin(&ans, solve(x));
	}
	printf("%d\n", ans);
	fflush(stdout);
	return 0;
}
0