fork download
  1. #pragma GCC optimize("Ofast")
  2. #pragma GCC optimize("unroll-loops")
  3. #pragma GCC optimize("inline")
  4. #include<bits/stdc++.h>
  5. using namespace std;
  6. template<class T> struct cLtraits_identity{
  7. using type = T;
  8. }
  9. ;
  10. template<class T> using cLtraits_try_make_signed =
  11. typename conditional<
  12. is_integral<T>::value,
  13. make_signed<T>,
  14. cLtraits_identity<T>
  15. >::type;
  16. template <class S, class T> struct cLtraits_common_type{
  17. using tS = typename cLtraits_try_make_signed<S>::type;
  18. using tT = typename cLtraits_try_make_signed<T>::type;
  19. using type = typename common_type<tS,tT>::type;
  20. }
  21. ;
  22. template<class S, class T> inline auto min_L(S a, T b)
  23. -> typename cLtraits_common_type<S,T>::type{
  24. return (typename cLtraits_common_type<S,T>::type) a <= (typename cLtraits_common_type<S,T>::type) b ? a : b;
  25. }
  26. template<class T> void Unique_L(int &N, T A[], int sorted=0){
  27. int i;
  28. int k;
  29. if(!sorted){
  30. sort(A, A+N);
  31. }
  32. k = 0;
  33. for(i=(0);i<(N);i++){
  34. if(k==0 || A[k-1]!=A[i]){
  35. A[k++] = A[i];
  36. }
  37. }
  38. N = k;
  39. }
  40. template<class T> struct Arr2d{
  41. int n1;
  42. int n2;
  43. int mem1;
  44. int mem2;
  45. T**d;
  46. T* operator[](int a){
  47. return d[a];
  48. }
  49. int set_cumulative_sum45;
  50. int cumulative_sum45_mem;
  51. T**cumulative_sum45;
  52. void setSum45(void){
  53. int i;
  54. int j;
  55. set_cumulative_sum45 = 1;
  56. if(cumulative_sum45_mem < n1+n2+1){
  57. for(i=(0);i<(cumulative_sum45_mem);i++){
  58. delete[] cumulative_sum45[i];
  59. }
  60. delete[] cumulative_sum45;
  61. cumulative_sum45_mem = n1+n2+1;
  62. cumulative_sum45 = new T*[cumulative_sum45_mem];
  63. for(i=(0);i<(cumulative_sum45_mem);i++){
  64. cumulative_sum45[i] = new T[cumulative_sum45_mem];
  65. }
  66. }
  67. for(i=(0);i<(n1+n2+1);i++){
  68. for(j=(0);j<(n1+n2+1);j++){
  69. cumulative_sum45[i][j] = 0;
  70. }
  71. }
  72. for(i=(0);i<(n1);i++){
  73. for(j=(0);j<(n2);j++){
  74. cumulative_sum45[n1-i+j][i+j+1] += d[i][j];
  75. }
  76. }
  77. for(i=(0);i<(n1+n2);i++){
  78. for(j=(0);j<(n1+n2);j++){
  79. cumulative_sum45[i+1][j+1] += cumulative_sum45[i+1][j] + cumulative_sum45[i][j+1] - cumulative_sum45[i][j];
  80. }
  81. }
  82. }
  83. T getSum45(int r1, int c1, int r2, int c2){
  84. int x1;
  85. int x2;
  86. int y1;
  87. int y2;
  88. if(!set_cumulative_sum45){
  89. setSum45();
  90. }
  91. x1 = n1 - 1 - r1 + c1;
  92. y1 = r1 + c1;
  93. x2 = n1 - 1 - r2 + c2;
  94. y2 = r2 + c2;
  95. if(x1 > x2){
  96. swap(x1, x2);
  97. }
  98. if(y1 > y2){
  99. swap(y1, y2);
  100. }
  101. return cumulative_sum45[x2+1][y2+1] - cumulative_sum45[x2+1][y1] - cumulative_sum45[x1][y2+1] + cumulative_sum45[x1][y1];
  102. }
  103. T getSum45Border(int r1, int c1, int r2, int c2){
  104. int x1;
  105. int x2;
  106. int y1;
  107. int y2;
  108. T res;
  109. if(!set_cumulative_sum45){
  110. setSum45();
  111. }
  112. x1 = n1 - 1 - r1 + c1;
  113. y1 = r1 + c1;
  114. x2 = n1 - 1 - r2 + c2;
  115. y2 = r2 + c2;
  116. if(x1 > x2){
  117. swap(x1, x2);
  118. }
  119. if(y1 > y2){
  120. swap(y1, y2);
  121. }
  122. res = cumulative_sum45[x2+1][y2+1] - cumulative_sum45[x2+1][y1] - cumulative_sum45[x1][y2+1] + cumulative_sum45[x1][y1];
  123. if(x2 - x1 > 1 && y2 - y1 > 1){
  124. res -= cumulative_sum45[x2][y2] - cumulative_sum45[x2][y1+1] - cumulative_sum45[x1+1][y2] + cumulative_sum45[x1+1][y1+1];
  125. }
  126. return res;
  127. }
  128. void reset(){
  129. set_cumulative_sum45 = 0;
  130. }
  131. void constructor(){
  132. n1 = n2 = mem1 = mem2 = 0;
  133. d = NULL;
  134. set_cumulative_sum45 = 0;
  135. cumulative_sum45_mem = 0;
  136. cumulative_sum45 = NULL;
  137. }
  138. void destructor(){
  139. int i;
  140. if(d != NULL){
  141. for(i=(0);i<(mem1);i++){
  142. delete[] d[i];
  143. }
  144. delete[] d;
  145. }
  146. d = NULL;
  147. mem1 = mem2 = n1 = n2 = 0;
  148. set_cumulative_sum45 = 0;
  149. if(cumulative_sum45 != NULL){
  150. for(i=(0);i<(cumulative_sum45_mem);i++){
  151. delete[] cumulative_sum45[i];
  152. }
  153. delete[] cumulative_sum45;
  154. }
  155. cumulative_sum45_mem = 0;
  156. cumulative_sum45 = NULL;
  157. }
  158. void constructor(int nn1, int nn2){
  159. constructor();
  160. malloc(nn1, nn2);
  161. }
  162. void memory_expand(int nn1, int nn2){
  163. int i;
  164. if(mem1 < nn1 || mem2 < nn2){
  165. if(d != NULL){
  166. for(i=(0);i<(mem1);i++){
  167. delete[] d[i];
  168. }
  169. delete[] d;
  170. }
  171. d = new T*[nn1];
  172. for(i=(0);i<(nn1);i++){
  173. d[i] = new T[nn2];
  174. }
  175. mem1 = nn1;
  176. mem2 = nn2;
  177. }
  178. }
  179. void malloc(int nn1, int nn2){
  180. reset();
  181. memory_expand(nn1, nn2);
  182. n1 = nn1;
  183. n2 = nn2;
  184. }
  185. void setN(int nn1, int nn2){
  186. reset();
  187. memory_expand(nn1, nn2);
  188. n1 = nn1;
  189. n2 = nn2;
  190. }
  191. void set(vector<vector<T>> &a){
  192. int i;
  193. int j;
  194. int nn1 = a.size();
  195. int nn2 = a[0].size();
  196. setN(nn1, nn2);
  197. for(i=(0);i<(nn1);i++){
  198. for(j=(0);j<(nn2);j++){
  199. d[i][j] = a[i][j];
  200. }
  201. }
  202. }
  203. void set(int nn1, int nn2, T **a){
  204. int i;
  205. int j;
  206. setN(nn1, nn2);
  207. for(i=(0);i<(nn1);i++){
  208. for(j=(0);j<(nn2);j++){
  209. d[i][j] = a[i][j];
  210. }
  211. }
  212. }
  213. void free(){
  214. destructor();
  215. }
  216. Arr2d(){
  217. constructor();
  218. }
  219. Arr2d(int nn1, int nn2){
  220. constructor(nn1, nn2);
  221. }
  222. ~Arr2d(){
  223. destructor();
  224. }
  225. }
  226. ;
  227. #define main dummy_main
  228. int main(){
  229. return 0;
  230. }
  231. #undef main
  232. int X;
  233. int Y;
  234. int sz;
  235. int arr[1000000];
  236. Arr2d<int> A;
  237. class Solution{
  238. public:
  239. vector<int> getBiggestThree(vector<vector<int>>& grid){
  240. int i;
  241. dummy_main();
  242. sz = 0;
  243. X = grid.size();
  244. Y = grid[0].size();
  245. A.set(grid);
  246. for(i=(0);i<(X);i++){
  247. int j;
  248. for(j=(0);j<(Y);j++){
  249. int k;
  250. for(k=(0);k<(101);k++){
  251. if(i+2*k >= X || j-k < 0 || j+k >= Y){
  252. break;
  253. }
  254. arr[sz++] = A.getSum45Border(i,j,i+2*k,j);
  255. }
  256. }
  257. }
  258. Unique_L(sz,arr);
  259. vector<int> res;
  260. for(i=(0);i<(min_L(3, sz));i++){
  261. res.push_back(arr[sz-1-i]);
  262. }
  263. return res;
  264. }
  265. }
  266. ;
  267. // cLay version 20210607-1
  268.  
  269. // --- original code ---
  270. // #define main dummy_main
  271. // {}
  272. // #undef main
  273. //
  274. // int X, Y, sz, arr[1d6];
  275. // Arr2d<int> A;
  276. //
  277. // class Solution {
  278. // public:
  279. // vector<int> getBiggestThree(vector<vector<int>>& grid) {
  280. // dummy_main();
  281. // sz = 0;
  282. // X = grid.size();
  283. // Y = grid[0].size();
  284. // A.set(grid);
  285. // rep(i,X) rep(j,Y) rep(k,101){
  286. // if(i+2*k >= X || j-k < 0 || j+k >= Y) break;
  287. // arr[sz++] = A.getSum45Border(i,j,i+2*k,j);
  288. // }
  289. // Unique(sz,arr);
  290. //
  291. // VI res;
  292. // rep(i,min(3,sz)) res.push_back(arr[sz-1-i]);
  293. // return res;
  294. // }
  295. // };
  296.  
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