結果
問題 |
No.1954 CHECKER×CHECKER(2)
|
ユーザー |
![]() |
提出日時 | 2022-04-25 03:59:54 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 16 ms / 1,000 ms |
コード長 | 2,329 bytes |
コンパイル時間 | 840 ms |
コンパイル使用メモリ | 88,924 KB |
最終ジャッジ日時 | 2025-01-28 21:32:20 |
ジャッジサーバーID (参考情報) |
judge5 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 29 |
ソースコード
#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); }