10782 - Send More Money

All about problems in Volume 107. If there is a thread about your problem, please use it. If not, create one with its number in the subject.

Moderator: Board moderators

Post Reply
Dreamer#1
Learning poster
Posts: 77
Joined: Tue Oct 07, 2003 10:07 pm

10782 - Send More Money

Post by Dreamer#1 »

I got several WA in this problem during contest though it was a very simple problem & I was pretty confident about my solution but now that I've got AC I feel that may be the problem description is not correct which led me to WA during contest despite of the fact that my solution was correct. :(
Problem description says "The original summation contained no leading zeros in the numbers"
"Summation" means "The arithmetic operation of summing; calculating the sum of two or more numbers."

So, the quoted line must have meant all the n numbers involved in the summation process can't have a leading zero for it to be a valid solution. Also, the word "numbers" certainly doesn't mean a single number.

After writing a solution following that constraint I kept getting WA then using assert() I found that my solution couldn't find any solution for some inputs in judge data so I started experimenting and lastly got AC after changing that constraint to hold only for the result of the summation, i.e. if only the summation result has no leading zero then I considered that to be a valid solution not caring whether the first n-1 numbers that are to be added has any leading zero or not.

Someone who got AC can you please verify whether it is really the case or may be I've made some mistake somewhere in coding or understanding.

thanks in advance... :)
sidky
New poster
Posts: 50
Joined: Wed Nov 06, 2002 1:37 pm
Location: Planet Earth, Universe
Contact:

Post by sidky »

During the contest, I was also stuck on this problem for a while. But finally I managed to get it accepted. I also assert() my cases, and found that, my program failed to solve some of the input data. My problem was also in the leading zero. According to my solution, no number can have leading zero (Not only the summation value), but the value zero as itself is allowed.
I think, that is the main trick in this problem.
Adrian Kuegel
Guru
Posts: 724
Joined: Wed Dec 19, 2001 2:00 am
Location: Germany

Post by Adrian Kuegel »

Dreamer#1 wrote:So, the quoted line must have meant all the n numbers involved in the summation process can't have a leading zero for it to be a valid solution. Also, the word "numbers" certainly doesn't mean a single number.
Yes, and exactly that is what you have to do. Probably you didn't allow a single zero within the summation.
Quoting the problem description:
"The original summation contained no leading zeros in the numbers (although the value 0 itself was allowed)."
Can you suggest something how to write this constraint clearer?

I guess you understood "although the value 0 itself was allowed" as "although the digit 0 at a non-leading position was allowed". Maybe it should be written as "although the number 0 itself was allowed" to make it clearer?
Dreamer#1
Learning poster
Posts: 77
Joined: Tue Oct 07, 2003 10:07 pm

Post by Dreamer#1 »

Thanks Adrian for your reply. :)
I was having trouble with my net so couldn't reply earlier.

  • Input:
    1
    7
    AA CA CA CA BA BA CCB

    My AC program's Output:
    A=5 B=0 C=1
This certainly doesn't go as per the constraint specified in the problem description which I've been talking about earlier.

You might say that there is no such input, and that might just infact be true. But if you've time can you please check the judge data to see if there is any output which corresponds to a solution with 1 or more numbers having leading zero(es).

I've checked my solution 4/5 times but still it won't be wise for me to say I'm sure that I'm not the one doing the mistake because that may very well be the case. :oops:

Thanks in advance.
Adrian Kuegel
Guru
Posts: 724
Joined: Wed Dec 19, 2001 2:00 am
Location: Germany

Post by Adrian Kuegel »

In this case I am absolutely sure that the test data are correct. I generated it myself, because Moni was ill and couldn't do it. I handle the leading zeros constraint in this way: for each input word (corresponding to some number) I mark the first character with a flag that indicates I can't assign a zero to it (but only if the word has length > 1 !!!).
Maybe try following input with your program:
2
3
A B AC
5
X ZZZAAFEXBX ZZZECAFCXX ZZZEAZXDAY YYYYYYYYYY

output should be:
A=1 B=9 C=0
A=1 B=8 C=7 D=2 E=4 F=5 X=0 Y=9 Z=3
Dreamer#1
Learning poster
Posts: 77
Joined: Tue Oct 07, 2003 10:07 pm

Post by Dreamer#1 »

"but only if the word has length > 1 !!!"

Oh no...how did I miss that part!!!

God help me. :D
But for now Adrian helped me. Thanks and sorry for wasting your time.
Post Reply

Return to “Volume 107 (10700-10799)”