CSES - Datatähti 2024 alku - Results
Submission details
Task:Uolevin kalansaalis
Sender:snowflake
Submission time:2023-11-11 21:59:52 +0200
Language:C++ (C++17)
Status:COMPILE ERROR

Compiler report

input/code.cpp:12:17: error: reference to 'size' is ambiguous
   12 | int invgridvals[size][size];
      |                 ^~~~
In file included from /usr/include/c++/11/string:54,
                 from /usr/include/c++/11/bits/locale_classes.h:40,
                 from /usr/include/c++/11/bits/ios_base.h:41,
                 from /usr/include/c++/11/ios:42,
                 from /usr/include/c++/11/ostream:38,
                 from /usr/include/c++/11/iostream:39,
                 from input/code.cpp:1:
/usr/include/c++/11/bits/range_access.h:254:5: note: candidates are: 'template<class _Tp, long unsigned int _Nm> constexpr std::size_t std::size(const _Tp (&)[_Nm])'
  254 |     size(const _Tp (&)[_Nm]) noexcept
      |     ^~~~
/usr/include/c++/11/bits/range_access.h:245:5: note:                 'template<class _Container> constexpr decltype (__cont.size()) std::size(const _Container&)'
  245 |     size(const _Container& __cont) noexcept(noexcept(__cont.size()))
      |     ^~~~
input...

Code

#include <iostream>
#include <algorithm>
#include <cmath>
using namespace std;

const int NEQ = -4096;
const int size = 512;

const char hauki = 'H';
const char katkarapu = 'K';

int invgridvals[size][size];
int trigs[size][size][size]; // [s][en][em]

int n;
int m;
int k;

int totalcut = 0;
int triangleboost = -2147483646;

void Setbounds()
{
    for (int en = 0; en <= n + 1; en++)
    {
        for (int em = 0; em <= m + 1; em++)
        {
            if (en < 1 || en > n || em < 1 || em > m)
            {
                for (int s = 0; s < size; s++)
                    trigs[s][en][em] = NEQ;
                invgridvals[en][em] = NEQ;
            }
        }
    }
}

void Calctridown() // down
{
    for (int en = 1; en <= n; en++)
    {
        for (int em = 1; em <= m; em++)
        {
            int s = 1;

            trigs[s][en][em] = invgridvals[en][em];

            triangleboost = max(triangleboost, trigs[s][en][em]);
        }
    }

    for (int en = 1; en <= n; en++)
    {
        for (int em = 1; em <= m; em++)
        {
            int s = 2;

            if (en == 1) trigs[s][en][em] = NEQ;
            else if (en % 2 == 1) trigs[s][en][em] = invgridvals[en][em] + invgridvals[en - 1][em - 1] + invgridvals[en - 1][em];
            else trigs[s][en][em] = invgridvals[en][em] + invgridvals[en - 1][em] + invgridvals[en - 1][em + 1];

            triangleboost = max(triangleboost, trigs[s][en][em]);
        }
    }

    for (int s = 3; s <= n; s++)
    {
        for (int en = 1; en <= n; en++)
        {
            for (int em = 1; em <= m; em++)
            {
                if (en < s) trigs[s][en][em] = NEQ;
                else if (en % 2 == 1) trigs[s][en][em] = invgridvals[en][em] + trigs[s - 1][en - 1][em - 1] + trigs[s - 1][en - 1][em] - trigs[s - 2][en - 2][em];
                else trigs[s][en][em] = invgridvals[en][em] + trigs[s - 1][en - 1][em] + trigs[s - 1][en - 1][em + 1] - trigs[s - 2][en - 2][em];

                int cur = trigs[s][en][em];
                if (cur <= NEQ + 1 || cur >= -NEQ - 1) trigs[s][en][em] = NEQ;
                else if (cur > triangleboost) triangleboost = cur;
            }
        }
    }
}

void Calctriup() // up
{
    for (int en = n; en >= 1; en--)
    {
        for (int em = 1; em <= m; em++)
        {
            int s = 1;

            trigs[s][en][em] = invgridvals[en][em];

            triangleboost = max(triangleboost, trigs[s][en][em]);
        }
    }

    for (int en = n; en >= 1; en--)
    {
        for (int em = 1; em <= m; em++)
        {
            int s = 2;

            if (en == n) trigs[s][en][em] = NEQ;
            else if (en % 2 == 1) trigs[s][en][em] = invgridvals[en][em] + invgridvals[en + 1][em + 1] + invgridvals[en + 1][em];
            else trigs[s][en][em] = invgridvals[en][em] + invgridvals[en + 1][em] + invgridvals[en + 1][em + 1];

            triangleboost = max(triangleboost, trigs[s][en][em]);
        }
    }

    for (int s = 3; s <= n; s++)
    {
        for (int en = n; en >= 1; en--)
        {
            for (int em = 1; em >= m; em++)
            {
                if (en > n - s + 1) trigs[s][en][em] = NEQ;
                else if (en % 2 == 1) trigs[s][en][em] = invgridvals[en][em] + trigs[s - 1][en + 1][em - 1] + trigs[s - 1][en + 1][em] - trigs[s - 2][en + 2][em];
                else trigs[s][en][em] = invgridvals[en][em] + trigs[s - 1][en  + 1][em] + trigs[s - 1][en  + 1][em + 1] - trigs[s - 2][en  + 2][em];

                int cur = trigs[s][en][em];
                if (cur <= NEQ + 1 || cur >= -NEQ - 1) trigs[s][en][em] = NEQ;
                else if (cur > triangleboost) triangleboost = cur;
            }
        }
    }
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);

    cin >> n >> m >> k;

    for (int z = 0; z < k; z++)
    {
        int x;
        int y;
        char spec;
        cin >> x >> y >> spec;

        if (spec == katkarapu)
        {
            invgridvals[x][y] = 10;
            totalcut -= 10;
        }
        else if (spec == hauki)
        {
            invgridvals[x][y] = -1;
            totalcut += 1;
        }
    }

    Setbounds();

    Calctridown();
    Calctriup();

    cout << totalcut + triangleboost;
}


// 5 6 13
// 1 1 K
// 5 1 K
// 2 6 K
// 3 4 K
// 3 6 K
// 4 4 K
// 2 2 H
// 4 2 H
// 5 2 H
// 3 3 H
// 3 5 H
// 2 5 H
// 5 5 H

// > -16



// 5 6 11
// 1 4 K
// 2 4 K
// 2 3 K
// 2 2 H
// 4 2 H
// 5 2 H
// 3 3 H
// 3 5 H
// 2 5 H
// 5 5 H
// 4 3 H

// > 8



// 3 2 5
// 1 1 K
// 1 2 H
// 2 1 K
// 2 2 H
// 3 1 H

// > 2





// 3 2 6
// 1 1 H
// 1 2 H
// 2 1 H
// 2 2 H
// 3 1 H
// 3 2 H

// > 5