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
3134 - INF
(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!
= Exemplu 2: = <code>infIN.txt</code> 1 5 NFFNI <code>infOUT.txt</code> Datele nu corespund restrictiilor impuse == Rezolvare == <syntaxhighlight lang="python3" line="1"> from collections import deque def next(ch): if ch == 'I': return 'N' if ch == 'N': return 'F' return 'I' def check_constraints(n, k): if not (2 <= n <= 1_500_000 and 1 <= k <= 500_000 and k <= n): with open("infOUT.txt", "w") as outfile: outfile.write("Datele nu corespund restrictiilor impuse") return False return True def main(): with open("infIN.txt", "r") as infile: n, k = map(int, infile.readline().split()) s = infile.readline().strip() if not check_constraints(n, k): return now = then = [s[i] for i in range(3)] # Inițializăm now și then cu primele 3 caractere din șirul s result = [0, 0, 0] res = float('inf') # Inițializăm res cu infinit q = deque() for i in range(1, n + 1): ch = s[i - 1] q.append(ch) for j in range(3): result[j] += (now[j] != ch) now[j] = next(now[j]) if i >= k: if i > k: cnow = q.popleft() for j in range(3): result[j] -= (then[j] != cnow) then[j] = next(then[j]) res = min(res, min(result)) with open("infOUT.txt", "w") as outfile: if res != float('inf'): outfile.write(str(res)) else: outfile.write("Datele nu corespund restrictiilor impuse") if __name__ == "__main__": main() </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