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
4044 - camere
(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="python"> from typing import List def validate_input(N: int, M: int, matrix: List[List[str]]) -> bool: # Verifică dacă N și M sunt în intervalul specificat if not (1 <= N <= 300) or not (1 <= M <= 300): return False # Verifică dacă matricea conține doar caracterele {'A', 'N', 'C'} for i in range(N): for j in range(M): if matrix[i][j] not in {'A', 'N', 'C'}: return False return True def count_submatrices(N: int, M: int, matrix: List[List[str]]) -> int: count = 0 # Iterează prin toate submatricile posibile ale matricei for i in range(N): for j in range(M): for k in range(i, N): for l in range(j, M): # Calculează numărul de alune și nuci în submatrice num_almonds = sum(matrix[p][q] == 'A' for p in range(i, k+1) for q in range(j, l+1)) num_walnuts = sum(matrix[p][q] == 'N' for p in range(i, k+1) for q in range(j, l+1)) # Verifică dacă numărul de alune este egal cu numărul de nuci if num_almonds == num_walnuts: count += 1 return count if __name__ == '__main__': # Citirea datelor de intrare N, M = map(int, input().split()) matrix = [list(input().strip()) for _ in range(N)] # Validarea datelor de intrare if not validate_input(N, M, matrix): print("Date de intrare invalide") return else: print("Date de intrare valide") # Rezolvarea problemei și afișarea rezultatului result = count_submatrices(N, M, matrix) print(result) </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