답안 #94963

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
94963 2019-01-25T22:28:38 Z bogdan10bos 구경하기 (JOI13_watching) C++14
100 / 100
425 ms 16120 KB
#include <bits/stdc++.h>

using namespace std;

//#define FILE_IO

const int NMAX = 2000;

int N, A, B;
int v[NMAX + 5];
int dp[NMAX + 5][NMAX + 5];
/// dp[i][j] - primele i, j camere mari

bool can(int w)
{
    int pA = 1, pB = 1;
    for(int i = 1; i <= N; i++)
        for(int j = 0; j <= B; j++)
        {
            while(v[i] - v[pA] + 1 > w) pA++;
            while(v[i] - v[pB] + 1 > 2 * w) pB++;

            dp[i][j] = dp[pA - 1][j] + 1;
            if(j > 0)   dp[i][j] = min(dp[i][j], dp[pB - 1][j - 1]);
        }
    return (dp[N][B] <= A);
}

int main()
{
    #ifdef FILE_IO
    freopen("1.in", "r", stdin);
    freopen("1.out", "w", stdout);
    #endif

    scanf("%d%d%d", &N, &A, &B);
    A = min(A, N); B = min(B, N);
    for(int i = 1; i <= N; i++) scanf("%d", &v[i]);
    sort(v + 1, v + N + 1);

    int p = 1, u = 1e9;
    int ans = 0;
    while(p <= u)
    {
        int mij = p + (u - p) / 2;
        if( can(mij) )
        {
            ans = mij;
            u = mij - 1;
        }
        else
            p = mij + 1;
    }
    printf("%d\n", ans);

    return 0;
}

Compilation message

watching.cpp: In function 'int main()':
watching.cpp:36:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d%d%d", &N, &A, &B);
     ~~~~~^~~~~~~~~~~~~~~~~~~~~~
watching.cpp:38:38: 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", &v[i]);
                                 ~~~~~^~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 888 KB Output is correct
2 Correct 2 ms 256 KB Output is correct
3 Correct 2 ms 376 KB Output is correct
4 Correct 2 ms 760 KB Output is correct
5 Correct 4 ms 760 KB Output is correct
6 Correct 3 ms 760 KB Output is correct
7 Correct 2 ms 760 KB Output is correct
8 Correct 2 ms 760 KB Output is correct
9 Correct 2 ms 760 KB Output is correct
10 Correct 3 ms 760 KB Output is correct
11 Correct 2 ms 760 KB Output is correct
12 Correct 3 ms 760 KB Output is correct
13 Correct 2 ms 760 KB Output is correct
14 Correct 2 ms 760 KB Output is correct
15 Correct 2 ms 760 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 9 ms 8312 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 316 ms 16092 KB Output is correct
4 Correct 25 ms 8952 KB Output is correct
5 Correct 425 ms 16120 KB Output is correct
6 Correct 402 ms 16120 KB Output is correct
7 Correct 14 ms 8468 KB Output is correct
8 Correct 165 ms 14328 KB Output is correct
9 Correct 35 ms 9336 KB Output is correct
10 Correct 28 ms 9080 KB Output is correct
11 Correct 400 ms 15992 KB Output is correct
12 Correct 210 ms 16120 KB Output is correct
13 Correct 13 ms 8568 KB Output is correct
14 Correct 12 ms 8440 KB Output is correct
15 Correct 11 ms 8484 KB Output is correct