Source code for submission s601

ants.cpp

  1. #include <algorithm>
  2. #include <cctype>
  3. #include <cmath>
  4. #include <complex>
  5. #include <cstdio>
  6. #include <cstring>
  7. #include <iomanip>
  8. #include <iostream>
  9. #include <list>
  10. #include <map>
  11. #include <queue>
  12. #include <set>
  13. #include <sstream>
  14. #include <stack>
  15. #include <string>
  16. #include <utility>
  17. #include <vector>
  18.  
  19. using namespace std;
  20. #define DEBUG(x) cerr << ">>> " << #x << " : " << x << endl;
  21. #define REP(i,a) for (int i = 0; i < (a); ++i)
  22. #define FOR(i,a,b) for (int i = (a); i <= (b); ++i)
  23. #define FORD(i,a,b) for (int i = (a); i >= (b); --i)
  24. inline bool EQ(double a, double b) { return fabs(a-b) < 1e-9; }
  25.  
  26. const int INF = 1<<29;
  27. typedef long long ll;
  28. //////////////////////////////////
  29.  
  30. #define MAXN 100000
  31. int start[MAXN];
  32. bool dir[MAXN];
  33.  
  34. int L, N;
  35.  
  36. int main() {
  37. char tmp[5];
  38. while(scanf("%d%d", &L, &N) != EOF){
  39. int left = 0;
  40. int max_left = -1, max_right = -1;
  41. REP(i, N){
  42. scanf("%d %s", start + i, tmp);
  43. dir[i] = (tmp[0] == 'L');
  44. left += dir[i];
  45. if(dir[i]) max_left = max(max_left, start[i]);
  46. else max_right = max(max_right, L - start[i]);
  47. }
  48. sort(start, start + N);
  49. if(max_left > max_right) printf("The last ant will fall down in %d seconds - started at %d.\n", max_left, start[left-1]);
  50. if(max_left < max_right) printf("The last ant will fall down in %d seconds - started at %d.\n", max_right, start[left]);
  51. if(max_left == max_right) printf("The last ant will fall down in %d seconds - started at %d and %d.\n", max_right, start[left-1], start[left]);
  52. }
  53. return 0;
  54. }
  55.