fork download
  1. #pragma GCC optimize ("Ofast")
  2. #include<bits/stdc++.h>
  3. using namespace std;
  4. #define main dummy_main
  5. int main(){
  6. return 0;
  7. }
  8. #undef main
  9. #define TreeNode dummy_TreeNode
  10. struct TreeNode{
  11. }
  12. ;
  13. #undef TreeNode
  14. int sz;
  15. int arr[10000];
  16. TreeNode node[10000];
  17. int us;
  18. void dfs(TreeNode *n){
  19. if(n==NULL){
  20. return;
  21. }
  22. arr[sz++] = n->val;
  23. dfs(n->left);
  24. dfs(n->right);
  25. }
  26. TreeNode* construct(int a, int b){
  27. if(a > b){
  28. return NULL;
  29. }
  30. int c = (a+b) / 2;
  31. int now = us++;
  32. node[now].val = arr[c];
  33. node[now].left = construct(a,c-1);
  34. node[now].right = construct(c+1,b);
  35. return &node[now];
  36. }
  37. class Solution{
  38. public:
  39. TreeNode* balanceBST(TreeNode* root){
  40. sz = us = 0;
  41. dfs(root);
  42. sort(arr, arr+sz);
  43. return construct(0, sz-1);
  44. }
  45. }
  46. ;
  47. // cLay varsion 20200325-1
  48.  
  49. // --- original code ---
  50. // #define main dummy_main
  51. // {}
  52. // #undef main
  53. //
  54. // #define TreeNode dummy_TreeNode
  55. // struct TreeNode {};
  56. // #undef TreeNode
  57. //
  58. // int sz, arr[1d4];
  59. // TreeNode node[1d4]; int us;
  60. //
  61. // void dfs(TreeNode *n){
  62. // if(n==NULL) return;
  63. // arr[sz++] = n->val;
  64. // dfs(n->left);
  65. // dfs(n->right);
  66. // }
  67. //
  68. // TreeNode* construct(int a, int b){
  69. // if(a > b) return NULL;
  70. // int c = (a+b) / 2, now = us++;
  71. // node[now].val = arr[c];
  72. // node[now].left = construct(a,c-1);
  73. // node[now].right = construct(c+1,b);
  74. // return &node[now];
  75. // }
  76. //
  77. // class Solution {
  78. // public:
  79. // TreeNode* balanceBST(TreeNode* root) {
  80. // sz = us = 0;
  81. // dfs(root);
  82. // sort(arr, arr+sz);
  83. // return construct(0, sz-1);
  84. // }
  85. // };
  86.  
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
prog.cpp:16:1: error: ‘TreeNode’ does not name a type; did you mean ‘remove’?
 TreeNode node[10000];
 ^~~~~~~~
 remove
prog.cpp:18:10: error: variable or field ‘dfs’ declared void
 void dfs(TreeNode *n){
          ^~~~~~~~
prog.cpp:18:10: error: ‘TreeNode’ was not declared in this scope
prog.cpp:18:10: note: suggested alternative: ‘remove’
 void dfs(TreeNode *n){
          ^~~~~~~~
          remove
prog.cpp:18:20: error: ‘n’ was not declared in this scope
 void dfs(TreeNode *n){
                    ^
prog.cpp:18:20: note: suggested alternative: ‘yn’
 void dfs(TreeNode *n){
                    ^
                    yn
prog.cpp:26:1: error: ‘TreeNode’ does not name a type; did you mean ‘remove’?
 TreeNode* construct(int a, int b){
 ^~~~~~~~
 remove
prog.cpp:39:3: error: ‘TreeNode’ does not name a type; did you mean ‘remove’?
   TreeNode* balanceBST(TreeNode* root){
   ^~~~~~~~
   remove
stdout
Standard output is empty