Skip to content

Instantly share code, notes, and snippets.

@tvhong
Created March 12, 2014 10:34
Show Gist options
  • Save tvhong/9504434 to your computer and use it in GitHub Desktop.
Save tvhong/9504434 to your computer and use it in GitHub Desktop.
#include <cstdio>
#include <algorithm>
#define x first
#define y second
using namespace std;
const int N = 100;
int n, ans;
char a[N][N];
int main() {
scanf("%d", &n);
for (int i=0; i<n; i++) {
scanf("%s", a[i]);
}
int ans = 0;
/*
for (int i=0; i<n; i++)
for (int j=0; j<n; j++)
for (int k=0; k<n-max(i,j); k++) {
if ((a[i][j] != 'B') && (a[i][j+k] != 'B') && (a[i+k][j+k] != 'B') && (a[i+k][j] != 'B')) {
int cnt = 0;
if (a[i][j] == 'J') cnt++;
if (a[i][j+k] == 'J') cnt++;
if (a[i+k][j+k] == 'J') cnt++;
if (a[i+k][j] == 'J') cnt++;
if (cnt >= 3 && k*k > ans) {
ans = k*k;
//printf("answer updated at 1 i=%d, j=%d, k=%d, ans=%d\n", i, j, k, ans);
}
}
}
*/
for (int i=0; i<n; i++)
for (int j=0; j<n; j++)
for (int d1=0; d1<n; d1++)
for (int d2=0; d2<n; d2++) {
pair<int, int> idx[4];
idx[0].x = i;
idx[0].y = j;
idx[1].x = idx[0].x + d1;
idx[1].y = idx[0].y + d2;
idx[2].x = idx[1].x + d2;
idx[2].y = idx[1].y - d1;
idx[3].x = idx[2].x - d1;
idx[3].y = idx[2].y - d2;
/*
if (i == 2 && j == 5 && d1 == 4 && d2 == 1)
printf("(%d %d) (%d %d) (%d %d) (%d %d)\n",
idx[0].x, idx[0].y,
idx[1].x, idx[1].y,
idx[2].x, idx[2].y,
idx[3].x, idx[3].y);
*/
if (idx[1].x >= n || idx[1].y >= n ||
idx[2].x >= n || idx[2].y < 0 ||
idx[3].x < 0 || idx[3].y < 0)
break;
if ((a[idx[0].x][idx[0].y] == 'B') ||
(a[idx[1].x][idx[1].y] == 'B') ||
(a[idx[2].x][idx[2].y] == 'B') ||
(a[idx[3].x][idx[3].y] == 'B'))
continue;
int cnt = 0;
if (a[idx[0].x][idx[0].y] == 'J') cnt++;
if (a[idx[1].x][idx[1].y] == 'J') cnt++;
if (a[idx[2].x][idx[2].y] == 'J') cnt++;
if (a[idx[3].x][idx[3].y] == 'J') cnt++;
if (cnt >= 3 && d1*d1+d2*d2 > ans)
ans = d1*d1 + d2*d2;
}
printf("%d\n", ans);
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment