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 1021. Sacrament of the Sum

Problem 1021 is under investigation. (+)
Posted by Sandro (USU) 20 Mar 2007 00:15
In fact many of you got AC with O(N1*N2) solution. Some new tests were added and some more will be added soon. This problem had very simple O(N) and O(N*log N) solutions but unfortunately very weak tests. 756 authors had already lost their AC.
Re: Problem 1021 is under investigation. (+)
Posted by Sandro (USU) 20 Mar 2007 11:13
Extra tests were added and Time Limit was decreased to 1 second. Because of limitations [-32768, 32767] some O(N^2) solutions still have AC, but these limitations will not be changed. Investigation is finished. :)
Re: Problem 1021 is under investigation. (+)
Posted by AlMag 20 Mar 2007 17:10
Are the limits the same?
I have O(n1+n2) and TLE#8
Is it too slow?!
Re: Problem 1021 is under investigation. (+)
Posted by Sandro (USU) 20 Mar 2007 21:39
Your algo is correct. Sorry for wrong verdict. This was a system bug.
Re: Problem 1021 is under investigation. (+)
Posted by Evgenij Makarov (Vologda SPU#2) 26 Mar 2007 17:19
On 3rd test my program get time 0.14 but system says "Time limit exceeded"..

Is this a bug?

I try pass problem again, and got AC...

Edited by author 26.03.2007 23:29
Why They Have Changed Tests
Posted by Shady TKTL 1 Apr 2007 19:48
My solution got AC by tnow it TL on 4 test
Thise code for those who can answer to my problem

var a:array[1..50001]of integer;
    n,i,j,k,m:longint;
begin read(n);
      for i:=1 to n do read(a[i]);
      read(m);
      for i:=1 to m do
          begin read(k);
                for j:=1 to n do
                    if (a[j]+k=10000) then
                       begin write('YES');
                             halt(0);
                       end;
          end;
      write('NO');
end.
Re: Why They Have Changed Tests
Posted by Samsonov Alex [USU] 1 Apr 2007 19:50
Your solution complexity is O(N*M), which is too slow. Try to find a better algorithm. Good luck!
Re: Why They Have Changed Tests
Posted by mathfrog 26 Aug 2007 20:27
 i got one with O(nlogn) but what the O(n) one ? you mean that we use hash to search ?
What's test 5
Posted by Asker_Kazharov 27 Aug 2007 17:25
I use binary search. But I have WE on test 5.
What's problem? Solution complexity is O(n+m).
Re: Why They Have Changed Tests
Posted by DixonD (Lviv NU) 28 Aug 2007 17:30
Just use array of bool
Re: Why They Have Changed Tests
Posted by Bobur 5 Dec 2007 18:48
here is my code and i've time limit test 10.
begin
  read(n);
  for i := 1 to n do
  read(a[i]);
  q := false;

  read(m);
  q1 := true;
  read(x);
  if x+a[n]<10000 then q1 := false
  else  begin   i := n;
      repeat
        if x+a[i]=10000 then q := true;
        i := i - 1;
      until (i=0) or (x+a[i]<10000);
        end;

  if q1 then
    begin
  for j := 1 to m-1 do
    begin
      read(x);
        i := n;
        repeat
        if x+a[i]=10000 then q := true;
        i := i - 1;
        until (i=0) or (x+a[i]<10000);
    end;
    end
  else  for j := 1 to m-1 do
          read(x);
  if q then write('YES')
  else write('NO');
end.
who can give me more correct than mine, pls!!
Re: Why They Have Changed Tests
Posted by Alias (Alexander Prudaev) 5 Dec 2007 23:32
your solution is too slow
there is O(n + m) solution
for example
4
5 7 10 15
5
[and some numbers]
at first you can read first group of 4 numbers (5, 7, 10,15)
and while you read second group you can easy check
is it 9995, 9993, 9990, 9985 or not

after reading next integer from second group
you dont need to check all 4 numbers.
you can do it fast just using array of boolean
Re: Why They Have Changed Tests
Posted by Bobur 7 Dec 2007 07:26
thanks!!, but I find new algo
begin
  read(n);
  for i := 1 to n do
  read(a[i]);

  q := false;
  j := 0;
  read(m);
  repeat
    inc(j);
    read(x);           i1 := 1;   ni := n;
      if (a[i1]+x<=10000) and (a[ni]+x>=10000) then
        begin  i := 0;
          repeat
          inc(i);
        if a[ni div 2]+x<=10000 then i1 := ni div 2
        else ni := ni div 2;
          until (i=10) or (ni-i1<=3);

     for i := i1  to ni do
     if a[i]+x=10000 then q := true;
       end;
  until (q) or (a[n]<=10000) or (j=m);
  if q then write('YES')
  else write('NO');
end.
but i've WA#3 now!!
Re: Why They Have Changed Tests
Posted by Madhav 13 Jun 2008 02:07
using a bool array of length 65000 will solve it very very fast.//idea of bucket sort

Edited by author 13.06.2008 02:08