結果

問題 No.226 0-1パズル
ユーザー ctyl_0ctyl_0
提出日時 2015-11-13 05:33:33
言語 C++11
(gcc 11.4.0)
結果
WA  
(最新)
AC  
(最初)
実行時間 -
コード長 3,070 bytes
コンパイル時間 689 ms
コンパイル使用メモリ 92,500 KB
実行使用メモリ 4,500 KB
最終ジャッジ日時 2023-08-24 16:45:53
合計ジャッジ時間 1,596 ms
ジャッジサーバーID
(参考情報)
judge15 / judge14
このコードへのチャレンジ(β)

テストケース

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

ソースコード

diff #

#include <iostream>
#include <iomanip>
#include <vector>
#include <algorithm>
#include <numeric>
#include <functional>
#include <cmath>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <sstream>
#include <string>

#define repd(i,a,b) for (int i=(a);i<(b);i++)
#define rep(i,n) repd(i,0,n)
#define var auto
#define mod 1000000007
#define inf 2147483647
#define nil -1
typedef long long ll;

using namespace std;

int input(){
    int a;
    cin >> a;
    return a;
}

template <typename T>
void output(T a, int p) {
    if(p){
        cout << fixed << setprecision(p)  << a << "\n";
    }
    else{
        cout << a << "\n";
    }
}

// end of template

int main() {
    cin.tie(0);
    // source code
    
    int H = input();
    int W = input();
    
    vector<vector<int>> cell(H, vector<int> (W, -1));
    
    rep(i, H){
        rep(j, W){
            char c;
            cin >> c;
            if (c == '0') cell[i][j] = 0;
            if (c == '1') cell[i][j] = 1;
        }
    }
    
    // 0101010101... or ...11..., ...00...
    
    vector<int> dpc[2]; // judge if the cell of the first row must be 0 or 1
    rep(i, 2){
        dpc[i].resize(W, 0);
    }
    
    ll ret = 1;
    
    rep(i, H){
        rep(j, W){
            if (cell[i][j] != -1) {
                dpc[(i + cell[i][j]) % 2][j] = 1;
            }
        }
    }
    
    rep(i, W){
        if (!dpc[0][i] && !dpc[1][i]) {
            ret *= 2;
        }
        else if (dpc[0][i] && dpc[1][i]){
            ret = 0;
        }
        
        ret %= mod;
    }
    
    bool is01 = true;
    bool is10 = true;
    if (ret) {
        rep(i, W){
            if (dpc[(i + 1) % 2][i]) {
                is01 = false;
            }
            if (dpc[i % 2][i]) {
                is10 = false;
            }
        }
        if (is01) ret--;
        if (is10) ret--;
        
    }
    
    is01 = true;
    is10 = true;
    rep(i, W){
        if (i % 2 == 0) {
            if (cell[0][i] == 1) {
                is01 = false;
            }
            else if(cell[0][i] == 0){
                is10 = false;
            }
        }
        else{
            if (cell[0][i] == 1) {
                is10 = false;
            }
            else if(cell[0][i] == 0){
                is01 = false;
            }
        }
    }
    
    vector<int> dpr[2];
    
    rep(i, 2){
        dpr[i].resize(H, 0);
    }
    
    rep(i, H){
        rep(j, W){
            if (cell[i][j] != -1) {
                dpr[(j + cell[i][j]) % 2][i] = 1;
            }
        }
    }
    
    ll ret01 = (is01 && !dpr[1][0]) ? 1 : 0;
    ll ret10 = (is10 && !dpr[0][0]) ? 1 : 0;
    
    repd(i, 1, H){
        if (!dpr[0][i] && !dpr[1][i]) {
            ret01 *= 2;
            ret10 *= 2;
            ret01 %= mod;
            ret10 %= mod;
        }
        else if(dpr[0][i] && dpr[1][i]){
            ret01 = 0;
            ret10 = 0;
        }
    }
    
    ret = (ret ? ret + ret01 + ret10 : 0);
    ret += mod;
    ret %= mod;
    output(ret, 0);
    
    
    
    return 0;
}
0