POJ3320 Jessica's Reading Problem

Source: Internet
Author: User

Jessica's Reading Problem
Time Limit:1000 MS   Memory Limit:65536 K
Total Submissions:7291   Accepted:2288

Description

Jessica's a very lovely girl wooed by lots of boys. recently she has a problem. the final exam is coming, yet she has spent little time on it. if she wants to pass it, she has to master all ideas encoded in a very thick text book. the author of that text book, like other authors, is extremely fussy about the ideas, thus some ideas are covered more than once. jessica think if she managed to read each idea at least once, she can pass the exam. she decides to read only one contiguous part of the book which contains all ideas covered by the entire book. and of course, the sub-book shoshould be as thin as possible.

A very hard-working boy had manually indexed for her each page of Jessica's text-book with what idea each page is about and thus made a big progress for his courtship. here you come in to save your skin: given the index, help Jessica decide which contiguous part she shoshould read. for convenience, each idea has been coded with an ID, which is a non-negative integer.

Input

The first line of input is an integerP(1 ≤P≤ 1000000), which is the number of pages of Jessica's text-book. The second line containsPNon-negative integers describing what idea each page is about. the first integer is what the first page is about, the second integer is what the second page is about, and so on. you may assume all integers that appear can fit well in the signed 32-bit integer type.

Output

Output one line: the number of pages of the shortest contiguous part of the book which contains all ideals covered in the book.

Sample Input

51 8 8 8 1

Sample Output

2

Source

POJ Monthly -- 2007.08.05, Jerry

# Include <stdio. h> # include <string. h >#include <algorithm> # include <set> # include <map> # define maxn 1000005int P [maxn]; int main () {int n, I, tar, s, ans, num; while (scanf ("% d", & n) = 1) {std: set <int> st; std: map <int, int> mp; for (I = 0; I <n; ++ I) {scanf ("% d", & P [I]); // the range of knowledge points is not limited to st. insert (P [I]);} tar = st. size (); ans = n; num = 0; for (I = s = 0; I <n; ++ I) {if (mp [P [I] ++ = 0) {++ num; wh Ile (num = tar) {ans = std: min (ans, I-s + 1); if (! -- Mp [P [s ++]) -- num ;}} printf ("% d \ n", ans) ;}return 0 ;}


POJ3320 Jessica's Reading Problem

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.