fork download
  1. #include <iostream>
  2.  
  3. using namespace std;
  4.  
  5. int main() {
  6.  
  7. int tc;
  8. cin >> tc;
  9.  
  10. while(tc > 0) {
  11.  
  12. int f,b,t,fd,bd,pointer=0,current_direction=1,total_traveled=0;
  13.  
  14. cin >> f >> b >> t >> fd >> bd;
  15.  
  16. bd = 0-bd;
  17.  
  18. if(f == b) {
  19. if(fd == f) {
  20. cout << f << " F" << endl;
  21. return 0;
  22. }
  23. else {
  24. cout << "No Ditch" << endl;
  25. return 0;
  26. }
  27. }
  28. while(true) {
  29. if(current_direction == 1) {
  30.  
  31. int pointer_after_current_step = pointer + f;
  32.  
  33. if(pointer_after_current_step >= fd) {
  34.  
  35. int current_taken = fd - pointer;
  36. total_traveled += current_taken;
  37.  
  38. cout << (total_traveled * t) << " F" << endl;
  39. return 0;
  40. }
  41. else {
  42. pointer += f;
  43. total_traveled += f;
  44. }
  45.  
  46. current_direction = 2;
  47. }
  48. else {
  49.  
  50. int pointer_after_current_step = pointer - b;
  51.  
  52. if(pointer_after_current_step <= bd) {
  53.  
  54. int current_taken = pointer - bd;
  55. total_traveled += current_taken;
  56.  
  57. cout << total_traveled * t << " B" << endl;
  58. return 0;
  59. }
  60. else {
  61. pointer -= b;
  62. total_traveled += b;
  63. }
  64.  
  65. current_direction = 1;
  66. }
  67. }
  68.  
  69. tc--;
  70. }
  71.  
  72. return 0;
  73. }
Success #stdin #stdout 0s 3460KB
stdin
8
9 4 3 13 10
9 7 1 11 13
4 4 3 8 12
8 4 7 11 22
4 5 4 25 6
4 9 3 6 29
7 10 6 24 12
10 10 1 9 7
stdout
63 F