結果

問題 No.2824 Lights Up! (Grid Edition)
ユーザー 👑 AngrySadEightAngrySadEight
提出日時 2024-07-13 20:13:24
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 931 ms / 2,000 ms
コード長 5,252 bytes
コンパイル時間 5,441 ms
コンパイル使用メモリ 230,352 KB
実行使用メモリ 30,940 KB
最終ジャッジ日時 2024-07-26 20:31:49
合計ジャッジ時間 17,846 ms
ジャッジサーバーID
(参考情報)
judge1 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,816 KB
testcase_01 AC 2 ms
6,816 KB
testcase_02 AC 2 ms
6,940 KB
testcase_03 AC 2 ms
6,940 KB
testcase_04 AC 28 ms
6,940 KB
testcase_05 AC 47 ms
13,440 KB
testcase_06 AC 29 ms
6,944 KB
testcase_07 AC 725 ms
22,028 KB
testcase_08 AC 29 ms
6,944 KB
testcase_09 AC 48 ms
13,312 KB
testcase_10 AC 29 ms
6,944 KB
testcase_11 AC 724 ms
22,104 KB
testcase_12 AC 28 ms
6,940 KB
testcase_13 AC 736 ms
21,708 KB
testcase_14 AC 28 ms
6,944 KB
testcase_15 AC 909 ms
29,820 KB
testcase_16 AC 26 ms
6,940 KB
testcase_17 AC 742 ms
22,536 KB
testcase_18 AC 28 ms
6,944 KB
testcase_19 AC 931 ms
30,940 KB
testcase_20 AC 9 ms
6,940 KB
testcase_21 AC 33 ms
9,600 KB
testcase_22 AC 2 ms
6,944 KB
testcase_23 AC 617 ms
19,744 KB
testcase_24 AC 2 ms
6,944 KB
testcase_25 AC 28 ms
6,940 KB
testcase_26 AC 11 ms
6,944 KB
testcase_27 AC 515 ms
22,012 KB
testcase_28 AC 3 ms
6,940 KB
testcase_29 AC 62 ms
6,944 KB
testcase_30 AC 3 ms
6,940 KB
testcase_31 AC 2 ms
6,944 KB
testcase_32 AC 5 ms
6,944 KB
testcase_33 AC 2 ms
6,940 KB
testcase_34 AC 2 ms
6,944 KB
testcase_35 AC 2 ms
6,940 KB
testcase_36 AC 2 ms
6,944 KB
testcase_37 AC 3 ms
6,940 KB
testcase_38 AC 2 ms
6,944 KB
testcase_39 AC 2 ms
6,940 KB
testcase_40 AC 2 ms
6,940 KB
testcase_41 AC 2 ms
6,944 KB
testcase_42 AC 2 ms
6,940 KB
testcase_43 AC 2 ms
6,944 KB
testcase_44 AC 2 ms
6,944 KB
testcase_45 AC 2 ms
6,944 KB
testcase_46 AC 2 ms
6,944 KB
testcase_47 AC 2 ms
6,940 KB
testcase_48 AC 2 ms
6,944 KB
testcase_49 AC 2 ms
6,944 KB
testcase_50 AC 2 ms
6,944 KB
testcase_51 AC 1 ms
6,944 KB
testcase_52 AC 2 ms
6,944 KB
testcase_53 AC 2 ms
6,940 KB
testcase_54 AC 2 ms
6,940 KB
testcase_55 AC 2 ms
6,944 KB
testcase_56 AC 2 ms
6,944 KB
testcase_57 AC 2 ms
6,944 KB
testcase_58 AC 2 ms
6,940 KB
testcase_59 AC 2 ms
6,940 KB
testcase_60 AC 2 ms
6,940 KB
testcase_61 AC 2 ms
6,940 KB
testcase_62 AC 2 ms
6,940 KB
testcase_63 AC 2 ms
6,944 KB
testcase_64 AC 2 ms
6,940 KB
testcase_65 AC 2 ms
6,944 KB
testcase_66 AC 2 ms
6,940 KB
testcase_67 AC 2 ms
6,940 KB
testcase_68 AC 2 ms
6,944 KB
testcase_69 AC 2 ms
6,940 KB
testcase_70 AC 2 ms
6,944 KB
testcase_71 AC 2 ms
6,940 KB
testcase_72 AC 2 ms
6,944 KB
testcase_73 AC 2 ms
6,940 KB
testcase_74 AC 1 ms
6,944 KB
testcase_75 AC 2 ms
6,944 KB
testcase_76 AC 2 ms
6,940 KB
testcase_77 AC 2 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,944 KB
testcase_81 AC 2 ms
6,940 KB
testcase_82 AC 1 ms
6,940 KB
testcase_83 AC 2 ms
6,940 KB
testcase_84 AC 2 ms
6,940 KB
testcase_85 AC 2 ms
6,944 KB
testcase_86 AC 2 ms
6,940 KB
testcase_87 AC 2 ms
6,944 KB
testcase_88 AC 2 ms
6,944 KB
testcase_89 AC 2 ms
6,944 KB
testcase_90 AC 2 ms
6,940 KB
testcase_91 AC 2 ms
6,940 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,944 KB
testcase_97 AC 1 ms
6,944 KB
testcase_98 AC 2 ms
6,944 KB
testcase_99 AC 2 ms
6,940 KB
testcase_100 AC 2 ms
6,944 KB
testcase_101 AC 2 ms
6,940 KB
testcase_102 AC 2 ms
6,940 KB
testcase_103 AC 2 ms
6,944 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#pragma GCC target("avx2")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")

#include <algorithm>
#include <atcoder/all>
#include <bitset>
#include <cassert>
#include <cmath>
#include <ctime>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>
using namespace std;
using namespace atcoder;
typedef long long ll;
#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--)
#define repk(i, k, n) for (int i = k; i < (int)(n); i++)
#define all(v) v.begin(), v.end()
#define mod1 1000000007
#define mod2 998244353
#define mod3 100000007
#define vi vector<int>
#define vs vector<string>
#define vc vector<char>
#define vl vector<ll>
#define vb vector<bool>
#define vvi vector<vector<int>>
#define vvc vector<vector<char>>
#define vvl vector<vector<ll>>
#define vvb vector<vector<bool>>
#define vvvi vector<vector<vector<int>>>
#define vvvl vector<vector<vector<ll>>>
#define pii pair<int, int>
#define pil pair<int, ll>
#define pli pair<ll, int>
#define pll pair<ll, ll>
#define vpii vector<pair<int, int>>
#define vpll vector<pair<ll, ll>>
#define vvpii vector<vector<pair<int, int>>>
#define vvpll vector<vector<pair<ll, ll>>>

using mint = modint998244353;

template <typename T>
void debug(T e) {
    cerr << e << endl;
}

template <typename T>
void debug(vector<T> &v) {
    rep(i, v.size()) { cerr << v[i] << " "; }
    cerr << endl;
}

template <typename T>
void debug(vector<vector<T>> &v) {
    rep(i, v.size()) {
        rep(j, v[i].size()) { cerr << v[i][j] << " "; }
        cerr << endl;
    }
}

template <typename T>
void debug(vector<pair<T, T>> &v) {
    rep(i, v.size()) { cerr << v[i].first << " " << v[i].second << endl; }
}

template <typename T>
void debug(set<T> &st) {
    for (auto itr = st.begin(); itr != st.end(); itr++) {
        cerr << *itr << " ";
    }
    cerr << endl;
}

template <typename T>
void debug(multiset<T> &ms) {
    for (auto itr = ms.begin(); itr != ms.end(); itr++) {
        cerr << *itr << " ";
    }
    cerr << endl;
}

template <typename T>
void debug(map<T, T> &mp) {
    for (auto itr = mp.begin(); itr != mp.end(); itr++) {
        cerr << itr->first << " " << itr->second << endl;
    }
}

void debug_out() { cerr << endl; }

template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
    cerr << H << " ";
    debug_out(T...);
}

int main() {
    ll N;
    cin >> N;
    vector<string> S(N);
    for (ll i = 0; i < N; i++) {
        cin >> S[i];
    }
    vector<ll> rows(N, 0);
    vector<ll> cols(N, 0);
    for (ll i = 0; i < N; i++) {
        for (ll j = 0; j < N; j++) {
            if (S[i][j] == '#') {
                rows[i]++;
                cols[j]++;
            }
        }
    }
    for (ll i = 0; i < N; i++) {
        if (rows[i] % 2 == 1) {
            cout << -1 << endl;
            return 0;
        }
        if (cols[i] % 2 == 1) {
            cout << -1 << endl;
            return 0;
        }
    }
    vector<vector<ll>> sums(N + 1, vector<ll>(N + 1, 0));
    for (ll i = 0; i < N; i++) {
        for (ll j = 0; j < N; j++) {
            if (S[i][j] == '#') {
                sums[i + 1][j + 1] += 1;
            }
            sums[i + 1][j + 1] +=
                (sums[i + 1][j] + sums[i][j + 1] - sums[i][j] + 2) % 2;
            sums[i + 1][j + 1] %= 2;
        }
    }
    vector<ll> rows2(N - 1);
    vector<ll> cols2(N - 1);
    for (ll i = 1; i < N; i++) {
        for (ll j = 1; j < N; j++) {
            if (sums[i][j] == 1) {
                rows2[i - 1] += 1;
                cols2[j - 1] += 1;
                rows2[i - 1] %= 2;
                cols2[j - 1] %= 2;
            }
        }
    }
    if (N % 2 == 1) {
        vector<pll> ans(0);
        for (ll i = 1; i < N; i++) {
            for (ll j = 1; j < N; j++) {
                if ((rows2[i - 1] + cols2[j - 1] + 2 - sums[i][j]) % 2 == 1) {
                    ans.push_back(pll(i, j));
                }
            }
        }
        ll len = ans.size();
        cout << len << endl;
        for (ll i = 0; i < len; i++) {
            cout << ans[i].first << " " << ans[i].second << endl;
        }
    } else {
        bool all_odd = true;
        bool all_even = true;
        for (ll i = 0; i < N - 1; i++) {
            if (rows2[i] % 2 == 1 || cols2[i] % 2 == 1) {
                all_even = false;
            }
            if (rows2[i] % 2 == 0 || cols2[i] % 2 == 0) {
                all_odd = false;
            }
        }
        if (!all_odd && !all_even) {
            cout << -1 << endl;
        } else {
            vector<pll> ans(0);
            for (ll i = 1; i < N; i++) {
                for (ll j = 1; j < N; j++) {
                    if (sums[i][j] == 1) {
                        ans.push_back(pll(i, j));
                    }
                }
            }
            ll len = ans.size();
            cout << len << endl;
            for (ll i = 0; i < len; i++) {
                cout << ans[i].first << " " << ans[i].second << endl;
            }
        }
    }
}
0