結果

問題 No.1056 2D Lamps
ユーザー noshi91noshi91
提出日時 2020-05-15 22:17:26
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,823 bytes
コンパイル時間 946 ms
コンパイル使用メモリ 87,580 KB
実行使用メモリ 4,680 KB
最終ジャッジ日時 2023-10-19 14:56:02
合計ジャッジ時間 6,557 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 WA -
testcase_02 WA -
testcase_03 WA -
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <algorithm>
#include <array>
#include <iostream>
#include <numeric>
#include <vector>

auto boolmat(int n, int m) {
  return std::vector<std::vector<bool>>(n, std::vector<bool>(m, false));
}

int main() {
  std::ios::sync_with_stdio(false);
  std::cin.tie(nullptr);

  int n, m;
  std::cin >> n >> m;
  auto b = boolmat(m, m);
  const int s = n >= 3 ? (n - 3) * (n - 3) : 0;
  auto c = boolmat(m, s);
  for (int i = 0; i < m; ++i) {
    auto a = boolmat(n, n);
    for (auto &&v : a) {
      for (auto &&e : v) {
        char t;
        std::cin >> t;
        e = t != '.';
      }
    }
    std::array<int, 8> dx = {-2, -2, -1, -1, 0, 0, 1, 1};
    std::array<int, 8> dy = {-1, 0, -2, 1, -2, 1, -1, 0};
    int j = 0;
    for (int x = 2; x + 2 <= n; ++x) {
      for (int y = 2; y + 2 <= n; ++y) {
        bool t = false;
        for (int k = 0; k < 8; ++k) {
          t = t != a[x + dx[k]][y + dy[k]];
        }
        c[i][j] = t;
        ++j;
      }
    }
  }
  {
    std::vector<int> idx(m);
    std::iota(idx.begin(), idx.end(), 0);
    for (int j = 0; j < s; ++j) {
      std::vector<int> f, t;
      for (const int i : idx) {
        if (c[i][j]) {
          t.push_back(i);
        } else {
          f.push_back(i);
        }
      }
      std::copy(f.cbegin(), f.cend(), idx.begin());
      std::copy(t.cbegin(), t.cend(), idx.begin() + f.size());
    }
    std::vector<int> list;
    for (int k = 0; k < m; ++k) {
      const int i = idx[k];
      if (k != 0 && c[idx[k - 1]] != c[i]) {
        list.clear();
      }
      for (const int j : list) {
        b[i][j] = true;
      }
      list.push_back(i);
    }
  }
  for (int i = 0; i < m; ++i) {
    for (int j = 0; j < m; ++j) {
      if (i < j) {
        std::cout << (b[i][j] || b[j][i] ? '1' : '0');
      }
    }
    std::cout << '\n';
  }
}
0