結果
問題 |
No.226 0-1パズル
|
ユーザー |
![]() |
提出日時 | 2015-07-21 15:53:41 |
言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 2,187 bytes |
コンパイル時間 | 598 ms |
コンパイル使用メモリ | 85,112 KB |
実行使用メモリ | 6,948 KB |
最終ジャッジ日時 | 2024-07-08 11:33:12 |
合計ジャッジ時間 | 1,569 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 13 WA * 9 |
ソースコード
#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; ll cnt = 0; 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; if (i == 0) cnt = tmp; } // cout << ans << endl; cout << (ans + calc()-cnt) % MOD << endl; return 0; }