답안 #1105272

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1105272 2024-10-26T02:00:29 Z duckindog Maze (JOI23_ho_t3) C++17
0 / 100
1 ms 508 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, vector<char>(c));
  for (int i = 0; i < r; ++i) { 
    for (int j = 0; j < c; ++j) cin >> a[i][j];
  }

  vector<vector<pair<int, int>>> ad(2 * r * c);

  auto in = [&](int x, int y) { return 0 <= x && x < r && 0 <= y && y < r; };
  auto idx = [&](int i, int j) { return i * c + j; };

  for (int i = 0; i < r; ++i) { 
    for (int j = 0; j < c; ++j) { 
      int u = idx(i, j);
      for (int t = 0; t < 4; ++t) { 
        if (!in(i + dx[t], j + dy[t])) continue;
        int v = idx(i + dx[t], j + dy[t]);
        ad[u].push_back({v, 0});
      }
    }
  }

  int it = idx(r - 1, c - 1);
  for (int i = 0; i < r; ++i) { 
    for (int j = 0; j < c; ++j) { 
      
      for (int t = j; t < min(c, j + n); ++t) { 
        for (int type = 0; type <= 1; ++type) { 
          if (!in(!type ? i - 1 : i + n, t)) continue;
          int v = idx(!type ? i - 1 : i + n, t);
          ad[it].push_back({v, 1});
          ad[v].push_back({it, 1});
        }
      }

      for (int t = i; t < min(r, i + n); ++t) { 
        for (int type = 0; type <= 1; ++type) { 
          if (!in(t, !type ? j - 1 : j + n)) continue;
          int v = idx(t, !type ? j - 1 : j + n);
          ad[it].push_back({v, 1});
          ad[v].push_back({it, 1});
        }
      }

      if (i <= r - 1 && j <= c - 1 && r - 1 < i + n && c - 1 < j + n) {
        ad[it].push_back({idx(r - 1, c - 1), 1});
        ad[idx(r - 1, c - 1)].push_back({it, 1});
      }
    }
  }

  using pii = pair<int, int>;
  priority_queue<pii, vector<pii>, greater<>> q;
  vector<int> f(2 * r * c, 1'000'000'000);
  q.push({f[0] = 0, 0});
  while (q.size()) { 
    auto [d, u] = q.top(); q.pop();
    if (d != f[u]) continue;
    for (const auto& [v, w] : ad[u])
      if (f[v] > d + w) q.push({f[v] = d + w, v});
  }

  cout << f[idx(r - 1, c - 1)] << "\n";
}
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 336 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 336 KB Output is correct
2 Incorrect 1 ms 336 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 508 KB Output is correct
2 Incorrect 1 ms 336 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 336 KB Output is correct
2 Incorrect 1 ms 336 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 336 KB Output is correct
2 Incorrect 1 ms 336 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 336 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 336 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 336 KB Output isn't correct
2 Halted 0 ms 0 KB -