...
Thu Aug 22 2024 17:30:29 GMT+0000 (Coordinated Universal Time)
Saved by
@besho
#include <bits/stdc++.h>
using namespace std;
int main(){
ios_base::sync_with_stdio(0);
cin.tie(NULL);
int n;
cin >> n;
vector<vector<int>> S(n);
for(int i = 0; i < n; i++){
for(int j = 0; j <= i; j++){
int a;
cin >> a;
S[i].push_back(a);
}
}
vector<vector<int>> dp(n);
for(int i = 0; i < n; i++){
dp[i] = vector<int>(i + 1, 1);
}
dp[0][0] = S[0][0];
for(int i = 1; i < n; i++){
for(int j = 0; j <= i; j++){
if (j == 0) {
dp[i][j] = dp[i-1][j] * S[i][j];
} else if (j == i) {
dp[i][j] = dp[i-1][j-1] * S[i][j];
} else {
if(S[i][j] > 0){
dp[i][j] = max(dp[i-1][j], dp[i-1][j-1]) * S[i][j];
} else {
dp[i][j] = min(dp[i-1][j], dp[i-1][j-1]) * S[i][j];
}
}
}
}
cout << *max_element(dp[n-1].begin(), dp[n-1].end());
return 0;
}
content_copyCOPY
Comments