답안 #56548

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
56548 2018-07-11T15:50:28 Z luciocf 구경하기 (JOI13_watching) C++14
100 / 100
336 ms 16636 KB
#include <bits/stdc++.h>

using namespace std;

const int MAXN = 2010;

typedef long long ll;

int n, p, q, num[MAXN], dp[MAXN][MAXN], next_[2][MAXN];

int busca2(int k)
{
    if (k > num[n]) return n;

    int ini = 1, fim = n, ans;
    while (ini <= fim)
    {
        int mid = (ini+fim)>>1;

        if (num[mid] <= k) ans = mid, ini = mid+1;
        else fim = mid-1;
    }
    return ans;
}

bool ok(int w)
{
    memset(dp, 0, sizeof dp);
    for (int i = 1; i <= p; i++)
        for (int j = 1; j <= q; j++)
            dp[i][j] = 1;

    for (int i = 1; i <= n; i++)
        next_[0][i] = busca2(num[i]+w-1), next_[1][i] = busca2(num[i]+2*w-1);

    for (int i = 0; i <= p; i++)
    {
        for (int j = 0; j <= q; j++)
        {
            if (i)
                dp[i][j] = max(dp[i][j], next_[0][min(n, dp[i-1][j]+1)]);
            if (j)
                dp[i][j] = max(dp[i][j], next_[1][min(n, dp[i][j-1]+1)]);
        }
    }
    return (dp[p][q] >= n);
}

int busca(void)
{
    int ini = 1, fim = 1e9+10, ans;
    while (ini <= fim)
    {
        int mid = (ini+fim)>>1;

        if (ok(mid)) ans = mid, fim = mid-1;
        else ini = mid+1;
    }
    return ans;
}

int main(void)
{
    scanf("%d %d %d", &n, &p, &q);

    for (int i = 1; i <= n; i++) scanf("%d", &num[i]);

    if (p+q >= n)
    {
        cout << "1\n";
        return 0;
    }

    sort(num+1, num+n+1);
    printf("%d\n", busca());
}

Compilation message

watching.cpp: In function 'int main()':
watching.cpp:64: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:66: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", &num[i]);
                                  ~~~~~^~~~~~~~~~~~~~~
watching.cpp: In function 'int busca2(int)':
watching.cpp:15:27: warning: 'ans' may be used uninitialized in this function [-Wmaybe-uninitialized]
     int ini = 1, fim = n, ans;
                           ^~~
watching.cpp: In function 'bool ok(int)':
watching.cpp:34:55: warning: 'ans' may be used uninitialized in this function [-Wmaybe-uninitialized]
         next_[0][i] = busca2(num[i]+w-1), next_[1][i] = busca2(num[i]+2*w-1);
                                           ~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~
watching.cpp:34:21: warning: 'ans' may be used uninitialized in this function [-Wmaybe-uninitialized]
         next_[0][i] = busca2(num[i]+w-1), next_[1][i] = busca2(num[i]+2*w-1);
         ~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~
watching.cpp: In function 'int busca()':
watching.cpp:59:12: warning: 'ans' may be used uninitialized in this function [-Wmaybe-uninitialized]
     return ans;
            ^~~
# 결과 실행 시간 메모리 Grader output
1 Correct 51 ms 16044 KB Output is correct
2 Correct 2 ms 16044 KB Output is correct
3 Correct 48 ms 16176 KB Output is correct
4 Correct 2 ms 16176 KB Output is correct
5 Correct 2 ms 16176 KB Output is correct
6 Correct 2 ms 16176 KB Output is correct
7 Correct 52 ms 16448 KB Output is correct
8 Correct 48 ms 16448 KB Output is correct
9 Correct 49 ms 16448 KB Output is correct
10 Correct 82 ms 16508 KB Output is correct
11 Correct 53 ms 16508 KB Output is correct
12 Correct 109 ms 16508 KB Output is correct
13 Correct 52 ms 16508 KB Output is correct
14 Correct 51 ms 16508 KB Output is correct
15 Correct 46 ms 16508 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 60 ms 16508 KB Output is correct
2 Correct 2 ms 16508 KB Output is correct
3 Correct 2 ms 16508 KB Output is correct
4 Correct 2 ms 16508 KB Output is correct
5 Correct 2 ms 16508 KB Output is correct
6 Correct 2 ms 16508 KB Output is correct
7 Correct 105 ms 16572 KB Output is correct
8 Correct 91 ms 16572 KB Output is correct
9 Correct 97 ms 16572 KB Output is correct
10 Correct 124 ms 16572 KB Output is correct
11 Correct 122 ms 16572 KB Output is correct
12 Correct 336 ms 16572 KB Output is correct
13 Correct 66 ms 16636 KB Output is correct
14 Correct 61 ms 16636 KB Output is correct
15 Correct 143 ms 16636 KB Output is correct