Ciao a tutti, ho bisogno di aiuto per risolvere il problema Progressive Art.
0/100 perchè in ogni subtask c’è 1 caso errato
Ho pensato a vari casi possibili anche strani, ma forse me ne sto dimenticando qualcuno
Come potrei risolvere?
Ecco il mio codice:
import sys
# uncomment the two following lines if you want to read/write from files
sys.stdin = open('input.txt')
sys.stdout = open('output.txt', 'w')
def Quad(posx, posy, l):
for i in range(posy,l+posy):
for j in range(posx,l+posx):
if (i+j)%3 == 0:
A[i][j] = "R"
elif (i+j+1)%3 == 0:
A[i][j] = "G"
else:
A[i][j] = "B"
N, M, L, K = map(int, input().strip().split())
A = [["" for _ in range(M)] for i in range(N)]
if L%3 == 0 and (N-L+1)*(M-L+1) >= K and N>=3 and M >=3:
for i in range(N):
for j in range(M):
A[i][j] = "G"
print("YES")
if K > 0:
if L + K - 1 <= max(M,N):
if N < M:
for j in range(L):
for i in range(L+K-1):
if (i+j)%3 == 0:
A[j][i] = "R"
elif (i+j+1)%3 == 0:
A[j][i] = "G"
else:
A[j][i] = "B"
else:
for j in range(L+K-1):
for i in range(L):
if (i+j)%3 == 0:
A[j][i] = "R"
elif (i+j+1)%3 == 0:
A[j][i] = "G"
else:
A[j][i] = "B"
else:
k = 0
x = 0
y = 0
while k < K:
Quad(x,y,L)
x += 1
if x == M-L+1:
x = 0
y += 1
k += 1
for i in range(N):
for j in range(M):
print(A[i][j], end="")
print()
else:
print("NO")
sys.stdout.close()
Grazie mille in anticipo!