結果

問題 No.226 0-1パズル
ユーザー ctyl_0ctyl_0
提出日時 2015-11-13 05:13:28
言語 C++11
(gcc 11.4.0)
結果
RE  
実行時間 -
コード長 2,635 bytes
コンパイル時間 739 ms
コンパイル使用メモリ 93,912 KB
実行使用メモリ 4,480 KB
最終ジャッジ日時 2023-10-11 15:46:37
合計ジャッジ時間 2,693 ms
ジャッジサーバーID
(参考情報)
judge15 / judge14
このコードへのチャレンジ(β)

テストケース

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

ソースコード

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;

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

template <typename T>
inline 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;
            }
        }
        
        ret -= (is01 ? 1 : 0);
        ret -= (is10 ? 1 : 0);
        
    }
    
    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[i][0] && !dpr[i][1]) {
            ret01 *= 2;
            ret10 *= 2;
            ret01 %= mod;
            ret10 %= mod;
        }
        else if(dpr[i][0] && dpr[i][1]){
            ret01 = 0;
            ret10 = 0;
        }
    }
    
    ret = ret + ret01 + ret10;
    ret %= mod;
    output(ret, 0);
    
    
    
    return 0;
}
0