Source code for submission s1329

Go to diff to previous submission

sablona.cc

  1. #include <cstdio>
  2. #include <iostream>
  3. #include <algorithm>
  4. #include <vector>
  5. #include <set>
  6. #include <map>
  7. #include <string>
  8. #include <cmath>
  9. #include <cstdlib>
  10. #include <cstring>
  11. #include <sstream>
  12.  
  13. #include <stdio.h>
  14. #include <ctype.h>
  15. #include <math.h>
  16. #include <string.h>
  17. #include <stdlib.h>
  18.  
  19. using namespace std;
  20.  
  21. #define X first
  22. #define Y second
  23. #define MP make_pair
  24. #define PB push_back
  25. #define SZ size
  26.  
  27. struct Dvojice {
  28. int zac;
  29. char smer;
  30. };
  31.  
  32. int compare (const void *a, const void *b) {
  33. struct Dvojice a1 = *(struct Dvojice*)a;
  34. struct Dvojice b1 = *(struct Dvojice*)b;
  35. return (a1.zac-b1.zac);
  36. }
  37.  
  38. int main(void)
  39. {
  40. int a, b, c, d, f, g, aa, i, ii, akt, akt2, j, k, ok2, ok, pom1, pom2, cas1, cas2, max;
  41. char e;
  42. struct Dvojice mrv[100005];
  43.  
  44. while (scanf("%d %d", &a, &b) > 0) {
  45. max = 0;
  46. for (i = 0; i < b; i++) {
  47. scanf("%d %c\n", &c, &e);
  48. mrv[i].zac = c;
  49. mrv[i].smer = e;
  50. if (e == 'R') {
  51. if (a - c > max)
  52. max = a - c;
  53. } else {
  54. if (c > max)
  55. max = c;
  56. }
  57. }
  58. qsort(mrv, b, sizeof(struct Dvojice), compare);
  59. d = 0;
  60. f = b - 1;
  61. ok2 = 1;
  62. pom1 = d + 1;
  63. pom2 = f - 1;
  64. while(d + 1 < f && ok2 == 1) {
  65. ok = 0;
  66. //pom1 = d + 1;
  67. //pom2 = f - 1;
  68. while (ok == 0) {
  69. if (mrv[pom1].smer != mrv[d].smer) {
  70. ok = 1;
  71. } else {
  72. pom1++;
  73. }
  74. if (pom1 > f) {
  75. ok = 1;
  76. pom1 = -1;
  77. }
  78. }
  79. ok = 0;
  80. while (ok == 0) {
  81. if (mrv[pom2].smer != mrv[f].smer) {
  82. ok = 1;
  83. } else {
  84. pom2++;
  85. }
  86. if (pom2 < d) {
  87. ok = 1;
  88. pom2 = -1;
  89. }
  90. }
  91. if (pom1 != -1) {
  92. cas1 = mrv[pom1].zac - mrv[d].zac;
  93. }
  94. if (pom2 != -1) {
  95. cas2 = mrv[f].zac - mrv[pom2].zac;
  96. }
  97. if (pom1 != -1) {
  98. if (cas1 == cas2) {
  99. if (mrv[pom2].smer == 'R')
  100. mrv[pom2].smer = 'L';
  101. else
  102. mrv[pom2].smer = 'R';
  103. f--;
  104. if (mrv[pom1].smer == 'R')
  105. mrv[pom1].smer = 'L';
  106. else
  107. mrv[pom1].smer = 'R';
  108. d++;
  109. if (pom1 > pom2)
  110. pom1 = d + 1;
  111. if (pom2 < pom1)
  112. pom2 = f - 1;
  113. //pom2 = f - 1;
  114. } else if (cas1 > cas2) {
  115. if (mrv[pom2].smer == 'R')
  116. mrv[pom2].smer = 'L';
  117. else
  118. mrv[pom2].smer = 'R';
  119. f--;
  120. if (pom1 > pom2)
  121. pom1 = d + 1;
  122. } else {
  123. if (mrv[pom1].smer == 'R')
  124. mrv[pom1].smer = 'L';
  125. else
  126. mrv[pom1].smer = 'R';
  127. d++;
  128. if (pom2 < pom1)
  129. pom2 = f - 1;
  130. }
  131. } else {
  132. ok2 = 0;
  133. }
  134. //printf("%d %d\n", d, f);
  135. }
  136. if (ok2 == 0) {
  137. if (mrv[d].smer == 'L')
  138. printf("The last ant will fall down in %d seconds - started at %d.\n", max, mrv[f].zac);
  139. else
  140. printf("The last ant will fall down in %d seconds - started at %d.\n", max, mrv[d].zac);
  141. } else {
  142. //printf("%d\n", mrv[f].zac);
  143. if (a - mrv[f].zac > mrv[d].zac)
  144. printf("The last ant will fall down in %d seconds - started at %d.\n", max, mrv[f].zac);
  145. else if (a - mrv[f].zac < mrv[d].zac)
  146. printf("The last ant will fall down in %d seconds - started at %d.\n", max, mrv[d].zac);
  147. else {
  148. if (f > d)
  149. printf("The last ant will fall down in %d seconds - started at %d and %d.\n", max, mrv[d].zac, mrv[f].zac);
  150. else
  151. printf("The last ant will fall down in %d seconds - started at %d and %d.\n", max, mrv[f].zac, mrv[d].zac);
  152. }
  153. }
  154. }
  155.  
  156. return 0;
  157. }
  158.  

Diff to submission s1317

sablona.cc

--- c4.s1317.cteam079.ants.cpp.0.sablona.cc
+++ c4.s1329.cteam079.ants.cpp.0.sablona.cc
@@ -142,7 +142,7 @@
          //printf("%d\n", mrv[f].zac);
          if (a - mrv[f].zac > mrv[d].zac)
-            printf("The last ant will fall down in %d seconds - started at %d.\n", max, mrv[d].zac);
-         else if (a - mrv[f].zac < mrv[d].zac)
             printf("The last ant will fall down in %d seconds - started at %d.\n", max, mrv[f].zac);
+         else if (a - mrv[f].zac < mrv[d].zac)
+            printf("The last ant will fall down in %d seconds - started at %d.\n", max, mrv[d].zac);
          else {
             if (f > d)