BCHESS - Bàn cờ tướng

Tác giả: flashmt

Ngôn ngữ: C++

#include <iostream>
#include <algorithm>
#include <cstdio>
#include <cstring>
using namespace std;

char s[2222];
int n, f[2222][2222], g[2222][2222], ans[3], cnt[3];

void update(int val, int &ans, int &cnt)
{
	if (val > ans) ans = val, cnt = 1;
	else cnt += val == ans;
}

int main()
{
	cin >> n;
	for (int i = 1; i <= n; i++) 
	{
		scanf("%s", s + 1);
		for (int j = 1; j <= n; j++)
			if (s[j] == '0')
			{
				f[i][j] = min(f[i - 1][j - 1], min(g[i - 1][j], g[i][j - 1])) + 1;
				g[i][j] = 0;
				update(f[i][j] - 1 + f[i][j] % 2, ans[2], cnt[2]);
				update(f[i][j] - f[i][j] % 2, ans[0], cnt[0]);
			}
			else
			{
				g[i][j] = min(g[i - 1][j - 1], min(f[i - 1][j], f[i][j - 1])) + 1;
				f[i][j] = 0;
				update(g[i][j] - 1 + g[i][j] % 2, ans[1], cnt[1]);
				update(g[i][j] - g[i][j] % 2, ans[0], cnt[0]);
			}
	}
	
	for (int i = 0; i < 3; i++) cout << ans[i] << ' ' << cnt[i] << endl;
}

Download