結果

問題 No.226 0-1パズル
ユーザー pekempeypekempey
提出日時 2019-03-20 18:35:33
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 3 ms / 5,000 ms
コード長 1,605 bytes
コンパイル時間 648 ms
コンパイル使用メモリ 73,512 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-10-04 12:07:48
合計ジャッジ時間 1,589 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <iostream>
#include <algorithm>
#include <vector>
#include <string>

using namespace std;

#define REP(i, n) for (int i = 0; i < (n); i++)

const int MOD = 1e9 + 7;

struct mint {
    int n;
    mint(int n_ = 0) : n(n_) {}
};

mint operator+(mint a, mint b) { a.n += b.n; if (a.n >= MOD) a.n -= MOD; return a; }
mint operator-(mint a, mint b) { a.n -= b.n; if (a.n < 0) a.n += MOD; return a; }
mint operator*(mint a, mint b) { return (long long)a.n * b.n % MOD; }
mint &operator+=(mint &a, mint b) { return a = a + b; }
mint &operator-=(mint &a, mint b) { return a = a - b; }
mint &operator*=(mint &a, mint b) { return a = a * b; }

mint mpow(mint a, int b) {
  mint ans = 1;
  REP(i, b) ans *= a;
  return ans;
}

int main() {
  int H, W;
  cin >> H >> W;
  vector<string> S(H);
  REP(i, H) cin >> S[i];
  mint ans = 1;
  REP(i, H) {
    int x = 1;
    int y = 1;
    REP(j, W) {
      if (S[i][j] == '?') continue;
      x &= S[i][j] - '0' == (j + 0) % 2;
      y &= S[i][j] - '0' == (j + 1) % 2;
    }
    ans *= x + y;
  }
  bool can = true;
  REP(i, H) REP(j, W) REP(k, H) {
    if (S[k][j] == '?' || S[i][j] == '?') continue;
    if ((S[k][j] + S[i][j] + k + i) % 2 != 0) {
      can = false;
    }
  }
  if (can) {
    int c = 0;
    REP(j, W) {
      bool all = true;
      REP(i, H) all &= S[i][j] == '?';
      c += all;
    }
    ans += mpow(2, c);
    int x = 1;
    int y = 1;
    REP(i, H) REP(j, W) {
      if (S[i][j] == '?') continue;
      x &= S[i][j] - '0' == (i + j + 0) % 2;
      y &= S[i][j] - '0' == (i + j + 1) % 2;
    }
    ans -= x + y;
  }
  cout << ans.n << '\n';
}
0