Darko wrote:I just recoded this in C and it worked. Here's my Java solution that I couldn't get accepted (I have no idea what's wrong - a few people got it in Java today):
Trace the wollowing part of your code for sequence "12 -1000":
work() wrote:............for (inti = 0; i < n; i++) { ...............if (b[i] > 10000 || (i < n - 1 && b[i] >= b[i + 1])) { ..................ok = false; ..................break; ...............} ...............for (intj = i; j < n; j++) { ..................intsum = b[i] + b[j]; ..................if (seen[sum]) { ...........<-- here you access seen[-999] fori=0andj=2as b[2] is not checked for being negative yet. .....................ok = false; .....................break; ..................} ..................seen[sum] = true; ...............} ...............if (!ok) ..................break; ............}
nymo wrote:I checked the followings:
i. number[0] is >= 1 else not a B2-seq
ii. number [i + 1] > number else not a B2-seq
iii. using a boolean array checking for uniqueness
I must be missing something, too. But what is that?
Yes, you are right, but make sure you check i. and ii. before checking iii. to make sure you don't access negative indicies of the array.
program hhh;
var sum:array[0..40000] of boolean;
tab:array[1..200] of longint;
b,a,n,numb:longint;
niemoge:boolean;
procedure read_data;
begin
niemoge:=false;
readln(n);
for a:=0 to 40000 do sum[a]:=false;
for a:=1 to n do read(tab[a]); readln; readln;
for a:=2 to n do if (tab[a]<=tab[a-1]) then niemoge:=true;
if tab[1]<1 then niemoge:=true;
if niemoge=false then
begin
for a:=1 to n do
for b:=a to n do
if (sum[tab[a]+tab[b]]=false) then sum[tab[a]+tab[b]]:=true else
niemoge:=true;
end;
write('Case #',numb,': It is');
if niemoge=false then writeln(' a B2-Sequence.') else
writeln(' not a B2-Sequence.');
writeln;
end;
begin
while not eof do
begin
inc(numb);
read_data;
end;
end.
miras, make the following to changes to your above code:
1. write "read(n)" instead of "readln(n)";
2. write "while not eof and eoln do readln" instead of "readln; readln;".
Then you can get Accepted!! Probably there are invalid cases where number of elements != N...
7th Contest of Newbies Date: December 31st, 2011 (Saturday) Time: 12:00 - 16:00 (UTC) URL: http://uva.onlinejudge.org
Ecou wrote:That did not help, still WA. and <=100 5 digit numbers should have fitted easily.
Yes, but possibly the numbers could be separated by more than just one space... or even by some other whitespace such as tabs.
I don't see any error in your code. Maybe you could try to change the way you are reading the input. Try to read it by scanf() directly instead of using gets(). Write something like the following:
Case #1: It is not a B2-Sequence.
Case #2: It is a B2-Sequence.
Case #3: It is not a B2-Sequence.
Case #4: It is not a B2-Sequence.
Case #5: It is a B2-Sequence.
Case #6: It is not a B2-Sequence.
Case #7: It is not a B2-Sequence.
Case #8: It is not a B2-Sequence.
Case #9: It is a B2-Sequence.
Case #10: It is not a B2-Sequence.