The Duel of Smokin' Joe
Time limit2sMemory limit1024 MB
Given a permutation, decide whether the first player wins a game where players swap unfixed elements until sorted and the last swap wins.
- Level
Medium6 of 10
- Topics
- Game theory, Math, Array
- Solved
- No attempts yet
Problem
In the wild west, people take Computer Science very seriously. Smokin' Joe is widely known for his skill, so outlaws from across the land come to challenge him to an old-fashioned sorting duel. The way outlaws duel in the wild west is by trying to be the one who makes the last move to sort an array of integers. One fateful day, The Outlaw, Smokin' Joe's infamous nemesis, came to town and challenged Joe to a duel. The rules of the duel are as follows. The outlaw spins the chambers, and a random permutation of length n falls out. A permutation of length n is an array of the integers from 1 to n in any order. Smokin' Joe and The Outlaw take turns swapping two elements of this permutation until it is sorted in increasing order. The player who makes the last swap wins. Once an element is in its final position, meaning value k is at position k, that element cannot be moved for the rest of the game. Otherwise, there are no restrictions on which two elements can be swapped. Both players always play perfectly. They play to win, not necessarily to sort the list as fast as possible. Can you predict who will win? Given a permutation, predict the winner of the game. Smokin' Joe makes the first move.
Input
The first line contains an integer n, the length of the permutation. () The second line contains n distinct integers, the permutation. It is guaranteed that the input is a permutation of the integers from 1 to n, and that the permutation is not already sorted.
Output
If Smokin' Joe wins, print "Smokin Joe!". If The Outlaw wins, print "Oh No!". The apostrophe in Smokin' is omitted from the output, because apostrophes can turn into different ASCII characters on different machines and cause format errors.