fork download
  1. class Solution {
  2. int N, M;
  3. vector<vector<int> > dp, vis;
  4. int dx[4] = { 1, 0 , -1, 0 };
  5. int dy[4] = { 0 , 1, 0 , -1 };
  6. bool isoutsize(int x, int y) {
  7. return x < 0 || x >= N || y < 0 || y >= M;
  8. }
  9. public:
  10. int longestIncreasingPath(vector<vector<int>>& matrix) {
  11.  
  12. int n = matrix.size();
  13. if(n == 0)return 0;
  14. int m = matrix[0].size();
  15. N = n, M = m;
  16. dp.resize(n, vector<int>(m, -1));
  17. int ans = 0;
  18. for (int i = 0; i < n; i++) {
  19. for (int j = 0; j < m; j++) {
  20. ans = max(ans, dfs(matrix, i, j));
  21. }
  22. }
  23. return ans;
  24. }
  25. int dfs(vector<vector<int>>& matrix, int x, int y) {
  26. if (isoutsize(x, y)) {
  27. return 0;
  28. }
  29. if (dp[x][y] != -1) {
  30. return dp[x][y];
  31. }
  32. int ans = 0;
  33. for (int i = 0; i < 4; i++) {
  34. int nextx = x + dx[i];
  35. int nexty = y + dy[i];
  36. if(!isoutsize(nextx, nexty) && matrix[x][y] < matrix[nextx][nexty])
  37. ans = max(ans, dfs(matrix , nextx,nexty));
  38. }
  39. return dp[x][y] = ans + 1;
  40. }
  41. };
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
prog.cpp:3:2: error: ‘vector’ does not name a type
  vector<vector<int> > dp, vis;
  ^~~~~~
prog.cpp:10:28: error: ‘vector’ has not been declared
  int longestIncreasingPath(vector<vector<int>>& matrix) {
                            ^~~~~~
prog.cpp:10:34: error: expected ‘,’ or ‘...’ before ‘<’ token
  int longestIncreasingPath(vector<vector<int>>& matrix) {
                                  ^
prog.cpp:25:10: error: ‘vector’ has not been declared
  int dfs(vector<vector<int>>& matrix, int x, int y) {
          ^~~~~~
prog.cpp:25:16: error: expected ‘,’ or ‘...’ before ‘<’ token
  int dfs(vector<vector<int>>& matrix, int x, int y) {
                ^
prog.cpp: In member function ‘int Solution::longestIncreasingPath(int)’:
prog.cpp:12:11: error: ‘matrix’ was not declared in this scope
   int n = matrix.size();
           ^~~~~~
prog.cpp:16:3: error: ‘dp’ was not declared in this scope
   dp.resize(n, vector<int>(m, -1));
   ^~
prog.cpp:16:3: note: suggested alternative: ‘dx’
   dp.resize(n, vector<int>(m, -1));
   ^~
   dx
prog.cpp:16:16: error: ‘vector’ was not declared in this scope
   dp.resize(n, vector<int>(m, -1));
                ^~~~~~
prog.cpp:16:23: error: expected primary-expression before ‘int’
   dp.resize(n, vector<int>(m, -1));
                       ^~~
prog.cpp:20:11: error: ‘max’ was not declared in this scope
     ans = max(ans, dfs(matrix, i, j));
           ^~~
prog.cpp: In member function ‘int Solution::dfs(int)’:
prog.cpp:26:17: error: ‘x’ was not declared in this scope
   if (isoutsize(x, y)) {
                 ^
prog.cpp:26:20: error: ‘y’ was not declared in this scope
   if (isoutsize(x, y)) {
                    ^
prog.cpp:29:7: error: ‘dp’ was not declared in this scope
   if (dp[x][y] != -1) {
       ^~
prog.cpp:29:7: note: suggested alternative: ‘dx’
   if (dp[x][y] != -1) {
       ^~
       dx
prog.cpp:29:10: error: ‘x’ was not declared in this scope
   if (dp[x][y] != -1) {
          ^
prog.cpp:29:13: error: ‘y’ was not declared in this scope
   if (dp[x][y] != -1) {
             ^
prog.cpp:34:16: error: ‘x’ was not declared in this scope
    int nextx = x + dx[i];
                ^
prog.cpp:35:16: error: ‘y’ was not declared in this scope
    int nexty = y + dy[i];
                ^
prog.cpp:36:36: error: ‘matrix’ was not declared in this scope
    if(!isoutsize(nextx, nexty)  && matrix[x][y] < matrix[nextx][nexty])
                                    ^~~~~~
prog.cpp:37:10: error: ‘max’ was not declared in this scope
    ans = max(ans, dfs(matrix , nextx,nexty));
          ^~~
prog.cpp:39:10: error: ‘dp’ was not declared in this scope
   return dp[x][y] = ans + 1;
          ^~
prog.cpp:39:10: note: suggested alternative: ‘dx’
   return dp[x][y] = ans + 1;
          ^~
          dx
prog.cpp:39:13: error: ‘x’ was not declared in this scope
   return dp[x][y] = ans + 1;
             ^
prog.cpp:39:16: error: ‘y’ was not declared in this scope
   return dp[x][y] = ans + 1;
                ^
stdout
Standard output is empty