#include #include #include #include #include using namespace std; struct State { int a[66][66]; }; int N, K, L[509]; State S; vector>X; tupleans[509]; tuple solve(int len) { int maxn = -1; tuplemaxid = make_tuple(0, 0, 0, 0); for (int i = 1; i <= N; i++) { for (int j = 1; j <= N - len + 1; j++) { int sum = 0; for (int k = j; k < j + len; k++) sum += (1 - S.a[i][k]); if (maxn < sum) { maxn = sum; maxid = make_tuple(i, j, i, j + len - 1); } } } for (int i = 1; i <= N; i++) { for (int j = 1; j <= N - len + 1; j++) { int sum = 0; for (int k = j; k < j + len; k++) sum += (1 - S.a[k][i]); if (maxn < sum) { maxn = sum; maxid = make_tuple(j, i, j + len - 1, i); } } } return maxid; } void flip(int px, int py, int qx, int qy) { for (int i = px; i <= qx; i++) { for (int j = py; j <= qy; j++) S.a[i][j] ^= 1; } } int score() { int ret = 0; for (int i = 1; i <= N; i++) { for (int j = 1; j <= N; j++) ret += S.a[i][j]; } return ret; } int main() { cin >> N >> K; for (int i = 1; i <= K; i++) { cin >> L[i]; X.push_back(make_pair(L[i], i)); } for (int i = 1; i <= N; i++) { for (int j = 1; j <= N; j++) { char c; cin >> c; if (c == '0') S.a[i][j] = 1; else S.a[i][j] = 0; } } //sort(X.begin(), X.end(), greater>()); for (int i = 0; i < X.size(); i++) { tupleG = solve(X[i].first); ans[X[i].second] = G; flip(get<0>(G), get<1>(G), get<2>(G), get<3>(G)); } for (int i = 1; i <= K; i++) { cout << get<0>(ans[i]) << " " << get<1>(ans[i]) << " " << get<2>(ans[i]) << " " << get<3>(ans[i]) << endl; } //cout << "#score = " << score() << endl; return 0; }