Skip to content

Octopussy solution too complicated - can be simplified #1

Description

@sevdari

Pretty much title.

In 2025, the story was different where we were given a flock of birds and had to shoot them with an arrow and kill them before a specified timestamp. The solution can be much simplified by using a combination of greedy + walk algorithm.

#include <limits>
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <vector>

using namespace std;

vector<int> kill_time;

void dfs(int root, int upper_bound){
  if(root >= kill_time.size()) return;
  if(kill_time[root] > upper_bound)
    kill_time[root] = upper_bound;
  
  int new_upper_bound = min(kill_time[root], upper_bound);
  dfs(2*root + 1, new_upper_bound - 1);
  dfs(2*root + 2, new_upper_bound - 1);
}

void testcase() {
  int n; cin>>n;
  kill_time.clear();
  int t; 
  for(int i = 0; i < n; i++){
    cin>>t; kill_time.push_back(t);
  }
  dfs(0, kill_time[0]);
  
  sort(kill_time.begin(), kill_time.end());
  t = 0;
  for(auto kill_t: kill_time){
    if(t >= kill_t){
      cout << "no\n"; return;
    }
    t++;
  }
  cout << "yes\n";
  
}

int main() {
  std::ios_base::sync_with_stdio(false);
  std::cout << std::fixed << std::setprecision(0);

  int t; std::cin >> t;
  for (int i = 0; i < t; ++i)
    testcase();
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions