Source code for submission s1123

Go to diff to previous submission

ants.cpp

  1. #include <cstdio>
  2.  
  3. int main(){
  4. int len, ants, cnt, maxCesta, maxIndex, maxIndex2, help;
  5. char dir;
  6. bool dva;
  7. while(1){
  8. maxCesta = cnt = maxIndex = maxIndex2 = help = 0;
  9. dva = false;
  10. if(scanf("%d %d\n", &len, &ants) != 2) return 0;
  11. int pole[len + 1];
  12. for(int i = 0; i <= len; i++) pole[i] = 0;
  13. for(int i = 0; i < ants; i++){
  14. scanf("%d %c\n", &help, &dir);
  15. dir == 'R' ? pole[help] = 1 : pole[help] = -1;
  16.  
  17. if((maxCesta == (len - help)) && (dir == 'R')){
  18. maxIndex2 = help;
  19. dva = true;
  20. }
  21. if((maxCesta < (len - help)) && (dir =='R')){
  22. maxCesta = len - help;
  23. maxIndex = help;
  24. dva = false;
  25. }
  26. if((maxCesta == help) && (dir == 'l')){
  27. maxIndex2 = help;
  28. dva = true;
  29. }
  30. if((maxCesta < help) && (dir == 'L')){
  31. maxCesta = maxIndex = help;
  32. dva = false;
  33. }
  34. }
  35. switch(pole[maxIndex]){
  36. case -1:{
  37. for(int i = maxIndex; i >=0; i--){
  38. if(pole[i] == 1) cnt++;
  39. }
  40. for(int i = maxIndex; i >=0 ; i--){
  41. if(pole[i] != 0){
  42. if(cnt == 0) maxIndex = i;
  43. cnt--;
  44. }
  45. }
  46. break;
  47. }
  48. case 1:{
  49. for(int i = maxIndex; i <= len; i++){
  50. if(pole[i] == -1) cnt++;
  51. }
  52. for(int i = maxIndex; i <= len ; i++){
  53. if(pole[i] != 0){
  54. if(cnt == 0) maxIndex = i;
  55. cnt--;
  56. }
  57. }
  58. break;
  59. }
  60. default:{break;}
  61. }
  62.  
  63. if(dva){
  64. cnt = 0;
  65. switch(pole[maxIndex2]){
  66. case -1:{
  67. for(int i = maxIndex2; i >=0; i--){
  68. if(pole[i] == 1) cnt++;
  69. }
  70. for(int i = maxIndex2; i >=0 ; i--){
  71. if(pole[i] != 0){
  72. if(cnt == 0) maxIndex2 = i;
  73. cnt--;
  74. }
  75. }
  76. break;
  77. }
  78. case 1:{
  79. for(int i = maxIndex2; i <= len; i++){
  80. if(pole[i] == -1) cnt++;
  81. }
  82. for(int i = maxIndex2; i <= len ; i++){
  83. if(pole[i] != 0){
  84. if(cnt == 0) maxIndex2 = i;
  85. cnt--;
  86. }
  87. }
  88. break;
  89. }
  90. default:{break;}
  91. }}
  92. if(dva) printf("The last ant will fall down in %d seconds - started at %d and %d.\n", maxCesta, maxIndex < maxIndex2 ? maxIndex : maxIndex2, maxIndex < maxIndex2 ? maxIndex2 : maxIndex);
  93. else
  94. printf("The last ant will fall down in %d seconds - started at %d.\n", maxCesta, maxIndex);
  95. }
  96. return 0;
  97. }
  98.  
  99.  

Diff to submission s1070

ants.cpp

--- c4.s1070.cteam037.ants.cpp.0.ants.cpp
+++ c4.s1123.cteam037.ants.cpp.0.ants.cpp
@@ -10,5 +10,5 @@
                 if(scanf("%d %d\n", &len, &ants) != 2) return 0;
                 int pole[len + 1];
-                for(int i = 0; i < len; i++) pole[i] = 0;
+                for(int i = 0; i <= len; i++) pole[i] = 0;
                 for(int i = 0; i < ants; i++){
                         scanf("%d %c\n", &help, &dir);