제출 #1274045

#제출 시각아이디문제언어결과실행 시간메모리
1274045nanaseyuzuki구경하기 (JOI13_watching)C++20
50 / 100
402 ms16448 KiB
#include <bits/stdc++.h> // Author: Kazuki_Will_Win_VOI_8703 #define fi first #define se second #define pii pair<int, int> // #define int long long #define all(a) a.begin(), a.end() using namespace std; const int mn = 2e3 + 5, bm = (1 << 11) + 1, mod = 1e9 + 7, offset = 5e4, B = 320 + 5; const int inf = 1e9, base = 311; int n, p, q, a[mn], dp[mn][mn], pre[2][mn]; bool check(int mid){ for(int i = 1; i <= n; i++){ for(int j = i - 1; j >= 0; j --){ if(a[i] - a[j] >= mid || j == 0){ pre[0][i] = j; break; } } } for(int i = 1; i <= n; i++){ for(int j = i - 1; j >= 0; j --){ if(a[i] - a[j] >= 2 * mid || j == 0){ pre[1][i] = j; break; } } } fill(&dp[0][0], &dp[0][0] + mn * mn, inf); dp[0][0] = 0; for(int i = 1; i <= n; i++){ for(int j = 0; j <= q; j++){ dp[i][j] = min(dp[i][j], dp[pre[0][i]][j] + 1); if(j > 0) dp[i][j] = min(dp[pre[1][i]][j - 1], dp[i][j]); } } for(int i = 0; i <= q; i++) if(dp[n][i] <= p) return true; return false; } void solve(){ cin >> n >> p >> q; for(int i = 1; i <= n; i++) cin >> a[i]; sort(a + 1, a + n + 1); int l = 1, r = 1e9, ans = -1; while(l <= r){ int mid = (l + r) >> 1; if(check(mid)){ ans = mid; r = mid - 1; } else l = mid + 1; } cout << ans << '\n'; } signed main(){ ios_base::sync_with_stdio(false); cin.tie(NULL); int t = 1; // cin >> t; while(t--){ solve(); } }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...