Submission #56547

# Submission time Handle Problem Language Result Execution time Memory
56547 2018-07-11T15:49:28 Z luciocf Watching (JOI13_watching) C++14
Compilation error
0 ms 0 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 'bool ok(int)':
watching.cpp:34:9: error: reference to 'next' is ambiguous
         next[0][i] = busca2(num[i]+w-1), next[1][i] = busca2(num[i]+2*w-1);
         ^~~~
watching.cpp:9:41: note: candidates are: int next [2][2010]
 int n, p, q, num[MAXN], dp[MAXN][MAXN], next[2][MAXN];
                                         ^~~~
In file included from /usr/include/c++/7/bits/stl_algobase.h:66:0,
                 from /usr/include/c++/7/bits/char_traits.h:39,
                 from /usr/include/c++/7/ios:40,
                 from /usr/include/c++/7/istream:38,
                 from /usr/include/c++/7/sstream:38,
                 from /usr/include/c++/7/complex:45,
                 from /usr/include/c++/7/ccomplex:39,
                 from /usr/include/x86_64-linux-gnu/c++/7/bits/stdc++.h:52,
                 from watching.cpp:1:
/usr/include/c++/7/bits/stl_iterator_base_funcs.h:208:5: note:                 template<class _ForwardIterator> _ForwardIterator std::next(_ForwardIterator, typename std::iterator_traits<_Iter>::difference_type)
     next(_ForwardIterator __x, typename
     ^~~~
watching.cpp:34:42: error: reference to 'next' is ambiguous
         next[0][i] = busca2(num[i]+w-1), next[1][i] = busca2(num[i]+2*w-1);
                                          ^~~~
watching.cpp:9:41: note: candidates are: int next [2][2010]
 int n, p, q, num[MAXN], dp[MAXN][MAXN], next[2][MAXN];
                                         ^~~~
In file included from /usr/include/c++/7/bits/stl_algobase.h:66:0,
                 from /usr/include/c++/7/bits/char_traits.h:39,
                 from /usr/include/c++/7/ios:40,
                 from /usr/include/c++/7/istream:38,
                 from /usr/include/c++/7/sstream:38,
                 from /usr/include/c++/7/complex:45,
                 from /usr/include/c++/7/ccomplex:39,
                 from /usr/include/x86_64-linux-gnu/c++/7/bits/stdc++.h:52,
                 from watching.cpp:1:
/usr/include/c++/7/bits/stl_iterator_base_funcs.h:208:5: note:                 template<class _ForwardIterator> _ForwardIterator std::next(_ForwardIterator, typename std::iterator_traits<_Iter>::difference_type)
     next(_ForwardIterator __x, typename
     ^~~~
watching.cpp:41:42: error: reference to 'next' is ambiguous
                 dp[i][j] = max(dp[i][j], next[0][min(n, dp[i-1][j]+1)]);
                                          ^~~~
watching.cpp:9:41: note: candidates are: int next [2][2010]
 int n, p, q, num[MAXN], dp[MAXN][MAXN], next[2][MAXN];
                                         ^~~~
In file included from /usr/include/c++/7/bits/stl_algobase.h:66:0,
                 from /usr/include/c++/7/bits/char_traits.h:39,
                 from /usr/include/c++/7/ios:40,
                 from /usr/include/c++/7/istream:38,
                 from /usr/include/c++/7/sstream:38,
                 from /usr/include/c++/7/complex:45,
                 from /usr/include/c++/7/ccomplex:39,
                 from /usr/include/x86_64-linux-gnu/c++/7/bits/stdc++.h:52,
                 from watching.cpp:1:
/usr/include/c++/7/bits/stl_iterator_base_funcs.h:208:5: note:                 template<class _ForwardIterator> _ForwardIterator std::next(_ForwardIterator, typename std::iterator_traits<_Iter>::difference_type)
     next(_ForwardIterator __x, typename
     ^~~~
watching.cpp:43:42: error: reference to 'next' is ambiguous
                 dp[i][j] = max(dp[i][j], next[1][min(n, dp[i][j-1]+1)]);
                                          ^~~~
watching.cpp:9:41: note: candidates are: int next [2][2010]
 int n, p, q, num[MAXN], dp[MAXN][MAXN], next[2][MAXN];
                                         ^~~~
In file included from /usr/include/c++/7/bits/stl_algobase.h:66:0,
                 from /usr/include/c++/7/bits/char_traits.h:39,
                 from /usr/include/c++/7/ios:40,
                 from /usr/include/c++/7/istream:38,
                 from /usr/include/c++/7/sstream:38,
                 from /usr/include/c++/7/complex:45,
                 from /usr/include/c++/7/ccomplex:39,
                 from /usr/include/x86_64-linux-gnu/c++/7/bits/stdc++.h:52,
                 from watching.cpp:1:
/usr/include/c++/7/bits/stl_iterator_base_funcs.h:208:5: note:                 template<class _ForwardIterator> _ForwardIterator std::next(_ForwardIterator, typename std::iterator_traits<_Iter>::difference_type)
     next(_ForwardIterator __x, typename
     ^~~~
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]);
                                  ~~~~~^~~~~~~~~~~~~~~