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 1126. Magnetic Storms

Why I got 'Wrang answer'?
Posted by qwt 3 Apr 2002 16:07
var
  a:array[0..14000] of integer;
  b:array[0..25000] of integer;
  n,i,j,k,max:integer;

begin
  readln(n);
  fillchar(a,sizeof(a),0);fillchar(b,sizeof(b),0);    b[0]:=1;
  for i:=0 to n-2 do begin
    readln(a[i]);
    inc(b[a[i]]);
    if a[i]>max then max:=a[i];
  end;
  readln(j);
  while j>=0 do begin
    inc(i);
    i:=i mod n;
    dec(b[a[i]]);a[i]:=j;
    inc(b[j]);
    if j>max then max:=j;
    k:=max;
    if b[max]=0 then for max:=k-1 downto 0 do if b[max]>0 then break;
    writeln(max);
    readln(j);
  end;
end.
Re: Why I got 'Wrang answer'?
Posted by MadPsyentist/Sam 4 Apr 2002 12:06
I don't know your logic truely but I test your program (compiled under
DevPascal (FreePascal), Windows98SE) and found your program get
Runtime Error and Wrong Answer many time when the value of
measure is high. It didn't crash but the error message was redirected to
the output instead , I don't know why.

I randomly generate the test data and this is a case your program make
wrong output, but no Runtime Error
Input:
6
29261
440
1757
22684
2247
11022
25134
22643
6002
3108
16056
12612
29390
25192
6271
26467
7802
23059
1921
-1

My AC program output:
29261
25134
25134
25134
25134
25134
25134
29390
29390
29390
29390
29390
29390
26467

Your output:
29261
27029
27029
27029
27029
27029
27029
29390
29390
29390
29390
29390
29390
27029

If you edit your program and pass this test data but still get WA, you can
ask me for me test. My e-mail address is piyawut@se-ed.net.
I mean "more test" ,not "me test"
Posted by MadPsyentist/Sam 4 Apr 2002 12:08
> I don't know your logic truely but I test your program (compiled under
> DevPascal (FreePascal), Windows98SE) and found your program get
> Runtime Error and Wrong Answer many time when the value of
> measure is high. It didn't crash but the error message was redirected
to
> the output instead , I don't know why.
>
> I randomly generate the test data and this is a case your program
make
> wrong output, but no Runtime Error
> Input:
> 6
> 29261
> 440
> 1757
> 22684
> 2247
> 11022
> 25134
> 22643
> 6002
> 3108
> 16056
> 12612
> 29390
> 25192
> 6271
> 26467
> 7802
> 23059
> 1921
> -1
>
> My AC program output:
> 29261
> 25134
> 25134
> 25134
> 25134
> 25134
> 25134
> 29390
> 29390
> 29390
> 29390
> 29390
> 29390
> 26467
>
> Your output:
> 29261
> 27029
> 27029
> 27029
> 27029
> 27029
> 27029
> 29390
> 29390
> 29390
> 29390
> 29390
> 29390
> 27029
>
> If you edit your program and pass this test data but still get WA, you
can
> ask me for me test. My e-mail address is piyawut@se-ed.net.
Re: I mean "more test" ,not "me test"
Posted by acmkx 22 May 2005 14:57
MY Program's answer is the same as yours
But I still get WA
Here is my source:
var a:array[1..14000]of longint;
    remax:array[1..140]of longint;
    temp,m,i,count,block,max:longint;
procedure findmax;
 var i:longint;
 begin
  max:=0;
  for i:=1 to 140 do
   if(remax[i]>max)then max:=remax[i];
 end;
begin
 readln(m);
 fillchar(remax,sizeof(remax),0);
 max:=0;
 for I:=1 to m-1 do
  begin
   readln(a[i]);
   if a[i]>max then max:=a[i];
   block:=i div 100;
   if a[i]>remax[block+1] then remax[block+1]:=a[i];
  end;
 readln(a[m]);
 count:=m;
 while(a[count]<>-1)do
  begin
   if a[count]>max then max:=a[count];
   writeln(max);
   block:=count div 100;
   if(a[count]>remax[block+1])then remax[block+1]:=a[count];
   count:=count+1;
   if count=m+1 then count:=1;
   temp:=a[count];
   a[count]:=0;
   block:=count div 100;
   if(temp=remax[block+1])then
    begin
     remax[block+1]:=0;
     for i:=block*100+1 to (block+1)*100 do
      if a[i]>remax[block+1]then remax[block+1]:=a[i];
    end;
   if(temp=max)then findmax;
   readln(a[count]);
  end;
end.