11179 - Bit Stream
Moderator: Board moderators
11179 - Bit Stream
I couldn't find any solution without brute forcing over all the chunks.
Find an efficient way to deal with long sequences of chunks consisting of only 0's or only 1's.
(Hint: some ideas behind problem 11149 could help here.)
(Hint: some ideas behind problem 11149 could help here.)
I am still wa. Here are some of the small cases that I have tried:
I think they are correct. It is hard to check big cases by myself.
Code: Select all
1 5 100 2 0 1 0
1 5 100 2 0 0 1 0
2 5 100 2 0 0 1 0
2 5 100 2 1 0 1 0
1 5 100 2 1 0 1 0
0
Code: Select all
Bitstream 1: Compression OK
Bitstream 2: Compression OK
Bitstream 3: Invalid Length
Bitstream 4: Invalid Length
Bitstream 5: Invalid Checksum
I followed your advice and write a brute force program, but it gives the same results for my cases as my wa solution. Can you see if my brute force code is correct? It will also be great if you can send me your brute force code.
Code: Select all
var
L, n, m, C, sum, check_digit, chunk_value : qword;
b, i, j, tcase, num_chunks, digit : longint;
position, start : int64;
chunk_length : array[1..100008] of longint;
padding : boolean;
begin
tcase := 0;
while (not eof) do begin
read(L);
if (L = 0) then break;
inc(tcase);
read(b, n, m, C);
num_chunks := 1;
read(chunk_length[1]);
sum := chunk_length[1];
repeat
inc(num_chunks);
read(chunk_length[num_chunks]);
sum := sum + chunk_length[num_chunks];
until chunk_length[num_chunks] = 0;
if (L <> sum) then
writeln('Bitstream ',tcase,': Invalid Length')
else begin
n := n mod m;
digit := 0;
chunk_value := 0;
check_digit := 0;
padding := false;
start := -1;
for i := 1 to num_chunks-1 do begin
for j := 1 to chunk_length[i] do begin
chunk_value := chunk_value + chunk_value + digit;
start := start + 1;
padding := true;
position := start mod b;
if (position = b-1) then begin
check_digit := ((check_digit*n) mod m+chunk_value mod m) mod m;
chunk_value := 0;
padding := false;
end;
end;
digit := 1-digit;
end;
if (padding) then begin
position := start mod b;
for i := 1 to (b-1)-position do
chunk_value := chunk_value + chunk_value; (* Append zeros *)
check_digit := ((check_digit*n) mod m+chunk_value mod m) mod m;
end;
if (check_digit = C) then
writeln('Bitstream ',tcase,': Compression OK')
else
writeln('Bitstream ',tcase,': Invalid Checksum');
end;
end;
end.
Hi,
your code looks ok to me. Does it give same result as your program for high chunk lenghts?
Compression OK should be output for
Cu, Erik 
your code looks ok to me. Does it give same result as your program for high chunk lenghts?
Compression OK should be output for
Code: Select all
640000 32 1234567890 1987654320 1671853665
320000 320000 0

Doesn't the input says that chunk length <= 100000? Anyway, I get the correct result for both my brute force program and my efficient program. Still I am getting wa. Shall I just give up?Erik wrote:Hi,
your code looks ok to me. Does it give same result as your program for high chunk lenghts?
Compression OK should be output forCu, ErikCode: Select all
640000 32 1234567890 1987654320 1671853665 320000 320000 0

Getting WA
Can someone help with some tricky test cases.
I find my soln gives same result as brutforce in small cases.
I find my soln gives same result as brutforce in small cases.
-
- New poster
- Posts: 5
- Joined: Fri Jan 25, 2008 9:27 pm