Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- #define pb push_back
- #define ins insert
- using namespace std;
- struct psycho {
- int aim;
- int val;
- };
- int n;
- vector<psycho> ps;
- set<int> killers;
- int killedThisIter=100;
- int timeTaken=0;
- void init() {
- psycho back;
- back.aim=-1;
- back.val=2147483647;
- ps.pb(back);
- cin>>n;
- vector<int> ids(n); for (int i=0; i<n; i++) {cin>>ids[n-i-1];}
- for (int i=0; i<n; i++) {
- psycho ss;
- ss.aim=i;
- ss.val=ids[i];
- ps.pb(ss);
- killers.ins(i+1);
- }
- psycho front;
- front.aim=-1;
- front.val=2147483647;
- ps.pb(front);
- }
- void Kill_People() {
- int killed=0;
- vector<int> nokill;
- for (auto i : killers) {
- if (ps[i].val>ps[ps[i].aim].val) {
- ps[i].aim=ps[ps[i].aim].aim;
- killed++;
- nokill.pb(ps[i].aim);
- } else {
- nokill.pb(i);
- }
- }
- for (auto i : nokill) {
- if (killers.find(i)!=killers.end()) {killers.erase(i);}
- }
- killedThisIter=killed;
- if (killed>0) { timeTaken++;}
- }
- bool Can_Kill() {
- return killedThisIter;
- }
- int main() {
- init();
- while (Can_Kill()) {
- Kill_People();
- }
- cout<<timeTaken;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement