結果

問題 No.226 0-1パズル
ユーザー K UK U
提出日時 2023-10-03 19:56:16
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 2 ms / 5,000 ms
コード長 2,555 bytes
コンパイル時間 4,608 ms
コンパイル使用メモリ 265,032 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-10-04 12:09:12
合計ジャッジ時間 5,294 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <bits/stdc++.h>
#include <atcoder/all>
using namespace atcoder;
#ifdef LOCAL
#include <debug.h>
#define dbg(...) debug::dbg(#__VA_ARGS__, __VA_ARGS__)
#else
#define dbg(...) void(0)
#endif
using namespace std;

// #define int long long

#define rep(i, a, b) for(int i=static_cast<int>(a), i##_end__=static_cast<int>(b); i < i##_end__; i++)
#define rep_r(i, a, b) for(int i=static_cast<int>(a), i##_end__=static_cast<int>(b); i >= i##_end__; i--)
#define fore(i, a) for(auto& i: a)
#define all(x) std::begin(x), std::end(x)

using ll = long long; // __int128;
using ull = unsigned long long;

template<class C> int siz(const C& c) { return static_cast<int>(c.size()); }
template<class T, size_t N> constexpr int siz(const T (&)[N]) { return static_cast<int>(N); }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
template<class T> constexpr T pow2(T x){ return x * x; }
template<class T, class S> constexpr T divceil(T x, S div) { return (x % div == 0) ? x / div : (x >= 0) ? (x / div) + 1 : -((-x) / div); }
template<class T, class S> constexpr T divfloor(T x, S div){ return (x % div == 0) ? x / div : (x >= 0) ? (x / div) : -((-x) / div) - 1; }
constexpr long long INF = 1LL << 60; // 1.15e18
constexpr int MOD = (int)1e9 + 7;

void _main() {
    using mint = modint1000000007;

    int H, W;
    cin >> H >> W;
    vector<vector<char>> S1(H, vector<char>(W)), S2(W, vector<char>(H));
    rep(y, 0, H) rep(x, 0, W){
        char c;
        cin >> c;
        S1[y][x] = S2[x][y] = c;
    }

    auto func = [](int h, int w, vector<vector<char>>& s) -> pair<mint, int> {
        mint cnt = 1;
        vector<bool> chkr(2, true); // 市松模様か?
        rep(x, 0, w){
            vector<bool> pos(2, true); // 無矛盾か?
            rep(y, 0, h){
                if(s[y][x] == '0') pos[y % 2] = false;
                if(s[y][x] == '1') pos[(y + 1) % 2] = false;
            }
            if(!pos[0]) chkr[x % 2] = false;
            if(!pos[1]) chkr[(x + 1) % 2] = false;

            cnt *= (int)pos[0] + pos[1];
        }
        return {cnt, (int)chkr[0] + chkr[1]};
    };

    auto [cnt1, chkr1] = func(H, W, S1);
    auto [cnt2, chkr2] = func(W, H, S2);
    assert(chkr1 == chkr2);

    cout << (cnt1 + cnt2 - chkr1).val() << endl;
}

signed main() { 
    cin.tie(nullptr); ios::sync_with_stdio(false);
    cout << fixed << setprecision(15); cerr << fixed << setprecision(15);
    _main();
}
0