제출 #1161335

#제출 시각아이디문제언어결과실행 시간메모리
1161335Der_VlaposMaze (JOI23_ho_t3)C++20
8 / 100
121 ms1576 KiB
#include <bits/stdc++.h>

using namespace std;

#define ll long long
#define pii pair<int, int>
#define f first
#define s second
#define all(v) v.begin(), v.end()
#define pb push_back

const int BIG = 1e9 + 10;

struct test
{
    void solve()
    {
        int n, m, k;
        cin >> n >> m >> k;
        int x1 = 0, y1 = 0, x2 = 0, y2 = 0;
        cin >> x1 >> y1 >> x2 >> y2;
        --x1, --y1;
        --x2, --y2;

        vector<vector<bool>> f(n, vector<bool>(m));
        for (int i = 0; i < n; ++i)
            for (int j = 0; j < m; ++j)
            {
                char x;
                cin >> x;
                f[i][j] = x == '.';
            }
        queue<pii> els;
        vector<vector<bool>> was(n, vector<bool>(m, 0));
        els.push({x1, y1});
        was[x1][y1] = 1;

        const int dx4[4] = {-1, 0, 0, 1};
        const int dy4[4] = {0, 1, -1, 0};

        auto good = [&](int x, int y) -> bool
        { return x >= 0 and y >= 0 and x < n and y < m; };

        int CNT = 0;
        while (!was[x2][y2])
        {
            // go through white
            queue<pair<pii, int>> adjacent_black;

            while (els.size())
            {
                auto [x, y] = els.front();
                els.pop();
                for (int d = 0; d < 4; ++d)
                {
                    int tox = x + dx4[d];
                    int toy = y + dy4[d];
                    if (good(tox, toy) and !was[tox][toy])
                    {
                        if (f[tox][toy])
                            els.push({tox, toy});
                        else
                        {
                            adjacent_black.push({{tox, toy}, k});
                        }
                        was[tox][toy] = 1;
                    }
                }
            }

            if (was[x2][y2])
                break;
            CNT++;

            queue<pii> newels;
            while (adjacent_black.size())
            {
                auto [c, D] = adjacent_black.front();
                adjacent_black.pop();
                auto [x, y] = c;

                if (D)
                {
                    f[x][y] = 1;
                    newels.push({x, y});
                }
                else
                {
                    if (f[x][y])
                        newels.push({x, y});
                    else
                        was[x][y] = 0;
                    continue;
                }
                for (int d = 0; d < 4; ++d)
                {
                    int tox = x + dx4[d];
                    int toy = y + dy4[d];
                    if (good(tox, toy) and !was[tox][toy])
                    {
                        adjacent_black.push({{tox, toy}, D - 1});
                        was[tox][toy] = 1;
                    }
                }
            }
            els = newels;
        }
        cout << CNT << "\n";
    }
};

main()
{
    test t;
    t.solve();
}

컴파일 시 표준 에러 (stderr) 메시지

Main.cpp:112:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
  112 | main()
      | ^~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...