#include using namespace std; using lint = long long int; using pint = pair; using plint = pair; struct fast_ios { fast_ios(){ cin.tie(0); ios::sync_with_stdio(false); cout << fixed << setprecision(20); }; } fast_ios_; #define ALL(x) (x).begin(), (x).end() #define SZ(x) ((lint)(x).size()) #define POW2(n) (1LL << (n)) #define FOR(i, begin, end) for(int i=(begin),i##_end_=(end);i=i##_begin_;i--) #define REP(i, n) FOR(i,0,n) #define IREP(i, n) IFOR(i,0,n) template void ndarray(vector &vec, int len) { vec.resize(len); } template void ndarray(vector &vec, int len, Args... args) { vec.resize(len); for (auto &v : vec) ndarray(v, args...); } template bool mmax(T &m, const T q) { if (m < q) {m = q; return true;} else return false; } template bool mmin(T &m, const T q) { if (m > q) {m = q; return true;} else return false; } template pair operator+(const pair &l, const pair &r) { return make_pair(l.first + r.first, l.second + r.second); } template pair operator-(const pair &l, const pair &r) { return make_pair(l.first - r.first, l.second - r.second); } template istream &operator>>(istream &is, vector &vec){ for (auto &v : vec) is >> v; return is; } ///// This part below is only for debug, not used ///// template ostream &operator<<(ostream &os, const vector &vec){ os << "["; for (auto v : vec) os << v << ","; os << "]"; return os; } template ostream &operator<<(ostream &os, const deque &vec){ os << "deq["; for (auto v : vec) os << v << ","; os << "]"; return os; } template ostream &operator<<(ostream &os, const set &vec){ os << "{"; for (auto v : vec) os << v << ","; os << "}"; return os; } template ostream &operator<<(ostream &os, const unordered_set &vec){ os << "{"; for (auto v : vec) os << v << ","; os << "}"; return os; } template ostream &operator<<(ostream &os, const multiset &vec){ os << "{"; for (auto v : vec) os << v << ","; os << "}"; return os; } template ostream &operator<<(ostream &os, const unordered_multiset &vec){ os << "{"; for (auto v : vec) os << v << ","; os << "}"; return os; } template ostream &operator<<(ostream &os, const pair &pa){ os << "(" << pa.first << "," << pa.second << ")"; return os; } template ostream &operator<<(ostream &os, const map &mp){ os << "{"; for (auto v : mp) os << v.first << "=>" << v.second << ","; os << "}"; return os; } template ostream &operator<<(ostream &os, const unordered_map &mp){ os << "{"; for (auto v : mp) os << v.first << "=>" << v.second << ","; os << "}"; return os; } #define dbg(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ") " << __FILE__ << endl; ///// END ///// /* #include #include #include using namespace __gnu_pbds; // find_by_order(), order_of_key() template using pbds_set = tree, rb_tree_tag, tree_order_statistics_node_update>; template using pbds_map = tree, rb_tree_tag, tree_order_statistics_node_update>; */ struct DirectedGraph { int V; // 頂点数 vector > to; vector > from; vector used; vector vs; void dfs(int v) { used[v] = true; for (auto t : to[v]) if (!used[t]) dfs(t); vs.push_back(v); } void rdfs(int v, int k) { used[v] = true; cmp[v] = k; for (auto t : from[v]) if (!used[t]) rdfs(t, k); } vector cmp; DirectedGraph(int V) : V(V), to(vector >(V)), from(vector >(V)), cmp(vector(V)) {} void add_edge(int from_, int to_) { to[from_].push_back(to_); from[to_].push_back(from_); } int scc_num = -1; int scc() { used = vector(V, false); vs.clear(); for (int v = 0; v < V; v++) if (!used[v]) dfs(v); used = vector(V, false); scc_num = 0; for (int i = vs.size() - 1; i >= 0; i--) if (!used[vs[i]]) rdfs(vs[i], scc_num++); return scc_num; // 強連結成分の個数を返却 } // scc()を実行したあと,強連結成分を潰したトポロジカル順序のグラフを生成 DirectedGraph generateTopologicalGraph() { DirectedGraph newgraph(scc_num); REP(s, V) for (auto t : to[s]) { if (cmp[s] != cmp[t]) newgraph.add_edge(cmp[s], cmp[t]); } return newgraph; } }; // DirectedGraph g(12); // g.add_edge(0, 1); // g.add_edge(6, 8); // g.add_edge(6, 9); // g.add_edge(9, 8); // g.add_edge(8, 10); // g.add_edge(10, 8); // g.add_edge(9, 11); // cout << g.scc() << endl; // for (auto e : g.cmp) cout << e << endl; int main() { int H, W; cin >> H >> W; vector A(H), B(W); cin >> A >> B; sort(A.rbegin(), A.rend()); sort(B.rbegin(), B.rend()); DirectedGraph g(H * W); REP(h, H) { int a = A[h]; REP(i, a - 1) g.add_edge(h * W + i, h * W + (i + 1)); FOR(i, a, W) g.add_edge(h * W + i, h * W + a - 1); } REP(w, W) { int b = B[w]; REP(i, b - 1) g.add_edge(i * W + w, (i + 1) * W + w); FOR(i, b, H) g.add_edge(i * W + w, (b - 1) * W + w); } int t = g.scc(); if (t < H * W) exit(8); vector> ret(H, vector(W)); REP(i, H * W) ret[i / W][i % W] = g.cmp[i]; REP(h, H) { REP(w, W) cout << ret[h][w] + 1 << " "; cout << endl; } }