Submission #1314697

#TimeUsernameProblemLanguageResultExecution timeMemory
1314697menkhMecho (IOI09_mecho)C++20
Compilation error
0 ms0 KiB
#include <bits/stdc++.h>
using namespace std;

#define ll long long
#define FORD(i, b, a) for (int i = (b), _a = (a); i >= _a; i--)
#define FOR(i, a, b) for (int i = (a), _b = (b); i <= _b; i++)
#define REP(i, n) for (int i = 0, _n = (n); i < _n; i++)

#define MAX 805
const int INF = 1000000000 + 10;
char forest[MAX][MAX];
int bear[MAX][MAX];
int ong[MAX][MAX];
bool vis[MAX][MAX];
int n, S;

int dx[4] = {0, 0, -1, 1};
int dy[4] = {1, -1, 0, 0};

int x1, y1, x2, y2;

bool check(int k) {
    if (k >= ong[x1][y1]) return false;

    FOR(i,1,n) FOR(j,1,n) bear[i][j] = INF;

    queue<pair<int,int>> q;
    bear[x1][y1] = k;
    q.push({x1, y1});

    while (!q.empty()) {
        auto it = q.front(); q.pop();
        int x = it.first, y = it.second;

        FOR(i,1,n) FOR(j,1,n) vis[i][j] = false;

        queue<pair<pair<int,int>,int>> qlocal;
        qlocal.push({{x, y}, 0});
        vis[x][y] = true;

        while (!qlocal.empty()) {
            auto cur = qlocal.front(); qlocal.pop();
            int cx = cur.first.first;
            int cy = cur.first.second;
            int steps = cur.second;
            int t = bear[x][y];

            if (ong[cx][cy] > t + 1 && bear[cx][cy] > t + 1) {
                bear[cx][cy] = t + 1;
                q.push({cx, cy});
            }

            if (steps == S) continue;

            FOR(d,0,3) {
                int nx = cx + dx[d];
                int ny = cy + dy[d];
                if (nx < 1 || ny < 1 || nx > n || ny > n) continue;
                if (vis[nx][ny]) continue;
                if (forest[nx][ny] == 'T' || forest[nx][ny] == 'H') continue;
                if (ong[nx][ny] <= t) continue;

                vis[nx][ny] = true;
                qlocal.push({{nx, ny}, steps + 1});
            }
        }
    }

    return bear[x2][y2] != INF;
}

void solve() {
    cin >> n >> S;
    FOR(i,1,n) FOR(j,1,n) {
        cin >> forest[i][j];
        if (forest[i][j] == 'M') x1 = i, y1 = j;
        if (forest[i][j] == 'D') x2 = i, y2 = j;
    }

    FOR(i,1,n) FOR(j,1,n) {
        ong[i][j] = INF;
        vis[i][j] = false;
    }

    queue<pair<int,int>> s;
    FOR(i,1,n) FOR(j,1,n)
        if (forest[i][j] == 'H') {
            ong[i][j] = 0;
            vis[i][j] = true;
            s.push({i,j});
        }

    while (!s.empty()) {
        auto up = s.front(); s.pop();
        int x = up.first, y = up.second;
        FOR(d,0,3) {
            int nx = x + dx[d], ny = y + dy[d];
            if (nx < 1 || ny < 1 || nx > n || ny > n) continue;
            if (vis[nx][ny]) continue;
            if (forest[nx][ny] == 'T' || forest[nx][ny] == 'D') continue;
            ong[nx][ny] = ong[x][y] + 1;
            vis[nx][ny] = true;
            s.push({nx, ny});
        }
    }

    int low = 0, high = 2027, ans = 0;
    while (low <= high) {
        int mid = (low + high) / 2;
        if (check(mid)) ans = mid, low = mid + 1;
        else high = mid - 1;
    }

    cout << ans << '\n';
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    solve();
}

Compilation message (stderr)

mecho.cpp:20:9: error: 'int y1' redeclared as different kind of entity
   20 | int x1, y1, x2, y2;
      |         ^~
In file included from /usr/include/features.h:502,
                 from /usr/include/x86_64-linux-gnu/c++/13/bits/os_defines.h:39,
                 from /usr/include/x86_64-linux-gnu/c++/13/bits/c++config.h:679,
                 from /usr/include/c++/13/cassert:43,
                 from /usr/include/x86_64-linux-gnu/c++/13/bits/stdc++.h:33,
                 from mecho.cpp:1:
/usr/include/x86_64-linux-gnu/bits/mathcalls.h:224:1: note: previous declaration 'double y1(double)'
  224 | __MATHCALL (y1,, (_Mdouble_));
      | ^~~~~~~~~~
mecho.cpp: In function 'bool check(int)':
mecho.cpp:23:21: error: invalid types 'int [805][double(double) noexcept]' for array subscript
   23 |     if (k >= ong[x1][y1]) return false;
      |                     ^
mecho.cpp:28:13: error: invalid types 'int [805][double(double) noexcept]' for array subscript
   28 |     bear[x1][y1] = k;
      |             ^
mecho.cpp:29:11: error: no matching function for call to 'std::queue<std::pair<int, int> >::push(<brace-enclosed initializer list>)'
   29 |     q.push({x1, y1});
      |     ~~~~~~^~~~~~~~~~
In file included from /usr/include/c++/13/queue:66,
                 from /usr/include/x86_64-linux-gnu/c++/13/bits/stdc++.h:157:
/usr/include/c++/13/bits/stl_queue.h:285:7: note: candidate: 'void std::queue<_Tp, _Sequence>::push(const value_type&) [with _Tp = std::pair<int, int>; _Sequence = std::deque<std::pair<int, int>, std::allocator<std::pair<int, int> > >; value_type = std::pair<int, int>]'
  285 |       push(const value_type& __x)
      |       ^~~~
/usr/include/c++/13/bits/stl_queue.h:285:30: note:   no known conversion for argument 1 from '<brace-enclosed initializer list>' to 'const std::queue<std::pair<int, int> >::value_type&' {aka 'const std::pair<int, int>&'}
  285 |       push(const value_type& __x)
      |            ~~~~~~~~~~~~~~~~~~^~~
/usr/include/c++/13/bits/stl_queue.h:290:7: note: candidate: 'void std::queue<_Tp, _Sequence>::push(value_type&&) [with _Tp = std::pair<int, int>; _Sequence = std::deque<std::pair<int, int>, std::allocator<std::pair<int, int> > >; value_type = std::pair<int, int>]'
  290 |       push(value_type&& __x)
      |       ^~~~
/usr/include/c++/13/bits/stl_queue.h:290:25: note:   no known conversion for argument 1 from '<brace-enclosed initializer list>' to 'std::queue<std::pair<int, int> >::value_type&&' {aka 'std::pair<int, int>&&'}
  290 |       push(value_type&& __x)
      |            ~~~~~~~~~~~~~^~~
mecho.cpp: In function 'void solve()':
mecho.cpp:76:45: error: assignment of function 'double y1(double)'
   76 |         if (forest[i][j] == 'M') x1 = i, y1 = j;
      |                                          ~~~^~~