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 chmax(S &a, T b){
  6. if(a<b){
  7. a=b;
  8. }
  9. return a;
  10. }
  11. #define main dummy_main
  12. int main(){
  13. return 0;
  14. }
  15. #undef main
  16. #define TreeNode dummy_TreeNode
  17. struct TreeNode{
  18. }
  19. ;
  20. #undef TreeNode
  21. int sz;
  22. int s[100000];
  23. int getsum(TreeNode *root){
  24. if(root==NULL){
  25. return 0;
  26. }
  27. int res = root->val + getsum(root->left) + getsum(root->right);
  28. s[sz++] = res;
  29. return res;
  30. }
  31. class Solution{
  32. public:
  33. int maxProduct(TreeNode* root){
  34. int i;
  35. long long all;
  36. long long res = 0;
  37. sz = 0;
  38. all = getsum(root);
  39. for(i=(0);i<(sz);i++){
  40. chmax(res, s[i] * (all - s[i]));
  41. }
  42. return res % MD;
  43. }
  44. }
  45. ;
  46. // cLay varsion 20200214-1
  47.  
  48. // --- original code ---
  49. // #define main dummy_main
  50. // {}
  51. // #undef main
  52. //
  53. // #define TreeNode dummy_TreeNode
  54. // struct TreeNode {};
  55. // #undef TreeNode
  56. //
  57. // int sz, s[1d5];
  58. //
  59. // int getsum(TreeNode *root){
  60. // if(root==NULL) return 0;
  61. // int res = root->val + getsum(root->left) + getsum(root->right);
  62. // s[sz++] = res;
  63. // return res;
  64. // }
  65. //
  66. // class Solution {
  67. // public:
  68. // int maxProduct(TreeNode* root) {
  69. // ll all, res = 0;
  70. // sz = 0;
  71. // all = getsum(root);
  72. // rep(i,sz) res >?= s[i] * (all - s[i]);
  73. // return res % MD;
  74. // }
  75. // };
  76.  
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
prog.cpp:23:12: error: ‘TreeNode’ was not declared in this scope
 int getsum(TreeNode *root){
            ^~~~~~~~
prog.cpp:23:12: note: suggested alternative: ‘remove’
 int getsum(TreeNode *root){
            ^~~~~~~~
            remove
prog.cpp:23:22: error: ‘root’ was not declared in this scope
 int getsum(TreeNode *root){
                      ^~~~
prog.cpp:23:22: note: suggested alternative: ‘rint’
 int getsum(TreeNode *root){
                      ^~~~
                      rint
prog.cpp:33:18: error: ‘TreeNode’ has not been declared
   int maxProduct(TreeNode* root){
                  ^~~~~~~~
prog.cpp: In member function ‘int Solution::maxProduct(int*)’:
prog.cpp:38:22: error: ‘getsum’ cannot be used as a function
     all = getsum(root);
                      ^
stdout
Standard output is empty