結果

問題 No.226 0-1パズル
ユーザー kimiyuki
提出日時 2017-01-10 18:40:57
言語 C++14
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 3 ms / 5,000 ms
コード長 1,625 bytes
コンパイル時間 644 ms
コンパイル使用メモリ 71,632 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-07-26 14:24:04
合計ジャッジ時間 1,415 ms
ジャッジサーバーID
(参考情報)
judge5 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 22
権限があれば一括ダウンロードができます

ソースコード

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