PROBLEM LINK:Setter Shivam Gupta DIFFICULTY:CAKEWALK PREREQUISITES:Looping, Conditionals Basic Coding . PROBLEM:There is a gold coin under box at index $X$. $S$ swaps are performed where two boxes are exchanged. We need to tell that finally, i.e. after all swaps are done, which indexed box has gold coin under it. QUICKEXPLANATION:Key to AC Having coded 56 problems from cakewalk question is enough to solve this problem. Looping, Conditionals and swapping of variables is needed. We initially know that gold coin is under box $X$. For each swap, we know the indices $(i,j)$ of the boxes which are being swapped. We form basic conditions of form
The final ans is in $Curr$. Please note I followed standard programming convention of $=$ representing assignment operator and $==$ representing "Check for Equality" operator. EXPLANATION:This is one of the editorial where Quick Explanation more than sums up everything about the logic. Instead of making editorial unnecessarily lengthy by formulating the logic again, lets focus on implementation. In case there is any doubt of logic under Quick Explanation, do ask. I kept it short as it was simply common sense. The gist of the logic is, if the coin is currently under any one of the bowls, $i$ or $j$, then it will be in the other bowl with which we swapped after the operation. Keep a track of which bowl the coin is CURRENTLY in. Taking the input is trivial, but with that being said, let me introduce you to Fast InputOutput methods. The rule of thumb says, if number of input is $>10^5$ or output $>10^5$, use fast inputoutput to save precious time. Else, many times correct solutions get TLE due to huge time wasted in IO operations. Maintain a temporary variable to store answer. I used $currAns$. After this, implement the conditionals mentioned above. Remember that, for cases where ($i \neq currAns$ $\&\&$ $j \neq currAns$) and $(i==currAns \&\& j==currAns)$ we dont need to do nothing, hence we ignore them. We only handle the remaining $2$ cases. Implementation in tab below SOLUTIONThe code is pasted in tabs below for you guys to refer in case solution links dont work. Setter $Time$ $Complexity=O(S)$ per test case CHEF VIJJU'S CORNER :D1. Swapping variables here and there kind of reminds me of the std::swap function of C++ STL. Its a nice function which comes in handy for beginners and professionals alike. It can swap variables, arrays, vectors, queues...you pretty much get it XD. 2. Why did Chef bother accepting Magicians challenge if he needs us to help him? _ 3. Related Problems: Frankly, the entire beginner section is filled to brim with such level problems. Solve any random problem from there, EXCEPT
List item
This question is marked "community wiki".
asked 07 Sep '18, 00:12

https://www.codechef.com/viewsolution/20123005 Please check why is it getting WA? answered 17 Sep '18, 22:51

https://www.codechef.com/viewsolution/20047736 Can someone explain why is this solution giving WA? answered 18 Sep '18, 19:19
You have a morethanusually magic coin. In your code, swapping two boxes means the coin always ends up under one of them, even if it was not under either to start with.
(18 Sep '18, 19:30)

https://www.codechef.com/viewsolution/20085700 Can someone explain why is this solution giving WA? answered 19 Sep '18, 11:52
For the following case, your code prints 1 instead of 3:
(19 Sep '18, 15:55)
You probably want to check the last element of answer instead of ans[i1].
(19 Sep '18, 15:55)

https://www.codechef.com/viewsolution/20243312 Why does this give WA, please help, someone? answered 19 Sep '18, 23:04
Ans of each test case must be printed in a new line. Make it
(19 Sep '18, 23:41)

https://www.codechef.com/viewsolution/21350841 can anyone tell why this is giving wrong answer answered 31 Oct '18, 20:38
You never produce any output, because you never enter the main loop. You missed:
to read the number of test cases.
(01 Nov '18, 00:05)
