ENG  RUSTimus Online Judge
Online Judge
Problems
Authors
Online contests
About Online Judge
Frequently asked questions
Site news
Webboard
Links
Problem set
Submit solution
Judge status
Guide
Register
Update your info
Authors ranklist
Current contest
Scheduled contests
Past contests
Rules
back to board

Discussion of Problem 1007. Code Words

Problem definition
Posted by Pavel Minev Penev 5 Oct 2000 18:17
Just an alert:

Are you aware that there are multiple solutions, e.g.:
from the sample input:

Input:

4
1011

Output 1:

1001

Output 2:

1111

My issue is that you don't mention anything about this in
the problem definition -- i.e. is any of the possible
solutions valid?
Re: Problem definition -- sorry for the useless question
Posted by Pavel Minev Penev 5 Oct 2000 18:54
> Just an alert:
>
> Are you aware that there are multiple solutions, e.g.:
> from the sample input:
>
> Input:
>
> 4
> 1011
>
> Output 1:
>
> 1001
>
> Output 2:
>
> 1111
>
> My issue is that you don't mention anything about this in
> the problem definition -- i.e. is any of the possible
> solutions valid?

Yes, no I noticed it in the problem definition. It is said:
"1. Any (but only one) symbol 0 is replaced by 1."

Excuse me, you all.

Pave;
but there still can be multiple solutions for some inputs
Posted by tjq(killer of zju) 5 Oct 2000 19:34
I guess the test data will have only one correct answer
Re: I don't think so.
Posted by Pavel Minev Penev 6 Oct 2000 15:09
I will try to proove this for you.

If you have a word one character shorter than expected, then
your ONLY choice is to insert a character somewhere.

If you have a word one character longer than expected, then
your ONLY choice is to delete a character somewhere.

If the word is the length expected, then if it has its
property, in order to change a character from it and
preserve its property, you have to change a bit one to bit
zero at position n+1, but you don't have such a bit.

If the word is the length expected and its property is
broken:
you need to convert bit one to bit zero at position k*(n+1)
+ (sum of positions of 1s in the broken word) % (n+1), but
since you don't have bits with numbers greater than n, then
your only solution is k=0, which makes:

(wrong bit position) = (sum of positons of 1s in the broken
word) % (n+1).

Let's name (sum of positions of 1s) "prop".

The first case:
If we insert a 1 in position "p" and there are "k" 1s after
this position, we increase "prop" by (k+p).
If we insert a 0 in position "p" and there are "k" 1s after
this position, we increase "prop" by (k).

If the first case has more than one solutions, then there
are more than one solutions to the following equation:

prop % (n+1) = k + i*p

where "i" is the bit we insert ("0" or "1").
If there are multiple solutions:

1. i = 0 and k remains the same changing p -> in this case
we would insert "0" beneath other zeros and this would not
give us multiple solutions, since it makes no difference
whether we would inser a "0" between the first and second
0s, or between the m-th and the (m+1)-st.

2. i = 1 and k + p = const -> this means: decreasing p by
one increases k by one. This is the case when we move
through a sequence of 1s and it makes no difference at wich
position we would insert "1" (just like in "1.").

Second case:
This is much like the first case, and I would leave it for
you.

Enjoy,
Pavel
Re: but there still can be multiple solutions for some inputs
Posted by Locomotive 13 Jan 2003 11:35
what do you say??????
1000 can be
both
1001
and
0000

which should be in output????
Re: I don't think so. 2 Pavel
Posted by Locomotive 13 Jan 2003 11:53
> I will try to proove this for you.
>
> If you have a word one character shorter than expected, then
> your ONLY choice is to insert a character somewhere.
>
> If you have a word one character longer than expected, then
> your ONLY choice is to delete a character somewhere.
>
> If the word is the length expected, then if it has its
> property, in order to change a character from it and
> preserve its property, you have to change a bit one to bit
> zero at position n+1, but you don't have such a bit.
>
> If the word is the length expected and its property is
> broken:
> you need to convert bit one to bit zero at position k*(n+1)
> + (sum of positions of 1s in the broken word) % (n+1), but
> since you don't have bits with numbers greater than n, then
> your only solution is k=0, which makes:
>
> (wrong bit position) = (sum of positons of 1s in the broken
> word) % (n+1).
>
> Let's name (sum of positions of 1s) "prop".
>
> The first case:
> If we insert a 1 in position "p" and there are "k" 1s after
> this position, we increase "prop" by (k+p).
> If we insert a 0 in position "p" and there are "k" 1s after
> this position, we increase "prop" by (k).
>
> If the first case has more than one solutions, then there
> are more than one solutions to the following equation:
>
> prop % (n+1) = k + i*p
>
> where "i" is the bit we insert ("0" or "1").
> If there are multiple solutions:
>
> 1. i = 0 and k remains the same changing p -> in this case
> we would insert "0" beneath other zeros and this would not
> give us multiple solutions, since it makes no difference
> whether we would inser a "0" between the first and second
> 0s, or between the m-th and the (m+1)-st.
>
> 2. i = 1 and k + p = const -> this means: decreasing p by
> one increases k by one. This is the case when we move
> through a sequence of 1s and it makes no difference at wich
> position we would insert "1" (just like in "1.").
>
> Second case:
> This is much like the first case, and I would leave it for
> you.
>
> Enjoy,
> Pavel

Hi Dear Pavel.
our problem is:
some answers
when length of input is the length we expect... (such as 1000 for n=4)
so we can change one bit from 1 to 0 (such as first bit in 1000) and
also
we can change another bit from 0 to 1 (such as 4th bit in 1000)...
and both of those work gives us correct answers
(0000 and 1001) are both correct.
so i think Ural grader should accept all answers...
but...
what is wrong with my prog?
see webboard...
thanks
Aidin_n7