fork(1) download
  1. #include <iostream>
  2. #include <cstdint>
  3.  
  4. typedef uint32_t coord_t;
  5.  
  6. coord_t n, r1, c1, r2, c2;
  7. bool blue_win;
  8.  
  9. int main() {
  10. std::ios::sync_with_stdio(false);
  11. std::cin.tie(nullptr);
  12.  
  13. std::cin >> n;
  14. std::cin >> r1 >> c1;
  15. std::cin >> r2 >> c2;
  16.  
  17. // Ensure Blue is on the left side.
  18. if (c1 > c2) {
  19. c1 = n - c1 + 1;
  20. c2 = n - c2 + 1;
  21. }
  22.  
  23. coord_t sum = c1 + c2;
  24. if (r1 == r2) {
  25. coord_t columns_taken1 = sum >> 1;
  26. blue_win = columns_taken1 > (n >> 1);
  27. }
  28. else {
  29. // Let's assume r1 == 1 && r2 == 2
  30. // They go towards each other.
  31. // The question is what to do near the meet point?
  32. coord_t diff = c2 - c1;
  33. if (diff == 0) {
  34. blue_win = false;
  35. }
  36. else if (diff == 1) {
  37. coord_t cells_taken1 = std::max(
  38. diff + 1 + ((n - c2) << 1), // moving right
  39. sum - 1 // moving down
  40. );
  41. blue_win = cells_taken1 > n;
  42. }
  43. else if (diff & 1) {
  44. // Let's calculate how many cells Blue can take if Red moves
  45. // to the left near the meet point:
  46. coord_t cells_taken1 = std::max(
  47. diff + 1 + ((n - c2) << 1), // moving right
  48. sum - 1 // moving down
  49. );
  50. // Now let's calculate how many cells Red would take:
  51. coord_t cells_taken2 = std::max(
  52. (n - (sum >> 1) - 1) << 1, // moving up
  53. (n << 1) - cells_taken1 // moving left
  54. );
  55. blue_win = cells_taken2 < n;
  56. }
  57. else {
  58. // Let's calculate how many cells Red can take if Blue moves
  59. // to the right near the meet point:
  60. coord_t cells_taken2 = std::max(
  61. ((c1 - 1) << 1) + (diff | 1), // moving left
  62. (n << 1) - sum // moving up
  63. );
  64. // Now let's calculate how many cells Blue would take:
  65. coord_t cells_taken1 = std::max(
  66. sum - 2, // moving down
  67. (n << 1) - cells_taken2 // moving right
  68. );
  69. blue_win = cells_taken1 > n;
  70. }
  71. }
  72.  
  73. if (blue_win)
  74. std::cout << "Blue";
  75. else
  76. std::cout << "Red";
  77.  
  78. return 0;
  79. }
Success #stdin #stdout 0.01s 5312KB
stdin
3
1 1
2 1
stdout
Red