結果

問題 No.179 塗り分け
ユーザー kakeyamay
提出日時 2023-01-02 16:23:55
言語 C++23
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 26 ms / 3,000 ms
コード長 1,026 bytes
コンパイル時間 1,675 ms
コンパイル使用メモリ 118,784 KB
実行使用メモリ 5,248 KB
最終ジャッジ日時 2024-11-27 00:59:58
合計ジャッジ時間 2,987 ms
ジャッジサーバーID
(参考情報)
judge3 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 6
other AC * 40
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <algorithm>
#include <iostream>
#include <ranges>
#include <string>
#include <vector>

int main() {
  int H, W;
  std::cin >> H >> W;
  std::vector<std::string> S(H);
  for (auto& s : S) std::cin >> s;
  
  if (!std::ranges::any_of(S, [](const std::string& s) { return s.contains('#'); }))
    goto outer_end;
  
  for (auto dy : std::views::iota(1 - H, H)) {
    for (auto dx : std::views::iota(1 - W, W)) {
      if (dx == 0 && dy == 0) continue;
      auto T = S;
      for (auto y : std::views::iota(std::max(0, -dy), H - std::max(0, dy))) {
        for (auto x : std::views::iota(std::max(0, -dx), W - std::max(0, dx))) {
          if (T[y][x] != '#') continue;
          if (T[y + dy][x + dx] != '#') goto inner_end;
          T[y][x] = 'R';
          T[y + dy][x + dx] = 'B';
        }
      }
      if (std::ranges::any_of(T, [](const std::string& s) { return s.contains('#'); })) continue;
      std::cout << "YES" << '\n';
      return 0;
    inner_end:;
    }
  }
outer_end:
  std::cout << "NO" << '\n';
}
0