// C++11 #include #include #include #include #include #include #include #include #include #include #include using namespace std; #define pv(val) cerr << #val << '=' << (val) << endl #define pvn(name, val) cerr << name << '=' << (val) << endl #define pl cerr << '@' << __LINE__ << endl static constexpr uint64_t u0 = 0ull; static constexpr uint64_t u1 = 1ull; static constexpr uint64_t uF = numeric_limits::max(); #ifdef _MSC_VER //dummy int __builtin_popcountll(unsigned long long) { return 0; } int __builtin_clzll(unsigned long long) { return 0; } #endif template ostream& operator<<(ostream& os, vector const& vec) { if (vec.empty()) { os << "{}"; } else { os << '{'; for (size_t i = 0; i < vec.size() - 1; i++) os << vec[i] << ", "; os << vec.back() << '}'; } return os; } template ostream& operator<<(ostream& os, array const& arr) { if (arr.empty()) { os << "{}"; } else { os << '{'; for (size_t i = 0; i < arr.size() - 1; i++) os << arr[i] << ", "; os << arr.back() << '}'; } return os; } class Timer { using clock = chrono::high_resolution_clock; clock::time_point startTime; template auto elapsed() const { return chrono::duration_cast(clock::now() - startTime).count(); } public: Timer() { restart(); } void restart() { startTime = clock::now(); } auto milli() const { return elapsed(); } auto micro() const { return elapsed(); } }; Timer globalTimer; class Xorshift128 { uint32_t x, y, z, w, t; public: using result_type = uint32_t; Xorshift128(uint32_t seed = 12433) : x(123456789), y(362436069), z(521288629), w(seed) {} static constexpr result_type min() { return std::numeric_limits::min(); } static constexpr result_type max() { return std::numeric_limits::max(); } result_type operator()() { t = x ^ (x << 11); x = y; y = z; z = w; return w = (w ^ (w >> 19)) ^ (t ^ (t >> 8)); } }; template > class PriorityQueue { public: using container = vector; using iterator = typename container::iterator; using const_iterator = typename container::const_iterator; private: container queue_; size_t last_; public: PriorityQueue() { last_ = 0; } size_t size() const { return last_; } const_iterator begin() const { return queue_.begin(); } const_iterator end() const { return queue_.begin() + last_; } bool full() const { return size() == capacity(); } void setCapacity(size_t n) { queue_.resize(n); } size_t capacity() const { return queue_.size(); } void push(const T& val) { queue_[last_] = val; last_++; std::push_heap(queue_.begin(), queue_.begin() + last_, Comp()); } void push(T&& val) { queue_[last_] = std::move(val); last_++; std::push_heap(queue_.begin(), queue_.begin() + last_, Comp()); } void clear() { last_ = 0; } T const& top() const { return queue_[0]; } void pop() { std::pop_heap(queue_.begin(), queue_.begin() + last_, Comp()); last_--; } }; struct Line { int a; int b, c; }; void solve(array L, array board) { Xorshift128 x128; std::uniform_int_distribution dist59(0, 60); std::uniform_int_distribution dist60(0, 60); std::uniform_int_distribution dist249(0, 249); array ansYoko, ansTate; for (int i = 0; i < 250; i++) { ansYoko[i].a = dist59(x128); ansYoko[i].b = dist60(x128); ansYoko[i].c = dist60(x128); if (ansYoko[i].b > ansYoko[i].c) swap(ansYoko[i].b, ansYoko[i].c); ansTate[i].a = dist59(x128); ansTate[i].b = dist60(x128); ansTate[i].c = dist60(x128); if (ansTate[i].b > ansTate[i].c) swap(ansTate[i].b, ansTate[i].c); } int score = 0; for (int i = 0; i < 250; i++) { auto yoko = ansYoko[i]; int diffW = __builtin_popcountll(board[yoko.a]); auto x = uF << yoko.b; x = x >> (64 - yoko.c) & x; board[yoko.a] = x; diffW = __builtin_popcountll(board[yoko.a]) - diffW; auto tate = ansTate[i]; x = u1 << tate.a; for (int j = tate.b; j < tate.c; j++) { diffW += (board[tate.a] & x == 0) ? -1 : 1; board[tate.a] ^= x; } score += diffW; } int rem = 0; for (int i = 0; i < 250; i++) { auto yoko = ansYoko[i]; if (yoko.b == yoko.c) { rem++; } else { cout << (60 - yoko.b) << ' ' << (yoko.a + 1) << ' ' << (60 - yoko.c) << ' ' << (yoko.a + 1) << endl; } auto tate = ansTate[i]; if (tate.b == tate.c) { rem++; } else { cout << (60 - tate.a) << ' ' << (tate.b + 1) << ' ' << (60 - tate.a) << ' ' << (tate.c + 1) << endl; } } while (rem > 0) { for (int i = 0; i < 60; i++) { while (board[i] != 0) { int j = 63 - __builtin_clzll(board[i]); auto x = ~(u1 << j); board[i] &= x; cout << (60 - j) << ' ' << i << ' ' << (60 - j) << ' ' << i << endl; ++score; --rem; if (rem == 0) goto END; } } } END:; pv(score); } int main(void) { int N, K; array L; array board; cin >> N >> K; for (int i = 0; i < 500; i++) cin >> L[i]; string line; for (int i = 0; i < 60; i++) { cin >> line; std::bitset<64> bs(line); board[i] = bs.to_ullong(); } solve(L, board); return 0; }