fork download
  1. #pragma GCC optimize ("Ofast")
  2. #include<bits/stdc++.h>
  3. using namespace std;
  4. void *wmem;
  5. char memarr[96000000];
  6. template<class T> inline void walloc1d(T **arr, int x, void **mem = &wmem){
  7. static int skip[16] = {0, 15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1};
  8. (*mem) = (void*)( ((char*)(*mem)) + skip[((unsigned long long)(*mem)) & 15] );
  9. (*arr)=(T*)(*mem);
  10. (*mem)=((*arr)+x);
  11. }
  12. struct unionFind{
  13. int *d;
  14. int N;
  15. int M;
  16. inline void malloc(const int n){
  17. d = (int*)std::malloc(n*sizeof(int));
  18. M = n;
  19. }
  20. inline void malloc(const int n, const int fg){
  21. d = (int*)std::malloc(n*sizeof(int));
  22. M = n;
  23. if(fg){
  24. init(n);
  25. }
  26. }
  27. inline void free(void){
  28. std::free(d);
  29. }
  30. inline void walloc(const int n, void **mem=&wmem){
  31. walloc1d(&d, n, mem);
  32. M = n;
  33. }
  34. inline void walloc(const int n, const int fg, void **mem=&wmem){
  35. walloc1d(&d, n, mem);
  36. M = n;
  37. if(fg){
  38. init(n);
  39. }
  40. }
  41. inline void init(const int n){
  42. int i;
  43. N = n;
  44. for(i=(0);i<(n);i++){
  45. d[i] = -1;
  46. }
  47. }
  48. inline void init(void){
  49. init(M);
  50. }
  51. inline int get(int a){
  52. int t = a;
  53. int k;
  54. while(d[t]>=0){
  55. t=d[t];
  56. }
  57. while(d[a]>=0){
  58. k=d[a];
  59. d[a]=t;
  60. a=k;
  61. }
  62. return a;
  63. }
  64. inline int connect(int a, int b){
  65. if(d[a]>=0){
  66. a=get(a);
  67. }
  68. if(d[b]>=0){
  69. b=get(b);
  70. }
  71. if(a==b){
  72. return 0;
  73. }
  74. if(d[a] < d[b]){
  75. d[a] += d[b];
  76. d[b] = a;
  77. }
  78. else{
  79. d[b] += d[a];
  80. d[a] = b;
  81. }
  82. return 1;
  83. }
  84. inline int operator()(int a){
  85. return get(a);
  86. }
  87. inline int operator()(int a, int b){
  88. return connect(a,b);
  89. }
  90. inline int& operator[](const int a){
  91. return d[a];
  92. }
  93. inline int size(int a){
  94. a = get(a);
  95. return -d[a];
  96. }
  97. inline int sizeList(int res[]){
  98. int i;
  99. int sz=0;
  100. for(i=(0);i<(N);i++){
  101. if(d[i]<0){
  102. res[sz++] = -d[i];
  103. }
  104. }
  105. return sz;
  106. }
  107. }
  108. ;
  109. #define main dummy_main
  110. int main(){
  111. wmem = memarr;
  112. return 0;
  113. }
  114. #undef main
  115. int con[6][4] = { // U, L, D, R
  116. 0,1,0,1,
  117. 1,0,1,0,
  118. 0,1,1,0,
  119. 0,0,1,1,
  120. 1,1,0,0,
  121. 1,0,0,1
  122. };
  123. class Solution{
  124. public:
  125. bool hasValidPath(vector<vector<int>>& A){
  126. int i;
  127. dummy_main();
  128. int X = A.size();
  129. int Y = A[0].size();
  130. unionFind uf;
  131. uf.walloc(X*Y, 1);
  132. for(i=(0);i<(X);i++){
  133. int j;
  134. for(j=(0);j<(Y);j++){
  135. A[i][j]--;
  136. }
  137. }
  138. for(i=(0);i<(X);i++){
  139. int j;
  140. for(j=(0);j<(Y-1);j++){
  141. if(con[A[i][j]][3] && con[A[i][j+1]][1]){
  142. uf(i*Y+j, i*Y+j+1);
  143. }
  144. }
  145. }
  146. for(i=(0);i<(X-1);i++){
  147. int j;
  148. for(j=(0);j<(Y);j++){
  149. if(con[A[i][j]][2] && con[A[i+1][j]][0]){
  150. uf(i*Y+j, (i+1)*Y+j);
  151. }
  152. }
  153. }
  154. return uf(0) == uf(X*Y-1);
  155. }
  156. }
  157. ;
  158. // cLay varsion 20200325-1
  159.  
  160. // --- original code ---
  161. // #define main dummy_main
  162. // {}
  163. // #undef main
  164. //
  165. // int con[6][4] = { // U, L, D, R
  166. // 0,1,0,1,
  167. // 1,0,1,0,
  168. // 0,1,1,0,
  169. // 0,0,1,1,
  170. // 1,1,0,0,
  171. // 1,0,0,1
  172. // };
  173. //
  174. // class Solution {
  175. // public:
  176. // bool hasValidPath(vector<vector<int>>& A) {
  177. // dummy_main();
  178. // int X = A.size(), Y = A[0].size();
  179. // unionFind uf;
  180. // uf.walloc(X*Y, 1);
  181. // rep(i,X) rep(j,Y) A[i][j]--;
  182. // rep(i,X) rep(j,Y-1) if(con[A[i][j]][3] && con[A[i][j+1]][1]) uf(i*Y+j, i*Y+j+1);
  183. // rep(i,X-1) rep(j,Y) if(con[A[i][j]][2] && con[A[i+1][j]][0]) uf(i*Y+j, (i+1)*Y+j);
  184. // return uf(0) == uf(X*Y-1);
  185. // }
  186. // };
  187.  
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