#include #include #include using namespace std; typedef complex POS; const POS DIR[] = { POS(2,0),POS(1,0),POS(-1,0),POS(-2,0), POS(0,2),POS(0,1),POS(0,-1),POS(0,-2),POS(0,0) }; main() { int loop; while (cin >> loop && loop){ int table[4][4]; for (int y = 0; y < 4; ++y){ for (int x = 0; x < 4; ++x){ cin >> table[x][y]; } } bool is_zero = false; for (int x = 1; x <= 2; ++x){ for (int y = 1; y <= 2; ++y){ is_zero |= table[x][y]; } } if (is_zero){ cout << 0 << endl; continue; } typedef pair STATE; set open; open.insert(make_pair(5, 0x1111100110011111ULL)); //cout << "START" << endl; for (int day = 1; day < loop; ++day){ //cout << open.size() << " "; int table[4][4]; for (int y = 0; y < 4; ++y){ for (int x = 0; x < 4; ++x){ cin >> table[x][y]; } } set next; for (set::iterator it = open.begin(); it != open.end(); ++it){ //cout << it->first << " " << it->second << endl; POS p(it->first % 4, it->first / 4); //unsigned long long land = it->second + 0x1111111111111111ULL; for (int dir = 0; dir < 9; ++dir){ unsigned long long land = it->second + 0x1111111111111111ULL; POS pp = p + DIR[dir]; if (pp.real() < 0 || pp.imag() < 0 || 3 <= pp.real() || 3 <= pp.imag()){ continue; } bool is_ok = true; for (int i = 0; i < 2; ++i){ for (int j = 0; j < 2; ++j){ int x = pp.real() + i; int y = pp.imag() + j; if (table[x][y]){ is_ok = false; } land &= (0xffffffffffffffffULL ^ (0xfULL << ((x + y * 4) * 4))); } } for (int i = 0; i < 16; ++i){ if (((land >> (i * 4)) & 0xfULL) >= 7){ //cout << "o"; is_ok = false; break; } } if (!is_ok){ continue; } next.insert(make_pair(pp.real() + pp.imag() * 4, land)); } } swap(open, next); } //cout << open.size() << " "; if (open.empty()){ cout << 0 << endl; } else { cout << 1 << endl; } } }