-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy path1354B.cpp
More file actions
50 lines (42 loc) · 1023 Bytes
/
1354B.cpp
File metadata and controls
50 lines (42 loc) · 1023 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
#define DEBUG
#define MAXN 100000010
#include <bits/stdc++.h>
using namespace std;
int main() {
#ifdef DEBUG
freopen("in.in", "r", stdin);
#endif
ios_base::sync_with_stdio(0);
cin.tie(0);
int t;
cin >> t;
while (t--) {
string s;
cin >> s;
vector<pair <int , int >> v;
v.push_back(make_pair(s[0]-'0', 1));
for (int i = 1; i < s.size(); ++i) {
if (s[i]-'0' != v.back().first ) {
v.push_back(make_pair(s[i]-'0', 1));
} else {
v.back().second ++ ;
}
}
if (v.size() < 3) {
cout << 0 << endl;
continue;
}
int ans = MAXN;
for (int i = 1; i < v.size()-1 ; ++i) {
if (v[i-1].first != v[i+1].first) {
ans = min(ans, v[i].second+2);
}
}
if (ans == MAXN) {
cout << 0 << endl;
} else {
cout << ans << endl;
}
}
return 0;
}