提出 #64542459


ソースコード 拡げる

#pragma region header
// C
#include <cassert>
#include <cctype>
#include <cfloat>
#include <climits>
#include <cmath>
#include <cstddef>
#include <cstdint>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
// C++
#include <algorithm>
#include <array>
#include <bit>
#include <bitset>
#include <chrono>
#include <compare>
#include <complex>
#include <concepts>
#include <deque>
#include <functional>
#include <initializer_list>
#include <iomanip>
#include <ios>
#include <iostream>
#include <iterator>
#include <limits>
#include <list>
#include <map>
#include <numbers>
#include <numeric>
#include <queue>
#include <random>
#include <ranges>
#include <regex>
#include <set>
#include <span>
#include <sstream>
#include <stack>
#include <string>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <valarray>
#include <vector>
// atcoder
#include <atcoder/all>

#define int ll
#define all(a) begin(a), end(a)
#define rall(a) rbegin(a), rend(a)
#define rep1(i, n) for (decltype(+n) i = 0; i < (n); i++)
#define rrep1(i, n) for (auto i = (n) - 1; i >= 0; i--)
#define rep2(i, a, b) for (auto i = (a); i < (b); i++)
#define rrep2(i, a, b) for (auto i = (b) - 1; i >= a; i--)
#define GET_NAME(_1, _2, _3, NAME, ...) NAME
#define rep(...) GET_NAME(__VA_ARGS__, rep2, rep1)(__VA_ARGS__)
#define rrep(...) \
  GET_NAME(__VA_ARGS__, rrep2, rrep1)(__VA_ARGS__)
using namespace std;
using namespace literals;

using ll = long long;
using ld = long double;
using vi = vector<int>;
using vvi = vector<vi>;
using vs = vector<string>;
using vvs = vector<vs>;
using vd = vector<ld>;
using vvd = vector<vd>;
using vb = vector<bool>;
using vvb = vector<vb>;
using pii = pair<int, int>;
using vp = vector<pii>;
using vvp = vector<vp>;
using i3 = tuple<int, int, int>;
using vi3 = vector<i3>;
using vvi3 = vector<vi3>;
using i4 = tuple<int, int, int, int>;
using vi4 = vector<i4>;
using vvi4 = vector<vi4>;
using mii = map<int, int>;
template <class T, class U>
using umap = unordered_map<T, U>;
using umii = umap<int, int>;
using seti = set<int>;
template <class T>
using uset = unordered_set<T>;
using useti = uset<int>;
template <class T>
using less_queue = priority_queue<T>;
template <class T>
using greater_queue = priority_queue<T, vector<T>, greater<T>>;
using int128 = __int128_t;

template <class T, class U>
istream &operator>>(istream &is, pair<T, U> &x) {
  T a;
  U b;
  is >> a >> b;
  x = {a, b};
  return is;
}
template <class T, class U>
ostream &operator<<(ostream &os, const pair<T, U> &x) {
  return os << x.first << ' ' << x.second;
}
template <class T, class... U>
tuple<T, U...> read_tuple(istream &is) {
  T a;
  is >> a;
  if constexpr (sizeof...(U) == 0)
    return {a};
  else
    return tuple_cat(tuple{a}, read_tuple<U...>(is));
}
template <class... T>
istream &operator>>(istream &is, tuple<T...> &x) {
  x = read_tuple<T...>(is);
  return is;
}
template <size_t I = 0, class... T>
constexpr void write_tuple(ostream &os, const tuple<T...> &x) {
  if constexpr (I < sizeof...(T)) {
    if constexpr (I == 0)
      os << get<0>(x);
    else
      os << ' ' << get<I>(x);
    write_tuple<I + 1>(os, x);
  }
}
template <class... T>
ostream &operator<<(ostream &os, const tuple<T...> &x) {
  write_tuple(os, x);
  return os;
}
template <class T>
istream &operator>>(istream &is, vector<T> &v) {
  for (T &x : v) is >> x;
  return is;
}
template <class T>
ostream &operator<<(ostream &os, const vector<T> &v) {
  const int n = v.size();
  if (n) os << v[0];
  for (int i = 1; i < n; i++) os << ' ' << v[i];
  return os;
}
ostream &operator<<(ostream &os, int128 x) {
  if (!x) return os << '0';
  if (x < 0) {
    os << '-';
    x = -x;
  }
  string s;
  for (; x; x /= 10) s += x % 10 + '0';
  reverse(all(s));
  return os << s;
}

constexpr long long INF = 1e18;
constexpr ld EPS = 1e-10;
const ld PI = acosl(-1);
bool eq(ld a, ld b) {
  return abs(a - b) < EPS;
}

template <typename T>
void SORT(T &a) {
  stable_sort(all(a));
}
template <typename T>
T sorted(T a) {
  SORT(a);
  return a;
}
template <typename T>
void RSORT(T &a) {
  stable_sort(rall(a));
}
template <typename T>
T rsorted(T a) {
  RSORT(a);
  return a;
}
template <typename T, typename U>
void ERASE(T &a, U i) {
  a.erase(remove(all(a), i), end(a));
}
template <typename T>
void rev(T &a) {
  reverse(all(a));
}
template <typename T>
T reversed(T a) {
  rev(a);
  return a;
}
template <typename T>
void uniq(T &a) {
  a.erase(unique(all(a)), end(a));
}
template <typename T>
auto min_of(const vector<T> &a) {
  return *min_element(all(a));
}
template <typename T>
auto max_of(const vector<T> &a) {
  return *max_element(all(a));
}
template <typename T>
T sum_of(const vector<T> &a) {
  return accumulate(all(a), T{});
}
template <typename T>
int count_of(const T &a, T i) {
  return count(all(a), i);
}
template <typename T>
bool has(const vector<T> &a, T i) {
  return find(all(a), i) != end(a);
}
bool has(const string &a, char i) {
  return find(all(a), i) != end(a);
}
template <typename T>
bool has(const set<T> &a, T i) {
  return a.find(i) != a.end();
}
template <typename T, typename U>
bool has(const map<T, U> &a, T i) {
  return a.find(i) != a.end();
}
template <typename T, typename U>
bool has(const umap<T, U> &a, T i) {
  return a.find(i) != a.end();
}

void CIN() {};
template <class T, class... U>
void CIN(T &&x, U &&...y) {
  cin >> x;
  CIN(forward<U>(y)...);
}
void _COUT() {
  cout << endl;
}
template <class T, class... U>
void _COUT(T &&x, U &&...y) {
  cout << ' ' << x;
  _COUT(forward<U>(y)...);
}
void COUT() {
  _COUT();
};
template <class T, class... U>
void COUT(T &&x, U &&...y) {
  cout << x;
  _COUT(forward<U>(y)...);
}
void CSP() {};
template <class T, class... U>
void CSP(T &&x, U &&...y) {
  cout << x << ' ';
  CSP(forward<U>(y)...);
}

template <typename T>
bool amin(T &a, const T &b) {
  return a > b ? a = b, true : false;
}
template <typename T>
bool amax(T &a, const T &b) {
  return a < b ? a = b, true : false;
}

template <typename T>
vector<T> powers(T base, int N) {
  vector<T> ret(N + 1);
  ret[0] = 1;
  rep(i, N) ret[i + 1] = ret[i] * base;
  return ret;
}
template <typename T>
vector<T> factorials(int N) {
  vector<T> ret(N + 1);
  ret[0] = 1;
  rep(i, N) ret[i + 1] = ret[i] * T{i + 1};
  return ret;
}

int ceil_div(int x, int y) {
  int d = x / y;
  return d * y == x ? d : d + ((x > 0) ^ (y < 0));
}
int floor_div(int x, int y) {
  int d = x / y;
  return d * y == x ? d : d - ((x < 0) ^ (y < 0));
}
int out_div(int x, int y) {
  int d = x / y;
  return d * y == x ? d : ((x > 0) == (y > 0)) ? d + 1 : d - 1;
}

#pragma endregion header

vvi grid_bfs(vs &s, int sx, int sy, const string &wall = "#") {
  const int vx[] = {0, 1, 0, -1}, vy[] = {1, 0, -1, 0};
  int H = s.size(), W = s[0].size();
  vvi min_cost(H, vi(W, INF));
  deque<pii> que;
  // rep(i, H) rep(j, W) if (s[i][j] == 'S') {
  //   que.emplace(i, j);
  //   min_cost[i][j] = 0;
  // }
  que.push_front({sx, sy});
  min_cost[sx][sy] = 0;
  while (!que.empty()) {
    auto [x, y] = que.front();
    que.pop_front();
    int ncost = min_cost[x][y];
    for (int i = 0; i < 4; i++) {
      int nx = x + vx[i], ny = y + vy[i];
      if (nx < 0 || ny < 0 || nx >= H || ny >= W) continue;
      if (wall.find(s[nx][ny]) != string::npos) {
        if (amin(min_cost[nx][ny], ncost + 1)) {
          que.push_back({nx, ny});
        }
        nx += vx[i], ny += vy[i];
        if (nx < 0 || ny < 0 || nx >= H || ny >= W) continue;
        if (amin(min_cost[nx][ny], ncost + 1)) {
          que.push_back({nx, ny});
        }
      } else {
        if (amin(min_cost[nx][ny], ncost)) {
          que.push_front({nx, ny});
        }
      }
    }
  }
  return min_cost;
}

void solve() {
  int H, W;
  CIN(H, W);
  vs S(H);
  CIN(S);
  int A, B, C, D;
  CIN(A, B, C, D);
  A--, B--, C--, D--;

  auto gb = grid_bfs(S, A, B);
  COUT(gb[C][D]);
}

#pragma region main
signed main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  cout << fixed << setprecision(15);

  solve();
}
#pragma endregion main

提出情報

提出日時
問題 D - Takahashi the Wall Breaker
ユーザ dnek
言語 C++ 23 (gcc 12.2)
得点 400
コード長 8078 Byte
結果 AC
実行時間 93 ms
メモリ 28484 KiB

コンパイルエラー

Main.cpp:1: warning: ignoring ‘#pragma region header’ [-Wunknown-pragmas]
    1 | #pragma region header
      | 
Main.cpp:309: warning: ignoring ‘#pragma endregion header’ [-Wunknown-pragmas]
  309 | #pragma endregion header
      | 
Main.cpp:361: warning: ignoring ‘#pragma region main’ [-Wunknown-pragmas]
  361 | #pragma region main
      | 
Main.cpp:370: warning: ignoring ‘#pragma endregion main’ [-Wunknown-pragmas]
  370 | #pragma endregion main
      | 

ジャッジ結果

セット名 Sample All
得点 / 配点 0 / 0 400 / 400
結果
AC × 4
AC × 34
セット名 テストケース
Sample example_00.txt, example_01.txt, example_02.txt, example_03.txt
All example_00.txt, example_01.txt, example_02.txt, example_03.txt, hand_00.txt, hand_01.txt, hand_02.txt, hand_03.txt, hand_04.txt, hand_05.txt, hand_06.txt, hand_07.txt, hand_08.txt, hand_09.txt, random_00.txt, random_01.txt, random_02.txt, random_03.txt, random_04.txt, random_05.txt, random_06.txt, random_07.txt, random_08.txt, random_09.txt, random_10.txt, random_11.txt, random_12.txt, random_13.txt, random_14.txt, random_15.txt, random_16.txt, random_17.txt, random_18.txt, random_19.txt
ケース名 結果 実行時間 メモリ
example_00.txt AC 1 ms 3492 KiB
example_01.txt AC 1 ms 3464 KiB
example_02.txt AC 1 ms 3500 KiB
example_03.txt AC 1 ms 3452 KiB
hand_00.txt AC 56 ms 12500 KiB
hand_01.txt AC 51 ms 12456 KiB
hand_02.txt AC 51 ms 12452 KiB
hand_03.txt AC 52 ms 12476 KiB
hand_04.txt AC 52 ms 12488 KiB
hand_05.txt AC 51 ms 16484 KiB
hand_06.txt AC 50 ms 16508 KiB
hand_07.txt AC 59 ms 28484 KiB
hand_08.txt AC 57 ms 20432 KiB
hand_09.txt AC 1 ms 3632 KiB
random_00.txt AC 42 ms 11940 KiB
random_01.txt AC 43 ms 11952 KiB
random_02.txt AC 54 ms 12200 KiB
random_03.txt AC 54 ms 12040 KiB
random_04.txt AC 48 ms 11644 KiB
random_05.txt AC 46 ms 11700 KiB
random_06.txt AC 92 ms 19984 KiB
random_07.txt AC 93 ms 20120 KiB
random_08.txt AC 81 ms 20964 KiB
random_09.txt AC 89 ms 19160 KiB
random_10.txt AC 86 ms 19204 KiB
random_11.txt AC 89 ms 19880 KiB
random_12.txt AC 69 ms 12184 KiB
random_13.txt AC 73 ms 12180 KiB
random_14.txt AC 63 ms 11856 KiB
random_15.txt AC 69 ms 12276 KiB
random_16.txt AC 73 ms 12120 KiB
random_17.txt AC 48 ms 11884 KiB
random_18.txt AC 54 ms 11972 KiB
random_19.txt AC 49 ms 12156 KiB