結果
問題 | No.2824 Lights Up! (Grid Edition) |
ユーザー |
![]() |
提出日時 | 2024-07-27 09:30:45 |
言語 | C++23 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 292 ms / 2,000 ms |
コード長 | 2,115 bytes |
コンパイル時間 | 3,802 ms |
コンパイル使用メモリ | 282,588 KB |
実行使用メモリ | 13,492 KB |
最終ジャッジ日時 | 2024-07-27 09:30:59 |
合計ジャッジ時間 | 14,615 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 4 |
other | AC * 100 |
ソースコード
#include<bits/stdc++.h> namespace { #pragma GCC diagnostic ignored "-Wunused-function" #include<atcoder/all> #pragma GCC diagnostic warning "-Wunused-function" using namespace std; using namespace atcoder; #define rep(i,n) for(int i = 0; i < (int)(n); i++) #define rrep(i,n) for(int i = (int)(n) - 1; i >= 0; i--) #define all(x) begin(x), end(x) #define rall(x) rbegin(x), rend(x) template<class T> bool chmax(T& a, const T& b) { if (a < b) { a = b; return true; } else return false; } template<class T> bool chmin(T& a, const T& b) { if (b < a) { a = b; return true; } else return false; } using ll = long long; using P = pair<int,int>; using VI = vector<int>; using VVI = vector<VI>; using VL = vector<ll>; using VVL = vector<VL>; } int main() { ios::sync_with_stdio(false); cin.tie(0); int n; cin >> n; vector<string> s(n); rep(i, n) cin >> s[i]; rep(i, n) rep(j, n) s[i][j] = s[i][j] == '#'; vector<vector<char>> act(n, vector<char>(n)); auto do_op = [&](int i, int j) { rep(di, 2) rep(dj, 2) { int x = i - di, y = j - dj; x %= n, y %= n; if (x < 0) x += n; if (y < 0) y += n; s[x][y] ^= 1; } }; auto do_act = [&](int i, int j) { i %= n, j %= n; if (i < 0) i += n; if (j < 0) j += n; act[i][j] ^= 1; do_op(i, j); do_op(i, 0); do_op(0, j); }; auto do_act4 = [&](int i, int j) { rep(di, 2) rep(dj, 2) do_act(i - di, j - dj); }; if (n % 2 == 0) { bool acc = 0; for (int j = 0; j < n; j += 2) acc ^= s[0][j]; if (acc) do_act(0, 0); for (int i = n - 1; i >= 2; i--) { for (int j = n - 1; j >= 2; j--) { if (s[i][j]) do_act4(i, j); } } } else { for (int i = (n + n - 2) % n; i != 0; i = (n + i - 2) % n) { for (int j = (n + n - 2) % n; j != 0; j = (n + j - 2) % n) { if (s[i][j]) do_act4(i, j); } } } vector<P> ans; rep(i, n) rep(j, n) { if (s[i][j]) { cout << -1 << '\n'; return 0; } if (act[i][j]) ans.emplace_back(i, j); } cout << ans.size() << '\n'; for (auto [i, j] : ans) cout << i << ' ' << j << '\n'; }