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
3282 – Transform1
(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!
= Restricții și precizări = * <code>3 ≤ N ≤ 256.000</code> * <code>1 ≤ x, y ≤ N</code> == Exemplul 1 == input.txt: 7 4 5 1 7 1 7 3 4 7 ouput.txt: 35 Explicație: După <code>transform(1)</code>, în care w = 3, șirul devine <code>3</code>, <code>7</code>, <code>3</code>, <code>7</code>, <code>3</code>, <code>4</code>, <code>7</code> care are suma <code>34</code>. După <code>transform(2)</code>, în care <code>w = 2</code>, șirul devine <code>3</code>, <code>2</code>, <code>3</code>, <code>2</code>, <code>3</code>, <code>4</code>, <code>2</code> care are suma <code>19</code>. După <code>transform(3)</code>, în care <code>w = 7</code>, șirul devine <code>3</code>, <code>2</code>, <code>7</code>, <code>2</code>, <code>7</code>, <code>4</code>, <code>2</code> care are suma <code>27</code>. După <code>transform(4)</code>, în care <code>w = 6</code>, șirul devine <code>3</code>, <code>2</code>, <code>7</code>, <code>6</code>, <code>7</code>, <code>4</code>, <code>6</code> care are suma <code>35</code>. După <code>transform(5)</code>, în care <code>w = 7</code>, șirul devine <code>3</code>, <code>2</code>, <code>7</code>, <code>6</code>, <code>7</code>, <code>4</code>, <code>6</code> care are suma <code>35</code>. După <code>transform(6)</code>, în care <code>w = 3</code>, șirul devine <code>3</code>, <code>2</code>, <code>7</code>, <code>6</code>, <code>7</code>, <code>3</code>, <code>6</code> care are suma <code>34</code>. După <code>transform(7)</code>, în care <code>w = 3</code>, șirul devine <code>3</code>, <code>2</code>, <code>7</code>, <code>6</code>, <code>7</code>, <code>3</code>, <code>3</code> care are suma <code>31</code>. Suma maximă care s-a obținut este <code>35</code>. == Exemplul 2 == input.txt: 999999999 4 5 1 7 1 7 3 4 7 Output: Invalid input. Please make sure 3 ≤ N ≤ 256000 and 1 ≤ x, y ≤ N. == Rezolvare == <syntaxhighlight lang="python3" line="1"> N = 260001 def validate_input(n, x, y): if 3 <= n <= 256000 and 1 <= x <= n and 1 <= y <= n: return True return False def main(): with open("input.txt", "r") as input_file, open("output.txt", "w") as output_file: n, x, y = map(int, input_file.readline().split()) a = list(map(int, input_file.readline().split())) if not validate_input(n, x, y): print("Invalid input. Please make sure 3 ≤ N ≤ 256000 and 1 ≤ x, y ≤ N.") return S = 0 Rad = [0] * N Val = [0] * N tata = [0] * N Card = [0] * N for i in range(1, n + 1): S += a[i - 1] for i in range(n, 0, -1): if not Rad[a[i - 1]]: Rad[a[i - 1]] = i Val[i] = a[i - 1] tata[i] = Rad[a[i - 1]] Card[a[i - 1]] += 1 Sol = 0 for i in range(1, n + 1): nod = i while nod != tata[nod]: nod = tata[nod] val1 = Val[nod] val2 = 1 + (i * x + val1 * y) % n rad2 = Rad[val2] if val1 == val2: Card[val1] -= 1 if Card[val1] == 0: Val[nod] = 0 Rad[val1] = 0 else: S = S + Card[val1] * (val2 - val1) Card[val2] = Card[val2] + Card[val1] - 1 Card[val1] = 0 if nod < rad2: tata[nod] = rad2 Rad[val2] = rad2 Val[rad2] = val2 Rad[val1] = 0 Val[nod] = 0 else: tata[rad2] = nod Rad[val2] = nod Val[nod] = val2 Rad[val1] = 0 Val[rad2] = 0 tata[i] = 0 Sol = max(Sol, S) output_file.write(str(Sol)) 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