Submission #790741

#TimeUsernameProblemLanguageResultExecution timeMemory
790741penguinmanRadio Towers (IOI22_towers)C++17
11 / 100
13 ms3468 KiB
#include "towers.h"

#include <bits/stdc++.h>

using std::vector;
using std::string;
using std::cin;
using std::cout;
using ll = long long;
using vi = vector<ll>;
using vii = vector<vi>;
using pii = std::pair<ll,ll>;
#define ln "\n"
#define rep(i,j,k) for(ll i=ll(j); i<ll(k); i++)
#define REP(i,j,k) for(ll i=ll(j); i<=ll(k); i++)
#define per(i,j,k) for(ll i=ll(j); i>=ll(k); i--)
#define all(a) a.begin(), a.end()
#define mp std::make_pair
constexpr ll inf = (1ll<<60);

ll N;
vi H;

void init(int n, std::vector<int> h) {
  N = n;
  H.resize(N);
  rep(i,0,N) H[i] = h[i];
  assert (N <= 2000);
}

int max_towers(int L, int R, int D) {
  vi h = H;
  ll ans = 0;
  REP(_,L,R){
    ll idx = std::min_element(H.begin()+L, H.begin()+R+1)-H.begin();
    bool flag = true;
    REP(j,idx+1,R){
      if(H[j] == inf){
        flag = false;
        break;
      }
      else if(H[j] == inf+1) continue;
      if(H[j] >= H[idx]+D) break;
    }
    per(j,idx-1,L){
      if(H[j] == inf){
        flag = false;
        break;
      }
      else if(H[j] == inf+1) continue;
      if(H[j] >= H[idx]+D) break;
    }
    if(flag){
      ans++;
      H[idx] = inf;
    }
    else H[idx] = inf+1;
  }
  H = h;
  return ans;
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...