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 1047. Simple Calculations

Help! My program got Memory Limit!
Posted by Tang RZ 3 Jun 2004 10:46
This is my program:
var
  a,c:array [0..3001] of real;
  n:integer;

procedure init;
var
  i:integer;
begin
  read(n);
  read(a[0],a[n+1]);
  for i:=1 to n do
    read(c[i]);
end;

function work(i:integer):real;
begin
  if i=0 then work:=a[0] else
  if i=n+1 then work:=a[n+1] else
  work:=(work(i-1)+work(i+1))/2-c[i];
end;

procedure print;
begin
  writeln(work(1):0:2);
end;

begin
  init;
  print;
end.
Re: Help! My program got Memory Limit!
Posted by marina_ufa 3 Jun 2004 14:49
Your algoritmh not correct again. It very long. This problem solve with other algoritmh.
Used that a[0] = 2*a[1] + 2*c[1] - a[2] = 3*a[2] - 2*a[3] + 2*c[1] + 4*c[2], etc.