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 1212. Battleship

I need your help.
Posted by Alexander Bovkun 6 Apr 2005 02:00
I have tried to submit my program and got Wrong Answer on test 23. Also I have already read a topic below, but still WA. Give me some tests or tell what is wrong with my program:

{$A+,B-,D+,E+,F-,G-,I+,L+,N-,O-,P-,Q-,R+,S+,T-,V+,X+}
{$M 16384,0,655360}
Program SeaBattle;
Type Point=Record
             X,Y:Integer;
           End;
Var N,M:Integer;L:Byte;
    Points:Array[1..200] Of Point;PointsCount:Byte;
    K:Byte;
    PointersOnBeginning:Array[1..30001] Of Byte;
    I,J,P,R,S,W:Integer;
    Result:LongInt;

Procedure ReadData;
Var ShipX,ShipY,ShipLen:Integer;
    ShipDir:Char;

  Procedure AddPoint(X,Y:Integer);
  Var Index:Byte;
  Begin
    For Index:=1 To PointsCount Do If (Points[Index].X=X) And (Points[Index].Y=Y) Then Exit;

    Inc(PointsCount);
    Points[PointsCount].X:=X;
    Points[PointsCount].Y:=Y;
  End;

Begin
  ReadLn(M,N,L);
  For I:=1 To L Do Begin
    Read(ShipX,ShipY,ShipLen);
    For J:=1 To 2 Do Read(ShipDir);
    ReadLn;

    If ShipDir='H' Then Begin
      For J:=1 To ShipLen Do AddPoint(ShipX+J-1,ShipY);

      If ShipY>=2 Then
        For J:=1 To ShipLen Do AddPoint(ShipX+J-1,ShipY-1);
      If ShipY<M Then
        For J:=1 To ShipLen Do AddPoint(ShipX+J-1,ShipY+1);

      If ShipX>=2 Then Begin
        If ShipY>=2 Then AddPoint(ShipX-1,ShipY-1);
        AddPoint(ShipX-1,ShipY);
        If ShipY<M Then AddPoint(ShipX-1,ShipY+1);
      End;

      If ShipX+ShipLen<=N Then Begin
        If ShipY>=2 Then AddPoint(ShipX+ShipLen,ShipY-1);
        AddPoint(ShipX+ShipLen,ShipY);
        If ShipY<M Then AddPoint(ShipX+ShipLen,ShipY+1);
      End;
    End Else Begin
      For J:=1 To ShipLen Do AddPoint(ShipX,ShipY+J-1);

      If ShipX>=2 Then
        For J:=1 To ShipLen Do AddPoint(ShipX-1,ShipY+J-1);
      If ShipX<N Then
        For J:=1 To ShipLen Do AddPoint(ShipX+1,ShipY+J-1);

      If ShipY>=2 Then Begin
        If ShipX>=2 Then AddPoint(ShipX-1,ShipY-1);
        AddPoint(ShipX,ShipY-1);
        If ShipX<N Then AddPoint(ShipX+1,ShipY-1);
      End;

      If ShipY+ShipLen<=M Then Begin
        If ShipX>=2 Then AddPoint(ShipX-1,ShipY+ShipLen);
        AddPoint(ShipX,ShipY+ShipLen);
        If ShipX<N Then AddPoint(ShipX+1,ShipY+ShipLen);
      End;
    End;
  End;
  ReadLn(K);
End;

Procedure Solve;

  Procedure SwapPoints(Var A,B:Point);
  Var TmpPoint:Point;
  Begin
    TmpPoint:=A;
    A:=B;
    B:=TmpPoint;
  End;

  Function GetCount(A:Integer):Integer;
  Begin
    If A>=K Then GetCount:=A-K+1 Else GetCount:=0;
  End;

Begin
  For I:=1 To M Do PointersOnBeginning[I]:=0;
  For I:=1 To PointsCount-1 Do
    For J:=I+1 To PointsCount Do If Points[I].Y>Points[J].Y Then SwapPoints(Points[I],Points[J]);

  J:=1;If PointsCount>=1 Then PointersOnBeginning[Points[J].Y]:=J;
  For I:=2 To PointsCount Do If Points[I].Y<>Points[J].Y Then Begin
    For P:=J To I-2 Do
      For R:=P+1 To I-1 Do If Points[P].X>Points[R].X Then SwapPoints(Points[P],Points[R]);

    J:=I;
    PointersOnBeginning[Points[J].Y]:=J;
  End;

  If J<>PointsCount Then
    For P:=J To PointsCount-1 Do
      For R:=P+1 To PointsCount Do If Points[P].X>Points[R].X Then SwapPoints(Points[P],Points[R]);

  For J:=1 To M Do Begin
    W:=1;
    If PointersOnBeginning[J]<>0 Then Begin
      For I:=PointersOnBeginning[J] To PointsCount Do If Points[I].Y=J Then Begin
        Result:=Result+GetCount(Points[I].X-W);
        W:=Points[I].X+1;

        If Points[I].Y>J Then Break;
      End;
    End;
    Result:=Result+GetCount(N-W+1);
  End;

  If K=1 Then Exit;

  For I:=1 To N Do PointersOnBeginning[I]:=0;
  For I:=1 To PointsCount-1 Do
    For J:=I+1 To PointsCount Do If Points[I].X>Points[J].X Then SwapPoints(Points[I],Points[J]);

  J:=1;If PointsCount>=1 Then PointersOnBeginning[Points[J].X]:=J;
  For I:=2 To PointsCount Do If Points[I].X<>Points[J].X Then Begin
    For P:=J To I-2 Do
      For R:=P+1 To I-1 Do If Points[P].Y>Points[R].Y Then SwapPoints(Points[P],Points[R]);

    J:=I;
    PointersOnBeginning[Points[J].X]:=J;
  End;

  If J<>PointsCount Then
    For P:=J To PointsCount-1 Do
      For R:=P+1 To PointsCount Do If Points[P].Y>Points[R].Y Then SwapPoints(Points[P],Points[R]);

  For J:=1 To N Do Begin
    W:=1;
    If PointersOnBeginning[J]<>0 Then Begin
      For I:=PointersOnBeginning[J] To PointsCount Do If Points[I].X=J Then Begin
        Result:=Result+GetCount(Points[I].Y-W);
        W:=Points[I].Y+1;

        If Points[I].X>J Then Break;
      End;
    End;
    Result:=Result+GetCount(M-W+1);
  End;
End;

Procedure WriteData;
Begin
  WriteLn(Result);
End;

Begin
  ReadData;
  Solve;
  WriteData;
End.