POJ 3320 (ruler)

Source: Internet
Author: User

Jessica ' s Reading problem
Time Limit: 1000MS Memory Limit: 65536K
Total Submissions: 10076 Accepted: 3356

Description

Jessica ' s a very lovely girl wooed by lots of boys. Recently she has a problem. The final exam is coming, yet she had spent little time on it. If She wants to pass it, she had to master all ideas included in a very thick the text book. The author of that text book, like other authors, was extremely fussy about the ideas, thus some ideas was covered more tha N once. Jessica think if she managed to read all 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 should be as thin as possible.

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

Input

The first line of input is a integer p (1≤ P ≤1000000), which is the number of pages of Jessica ' s Tex T-book. The second line contains P non-negative integers describing what's the idea of each page was about. The first integer is what the first page was about, the second integer was what the second page was about, and so on. Assume all integers this 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

Test instructions

The problem: the basis of the ruler, what is the size of the stamp here: http://blog.chinaunix.net/uid-24922718-id-4848418.html

Map each point of knowledge with a map, and each time it is pushed around.

#include <iostream>#include<stdio.h>#include<string.h>#include<algorithm>#include<map>using namespaceStd;typedefLong LongLL;Const intN =1000005;intA[n];map<int,int>MP;intMain () {intN;  while(SCANF ("%d", &n)! =EOF)        {mp.clear (); intm=0;  for(intI=1; i<=n;i++) {scanf ("%d",&A[i]); if(mp[a[i]]==0) m++; Mp[a[i]]=1;        } mp.clear (); intL=1, r=1, cnt=0, ans=n+1;  while(l<=N) {             while(r<=n&&cnt<L) {                if(mp[a[r]]==0) cnt++; MP[A[R]]++; R++; }            if(cnt<m) Break; if(cnt==m) ans = min (ans,r-l); MP[A[L]]--; if(mp[a[l]]==0) cnt--; L++; } printf ("%d\n", ans); }    return 0;}

POJ 3320 (ruler)

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.