結果
問題 | No.2824 Lights Up! (Grid Edition) |
ユーザー |
![]() |
提出日時 | 2024-04-11 21:57:07 |
言語 | C++23 (gcc 13.3.0 + boost 1.87.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 2,044 bytes |
コンパイル時間 | 1,504 ms |
コンパイル使用メモリ | 136,168 KB |
実行使用メモリ | 13,744 KB |
最終ジャッジ日時 | 2024-07-26 20:31:16 |
合計ジャッジ時間 | 8,058 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 4 |
other | AC * 92 WA * 8 |
ソースコード
#include <utility> #include <numeric> #include <algorithm> #include <iostream> #include <valarray> #include <vector> #include <ranges> void solve() { int n; std::cin >> n; std::vector pos(n, std::valarray<bool>(n)); std::valarray<bool> row(n), col(n); for(int i : std::views::iota(0, n)) { for(int j : std::views::iota(0, n)) { char c; std::cin >> c; if((pos[i][j] = (c == '#'))) row[i] ^= 1, col[j] ^= 1; } } auto check_parity = [&](const bool even) { if(even && row[0] != 0) { std::cout << "-1\n"; exit(0); } if(row[0] != col[0]) { std::cout << "-1\n"; exit(0); } for(const int i : std::views::iota(1, n)) { if(row[0] != row[i] or col[0] != col[i]) { std::cout << "-1\n"; exit(0); } } }; check_parity(true); if(--n == 0) { std::cout << "0\n"; return; } for(int i : std::views::iota(0, n)) { for(int j : std::views::iota(0, n)) { if(i > 0) pos[i][j] ^= pos[i - 1][j]; if(j > 0) pos[i][j] ^= pos[i][j - 1]; if(i > 0 and j > 0) pos[i][j] ^= pos[i - 1][j - 1]; } } std::ranges::fill(row, 0); std::ranges::fill(col, 0); for(int i : std::views::iota(0, n)) { for(int j : std::views::iota(0, n)) { if(pos[i][j]) row[i] ^= 1, col[j] ^= 1; } } // if(n % 2 == 1) check_parity(false); std::vector<std::pair<int,int>> ans; for(int i : std::views::iota(0, n)) { for(int j : std::views::iota(0, n)) { if(pos[i][j] ^ row[i] ^ col[j]) ans.emplace_back(i, j); } } std::cout << ans.size() << "\n"; for(const auto& [ i, j ] : ans) std::cout << i + 1 << " " << j + 1 << "\n"; return; } int main() { solve(); return 0; } __attribute__((constructor)) inline void fast_io() { std::ios::sync_with_stdio(false), std::cin.tie(nullptr); }