Source code for submission s1161

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

Diff to submission s1123

ants.cpp

--- c4.s1123.cteam037.ants.cpp.0.ants.cpp
+++ c4.s1161.cteam037.ants.cpp.0.ants.cpp
@@ -6,5 +6,6 @@
         bool dva;
         while(1){
-                maxCesta = cnt = maxIndex = maxIndex2 = help = 0;
+                cnt = maxIndex = maxIndex2 = help = 0;
+                maxCesta = -1;
                 dva = false;
                 if(scanf("%d %d\n", &len, &ants) != 2) return 0;
@@ -24,5 +25,5 @@
                                 dva = false;
                         }
-                        if((maxCesta == help) && (dir == 'l')){
+                        if((maxCesta == help) && (dir == 'L')){
                                 maxIndex2 = help;
                                 dva = true;