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 1007. Code Words

This is my program,but I got"Momory Limit Exceeded".Why?
Posted by try try try 7 Jul 2001 05:00
Var N   : Integer;
    C   : Array[0..1500] of Char;
    A   : Array[0..1500] of Integer;
    S   : Array[1..10] of String;
 Total  : Longint;

Procedure Main(X : Integer);
Var i,j : Longint;
Begin
  If X<N then
    Begin
      For i := 1 to N do
        If (Total+i+(A[X]-A[i-1])) mod (N+1) = 0 then
          Begin
            For j := 1 to i-1 do
              Write(C[j]);
            Write(1);
            For j := i to X do
              Write(C[j]);
            Writeln;
            Exit;
          End else If (Total+(A[X]-A[i-1])) mod (N+1) = 0
then
                     Begin
                        For j := 1 to i-1 do
                          Write(C[j]);
                        Write(0);
                        For j := i to X do
                          Write(C[j]);
                        Writeln;
                        Exit;
                     End;
    End;
  If X>N then
    Begin
      For i := 1 to N+1 do
        If (Total-(A[X]-A[i])-(A[i]-A[i-1])*i) Mod (N+1)=0
then
          Begin
            For j := 1 to i-1 do
              Write(C[j]);
            For j := i+1 to X do
              Write(C[j]);
            Writeln;
            Exit;
          End;
    End;
  If X=N then
    Begin
      If Total Mod (N+1)=0 then
        Begin
          For j := 1 to N do
            Write(C[j]);
          Writeln;
          Exit;
        End;
      For i := 1 to X do
        If C[i]='1' then
          If (Total-i) Mod (N+1)=0 then
            Begin
              C[i] := '0';
              For j := 1 to X do
                Write(C[j]);
              Writeln;
              Exit;
            End;
    End;
End;


Procedure Init;
Var i,j,k,l : Longint;
    BB      : Boolean;
    Long    : Byte;
Begin
  Readln(N);
  Long := (N+1) Div 255;
  If (N+1) mod 255<>0 then Inc(Long);
  Repeat
    Fillchar(S,Sizeof(S),0);
    For i := 1 to Long do
      Read(S[i]);
    If Pos('0',S[1])=0 then
      If Pos('1',S[1])=0 then Break;
    Readln;
    j := 0;
    Fillchar(A,Sizeof(A),0); Total := 0;
    For i := 1 to Long do
      For k := 1 to Length(S[i]) do
        Begin
          If S[i][k] in ['0','1'] then
            Begin
              Inc(j);
              A[j] := A[j-1]+Ord(S[i][k])-48;
              Inc(Total,(Ord(S[i][k])-48)*j);
              C[j] := S[i][k];
            End;
        End;
    Main(j);
  Until Eof;
End;

Begin
  Init;
End.
Re: This is my program,but I got
Posted by Band of Brothers 12 Aug 2001 18:38
If you write:
S: array[1..10] of string[255];
Then everything is all right.
Because Ural use a compiler like Delphi,so that string
means ANSI string.