Send your feedback or ask for help here!
Based on all the IDE tests I assumed that the unit names are single words (it is not explicitly stated in statement). As I split input by space, this resulted a nasty fail in the last validator. It took quite some time to figure out that the input parsing was the culprit, and not my solver algorithm or its implementation.
I suggest to make this fact more explicit in the statement and/or put a two-word unit name also in one of the IDE tests.
There are units like nautic miles or roman miles. They are in the last test case and the nautic mile is even the first met unit in the statement.
You are right, my bad.
Interestingly, my original code with bad space split passed the last ide test but not the last validator. Most likely because the first word of these composite unit names were still unique in ide, but possibly not in the validator.
Thanks for the puzzle Dude !
Thanks, you just saved me a lot of time!
Yup, my php code passes all the tests but not the last validator. I sscanf instead of splitting by spaces. I even tried md5 on the units, and htmlspecialchars on the input. What am I missing? Code works with apostrophies anyway… I can’t think of anything I missed, unless validator has bad input. help?
there’s no constraints shown for the value of n, so is it just timing out because n is too large?
What kind of algorithm are you implementing?
I’m just using one recursive function that explores the links from start to dest. The current path explored I’m just using a stack, I just added a stack for the deadends found to reduce the number of calls. The links are saved bidirectionally, so reversing start and dest shouldn’t matter. I reduce using the gcd of the n and d, i guess it’s possible php is truncating large #s. I can’t seem to finagle the 4th validator. plz help.
How are you decoding the very first line of input? No problem with spaces in unit1 and/or unit2?
As any rational ratio can turn up in the exchange rates, it is important to accumulate the result during tree walk as a (nominator, denominator) pair and not as a single float.
I also use a stack for DFS tree traversal, recursion is not even needed (but should be fine)
Additionally, make sure your parser works even if two unit names are starting with the same word.
My parser is like this:
$line = explode(' = ', stream_get_line(STDIN, 40 + 1, "\n")); $left = explode(' ', $line, 2); $value1 = intval($left); $unit1 = $left; $right = explode(' ', $line, 2); $value2 = intval($right); $unit2 = $right; $conversion[$unit1][$unit2] = [$value1, $value2]; $conversion[$unit2][$unit1] = [$value2, $value1];
Do you apply normalization to the end result before outputting? (I mean getting gcd and then intdiv with it.)
as some others comments, i pass all the ide test but not the last validator…
Any clue about this last validator data set ?
How do you parse the first line?
did i lose something ? ^^
The units may contain spaces.
lol thank you !
hey, now i threat inputs with spaces,
as i rename spindle to spin dle with the last test (spi ndle in league, and i change the definition 1 spi ndle = 120 skein) and i get the right result,
but 100% in tests, and still 75% in submission…
i can’t figure out what happen here… lost time…
thx for your attention
my bad ^^ i understood…
don’t forget to reformalize the name of the spaced parameter as it was in inputs… thx and sorry for my last message