1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67
| (x,y)=[int(e) for e in raw_input("").split()] data=[] for i in range(x): data.append([int(e) for e in list(raw_input(""))])
sum_value=[[0 for x_i in range(80)] for y_j in range(80)]
for i in range(x+1): for j in range(y+1): if i == 0 or j == 0: sum_value[i][j] = 0 else: sum_value[i][j] = sum_value[i-1][j] + sum_value[i][j-1] -sum_value[i-1][j-1] +data[i-1][j-1] def get_data(x1,y1,x2,y2): return sum_value[x2][y2]-sum_value[x1][y2]-sum_value[x2][y1]+sum_value[x1][y1]
def fentiandi(x_length,y_length,avg_value): for index_i in range(1,y_length-2): for index_j in range(index_i+1,y_length-1): for index_k in range(index_j+1,y_length): count_value = 0 pre_line_index=0 for x_index_i in range(1,x_length+1): line1 = get_data(pre_line_index,0,x_index_i,index_i) line2 = get_data(pre_line_index,index_i,x_index_i,index_j) line3 = get_data(pre_line_index,index_j,x_index_i,index_k) line4 = get_data(pre_line_index,index_k,x_index_i,y_length)
if line1 >= avg_value and line2 >= avg_value and line3 >= avg_value and line4 >= avg_value: pre_line_index = x_index_i count_value += 1 if count_value >= 4: return True return False def get_min_value(): high=sum_value[x-1][y-1] best_value=0 low=0 while low <= high: middle=(low+high)/2
if fentiandi(x,y,middle) == True: low=middle+1 best_value=middle else: high = middle-1 print best_value
get_min_value()
|