|
|
back to boardWhy wrong answer??? Sorting is simple! Can anyone tell us, why our program is wrong? After sorting, this is a very simple task! We sort intervals by Ts (if equals Ts, by Te). Check it please! P.S. And why judge say, that our program request 53K memory??? Andrey Popyk & Sergey Snitsar. CONST Dim = 100007; TYPE TLine = record L,R:integer end; TYPE Arr = Array[1..Dim] of TLine; VAR A:Arr; N,Res:longint; PROCEDURE Shell; var M,i,j:longint; P:TLine; bool:boolean; begin M:=N; repeat M:=(M+1) div 2; for i:=M+1 to N do begin j:=i-M; p:=A[i]; bool:=true; while (j>=1) and bool do begin if (A[j].L>p.L) or (A[j].L=p.L) and (A[j].R>p.R) then begin A[j+M]:=A[j]; j:=j-M end else bool:=false end; A[j+M]:=p; end; until M=1; end; PROCEDURE ReadData; var i:longint; begin readln(N); for i:=1 to N do readln(A[i].L,A[i].R); end; PROCEDURE Solve; var Curr,i:longint; begin Res:=0; Curr:=0; for i:=1 to N do if A[i].L>Curr then begin inc(Res); Curr:=A[i].R end; end; BEGIN { assign(INPUT,'1.txt'); reset(INPUT);} ReadData; Shell; Solve; writeln(Res); END. Sorting isn't correct here, even more you don't need a 100,000 array (30,000 is enough :)) > Can anyone tell us, why our program is wrong? > After sorting, this is a very simple task! > We sort intervals by Ts (if equals Ts, by Te). > Check it please! > > P.S. And why judge say, that our program request 53K memory??? > > Andrey Popyk & Sergey Snitsar. > > > CONST Dim = 100007; > TYPE TLine = record L,R:integer end; > > TYPE Arr = Array[1..Dim] of TLine; > VAR A:Arr; > N,Res:longint; > > PROCEDURE Shell; > var M,i,j:longint; > P:TLine; > bool:boolean; > begin > M:=N; > repeat > M:=(M+1) div 2; > for i:=M+1 to N do > begin > j:=i-M; p:=A[i]; bool:=true; > while (j>=1) and bool do > begin > if (A[j].L>p.L) or (A[j].L=p.L) and (A[j].R>p.R) > then begin A[j+M]:=A[j]; j:=j-M end > else bool:=false > end; > A[j+M]:=p; > end; > until M=1; > end; > > > PROCEDURE ReadData; > var i:longint; > begin > readln(N); > for i:=1 to N do readln(A[i].L,A[i].R); > end; > > PROCEDURE Solve; > var Curr,i:longint; > begin > Res:=0; > Curr:=0; > for i:=1 to N do > if A[i].L>Curr then begin inc(Res); Curr:=A[i].R end; > end; > > BEGIN > { assign(INPUT,'1.txt'); reset(INPUT);} > ReadData; > Shell; > Solve; > writeln(Res); > END. > |
|
|