結果

問題 No.1954 CHECKER×CHECKER(2)
ユーザー naskyanaskya
提出日時 2022-04-25 03:59:54
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 2 ms / 1,000 ms
コード長 2,329 bytes
コンパイル時間 912 ms
コンパイル使用メモリ 91,356 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-09-10 16:32:04
合計ジャッジ時間 2,193 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 2 ms
4,376 KB
testcase_03 AC 2 ms
4,376 KB
testcase_04 AC 2 ms
4,376 KB
testcase_05 AC 1 ms
4,376 KB
testcase_06 AC 1 ms
4,380 KB
testcase_07 AC 2 ms
4,380 KB
testcase_08 AC 2 ms
4,376 KB
testcase_09 AC 1 ms
4,376 KB
testcase_10 AC 1 ms
4,380 KB
testcase_11 AC 1 ms
4,376 KB
testcase_12 AC 2 ms
4,376 KB
testcase_13 AC 2 ms
4,376 KB
testcase_14 AC 2 ms
4,380 KB
testcase_15 AC 1 ms
4,376 KB
testcase_16 AC 1 ms
4,376 KB
testcase_17 AC 1 ms
4,376 KB
testcase_18 AC 1 ms
4,380 KB
testcase_19 AC 1 ms
4,376 KB
testcase_20 AC 2 ms
4,380 KB
testcase_21 AC 2 ms
4,380 KB
testcase_22 AC 2 ms
4,380 KB
testcase_23 AC 1 ms
4,380 KB
testcase_24 AC 2 ms
4,380 KB
testcase_25 AC 2 ms
4,380 KB
testcase_26 AC 2 ms
4,380 KB
testcase_27 AC 2 ms
4,380 KB
testcase_28 AC 2 ms
4,380 KB
testcase_29 AC 1 ms
4,376 KB
testcase_30 AC 2 ms
4,380 KB
testcase_31 AC 1 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <algorithm>
#include <cstdlib>
#include <iostream>
#include <iterator>
#include <set>
#include <string>
#include <vector>

void answer(const bool f) {
  std::cout << (f ? "Yes\n" : "No\n");
  std::exit(EXIT_SUCCESS);
}

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

  int H, W;
  std::cin >> H >> W;

  std::vector<std::string> S(H);
  for (int i = 0; i < H; ++i) {
    std::cin >> S[i];
    for (int j = i & 1; j < W; j += 2)
      S[i][j] = (S[i][j] == '.' ? '#' : '.');
  }

  int M;
  std::cin >> M;

  std::set<int> immutable_horizontal_edges, immutable_vertical_edges;
  std::generate_n(std::inserter(immutable_horizontal_edges, immutable_horizontal_edges.end()), H - 1, [i = 0]() mutable { return i++; });
  std::generate_n(std::inserter(immutable_vertical_edges, immutable_vertical_edges.end()), W - 1, [j = 0]() mutable { return j++; });

  std::vector<int> mutable_horizontal_edges, mutable_vertical_edges;
  mutable_horizontal_edges.reserve(M);
  mutable_vertical_edges.reserve(M);

  for (int _ = 0; _ < M; ++_) {
    int t, n;
    std::cin >> t >> n;

    if ((t == 1 && n == H) || (t == 2 && n == W))
      continue;

    --n;

    (t == 1 ? immutable_horizontal_edges : immutable_vertical_edges).erase(n);
    (t == 1 ? mutable_horizontal_edges : mutable_vertical_edges).emplace_back(n);
  }

  for (const auto i : immutable_horizontal_edges)
    for (int j = 0; j < W; ++j)
      if (S[i][j] != S[i + 1][j])
        answer(false);

  for (const auto j : immutable_vertical_edges)
    for (int i = 0; i < H; ++i)
      if (S[i][j] != S[i][j + 1])
        answer(false);

  mutable_horizontal_edges.emplace_back(H - 1);
  mutable_vertical_edges.emplace_back(W - 1);

  for (const int i : mutable_horizontal_edges)
    if (S[i][0] == '.')
      for (const int j : mutable_vertical_edges)
        S[i][j] = (S[i][j] == '.' ? '#' : '.');

  for (const int j : mutable_vertical_edges)
    if (S[0][j] == '.')
      for (const int i : mutable_horizontal_edges)
        S[i][j] = (S[i][j] == '.' ? '#' : '.');

  for (const char target : ".#") {
    bool tmp = true;

    for (const int i : mutable_horizontal_edges)
      for (const int j : mutable_vertical_edges)
        if (S[i][j] != target)
          tmp = false;

    if (tmp)
      answer(true);
  }

  answer(false);
}
0