Test answer rejected for saying more than asked for
I know from personal experience that it's very frustrating not to get proper credit for knowledge that you think you demonstrated correctly, so let me start by saying I sympathize with your situation. Now let me address your questions:


  Is it justifiable to reject an entire answer because more was said,
  without even partial credit?


To give a literal, completely general answer: obviously yes. If the correct answer is, say, one sentence long, and your answer quotes the complete works of Shakespeare that happen to contain that sentence, I personally would not give you any points (but I would still be very impressed :-)). Of course, that is an absurd example, but it illustrates the point that what likely matters to your professor (or if not, certainly what should matter to a reasonable professor) is that your answer demonstrates an understanding of the topic the question asks about. It is certainly possible, and happens pretty frequently, that an answer Y contains the correct answer X but by adding more irrelevant things demonstrates a less good level of understanding than just the shorter answer X. The way this typically happens is that a student doesn't understand the material well and upon being asked about a certain topic, regurgitates everything they memorized about the topic, not knowing which part is relevant to the question. Clearly that does not leave a very good impression.

Now of course, the above does not address what happened in your specific situation. It is completely possible that your longer answer Y still demonstrated as good of an understanding of the material as the official answer X, and deserves to get partial or full credit; or not - you haven't given us enough information to say.


  Is it justifiable to reject an answer that gives something better than
  what is required, perfectly equivalent, even if relying on the
  student's intervention? (in this case, it would be a compiler
  optimization, thus not an entirely direct interpretation, but an
  elegant and industrially valuable workaround)


I think this question is too specific for anyone here to be able to answer without knowing more details. As I said above, the points you get for the answer should be correlated with the perceived mastery of the topic being asked about that your answer demonstrates. If including the optimization demonstrates that mastery, you should get the points. But I can imagine a situation where using the optimized method instead of the official method actually demonstrates less mastery, for example if it appears that you used the optimized method to avoid revealing that you don't know the simpler, less sophisticated method the question asked about. In that case, it may make sense for your answer to be rejected.


  Is it acceptable to direct students to example answers and not allow
  them to explain why they think their answer is correct?


I think it may be acceptable in certain cases. For example, if you have already asked many questions of the professor, argued with him in a way that he thought was unreasonable, overly argumentative, or delusional, and if the professor is very busy, for example is also teaching a class of 500 students in addition to the smaller class you're taking with him, at some point he may decide that spending more time discussing your exam with you can limit his ability to perform his other duties effectively, and be a disservice to the other students.



Summary. As you can see from my answers above, whether the professor's behavior is unreasonable depends on many details that you haven't provided. It's certainly possible that it is unreasonable, but it's also possible that it is less unreasonable than you may think. Statistically speaking, I've found that students often overestimate the extent to which they understand the material and the degree of correctness of their exam answers. That doesn't mean it's what happened in your case, but it's a possibility you should keep in mind as you consider your next steps. In any case, good luck! As for what steps you should take to address the situation, this answer is already quite long so I think it makes sense to save that for a follow-up question if you care to post one.