Submission #289992

# Submission time Handle Problem Language Result Execution time Memory
289992 2020-09-03T09:40:17 Z BeanZ Watching (JOI13_watching) C++14
100 / 100
314 ms 31864 KB
#include <bits/stdc++.h>

using namespace std;

#define ll long long
#define endl '\n'
const int N = 5e5 + 5;
ll n, p, q;
ll dp[2005][2005], a[2005], bestw[2005], bestw2[2005];
bool chk(ll k){
        for (int i = 1; i <= n; i++){
                ll l = 1, h = i;
                ll w2 = a[i] - 2 * k + 1;
                while (l <= h){
                        ll mid = (l + h) >> 1;
                        if (a[mid] < w2) l = mid + 1;
                        else h = mid - 1;
                }
                bestw2[i] = l;
                l = 1, h = i;
                ll w = a[i] - k + 1;
                while (l <= h){
                        ll mid = (l + h) >> 1;
                        if (a[mid] < w) l = mid + 1;
                        else h = mid - 1;
                }
                bestw[i] = l;
        }
        for (int i = 1; i <= n; i++){
                for (int j = 0; j <= q; j++){
                        dp[i][j] = 1e18;
                        ll l = bestw2[i];
                        if (j > 0) dp[i][j] = min(dp[i][j], dp[l - 1][j - 1]);
                        l = bestw[i];
                        dp[i][j] = min(dp[i][j], dp[l - 1][j] + 1);
                }
        }
        for (int i = 0; i <= q; i++){
                if (dp[n][i] <= p) return 1;
        }
        return 0;
}
int main(){
        ios_base::sync_with_stdio(false);
        cin.tie(0);
        if (fopen("simplify.in", "r")){
                freopen("simplify.in", "r", stdin);
                freopen("simplify.out", "w", stdout);
        }
        cin >> n >> p >> q;
        for (int i = 1; i <= n; i++) cin >> a[i];
        sort(a + 1, a + n + 1);
        if ((p + q) >= n) return cout << 1, 0;
        ll l = 1, h = 1e9;
        while (l <= h){
                ll mid = (l + h) >> 1;
                if (chk(mid)) h = mid - 1;
                else l = mid + 1;
        }
        cout << l;
}
/*
*/

Compilation message

watching.cpp: In function 'int main()':
watching.cpp:47:24: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)', declared with attribute warn_unused_result [-Wunused-result]
   47 |                 freopen("simplify.in", "r", stdin);
      |                 ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~
watching.cpp:48:24: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)', declared with attribute warn_unused_result [-Wunused-result]
   48 |                 freopen("simplify.out", "w", stdout);
      |                 ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 768 KB Output is correct
2 Correct 0 ms 384 KB Output is correct
3 Correct 1 ms 384 KB Output is correct
4 Correct 0 ms 384 KB Output is correct
5 Correct 1 ms 384 KB Output is correct
6 Correct 0 ms 384 KB Output is correct
7 Correct 1 ms 768 KB Output is correct
8 Correct 1 ms 768 KB Output is correct
9 Correct 1 ms 768 KB Output is correct
10 Correct 1 ms 768 KB Output is correct
11 Correct 1 ms 768 KB Output is correct
12 Correct 1 ms 768 KB Output is correct
13 Correct 1 ms 768 KB Output is correct
14 Correct 1 ms 768 KB Output is correct
15 Correct 1 ms 768 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 8 ms 8448 KB Output is correct
2 Correct 0 ms 384 KB Output is correct
3 Correct 1 ms 384 KB Output is correct
4 Correct 1 ms 384 KB Output is correct
5 Correct 1 ms 384 KB Output is correct
6 Correct 1 ms 384 KB Output is correct
7 Correct 13 ms 8704 KB Output is correct
8 Correct 142 ms 20224 KB Output is correct
9 Correct 33 ms 10368 KB Output is correct
10 Correct 31 ms 9856 KB Output is correct
11 Correct 314 ms 31864 KB Output is correct
12 Correct 181 ms 23800 KB Output is correct
13 Correct 11 ms 8704 KB Output is correct
14 Correct 10 ms 8704 KB Output is correct
15 Correct 11 ms 8704 KB Output is correct