結果

問題 No.1056 2D Lamps
ユーザー kcvlexkcvlex
提出日時 2020-05-15 23:01:25
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
TLE  
実行時間 -
コード長 4,827 bytes
コンパイル時間 1,748 ms
コンパイル使用メモリ 158,860 KB
実行使用メモリ 8,696 KB
最終ジャッジ日時 2023-10-19 16:24:52
合計ジャッジ時間 6,884 ms
ジャッジサーバーID
(参考情報)
judge14 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 3 ms
4,368 KB
testcase_01 AC 4 ms
4,348 KB
testcase_02 AC 2 ms
4,348 KB
testcase_03 TLE -
testcase_04 -- -
testcase_05 -- -
testcase_06 -- -
testcase_07 -- -
testcase_08 -- -
testcase_09 -- -
testcase_10 -- -
testcase_11 -- -
testcase_12 -- -
testcase_13 -- -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <limits>
#include <initializer_list>
#include <utility>
#include <bitset>
#include <tuple>
#include <type_traits>
#include <functional>
#include <string>
#include <array>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <iterator>
#include <algorithm>
#include <complex>
#include <random>
#include <numeric>
#include <iostream>
#include <iomanip>
#include <sstream>
#include <regex>
#include <cassert>
#include <cstddef>
#include <variant>

// Yay!!
#define endl codeforces

// macros for iterator
#define ALL(v) std::begin(v), std::end(v)
#define ALLR(v) std::rbegin(v), std::rend(v)

// alias
using ll = std::int64_t;
using ull = std::uint64_t;
using pii = std::pair<int, int>;
using tii = std::tuple<int, int, int>;
using pll = std::pair<ll, ll>;
using tll = std::tuple<ll, ll, ll>;
template <typename T> using vec = std::vector<T>;
template <typename T> using vvec = vec<vec<T>>;

// variadic min/max
template <typename T> const T& var_min(const T &t) { return t; }
template <typename T> const T& var_max(const T &t) { return t; }
template <typename T, typename... Tail> const T& var_min(const T &t, const Tail&... tail) { return std::min(t, var_min(tail...)); }
template <typename T, typename... Tail> const T& var_max(const T &t, const Tail&... tail) { return std::max(t, var_max(tail...)); }

// variadic chmin/chmax
template <typename T, typename... Tail> void chmin(T &t, const Tail&... tail) { t = var_min(t, tail...); }
template <typename T, typename... Tail> void chmax(T &t, const Tail&... tail) { t = var_max(t, tail...); }

// multi demension array
template <typename T, std::size_t Head, std::size_t... Tail> struct multi_dim_array { using type = std::array<typename multi_dim_array<T, Tail...>::type, Head>; };
template <typename T, std::size_t Head> struct multi_dim_array<T, Head> { using type = std::array<T, Head>; };
template <typename T, std::size_t... Args> using mdarray = typename multi_dim_array<T, Args...>::type;

// fill container
template <typename T, typename F, typename... Args> 
void fill_seq(T &t, F f, Args... args) { if constexpr (std::is_invocable<F, Args...>::value) { t = f(args...); } else { for (ssize_t i = 0; i < t.size(); i++) fill_seq(t[i], f, args..., i); } }

// make multi dimension vector
template <typename T> vec<T> make_v(ssize_t sz) { return vec<T>(sz); }
template <typename T, typename... Tail> auto make_v(ssize_t hs, Tail&&... ts) { auto v = std::move(make_v<T>(std::forward<Tail>(ts)...)); return vec<decltype(v)>(hs, v); }

// init
namespace init__ { 
struct InitIO { InitIO() { std::cin.tie(nullptr); std::ios_base::sync_with_stdio(false); std::cout << std::fixed << std::setprecision(30); } } init_io; 
}


constexpr std::size_t SIZE = 200 * 200;
using bs_type = std::bitset<SIZE>;
using matrix_type = vec<bs_type>;

std::pair<matrix_type, ll> gauss_elim(matrix_type mat) {
    ll upper_row = 0;
    ll rank = 0;
    for (ll col = 0; col < SIZE && upper_row < mat.size(); col++) {
        ll row = -1;
        for (ll r = upper_row; r < mat.size(); r++) {
            if (mat[r].test(col)) {
                row = r;
                break;
            }
        }
        if (row == -1) continue;
        rank++;
        std::swap(mat[upper_row], mat[row]);
        for (ll r = 0; r < mat.size(); r++) {
            if (r == upper_row) continue;
            if (!mat[r].test(col)) continue;
            mat[r] ^= mat[upper_row];
        }
        upper_row++;
    }
    return std::make_pair(std::move(mat), rank);
}

int main() {
    ll n, m;
    std::cin >> n >> m;
    auto av = make_v<std::string>(m, n);
    for (auto &&vs : av) for (auto &&s : vs) std::cin >> s;
    vec<std::string> ans(m - 1);
    for (ll i = 0; i < m - 1; i++) ans[i] = std::string(m - i - 1, '0');
    matrix_type op_mat(2 * n + 2 * (2 * n - 1));
    for (ll i = 0; i < n; i++) for (ll j = 0; j < n; j++) {
        ll idx = i * n + j;
        op_mat[i].set(idx, 1);
        op_mat[j + n].set(idx, 1);
        ll k1 = i + j;
        op_mat[k1 + 2 * n].set(idx, 1);
        ll k2 = i - j;
        k2 += n - 1;
        op_mat[k2 + 2 * n + 2 * n - 1].set(idx, 1);
    }

    {
        auto [ tmp, rank ] = gauss_elim(op_mat);
        op_mat = std::move(tmp);
        op_mat.erase(op_mat.begin() + rank, op_mat.end());
    }


    for (ll i = 0; i < m; i++) for (ll j = i + 1; j < m; j++) {
        bs_type bs;
        for (ll r = 0; r < n; r++) for (ll c = 0; c < n; c++) if (av[i][r][c] != av[j][r][c]) bs.set(r * n + c, 1);
        auto cpy = op_mat;
        cpy.push_back(bs);
        auto [ ign, rank ] = gauss_elim(cpy);
        if (rank == op_mat.size()) ans[i][j - i - 1] = '1';
    }

    for (auto &&s : ans) std::cout << s << "\n";
    return 0;
}
0