結果

問題 No.226 0-1パズル
ユーザー kimiyukikimiyuki
提出日時 2017-01-10 18:40:57
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 2 ms / 5,000 ms
コード長 1,625 bytes
コンパイル時間 612 ms
コンパイル使用メモリ 72,224 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-10-04 12:07:39
合計ジャッジ時間 1,582 ms
ジャッジサーバーID
(参考情報)
judge14 / judge13
このコードへのチャレンジ(β)

テストケース

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

ソースコード

diff #

#include <iostream>
#include <vector>
#define repeat(i,n) for (int i = 0; (i) < int(n); ++(i))
using ll = long long;
using namespace std;
const int mod = 1e9+7;
int count1(vector<string> const & f) {
    int h = f.size();
    int w = f.front().size();
    ll acc = 1;
    repeat (x,w) {
        int sats = 0;
        repeat (p,2) {
            bool sat = true;
            repeat (y,h) {
                int clr = (x % 2) ^ p ^ (y % 2);
                if (f[y][x] != '?' and f[y][x] - '0' != clr) {
                    sat = false;
                    break;
                }
            }
            sats += sat;
        }
        acc = acc * sats % mod;
        if (not acc) break;
    }
    return acc;
}
int count2(vector<string> const & f) {
    int h = f.size();
    int w = f.front().size();
    int acc = 0;
    repeat (p,2) {
        bool sat = true;
        repeat (y,h) {
            repeat (x,w) {
                int clr = p ^ (x % 2) ^ (y % 2);
                if (f[y][x] != '?' and f[y][x] - '0' != clr) {
                    sat = false;
                    break;
                }
            }
        }
        acc += sat;
    }
    return acc;
}
vector<string> tr(vector<string> const & f) {
    int h = f.size();
    int w = f.front().size();
    vector<string> g(w, string(h, '\0'));
    repeat (x,w) repeat (y,h) g[x][y] = f[y][x];
    return g;
}
int main() {
    int h, w; cin >> h >> w;
    vector<string> f(h); repeat (y,h) cin >> f[y];
    ll ans = 0;
    ans += count1(f);
    ans += count1(tr(f));
    ans -= count2(f);
    ans = (ans + mod) % mod;
    cout << ans << endl;
    return 0;
}
0