답안 #539161

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
539161 2022-03-18T14:04:30 Z astoria 구경하기 (JOI13_watching) C++14
100 / 100
233 ms 15988 KB
#include <bits/stdc++.h>
using namespace std;

int N,P,Q;
int events[2001], prep[2001], preq[2001], minq[2001][2001];

bool f (int w){
  for (int i=N-1; i>=0; i--){
    prep[i] = int(lower_bound(events, events+N, events[i]+w)-events);
    preq[i] = int(lower_bound(events, events+N, events[i]+min(1000000001, 2*w))-events);
    for (int p=0; p<=P; p++){
      /*if (q==0) minp[i][q] = minp[prep[i]-1][q]+1;
      else minp[i][q] = min(minp[prep[i]-1][q]+1 , minp[preq[i]-1][q-1]);*/
      minq[i][p] = 1000000001;
      if (p>0) minq[i][p] = minq[prep[i]][p-1];
      minq[i][p] = min( minq[i][p], minq[preq[i]][p]+1 );
    }
  }
  if (minq[0][P]<=Q) return true;
  else return false;
}

int binarySearch(){
  int L=0; int R=1000000001;
  while (L<R){
    int middle = (L+R)/2;
    if (f(middle)){
      R = middle;
    }
    else{
      L = middle+1;
    }
  }
  return L;
}

int main(){
  cin >> N >> P >> Q;
  for (int i=0; i<N; i++){
    cin >> events[i];
  }
  if ((P+Q)>=N){
      cout << 1;
      return 0;
  }
  sort(events,events+N);
  cout << binarySearch();
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 720 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 308 KB Output is correct
5 Correct 1 ms 328 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 3 ms 724 KB Output is correct
8 Correct 1 ms 724 KB Output is correct
9 Correct 1 ms 724 KB Output is correct
10 Correct 1 ms 724 KB Output is correct
11 Correct 2 ms 692 KB Output is correct
12 Correct 2 ms 724 KB Output is correct
13 Correct 1 ms 724 KB Output is correct
14 Correct 2 ms 724 KB Output is correct
15 Correct 2 ms 724 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 11 ms 8252 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 2 ms 212 KB Output is correct
4 Correct 2 ms 212 KB Output is correct
5 Correct 2 ms 384 KB Output is correct
6 Correct 2 ms 212 KB Output is correct
7 Correct 12 ms 8484 KB Output is correct
8 Correct 23 ms 9300 KB Output is correct
9 Correct 92 ms 14228 KB Output is correct
10 Correct 233 ms 15936 KB Output is correct
11 Correct 20 ms 9044 KB Output is correct
12 Correct 151 ms 15988 KB Output is correct
13 Correct 14 ms 8396 KB Output is correct
14 Correct 22 ms 8380 KB Output is correct
15 Correct 13 ms 8384 KB Output is correct