#include using namespace std; #include #include #include #include #include #include #include #include #if defined(__unix__) || defined(__APPLE__) #include #endif template std::istream& operator>>(std::istream& is, std::vector& v); template std::istream& operator>>(std::istream& is, std::pair& p); template std::istream& operator>>(std::istream& is, std::tuple& 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 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 void read_one(std::istream& is, T& value) { is >> value; } #endif template 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 std::istream& operator>>(std::istream& is, std::pair& p) { input_detail::read_one(is, p.first); input_detail::read_one(is, p.second); return is; } template void read_tuple_impl(std::istream& is, Tuple& t, std::index_sequence) { (..., input_detail::read_one(is, std::get(t))); } template std::istream& operator>>(std::istream& is, std::tuple& t) { read_tuple_impl(is, t, std::index_sequence_for{}); return is; } template std::istream& operator>>(std::istream& is, std::vector& v) { for (auto& elem : v) { input_detail::read_one(is, elem); } return is; } template struct is_pair : std::false_type {}; template struct is_pair> : std::true_type {}; template struct is_tuple : std::false_type {}; template struct is_tuple> : std::true_type {}; template struct is_vector : std::false_type {}; template struct is_vector> : std::true_type {}; template void adjust_zero_indexed(T& val) { using DecayedT = std::decay_t; if constexpr (is_pair::value) { adjust_zero_indexed(val.first); adjust_zero_indexed(val.second); } else if constexpr (is_tuple::value) { std::apply([](auto&... args) { (adjust_zero_indexed(args), ...); }, val); } else if constexpr (is_vector::value) { for (auto& elem : val) { adjust_zero_indexed(elem); } } else if constexpr (std::is_arithmetic_v && !std::is_same_v && !std::is_same_v && !std::is_same_v && !std::is_same_v && #if defined(__cpp_char8_t) !std::is_same_v && #endif !std::is_same_v && !std::is_same_v && !std::is_same_v) { --val; } else { } } using default_type = long; template void read(Args&... args) { input_detail::read_values(args...); } template T read_val() { T val; input_detail::read_one(std::cin, val); return val; } template std::pair read_pair() { std::pair p; input_detail::begin_input(); std::cin >> p; return p; } template std::tuple read_tuple() { std::tuple t; input_detail::begin_input(); std::cin >> t; return t; } template && !std::is_same_v, int> = 0> std::vector read_vec(Size n, bool zero_indexed = false) { std::vector v(n); input_detail::begin_input(); std::cin >> v; if (zero_indexed) { adjust_zero_indexed(v); } return v; } template std::vector read_vec(bool zero_indexed = false) { int n; input_detail::read_one(std::cin, n); return read_vec(n, zero_indexed); } template && !std::is_same_v, int> = 0> std::vector> read_vec_pair(Size n, bool zero_indexed = false) { return read_vec>(n, zero_indexed); } template std::vector> read_vec_pair(bool zero_indexed = false) { int n; input_detail::read_one(std::cin, n); return read_vec_pair(n, zero_indexed); } template && !std::is_same_v, int> = 0> std::vector> read_vec_tuple(Size n, bool zero_indexed = false) { return read_vec>(n, zero_indexed); } template std::vector> read_vec_tuple(bool zero_indexed = false) { int n; input_detail::read_one(std::cin, n); return read_vec_tuple(n, zero_indexed); } template std::vector> read_vec_grid(int h, int w, bool zero_indexed = false) { std::vector> grid(h, std::vector(w)); input_detail::begin_input(); std::cin >> grid; if (zero_indexed) { adjust_zero_indexed(grid); } return grid; } template std::vector> read_vec_grid(bool zero_indexed = false) { int h, w; input_detail::read_values(h, w); return read_vec_grid(h, w, zero_indexed); } template && !std::is_same_v, int> = 0> std::vector> read_vec_var(Size n, bool zero_indexed = false) { std::vector> res(n); input_detail::begin_input(); for (int i = 0; i < static_cast(n); ++i) { int m; input_detail::read_one(std::cin, m); res[i] = read_vec(m, zero_indexed); } return res; } template std::vector> read_vec_var(bool zero_indexed = false) { int n; input_detail::read_one(std::cin, n); return read_vec_var(n, zero_indexed); } template T read_zero_idx() { T val; input_detail::read_one(std::cin, val); adjust_zero_indexed(val); return val; } inline std::vector> read_graph(int n, int m, bool directed = false) { std::vector> g(n); input_detail::begin_input(); for (int i = 0; i < m; ++i) { int u = read_zero_idx(); int v = read_zero_idx(); g[u].push_back(v); if (!directed) { g[v].push_back(u); } } return g; } inline std::vector> read_graph(bool directed = false) { int n, m; input_detail::read_values(n, m); return read_graph(n, m, directed); } template struct Edge { int to; Cost cost; Edge() = default; Edge(int to, Cost cost) : to(to), cost(cost) {} }; template inline std::vector>> read_weighted_graph(int n, int m, bool directed = false) { std::vector>> g(n); input_detail::begin_input(); for (int i = 0; i < m; ++i) { int u = read_zero_idx(); int v = read_zero_idx(); Cost w; input_detail::read_one(std::cin, w); g[u].push_back(Edge{v, w}); if (!directed) { g[v].push_back(Edge{u, w}); } } return g; } template inline std::vector>> read_weighted_graph(bool directed = false) { int n, m; input_detail::read_values(n, m); return read_weighted_graph(n, m, directed); } #include #include #include #include #include #include #include #include #include #include #include #include #include #include template std::ostream& operator<<(std::ostream& os, const std::pair& p); template std::ostream& operator<<(std::ostream& os, const std::tuple& t); template std::ostream& operator<<(std::ostream& os, const std::optional& opt); template struct is_iterable : std::false_type {}; template struct is_iterable())), decltype(std::end(std::declval()))>> : std::bool_constant> {}; template inline constexpr bool is_iterable_v = is_iterable::value; template , int> = 0> std::ostream& operator<<(std::ostream& os, const T& container); template std::ostream& operator<<(std::ostream& os, const std::pair& p) { return os << p.first << " " << p.second; } template void print_tuple_impl(std::ostream& os, const Tuple& t, std::index_sequence) { ((os << (I == 0 ? "" : " ") << std::get(t)), ...); } template std::ostream& operator<<(std::ostream& os, const std::tuple& t) { print_tuple_impl(os, t, std::index_sequence_for{}); return os; } template std::ostream& operator<<(std::ostream& os, const std::optional& opt) { if (opt.has_value()) return os << *opt; return os << "-1"; } template , 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 struct Plus1Wrapper { const T& val; }; template constexpr Plus1Wrapper plus1(const T& x) { return Plus1Wrapper{x}; } template std::ostream& operator<<(std::ostream& os, const Plus1Wrapper>& w) { return os << (w.val.first + 1) << " " << (w.val.second + 1); } template std::ostream& operator<<(std::ostream& os, const Plus1Wrapper& w) { if constexpr (is_iterable_v) { 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 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 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 void pr(const Args&... args) { out(args...); } template void out_lines(const Container& c) { for (const auto& x : c) { std::cout << x << "\n"; } } template 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 #include #include #include #include #define ALL(a) (a).begin(), (a).end() using i128 = __int128; template inline bool chmin(T& a, const U& b) { if (a > b) { a = b; return true; } return false; } template inline bool chmax(T& a, const U& b) { if (a < b) { a = b; return true; } return false; } template inline T div_ceil(T a, T b) { if (a > 0) return a / b + (a % b != 0); return a / b; } template inline T div_floor(T a, T b) { if (a < 0) return a / b - (a % b != 0); return a / b; } template inline T mod(T a, T m) { a %= m; if (a < 0) a += m; return a; } template inline constexpr T INF = std::numeric_limits::max() / 2; template <> inline constexpr float INF = std::numeric_limits::infinity(); template <> inline constexpr double INF = std::numeric_limits::infinity(); template <> inline constexpr long double INF = std::numeric_limits::infinity(); template auto make_vector(size_t size, T&& initial_value) { return std::vector>(size, std::forward(initial_value)); } template auto make_vector(size_t size, Args&&... args) { auto inner = make_vector(std::forward(args)...); return std::vector(size, inner); } template inline std::vector iota_vec(int n, T start = 0) { std::vector v(n); std::iota(v.begin(), v.end(), start); return v; } template inline std::vector doubled_vec(const std::vector& v) { std::vector 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 #else #define debug(...) #endif void solve() { ios::sync_with_stdio(false); cin.tie(nullptr); int N, M, K; read(N, M, K); auto G = make_vector(N, N, 0); vector perm; for (int iter = 0; iter < N / M; iter++) { for (int j = 0; j < M; j++) { perm.push_back(j + 1); } } deque deq(ALL(perm)); for (int i = 0; i < N; i++) { G[i] = vector(ALL(deq)); for (int j = 0; j < K; j++) { deq.push_back(deq[0]); deq.pop_front(); } } out_lines(G); } int main() { solve(); }