結果

問題 No.918 LISGRID
ユーザー pekempeypekempey
提出日時 2019-10-25 22:48:12
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
MLE  
実行時間 -
コード長 1,584 bytes
コンパイル時間 1,822 ms
コンパイル使用メモリ 172,588 KB
実行使用メモリ 814,168 KB
最終ジャッジ日時 2023-10-11 07:12:47
合計ジャッジ時間 5,202 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,352 KB
testcase_01 AC 26 ms
8,452 KB
testcase_02 AC 9 ms
5,008 KB
testcase_03 AC 11 ms
5,684 KB
testcase_04 AC 10 ms
5,092 KB
testcase_05 MLE -
testcase_06 -- -
testcase_07 -- -
testcase_08 -- -
testcase_09 -- -
testcase_10 -- -
testcase_11 -- -
testcase_12 -- -
testcase_13 -- -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
testcase_20 -- -
testcase_21 -- -
testcase_22 -- -
testcase_23 -- -
testcase_24 -- -
testcase_25 -- -
testcase_26 -- -
testcase_27 -- -
testcase_28 -- -
testcase_29 -- -
testcase_30 -- -
testcase_31 -- -
testcase_32 -- -
testcase_33 -- -
testcase_34 -- -
testcase_35 -- -
testcase_36 -- -
testcase_37 -- -
testcase_38 -- -
権限があれば一括ダウンロードができます

ソースコード

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];
  vector<vector<int>> g(H * W);
  auto index = [&](int i, int j) { return i * W + j; };
  rep(i, H) {
    if (A[i] == 1) {
      repr(j, W - 1) g[index(i, j + 1)].push_back(index(i, j));
    } else {
      rep(j, A[i] - 2) g[index(i, j)].push_back(index(i, j + 1));
      g[index(i, A[i] - 2)].push_back(index(i, W - 1));
      rep2r(j, A[i] - 1, W - 1) g[index(i, j + 1)].push_back(index(i, j));
    }
  }
  rep(j, W) {
    if (B[j] == 1) {
      repr(i, H - 1) g[index(i + 1, j)].push_back(index(i, j));
    } else {
      rep(i, B[j] - 2) g[index(i, j)].push_back(index(i + 1, j));
      g[index(B[j] - 2, j)].push_back(index(H - 1, j));
      rep2r(i, B[j] - 1, H - 1) g[index(i + 1, j)].push_back(index(i, j));
    }
  }
  vector<int> ans(H * W, -1);
  int now = H * W;
  auto dfs = [&](auto dfs, int u) -> void {
    for (int v : g[u]) {
      if (ans[v] == -1) {
        dfs(dfs, v);
      }
    }
    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