fork download
  1. #pragma GCC optimize ("Ofast")
  2. #include<bits/stdc++.h>
  3. using namespace std;
  4. #define MD (1000000007U)
  5. template<class S, class T> inline S min_L(S a,T b){
  6. return a<=b?a:b;
  7. }
  8. template<class S, class T> inline S max_L(S a,T b){
  9. return a>=b?a:b;
  10. }
  11. #define main dummy_main
  12. int main(){
  13. return 0;
  14. }
  15. #undef main
  16. long long mx[15][15];
  17. long long mn[15][15];
  18. class Solution{
  19. public:
  20. int maxProductPath(vector<vector<int>>& A){
  21. int i, j;
  22. int x = A.size();
  23. int y = A[0].size();
  24. mx[0][0] = mn[0][0] = A[0][0];
  25. for(i=(1);i<(x);i++){
  26. mx[i][0] = mn[i][0] = mn[i-1][0] * A[i][0];
  27. }
  28. for(j=(1);j<(y);j++){
  29. mx[0][j] = mn[0][j] = mn[0][j-1] * A[0][j];
  30. }
  31. for(i=(1);i<(x);i++){
  32. for(j=(1);j<(y);j++){
  33. mx[i][j] =max_L(max_L(max_L(mx[i-1][j]*A[i][j], mn[i-1][j]*A[i][j]), mx[i][j-1]*A[i][j]), mn[i][j-1]*A[i][j]);
  34. mn[i][j] =min_L(min_L(min_L(mx[i-1][j]*A[i][j], mn[i-1][j]*A[i][j]), mx[i][j-1]*A[i][j]), mn[i][j-1]*A[i][j]);
  35. }
  36. }
  37. if(mx[x-1][y-1] < 0){
  38. return -1;
  39. }
  40. return mx[x-1][y-1] % MD;
  41. }
  42. }
  43. ;
  44. // cLay varsion 20200920-1
  45.  
  46. // --- original code ---
  47. // #define main dummy_main
  48. // {}
  49. // #undef main
  50. //
  51. // ll mx[15][15], mn[15][15];
  52. //
  53. // class Solution {
  54. // public:
  55. // int maxProductPath(vector<vector<int>>& A) {
  56. // int x = A.size(), y = A[0].size();
  57. // mx[0][0] = mn[0][0] = A[0][0];
  58. // rep(i,1,x) mx[i][0] = mn[i][0] = mn[i-1][0] * A[i][0];
  59. // rep(j,1,y) mx[0][j] = mn[0][j] = mn[0][j-1] * A[0][j];
  60. // rep(i,1,x) rep(j,1,y){
  61. // mx[i][j] = max(mx[i-1][j]*A[i][j], mn[i-1][j]*A[i][j], mx[i][j-1]*A[i][j], mn[i][j-1]*A[i][j]);
  62. // mn[i][j] = min(mx[i-1][j]*A[i][j], mn[i-1][j]*A[i][j], mx[i][j-1]*A[i][j], mn[i][j-1]*A[i][j]);
  63. // }
  64. // if(mx[x-1][y-1] < 0) return -1;
  65. // return mx[x-1][y-1] % MD;
  66. // }
  67. // };
  68.  
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
/usr/bin/ld: /usr/lib/gcc/x86_64-linux-gnu/8/../../../x86_64-linux-gnu/Scrt1.o: in function `_start':
(.text+0x20): undefined reference to `main'
collect2: error: ld returned 1 exit status
stdout
Standard output is empty