#if __INCLUDE_LEVEL__ == 0 #include __BASE_FILE__ void Solve() { int n; IN(n); vector s(n); IN(s); vector ans(n, string(n, '?')); auto go = [&](int i, int j) -> pair { int lo = 0; int hi = 0; for (int ni : Rep1(max(i - 1, 0), min(i + 1, n - 1))) for (int nj : Rep1(max(j - 1, 0), min(j + 1, n - 1))) { if (ni == i && nj == j) continue; lo += ans[ni][nj] == 'o'; hi += ans[ni][nj] != '.'; } return {lo, hi}; }; auto get_val = [&](int i, int j) -> int { int a = s[i][j] - '0'; auto [lo, hi] = go(i, j); return -min(a - lo - 1, hi - a); }; priority_queue> q; for (int i : Rep(0, n)) for (int j : Rep(0, n)) q.emplace(get_val(i, j), i, j); while (Len(q)) { auto [val, i, j] = q.top(); q.pop(); if (val != get_val(i, j)) continue; if (ans[i][j] != '?') continue; int a = s[i][j] - '0'; auto [lo, hi] = go(i, j); ans[i][j] = "o."[a - lo - 1 < hi - a]; for (int ni : Rep1(max(i - 1, 0), min(i + 1, n - 1))) for (int nj : Rep1(max(j - 1, 0), min(j + 1, n - 1))) { if (ni == i && nj == j) continue; if (ans[ni][nj] == '?') q.emplace(get_val(ni, nj), ni, nj); } } ranges::for_each(ans, LIFT(OUT)); } int main() { ios::sync_with_stdio(false); cin.tie(nullptr); Solve(); } #elif __INCLUDE_LEVEL__ == 1 #include template concept MyRange = std::ranges::range && !std::convertible_to && !std::convertible_to; template concept MyTuple = std::__is_tuple_like::value && !MyRange; namespace std { istream& operator>>(istream& is, MyRange auto&& r) { for (auto&& e : r) { is >> e; } return is; } istream& operator>>(istream& is, MyTuple auto&& t) { apply([&](auto&... xs) { (is >> ... >> xs); }, t); return is; } ostream& operator<<(ostream& os, MyRange auto&& r) { auto sep = ""; for (auto&& e : r) { os << exchange(sep, " ") << forward(e); } return os; } ostream& operator<<(ostream& os, MyTuple auto&& t) { auto sep = ""; apply([&](auto&... xs) { ((os << exchange(sep, " ") << xs), ...); }, t); return os; } } // namespace std template class OneBased { public: explicit OneBased(T&& x) : ref_(std::forward(x)) {} template requires(sizeof...(Ts) > 1) OneBased(Ts&&... xs) : ref_(std::forward_as_tuple(std::forward(xs)...)) {} friend std::istream& operator>>(std::istream& is, OneBased x) { if constexpr (MyRange) { for (auto&& e : x.ref_) { is >> ::OneBased(e); } } else if constexpr (MyTuple) { std::apply([&](auto&... xs) { (is >> ... >> ::OneBased(xs)); }, x.ref_); } else { is >> x.ref_; --x.ref_; } return is; } friend std::ostream& operator<<(std::ostream& os, OneBased x) { if constexpr (MyRange) { auto f = [](auto&& e) { return ::OneBased(std::forward(e)); }; os << (x.ref_ | std::views::transform(f)); } else if constexpr (MyTuple) { std::apply([&](auto&... xs) { os << std::tuple(::OneBased(xs)...); }, x.ref_); } else { os << ++x.ref_; --x.ref_; } return os; } private: T ref_; }; template OneBased(T&&) -> OneBased; template OneBased(Ts&&...) -> OneBased>; using namespace std; #define LIFT(f) ([&](auto&&... xs) -> decltype(auto) { return f(forward(xs)...); }) #define Rep(...) [](int l, int r) { return views::iota(min(l, r), r); }(__VA_ARGS__) #define Rep1(...) [](int l, int r) { return Rep(l, r + 1); }(__VA_ARGS__) #define Len(r) int(size(r)) #define IN(...) (cin >> forward_as_tuple(__VA_ARGS__)) #define OUT(...) (cout << forward_as_tuple(__VA_ARGS__) << '\n') #endif // __INCLUDE_LEVEL__ == 1