답안 #1105322

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1105322 2024-10-26T07:14:23 Z duckindog Maze (JOI23_ho_t3) C++17
0 / 100
2000 ms 1492 KB
#include <bits/stdc++.h>

using namespace std;

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

int32_t main() { 
  cin.tie(0)->sync_with_stdio(0);

  int r, c, n; cin >> r >> c >> n;
  int Sr, Sc; cin >> Sr >> Sc;
  int Gr, Gc; cin >> Gr >> Gc;

  vector<vector<char>> a(r + 10, vector<char>(c + 10));
  for (int i = 1; i <= r; ++i) { 
    for (int j = 1; j <= c; ++j) cin >> a[i][j];
  }
  auto in = [&](int x, int y) { return 1 <= x && x <= r && 1 <= y && y <= c; };

  vector<vector<int>> f(r + 10, vector<int>(c + 10, 1'000'000'000));

  auto getSquare = [&](int x, int y, int way, int type) { 
    vector<pair<int, int>> ret = {{x, y}};

    for (int t = 0; t < 4; ++t) { 
      for (int i = 1; i < n; ++i) { 
        x += dx[way]; y += dy[way];
        ret.push_back({x, y});
      }
      way = (way + type + 4) % 4;
    }

    return ret;
  };

  deque<pair<int, int>> q;
  q.push_back({Sr, Sc});
  f[Sr][Sc] = 0;
  while (q.size()) { 
    auto [x, y] = q.front(); q.pop_front();
    if (f[x][y] == 10) continue;
    if (abs(Gr - x) <= n && abs(Gc - y) <= n) { f[Gr][Gc] = min(f[Gr][Gc], f[x][y] + 1); }

    for (int t = 0; t < 4; ++t) { 
      int nX = x + dx[t], nY = y + dy[t];
      if (!in(nX, nY) || a[nX][nY] == '#') continue;
      if (f[nX][nY] > f[x][y]) {
        f[nX][nY] = f[x][y];
        q.push_front({nX, nY});
      }
    }

    for (int t = 0; t < 4; ++t) { 
      int stX = x + dx[t], stY = y + dy[t];

      for (int type = -1; type <= 1; type += 2) { 
        for (const auto& [nX, nY] : getSquare(stX, stY, t, type)) { 
          if (!in(nX, nY)) continue; 
          if (f[nX][nY] > f[x][y] + 1) { 
            f[nX][nY] = f[x][y] + 1;
            q.push_back({nX, nY});
          }
        }
      }
    }
  }

  cout << f[Gr][Gc] << "\n";
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 336 KB Output is correct
2 Correct 1 ms 336 KB Output is correct
3 Incorrect 1 ms 336 KB Output isn't correct
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 336 KB Output is correct
2 Correct 1 ms 336 KB Output is correct
3 Correct 1 ms 336 KB Output is correct
4 Correct 1 ms 336 KB Output is correct
5 Incorrect 1 ms 336 KB Output isn't correct
6 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 336 KB Output is correct
2 Correct 1 ms 336 KB Output is correct
3 Correct 1 ms 336 KB Output is correct
4 Correct 1 ms 336 KB Output is correct
5 Correct 1 ms 336 KB Output is correct
6 Correct 1 ms 336 KB Output is correct
7 Correct 1 ms 336 KB Output is correct
8 Correct 1 ms 464 KB Output is correct
9 Correct 16 ms 336 KB Output is correct
10 Correct 9 ms 336 KB Output is correct
11 Correct 8 ms 508 KB Output is correct
12 Correct 1 ms 336 KB Output is correct
13 Correct 1 ms 336 KB Output is correct
14 Correct 3 ms 336 KB Output is correct
15 Correct 1 ms 336 KB Output is correct
16 Correct 1 ms 336 KB Output is correct
17 Correct 1 ms 336 KB Output is correct
18 Correct 1 ms 336 KB Output is correct
19 Correct 1 ms 336 KB Output is correct
20 Correct 1 ms 336 KB Output is correct
21 Correct 1 ms 336 KB Output is correct
22 Correct 1 ms 336 KB Output is correct
23 Correct 1 ms 336 KB Output is correct
24 Correct 18 ms 336 KB Output is correct
25 Correct 7 ms 592 KB Output is correct
26 Correct 164 ms 1228 KB Output is correct
27 Correct 11 ms 848 KB Output is correct
28 Execution timed out 2070 ms 1492 KB Time limit exceeded
29 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 336 KB Output is correct
2 Correct 1 ms 336 KB Output is correct
3 Correct 1 ms 336 KB Output is correct
4 Correct 1 ms 336 KB Output is correct
5 Incorrect 1 ms 336 KB Output isn't correct
6 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 336 KB Output is correct
2 Correct 1 ms 336 KB Output is correct
3 Correct 1 ms 336 KB Output is correct
4 Correct 1 ms 336 KB Output is correct
5 Incorrect 1 ms 336 KB Output isn't correct
6 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 336 KB Output is correct
2 Correct 1 ms 336 KB Output is correct
3 Incorrect 1 ms 336 KB Output isn't correct
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 336 KB Output is correct
2 Correct 1 ms 336 KB Output is correct
3 Incorrect 1 ms 336 KB Output isn't correct
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 336 KB Output is correct
2 Correct 1 ms 336 KB Output is correct
3 Incorrect 1 ms 336 KB Output isn't correct
4 Halted 0 ms 0 KB -