답안 #200578

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
200578 2020-02-07T12:45:37 Z quocnguyen1012 구경하기 (JOI13_watching) C++14
0 / 100
167 ms 16248 KB
#include <bits/stdc++.h>

#define fi first
#define se second
#define mp make_pair
#define pb push_back

using namespace std;
typedef long long ll;

const int maxn = 2005;

int f[maxn][maxn];
int a[maxn], N;
int P, Q;

bool check(int len)
{
  const int inf = 1e9;
  fill_n(&f[0][0], maxn * maxn, inf);
  f[0][0] = 0;
  int l = 1, r = 1;
  for (int i = 1; i <= N; ++i){
    while (l <= N && a[l] <= a[i] - len) ++l;
    while (r <= N && a[r] <= a[i] - 2 * len) ++r;
    for (int j = 0; j <= min(i, P); ++j){
      if (j > 0) f[i][j] = f[l - 1][j - 1];
      f[i][j] = min(f[i][j], f[r - 1][j] + 1);
    }
  }
  return f[N][P] <= Q;
}

signed main(void)
{
  ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
  if (fopen("A.INP", "r")){
    freopen("A.INP", "r", stdin);
    freopen("A.OUT", "w", stdout);
  }
  cin >> N >> P >> Q;
  P = min(P, N); Q = min(Q, N);
  for (int i = 1; i <= N; ++i){
    cin >> a[i];
  }
  sort(a + 1, a + 1 + N);
  int l = 1, r = 1e9, mid;
  while (l <= r){
    mid = (l + r) / 2;
    if (!check(mid)) l = mid + 1;
    else r = mid - 1;
  }
  cout << l;
}

Compilation message

watching.cpp: In function 'int main()':
watching.cpp:38:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)', declared with attribute warn_unused_result [-Wunused-result]
     freopen("A.INP", "r", stdin);
     ~~~~~~~^~~~~~~~~~~~~~~~~~~~~
watching.cpp:39:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)', declared with attribute warn_unused_result [-Wunused-result]
     freopen("A.OUT", "w", stdout);
     ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 91 ms 15864 KB Output is correct
2 Correct 86 ms 16120 KB Output is correct
3 Incorrect 89 ms 16248 KB Output isn't correct
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 86 ms 16120 KB Output is correct
2 Correct 81 ms 16096 KB Output is correct
3 Incorrect 167 ms 16124 KB Output isn't correct
4 Halted 0 ms 0 KB -