CSES - Datatähti 2024 loppu - Results
Submission details
Task:Retkeily
Sender:adex720
Submission time:2024-01-20 16:37:17 +0200
Language:C++11
Status:COMPILE ERROR

Compiler report

input/code.cpp: In function 'bool onTeltta(int, int, int, std::pair<int, int>*)':
input/code.cpp:74:31: error: expected primary-expression before '=' token
   74 |         if (teltta.first > x) = v.at(0);
      |                               ^
input/code.cpp:74:33: error: 'v' was not declared in this scope
   74 |         if (teltta.first > x) = v.at(0);
      |                                 ^

Code

#include <bits/stdc++.h>
#include <iostream>
#include <vector>

using namespace std;

#define MP make_pair

void m1(int n, int m)
{
    pair<int, int> teltat[n];
    pair<int, int> paikat[m];

    int x, y;
    for (int i = 0; i < n; i++)
    {
        cin >> x >> y;
        teltat[i] = MP(x, y);
    }

    for (int i = 0; i < m; i++)
    {
        cin >> x >> y;
        paikat[i] = MP(x, y);
    }

    int suurin = 1;
    for (int i = 0; i < m; i++)
    {
        x = paikat[i].first;
        y = paikat[i].second;

        int pienin = INT_MAX;
        for (int j = 0; j < n; j++)
        {
            int etaisyys = abs(x - teltat[j].first) + abs(y - teltat[j].second);
            if (etaisyys < pienin)
            {
                pienin = etaisyys;
            }
        }

        if (pienin > suurin)
        {
            suurin = pienin;
        }
    }

    cout << suurin;
}

bool onTeltta(int x, int y, int n, pair<int, int> teltat[])
{
    int min = 0;
    int max = n - 1;

    while (true)
    {
        if (min >= max)
        {
            auto teltta = teltat[min];
            return teltta.first == x && teltta.second == y;
        }

        int keski = (min + max) >> 1;
        auto teltta = teltat[keski];

        if (teltta.first < x)
        {
            min = keski + 1;
            continue;
        }

        if (teltta.first > x) = v.at(0);
        {
            max = keski - 1;
            continue;
        }

        if (teltta.second < y)
        {
            min = keski + 1;
            continue;
        }

        if (teltta.second > y)
        {
            max = keski - 1;
            continue;
        }

        return true;
    }
}

void m3(int n, int m, pair<int, int> teltat[], pair<int, int> paikat[])
{
    int x, y, x2, y2, y3;
    int suurin = 1;

    for (int i = 0; i < m; i++)
    {
        x = paikat[i].first;
        y = paikat[i].second;

        bool b = false;
        for (int d = 1; d <= 10; d++)
        {
            bool l = false;
            for (int m = -d; m < d; m++)
            {
                x2 = x + m;
                y2 = y + abs(d - abs(m));
                y3 = y - abs(d - abs(m));

                if (x2 < 0 || x2 > 1000000)
                {
                    continue;
                }

                if (y2 <= 1000000)
                {
                    if (onTeltta(x2, y2, n, teltat))
                    {
                        if (d > suurin)
                        {
                            suurin = d;
                        }
                        l = true;
                        break;
                    }
                }

                if (y3 >= 0)
                {
                    if (onTeltta(x2, y3, n, teltat))
                    {
                        if (d > suurin)
                        {
                            suurin = d;
                        }
                        l = true;
                        break;
                    }
                }
            }

            if (l)
            {
                b = true;
                break;
            }
        }

        /*if (!b)
        {
            cout << "10";
            return;
        }*/
    }

    cout << suurin;
}
void m2(int n, int m)
{

    pair<int, int> teltat[n];
    pair<int, int> paikat[m];

    int x, y;
    int isoin = 1;
    for (int i = 0; i < n; i++)
    {
        cin >> x >> y;
        x--;
        y--;
        teltat[i] = MP(x, y);
        if (isoin <= 1000)
        {
            isoin = max(x, y);
        }
    }

    for (int i = 0; i < m; i++)
    {
        cin >> x >> y;
        x--;
        y--;
        paikat[i] = MP(x, y);
        if (isoin <= 1000)
        {
            isoin = max(x, y);
        }
    }

    if (isoin > 1000)
    {
        sort(teltat, teltat + n); // ehkä
        sort(paikat, paikat + m); // ehkä
        m3(n, m, teltat, paikat);
        return;
    }

    int d[1000000];
    bool c[1000000];

    priority_queue<pair<int, pair<int, int>>> q;
    pair<int, int> teltta;

    for (int i = 0; i < n; i++)
    {
        teltta = teltat[i];
        x = teltta.first;
        y = teltta.second;

        d[x * 1000 + y] = 0;
        c[x * 1000 + y] = 1;

        if (x > 0)
        {
            if (!c[(x - 1) * 1000 + y])
            {
                q.push(MP(-1, MP(x - 1, y)));
                c[(x - 1) * 1000 + y] = 1;
            }
        }
        if (x < 999)
        {
            if (!c[(x + 1) * 1000 + y])
            {
                q.push(MP(-1, MP(x + 1, y)));
                c[(x + 1) * 1000 + y] = 1;
            }
        }
        if (y > 0)
        {
            if (!c[x * 1000 + y - 1])
            {
                q.push(MP(-1, MP(x, y - 1)));
                c[x * 1000 + y - 1] = 1;
            }
        }
        if (y < 999)
        {
            if (!c[x * 1000 + y + 1])
            {
                q.push(MP(-1, MP(x, y + 1)));
                c[x * 1000 + y + 1] = 1;
            }
        }
    }

    int dist;
    while (!q.empty())
    {
        auto ruutu = q.top();
        q.pop();

        dist = -ruutu.first;
        x = ruutu.second.first;
        y = ruutu.second.second;

        d[x * 1000 + y] = dist;

        if (x > 0)
        {
            if (!c[(x - 1) * 1000 + y])
            {
                q.push(MP(-dist - 1, MP(x - 1, y)));
                c[(x - 1) * 1000 + y] = 1;
            }
        }
        if (x < 999)
        {
            if (!c[(x + 1) * 1000 + y])
            {
                q.push(MP(-dist - 1, MP(x + 1, y)));
                c[(x + 1) * 1000 + y] = 1;
            }
        }
        if (y > 0)
        {
            if (!c[x * 1000 + y - 1])
            {
                q.push(MP(-dist - 1, MP(x, y - 1)));
                c[x * 1000 + y - 1] = 1;
            }
        }
        if (y < 999)
        {
            if (!c[x * 1000 + y + 1])
            {
                q.push(MP(-dist - 1, MP(x, y + 1)));
                c[x * 1000 + y + 1] = 1;
            }
        }
    }

    int suurin = 1;
    int arvo;
    for (int i = 0; i < m; i++)
    {
        auto paikka = paikat[i];

        x = paikka.first;
        y = paikka.second;

        arvo = d[x * 1000 + y];
        if (arvo > suurin)
        {
            suurin = arvo;
        }
    }

    /*for (int x = 0; x < 20; x++)
    {
        for (int y = 0; y < 20; y++)
        {
            cout << d[x * 1000 + y] << "    ";
        }

        cout << "\n";
    }*/

    cout << suurin;
}

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

    int n, m;
    cin >> n >> m;

    if (n <= 1000 && m <= 1000)
    {
        m1(n, m);
        return 0;
    }

    m2(n, m);
}