답안 #976357

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
976357 2024-05-06T13:18:29 Z vjudge1 구경하기 (JOI13_watching) C++17
0 / 100
53 ms 604 KB
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define lld double
#define int ll
#define usaco(fname) freopen(#fname ".in","r",stdin);freopen(#fname ".out","w",stdout);
template<typename A, typename B> ostream& operator<<(ostream &os, const pair<A, B> &p) { return os << '(' << p.first << ", " << p.second << ')'; }
template<typename T_container, typename T = typename enable_if<!is_same<T_container, string>::value, typename T_container::value_type>::type> ostream& operator<<(ostream &os, const T_container &v) { os << '{'; string sep; for (const T &x : v) os << sep << x, sep = ", "; return os << '}'; }
// const ll INF = 1e18;
const int INF = 1e18;
const int mod = 1e9+7;
const lld PI = acos(-1.0);
int di[] = {1, -1, 0, 0, 1, 1, -1, -1};
int dj[] = {0, 0, 1, -1, 1, -1, 1, -1};
#define debug(x) cout << #x << ": " << x << endl;
#define add(a, b) a += b, a %= mod
#define mul(a, b) ((a % mod) * (b % mod)) % mod
#define all(x) x.begin(),x.end()

void solve() {
  int n,p,q;cin>>n>>p>>q;
  vector<int> a(n);
  for (int i =0 ; i < n; i++) cin >> a[i];
  sort(all(a));

  function<bool(int)> chk = [&](int k) {
    vector<int> dp(n, INF); // fewest q to cover all
    for (int i = 0; i < n; i++) {
      int before = (i-1 >= 0 ? dp[i-1] : 0);
      int j = i;
      for (; j < n; j++) {
        if (a[i]+2*k-1 < a[j]) break;
        dp[j] = min(dp[j], before+1);
      }
    }

    if (dp[n-1] <= q) return true;

    // cout << dp  endl;
    map<int, int> cnt;
    for (int i = 0; i < n; i++) cnt[dp[i]]++;
    
    vector<pair<int, int>> bruh(all(cnt));
    sort(all(bruh), [&](auto &x, auto &y) {
      return x.second > y.second;
    });

    set<int> dontcount;
    for (int i = 0; i < q; i++) dontcount.insert(bruh[i].first);

    vector<int> newa;
    for (int i = 0; i < n; i++) {
      if (dontcount.count(dp[i])) continue;
      newa.push_back(a[i]);
    }
    
    int sz = newa.size();
    vector<int> dp2(sz, INF);
    for (int i = 0; i < sz; i++) {
      int before = (i-1 >= 0 ? dp2[i-1] : 0);
      int j = i;
      for (; j < sz; j++) {
        if (newa[i]+k-1 < newa[j]) break;
        dp2[j] = min(dp2[j], before+1);
      }
    }
    
    return dp2[sz-1] <= p;
  };

  int ans = 1e9+69;
  int l = 1, r = 1e9+69;
  while (l <= r) {
    int mid = (l+r)>>1;

    if (chk(mid)) {
      r = mid-1;
      ans = mid;
    } else l = mid+1;
  }

  cout << ans << endl;
}

int32_t main() {
  ios_base::sync_with_stdio(0);cin.tie(0);
  int t=1;
  while(t--) solve();

  return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 460 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
6 Correct 1 ms 452 KB Output is correct
7 Incorrect 1 ms 348 KB Output isn't correct
8 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 53 ms 348 KB Output is correct
2 Correct 0 ms 344 KB Output is correct
3 Correct 13 ms 604 KB Output is correct
4 Correct 11 ms 604 KB Output is correct
5 Correct 7 ms 348 KB Output is correct
6 Correct 6 ms 348 KB Output is correct
7 Incorrect 15 ms 348 KB Output isn't correct
8 Halted 0 ms 0 KB -