← Back to topics
Topic

z-javelin

D
Daniel93
Can someone explain how to solve this problem. I tried simple brute-force, and there worked 17/25 test cases.
A
Al3kSaNdaR
I need help, too. I've also tried simple bf and my solution passes 10/25 test cases. :-(
b
boba5551
Official solution is to use data structures, but it can be solved in another way, IMHO, a bit simpler. However, try to solve an easier problem: for each try, let t_i = 0, so you have k_i and t1_i.
b
boba5551
@turgond: I have solved the problem using cumulative tables, so you can look at my solution (if you have solved it already). It depends how you store information in cumulative tables.
t
turgond
I'll look at your soltion as soon as I get mine to work :) Your tutorial at TC really helped me understand them!
b
boris4
I solved it with smart brute force.
i
iggy91
Define "smart brute force"... Maybe you're on to some inovative algorithmic method, who knows? :) Image that... BBF - Boris' Brute Force :P
p
picsel
Dinamicko
i
iggy91
@ picsel:
Very... descriptive post.
T
Tavo92
Give us more hints, I can't work out a nice solution.
D
Daniel93
@boris
Can you describe your smart brute force?
p
picsel
Position X is possible if position X - ki (where Ki is a number from 1 to 10) is possible.
p
picsel
But not always, you gotta keep track of ti. For every X + ki, ti is ti-1.
Something like that :)
t
tgudlek
My solution is very simple and works for all test cases (even though it's way too slow for some cases I tested locally ).

I loop through possible distances ( from 1 to 100 000, as it's said in the problem statement ) and try if this distance can be obainted from one of the runs ( if (distance - t1i) is divisible with ki and (distance - t1i) / ki <= ti ).
D
Daniel93
Very interesting. Thx tgudlek, I will try it as soon as possible.
R
RobertGerbicz
To turgond:
"All the forum posts should be in English"
t
turgond
hard getting used to, if u look at the forum u'll see everything was in serbian ;) the idea I presented was to use 45 cumulative index trees, to save by k and modulo k
b
boba5551
@turgond: Please, post the last question in English and I will remove the previous one.

However, you don't need 90 cumulative tables. Most of those cumulative tables (in your case) will be sparse, so you need only 10 that are fully used.
That what you know is:
t1 is filled, t1 + k is filled, t1 + 2*k is filled and so on. What if you consider t1, t1+k, t1+2*k and so on as adjacent numbers? Can you divide one of your cumulative tables to store this kind of adjacent numbers?
t
turgond
hmm, thought of that, but it seemed to me like it would be a mess with those binary operators, will give it a try, thanks a lot!!!
b
boba5551
You will not have a mess with binary operation. Ok, let's take an example with k = 3 and maxn = 20; and let's put numbers in this way
0, 3, 6, 9, 12, 15, 18, 1, 4, 7, 10, 13, 16, 19, 2, 5, 8, 11, 14, 17, 20

Suppose you got t1 = 4 (k = 3, of course) and t = 3. Then you need to mark 4, 7, 10, 13 and as you see those number are adjacent, just as 9, 10, 11 and 12 are in usual cumulative table. Everything you need to do is to index in different way.
b
boba5551
@turgond: Please, do not post more times the same post. Thanks.
A
Al3kSaNdaR
@boba5551:

Can you explain solution to the problem without using Cumultative tables.
t
turgond
omg, I am sorry, refresh resent the posts :)...
b
boba5551
Without using cumulative tables - hint:
If you have t1_i = 0, then for fixed k = const you can take highest t that has k = const, let it be T_MAX_k. Then all marked positions for k = const will be
0, k, 2 * k, ..., T_MAX_k * k

Try to extend this and solve current version of the problem.
i
iggy91
Can you describe solution with cummulative tables with more details? I really can't find any sense in using 90 cummulative arrays in this task... :S
A
Al3kSaNdaR
Ok, i'll try it tomorrow because i'm so sleepy now. :) Thanks for the hint.
b
boba5551
I have forgotten, sorry - for each i, let t1_i = 0, not for some of them, but for each i. So t1_i actually doesn't exist in this simplified problem.
t
turgond
As Sloba said, you only need 10 :)
i
iggy91
@turgon:
That's OK, but in order to understand that version with 10, I have to understand how to utilize 90 first... Right?
t
turgond
well....they are basically the same, Boba's solution requires a bit more work....
basicaly, since k is <= 10,
u can divide every query by k and t1 modulo k.
Than, in the cumulative tabel for k and l, where l>=0&&l<k, where l is t1%l, you mark each field from t1 do t1+t*k, and later when checking if it is marked, u look it up for each k.
I think that's it!
D
Daniel93
@Tgudlek

First, why did you go up to 100000, wasn't it enough to go up to t1i + (ti*k) ? Second how did you do it that it works? You see my code down here and it says for all tests time-limit. A very funny thing happening to me was I submited serveral times the code for the task z-passwrd for z-javelin and there worked about 7 tests xD/

Ok, here is it:

for(int i=0; i < n; i++){
scanf("%d %d %d", &pt, &et, &k);
for(int j=pt; j <=pt+(et*k); j++){
if( !((j - pt)%k) && ((j-pt)/k) <= et && !T[j]){
T[j] = true;
res++;
}
}
}

A
Al3kSaNdaR
I've done it the same way and it won't work. tgudulek can you explain us how have you done it please? :)
D
Daniel93
I did it. Thx Tgudlek, it was my fault.
A
Al3kSaNdaR
Aha, i see it now. I'll write it at my uncle's place because i have to go now. Thanks for the idea. :)
t
tgudlek
I'm glad you figured it out. ;)
D
Daniel93
Well, I duno if I helped you in some way. But if you got problems with it, just ask.
t
tgudlek
@Daniel93: I belive you can see that this isn't the real solution. For example:

100000
99992 2 3
99992 2 3
99992 2 3
..
99992 2 3

It would be almost O ( N ^ 2 ), which is waaay to slow.
t
turgond
Ok, to help anyone who wants to do it with cumulative tables, 45 of 100000 of SHORT type gets the job done!!!!!!!!!!!!! xD hurray!!!!!
A
Amtrix
@Tgudlek
Yes, I guess I'll have to learn comulative tables xD
D
Daniel93
Ups, this should be mine post. I mean that from Amtrix, I'm on his PC, so he was logged in.
D
Daniel93
Hmm, for me it seems that the solution with the comulative tables is even slower.
A
Al3kSaNdaR
Can you please take a look at my solution.

http://pastebin.com/f6381a084

I get time limit exceeded at every test case. :-(
m
mbalunovic
I think that you used too much memory space.
A
Amtrix
No its not the memory. You should separate input and searching. First input the given statmnets, and then like Tgudlek said you have to go for each distance between 1 and 100000 and try to get it. I think that will help.
D
Daniel93
This post was again mine xD
b
boba5551
@Daniel93: Do you have two accounts? That is forbidden. If you have, please e-mail to admin to remove one of them.
D
Daniel93
Nope, this is a account from my brother, I was on his PC, I'm sorry for posting on his name.
t
tgudlek
Wow, you two have very similar scores on competitions. :)
i
iggy91
Not ony similar scores, but very close submit times... ;)
b
boris4
not only on this competition
A
Amtrix
How much I know ACM is a team competetion :P
http://en.wikipedia.org/wiki/ACM_International_Collegiate_Programming_Contest#Contest_rules
And I became only this link for the rules....
t
tgudlek
;) But "08/09 Quals" isn't :)

Wow, you must have some super natural powers since your codes for some tasks ( Wovels, for example ) look like some just chagned few things and uploaded them :)

But this is not of my buisness, so I'll leave this discussion :)
A
Amtrix
C'mon.....
Wovels is a so simply task....
And in Quals we didn't corporate in any way... But ok,lets end this discussion here. ;)
t
turgond
why the hell is it important if they cooperate? You should all try to work on improving yourself, don't judge others....