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 1104. Don’t Ask Woman about Her Age

wjy have i got Memory Limit Exceed?
Posted by Koala 25 Jul 2002 18:04
program Prob1104;
const
  maxn=1000000;
var
  n,low,k,r,i:longint;
  a:array [1..maxn] of shortint;
  ch:char;
begin
  assign(input,'');
  assign(output,'');
  reset(input);
  n:=0;
  low:=0;
  while not eoln do
  begin
    read(ch);
    if ch<>' ' then
    begin
      inc(n);
      if ch in ['0'..'9']
        then a[n]:=ord(ch)-48
        else a[n]:=ord(ch)-55;
      if a[n]+1>low then low:=a[n]+1;
    end;
  end;
  close(input);

  if low<2 then low:=2;
  for k:=low to 36 do
  begin
    r:=0;
    for i:=1 to n do
    begin
      r:=r*k+a[i];
      r:=r mod (k-1);
    end;
    if r=0 then
    begin
      rewrite(output);
      writeln(k);
      close(output);
      halt;
    end;
  end;

  rewrite(output);
  writeln('No solution.');
  close(output);
end.
Re: wjy have i got Memory Limit Exceed?
Posted by Dinu Adrian Florin 30 Apr 2004 13:12
You got Memory Limit Exceed because you use an 1 Mb array
(max memory limit for this task) and you dont have any other
Memory available for your program.
I use only 17 bytes of variables and they report 373 Kb of
memory used