Init
This commit is contained in:
36
ACMOJ-1948.cpp
Normal file
36
ACMOJ-1948.cpp
Normal file
@ -0,0 +1,36 @@
|
||||
#include<iostream>
|
||||
#include<cstring>
|
||||
#include<algorithm>
|
||||
#include<cassert>
|
||||
#include<string>
|
||||
using namespace std;
|
||||
typedef long long LL;
|
||||
const int inf=0x3f3f3f3f;
|
||||
const int maxn=200005;
|
||||
char s[maxn];
|
||||
int main()
|
||||
{
|
||||
#ifdef local
|
||||
freopen("pro.in","r",stdin);
|
||||
// freopen("pro.out","w",stdout);
|
||||
#endif
|
||||
int T,n; scanf("%d",&T);
|
||||
while(T-->0)
|
||||
{
|
||||
scanf("%s",s); n=strlen(s);
|
||||
int pos[4];
|
||||
pos[1]=pos[2]=pos[3]=-1;
|
||||
int res=inf;
|
||||
for(int i=0;i<n;i++)
|
||||
{
|
||||
int loc=inf;
|
||||
for(int j=1;j<=3;j++)
|
||||
if(j!=s[i]-'0')
|
||||
loc=min(loc,pos[j]);
|
||||
pos[s[i]-'0']=i;
|
||||
if(loc>=0) res=min(res,i-loc+1);
|
||||
}
|
||||
printf("%d\n",res==inf?0:res);
|
||||
}
|
||||
return 0;
|
||||
}
|
Reference in New Issue
Block a user