1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81
| #include <iostream> #include <cstdio> #include <algorithm> #include <cstring> #define init(x) memset (x,0,sizeof (x)) #define ll long long #define ull unsigned long long #define INF 0x3f3f3f3f using namespace std; const int MAX = 1e3 + 5; const int MOD = 1e9 + 7; inline int read (); int n,cnt,ans; int a[MAX][MAX],num[MAX]; bool vis[MAX]; void search (int x,int y,int st); int work (int x,int y); int main () { freopen ("pacman.in","r",stdin); freopen ("pacman.out","w",stdout); n = read (); for (int i = 1;i <= n;++i) for (int j = 1;j <= n;++j) a[i][j] = read (); for (int i = 1;i <= n;++i) { cnt = 0; if (i == 1) for (int j = 1;j <= n;++j) cnt += a[j][j]; else if (i == n) for (int j = 1;j <= n;++j) cnt += a[n - j + 1][j]; else search (1,i,1); num[i] = cnt; } for (int i = 1;i <= n;++i) for (int j = i + 1;j <= n;++j) ans = max (ans,work (i,j)); printf ("%d\n",ans); return 0; } inline int read () { int s = 0;int f = 1; char ch = getchar (); while ((ch < '0' || ch > '9') && ch != EOF) { if (ch == '-') f = -1; ch = getchar (); } while (ch >= '0' && ch <= '9') { s = s * 10 + ch - '0'; ch = getchar (); } return s * f; } void search (int x,int y,int st) { if (x == 1) { if (vis[y]) return ; else vis[y] = 1; } cnt += a[x][y]; if (y == 1) st = 3; if (y == n) st = 2; if (x == n) st = 4; if (st == 1) search (x + 1,y + 1,st); if (st == 2) search (x + 1,y - 1,st); if (st == 3) search (x - 1,y + 1,st); if (st == 4) search (x - 1,y - 1,st); } int work (int x,int y) { int sum = num[x] + num[y],same = 0; if ((y - x) % 2 == 1) return sum; int len = (y - x) / 2; same += a[len + 1][x + len]; if (x + len != len + 1) same += a[x + len][len + 1]; if ((n - x) + 1 - len != x + len && n - len != 1 + len && (n - x) + 1 - len != 1 + len && n - len != x + len) same += a[(n - x) + 1 - len][n - len]; if ((n - x) + 1 - len != x + len && n - len != 1 + len && (n - x) + 1 - len != 1 + len && n - len != x + len && (n - x + 1) - len != n - len) same += a[n - len][(n - x) + 1 - len]; return sum - same; }
|