Source code for submission s1364

Go to diff to previous submission

ants.cpp

  1. #include <cstdio>
  2. #include <cstdlib>
  3. #define MAX 100010
  4. int l,n;
  5. char dirs[MAX];
  6. int ants[MAX];
  7. int start,end;
  8. int lcnt;
  9. int maxL,maxR;
  10. int pos2,pos1;
  11.  
  12. int getLastL(){
  13. int ctr=0;
  14. for(int i=0;i<=l;i++){
  15. if(ants[i]!=-1)
  16. ctr++;
  17. if(ctr == lcnt)
  18. return i;
  19. }
  20. return n+100;
  21. }
  22. int getLastR(){
  23. int ctr=0;
  24. for(int i=0;i<=l;i++){
  25. if(ants[i]!=-1)
  26. ctr++;
  27. if(ctr == lcnt+1)
  28. return i;
  29. }
  30. return n+100;
  31. }
  32.  
  33. int main(int argc, char ** argv){
  34. int pos;
  35. char dir;
  36. bool noL,noR;
  37. int pom;
  38.  
  39. while(scanf("%d %d",&l,&n) == 2){
  40. noL = noR = true;
  41. lcnt=0;
  42. maxR = maxL = 0;
  43. pos = 0;
  44. for(int i=0; i < MAX;i++){
  45. ants[i] = -1;
  46. }
  47.  
  48.  
  49. for(int i=0; i < n;i++){
  50. scanf("%d %c",&pos,&dir);
  51. if(dir == 'R'){
  52. noR = false;
  53. ants[pos] = l - pos;
  54. if(ants[maxL] < ants[pos]){
  55. maxL = pos;
  56. }
  57. }
  58. else{
  59. lcnt++;
  60. noL = false;
  61. ants[pos] = pos;
  62. if(ants[maxR] < ants[pos]){
  63. maxR = pos;
  64. }
  65. }
  66. }
  67. // no left oriented
  68. if(noL){
  69. printf("The last ant will fall down in %d seconds - started at %d.\n",ants[maxL],maxL);
  70.  
  71.  
  72. continue;
  73. }
  74. // no right oriented
  75. if(noR){
  76. printf("The last ant will fall down in %d seconds - started at %d.\n",ants[maxR],maxR);
  77.  
  78. continue;
  79. }
  80. //printf("%d %d \n",maxL,maxR);
  81. // for(int i=0;i<=l;i++){
  82. //if(ants[i]!=-1)
  83. // printf("%d ",i);
  84. //printf("\n");
  85. // }
  86.  
  87.  
  88.  
  89. if(ants[maxL] > ants[maxR]){
  90. pos1 = getLastL();
  91. printf("The last ant will fall down in %d seconds - started at %d.\n",ants[maxL],pos1);
  92. continue;
  93. }
  94. if(ants[maxR] > ants[maxL]){
  95. pos1 = getLastR();
  96. printf("The last ant will fall down in %d seconds - started at %d.\n",ants[maxR],pos1);
  97. continue;
  98. }
  99. pos1 = getLastR();
  100. pos2 = getLastL();
  101. if(pos2 < pos1){
  102. pom = pos1;
  103. pos1 = pos2;
  104. pos2 = pom;
  105. }
  106. printf("The last ant will fall down in %d seconds - started at %d and %d.\n",ants[maxR],pos1,pos2);
  107.  
  108. }
  109. return 0;
  110. }
  111.  

Diff to submission s1344

ants.cpp

--- c4.s1344.cteam058.ants.cpp.0.ants.cpp
+++ c4.s1364.cteam058.ants.cpp.0.ants.cpp
@@ -42,5 +42,5 @@
                 maxR = maxL = 0;
                 pos = 0;
-                for(int i=0; i <= l;i++){
+                for(int i=0; i < MAX;i++){
                         ants[i] = -1;
                 }