Source code for submission s751

ololo.cpp

  1. #include <iostream>
  2. #include <cstdio>
  3. #include <vector>
  4. #include <algorithm>
  5. #include <memory.h>
  6. #include <cstring>
  7. #include <string>
  8.  
  9.  
  10. #define FOR(i,a,b) for (int i = (a); i < (b); ++i)
  11. #define FI(i,b) FOR(i,0,b)
  12. #define V(t) vector < t >
  13. #define pb push_back
  14. #define MEMS(a,b) memset((a),(b),sizeof(a))
  15. #define U unsigned
  16. #define LL long long
  17. #define pnt pair<int,int>
  18. #define mp make_pair
  19.  
  20.  
  21. using namespace std;
  22.  
  23.  
  24. vector<pair<int,int> > a;
  25. vector<int> pos;
  26. char s[3];
  27. int main()
  28. {
  29. int l,n;
  30. while (scanf("%d%d",&l,&n)!=EOF)
  31. {
  32. a.clear();
  33. pos.clear();
  34. int res=0;
  35. FOR(i,0,n)
  36. {
  37. int x;
  38. scanf("%d%s",&x,&s);
  39. if (s[0]=='L')
  40. {
  41. a.push_back(mp(x,0));
  42. res=max(res,x);
  43. }
  44. else
  45. {
  46. a.push_back(mp(l-x,1));
  47. res=max(res,l-x);
  48. }
  49. pos.push_back(x);
  50. }
  51. sort(pos.begin(),pos.end());
  52. sort(a.begin(),a.end());
  53. int l=0,r=(int)pos.size()-1;
  54. FOR(i,0,a.size())
  55. {
  56. //cout<<a[i].second<<endl;
  57. int sz=(int)a.size();
  58. if (i+2==sz)
  59. {
  60. if (a[i].first==a[i+1].first)
  61. {
  62. printf("The last ant will fall down in %d seconds - started at %d and %d.\n",res,pos[l],pos[l+1]);
  63. break;
  64. }
  65. }
  66. if (i+1==sz)
  67. {
  68. printf("The last ant will fall down in %d seconds - started at %d.\n",res,pos[l]);
  69. break;
  70. }
  71. if (a[i].second==0)
  72. l++;
  73. else
  74. r--;
  75. }
  76.  
  77. }
  78. return 0;
  79. }