結果

問題 No.1056 2D Lamps
ユーザー hitonanodehitonanode
提出日時 2020-05-17 17:02:30
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 208 ms / 3,000 ms
コード長 5,522 bytes
コンパイル時間 2,490 ms
コンパイル使用メモリ 214,268 KB
実行使用メモリ 15,224 KB
最終ジャッジ日時 2024-09-25 09:52:22
合計ジャッジ時間 6,580 ms
ジャッジサーバーID
(参考情報)
judge3 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,248 KB
testcase_01 AC 2 ms
5,376 KB
testcase_02 AC 2 ms
5,376 KB
testcase_03 AC 189 ms
14,968 KB
testcase_04 AC 190 ms
15,096 KB
testcase_05 AC 195 ms
15,096 KB
testcase_06 AC 190 ms
15,096 KB
testcase_07 AC 194 ms
14,964 KB
testcase_08 AC 200 ms
15,096 KB
testcase_09 AC 104 ms
15,224 KB
testcase_10 AC 208 ms
15,088 KB
testcase_11 AC 187 ms
15,092 KB
testcase_12 AC 189 ms
15,092 KB
testcase_13 AC 2 ms
5,376 KB
testcase_14 AC 11 ms
5,376 KB
testcase_15 AC 8 ms
5,376 KB
testcase_16 AC 5 ms
5,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
using lint = long long int;
using pint = pair<int, int>;
using plint = pair<lint, lint>;
struct fast_ios { fast_ios(){ cin.tie(0); ios::sync_with_stdio(false); cout << fixed << setprecision(20); }; } fast_ios_;
#define ALL(x) (x).begin(), (x).end()
#define FOR(i, begin, end) for(int i=(begin),i##_end_=(end);i<i##_end_;i++)
#define IFOR(i, begin, end) for(int i=(end)-1,i##_begin_=(begin);i>=i##_begin_;i--)
#define REP(i, n) FOR(i,0,n)
#define IREP(i, n) IFOR(i,0,n)
template<typename T> void ndarray(vector<T> &vec, int len) { vec.resize(len); }
template<typename T, typename... Args> void ndarray(vector<T> &vec, int len, Args... args) { vec.resize(len); for (auto &v : vec) ndarray(v, args...); }
template<typename T> bool chmax(T &m, const T q) { if (m < q) {m = q; return true;} else return false; }
template<typename T> bool chmin(T &m, const T q) { if (m > q) {m = q; return true;} else return false; }
template<typename T1, typename T2> pair<T1, T2> operator+(const pair<T1, T2> &l, const pair<T1, T2> &r) { return make_pair(l.first + r.first, l.second + r.second); }
template<typename T1, typename T2> pair<T1, T2> operator-(const pair<T1, T2> &l, const pair<T1, T2> &r) { return make_pair(l.first - r.first, l.second - r.second); }
template<typename T> istream &operator>>(istream &is, vector<T> &vec){ for (auto &v : vec) is >> v; return is; }
template<typename T> ostream &operator<<(ostream &os, const vector<T> &vec){ os << "["; for (auto v : vec) os << v << ","; os << "]"; return os; }
template<typename T> ostream &operator<<(ostream &os, const deque<T> &vec){ os << "deq["; for (auto v : vec) os << v << ","; os << "]"; return os; }
template<typename T> ostream &operator<<(ostream &os, const set<T> &vec){ os << "{"; for (auto v : vec) os << v << ","; os << "}"; return os; }
template<typename T> ostream &operator<<(ostream &os, const unordered_set<T> &vec){ os << "{"; for (auto v : vec) os << v << ","; os << "}"; return os; }
template<typename T> ostream &operator<<(ostream &os, const multiset<T> &vec){ os << "{"; for (auto v : vec) os << v << ","; os << "}"; return os; }
template<typename T> ostream &operator<<(ostream &os, const unordered_multiset<T> &vec){ os << "{"; for (auto v : vec) os << v << ","; os << "}"; return os; }
template<typename T1, typename T2> ostream &operator<<(ostream &os, const pair<T1, T2> &pa){ os << "(" << pa.first << "," << pa.second << ")"; return os; }
template<typename TK, typename TV> ostream &operator<<(ostream &os, const map<TK, TV> &mp){ os << "{"; for (auto v : mp) os << v.first << "=>" << v.second << ","; os << "}"; return os; }
template<typename TK, typename TV> ostream &operator<<(ostream &os, const unordered_map<TK, TV> &mp){ os << "{"; for (auto v : mp) os << v.first << "=>" << v.second << ","; os << "}"; return os; }
#define dbg(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ") " << __FILE__ << endl;
/*
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/tag_and_trait.hpp>
using namespace __gnu_pbds; // find_by_order(), order_of_key()
template<typename TK> using pbds_set = tree<TK, null_type, less<TK>, rb_tree_tag, tree_order_statistics_node_update>;
template<typename TK, typename TV> using pbds_map = tree<TK, TV, less<TK>, rb_tree_tag, tree_order_statistics_node_update>;
*/

constexpr int Wmax = 200 * 200;
using BS = bitset<Wmax>;
std::vector<std::bitset<Wmax>> gauss_jordan(int W, std::vector<std::bitset<Wmax>> mtr)
{
    int H = mtr.size(), c = 0;
    for (int h = 0; h < H; h++, c++)
    {
        if (c == W) break;
        int piv = -1;
        for (int j = h; j < H; j++) if (mtr[j][c]) {
                piv = j; break;
        }
        if (piv == -1) { h--; continue; }
        std::swap(mtr[piv], mtr[h]);
        for (int hh = 0; hh < H; hh++) {
            if (hh != h and mtr[hh][c]) mtr[hh] ^= mtr[h];
        }
    }
    return mtr;
}

int rank_gauss_jordan(int W, const std::vector<std::bitset<Wmax>> &mtr) // Rank of Gauss-Jordan eliminated matrix
{
    for (int h = (int)mtr.size() - 1; h >= 0; h--) {
        if (mtr[h]._Find_first() < W) return h + 1;
    }
    return 0;
}

int main()
{
    int N, M;
    cin >> N >> M;
    vector<BS> basis;
    REP(i, N)
    {
        BS bs1, bs2;
        REP(j, N) bs1[i * N + j] = 1;
        REP(j, N) bs2[j * N + i] = 1;
        basis.push_back(bs1);
        basis.push_back(bs2);
    }
    REP(s, N * 2 - 1)
    {
        BS b;
        REP(i, N)
        {
            int j = s - i;
            if (j >= 0 and j < N)
            {
                b[i * N + j] = 1;
            }
        }
        basis.push_back(b);
    }
    FOR(d, -N + 1, N)
    {
        BS b;
        REP(i, N)
        {
            int j = i - d;
            if (j >= 0 and j < N)
            {
                b[i * N + j] = 1;
            }
        }
        basis.push_back(b);
    }
    basis = gauss_jordan(N * N, basis);

    vector<int> O;
    for (auto &b : basis) O.emplace_back(b._Find_first());

    vector<BS> hyojun;
    REP(i, M)
    {
        vector<string> A(N);
        cin >> A;
        BS b;
        REP(i, N) REP(j, N) if (A[i][j] == '#') b[i * N + j] = 1;
        REP(i, basis.size()) if (O[i] >= 0 and b[O[i]])
        {
            b ^= basis[i];
        }
        hyojun.emplace_back(b);
    }
    REP(i, M - 1)
    {
        FOR(j, i + 1, M)
        {
            if (hyojun[i] == hyojun[j]) printf("1");
            else printf("0");
        }
        puts("");
    }
}
0