ENG  RUS Timus Online Judge
Online Judge
Problems
Authors
Online contests
Site news
Webboard
Problem set
Submit solution
Judge status
Guide
Register
Authors ranklist
Current contest
Scheduled contests
Past contests
Rules
back to board

## Discussion of Problem 1019. Line Painting

WA 11
Posted by Ilya 30 Jan 2015 09:55
I've checked all the tests on the forum, but all of them actually wokred. What's wrong with the code?

type
Otrezok=record
beginning,ending:real;
colour:string;
end;

type
Point=record
mean,predel:real;
end;

var
a:array[0..50000] of Otrezok;
b:array[0..50002] of Point;
i,N,j,s:integer;
k,j1,j2,max,f1,f2:real;
t,f3:string;

function colour(x:real;H:integer):string;
var j:integer;
begin

for j:=0 to H do
begin
if (x>=a[j].beginning) and (x<=a[j].ending) and (a[j].colour=' w') then colour:='w';
if (x>=a[j].beginning) and (x<=a[j].ending) and (a[j].colour=' b') then colour:='b';
end;
end;

begin

a[0].beginning:=0;
a[0].ending:=1000000000;
a[0].colour:=' w';
for i:=1 to N do
begin
if f1<f2 then
begin
a[i].beginning:=f1;
a[i].ending:=f2;
a[i].colour:=f3;
end;
end;
for j:=1 to N do
begin
b[j].predel:=0;
b[j+N].predel:=0;
b[j].mean:=a[j].beginning;
b[j+N].mean:=a[j].ending;
end;
b[0].predel:=0;
b[0].mean:=0;

for i:=(2*N-1) downto 1 do
for j:=1 to i do
begin
if b[j].mean>b[j+1].mean then
begin
k:=b[j+1].mean;
b[j+1].mean:=b[j].mean;
b[j].mean:=k;
end;
if (b[j].mean=b[j+1].mean) then b[j+1].mean:=0
end;

for i:=1 to 2*N do
begin
if (b[i].mean<>0) and (colour(b[i].mean,N)<>colour(b[i].mean+0.1,N)) or (colour(b[i].mean,N)<>colour(b[i].mean-0.1,N)) then b[i].predel:=1;
if b[i].mean=0 then b[i].predel:=0;
end;
t:=colour(0,N);

s:=0;
for i:=0 to 2*N do
begin
if (b[i].predel=1) then
begin
s:=s+1;
k:=b[s].mean;
b[s].mean:=b[i].mean;
b[i].mean:=k;
end;
end;

for i:=s downto 0 do
b[i+1].mean:=b[i].mean;

b[s+2].mean:=1000000000;

max:=0;
b[0].mean:=0;

for i:=1 to s+2 do
begin
if t='w' then
begin
if (i mod 2)=0 then
begin
if (b[i].mean-b[i-1].mean)>max then
begin
max:=b[i].mean-b[i-1].mean;
j1:=b[i-1].mean;
j2:=b[i].mean;
end;
end;
end;
if t='b' then
begin
if (i mod 2)=1 then
begin
if b[i].mean-b[i-1].mean>max then
begin
max:=b[i].mean-b[i-1].mean;
j1:=b[i-1].mean;
j2:=b[i].mean;
end;
end;
end;
end;

write(Round(j1),' ',Round(j2));
end.