답안 #253892

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
253892 2020-07-29T04:20:17 Z ChrisT 구경하기 (JOI13_watching) C++17
100 / 100
213 ms 16248 KB
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 2005;
typedef long long ll;
typedef pair<int,int> pii;
int dp[MAXN][MAXN], a[MAXN],p,q,n;
int findlast (int cur, int w) {
  return max((int)(lower_bound(a+1,a+1+n,cur-w+1)-a-1),0);
}
bool check (int w) {
  memset(dp,0x3f,sizeof dp); memset(dp[0],0,sizeof dp[0]);
  for (int i = 1; i <= n; i++) {
    int lp = findlast(a[i],w), lq = findlast(a[i],w<<1);
    for (int j = 0; j <= p; j++) {
      dp[i][j] = dp[lq][j] + 1;
      if (j) dp[i][j] = min(dp[i][j],dp[lp][j-1]);
    }
  }
  return dp[n][p] <= q;
}
int main() {
  int ans=INT_MAX;
  scanf ("%d %d %d",&n,&p,&q);
  if (p + q >= n) return !printf ("1\n");
  for (int i = 1; i <= n; i++) scanf ("%d",&a[i]);
  sort(a+1,a+1+n);
  for (int low = 1, high = 1e9,mid; low <= high;) {
    if (check(mid = (low + high)>>1)) high = mid-1, ans = mid;
    else low = mid+1;
  }
  printf ("%d\n",ans);
  return 0;
}

Compilation message

watching.cpp: In function 'int main()':
watching.cpp:23:9: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf ("%d %d %d",&n,&p,&q);
   ~~~~~~^~~~~~~~~~~~~~~~~~~~~
watching.cpp:25:38: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   for (int i = 1; i <= n; i++) scanf ("%d",&a[i]);
                                ~~~~~~^~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 59 ms 16000 KB Output is correct
2 Correct 0 ms 256 KB Output is correct
3 Correct 75 ms 16000 KB Output is correct
4 Correct 1 ms 256 KB Output is correct
5 Correct 1 ms 256 KB Output is correct
6 Correct 0 ms 256 KB Output is correct
7 Correct 75 ms 16000 KB Output is correct
8 Correct 58 ms 16128 KB Output is correct
9 Correct 60 ms 16000 KB Output is correct
10 Correct 58 ms 16000 KB Output is correct
11 Correct 59 ms 16000 KB Output is correct
12 Correct 60 ms 16000 KB Output is correct
13 Correct 60 ms 16000 KB Output is correct
14 Correct 57 ms 16104 KB Output is correct
15 Correct 64 ms 16000 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 65 ms 16036 KB Output is correct
2 Correct 0 ms 256 KB Output is correct
3 Correct 0 ms 384 KB Output is correct
4 Correct 1 ms 384 KB Output is correct
5 Correct 0 ms 384 KB Output is correct
6 Correct 1 ms 384 KB Output is correct
7 Correct 78 ms 16120 KB Output is correct
8 Correct 75 ms 16248 KB Output is correct
9 Correct 150 ms 16120 KB Output is correct
10 Correct 213 ms 16116 KB Output is correct
11 Correct 72 ms 16120 KB Output is correct
12 Correct 148 ms 16116 KB Output is correct
13 Correct 70 ms 16120 KB Output is correct
14 Correct 67 ms 16120 KB Output is correct
15 Correct 68 ms 16120 KB Output is correct