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 1005. Stone Pile

I use DP, but get WA#4!!!
Posted by Akshin Salimov 24 Apr 2005 14:05
var
  a:array[1..20] of longint;
  b:array[1..440] of longint;
  max,n,nn,i,s,s2:longint;

procedure readdata;
begin
  assign(input,'in.in');
  reset(input);
  readln(n);
  s:=0;
  for i:=1 to n do
  begin
  readln(a[i]);
  s:=s+a[i];
  end;
  s2:=s div 2;
  close(input);
end;

procedure writedata;
begin
  writeln(abs( (s-max)-max ));
end;

function check(l:longint):boolean;
var
  i:integer;
  bb:boolean;

begin
  bb:=false;
  for i:=1 to nn do
  if b[i]=l then
  begin
    bb:=true;
    break;
  end;
  check:=false;
end;

procedure sum(l:longint);
var
  i,nnn:longint;

begin
  nnn:=nn;
  for i:=1 to nnn do
  begin
    if not check(b[i]+l) then
    begin
      inc(nn);
      b[nn]:=b[i]+l;
      if (b[nn]<=s2) and (b[nn]>max) then
      max:=b[nn];
    end;
  end;
end;

begin
  readdata;
  nn:=0;  max:=-maxint;
  for i:=1 to n do
  begin
    if not check(a[i]) then
    begin
      inc(nn);
      b[nn]:=a[i];
      sum(a[i]);
    end;
  end;
  writedata;
end.
Re: I use DP, but get WA#4!!!
Posted by Bidea Cristian 24 Apr 2005 18:28
Please explain what you are doing! I have an AC solution in C+ + for this problem, if you want I can mail it to you.
+++++++++++++++++
Posted by Виктор Крупко 24 Apr 2005 22:25
3
1
1
1
{1} YOUR (65...)
2
1
1
{0} YOUR (65...)
Re: +++++++++++++++++
Posted by SSS 24 Apr 2005 23:30
{Виктор, история повторяется}

Here is program which gives correct answer for your tests, but I still get WA!

var
a:array[1..20] of longint;
b:array[1..440] of longint;
max,n,nn,i,s,s2:longint;

procedure readdata;
begin
readln(n);
s:=0;
for i:=1 to n do
begin
readln(a[i]);
s:=s+a[i];
end;
s2:=s div 2;
end;

procedure writedata;
begin
writeln(abs( abs(s-max)-abs(max) ));
end;

function check(l:longint):boolean;
var
i:integer;
bb:boolean;

begin
bb:=false;
for i:=1 to nn do
if b[i]=l then
begin
bb:=true;
exit;
end;
check:=false;
end;

procedure sum(l:longint);
var
i,nnn:longint;

begin
nnn:=nn;
for i:=1 to nnn do
begin
if not check(b[i]+l) then
begin
if (b[nn]<=s2) and (b[nn]>max) then
max:=b[nn];
inc(nn);
b[nn]:=b[i]+l;
if (b[nn]<=s2) and (b[nn]>max) then
max:=b[nn];
end;
end;
end;

begin
readdata;
nn:=0; max:=-maxint;
for i:=1 to n do
begin
if not check(a[i]) then
begin
inc(nn);
b[nn]:=a[i];
sum(a[i]);
end;
end;
writedata;
end.
Re: +++++++++++++++++
Posted by Виктор Крупко 25 Apr 2005 00:01
readln[a[i]] >>read[a[i]] (change)
2
323
2222
1899 (1253?????As so it has turned out)
3
2
22
222
198
Re: +++++++++++++++++
Posted by SSS 25 Apr 2005 12:24
Here is program which gives correct answer for your tests, BUT I still get WA! ;(

When I change readln to read I got Crash(Access Violation).

var
a:array[1..20] of longint;
b:array[1..440] of longint;
max,n,nn,i,s,s2:longint;

procedure readdata;
begin
{
assign(input,'in.in');
reset(input);
}
readln(n);
s:=0;
for i:=1 to n do
begin
readln(a[i]);
s:=s+a[i];
end;
s2:=s div 2;
{
close(input);
}
end;

procedure writedata;
begin
writeln(abs( abs(s-max)-abs(max) ));
end;

function check(l:longint):boolean;
var
i:integer;
bb:boolean;

begin
bb:=false;
for i:=1 to nn do
if b[i]=l then
begin
bb:=true;
exit;
end;
check:=false;
end;

procedure sum(l:longint);
var
i,nnn:longint;

begin
nnn:=nn;
for i:=1 to nnn-1 do
begin
if ((b[i]+l)<=s2) and (not check(b[i]+l)) then
begin
if (b[nn]<=s2) and (b[nn]>max) then
max:=b[nn];
inc(nn);
b[nn]:=b[i]+l;
if (b[nn]<=s2) and (b[nn]>max) then
max:=b[nn];
end;
end;
end;

begin
readdata;
nn:=0; max:=a[1];
for i:=1 to n do
begin
if not check(a[i]) then
begin
inc(nn);
b[nn]:=a[i];
sum(a[i]);
end;
end;
writedata;
end.


Edited by author 25.04.2005 12:29
Re: +++++++++++++++++
Posted by Виктор Крупко 25 Apr 2005 22:19
3
1
2
1
0


4
2
2
2
2
0
Reconsider the algorithm
Algorithm was reconsidered, still WA!
Posted by Akshin Salimov 26 Apr 2005 16:17
Algorithm was reconsidered, still WA!
This program gives correct answer for your tests, but ... WA!

var
a:array[1..20] of longint;
b:array[1..440] of longint;
max,n,nn,i,s,s2:longint;

procedure readdata;
begin
{
assign(input,'in.in');
reset(input);
}
readln(n);
s:=0;
for i:=1 to n do
begin
readln(a[i]);
s:=s+a[i];
end;
s2:=s div 2;
{
close(input);
}
end;

procedure writedata;
begin
writeln(abs( abs(s-max)-abs(max) ));
end;

function check(l:longint):boolean;
var
i:integer;
bb:boolean;

begin
bb:=false;
for i:=1 to nn do
if b[i]=l then
begin
bb:=true;
exit;
end;
check:=false;
end;

procedure sum(l:longint);
var
i,nnn:longint;

begin
nnn:=nn;
for i:=1 to nnn-1 do
begin
if ((b[i]+l)<=s2) and (not check(b[i]+l)) then
begin
if (b[nn]<=s2) and (b[nn]>max) then
max:=b[nn];
inc(nn);
b[nn]:=b[i]+l;
if (b[nn]<=s2) and (b[nn]>max) then
max:=b[nn];
end;
end;
end;

begin
readdata;
nn:=0; max:=a[1];
for i:=1 to n do
begin
if not check(a[i]) then
begin
inc(nn);
b[nn]:=a[i];
if (b[nn]<=s2) and (b[nn]>max) then max:=b[nn];
sum(a[i]);
end;
end;
writedata;
end.

Edited by author 26.04.2005 16:19
Замени readln(a[i])>>>read(a[i]) и (b:array[1..10000] of longint)
Posted by Виктор Крупко 26 Apr 2005 22:51
Crash (ACCESS_VIOLATION)test 4
write on mail

Edited by author 26.04.2005 22:53