結果

問題 No.2824 Lights Up! (Grid Edition)
ユーザー 👑 Nachia
提出日時 2024-07-26 22:31:18
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 993 ms / 2,000 ms
コード長 2,336 bytes
コンパイル時間 1,409 ms
コンパイル使用メモリ 114,508 KB
最終ジャッジ日時 2025-02-23 18:47:32
ジャッジサーバーID
(参考情報)
judge1 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 4
other AC * 100
権限があれば一括ダウンロードができます

ソースコード

diff #

#ifdef NACHIA
#define _GLIBCXX_DEBUG
#else
#define NDEBUG
#endif
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <utility>
#include <queue>
#include <array>
#include <cmath>
using i64 = long long;
using u64 = unsigned long long;
#define rep(i,n) for(int i=0; i<int(n); i++)
#define repr(i,n) for(int i=int(n)-1; i>=0; i--)
const i64 INF = 1001001001001001001;
const char* yn(bool x){ return x ? "Yes" : "No"; }
template<typename A> void chmin(A& l, const A& r){ if(r < l) l = r; }
template<typename A> void chmax(A& l, const A& r){ if(l < r) l = r; }
template<typename A> using nega_queue = std::priority_queue<A,std::vector<A>,std::greater<A>>;
template<class R> auto ComparingBy(R f){ return [g=std::move(f)](auto l, auto r) -> bool { return g(l) < g(r); }; }
#include <atcoder/modint>
#include <set>
using Modint = atcoder::static_modint<998244353>;
using namespace std;

void testcase(){
    int N; cin >> N;
    set<pair<int,int>> ans;
    vector<vector<int>> Q(N, vector<int>(N));
    rep(x,N){
        string s; cin >> s;
        rep(y,N) Q[x][y] = (s[y] == '#' ? 1 : 0);
    }
   // rep(x,N){ rep(y,N){ cout << Q[x][y]; } cout << endl; }
    auto ope = [&](int x, int y){
        Q[x][y] ^= 1;
        Q[x == 0 ? N - 1 : x - 1][y] ^= 1;
        Q[x][y == 0 ? N - 1 : y - 1] ^= 1;
        Q[x == 0 ? N - 1 : x - 1][y == 0 ? N - 1 : y - 1] ^= 1;
    };
    auto mov = [&](int x, int y){
        ope(x, y);
        ope(x, 0);
        ope(0, y);
        if(ans.count({x,y})) ans.erase({x,y}); else ans.insert({x,y});
    };
    for(int x=1; x<N-1; x++) for(int y=1; y<N-1; y++) if(Q[x][y]) mov(x+1, y+1);
    //rep(x,N){ rep(y,N){ cout << Q[x][y]; } cout << endl; }
    //vector<nachia::Bitset> bs(N*4 - 4, nachia::Bitset(N*2-1));
    for(int i=N-2; i>0; i--) if(Q[i][0]){
        for(int j=1; j<N; j++) mov(i,j);
    }
    for(int i=N-2; i>=0; i--) if(Q[0][i]){
        for(int j=1; j<N; j++) mov(j,i);
    }
    if(Q[0][0]) mov(0,0);
    //rep(x,N){ rep(y,N){ cout << Q[x][y]; } cout << endl; }
    bool ok = true;
    rep(x,N) rep(y,N) if(Q[x][y] != 0) ok = false;
    if(!ok){ cout << "-1\n"; return; }
    cout << ans.size() << '\n';
    for(auto [x,y] : ans) cout << x << ' ' << y << '\n';
}

int main(){
    ios::sync_with_stdio(false); cin.tie(nullptr);
    testcase();
    return 0;
}
0