Submission #1059766

# Submission time Handle Problem Language Result Execution time Memory
1059766 2024-08-15T08:03:16 Z aykhn Soccer Stadium (IOI23_soccer) C++17
Compilation error
0 ms 0 KB
#include <bits/stdc++.h>
#include "soccer.h"
 
using namespace std;
 
int n;
vector<vector<int>> A;
int dp[31][31][31][31];
int cur;
 
int f(int i, int pos, int l, int r)
{
    if (i < 0 || i >= n) return 0;
    if (l > r) return 0;
    if (pos >= n) return 0;
    if (dp[i][pos][l][r] != -1) return dp[i][pos][l][r];
    vector<int> v;
    v.push_back(l - 1);
    for (int j = l; j <= r; j++) if (A[i][j]) v.push_back(j);
    v.push_back(r + 1);
    int res = 0;
    for (int j = 1; j < v.size(); j++)
    {
        if (i <= cur) 
        {
            res = max(res, f(i - 1, pos + 1, v[j - 1] + 1, v[j] - 1) + (v[j] - v[j - 1] - 1));
            res = max(res, f(cur + (pos - (cur - i)) + 1, pos + 1, v[j - 1] + 1, v[j] - 1) + (v[j] - v[j - 1] - 1));
        }
        else
        {
            res = max(res, f(i + 1, pos + 1, v[j - 1] + 1, v[j] - 1) + (v[j] - v[j - 1] - 1));
            res = max(res, f(cur - (pos - (i - cur)) - 1, pos + 1, v[j - 1] + 1, v[j] - 1) + (v[j] - v[j - 1] - 1));
        }
    }
    return dp[i][pos][l][r] = res;
}
 
int solve()
{
    for (int i = 0; i < 31; i++)
    {
        for (int j = 0; j < 31; j++)
        {
            for (int k = 0; k < 31; k++)
            {
                for (int l = k; l < 31; l++) dp[i][j][k][l] = -1;
            }
        }
    }
    return f(cur, 0, 0, n - 1);
}
 
int calc(int i, int j)
{
    return i * n + j * n - i * j;
}
 
int biggest_stadium(int N, vector<vector<int>> B)
{
    n = N;
    A = B;
    int c = 0;
    for (int i = 0; i < n; i++)
    {
        for (int j = 0; j < n; j++)
        {
            c += A[i][j];
        }
    }
    if (c == 1)
    {
        for (int i = 0; i < n; i++)
        {
            for (int j = 0; j < n; j++)
            {
                if (A[i][j])
                {
                    int i1 = n - i - 1, j1 = n - j - 1;
                    return max({calc(i, j), calc(i1, j), calc(i, j1), calc(i1, j1)});
                }
            }
        }
    }
    int ok = 1, c1 = 0;
    int l[N], r[N], cnt[N];
    array<int, 2> mx = {-1, -1};
    for (int i = 0; i < n; i++)
    {
        cnt[i] = 0;
        l[i] = n + 1, r[i] = -1;
        for (int j = 0; j < n; j++)
        {
            if (A[i][j]) continue;
            cnt[i]++,
            l[i] = min(l, j), r[i] = max(r, j);
        }
        if (!cnt[i]) continue;
        if (cnt[i] != r - l + 1) ok = 0;
        c1++;
        mx = max(mx, {cnt[i], i});
    }
    if (ok)
    {
        int lx = mx[1], rx = mx[1];
        int last = mx[1];
        while (lx >= 0 || rx < N)
        {
            if (cnt[lx] && lx >= 0 && (rx == N || cnt[lx] <= cnt[rx]))
            {
                if (!(l[last] <= l[lx] && r[lx] <= r[last])) 
                {
                    ok = 0;
                    break;
                }
                last = lx;
                lx--;
            }
            else if (cnt[rx] && rx < N && (lx == -1 || cnt[rx] <= cnt[lx]))
            {
                if (!(l[last] <= l[rx] && r[rx] <= r[last])) 
                {
                    ok = 0;
                    break;
                }
                last = rx;
                rx++;
            }
        }
        if (rx - lx - 1 == c1 && ok)
        {
            return n * n - c;
        }
    }
    int res = 0;
    for (cur = 0; cur < n; cur++)
    {
        res = max(res, solve());
    }
    return res;
}

Compilation message

soccer.cpp: In function 'int f(int, int, int, int)':
soccer.cpp:22:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   22 |     for (int j = 1; j < v.size(); j++)
      |                     ~~^~~~~~~~~~
soccer.cpp: In function 'int biggest_stadium(int, std::vector<std::vector<int> >)':
soccer.cpp:95:28: error: no matching function for call to 'min(int [N], int&)'
   95 |             l[i] = min(l, j), r[i] = max(r, j);
      |                            ^
In file included from /usr/include/c++/10/bits/specfun.h:45,
                 from /usr/include/c++/10/cmath:1927,
                 from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:41,
                 from soccer.cpp:1:
/usr/include/c++/10/bits/stl_algobase.h:230:5: note: candidate: 'template<class _Tp> constexpr const _Tp& std::min(const _Tp&, const _Tp&)'
  230 |     min(const _Tp& __a, const _Tp& __b)
      |     ^~~
/usr/include/c++/10/bits/stl_algobase.h:230:5: note:   template argument deduction/substitution failed:
soccer.cpp:95:28: note:   variable-sized array type 'int [N]' is not a valid template argument
   95 |             l[i] = min(l, j), r[i] = max(r, j);
      |                            ^
In file included from /usr/include/c++/10/bits/specfun.h:45,
                 from /usr/include/c++/10/cmath:1927,
                 from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:41,
                 from soccer.cpp:1:
/usr/include/c++/10/bits/stl_algobase.h:278:5: note: candidate: 'template<class _Tp, class _Compare> constexpr const _Tp& std::min(const _Tp&, const _Tp&, _Compare)'
  278 |     min(const _Tp& __a, const _Tp& __b, _Compare __comp)
      |     ^~~
/usr/include/c++/10/bits/stl_algobase.h:278:5: note:   template argument deduction/substitution failed:
soccer.cpp:95:28: note:   variable-sized array type 'int [N]' is not a valid template argument
   95 |             l[i] = min(l, j), r[i] = max(r, j);
      |                            ^
In file included from /usr/include/c++/10/algorithm:62,
                 from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:65,
                 from soccer.cpp:1:
/usr/include/c++/10/bits/stl_algo.h:3468:5: note: candidate: 'template<class _Tp> constexpr _Tp std::min(std::initializer_list<_Tp>)'
 3468 |     min(initializer_list<_Tp> __l)
      |     ^~~
/usr/include/c++/10/bits/stl_algo.h:3468:5: note:   template argument deduction/substitution failed:
soccer.cpp:95:28: note:   mismatched types 'std::initializer_list<_Tp>' and 'int*'
   95 |             l[i] = min(l, j), r[i] = max(r, j);
      |                            ^
In file included from /usr/include/c++/10/algorithm:62,
                 from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:65,
                 from soccer.cpp:1:
/usr/include/c++/10/bits/stl_algo.h:3474:5: note: candidate: 'template<class _Tp, class _Compare> constexpr _Tp std::min(std::initializer_list<_Tp>, _Compare)'
 3474 |     min(initializer_list<_Tp> __l, _Compare __comp)
      |     ^~~
/usr/include/c++/10/bits/stl_algo.h:3474:5: note:   template argument deduction/substitution failed:
soccer.cpp:95:28: note:   mismatched types 'std::initializer_list<_Tp>' and 'int*'
   95 |             l[i] = min(l, j), r[i] = max(r, j);
      |                            ^
soccer.cpp:95:46: error: no matching function for call to 'max(int [N], int&)'
   95 |             l[i] = min(l, j), r[i] = max(r, j);
      |                                              ^
In file included from /usr/include/c++/10/bits/specfun.h:45,
                 from /usr/include/c++/10/cmath:1927,
                 from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:41,
                 from soccer.cpp:1:
/usr/include/c++/10/bits/stl_algobase.h:254:5: note: candidate: 'template<class _Tp> constexpr const _Tp& std::max(const _Tp&, const _Tp&)'
  254 |     max(const _Tp& __a, const _Tp& __b)
      |     ^~~
/usr/include/c++/10/bits/stl_algobase.h:254:5: note:   template argument deduction/substitution failed:
soccer.cpp:95:46: note:   variable-sized array type 'int [N]' is not a valid template argument
   95 |             l[i] = min(l, j), r[i] = max(r, j);
      |                                              ^
In file included from /usr/include/c++/10/bits/specfun.h:45,
                 from /usr/include/c++/10/cmath:1927,
                 from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:41,
                 from soccer.cpp:1:
/usr/include/c++/10/bits/stl_algobase.h:300:5: note: candidate: 'template<class _Tp, class _Compare> constexpr const _Tp& std::max(const _Tp&, const _Tp&, _Compare)'
  300 |     max(const _Tp& __a, const _Tp& __b, _Compare __comp)
      |     ^~~
/usr/include/c++/10/bits/stl_algobase.h:300:5: note:   template argument deduction/substitution failed:
soccer.cpp:95:46: note:   variable-sized array type 'int [N]' is not a valid template argument
   95 |             l[i] = min(l, j), r[i] = max(r, j);
      |                                              ^
In file included from /usr/include/c++/10/algorithm:62,
                 from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:65,
                 from soccer.cpp:1:
/usr/include/c++/10/bits/stl_algo.h:3480:5: note: candidate: 'template<class _Tp> constexpr _Tp std::max(std::initializer_list<_Tp>)'
 3480 |     max(initializer_list<_Tp> __l)
      |     ^~~
/usr/include/c++/10/bits/stl_algo.h:3480:5: note:   template argument deduction/substitution failed:
soccer.cpp:95:46: note:   mismatched types 'std::initializer_list<_Tp>' and 'int*'
   95 |             l[i] = min(l, j), r[i] = max(r, j);
      |                                              ^
In file included from /usr/include/c++/10/algorithm:62,
                 from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:65,
                 from soccer.cpp:1:
/usr/include/c++/10/bits/stl_algo.h:3486:5: note: candidate: 'template<class _Tp, class _Compare> constexpr _Tp std::max(std::initializer_list<_Tp>, _Compare)'
 3486 |     max(initializer_list<_Tp> __l, _Compare __comp)
      |     ^~~
/usr/include/c++/10/bits/stl_algo.h:3486:5: note:   template argument deduction/substitution failed:
soccer.cpp:95:46: note:   mismatched types 'std::initializer_list<_Tp>' and 'int*'
   95 |             l[i] = min(l, j), r[i] = max(r, j);
      |                                              ^