結果
問題 | No.226 0-1パズル |
ユーザー |
![]() |
提出日時 | 2015-05-30 00:51:50 |
言語 | C++11 (gcc 13.3.0) |
結果 |
AC
|
実行時間 | 2 ms / 5,000 ms |
コード長 | 2,486 bytes |
コンパイル時間 | 892 ms |
コンパイル使用メモリ | 59,692 KB |
実行使用メモリ | 5,376 KB |
最終ジャッジ日時 | 2024-07-26 14:22:57 |
合計ジャッジ時間 | 1,735 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 22 |
ソースコード
#include <iostream>#include <string>#include <vector>using namespace std;#define COUT(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << endl#define MAXW 110#define MAXH 110const long long MOD = 1000000007;int H, W;string str[MAXH];bool canZero[MAXW], canIchi[MAXW]; // can put 0/1 in (0, i) ?bool canZeroIchi[MAXH], canIchiZero[MAXH];int main() {while (cin >> H >> W) {for (int i = 0; i < H; ++i) cin >> str[i];// the first row is neither 010101010101... nor 10101010...long long res1 = 1;for (int i = 0; i < MAXW; ++i) canZero[i] = canIchi[i] = true;for (int i = 0; i < W; ++i) {for (int j = 0; j < H; ++j) {if (str[j][i] == '0') {if (j & 1) canZero[i] = false;else canIchi[i] = false;}else if (str[j][i] == '1') {if (j & 1) canIchi[i] = false;else canZero[i] = false;}}int con = 0;if (canZero[i]) ++con;if (canIchi[i]) ++con;(res1 *= con) %= MOD;}bool canStartZero = true, canStartIchi = true;for (int i = 0; i < W; ++i) {if (i & 1) {if (!canZero[i]) canStartIchi = false;if (!canIchi[i]) canStartZero = false;}else {if (!canZero[i]) canStartZero = false;if (!canIchi[i]) canStartIchi = false;}}if (canStartZero) --res1;if (canStartIchi) --res1;// the first row is 010101010101... or 10101010...long long res2 = 1;for (int i = 0; i < MAXH; ++i) canZeroIchi[i] = canIchiZero[i] = true;for (int i = 0; i < H; ++i) {for (int j = 0; j < W; ++j) {if (str[i][j] == '0') {if (j & 1) canZeroIchi[i] = false;else canIchiZero[i] = false;}else if (str[i][j] == '1') {if (j & 1) canIchiZero[i] = false;else canZeroIchi[i] = false;}}int con = 0;if (canZeroIchi[i]) ++con;if (canIchiZero[i]) ++con;(res2 *= con) %= MOD;}long long res = (res1 + res2) % MOD;cout << res << endl;}}