Skip to content

Instantly share code, notes, and snippets.

@kira924age
Last active January 2, 2016 07:34
Show Gist options
  • Save kira924age/cdda4222606176443167 to your computer and use it in GitHub Desktop.
Save kira924age/cdda4222606176443167 to your computer and use it in GitHub Desktop.
尺取法
/*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