結果

問題 No.226 0-1パズル
ユーザー 303Yuyu303Yuyu
提出日時 2021-02-13 15:43:56
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 3,628 bytes
コンパイル時間 1,489 ms
コンパイル使用メモリ 170,572 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-09-28 00:11:46
合計ジャッジ時間 2,531 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <bits/stdc++.h>
//#include <atcoder/all>

using namespace std;
//using namespace atcoder;

using ll = long long;
using vll = vector<ll>;
using vvll = vector<vll>;
using pll = pair<ll, ll>;
using vpll = vector<pll>;
using ld = long double;
using vld = vector<ld>;
using vb = vector<bool>;

#define rep(i, n) for (ll i = 0; i < (n); i++)
#ifdef LOCAL
#define dbg(x) cerr << __LINE__ << " : " << #x << " = " << (x) << endl
#else
#define dbg(x) true
#endif

template <class T> bool chmin(T& a, T b) {
    if(a > b) { a = b; return true; }
    else return false;
}

template <class T> bool chmax(T& a, T b) {
    if(a < b) { a = b; return true; }
    else return false;
}

template <class T> ostream& operator<<(ostream& s, const vector<T>& a) {
    for(auto i : a) s << i << ' ';
    return s;
}

constexpr int INF = 1 << 30;
constexpr ll INFL = 1LL << 60;
constexpr ld EPS = 1e-12;
ld PI = acos(-1.0);

struct mint {
    static const long long mod = 1000000007;
    long long x;
    mint(long long x = 0) : x((x % mod + mod) % mod) {}
    mint operator-() const { return mint(-x);}
    mint& operator+=(const mint& a) {if ((x += a.x) >= mod) x -= mod; return *this;}
    mint& operator-=(const mint& a) {if ((x += mod - a.x) >= mod) x -= mod; return *this;}
    mint& operator*=(const mint& a) {(x *= a.x) %= mod; return *this;}

    friend const mint operator+(const mint& a, const mint& b) { mint ret = a; return ret += b; }
    friend const mint operator-(const mint& a, const mint& b) { mint ret = a; return ret -= b; }
    friend const mint operator*(const mint& a, const mint& b) { mint ret = a; return ret *= b; }
    friend ostream& operator<<(ostream& s, const mint& a) { return s << a.x; }

    mint pow(long long t) const {
        if (!t) return 1;
        mint a = pow(t >> 1);
        a *= a;
        if (t & 1) a *= *this;
        return a;
    }

    // for prime mod
    mint inv() const { return pow(mod - 2);}
    mint& operator/=(const mint a) { return (*this) *= a.inv();}
    friend const mint operator/(const mint& a, const mint& b) { mint ret = a; return ret /= b; }
};

void solve() {
    ll h, w;
    cin >> h >> w;
    vector<string> s(h);
    rep(i, h) cin >> s[i];

    // 0101..又は1010..のパターン
    mint ans = 1;
    rep(i, h) {
        vll p(2, -1);   // 0又は1のインデックスの2の剰余
        rep(j, w) {
            char c = s[i][j];
            if(c == '?') continue;
            else if(p[c-'0'] == -1) p[c-'0'] = j%2;
            else if(p[c-'0'] != j%2) {  // 0101..のパターンはない
                ans = 0;
                break;
            }
        }
        if(ans.x == 0) break;
        if(p[0] == -1 && p[1] == -1) ans *= 2;
    }

    // 0101..以外のパターン
    mint ans2 = 1;
    vll a(w, -1);
    rep(i, h) {
        rep(j, w) {
            char c = s[i][j];
            if(c == '?') continue;
            if(a[j] == -1) a[j] = (c-'0'+i)%2;
            else if(a[j] != (c-'0'+i)%2) {  // 0101..以外のパターンはない
                ans2 = 0;
                break;
            }
        }
        if(ans2.x == 0) break;
    }
    rep(i, w) if(a[i] == -1) ans2 *= 2;
    if(ans2.x != 0) {
        bool f = true;
        rep(i, w) if(a[i] != -1 && a[i] != i%2) f = false;  // 0101..でない
        if(f) ans2 -= 1;
        f = true;
        rep(i, w) if(a[i] != -1 && a[i] == i%2) f = false;  // 1010..でない
        if(f) ans2 -= 1;
    }

    cout << ans + ans2 << endl;
    return;
}

int main() {
    std::cin.tie(nullptr);
    std::ios_base::sync_with_stdio(false);
    cout << fixed << setprecision(15);
    solve();
}
0