0789 - Max 2 Ap

From Bitnami MediaWiki
Revision as of 19:31, 3 April 2023 by Andor Giulia (talk | contribs) (Pagină nouă: == Rezolvare == <syntaxhighlight lang="python" line="1"> n, m = map(int, input().split()) matrix = [] for i in range(n): row = list(map(int, input().split())) matrix.append(row) seen = set() max_duplicate = None for i in range(n): for j in range(m): value = matrix[i][j] if value in seen and (max_duplicate is None or value > max_duplicate): max_duplicate = value else: seen.add(value) if max_duplicate is None:...)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

Rezolvare

<syntaxhighlight lang="python" line="1"> n, m = map(int, input().split())

matrix = [] for i in range(n):

   row = list(map(int, input().split()))
   matrix.append(row)

seen = set() max_duplicate = None

for i in range(n):

   for j in range(m):
       value = matrix[i][j]
       if value in seen and (max_duplicate is None or value > max_duplicate):
           max_duplicate = value
       else:
           seen.add(value)

if max_duplicate is None:

   print("IMPOSIBIL")

else:

   print(max_duplicate)

</syntaxhighlight>