結果

問題 No.918 LISGRID
ユーザー pekempeypekempey
提出日時 2019-10-25 23:18:37
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 15 ms / 2,000 ms
コード長 1,697 bytes
コンパイル時間 1,660 ms
コンパイル使用メモリ 172,716 KB
実行使用メモリ 6,420 KB
最終ジャッジ日時 2023-10-11 09:35:08
合計ジャッジ時間 5,308 ms
ジャッジサーバーID
(参考情報)
judge11 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,356 KB
testcase_01 AC 9 ms
4,348 KB
testcase_02 AC 4 ms
4,348 KB
testcase_03 AC 5 ms
4,352 KB
testcase_04 AC 5 ms
4,352 KB
testcase_05 AC 13 ms
6,416 KB
testcase_06 AC 11 ms
4,348 KB
testcase_07 AC 14 ms
4,884 KB
testcase_08 AC 9 ms
4,380 KB
testcase_09 AC 11 ms
4,696 KB
testcase_10 AC 11 ms
4,640 KB
testcase_11 AC 12 ms
4,640 KB
testcase_12 AC 13 ms
4,624 KB
testcase_13 AC 10 ms
4,620 KB
testcase_14 AC 14 ms
4,964 KB
testcase_15 AC 15 ms
6,212 KB
testcase_16 AC 7 ms
4,352 KB
testcase_17 AC 7 ms
4,352 KB
testcase_18 AC 7 ms
4,348 KB
testcase_19 AC 4 ms
4,348 KB
testcase_20 AC 11 ms
6,420 KB
testcase_21 AC 4 ms
4,352 KB
testcase_22 AC 3 ms
4,352 KB
testcase_23 AC 6 ms
4,348 KB
testcase_24 AC 2 ms
4,348 KB
testcase_25 AC 1 ms
4,348 KB
testcase_26 AC 1 ms
4,356 KB
testcase_27 AC 1 ms
4,348 KB
testcase_28 AC 1 ms
4,348 KB
testcase_29 AC 1 ms
4,348 KB
testcase_30 AC 2 ms
4,348 KB
testcase_31 AC 2 ms
4,348 KB
testcase_32 AC 2 ms
4,352 KB
testcase_33 AC 2 ms
4,352 KB
testcase_34 AC 2 ms
4,352 KB
testcase_35 AC 2 ms
4,348 KB
testcase_36 AC 2 ms
4,348 KB
testcase_37 AC 9 ms
4,356 KB
testcase_38 AC 6 ms
4,348 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>

#define rep(i, n) for (int i = 0; i < (n); i++)
#define repr(i, n) for (int i = (n) - 1; i >= 0; i--)
#define rep2(i, l, r) for (int i = (l); i < (r); i++)
#define rep2r(i, l, r) for (int i = (r) - 1; i >= (l); i--)
#define range(a) a.begin(), a.end()

using namespace std;
using ll = long long;

int main() {
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  cout << fixed << setprecision(15);
  int H, W; cin >> H >> W;
  vector<int> A(H); rep(i, H) cin >> A[i];
  vector<int> B(W); rep(i, W) cin >> B[i];
  sort(range(A));
  sort(range(B));
  vector<int> row(H * W, -1);
  vector<int> col(H * W, -1);
  auto index = [&](int i, int j) { return i * W + j; };
  rep(i, H) {
    if (A[i] == 1) {
      repr(j, W - 1) row[index(i, j + 1)] = index(i, j);
    } else {
      rep(j, A[i] - 2) row[index(i, j)] = index(i, j + 1);
      row[index(i, A[i] - 2)] = index(i, W - 1);
      rep2r(j, A[i] - 1, W - 1) row[index(i, j + 1)] = index(i, j);
    }
  }
  rep(j, W) {
    if (B[j] == 1) {
      repr(i, H - 1) col[index(i + 1, j)] = index(i, j);
    } else {
      rep(i, B[j] - 2) col[index(i, j)] = index(i + 1, j);
      col[index(B[j] - 2, j)] = index(H - 1, j);
      rep2r(i, B[j] - 1, H - 1) col[index(i + 1, j)] = index(i, j);
    }
  }
  auto decomp = [&](int x) {
    return make_pair(x / W, x % W);
  };
  vector<int> ans(H * W, -1);
  int now = H * W;
  auto dfs = [&](auto dfs, int u) -> void {
    if (u == -1) return;
    if (ans[u] != -1) return;
    dfs(dfs, row[u]);
    dfs(dfs, col[u]);
    assert(now >= 1);
    ans[u] = now--;
  };
  rep(i, H * W) if (ans[i] == -1) dfs(dfs, i);
  rep(i, H) rep(j, W) cout << ans[index(i, j)] << " \n"[j == W - 1];
}
0