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

Common Board

P1212 WA. HELP
Posted by I am david. Tabo. 17 Nov 2002 21:37
var
  cur, i, j, n, m, l, k, r: longint;
  ships: array[1..100] of
    record
      x, y, d: longint;
      o: char;
    end;
  st: string;
  total: extended;
  curline, vempty, hempty: array[0..30001] of boolean;
{}
begin
{  assign( input, 'p1212.in' ); reset( input );
  assign( output, 'p1212.out' ); rewrite( output );}
  {}
  readln( n, m, l );
  for i := 1 to l do
    begin
      read( ships[i].x, ships[i].y, ships[i].d );
      readln( st );
      if ( ( pos( 'V', st ) = 0 ) and ( pos( 'v', st ) = 0 ) ) then
        ships[i].o := 'H'
      else
        ships[i].o := 'V';
   end;
  read( k );
  {}
  for i := 0 to 30001 do
    begin
      curline[i] := true;
      vempty[i] := true;
      hempty[i] := true;
    end;
  {}
  for i := 1 to l do
    begin
      case ( ships[i].o ) of
        'V':
          begin
            for j := ( ships[i].y - 1 ) to ( ships[i].y + ships
[i].d ) do
              hempty[j] := false;
            vempty[ships[i].x - 1] := false;
            vempty[ships[i].x] := false;
            vempty[ships[i].x + 1] := false;
          end;
        'H':
          begin
            for j := ( ships[i].x - 1 ) to ( ships[i].x + ships
[i].d ) do
              vempty[j] := false;
            hempty[ships[i].y - 1] := false;
            hempty[ships[i].y] := false;
            hempty[ships[i].y + 1] := false;
          end;
      end;
    end;
  {}
  total := 0;
  {}
  for i := 1 to n do
    begin
      if ( hempty[i] ) then
        total := total + m - k + 1
      else
        begin
          for j := 0 to 30001 do
            curline[j] := true;
          curline[0] := false;
          curline[m+1] := false;
          for j := 1 to l do
            begin
              case ( ships[j].o ) of
                'V':
                  begin
                    if ( ( ships[j].y - 1 <= i ) and ( ( ships[j].y +
ships[j].d ) >= i ) ) then
                      begin
                        curline[ships[j].x-1] := false;
                        curline[ships[j].x] := false;
                        curline[ships[j].x+1] := false;
                      end;
                  end;
                'H':
                  begin
                    if ( ( ( ships[j].y - 1 ) = i ) or ( ( ships
[j].y ) = i ) or ( ( ships[j].y + 1 ) = i ) ) then
                      for r := ( ships[j].x - 1 ) to ( ships[j].x +
ships[j].d ) do
                        curline[r] := false;
                  end;
              end;
            end;
          {}
          cur := 0;
          for j := 1 to ( m + 1 ) do
            if ( curline[j] ) then
              inc( cur )
            else
              begin
                if ( cur >= k ) then
                  total := total + cur - k + 1;
                cur := 0;
              end;
        end;
    end;
  {}
  for i := 1 to m do
    begin
      if ( vempty[i] ) then
        total := total + n - k + 1
      else
        begin
          for j := 0 to 30001 do
            curline[j] := true;
          curline[0] := false;
          curline[n+1] := false;
          for j := 1 to l do
            begin
              case ( ships[j].o ) of
                'H':
                  begin
                    if ( ( ships[j].x - 1 <= i ) and ( ( ships[j].x +
ships[j].d ) >= i ) ) then
                      begin
                        curline[ships[j].y-1] := false;
                        curline[ships[j].y] := false;
                        curline[ships[j].y+1] := false;
                      end;
                  end;
                'V':
                  begin
                    if ( ( ( ships[j].x - 1 ) = i ) or ( ( ships
[j].x ) = i ) or ( ( ships[j].x + 1 ) = i ) ) then
                      for r := ( ships[j].y - 1 ) to ( ships[j].y +
ships[j].d ) do
                        curline[r] := false;