fork download
  1. #include <cstdio>
  2. #include <dispatch/dispatch.h>
  3.  
  4. #define W (1920)
  5. #define H (1080)
  6.  
  7. char board[H][W];
  8. const char * actions = "UULLLDULDRRDDLDULDURLDDRUDLUDRUDLDRRRDLDUDDDLLDURLLUURUDLLUDDDULRRDRLULLLDDRDLUDRRRRUDLRDURLLDDDLLRULURDLLLLDLRRUDLRRLULUUUDULULLLRLLLUDLRDLDLUUUDRUULURURDLLRLDDDDDURDDULURUDDDULLLDRDLULURLUURLRUDLLUULUDLLDUUURLLDLDUURRRUURRRUDLUDURLLLLDRULLLRULRURLUDDLDUL";
  9.  
  10. void do_action(char action, int den = 1, int task = 0) {
  11. switch (action) {
  12. case 'U':
  13. {
  14. int count = W/den;
  15. int sx = count*task;
  16. for (int x = sx; x < sx+count; ++x) {
  17. int dst_y = 0;
  18. for (int y = 0; y < H; ++y) {
  19. if (board[y][x] != '.') {
  20. board[dst_y++][x] = board[y][x];
  21. }
  22. }
  23. for (; dst_y < H; ++dst_y) {
  24. board[dst_y][x] = '.';
  25. }
  26. }
  27. break;
  28. }
  29. case 'D':
  30. {
  31. int count = W/den;
  32. int sx = count*task;
  33. for (int x = sx; x < sx+count; ++x) {
  34. int dst_y = H-1;
  35. for (int y = H-1; y >= 0; --y) {
  36. if (board[y][x] != '.') {
  37. board[dst_y--][x] = board[y][x];
  38. }
  39. }
  40. for (; dst_y >= 0; --dst_y) {
  41. board[dst_y][x] = '.';
  42. }
  43. }
  44. break;
  45. }
  46. case 'L':
  47. {
  48. int count = H/den;
  49. int sy = count*task;
  50. for (int y = sy; y < sy+count; ++y) {
  51. int dst_x = 0;
  52. for (int x = 0; x < W; ++x) {
  53. if (board[y][x] != '.') {
  54. board[y][dst_x++] = board[y][x];
  55. }
  56. }
  57. for (; dst_x < W; ++dst_x) {
  58. board[y][dst_x] = '.';
  59. }
  60. }
  61. break;
  62. }
  63. case 'R':
  64. {
  65. int count = H/den;
  66. int sy = count*task;
  67. for (int y = sy; y < sy+count; ++y) {
  68. int dst_x = W-1;
  69. for (int x = W-1; x >= 0; --x) {
  70. if (board[y][x] != '.') {
  71. board[y][dst_x--] = board[y][x];
  72. }
  73. }
  74. for (; dst_x >= 0; --dst_x) {
  75. board[y][dst_x] = '.';
  76. }
  77. }
  78. break;
  79. }
  80. }
  81. }
  82.  
  83.  
  84. int main(int argc, const char* argv[]) {
  85. const char *ac = actions;
  86.  
  87. #if 1
  88. /* reduce qctions */
  89. char opt[512];
  90. char attr[256] = {0};
  91. attr['U'] = attr['D'] = 1;
  92. attr['L'] = attr['R'] = 2;
  93.  
  94. while (1) {
  95. char last[3] = {0};
  96. int dst = 0, count = 0;
  97. for (int i = 0; ac[i]; ++i) {
  98. count++;
  99. int a = attr[ac[i]];
  100. if (ac[i+1] == 0 || a != attr[ac[i+1]]) {
  101. if (last[a] != ac[i]) {
  102. opt[dst++] = ac[i];
  103. last[a] = ac[i];
  104. }
  105. }
  106. }
  107. opt[dst] = 0;
  108. ac = opt;
  109. if (dst == count)
  110. break;
  111. }
  112. #else
  113. ac = actions;
  114. #endif
  115.  
  116. /* read initial board */
  117. fread(board, W * H, 1, stdin);
  118.  
  119. #if 1
  120. /* doit */
  121. const int num = 8;
  122. dispatch_queue_t queue = dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0);
  123. dispatch_group_t group = dispatch_group_create();
  124. for (int i = 0; ac[i]; ++i) {
  125. for (int j = 0; j < num; j++) {
  126. dispatch_group_async(group, queue, ^{
  127. do_action(ac[i], num, j);
  128. });
  129. }
  130. dispatch_group_wait(group, DISPATCH_TIME_FOREVER);
  131. }
  132. dispatch_release(group);
  133. #else
  134. /* doit */
  135. for (int i = 0; ac[i]; ++i) {
  136. do_action(ac[i]);
  137. }
  138. #endif
  139.  
  140. /* write result */
  141. fwrite(board, W * H, 1, stdout);
  142. }
  143.  
  144.  
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
prog.cpp:2:31: fatal error: dispatch/dispatch.h: No such file or directory
 #include <dispatch/dispatch.h>
                               ^
compilation terminated.
stdout
Standard output is empty