結果
問題 | No.226 0-1パズル |
ユーザー |
![]() |
提出日時 | 2015-07-21 21:48:51 |
言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
結果 |
AC
|
実行時間 | 4 ms / 5,000 ms |
コード長 | 2,562 bytes |
コンパイル時間 | 707 ms |
コンパイル使用メモリ | 85,688 KB |
実行使用メモリ | 5,376 KB |
最終ジャッジ日時 | 2024-07-26 14:23:58 |
合計ジャッジ時間 | 1,409 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 22 |
ソースコード
#include<cstdio> #include<cstdlib> #include<cstring> #include<cmath> //#include<cctype> #include<climits> #include<iostream> #include<string> #include<vector> #include<map> //#include<list> #include<queue> #include<deque> #include<algorithm> //#include<numeric> #include<utility> #include<complex> //#include<memory> #include<functional> #include<cassert> #include<set> const int dx[] = {1, 0, -1, 0}; const int dy[] = {0, 1, 0, -1}; using namespace std; typedef long long ll; typedef vector<int> vi; typedef vector<ll> vll; typedef pair<int, int> pii; typedef complex<double> C; const int MAX = 111; const ll MOD = 1e9+7; int H, W; string board[MAX]; ll calc() { for (int i = 0; i < H; i++) { for (int j = 0; j < W; j++) { if (board[i][j] != '?') { for (int k = 0; k < H; k++) { const int diff = abs(i-k) % 2; int should = board[i][j] - '0'; if (diff == 1) should ^= 1; char c = (char)('0'+should); if (board[k][j] != '?' && board[k][j] != c) { return 0; } board[k][j] = c; } } } } //for (int i = 0; i < H; i++) cout << board[i] << endl; ll ans = 1; for (int i = 0; i < W; i++) { if (board[0][i] == '?') (ans *= 2) %= MOD; } return ans; } int main() { cin.tie(0); ios::sync_with_stdio(false); cin >> H >> W; for (int i = 0; i < H; i++) cin >> board[i]; ll ans = 1; for (int i = 0; i < H; i++) { // 101010的something int ok = 0; // 最初1, 最初0 でないと11 for (int j = 0; j < W; j++) { if (board[i][j] == '0') { if (j%2) ok |= 2; else ok |= 1; } if (board[i][j] == '1') { if (j%2) ok |= 1; else ok |= 2; } } int tmp = 2-__builtin_popcount(ok); ans *= tmp; ans %= MOD; } ll tmp = calc(); ans += tmp; ll cnt = 0; if (tmp != 0) { int ok = 0; // 最初1, 最初0 でないと11 for (int i = 0; i < W; i++) { if (board[0][i] == '0') { if (i%2) ok |= 2; else ok |= 1; } if (board[0][i] == '1') { if (i%2) ok |= 1; else ok |= 2; } cnt = 2-__builtin_popcount(ok); } } cout << (ans-cnt) % MOD << endl; return 0; }