Submission #703638

# Submission time Handle Problem Language Result Execution time Memory
703638 2023-02-28T02:19:20 Z Belgutei Radio Towers (IOI22_towers) C++17
0 / 100
4000 ms 7536 KB
#include "towers.h"
#include<bits/stdc++.h>

using namespace std;

#define pb push_back

vector<int> a;
vector<int> v[30], b;
set<int> s;
set<int> :: iterator it;

int level, zereg[30];
int dp[100005];
int pos;

void build_tree(int tmp) {
  zereg[0] = 1;
  for(int i = 0; i <= 30; i ++) {
    if(zereg[i] >= tmp) {
      level = i;
      break;
    }
    zereg[i + 1] = zereg[i] * 2;
  }
  for(int i = 0; i < zereg[level]; i ++) {
    v[level].pb(0);
  }
  for(int i = level - 1; i >= 0; i --) {
    for(int j = 0; j < zereg[i]; j ++) v[i].pb(0);
  }
  return;
}

void init(int N, std::vector<int> H) {
  a.resize(N);
  for(int i = 0; i < H.size(); i ++) {
    a[i] = H[i];
    s.insert(a[i]);
  }
  for(it = s.begin(); it != s.end(); it ++) {
    b.pb(*it);
  }
  build_tree(s.size());
}

int dfs(int k, int x, int l) {
  int y = zereg[level - k] * x;
  int z = zereg[level - k] * (x + 1) - 1;
  if(y >= l) return v[k][x];
  if(z < l || k == level) return 0;
  return max(dfs(k + 1, x * 2, l), dfs(k + 1, x * 2 + 1, l));
}

void update(int pos, int val) {
  v[level][pos] = max(v[level][pos], val);
  for(int i = level - 1; i >= 0; i --) {
    pos /= 2;
    v[i][pos] = max(v[i + 1][pos * 2], v[i + 1][pos * 2 + 1]);
  }
}

int max_towers(int L, int R, int D) {
  memset(dp, 0, sizeof(dp));
  int ret = 0;
  for(int i = L; i <= R; i ++) {
    int l = 0;
    int r = b.size() - 1;
    if(b[r] < a[i] + D) {
      dp[i] = 1;
      ret = max(ret, dp[i]);
      continue;
    }
    int val = a[i] + D;
    while(l < r) {
      int mid = (l + r) / 2;
      if(b[mid] >= val) {
        r = mid;
      }
      else l = mid + 1;
    }
    dp[i] = 1 + dfs(0,0,l);
    ret = max(ret, dp[i]);
    //
    l = 0;
    r = b.size() - 1;
    val = a[i];
    while(l < r) {
      int mid = (l + r) / 2;
      if(b[mid] >= val) {
        r = mid;
      }
      else l = mid + 1;
    }
    update(l, dp[i]);
  }
  return ret;
}

Compilation message

towers.cpp: In function 'void init(int, std::vector<int>)':
towers.cpp:37:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   37 |   for(int i = 0; i < H.size(); i ++) {
      |                  ~~^~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Execution timed out 4066 ms 4696 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 720 KB 1st lines differ - on the 1st token, expected: '13', found: '6'
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 720 KB 1st lines differ - on the 1st token, expected: '13', found: '6'
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 4081 ms 7536 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 4097 ms 2344 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 720 KB 1st lines differ - on the 1st token, expected: '13', found: '6'
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 4066 ms 4696 KB Time limit exceeded
2 Halted 0 ms 0 KB -