### G. Emergency Handling

Author: Derianto Kusuma

(link to problem G)

If you don’t read this problem carefully, it can be very hard to solve this problem. The key point which makes this problem easy lies on the small constraint of r (<= 100). Originally, Derianto (the author) wrote all constraints in the story (problem statement). However, for the sake of "uniformity" (with all other problems), I moved the constraints to the input section. Therefore, those who do not read the input section thoroughly before working on the solution will have a hard time. The small constraint of r allows us to keep (r + 1) different priority queue, one for each rate of severity increase from 0 to r. Put all patients with the same rate of severity increase into one priority queue. Because these patients have the same rate of severity increase, thus the patient with the highest severity at any time t is determined only by the initial severity of each patient. For each query 'A', we need to check all (r + 1) priority queues and determine which patient has the highest severity at that time (only consider the patients with highest severity in each priority queue). For each query 'P', this approach has O(lg N) time complexity, while for each query 'A', it has O(r lg N) time complexity. After the contest, team koalabiru said to me that they did notice the r constraint; however, they thought that r is set to be small so that the output is fit within 32 bit integer, thus they did not consider any solution which exploit r).

are you sure there isn’t mod operation ?

and this : j = j + 1, why it isn’t j = j-1 ?

Ah, you’re right, it should be j =j – 1 (updated).

MOD operation is not needed, What we really need is whether a two substrings have a same hash value or not, not the hash value itself. There are only addition and multiplication operators, so overflowing the result doesn’t matter.

^that comment above is for pasti pas

Halo Mr. Suhendry.

Saya ingin sekali bisa berkompetisi di ACM ICPC. Saya Mahasiswa tingkat 2 di salah satu perguruan tinggi di bandung. Tapi skill koding saya tidak terlalu bagus. algoritma sorting saja masih bingung. Gimana ya kiat nya untuk belajar algoritma yg baik dan benar agar bisa nanti suatu saat ke ACM ICPC?

How to determine which prime number should be used? I tried some prime numbers and the result is not as expected.

(Problem F). Just use large prime number (larger is better, its chance to collide is smaller). I used 1000003 and it’s fine.

I have implemented it and submitted on Live Archive, but got WA 😀

Is there something wrong with my implementation? Could you please check it? http://pastebin.com/ECJX9yEa

I didn’t read your code, but it failed the first sample input: PASTIPAS.

Yes and it works if I do MOD operation, but still WA on Live Archive. Does your solution with above algorithm still work on LA? Maybe you/others have added more test cases to break that hash function? Or my implementation wrong?

I’m the one who send the data to LA and I’m pretty sure LA’s admin was quite busy to do any changes on the dataset.

BTW, I’ve just noticed an error in F’s pseudocode. There is one line which is wrong. Try to figure that out! 🙂

hint: pay attention to the rolling hash (when you do the multiplication with prime number); you might want to check other resources on rolling hash.

^ problem F Pasti Pas!

Problem H can be solved by Dynamic Programming,here I find two states,one is index of the current question,another is wrong answers used/left so far, and then minimize the answer. But this solution does not work,though sample test case gives correct output. I saw another boolean state in some accepted codes in HUST, which tries both minimizing and maximizing. Can you please explain why another state is needed here?