-
Notifications
You must be signed in to change notification settings - Fork 0
/
largest-product-in-a-grid.cpp
48 lines (44 loc) · 1.06 KB
/
largest-product-in-a-grid.cpp
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
// https://www.hackerrank.com/contests/projecteuler/challenges/euler011/problem
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
int main()
{
int grid[20][20];
for(int i = 0 ; i< 20 ; i ++)
{
for(int j = 0 ; j < 20; j++)
cin >> grid[i][j];
}
int ans ;
int mx = 0;
for(int i = 0; i < 20 ; i ++)
{
for(int j = 0 ; j < 20 ; j ++ )
{
int p[4] = { 1 , 1, 1 , 1};
int k = 0;
while( k<= 3)
{
if( i < 17)
{
p[0] *= grid[i + k][j];
}
if( j < 17)
{
p[1] *= grid[i][j + k];
}
if(j < 17 && i < 17)
{
p[2] *= grid[i + k][j + k];
}
if( i < 17 && j > 2)
p[3] *= grid[ i + k][j - k];
k++;
}
sort(p , p + 4);
ans = max(ans , p[3]);
}
}
cout << ans << endl;
}