fork(1) download
  1. /**
  2.  * Definition for a binary tree node.
  3.  * struct TreeNode {
  4.  * int val;
  5.  * TreeNode *left;
  6.  * TreeNode *right;
  7.  * TreeNode() : val(0), left(nullptr), right(nullptr) {}
  8.  * TreeNode(int x) : val(x), left(nullptr), right(nullptr) {}
  9.  * TreeNode(int x, TreeNode *left, TreeNode *right) : val(x), left(left), right(right) {}
  10.  * };
  11.  */
  12. #define tn TreeNode*
  13. #define inf (1<<20)
  14.  
  15.  
  16. map<pair<tn, pair<bool, bool>>, int> dp;
  17.  
  18. class Solution {
  19. int solve(tn root, bool cam, bool parCam){
  20. if(root == NULL){
  21. if(cam)return inf;
  22. else return 0;
  23. }
  24. if(root->left == NULL && root->right == NULL){
  25. if(cam)
  26. return 1;
  27. else{
  28. if(parCam)
  29. return 0;
  30. else return inf;
  31. }
  32. }
  33.  
  34. if(dp.find({root, {cam, parCam}}) != dp.end())
  35. return dp[{root, {cam, parCam}}];
  36. if(cam){
  37. return dp[{root, {cam, parCam}}] = 1 + min(solve(root->left, 0, 1), solve(root->left, 1, 1)) +
  38. min(solve(root->right, 0, 1), solve(root->right, 1, 1));
  39. }
  40. else{
  41. if(parCam){
  42. return dp[{root, {cam, parCam}}] = min(solve(root->left, 0, 0), solve(root->left, 1, 0)) +
  43. min(solve(root->right, 0, 0), solve(root->right, 1, 0));
  44. }
  45. else{
  46. int op1 = solve(root->left, 1, 0) + min(solve(root->right, 0, 0), solve(root->right, 1, 0));
  47. int op2 = solve(root->right, 1, 0) + min(solve(root->left, 0, 0), solve(root->left, 1, 0));
  48. return dp[{root, {cam, parCam}}] = min(op1, op2);
  49. }
  50. }
  51. }
  52. public:
  53. int minCameraCover(TreeNode* root) {
  54. dp.clear();
  55. return min(solve(root, 0, 0), solve(root, 1, 0));
  56. }
  57. };
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
prog.cpp:16:1: error: ‘map’ does not name a type
 map<pair<tn, pair<bool, bool>>, int> dp;
 ^~~
prog.cpp:12:12: error: ‘TreeNode’ has not been declared
 #define tn TreeNode*
            ^~~~~~~~
prog.cpp:19:15: note: in expansion of macro ‘tn’
     int solve(tn root, bool cam, bool parCam){
               ^~
prog.cpp:53:24: error: ‘TreeNode’ has not been declared
     int minCameraCover(TreeNode* root) {
                        ^~~~~~~~
prog.cpp: In member function ‘int Solution::solve(int*, bool, bool)’:
prog.cpp:20:20: error: ‘NULL’ was not declared in this scope
         if(root == NULL){
                    ^~~~
prog.cpp:20:20: note: ‘NULL’ is defined in header ‘<cstddef>’; did you forget to ‘#include <cstddef>’?
prog.cpp:1:1:
+#include <cstddef>
 /**
prog.cpp:20:20:
         if(root == NULL){
                    ^~~~
prog.cpp:24:18: error: request for member ‘left’ in ‘* root’, which is of non-class type ‘int’
         if(root->left == NULL && root->right == NULL){
                  ^~~~
prog.cpp:24:26: error: ‘NULL’ was not declared in this scope
         if(root->left == NULL && root->right == NULL){
                          ^~~~
prog.cpp:24:26: note: ‘NULL’ is defined in header ‘<cstddef>’; did you forget to ‘#include <cstddef>’?
prog.cpp:24:40: error: request for member ‘right’ in ‘* root’, which is of non-class type ‘int’
         if(root->left == NULL && root->right == NULL){
                                        ^~~~~
prog.cpp:34:12: error: ‘dp’ was not declared in this scope
         if(dp.find({root, {cam, parCam}}) != dp.end())
            ^~
prog.cpp:37:20: error: ‘dp’ was not declared in this scope
             return dp[{root, {cam, parCam}}] = 1 + min(solve(root->left, 0, 1), solve(root->left, 1, 1)) +
                    ^~
prog.cpp:37:68: error: request for member ‘left’ in ‘* root’, which is of non-class type ‘int’
             return dp[{root, {cam, parCam}}] = 1 + min(solve(root->left, 0, 1), solve(root->left, 1, 1)) +
                                                                    ^~~~
prog.cpp:37:93: error: request for member ‘left’ in ‘* root’, which is of non-class type ‘int’
             return dp[{root, {cam, parCam}}] = 1 + min(solve(root->left, 0, 1), solve(root->left, 1, 1)) +
                                                                                             ^~~~
prog.cpp:37:52: error: ‘min’ was not declared in this scope
             return dp[{root, {cam, parCam}}] = 1 + min(solve(root->left, 0, 1), solve(root->left, 1, 1)) +
                                                    ^~~
prog.cpp:38:41: error: request for member ‘right’ in ‘* root’, which is of non-class type ‘int’
                         min(solve(root->right, 0, 1), solve(root->right, 1, 1));
                                         ^~~~~
prog.cpp:38:67: error: request for member ‘right’ in ‘* root’, which is of non-class type ‘int’
                         min(solve(root->right, 0, 1), solve(root->right, 1, 1));
                                                                   ^~~~~
prog.cpp:42:24: error: ‘dp’ was not declared in this scope
                 return dp[{root, {cam, parCam}}] = min(solve(root->left, 0, 0), solve(root->left, 1, 0)) +
                        ^~
prog.cpp:42:68: error: request for member ‘left’ in ‘* root’, which is of non-class type ‘int’
                 return dp[{root, {cam, parCam}}] = min(solve(root->left, 0, 0), solve(root->left, 1, 0)) +
                                                                    ^~~~
prog.cpp:42:93: error: request for member ‘left’ in ‘* root’, which is of non-class type ‘int’
                 return dp[{root, {cam, parCam}}] = min(solve(root->left, 0, 0), solve(root->left, 1, 0)) +
                                                                                             ^~~~
prog.cpp:42:52: error: ‘min’ was not declared in this scope
                 return dp[{root, {cam, parCam}}] = min(solve(root->left, 0, 0), solve(root->left, 1, 0)) +
                                                    ^~~
prog.cpp:43:41: error: request for member ‘right’ in ‘* root’, which is of non-class type ‘int’
                         min(solve(root->right, 0, 0), solve(root->right, 1, 0));
                                         ^~~~~
prog.cpp:43:67: error: request for member ‘right’ in ‘* root’, which is of non-class type ‘int’
                         min(solve(root->right, 0, 0), solve(root->right, 1, 0));
                                                                   ^~~~~
prog.cpp:46:39: error: request for member ‘left’ in ‘* root’, which is of non-class type ‘int’
                 int op1 = solve(root->left, 1, 0) + min(solve(root->right, 0, 0), solve(root->right, 1, 0));
                                       ^~~~
prog.cpp:46:69: error: request for member ‘right’ in ‘* root’, which is of non-class type ‘int’
                 int op1 = solve(root->left, 1, 0) + min(solve(root->right, 0, 0), solve(root->right, 1, 0));
                                                                     ^~~~~
prog.cpp:46:95: error: request for member ‘right’ in ‘* root’, which is of non-class type ‘int’
                 int op1 = solve(root->left, 1, 0) + min(solve(root->right, 0, 0), solve(root->right, 1, 0));
                                                                                               ^~~~~
prog.cpp:46:53: error: ‘min’ was not declared in this scope
                 int op1 = solve(root->left, 1, 0) + min(solve(root->right, 0, 0), solve(root->right, 1, 0));
                                                     ^~~
prog.cpp:47:39: error: request for member ‘right’ in ‘* root’, which is of non-class type ‘int’
                 int op2 = solve(root->right, 1, 0) + min(solve(root->left, 0, 0), solve(root->left, 1, 0));
                                       ^~~~~
prog.cpp:47:70: error: request for member ‘left’ in ‘* root’, which is of non-class type ‘int’
                 int op2 = solve(root->right, 1, 0) + min(solve(root->left, 0, 0), solve(root->left, 1, 0));
                                                                      ^~~~
prog.cpp:47:95: error: request for member ‘left’ in ‘* root’, which is of non-class type ‘int’
                 int op2 = solve(root->right, 1, 0) + min(solve(root->left, 0, 0), solve(root->left, 1, 0));
                                                                                               ^~~~
prog.cpp:48:24: error: ‘dp’ was not declared in this scope
                 return dp[{root, {cam, parCam}}] = min(op1, op2);
                        ^~
prog.cpp: In member function ‘int Solution::minCameraCover(int*)’:
prog.cpp:54:9: error: ‘dp’ was not declared in this scope
         dp.clear();
         ^~
prog.cpp:55:16: error: ‘min’ was not declared in this scope
         return min(solve(root, 0, 0), solve(root, 1, 0));
                ^~~
stdout
Standard output is empty