Jump to content
Main menu
Main menu
move to sidebar
hide
Navigation
Main page
Recent changes
Random page
Help about MediaWiki
Bitnami MediaWiki
Search
Search
Create account
Log in
Personal tools
Create account
Log in
Pages for logged out editors
learn more
Contributions
Talk
Editing
2429 - matrice9
(section)
Page
Discussion
English
Read
Edit
Edit source
View history
Tools
Tools
move to sidebar
hide
Actions
Read
Edit
Edit source
View history
General
What links here
Related changes
Special pages
Page information
Warning:
You are not logged in. Your IP address will be publicly visible if you make any edits. If you
log in
or
create an account
, your edits will be attributed to your username, along with other benefits.
Anti-spam check. Do
not
fill this in!
== Rezolvare == <syntaxhighlight lang="python3" line="1"> N_MAX = 1024 SEQ_UNKNOWN = 0 SEQ_INCREASING = 1 SEQ_DECREASING = 2 N, M = 0, 0 A = [[0] * N_MAX for _ in range(N_MAX)] Inaltime = [0] * N_MAX Tip = [SEQ_UNKNOWN] * N_MAX Inceput = [0] * N_MAX Contor = 0 Stiva = [0] * N_MAX Top = [0] * N_MAX CelMaiBun, CelMaiBun1l, CelMaiBun1c, CelMaiBun2l, CelMaiBun2c = 0, 0, 0, 0, 0 def verifica_restrictiile(): if not (1 <= N <= 1000 and 1 <= M <= 1000): with open("matrice9OUT.txt", "w") as fisier: fisier.write("Datele nu corespund restrictiilor impuse\n") return False return True def rezolva(): global N, M, A, Inaltime, Tip, Inceput, Contor, Stiva, Top, CelMaiBun, CelMaiBun1l, CelMaiBun1c, CelMaiBun2l, CelMaiBun2c for j in range(M): for i in range(N + 1): if i == N: Inaltime[i] = 0 elif j == 0: Inaltime[i] = 1 elif Tip[i] == SEQ_UNKNOWN: Tip[i] = SEQ_INCREASING if A[i][j] > A[i][j - 1] else SEQ_DECREASING Inaltime[i] += 1 elif Tip[i] == SEQ_INCREASING: if A[i][j] < A[i][j - 1]: Inaltime[i] = j - Inceput[i] + 1 Inceput[i] = j - 1 Tip[i] = SEQ_DECREASING else: Inaltime[i] += 1 elif Tip[i] == SEQ_DECREASING: if A[i][j] > A[i][j - 1]: Inaltime[i] = j - Inceput[i] + 1 Inceput[i] = j - 1 Tip[i] = SEQ_INCREASING else: Inaltime[i] += 1 varf = i while Contor > 0 and Inaltime[i] <= Stiva[Contor - 1]: varf = Top[Contor - 1] if Stiva[Contor - 1] * (i - varf) > CelMaiBun: CelMaiBun = Stiva[Contor - 1] * (i - varf) CelMaiBun1l, CelMaiBun2l = varf, i - 1 CelMaiBun1c, CelMaiBun2c = j - Stiva[Contor - 1] + 1, j Contor -= 1 if Inaltime[i] > 0: Stiva[Contor] = Inaltime[i] Top[Contor] = varf Contor += 1 return CelMaiBun1l + 1, CelMaiBun1c + 1, CelMaiBun2l + 1, CelMaiBun2c + 1 def citeste_rezolva(): global N, M, A with open("matrice9IN.txt", "r") as fisier: N, M = map(int, fisier.readline().split()) if not verifica_restrictiile(): return for i in range(N): A[i] = list(map(int, fisier.readline().split())) rezultat = rezolva() with open("matrice9OUT.txt", "w") as fisier: fisier.write(f"{rezultat[0]} {rezultat[1]} {rezultat[2]} {rezultat[3]}\n") if __name__ == "__main__": citeste_rezolva() </syntaxhighlight>
Summary:
Please note that all contributions to Bitnami MediaWiki may be edited, altered, or removed by other contributors. If you do not want your writing to be edited mercilessly, then do not submit it here.
You are also promising us that you wrote this yourself, or copied it from a public domain or similar free resource (see
Bitnami MediaWiki:Copyrights
for details).
Do not submit copyrighted work without permission!
Cancel
Editing help
(opens in new window)
Toggle limited content width