제출 #1132790

#제출 시각아이디문제언어결과실행 시간메모리
1132790altern23구경하기 (JOI13_watching)C++20
100 / 100
105 ms31884 KiB
#include <bits/stdc++.h> using namespace std; #pragma GCC optimize ("O2") #pragma GCC optimize ("unroll-loops") #define ll long long #define pii pair<ll,ll> #define fi first #define sec second #define ld long double template <typename T> ostream& operator << (ostream& os, vector<T>tmp){ os << "["; for(auto x : tmp) os << " " << x; os << " ]"; return os; } template <typename T> ostream& operator << (ostream& os, set<T>tmp){ os << "["; for(auto x : tmp) os << " " << x; os << " ]"; return os; } template <typename T> ostream& operator << (ostream& os, multiset<T>tmp){ os << "["; for(auto x : tmp) os << " " << x; os << " ]"; return os; } ostream& operator << (ostream& os, pii x){ os << "["; os << " " << x.fi << " " << x.sec; os << " ]"; return os; } const ll MOD = 998244353; const ll N = 2e5 + 5; const ll INF = 2e18; // modulo operations void add(ll &a, ll b) { a = (a + b) % MOD; } void sub(ll &a, ll b) { a -= b; while(a < 0) a += MOD; a %= MOD; } void mul(ll &a, ll b) { a = (a * b) % MOD; } ll expo(ll a, ll b) { ll ans = 1; while(b > 0){ if(b & 1) mul(ans, a); mul(a, a); b /= 2; } return ans; } ll dp[2005][2005]; ll l1[2005], l2[2005]; int32_t main(){ ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); int tc = 1; // cin >> tc; for(;tc--;){ ll n, p, q; cin >> n >> p >> q; vector<ll> a(n + 5); for(int i = 1; i <= n; i++) cin >> a[i]; if(p + q >= n){ cout << 1 << "\n"; continue; } sort(a.begin() + 1, a.begin() + 1 + n); ll l = 1, r = 1e9, ans = -1; for(;l <= r;){ ll mid = (l + r) / 2; ll pt = 1, pt2 = 1; dp[0][0] = 0; ll mn = INF; for(int i = 1; i <= n; i++){ while(pt <= n && a[i] - a[pt] + 1 > mid) pt++; while(pt2 <= n && a[i] - a[pt2] + 1 > 2 * mid) pt2++; l1[i] = pt, l2[i] = pt2; for(int j = 0; j <= p; j++){ dp[i][j] = INF; dp[i][j] = dp[l2[i] - 1][j] + 1; if(j) dp[i][j] = min(dp[i][j], dp[l1[i] - 1][j - 1]); if(i == n) mn = min(mn, dp[i][j]); } } if(mn <= q){ ans = mid; r = mid - 1; } else l = mid + 1; } cout << ans << "\n"; } } /* */
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...