Untitled
TEXT
views 26
,
size 2031 b
``````#include <iostream>
using namespace std;
int main() {
int n;
cin >> n;
int arr[100][100];
bool visited[100][100];
for (int  i = 0 ; i < n ; i ++) {
for (int j = 0 ; j < n ; j ++) {
cin >> arr[i][j];
visited[i][j] = false;
}
}
int max = 0, count = 0, sum = 0;
int xMove[8] = {0,1,1,0,-1,-1,1,-1};
int yMove[8] = {-1,1,0,1,1,-1,-1,0};
int xPos = 0, yPos = 0;
while (xPos <= n - 1 && yPos <= n - 1) {
sum = arr[yPos][xPos];
int maxInNeb = 0;
for (int move = 0 ; move < 8 ; move ++) {
yPos +=  yMove[move];
xPos += xMove[move];
if (xPos >= 0 && xPos <= n - 1 && yPos >= 0 && yPos <= n - 1  ) {
sum += arr[yPos][xPos];
if (sum > maxInNeb) {
maxInNeb = sum;
}
sum -= arr[yPos][xPos];

}
yPos -=  yMove[move];
xPos -= xMove[move];
}
if (maxInNeb > max) {

max = maxInNeb;
}
xPos++;
if (xPos == n  && yPos != n - 1) {
xPos = 0;
yPos++;
}
}
yPos = 0;
xPos = 0;
while (xPos <= n - 1 && yPos <= n - 1) {
sum = arr[yPos][xPos];
int maxInNeb = 0;
for (int move = 0 ; move < 8 ; move ++) {
yPos +=  yMove[move];
xPos += xMove[move];
if (xPos >= 0 && xPos <= n - 1 && yPos >= 0 && yPos <= n - 1  ) {
sum += arr[yPos][xPos];
if (sum == max) {
count++;
}
sum -= arr[yPos][xPos];

}
yPos -=  yMove[move];
xPos -= xMove[move];
}
xPos++;
if (xPos == n  && yPos != n - 1) {
xPos = 0;
yPos++;
}
}

cout << max << " " << count/2;
}``````