Submission #51423

# Submission time Handle Problem Language Result Execution time Memory
51423 2018-06-18T01:45:24 Z FutymyClone Watching (JOI13_watching) C++14
100 / 100
916 ms 16424 KB
#include <bits/stdc++.h>

using namespace std;

const int N = 2005;
int dp[N][N], a[N], n, p, q;

int main(){
    scanf("%d %d %d", &n, &p, &q);
    for (int i = 1; i <= n; i++) scanf("%d", &a[i]);

    if (p >= n) printf("%d", 1);
    else {

        sort(a + 1, a + n + 1);
        a[0] = -2000000000;

        int l = 1;
        int r = 1000000000;

        while (l <= r) {
            int mid = (l + r)/2;
            memset(dp, 0x3f, sizeof(dp));

            for (int i = 0; i <= n; i++) {
                for (int j = i; j <= p; j++) {
                    dp[i][j] = 0;
                }
            }

            dp[0][0] = dp[0][1] = 0;
            dp[1][0] = 1;
            dp[1][1] = 0;
            int pt = 0;
            int pt2 = 0;

            for (int i = 2; i <= n; i++) {
                for (int j = 0; j <= p; j++) {
                    if (j) {
                        while (a[pt] + mid - 1 < a[i]) pt++;
                        pt--;

                        dp[i][j] = min(dp[i][j], dp[pt][j - 1]);
                    }

                    while (a[pt2] + 2 * mid - 1 < a[i]) pt2++;
                    pt2--;

                    dp[i][j] = min(dp[i][j], dp[pt2][j] + 1);
                }
            }

            int mn = 0x3f3f3f3f;
            for (int i = 0; i <= p; i++) mn = min(mn, dp[n][i]);

            if (mn <= q) r = mid - 1;
            else l = mid + 1;
        }

        #ifdef Futymy
        for (int i = 0; i <= n; i++) {
            for (int j = 0; j <= p; j++) {
                cout << dp[i][j] << " ";
            }
            cout << "\n";
        }
        #endif // Futymy

        printf("%d", l);
    }
    return 0;
}

Compilation message

watching.cpp: In function 'int main()':
watching.cpp:9:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d %d %d", &n, &p, &q);
     ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
watching.cpp:10:39: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     for (int i = 1; i <= n; i++) scanf("%d", &a[i]);
                                  ~~~~~^~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 50 ms 16120 KB Output is correct
2 Correct 2 ms 16120 KB Output is correct
3 Correct 50 ms 16212 KB Output is correct
4 Correct 2 ms 16212 KB Output is correct
5 Correct 41 ms 16236 KB Output is correct
6 Correct 2 ms 16236 KB Output is correct
7 Correct 45 ms 16236 KB Output is correct
8 Correct 41 ms 16236 KB Output is correct
9 Correct 45 ms 16236 KB Output is correct
10 Correct 49 ms 16280 KB Output is correct
11 Correct 57 ms 16280 KB Output is correct
12 Correct 43 ms 16280 KB Output is correct
13 Correct 40 ms 16280 KB Output is correct
14 Correct 92 ms 16304 KB Output is correct
15 Correct 60 ms 16352 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 95 ms 16352 KB Output is correct
2 Correct 41 ms 16360 KB Output is correct
3 Correct 641 ms 16360 KB Output is correct
4 Correct 2 ms 16360 KB Output is correct
5 Correct 79 ms 16364 KB Output is correct
6 Correct 2 ms 16364 KB Output is correct
7 Correct 76 ms 16372 KB Output is correct
8 Correct 165 ms 16372 KB Output is correct
9 Correct 405 ms 16372 KB Output is correct
10 Correct 916 ms 16372 KB Output is correct
11 Correct 104 ms 16372 KB Output is correct
12 Correct 465 ms 16372 KB Output is correct
13 Correct 66 ms 16372 KB Output is correct
14 Correct 59 ms 16424 KB Output is correct
15 Correct 59 ms 16424 KB Output is correct