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
3652 - secvcost
(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" line="1"> # 3652 - secvcost def validare(date1): # functia de validare a datelor de intrare numar_elemente, numar_intrebari = map(int, date1[0].split()) if not (1 <= numar_elemente <= 200000) or not (1 <= numar_intrebari <= 200000): raise ValueError sir = list(map(int, date1[1].split())) if len(sir) != numar_elemente or any(element > 5000000 for element in sir): raise ValueError intrebari = [list(map(int, date1[i].split())) for i in range(2, 2 + numar_intrebari)] if any(not (1 <= X <= Y <= numar_elemente) for X, Y in intrebari): raise ValueError fisier_iesire.write("Datele de intrare corespund restrictiilor impuse\n") def cost_secventa(date1): # functia de rezolvare numar_elemente, numar_intrebari = map(int, date1[0].split()) sir = list(map(int, date1[1].split())) intrebari = [list(map(int, date1[i].split())) for i in range(2, 2 + numar_intrebari)] for X, Y in intrebari: cost = sum([sir[i] * max(len(sir[:i+1]), len(sir[i:])) for i in range(X-1, Y)]) fisier_iesire.write(f"{cost}\n") if __name__ == '__main__': fisier_intrare = open("secvcostin.txt", "r") # declararea fisierelor fisier_iesire = open("secvcostout.txt", "w") # fisierul out trebuie declarat cu optiunea "w" (write) # din cauza datelor de intrare pot aparea 2 tipuri de erori, valueError sau IndexError pe care le tratam try: date = fisier_intrare.readlines() # citirea numerelor se face ca sir de caractere validare(date) # apelul functiei de validare cost_secventa(date) # apelul functiei de rezolvare except ValueError: fisier_iesire.write("Datele de intrare nu corespund restrictiilor impuse") except IndexError: fisier_iesire.write("Datele de intrare nu corespund restrictiilor impuse") </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