Last active
January 2, 2016 07:34
-
-
Save kira924age/cdda4222606176443167 to your computer and use it in GitHub Desktop.
尺取法
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/*http://arc022.contest.atcoder.jp/tasks/arc022_2*/ | |
#include <stdio.h> | |
#define max(a, b) ((a > b) ? a : b) | |
int main(){ | |
int N, A[100001], S[100001]={0}; | |
int ans=0, r=0, l; | |
scanf("%d", &N); | |
for(l=0; l<N; l++) scanf("%d", &A[l]); | |
for(l=0; l<N; l++){ | |
while(r<N && S[A[r]]==0){ | |
S[A[r]]++; | |
r++; | |
} | |
ans = max(ans, r-l); | |
S[A[l]]--; | |
} | |
printf("%d\n", ans); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment