Advertisement
FyanRu

Untitled

Feb 26th, 2023
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.32 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2. #define pb push_back
  3. #define ins insert
  4. using namespace std;
  5.  
  6.  
  7. struct psycho {
  8. int aim;
  9. int val;
  10. };
  11.  
  12. int n;
  13. vector<psycho> ps;
  14. set<int> killers;
  15. int killedThisIter=100;
  16. int timeTaken=0;
  17.  
  18. void init() {
  19. psycho back;
  20. back.aim=-1;
  21. back.val=2147483647;
  22. ps.pb(back);
  23.  
  24. cin>>n;
  25.  
  26. vector<int> ids(n); for (int i=0; i<n; i++) {cin>>ids[n-i-1];}
  27.  
  28. for (int i=0; i<n; i++) {
  29. psycho ss;
  30. ss.aim=i;
  31. ss.val=ids[i];
  32. ps.pb(ss);
  33. killers.ins(i+1);
  34. }
  35. psycho front;
  36. front.aim=-1;
  37. front.val=2147483647;
  38. ps.pb(front);
  39.  
  40. }
  41.  
  42. void Kill_People() {
  43. int killed=0;
  44. vector<int> nokill;
  45. for (auto i : killers) {
  46. if (ps[i].val>ps[ps[i].aim].val) {
  47. ps[i].aim=ps[ps[i].aim].aim;
  48. killed++;
  49. nokill.pb(ps[i].aim);
  50. } else {
  51. nokill.pb(i);
  52. }
  53. }
  54.  
  55. for (auto i : nokill) {
  56. if (killers.find(i)!=killers.end()) {killers.erase(i);}
  57. }
  58.  
  59. killedThisIter=killed;
  60. if (killed>0) { timeTaken++;}
  61. }
  62.  
  63. bool Can_Kill() {
  64. return killedThisIter;
  65. }
  66.  
  67. int main() {
  68. init();
  69.  
  70. while (Can_Kill()) {
  71. Kill_People();
  72. }
  73.  
  74. cout<<timeTaken;
  75.  
  76. return 0;
  77. }
  78.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement