Last active
April 27, 2017 10:52
-
-
Save znxkznxk1030/ed47533f7a0e50ae81aac9898887aba3 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdio.h> | |
#include <iostream> | |
#include <stack> | |
#include <cstring> | |
#define ll long long int | |
#define MAX(a,b) (a)>(b)?(a):(b) | |
#define MIN(a,b) (a)>(b)?(b):(a) | |
using namespace std; | |
int n, m; | |
int nx[2] = { 1, 0 }, ny[2] = { 1, 0 }; | |
int matrix[543][543]; | |
int func(int x, int y) | |
{ | |
int sum = 0; | |
int a, b; | |
a = b = 0; | |
for (int i = 0; i < 4; i++) { | |
a += matrix[x][y + i]; | |
b += matrix[x + i][y]; | |
} | |
sum = MAX(sum, MAX(a, b)); | |
a = 0; | |
a += matrix[x][y]; | |
a += matrix[x][y + 1]; | |
a += matrix[x + 1][y + 1]; | |
a += matrix[x + 2][y + 1]; | |
sum = MAX(sum, a); | |
a = 0; | |
a += matrix[x + 1][y]; | |
a += matrix[x + 1][y + 1]; | |
a += matrix[x + 1][y + 2]; | |
a += matrix[x][y + 2]; | |
sum = MAX(sum, a); | |
a = 0; | |
a += matrix[x][y]; | |
a += matrix[x + 1][y]; | |
a += matrix[x + 2][y]; | |
a += matrix[x + 2][y + 1]; | |
sum = MAX(sum, a); | |
a = 0; | |
a += matrix[x][y]; | |
a += matrix[x + 1][y]; | |
a += matrix[x][y + 1]; | |
a += matrix[x][y + 2]; | |
sum = MAX(sum, a); | |
a = 0; | |
a += matrix[x][y + 1]; | |
a += matrix[x][y]; | |
a += matrix[x + 1][y]; | |
a += matrix[x + 2][y]; | |
sum = MAX(sum, a); | |
a = 0; | |
a += matrix[x][y]; | |
a += matrix[x + 1][y]; | |
a += matrix[x + 1][y + 1]; | |
a += matrix[x + 1][y + 2]; | |
sum = MAX(sum, a); | |
a = 0; | |
a += matrix[x][y]; | |
a += matrix[x][y + 1]; | |
a += matrix[x][y + 2]; | |
a += matrix[x + 1][y + 2]; | |
sum = MAX(sum, a); | |
a = 0; | |
a += matrix[x + 2][y]; | |
a += matrix[x + 2][y + 1]; | |
a += matrix[x + 1][y + 1]; | |
a += matrix[x][y + 1]; | |
sum = MAX(sum, a); | |
a = 0; | |
a += matrix[x][y]; | |
a += matrix[x + 1][y]; | |
a += matrix[x][y + 1]; | |
a += matrix[x + 1][y + 1]; | |
sum = MAX(sum, a); | |
a = 0; | |
a += matrix[x][y]; | |
a += matrix[x + 1][y]; | |
a += matrix[x + 1][y + 1]; | |
a += matrix[x + 2][y + 1]; | |
sum = MAX(sum, a); | |
a = 0; | |
a += matrix[x][y + 1]; | |
a += matrix[x][y + 2]; | |
a += matrix[x + 1][y + 1]; | |
a += matrix[x + 1][y]; | |
sum = MAX(sum, a); | |
a = 0; | |
a += matrix[x][y + 1]; | |
a += matrix[x + 1][y + 1]; | |
a += matrix[x + 1][y]; | |
a += matrix[x + 2][y]; | |
sum = MAX(sum, a); | |
a = 0; | |
a += matrix[x][y]; | |
a += matrix[x][y + 1]; | |
a += matrix[x + 1][y + 1]; | |
a += matrix[x + 1][y + 2]; | |
sum = MAX(sum, a); | |
a = 0; | |
a += matrix[x][y]; | |
a += matrix[x + 1][y]; | |
a += matrix[x + 1][y + 1]; | |
a += matrix[x + 2][y]; | |
sum = MAX(sum, a); | |
a = 0; | |
a += matrix[x][y]; | |
a += matrix[x][y + 1]; | |
a += matrix[x][y + 2]; | |
a += matrix[x + 1][y + 1]; | |
sum = MAX(sum, a); | |
a = 0; | |
a += matrix[x + 1][y]; | |
a += matrix[x][y + 1]; | |
a += matrix[x + 1][y + 1]; | |
a += matrix[x + 2][y + 1]; | |
sum = MAX(sum, a); | |
a = 0; | |
a += matrix[x][y + 1]; | |
a += matrix[x + 1][y + 1]; | |
a += matrix[x + 1][y]; | |
a += matrix[x + 1][y + 2]; | |
sum = MAX(sum, a); | |
return sum; | |
} | |
int main() | |
{ | |
int ans = 0; | |
scanf("%d %d", &n, &m); | |
for (int i = 0; i < n; i++) for (int j = 0; j < m; j++) | |
scanf("%d", &matrix[i][j]); | |
for (int i = 0; i < n; i++) for (int j = 0; j < m; j++) | |
{ | |
ans = MAX(ans, func(i, j)); | |
} | |
printf("%d\n", ans); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment