Nov-05-2023, 09:35 AM
Hello, i have a task that i am really struggling with for 5 days straight and i would preferably need it done by Monday (tomorrow)
The task reads:
With some mild help from r/learnpython i have managed to put together this piece of code:[/b]
I would be very thankful if any of you could help me write working code for this task
Also, some more test cases for this task here:
The task reads:
Quote:Byteasar is currently developing a plan for a new airport to be built in the center of Byteotia.
Airport occupies a square of n × n bytemeters and on the plan it is divided into n2 fields of dimensions 1 × 1
bytemeters. Some of the fields are already occupied by the planned buildings (departures and arrivals hall, control tower
flights, hangars). Byteasar's task is to plan a place for m (m ≤ 2) runways of the same
length.
Each runway of length k must consist of k adjacent free fields, forming a rectangle
with dimensions of 1 × k or k × 1 bytemeters. Runways must be disjoint (in the case of m = 2) and not
may contain occupied fields. Byteasar wonders what the maximum length of the runways is
they will fit at the airport.
Entry
The first line of the input contains two integers n and m (1 ≤ n ≤ 1500, 1 ≤ m ≤ 2), meaning
the length of the side of the airport and the number of runways to be built.
The next n lines contain the airport description; each of them contains an n-letter word composed of X characters (field
busy) or . (empty field).
Exit
In the only line of the output, one integer k should be written, denoting the maximum length of the strips
startups that can be scheduled.
Example:
For input:
the correct result is:
Output:5 2 .X... .XXXX XX... ..... .X.X.
Output:3 Explanation of the example: The figure below shows the possible arrangement of runways of length 3: .X... .XXXX XX..2 111.2 .X.X2
With some mild help from r/learnpython i have managed to put together this piece of code:[/b]
from itertools import product n, m = map(int, input().split()) airport = [input() for _ in range(n)] def check(k): """Helper function to check if k-length runways can be built.""" for i in range(n): for j in range(n - k + 1): if all(c == '.' for c in airport[i][j:j+k]): if m == 1: return True for l in range(i+1, n): if all(c == '.' for c in airport[l][j:j+k]): return True break return False lo, hi = 1, n while lo < hi: mid = (lo + hi + 1) // 2 if check(mid): lo = mid else: hi = mid - 1 print(lo)The problem is, the person that was helping me understand this task, has been straight up ghosting me for the past 3 days, and I'm stuck at this point because no matter what i try, it eighter breaks as a whole some other part of the code, or just doesn't work at all.
I would be very thankful if any of you could help me write working code for this task

Also, some more test cases for this task here:
Output:1rating: n = 2, m = 1, all fields are empty; the answer is 2.
2ratings: n = 2, m = 2, one field is occupied; the answer is 1.
3ratings: n = 10, m = 2, all fields are occupied except line 5; the answer is 5.
4ratings: n = 10, m = 2, all fields are occupied except columns 2 and 8; the answer is 10.
5ratings: n = 1500, m = 2, all fields are occupied except column 31, which has only 2 fields occupied; the answer is 531
My code work only up to the 2nd test.