Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- #define ll long long
- using namespace std;
- const int INF = 1e9 + 10;
- const int MAXN = 2e5 + 10;
- int cnt[5];
- void solve(){
- string s;
- cin >> s;
- int n = s.size();
- s = "#" + s;
- int ans = n + 1;
- int right = 0;
- int k = 0;
- for (int left = 1; left <= n; left++){
- while (right < n && k < 3){
- right++;
- cnt[s[right] - '0']++;
- if (cnt[s[right] - '0'] == 1){
- k++;
- }
- }
- if (k == 3){
- ans = min(ans, right - left + 1);
- }
- cnt[s[left] - '0']--;
- if (cnt[s[left] - '0'] == 0){
- k--;
- }
- }
- if (ans == n + 1){
- cout << 0 <<"\n";
- }
- else
- cout << ans << '\n';
- }
- int main()
- {
- int t = 1;
- cin >> t;
- while(t--){
- solve();
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment