#include <bits/stdc++.h>
using namespace std;
using lint = long long;
using pi = array<lint, 2>;
#define sz(v) ((int)(v).size())
#define all(v) (v).begin(), (v).end()
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
string s, t;
cin >> s >> t;
if (sz(t) == 1) {
if (count(all(s), t[0]) == 0)
cout << "0\n";
else
cout << "-1\n";
return 0;
}
if (sz(t) == 2) {
if (t[0] != t[1]) {
if (t[0] == '0') {
for (auto &x : s)
x ^= 1;
}
t = "10";
vector<int> poses;
for (int i = 0; i < sz(s); i++) {
if (s[i] == '1')
poses.push_back(i);
}
poses.push_back(sz(s));
int ans = 0;
for (int i = 1; i < sz(poses); i++)
if (poses[i - 1] + 1 != poses[i])
ans++;
cout << ans << "\n";
} else {
int cnt = count(all(s), t[0]);
if (2 * cnt - 1 <= sz(s)) {
int ans = 0;
for (int i = 0; i + 1 < sz(s); i++) {
if (s[i] == t[0] && s[i + 1] == t[0])
ans++;
}
cout << ans << "\n";
} else {
cout << "-1\n";
}
}
return 0;
}
if (t[0] == '1') {
for (auto &x : s)
x ^= 1;
for (auto &x : t)
x ^= 1;
}
if (t[2] == '1') {
int ans = 0;
for (int i = 0; i + 3 <= sz(s); i++) {
if (s.substr(i, 3) == t)
ans++;
}
cout << ans << "\n";
return 0;
} else if (t[1] == '1') {
int ans = 0;
for (int i = 0; i + 3 <= sz(s); i++) {
if (s.substr(i, 3) == t) {
ans++;
}
}
cout << (ans + 1) / 2 << "\n";
return 0;
}
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
604 KB |
Output is correct |
4 |
Correct |
1 ms |
604 KB |
Output is correct |
5 |
Correct |
1 ms |
604 KB |
Output is correct |
6 |
Correct |
1 ms |
604 KB |
Output is correct |
7 |
Correct |
1 ms |
604 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
0 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 |
224 KB |
Output is correct |
6 |
Correct |
2 ms |
1620 KB |
Output is correct |
7 |
Correct |
2 ms |
1620 KB |
Output is correct |
8 |
Correct |
2 ms |
1112 KB |
Output is correct |
9 |
Correct |
2 ms |
1112 KB |
Output is correct |
10 |
Correct |
2 ms |
1112 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
0 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 |
224 KB |
Output is correct |
6 |
Correct |
2 ms |
1620 KB |
Output is correct |
7 |
Correct |
2 ms |
1620 KB |
Output is correct |
8 |
Correct |
2 ms |
1112 KB |
Output is correct |
9 |
Correct |
2 ms |
1112 KB |
Output is correct |
10 |
Correct |
2 ms |
1112 KB |
Output is correct |
11 |
Correct |
0 ms |
212 KB |
Output is correct |
12 |
Correct |
0 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 |
212 KB |
Output is correct |
16 |
Correct |
0 ms |
212 KB |
Output is correct |
17 |
Correct |
0 ms |
212 KB |
Output is correct |
18 |
Correct |
1 ms |
212 KB |
Output is correct |
19 |
Correct |
0 ms |
212 KB |
Output is correct |
20 |
Correct |
2 ms |
1620 KB |
Output is correct |
21 |
Correct |
2 ms |
1620 KB |
Output is correct |
22 |
Correct |
2 ms |
1112 KB |
Output is correct |
23 |
Correct |
2 ms |
1112 KB |
Output is correct |
24 |
Correct |
2 ms |
1112 KB |
Output is correct |
25 |
Correct |
0 ms |
212 KB |
Output is correct |
26 |
Correct |
1 ms |
604 KB |
Output is correct |
27 |
Correct |
2 ms |
604 KB |
Output is correct |
28 |
Correct |
2 ms |
604 KB |
Output is correct |
29 |
Correct |
1 ms |
604 KB |
Output is correct |
30 |
Correct |
1 ms |
604 KB |
Output is correct |
31 |
Correct |
2 ms |
604 KB |
Output is correct |
32 |
Correct |
2 ms |
604 KB |
Output is correct |
33 |
Correct |
0 ms |
212 KB |
Output is correct |
34 |
Correct |
0 ms |
212 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
0 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 |
0 ms |
212 KB |
Output is correct |
7 |
Correct |
3 ms |
604 KB |
Output is correct |
8 |
Correct |
4 ms |
604 KB |
Output is correct |
9 |
Correct |
4 ms |
604 KB |
Output is correct |
10 |
Correct |
4 ms |
604 KB |
Output is correct |
11 |
Correct |
3 ms |
604 KB |
Output is correct |
12 |
Correct |
3 ms |
604 KB |
Output is correct |
13 |
Correct |
4 ms |
604 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
0 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 |
0 ms |
212 KB |
Output is correct |
7 |
Correct |
0 ms |
212 KB |
Output is correct |
8 |
Correct |
0 ms |
212 KB |
Output is correct |
9 |
Correct |
0 ms |
212 KB |
Output is correct |
10 |
Correct |
3 ms |
604 KB |
Output is correct |
11 |
Correct |
3 ms |
604 KB |
Output is correct |
12 |
Correct |
4 ms |
604 KB |
Output is correct |
13 |
Correct |
4 ms |
604 KB |
Output is correct |
14 |
Correct |
3 ms |
604 KB |
Output is correct |
15 |
Correct |
3 ms |
604 KB |
Output is correct |
16 |
Correct |
3 ms |
604 KB |
Output is correct |
17 |
Correct |
4 ms |
604 KB |
Output is correct |
18 |
Correct |
4 ms |
604 KB |
Output is correct |
19 |
Correct |
4 ms |
604 KB |
Output is correct |
20 |
Correct |
4 ms |
604 KB |
Output is correct |
21 |
Correct |
3 ms |
604 KB |
Output is correct |
22 |
Correct |
4 ms |
604 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
0 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 |
0 ms |
212 KB |
Output is correct |
7 |
Correct |
3 ms |
604 KB |
Output is correct |
8 |
Correct |
4 ms |
604 KB |
Output is correct |
9 |
Correct |
4 ms |
604 KB |
Output is correct |
10 |
Correct |
4 ms |
604 KB |
Output is correct |
11 |
Correct |
3 ms |
604 KB |
Output is correct |
12 |
Correct |
3 ms |
604 KB |
Output is correct |
13 |
Correct |
4 ms |
604 KB |
Output is correct |
14 |
Correct |
0 ms |
212 KB |
Output is correct |
15 |
Correct |
0 ms |
212 KB |
Output is correct |
16 |
Correct |
0 ms |
212 KB |
Output is correct |
17 |
Correct |
0 ms |
212 KB |
Output is correct |
18 |
Correct |
0 ms |
212 KB |
Output is correct |
19 |
Correct |
0 ms |
212 KB |
Output is correct |
20 |
Correct |
0 ms |
212 KB |
Output is correct |
21 |
Correct |
0 ms |
212 KB |
Output is correct |
22 |
Correct |
0 ms |
212 KB |
Output is correct |
23 |
Correct |
3 ms |
604 KB |
Output is correct |
24 |
Correct |
3 ms |
604 KB |
Output is correct |
25 |
Correct |
4 ms |
604 KB |
Output is correct |
26 |
Correct |
4 ms |
604 KB |
Output is correct |
27 |
Correct |
3 ms |
604 KB |
Output is correct |
28 |
Correct |
3 ms |
604 KB |
Output is correct |
29 |
Correct |
3 ms |
604 KB |
Output is correct |
30 |
Correct |
4 ms |
604 KB |
Output is correct |
31 |
Correct |
4 ms |
604 KB |
Output is correct |
32 |
Correct |
4 ms |
604 KB |
Output is correct |
33 |
Correct |
4 ms |
604 KB |
Output is correct |
34 |
Correct |
3 ms |
604 KB |
Output is correct |
35 |
Correct |
4 ms |
604 KB |
Output is correct |
36 |
Incorrect |
0 ms |
212 KB |
Output isn't correct |
37 |
Halted |
0 ms |
0 KB |
- |