#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int n;
int arr[200002];
int k;
int b[4];
void input();
void solvek1();
void solvek2();
int main(){
input();
if(k==1) solvek1();
if(k==2) solvek2();
}
void input(){
string str;
cin >> str;
n = (int)str.size();
for(int i=1; i<=n; i++) arr[i] = (str[i-1] - '0');
cin >> str;
k = (int)str.size();
for(int i=1; i<=k; i++) b[i] = (str[i-1] - '0');
}
void solvek1(){
if(count(arr+1, arr+n+1, b[1])) printf("-1");
else printf("0");
exit(0);
}
void solvek2(){
ll ans = 0;
if(b[1] != b[2]){
int l = b[2], r = b[1];
vector<int> v;
for(int i=1; i<=n; i++){
if(v.empty() || v.back() != arr[i]) v.push_back(arr[i]);
}
if(!v.empty() && v.back() == r) v.pop_back();
if(!v.empty() && v[0] == l) v.erase(v.begin());
ans = (int)v.size()/2;
}
else{
}
printf("%lld", ans);
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
3 ms |
1380 KB |
Output is correct |
4 |
Correct |
5 ms |
1380 KB |
Output is correct |
5 |
Correct |
4 ms |
1320 KB |
Output is correct |
6 |
Correct |
4 ms |
1380 KB |
Output is correct |
7 |
Correct |
4 ms |
1380 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
0 ms |
212 KB |
Output is correct |
6 |
Correct |
4 ms |
1380 KB |
Output is correct |
7 |
Correct |
4 ms |
1408 KB |
Output is correct |
8 |
Correct |
4 ms |
2332 KB |
Output is correct |
9 |
Correct |
5 ms |
1832 KB |
Output is correct |
10 |
Correct |
5 ms |
1836 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
0 ms |
212 KB |
Output is correct |
6 |
Correct |
4 ms |
1380 KB |
Output is correct |
7 |
Correct |
4 ms |
1408 KB |
Output is correct |
8 |
Correct |
4 ms |
2332 KB |
Output is correct |
9 |
Correct |
5 ms |
1832 KB |
Output is correct |
10 |
Correct |
5 ms |
1836 KB |
Output is correct |
11 |
Correct |
1 ms |
212 KB |
Output is correct |
12 |
Correct |
1 ms |
212 KB |
Output is correct |
13 |
Correct |
0 ms |
212 KB |
Output is correct |
14 |
Correct |
0 ms |
212 KB |
Output is correct |
15 |
Correct |
0 ms |
312 KB |
Output is correct |
16 |
Correct |
0 ms |
212 KB |
Output is correct |
17 |
Correct |
1 ms |
212 KB |
Output is correct |
18 |
Incorrect |
0 ms |
312 KB |
Output isn't correct |
19 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
0 ms |
212 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
0 ms |
212 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
0 ms |
212 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |