답안 #1061607

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1061607 2024-08-16T11:11:10 Z MarwenElarbi 송신탑 (IOI22_towers) C++17
컴파일 오류
0 ms 0 KB
#include <bits/stdc++.h>
using namespace std;
#include "towers.h"
#define pb push_back
#define ll long long
#define fi first
#define se second
int k;
vector<int> tab;
void init(int N, std::vector<int> H) {
  n=N;
  for (int i = 0; i < N; ++i)
  {
    tab.pb(H[i]);
  }
  for (int i = 0; i < N-1; ++i)
  {
    if(tab[i]>tab[i+1]){
      k=i;
      break;
    }
  }
}

int max_towers(int L, int R, int D){
  if(L>k||R<k) return 0;
  int l=L;
  int r=k;
  while(r-l>1){
    int mid=(r+l)/2;
    if(tab[mid]>tab[k]-D) r=mid;
    else l=mid;
  }
  int a=l;
  l=k;
  r=n-1;
  while(r-l>1){
    int mid=(r+l)/2;
    if(tab[mid]>tab[k]-D) l=mid;
    else r=mid;
  }
  return a-L+1+R-r+1;
}

Compilation message

towers.cpp: In function 'void init(int, std::vector<int>)':
towers.cpp:11:3: error: 'n' was not declared in this scope
   11 |   n=N;
      |   ^
towers.cpp: In function 'int max_towers(int, int, int)':
towers.cpp:36:5: error: 'n' was not declared in this scope
   36 |   r=n-1;
      |     ^