​题目传送门​​ 代码:

#include<bits/stdc++.h>
using namespace std;

#define lson rt<<1,l,mid
#define rson rt<<1|1,mid+1,r
#define ls (rt<<1)
#define rs (rt<<1|1)
#define pb push_back
#define max(a,b) (a>b?a:b)
#define min(a,b) (a<b?a:b)
#define MEM(a,b,start,end) for(int ii=start;ii<=end;ii++) a[ii]=b
#define low(x) (x&(-x))
#define v(x) vector<x>
#define Map1(a,b) map<a,b>
#define Map2(a,b) unordered_map<a,b>
#define pqg(x) priority_queue<x,vector<x>,greater<x> >
#define pql(x) priority_queue<x,vector<x>,less<x> >
typedef unsigned long long ULL;
typedef long long LL;
typedef double D;
typedef complex<double> COMD;
const int maxn=100000+100;

char ch[maxn];
int cnt[100];

bool check(){

for(int i=0;i<26;i++) if(cnt[i]==0) return false;
return true;
}

int main(){

scanf("%s",ch);
int len=strlen(ch);
int l=0,r=0;
int num=len+1;
while(r<len){

while((r==0 || !check()) && r<len) cnt[ch[r++]-'A']++;
while(check() && l<=r) cnt[ch[l++]-'A']--;
if(r<len) num=min(num,r-l+1);
}
if(num!=len+1) printf("%d\n",num);
else printf("No Solution\n");
}