poj3320

来源:互联网 发布:七匣子淘宝 编辑:程序博客网 时间:2024/06/12 00:36
Jessica's Reading Problem
Time Limit: 1000MS Memory Limit: 65536KTotal Submissions: 8626 Accepted: 2761

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 included 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 should 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 should 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 integer P (1 ≤ P ≤ 1000000), which is the number of pages of Jessica's text-book. The second line contains Pnon-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


代码:

/*踏实!!努力!!*/#include<iostream>#include<stdio.h>#include<cmath>#include<cstring>#include<map>#include<queue>#include<stack>#include<set>using namespace std;#define N 1000005int n,data[N];set<int>S;map<int,int>P;int main(){    while(scanf("%d",&n)!=EOF){        S.clear();        P.clear();        for(int i=0;i<n;i++){            scanf("%d",&data[i]);            S.insert(data[i]);        }        int Min=n;        int last=0,ans=S.size(),pre=0,now=0;        while(1){            while(last<n&&now<ans){                if(!P[data[last]])                    now++;                P[data[last++]]++;            }            while(P[data[pre]]>1)                P[data[pre++]]--;            if(now==ans){                Min=min(Min,last-pre);                now--;                P[data[pre++]]--;            }            if(last==n)                break;        }        printf("%d\n",Min);    }    return 0;}

0 0
原创粉丝点击
热门问题 老师的惩罚 人脸识别 我在镇武司摸鱼那些年 重生之率土为王 我在大康的咸鱼生活 盘龙之生命进化 天生仙种 凡人之先天五行 春回大明朝 姑娘不必设防,我是瞎子 感冒吃了阿胶糕怎么办 身上起湿疹很痒怎么办 身上起小疹子痒怎么办 吊带裙带子断了怎么办 裙子洗完缩水了怎么办 衬衫洗后缩水了怎么办 羊毛被洗缩水了怎么办 蕾丝洗后缩水了怎么办 天丝针织衫缩水怎么办? 氨纶面料起球怎么办? 新买的衬衫很硬怎么办 孕晚期睡不好觉怎么办 全棉衣服缩水了怎么办 棉麻的衣服起球怎么办 布艺沙发起球怎么办 加绒的衣服掉毛怎么办 新裤子有刺鼻味怎么办 新买鞋子味道大怎么办 天窗下水管堵了怎么办 雪纺衬衫染色了怎么办 雪纺衣服染色了怎么办 漂白后衣服变黄怎么办 用84泡衣服变红怎么办 84腐蚀过的衣服怎么办 紫檀手链泡水了怎么办 链条包链条太短怎么办 涂银遮光布有毒怎么办 车顶布掉下来了怎么办 公摊面积被占用怎么办 按揭房卖了贷款怎么办 首付了贷款不批怎么办 买的房子烂尾了怎么办 备案的房子烂尾怎么办 漏水把楼下泡了怎么办 电动拉闸门没电怎么办 封阳台空调外机怎么办 门牙有缝怎么办1毫米 玻璃房夏天太晒怎么办 十元人民币缺角怎么办 楼上租房的太吵怎么办 交通事故责任方不赔偿怎么办