0% found this document useful (0 votes)
64 views1 page

Petr Permutation 987E

This document describes a problem about determining whether a random permutation was generated using one of two different methods. The first method, used by Petr, generates a permutation by starting with the identity permutation and swapping random pairs of elements 3n times. The second method, used by Alex, similarly starts with the identity permutation but swaps random pairs 7n+1 times instead of 3n times. The problem is to determine, based on the given permutation, whether it was generated using Petr's method or Alex's method. The solution is to calculate the parity (even or odd number of inversions) of the given permutation and check if it matches the expected parity of 3n swaps or 7n+1 swaps.

Uploaded by

mera nam chin
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
64 views1 page

Petr Permutation 987E

This document describes a problem about determining whether a random permutation was generated using one of two different methods. The first method, used by Petr, generates a permutation by starting with the identity permutation and swapping random pairs of elements 3n times. The second method, used by Alex, similarly starts with the identity permutation but swaps random pairs 7n+1 times instead of 3n times. The problem is to determine, based on the given permutation, whether it was generated using Petr's method or Alex's method. The solution is to calculate the parity (even or odd number of inversions) of the given permutation and check if it matches the expected parity of 3n swaps or 7n+1 swaps.

Uploaded by

mera nam chin
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 1

7/6/2020 Problem - E - Codeforces

|
ridwanultanvir | Logout

HOME TOP CONTESTS GYM PROBLEMSET GROUPS RATING EDU API CALENDAR HELP ICPC CHALLENGE 10 YEARS! 

Please, try EDU on Codeforces! New educational section with videos, subtitles, texts, and problems. ×

PROBLEMS SUBMIT CODE MY SUBMISSIONS STATUS HACKS ROOM STANDINGS CUSTOM INVOCATION

Codeforces Round #485 (Div. 2)


E. Petr and Permutations Finished
time limit per test: 2 seconds
Practice
memory limit per test: 256 megabytes
input: standard input
output: standard output

Petr likes to come up with problems about randomly generated data. This time problem is → Virtual participation
about random permutation. He decided to generate a random permutation this way: he takes
Virtual contest is a way to take part in past
identity permutation of numbers from 1 to n and then 3n times takes a random pair of different contest, as close as possible to participation
elements and swaps them. Alex envies Petr and tries to imitate him in all kind of things. Alex on time. It is supported only ICPC mode for
virtual contests. If you've seen these
has also come up with a problem about random permutation. He generates a random problems, a virtual contest is not for you -
permutation just like Petr but swaps elements 7n + 1 times instead of 3n times. Because it is solve these problems in the archive. If you
just want to solve some problem from a
more random, OK?! contest, a virtual contest is not for you -
solve this problem in the archive. Never use
You somehow get a test from one of these problems and now you want to know from which someone else's code, read the tutorials or
communicate with other person during a
one. virtual contest.

Input Start virtual contest


In the first line of input there is one integer n (103 ≤ n ≤ 10
6
).

In the second line there are n distinct integers between 1 and n — the permutation of size n → Practice
from the test.
You are registered for practice. You can solve
It is guaranteed that all tests except for sample are generated this way: First we choose n — problems unofficially. Results can be found in
the contest status and in the bottom of
the size of the permutation. Then we randomly choose a method to generate a permutation — standings.
the one of Petr or the one of Alex. Then we generate a permutation using chosen method.

Output → Clone Contest to Mashup


If the test is generated via Petr's method print "Petr" (without quotes). If the test is generated
via Alex's method print "Um_nik" (without quotes). You can clone this contest to a mashup.

Clone Contest
Example
input Copy

5 → Submit?
2 4 5 1 3

output Copy Language: GNU G++14 6.4.0

Petr Choose
Choose File No file chosen
file:
Note Be careful: there is 50 points penalty for
Please note that the sample is not a valid test (because of limitations for n) and is given only submission which fails the pretests or
resubmission (except failure on the first test,
to illustrate input/output format. Your program still has to print correct answer to this test to denial of judgement or similar verdicts).
get AC. "Passed pretests" submission verdict doesn't
guarantee that the solution is absolutely
correct and it will pass system tests.
Due to randomness of input hacks in this problem are forbidden.
Submit
Each swap change the parity of permutation. 3n and 7n+1 always have different parities, so the solution is just to calculate the parity
of the given permutation and check if it is equal to parity of 3n or to parity of 7n+1.
→ Problem tags
To calculate the parity you can just calculate the number of inversions with your favorite
method (Fenwick tree, Segment tree, mergesort or whatever) in O(nlogn) time. But it is math *1800
easier to calculate the number of cycles in permutation in O(n) time.
https://codeforces.com/contest/987/problem/E 1/2

You might also like