I am trying my hands on Ambiguous Permutation problem listed under Easy problems in Practice Section. I have employed logic that if I make a number out of provided combination and again create a number based on its inverse permutation, if both numbers are same, it would be an ambiguous permutation. Consider the first test input 1 4 3 2 According to logic, I take an integer initial that would take hold number made out of given permutation and final would hold up number made out of its inverse permutation. So, here is calculation of initial, initially initial and final are 0. powr() is a function here, It gives out 10^n. And till holds number of numbers in test case, so, till=4 and limit holds copy of till. initial = initial10 + numberpowr(till1); till; so, For First, initial = 0 + 1*10^(41); initial = 1000; initial = 1000 + 4*10^(31); initial = 1000 + 400; initial = 1400; initial = 1400 + 3*10(21) initial = 1400 + 30 initial = 1430 initial = 1430 + 2*10(11) initial = 1432; And for final computation final= final + currIndex*10^(limitnum); final = 0 + 1*10^(41) final = 0 + 1000 final = 1000 final = 1000 + 2*10^(44) final = 1000 + 2 final = 1002 final = 1002 + 3*10^(43) final = 1002 + 30 final = 1032 final = 1032 + 4*10^(42) final = 1032 + 400 final = 1432 Both numbers are same. But I am getting wrong answer for my solution. I don't wish to copy other's solution. I want to know error of my way. By the way, logic works for numbers >10. I have checked. Here is code.
asked 29 Oct '13, 04:04

why don't you use standard C library to read the standard input ? i mean scanf() ?
it would probably be easier, and less errorprone.
really ?
what would be initial and final values for N = 10 ?
let's say the permutation is 1 2 3 4 5 6 7 8 10 9 :
initial = 1234567909
final = 1234567900
this permutation should be considered ambigous.
moreover, storing them in simple C integers won't fit. it cannot hold a number with 10^5 digits.
i think you'll need another approach. good luck !
I can, but I assume to produce output within timelimit, fread() cam help. Is it where I am wrong ?
no, but you shouldn't worry about the time limit in the first attempt. the main step is at first to get a correct algorithm. then, if you obtain TLE (time limit exceeded) with a fast algorithm, it'll be time to solve performance issues the hard way. :)
I have made fallowing test case for myself. 41 4 3 252 3 4 5 111111 4 3 2 11 8 10 6 9 7 5105 8 7 6 1 4 3 2 10 9105 8 7 6 1 4 3 10 2 90
 = newLine
And I am receiving output as ambiguousnot ambiguousambiguousambiguousambiguousnot ambiguous
It's right. It works for n=11 and 10.