Submit | All submissions | Best solutions | Back to list |
BRODOVI - BRODOVI |
Mirko lives in a small town with a harbour: once in a blue moon a ship passes by. However, to this day Mirko remembers the day when all the ships who had ever visited the harbour showed up. He denoted this day by index 1. Many days have passed since, but Mirko noted each day when at least one ship visited the harbour, naming these days entertaining. Additionally, Mirko has noticed that each ship visits the harbour periodically, at regular intervals. For instance, an interval of length 3 implies that some ship visited the harbour on days 1, 4, 7, 10 etc.
Given Mirko’s list of entertaining days (including today which is considered to be an entertaining day as well), compute the minimum possible number of ships visiting his harbour.
Notes: All entertaining days appear on Mirko’s list. It is guaranteed that the given data is consistent - in other words, a solution will always exist.
Input
The first line of input contains an integer N (2 ≤ N ≤ 5000), the number of entertaining days. The following N lines contain indices of entertaining days, one per line, in ascending order. The first and the last indices, representing the day from which Mirko started monitoring harbour traffic and today, respectively, will always appear on the list. The first index will always be 1, and the last one (index of today) will be less than 109.
Output
The first and only line of output must contain the required minimum number of ships.
Example
Input: 5 1 7 10 13 19 Output: 2
Added by: | akaki |
Date: | 2011-02-15 |
Time limit: | 1s |
Source limit: | 50000B |
Memory limit: | 1536MB |
Cluster: | Cube (Intel G860) |
Languages: | All except: ASM64 |
Resource: | coci |
hide comments
|
||||||
2011-03-28 12:20:19 Govardhan Reddy M
worst ever description i have ever seen in SPOJ problems ... |
||||||
2011-03-18 05:47:32 Daniel Hernandez
is wrong explained |
||||||
2011-03-06 17:32:23 Adrian Satja Kurdija
1, 1 and 1 respectively. |
||||||
2011-03-06 09:16:54 Jay Pandya
ok no problem..but is there any special cases??? what is the answers of following input?? 10 1 2 3 4 5 6 7 8 9 10 3 1 7 13 2 1 10 |
||||||
2011-03-05 23:11:45 Adrian Satja Kurdija
I can't see your solution since I haven't set this problem on Spoj. |
||||||
2011-03-05 18:00:41 Jay Pandya
please..can you check my solution ?? i am getting wrong answer..and i got right output for all input i gave... :(( please help me..my solution number is 4771798.. |
||||||
2011-03-05 17:33:15 Adrian Satja Kurdija
@Jay Pandya: I'm not sure if O(N^2 log N) is too slow; it might work. But try to think of an O(N^2) solution, it's not hard to find. |
||||||
2011-02-24 22:31:29 Adrian Satja Kurdija
It can be done in O(N log N). |
||||||
2011-02-23 18:14:43 যোবায়ের
@Adrian Satja Kurdija what is your complexity? |
||||||
2011-02-23 09:28:17 Adrian Satja Kurdija
you can find them at http://www.hsin.hr/coci/ , contest #5 |