QOJ.ac

QOJ

Time Limit: 1.5 s Memory Limit: 512 MB Total points: 100
[0]

# 10144. Circles

Statistics

Two of the most mischievous Dacians in history, Danillo and Stegano, thought it would be funny to dig some tunnels that go nowhere. They knew that future historians would be extremely confused about the existence of some random tunnels and would try to speculate their purpose, but the tunnels would be, in fact, useless.

They found a huge wall in which they could start digging, but unfortunately, some patches of the wall would be unbreakable, so they would have to avoid them. The entrance to the tunnel would have to be circular for aesthetic reasons.

Formally, the wall can be described as a cartesian plane with x coordinates in the range [0,M] and y coordinates in the range [0,N]. The patches that are unbreakable are squares with sides parallel to the axes of length 1 with corners in integer coordinates. The map of the zones that can be broken can be described by a binary matrix with N lines numbered from 0 to N1 and M columns numbered from 0 to M1. If the element from line l and column c is 1, then all the points (x,y) with cxc+1 and lyl+1 can be mined. Note the difference between the coordinates (x,y) in the plane and the coordinates (l,c) of elements in the matrix.

When mining a tunnel, the two select a point with integer coordinates (x,y) as the center of the tunnel, then they select a radius r, and, finally, they start digging through all the points that lie inside the disc with the center in (x,y) of radius r. Note that the disc includes all the points inside, not just on the boundary of the circle, and the disc must lie completely inside the defined plane.

Task

They want the tunnel to be as noticeable as possible, so they want the tunnel with the largest radius. For easier construction, if there are multiple such tunnels, they want the one that is the easiest to dig. If the center of the tunnel is in coordinates (x,y), they want the one with the smallest y. If there are still multiple tunnels to choose from, they want the one with the smallest x.

Input data

The first line contains two integers N and M in this order, defining the plane and the lengths of the binary matrix.

The following N lines each contain a string of length M consisting of 0's and 1's, denoting the elements of the matrix defined above.

Output data

On a single line, you must print three space separated integers x, y and R. (x,y) represent the coordinates of the center of the tunnel that Danillo and Stegano will dig, and R represents the radius of the circle, squared and rounded to the nearest integer. If there are no circles with positive integers, you must print 0 0 0.

Constraints and clarifications

  • 1N,M3 000
# Points Constraints
0 0 Examples
1 4 The matrix contains exactly four cells with 1.
2 9 The 1's in the matrix form a rectangle with sides parallel to the axes.
3 14 N,M50
4 15 N,M600
5 21 The matrix is randomly generated.
6 37 No additional constraints

Example 1

stdin

5 6
011110
111110
011111
111111
011110

stdout

3 2 4

Explanation

problem_10144_1.png

Example 2

stdin

3 3
010
101
010

stdout

0 0 0

Doi din cei mai neastâmpărați Daci din toată istoria, Danillo și Stegano, s-au gândit că ar fi amuzant să sape niște tunele care nu duc nicăieri. Ei știau că viitorii istorici vor fi foarte confuzi în legătură cu existența unor tunele fără sens și vor încerca să găsească motivul construirii lor, când, de fapt, aceste tunele nu au niciun scop.

Aceștia au găsit un zid imens în care ar putea începe să sape, dar din păcate niște părți din zid sunt indestructibile, deci vor trebui să le ocolească. Din motive estetice, intrarea în tunel trebuie să fie circulară.

Mai exact, zidul poate fi descris ca un plan cartezian cu coordonatele x în intervalul [0,M] și coordonatele y în intervalul [0,N]. Părțile care sunt indestructibile sunt pătrate cu laturile paralele cu axele, de lungime 1 și cu colțurile în coordonate întregi. Harta zonelor ce pot fi săpate poate fi descrisă printr-o matrice binară cu N linii numerotate de la 0 la N1 și M coloane numerotate de la 0 la M1. Dacă elementul de pe linia l și coloana c este 1, atunci toate punctele (x,y) cu cxc+1 și lyl+1 pot fi săpate. Atenție la diferența între coordonatele (x,y) în plan și coordonatele (l,c) ca elemente ale matricei.

La săparea unui tunel, cei doi aleg un punct cu coordonate întregi (x,y) ca și centru al tunelului, iar apoi ei aleg o rază r, și, în final, se apucă să sape prin toate punctele care se află în discul centrat în (x,y) de rază r. Atenție la faptul că discul include toate punctele dinăuntrul lui, nu doar circumferința lui, și că discul trebuie să se afle complet înăuntrul planului definit.

Cerință

Aceștia își doresc ca tunelul lor să fie cât mai ușor de sesizat, așadar ei își doresc tunelul cu cea mai mare rază posibilă. Pentru o construire mai simplă, dacă există mai multe astfel de tunele, ei îl vor alege pe cel mai ușor de construit dintre ele. Dacă considerăm că centrul unui tunel este la coordonatele (x,y), ei vor prefera tunelul cu cel mai mic y. Dacă încă există mai multe astfel de tunele, ei îl vor alege pe cel cu cel mai mic x dintre acestea.

Date de intrare

Prima linie va conține două numere întregi N și M în această ordine, definind planul precum și mărimea matricei binare.

Următoarele N linii conțin fiecare câte un șir binar de lungime M format din 0-uri și 1-uri, reprezentând elementele matricei definite mai sus.

Date de ieșire

Afișați pe o singură linie trei numere întregi separate prin spații x, y și R. (x,y) reprezintă coordonatele centrului tunelului pe care Danillo și Stegano îl vor săpa, iar R reprezintă raza cercului, ridicată la pătrat si aproximată la cel mai apropiat întreg. Dacă nu există vreun cerc care să aibă coordonate pozitive, se va afișa 0 0 0.

Restricții și precizări

  • 1N,M3 000
# Puncte Restricții
0 0 Exemplele
1 4 Matricea conține exact patru celule cu 1.
2 9 Valorile de 1 din matrice formează un dreptunghi cu laturile paralele cu axele.
3 14 N,M50
4 15 N,M600
5 21 Matricea este generată prin random.
6 37 Fără restricții suplimentare

Exemplul 1

stdin

5 6
011110
111110
011111
111111
011110

stdout

3 2 4

Explicație

problem_10144_1.png

Exemplul 2

stdin

3 3
010
101
010

stdout

0 0 0