Pagini: [1]   În jos
  Imprimă  
Ajutor Subiect: 1135. Recruits  (Citit de 10301 ori)
0 Utilizatori şi 1 Vizitator pe acest subiect.
pkiulian
Strain


Karma: 0
Deconectat Deconectat

Mesaje: 1



Vezi Profilul
« : Noiembrie 30, 2012, 01:13:00 »

So what I am doing is to note 1 instead of > and 0 instead of <. Therefore if I have the configuration 10 then it will become 01. The 01 configuration doesn't change.
Therefore if I take the example from the problem I have

110010
101001
010101
001011
000111

So I see there is a shifting of the zero's to the left and a of one's to the right.
So I am saving in the beginning the positions of zero's in an array (zero[]) and the positions of the one's in another array (one[]).
then I consider k = one[0].

Therefore the all algorithm (after reading the data) looks practically like this

Cod:
k=one[0];
for (int i=0;i<z;i++){
    if ((zero[i]-k) >=0){
     result+=(zero[i]-k);
     k++;
    }
}

I think the complexity of this is even O(z) where z is the numbers of zero's.

The problem with this is that I obtain TL on test 15. Is there anything faster or is only my coding problme (java)?

Thank you!
« Ultima modificare: Decembrie 02, 2012, 21:41:07 de către Andrei Grigorean » Memorat
wefgef
Nu mai tace
*****

Karma: 1049
Deconectat Deconectat

Mesaje: 3.008


razboinicu' luminii


Vezi Profilul
« Răspunde #1 : Decembrie 02, 2012, 21:43:22 »

Try coding it in C++ and see if you still get TLE.
Memorat

omului i-au fost date instinctele pentru a supravietui, nu pentru a fi sclavul lor.
Pagini: [1]   În sus
  Imprimă  
 
Schimbă forumul:  

Powered by SMF 1.1.19 | SMF © 2006-2013, Simple Machines