結果
問題 | No.2824 Lights Up! (Grid Edition) |
ユーザー |
|
提出日時 | 2024-07-25 08:55:25 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 928 ms / 2,000 ms |
コード長 | 1,337 bytes |
コンパイル時間 | 2,250 ms |
コンパイル使用メモリ | 204,852 KB |
最終ジャッジ日時 | 2025-02-23 17:59:33 |
ジャッジサーバーID (参考情報) |
judge4 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 4 |
other | AC * 100 |
ソースコード
#include <bits/stdc++.h> using namespace std; int main(){ int N; cin >> N; vector<string> S(N); for (int i = 0; i < N; i++){ cin >> S[i]; } auto op = [&](int r, int c){ S[r][c] ^= '.' ^ '#'; S[(N + r - 1) % N][c] ^= '.' ^ '#'; S[r][(N + c - 1) % N] ^= '.' ^ '#'; S[(N + r - 1) % N][(N + c - 1) % N] ^= '.' ^ '#'; }; vector<vector<int>> ans(N, vector<int>(N)); for (int i = 1; i < N; i++){ for (int j = 1; j < N; j++){ if (S[i - 1][j - 1] == '#'){ ans[i][j] ^= true; op(i, j); op(i, 0); op(0, j); } } } for (int i = 1; i < N; i++){ if (S[i - 1][0] == '#'){ for (int j = 1; j < N; j++){ ans[i][j] ^= true; op(i, j); op(i, 0); op(0, j); } } if (S[0][i - 1] == '#'){ for (int j = 1; j < N; j++){ ans[j][i] ^= true; op(j, i); op(j, 0); op(0, i); } } } if (S[0][0] == '#'){ ans[0][0] ^= true; op(0, 0); } bool ok = true; for (int i = 0; i < N; i++){ for (int j = 0; j < N; j++){ if (S[i][j] == '#'){ ok = false; } } } if (ok){ vector<pair<int, int>> RC; for (int i = 0; i < N; i++){ for (int j = 0; j < N; j++){ if (ans[i][j]){ RC.push_back(make_pair(i, j)); } } } cout << RC.size() << endl; for (auto [R, C] : RC){ cout << R << ' ' << C << endl; } } else { cout << -1 << endl; } }