結果

問題 No.2824 Lights Up! (Grid Edition)
ユーザー NachiaNachia
提出日時 2024-07-26 22:31:18
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 996 ms / 2,000 ms
コード長 2,336 bytes
コンパイル時間 1,263 ms
コンパイル使用メモリ 115,120 KB
実行使用メモリ 37,760 KB
最終ジャッジ日時 2024-07-26 22:31:41
合計ジャッジ時間 21,785 ms
ジャッジサーバーID
(参考情報)
judge2 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,816 KB
testcase_01 AC 2 ms
6,940 KB
testcase_02 AC 2 ms
6,940 KB
testcase_03 AC 2 ms
6,940 KB
testcase_04 AC 765 ms
30,848 KB
testcase_05 AC 730 ms
30,848 KB
testcase_06 AC 774 ms
30,976 KB
testcase_07 AC 333 ms
30,848 KB
testcase_08 AC 743 ms
30,976 KB
testcase_09 AC 798 ms
30,720 KB
testcase_10 AC 736 ms
30,720 KB
testcase_11 AC 334 ms
30,848 KB
testcase_12 AC 781 ms
30,720 KB
testcase_13 AC 888 ms
30,848 KB
testcase_14 AC 780 ms
30,720 KB
testcase_15 AC 827 ms
36,096 KB
testcase_16 AC 797 ms
30,848 KB
testcase_17 AC 835 ms
30,848 KB
testcase_18 AC 764 ms
30,720 KB
testcase_19 AC 996 ms
37,760 KB
testcase_20 AC 188 ms
12,160 KB
testcase_21 AC 482 ms
22,016 KB
testcase_22 AC 11 ms
6,940 KB
testcase_23 AC 268 ms
25,856 KB
testcase_24 AC 2 ms
6,940 KB
testcase_25 AC 18 ms
6,940 KB
testcase_26 AC 237 ms
13,184 KB
testcase_27 AC 664 ms
28,800 KB
testcase_28 AC 8 ms
6,944 KB
testcase_29 AC 46 ms
6,944 KB
testcase_30 AC 24 ms
6,940 KB
testcase_31 AC 2 ms
6,944 KB
testcase_32 AC 42 ms
6,940 KB
testcase_33 AC 9 ms
6,940 KB
testcase_34 AC 4 ms
6,944 KB
testcase_35 AC 3 ms
6,944 KB
testcase_36 AC 2 ms
6,940 KB
testcase_37 AC 3 ms
6,940 KB
testcase_38 AC 3 ms
6,940 KB
testcase_39 AC 2 ms
6,944 KB
testcase_40 AC 3 ms
6,944 KB
testcase_41 AC 2 ms
6,940 KB
testcase_42 AC 2 ms
6,944 KB
testcase_43 AC 2 ms
6,940 KB
testcase_44 AC 2 ms
6,944 KB
testcase_45 AC 2 ms
6,940 KB
testcase_46 AC 2 ms
6,944 KB
testcase_47 AC 2 ms
6,944 KB
testcase_48 AC 2 ms
6,940 KB
testcase_49 AC 2 ms
6,940 KB
testcase_50 AC 2 ms
6,940 KB
testcase_51 AC 2 ms
6,940 KB
testcase_52 AC 2 ms
6,940 KB
testcase_53 AC 2 ms
6,940 KB
testcase_54 AC 2 ms
6,944 KB
testcase_55 AC 2 ms
6,940 KB
testcase_56 AC 2 ms
6,944 KB
testcase_57 AC 2 ms
6,940 KB
testcase_58 AC 2 ms
6,944 KB
testcase_59 AC 2 ms
6,944 KB
testcase_60 AC 2 ms
6,940 KB
testcase_61 AC 2 ms
6,944 KB
testcase_62 AC 2 ms
6,940 KB
testcase_63 AC 2 ms
6,940 KB
testcase_64 AC 2 ms
6,944 KB
testcase_65 AC 2 ms
6,944 KB
testcase_66 AC 2 ms
6,944 KB
testcase_67 AC 2 ms
6,944 KB
testcase_68 AC 2 ms
6,944 KB
testcase_69 AC 2 ms
6,944 KB
testcase_70 AC 2 ms
6,944 KB
testcase_71 AC 2 ms
6,944 KB
testcase_72 AC 2 ms
6,944 KB
testcase_73 AC 2 ms
6,944 KB
testcase_74 AC 2 ms
6,944 KB
testcase_75 AC 2 ms
6,940 KB
testcase_76 AC 2 ms
6,944 KB
testcase_77 AC 3 ms
6,940 KB
testcase_78 AC 2 ms
6,944 KB
testcase_79 AC 2 ms
6,940 KB
testcase_80 AC 2 ms
6,940 KB
testcase_81 AC 2 ms
6,940 KB
testcase_82 AC 2 ms
6,944 KB
testcase_83 AC 2 ms
6,948 KB
testcase_84 AC 2 ms
6,944 KB
testcase_85 AC 2 ms
6,940 KB
testcase_86 AC 2 ms
6,940 KB
testcase_87 AC 2 ms
6,944 KB
testcase_88 AC 2 ms
6,940 KB
testcase_89 AC 2 ms
6,944 KB
testcase_90 AC 2 ms
6,944 KB
testcase_91 AC 2 ms
6,944 KB
testcase_92 AC 2 ms
6,944 KB
testcase_93 AC 2 ms
6,940 KB
testcase_94 AC 2 ms
6,940 KB
testcase_95 AC 2 ms
6,944 KB
testcase_96 AC 2 ms
6,940 KB
testcase_97 AC 2 ms
6,940 KB
testcase_98 AC 2 ms
6,940 KB
testcase_99 AC 2 ms
6,944 KB
testcase_100 AC 2 ms
6,940 KB
testcase_101 AC 2 ms
6,940 KB
testcase_102 AC 2 ms
6,940 KB
testcase_103 AC 2 ms
6,940 KB
権限があれば一括ダウンロードができます

ソースコード

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