Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- using namespace std;
- void solve(){
- int n;
- string s;
- cin >> n >> s;
- int posa = -22, posb = -22, posc = -22, posd = -22;
- int ans = -1;
- for (int r = 0; r < n; r++){
- if (s[r] == 'a') posa = r;
- if (s[r] == 'b') posb = r;
- if (s[r] == 'c') posc = r;
- if (s[r] == 'd') posd = r;
- int l = min(min(posa, posb), min(posc, posd));
- int le = r - l;
- int len = le + 1;
- if (l != -22){
- if (ans == -1 || len < ans){
- ans = len;
- }
- }
- }
- cout << ans << endl;
- }
- int main(){
- ios::sync_with_stdio(NULL), cin.tie(0), cout.tie(0); // Оптимизация
- solve();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement