結果
| 問題 | No.3723 Climb or Detour |
| コンテスト | |
| ユーザー |
秋ナス🍆
|
| 提出日時 | 2026-09-19 15:16:14 |
| 言語 | C++23(gcc16) (gcc 16.1.0 + boost 1.92.0 + ACL) |
| 結果 |
WA
不安定
|
| 実行時間 | - |
| コード長 | 17,605 bytes |
| 記録 | |
| コンパイル時間 | 5,349 ms |
| コンパイル使用メモリ | 390,624 KB |
| 実行使用メモリ | 6,912 KB |
| 最終ジャッジ日時 | 2026-09-19 15:16:27 |
| 合計ジャッジ時間 | 9,072 ms |
|
ジャッジサーバーID (参考情報) |
judge1_0 / judge5_0 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 2 |
| other | AC * 45 WA * 13 |
ソースコード
#include <bits/stdc++.h>
using namespace std;
#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <string>
#include <tuple>
#include <type_traits>
#include <utility>
#include <vector>
#if defined(__unix__) || defined(__APPLE__)
#include <unistd.h>
#endif
template <typename T>
std::istream& operator>>(std::istream& is, std::vector<T>& v);
template <typename T1, typename T2>
std::istream& operator>>(std::istream& is, std::pair<T1, T2>& p);
template <typename... Args>
std::istream& operator>>(std::istream& is, std::tuple<Args...>& t);
namespace input_detail {
#ifdef LOCAL
inline std::size_t& read_count() {
static std::size_t count = 0;
return count;
}
inline bool& failed_read() {
static bool failed = false;
return failed;
}
inline bool stdin_is_terminal() {
#if defined(__unix__) || defined(__APPLE__)
return isatty(fileno(stdin));
#else
return false;
#endif
}
struct EndOfInputChecker {
~EndOfInputChecker() {
if (stdin_is_terminal() || failed_read() || std::cin.bad()) return;
std::cin >> std::ws;
std::string token;
if (std::cin >> token) {
std::cerr << "[input error] 入力が余っています。\n"
<< " 最初に余った値: " << token << '\n'
<< " N と M、H と W、辺数 m、配列長 n などを間違えていないか確認してください。\n";
std::abort();
}
}
};
inline void ensure_end_checker() {
static EndOfInputChecker checker;
(void)checker;
}
inline void begin_input() {
ensure_end_checker();
}
template <typename T>
void read_one(std::istream& is, T& value) {
if (&is != &std::cin) {
is >> value;
return;
}
ensure_end_checker();
++read_count();
if (!(is >> value)) {
failed_read() = true;
std::cerr << "[input error] 入力が足りないか、型が合いません。\n"
<< " " << read_count() << " 個目の値を読み込めませんでした。\n"
<< " N と M、H と W、辺数 m、配列長 n などを間違えていないか確認してください。\n";
std::abort();
}
}
#else
inline void begin_input() {
}
template <typename T>
void read_one(std::istream& is, T& value) {
is >> value;
}
#endif
template <typename... Args>
void read_values(Args&... args) {
(read_one(std::cin, args), ...);
}
}
struct FastIO {
FastIO() {
std::ios_base::sync_with_stdio(false);
std::cin.tie(nullptr);
}
};
inline FastIO fast_io_init;
template <typename T1, typename T2>
std::istream& operator>>(std::istream& is, std::pair<T1, T2>& p) {
input_detail::read_one(is, p.first);
input_detail::read_one(is, p.second);
return is;
}
template <typename Tuple, std::size_t... I>
void read_tuple_impl(std::istream& is, Tuple& t, std::index_sequence<I...>) {
(..., input_detail::read_one(is, std::get<I>(t)));
}
template <typename... Args>
std::istream& operator>>(std::istream& is, std::tuple<Args...>& t) {
read_tuple_impl(is, t, std::index_sequence_for<Args...>{});
return is;
}
template <typename T>
std::istream& operator>>(std::istream& is, std::vector<T>& v) {
for (auto& elem : v) {
input_detail::read_one(is, elem);
}
return is;
}
template <typename T>
struct is_pair : std::false_type {};
template <typename T1, typename T2>
struct is_pair<std::pair<T1, T2>> : std::true_type {};
template <typename T>
struct is_tuple : std::false_type {};
template <typename... Args>
struct is_tuple<std::tuple<Args...>> : std::true_type {};
template <typename T>
struct is_vector : std::false_type {};
template <typename T>
struct is_vector<std::vector<T>> : std::true_type {};
template <typename T>
void adjust_zero_indexed(T& val) {
using DecayedT = std::decay_t<T>;
if constexpr (is_pair<DecayedT>::value) {
adjust_zero_indexed(val.first);
adjust_zero_indexed(val.second);
} else if constexpr (is_tuple<DecayedT>::value) {
std::apply([](auto&... args) { (adjust_zero_indexed(args), ...); }, val);
} else if constexpr (is_vector<DecayedT>::value) {
for (auto& elem : val) {
adjust_zero_indexed(elem);
}
} else if constexpr (std::is_arithmetic_v<DecayedT> && !std::is_same_v<DecayedT, char> && !std::is_same_v<DecayedT, signed char> &&
!std::is_same_v<DecayedT, unsigned char> && !std::is_same_v<DecayedT, wchar_t> &&
#if defined(__cpp_char8_t)
!std::is_same_v<DecayedT, char8_t> &&
#endif
!std::is_same_v<DecayedT, char16_t> && !std::is_same_v<DecayedT, char32_t> && !std::is_same_v<DecayedT, bool>) {
--val;
} else {
}
}
using default_type = long;
template <typename... Args>
void read(Args&... args) {
input_detail::read_values(args...);
}
template <typename T = default_type>
T read_val() {
T val;
input_detail::read_one(std::cin, val);
return val;
}
template <typename T1 = default_type, typename T2 = default_type>
std::pair<T1, T2> read_pair() {
std::pair<T1, T2> p;
input_detail::begin_input();
std::cin >> p;
return p;
}
template <typename... Args>
std::tuple<Args...> read_tuple() {
std::tuple<Args...> t;
input_detail::begin_input();
std::cin >> t;
return t;
}
template <typename T = default_type, typename Size, std::enable_if_t<std::is_integral_v<Size> && !std::is_same_v<Size, bool>, int> = 0>
std::vector<T> read_vec(Size n, bool zero_indexed = false) {
std::vector<T> v(n);
input_detail::begin_input();
std::cin >> v;
if (zero_indexed) {
adjust_zero_indexed(v);
}
return v;
}
template <typename T = default_type>
std::vector<T> read_vec(bool zero_indexed = false) {
int n;
input_detail::read_one(std::cin, n);
return read_vec<T>(n, zero_indexed);
}
template <typename T1 = default_type, typename T2 = default_type, typename Size,
std::enable_if_t<std::is_integral_v<Size> && !std::is_same_v<Size, bool>, int> = 0>
std::vector<std::pair<T1, T2>> read_vec_pair(Size n, bool zero_indexed = false) {
return read_vec<std::pair<T1, T2>>(n, zero_indexed);
}
template <typename T1 = default_type, typename T2 = default_type>
std::vector<std::pair<T1, T2>> read_vec_pair(bool zero_indexed = false) {
int n;
input_detail::read_one(std::cin, n);
return read_vec_pair<T1, T2>(n, zero_indexed);
}
template <typename... Args, typename Size, std::enable_if_t<std::is_integral_v<Size> && !std::is_same_v<Size, bool>, int> = 0>
std::vector<std::tuple<Args...>> read_vec_tuple(Size n, bool zero_indexed = false) {
return read_vec<std::tuple<Args...>>(n, zero_indexed);
}
template <typename... Args>
std::vector<std::tuple<Args...>> read_vec_tuple(bool zero_indexed = false) {
int n;
input_detail::read_one(std::cin, n);
return read_vec_tuple<Args...>(n, zero_indexed);
}
template <typename T = default_type>
std::vector<std::vector<T>> read_vec_grid(int h, int w, bool zero_indexed = false) {
std::vector<std::vector<T>> grid(h, std::vector<T>(w));
input_detail::begin_input();
std::cin >> grid;
if (zero_indexed) {
adjust_zero_indexed(grid);
}
return grid;
}
template <typename T = default_type>
std::vector<std::vector<T>> read_vec_grid(bool zero_indexed = false) {
int h, w;
input_detail::read_values(h, w);
return read_vec_grid<T>(h, w, zero_indexed);
}
template <typename T = default_type, typename Size, std::enable_if_t<std::is_integral_v<Size> && !std::is_same_v<Size, bool>, int> = 0>
std::vector<std::vector<T>> read_vec_var(Size n, bool zero_indexed = false) {
std::vector<std::vector<T>> res(n);
input_detail::begin_input();
for (int i = 0; i < static_cast<int>(n); ++i) {
int m;
input_detail::read_one(std::cin, m);
res[i] = read_vec<T>(m, zero_indexed);
}
return res;
}
template <typename T = default_type>
std::vector<std::vector<T>> read_vec_var(bool zero_indexed = false) {
int n;
input_detail::read_one(std::cin, n);
return read_vec_var<T>(n, zero_indexed);
}
template <typename T = default_type>
T read_zero_idx() {
T val;
input_detail::read_one(std::cin, val);
adjust_zero_indexed(val);
return val;
}
inline std::vector<std::vector<int>> read_graph(int n, int m, bool directed = false) {
std::vector<std::vector<int>> g(n);
input_detail::begin_input();
for (int i = 0; i < m; ++i) {
int u = read_zero_idx<int>();
int v = read_zero_idx<int>();
g[u].push_back(v);
if (!directed) {
g[v].push_back(u);
}
}
return g;
}
inline std::vector<std::vector<int>> read_graph(bool directed = false) {
int n, m;
input_detail::read_values(n, m);
return read_graph(n, m, directed);
}
template <typename Cost = default_type>
struct Edge {
int to;
Cost cost;
Edge() = default;
Edge(int to, Cost cost) : to(to), cost(cost) {}
};
template <typename Cost = default_type>
inline std::vector<std::vector<Edge<Cost>>> read_weighted_graph(int n, int m, bool directed = false) {
std::vector<std::vector<Edge<Cost>>> g(n);
input_detail::begin_input();
for (int i = 0; i < m; ++i) {
int u = read_zero_idx<int>();
int v = read_zero_idx<int>();
Cost w;
input_detail::read_one(std::cin, w);
g[u].push_back(Edge<Cost>{v, w});
if (!directed) {
g[v].push_back(Edge<Cost>{u, w});
}
}
return g;
}
template <typename Cost = default_type>
inline std::vector<std::vector<Edge<Cost>>> read_weighted_graph(bool directed = false) {
int n, m;
input_detail::read_values(n, m);
return read_weighted_graph<Cost>(n, m, directed);
}
#include <deque>
#include <iostream>
#include <list>
#include <map>
#include <optional>
#include <set>
#include <string>
#include <string_view>
#include <tuple>
#include <type_traits>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>
template <typename T, typename U>
std::ostream& operator<<(std::ostream& os, const std::pair<T, U>& p);
template <typename... Args>
std::ostream& operator<<(std::ostream& os, const std::tuple<Args...>& t);
template <typename T>
std::ostream& operator<<(std::ostream& os, const std::optional<T>& opt);
template <typename T, typename = void>
struct is_iterable : std::false_type {};
template <typename T>
struct is_iterable<T, std::void_t<decltype(std::begin(std::declval<T>())), decltype(std::end(std::declval<T>()))>>
: std::bool_constant<!std::is_convertible_v<T, std::string_view>> {};
template <typename T>
inline constexpr bool is_iterable_v = is_iterable<T>::value;
template <typename T, std::enable_if_t<is_iterable_v<T>, int> = 0>
std::ostream& operator<<(std::ostream& os, const T& container);
template <typename T, typename U>
std::ostream& operator<<(std::ostream& os, const std::pair<T, U>& p) {
return os << p.first << " " << p.second;
}
template <typename Tuple, std::size_t... I>
void print_tuple_impl(std::ostream& os, const Tuple& t, std::index_sequence<I...>) {
((os << (I == 0 ? "" : " ") << std::get<I>(t)), ...);
}
template <typename... Args>
std::ostream& operator<<(std::ostream& os, const std::tuple<Args...>& t) {
print_tuple_impl(os, t, std::index_sequence_for<Args...>{});
return os;
}
template <typename T>
std::ostream& operator<<(std::ostream& os, const std::optional<T>& opt) {
if (opt.has_value()) return os << *opt;
return os << "-1";
}
template <typename T, std::enable_if_t<is_iterable_v<T>, int>>
std::ostream& operator<<(std::ostream& os, const T& container) {
bool first = true;
for (const auto& item : container) {
if (!first) os << " ";
first = false;
os << item;
}
return os;
}
template <typename T>
struct Plus1Wrapper {
const T& val;
};
template <typename T>
constexpr Plus1Wrapper<T> plus1(const T& x) {
return Plus1Wrapper<T>{x};
}
template <typename T, typename U>
std::ostream& operator<<(std::ostream& os, const Plus1Wrapper<std::pair<T, U>>& w) {
return os << (w.val.first + 1) << " " << (w.val.second + 1);
}
template <typename T>
std::ostream& operator<<(std::ostream& os, const Plus1Wrapper<T>& w) {
if constexpr (is_iterable_v<T>) {
bool first = true;
for (const auto& item : w.val) {
if (!first) os << " ";
first = false;
os << plus1(item);
}
return os;
} else {
return os << (w.val + 1);
}
}
template <typename Container>
void out_from1(const Container& c) {
auto it = std::begin(c);
if (it != std::end(c)) ++it;
bool first = true;
for (; it != std::end(c); ++it) {
if (!first) std::cout << " ";
first = false;
std::cout << *it;
}
std::cout << "\n";
}
inline void out() {
std::cout << "\n";
}
template <typename T, typename... Args>
void out(const T& head, const Args&... tail) {
std::cout << head;
if constexpr (sizeof...(tail) > 0) {
std::cout << " ";
out(tail...);
} else {
std::cout << "\n";
}
}
template <typename... Args>
void pr(const Args&... args) {
out(args...);
}
template <typename Container>
void out_lines(const Container& c) {
for (const auto& x : c) {
std::cout << x << "\n";
}
}
template <typename Grid>
void out_grid(const Grid& grid) {
for (const auto& row : grid) {
out(row);
}
}
inline void Yes(bool condition = true, std::string_view true_str = "Yes", std::string_view false_str = "No") {
std::cout << (condition ? true_str : false_str) << "\n";
}
inline void No(bool condition = true) {
Yes(!condition);
}
#include <istream>
#include <numeric>
#include <print>
#include <ranges>
#include <vector>
#define ALL(a) (a).begin(), (a).end()
using i128 = __int128;
template <typename T, typename U>
inline bool chmin(T& a, const U& b) {
if (a > b) {
a = b;
return true;
}
return false;
}
template <typename T, typename U>
inline bool chmax(T& a, const U& b) {
if (a < b) {
a = b;
return true;
}
return false;
}
template <std::integral T>
inline T div_ceil(T a, T b) {
if (a > 0) return a / b + (a % b != 0);
return a / b;
}
template <std::integral T>
inline T div_floor(T a, T b) {
if (a < 0) return a / b - (a % b != 0);
return a / b;
}
template <std::integral T>
inline T mod(T a, T m) {
a %= m;
if (a < 0) a += m;
return a;
}
template <typename T>
inline constexpr T INF = std::numeric_limits<T>::max() / 2;
template <>
inline constexpr float INF<float> = std::numeric_limits<float>::infinity();
template <>
inline constexpr double INF<double> = std::numeric_limits<double>::infinity();
template <>
inline constexpr long double INF<long double> = std::numeric_limits<long double>::infinity();
template <typename T>
auto make_vector(size_t size, T&& initial_value) {
return std::vector<std::decay_t<T>>(size, std::forward<T>(initial_value));
}
template <typename... Args>
auto make_vector(size_t size, Args&&... args) {
auto inner = make_vector(std::forward<Args>(args)...);
return std::vector<decltype(inner)>(size, inner);
}
template <typename T = int>
inline std::vector<T> iota_vec(int n, T start = 0) {
std::vector<T> v(n);
std::iota(v.begin(), v.end(), start);
return v;
}
template <typename T>
inline std::vector<T> doubled_vec(const std::vector<T>& v) {
std::vector<T> res;
res.reserve(v.size() * 2);
res.insert(res.end(), v.begin(), v.end());
res.insert(res.end(), v.begin(), v.end());
return res;
}
inline bool is_palindrome(std::string_view s) {
return std::ranges::equal(s, s | std::views::reverse);
}
#ifdef LOCAL
#include <utility/debug.hpp>
#else
#define debug(...)
#endif
void solve() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
int N, K, sr, sc, tr, tc;
read(N, K, sr, sc, tr, tc);
sr--, sc--, tr--, tc--;
int min_need = abs(sr - tr) + abs(sc - tc);
debug(min_need);
bool sign = ((sr + sc) % 2) == ((tr + tc) % 2);
if (sr > tr) swap(sr, tr);
if (sc > tc) swap(sc, tc);
debug(sr, tr, sc, tc);
debug(sign);
int max_need = 0;
if (sign) {
debug("偶奇一致");
max_need = min_need * 2;
} else {
debug("偶奇不一致");
max_need = min_need * 2 - 1;
}
if (K < min_need || max_need < K) {
println("{}", -1);
debug("pattern A");
return;
}
if (sign != !(K & 1)) {
println("{}", -1);
debug("pattern B");
return;
}
vector<string> G_even(N, string(N, '.'));
vector<string> G_odd(N, string(N, '.'));
for (int i = 0; i < N; i++) {
for (int j = 0; j < N; j++) {
if ((i + j) % 2 == 0)
G_even[i][j] = '#';
else
G_odd[i][j] = '#';
}
}
auto ans = ((sr + sc) % 2 == 0) ? G_odd : G_even;
if (!sign) {
ans[sr][sc] = '.';
ans[tr][tc] = '.';
}
debug(ans);
int need_erase = (max_need - K) / 2;
int cnt = 0;
for (int i = sr; i < tr; i++) {
if (cnt < need_erase && ans[i][tc] == '#') {
cnt++;
ans[i][tc] = '.';
}
}
for (int j = sc; j < tc; j++) {
if (cnt < need_erase && ans[sr][j] == '#') {
cnt++;
ans[sr][j] = '.';
}
}
out_lines(ans);
}
int main() {
solve();
}
秋ナス🍆