fork download
  1. #include <iostream>
  2.  
  3. using namespace std;
  4.  
  5. int main() {
  6. ios_base::sync_with_stdio(false);
  7. cin.tie(NULL);
  8.  
  9. long long x1, y1, x2, y2;
  10. if (!(cin >> x1 >> y1 >> x2 >> y2)) return 0;
  11.  
  12. long long cur_x = x1, cur_y = y1;
  13. long long prev_x = x1, prev_y = y1;
  14. long long truck_hits = 0;
  15. char last_move = ' ';
  16. bool reached = false;
  17.  
  18. if (cur_x == x2 && cur_y == y2) {
  19. reached = true;
  20. }
  21.  
  22. char c;
  23. while (cin >> c) {
  24. if (reached) {
  25. continue;
  26. }
  27.  
  28. if (c == 'p') {
  29. break;
  30. }
  31.  
  32. long long old_x = cur_x;
  33. long long old_y = cur_y;
  34.  
  35. if (c == 'r') {
  36. cur_x += 1;
  37. last_move = 'r';
  38. prev_x = old_x; prev_y = old_y;
  39. } else if (c == 'l') {
  40. cur_x -= 1;
  41. last_move = 'l';
  42. prev_x = old_x; prev_y = old_y;
  43. } else if (c == 'u') {
  44. cur_y += 1;
  45. last_move = 'u';
  46. prev_x = old_x; prev_y = old_y;
  47. } else if (c == 'd') {
  48. cur_y -= 1;
  49. last_move = 'd';
  50. prev_x = old_x; prev_y = old_y;
  51. } else if (c == 's') {
  52. // Đứng im
  53. } else if (c == 'b') {
  54. if (last_move == 'r') {
  55. cur_x -= 1;
  56. last_move = 'l';
  57. } else if (last_move == 'l') {
  58. cur_x += 1;
  59. last_move = 'r';
  60. } else if (last_move == 'u') {
  61. cur_y -= 1;
  62. last_move = 'd';
  63. } else if (last_move == 'd') {
  64. cur_y += 1;
  65. last_move = 'u';
  66. }
  67. prev_x = old_x; prev_y = old_y;
  68. } else if (c == 't') {
  69. truck_hits++;
  70. cur_x = prev_x;
  71. cur_y = prev_y;
  72. // Lưu lại vị trí trước khi bị cán
  73. prev_x = old_x; prev_y = old_y;
  74. } else if (c == 'm') {
  75. cur_x = truck_hits;
  76. prev_x = old_x; prev_y = old_y;
  77. }
  78.  
  79. if (cur_x == x2 && cur_y == y2) {
  80. reached = true;
  81. }
  82. }
  83.  
  84. if (reached) {
  85. cout << "SAVED\n";
  86. } else {
  87. cout << "DEAD\n";
  88. }
  89.  
  90. return 0;
  91. }
Success #stdin #stdout 0s 5308KB
stdin
Standard input is empty
stdout
Standard output is empty