Submission #1035532

# Submission time Handle Problem Language Result Execution time Memory
1035532 2024-07-26T11:45:49 Z aymanrs Radio Towers (IOI22_towers) C++17
14 / 100
4000 ms 22032 KB
#include "towers.h"
#include <bits/stdc++.h>
using namespace std;
vector<int> pr, h;
const int K = 17;
vector<pair<int, int>> sp[K];
vector<int> spm[K];
inline int msb(int x){
    return 31-__builtin_clz(x);
}
int que(int l, int r){
  int d = msb(r-l+1);
  return max(sp[d][l], sp[d][r-(1<<d)+1]).second;
}
int qum(int l, int r){
  int d = msb(r-l+1);
  return min(spm[d][l], spm[d][r-(1<<d)+1]);
}
void init(int N, std::vector<int> H) {
  h = H;
  pr.resize(N);
  pr[0]=0;
  for(int i = 0;i < K;i++) {
    sp[i].resize(N);
    spm[i].resize(N);
  }
  for(int i = 0;i < N;i++){
    sp[0][i] = {H[i], i};spm[0][i]=H[i];
  }
  for(int k = 1;k < K;k++){
    for(int i = 0;i+(1<<k)<=N;i++){
      sp[k][i] = max(sp[k-1][i], sp[k-1][i+(1<<k-1)]);
      spm[k][i] = max(spm[k-1][i], spm[k-1][i+(1<<k-1)]);
    }
  }
  for(int i = 1;i < N-1;i++){
    pr[i]=pr[i-1];
    if(H[i] < H[i-1] && H[i] < H[i+1]) pr[i]++;
  }
}
int de;
int ans(int l, int r, int atm){
  if(l==r){
    if(h[l]<=atm) return 1;
    return 0;
  }
  int m = que(l, r);
  if(l==m) return ans(l+1, r, atm);
  if(m==r) return ans(l, r-1, atm);
  return max(ans(l, m-1, h[m]-de)+ans(m+1, r, h[m]-de), (qum(l,r) <= atm ? 1 : 0));
}
int max_towers(int L, int R, int D) {
  de = D;
  if(L+1>=R) return 1;
  if(D==1) return pr[R-1]-pr[L]+(h[L] < h[L+1])+(h[R]<h[R-1]);
  return ans(L, R, INT_MAX);
}

Compilation message

towers.cpp: In function 'void init(int, std::vector<int>)':
towers.cpp:32:49: warning: suggest parentheses around '-' inside '<<' [-Wparentheses]
   32 |       sp[k][i] = max(sp[k-1][i], sp[k-1][i+(1<<k-1)]);
      |                                                ~^~
towers.cpp:33:52: warning: suggest parentheses around '-' inside '<<' [-Wparentheses]
   33 |       spm[k][i] = max(spm[k-1][i], spm[k-1][i+(1<<k-1)]);
      |                                                   ~^~
# Verdict Execution time Memory Grader output
1 Correct 3821 ms 13144 KB Output is correct
2 Execution timed out 4086 ms 21840 KB Time limit exceeded
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 596 KB Output is correct
2 Incorrect 1 ms 856 KB 1st lines differ - on the 1st token, expected: '292', found: '289'
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 596 KB Output is correct
2 Incorrect 1 ms 856 KB 1st lines differ - on the 1st token, expected: '292', found: '289'
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 517 ms 21748 KB Output is correct
2 Correct 693 ms 21848 KB Output is correct
3 Correct 678 ms 21848 KB Output is correct
4 Correct 673 ms 21844 KB Output is correct
5 Correct 622 ms 21848 KB Output is correct
6 Correct 589 ms 21848 KB Output is correct
7 Correct 660 ms 21848 KB Output is correct
8 Correct 587 ms 21848 KB Output is correct
9 Correct 538 ms 21848 KB Output is correct
10 Correct 509 ms 21848 KB Output is correct
11 Correct 523 ms 21816 KB Output is correct
12 Correct 575 ms 21824 KB Output is correct
13 Correct 612 ms 21848 KB Output is correct
14 Correct 0 ms 344 KB Output is correct
15 Correct 1 ms 856 KB Output is correct
16 Correct 1 ms 856 KB Output is correct
17 Correct 22 ms 21840 KB Output is correct
18 Correct 21 ms 21848 KB Output is correct
19 Correct 27 ms 21840 KB Output is correct
20 Correct 20 ms 22032 KB Output is correct
21 Correct 22 ms 21848 KB Output is correct
22 Correct 23 ms 21848 KB Output is correct
23 Correct 22 ms 21848 KB Output is correct
24 Correct 21 ms 21848 KB Output is correct
25 Correct 20 ms 21848 KB Output is correct
26 Correct 21 ms 21848 KB Output is correct
27 Correct 1 ms 856 KB Output is correct
28 Correct 1 ms 856 KB Output is correct
29 Correct 1 ms 856 KB Output is correct
30 Correct 1 ms 856 KB Output is correct
31 Correct 1 ms 856 KB Output is correct
32 Correct 1 ms 856 KB Output is correct
33 Correct 1 ms 600 KB Output is correct
34 Correct 1 ms 856 KB Output is correct
35 Correct 1 ms 856 KB Output is correct
36 Correct 1 ms 856 KB Output is correct
# Verdict Execution time Memory Grader output
1 Execution timed out 4073 ms 5464 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 596 KB Output is correct
2 Incorrect 1 ms 856 KB 1st lines differ - on the 1st token, expected: '292', found: '289'
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 3821 ms 13144 KB Output is correct
2 Execution timed out 4086 ms 21840 KB Time limit exceeded
3 Halted 0 ms 0 KB -