Daydream
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 1907 Accepted Submission(s): 583
Every girl are beautiful if you use you heart to feel. Every corner in the world will colourful and energetic by several girls standing. If you boy, a normal bay, I believe that you will try to watch when a beautiful girl passing you and you will nervous if a girl watching you just when you are watching her.
Now give you a surprise that may be never happy in the real time. Millions of PLMM stand in a line and facing you(^_^). They are dress colourful clothings. You should to find out a maximal subline PLMM that their clothing color are all different.
Each case first give a integer n expressing many many girls stand in line.(n<=10000000)
Next line a string including n character, each character standing one girls’s clothing color.
3 abc 5 aaaba 8 hdugirls
3 0 2 2 2 38 0 7
AC代码:
#include<cstring> #include <cstdio> #include<iostream> #include<algorithm> using namespace std; const int N = 1000; char s[10000006]; int mp[N]; int main() { int n,l,r,curL, len; //l, r 是最终答案 while(~scanf("%d",&n)) { getchar(); gets(s); len = 0; curL = 0; memset(mp,-1,sizeof(mp)); for(int i = 0; i < n; i++) { if(mp[s[i]] >= curL) { if(i-curL > len) { len = i-curL; l = curL; r = i-1; } curL = mp[s[i]]+1; } mp[s[i]] = i; } if(n-curL > len) { len = n-curL; l = curL; r = n-1; } printf("%d %d %d\n", len, l, r); } return 0; }