#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,sse4.1,sse4.2,popcnt,abm,mmx,avx,avx2,fma")
#include <bits/stdc++.h>
using namespace std;
#ifdef LOCAL
#include "debug.h"
#else
#define debug(...) 42
#endif
using ll=long long;
using pll=array<ll,2>;
const ll inf=1e18;
const int N=2e5+5;
string s,t;
int n,m,a[N],b[N];
int ans,cur;
int main(){
ios::sync_with_stdio(false); cin.tie(0);
cin>>s>>t;
n=s.size();
m=t.size();
if(n<m){
cout<<0;
return 0;
}
for(int i=1;i<=n;i++) a[i]=s[i-1]-'0';
for(int i=1;i<=m;i++) b[i]=t[i-1]-'0';
if(b[1]==1){
for(int i=1;i<=n;i++) a[i]^=1;
for(int i=1;i<=m;i++) b[i]^=1;
}
if(m==1){
for(int i=1;i<=n;i++) if(a[i]==b[1]) ans=-1;
} else if(m==2){
if(!b[2]){
int cnt0=0;
for(int i=1;i<=n;i++){
if(!a[i]) cnt0++;
if(i<n&&!a[i]&&!a[i+1]) ans++;
}
if(cnt0>(n+1)/2) ans=-1;
} else{
for(int i=1;i<=n;i++){
int j=i;
while(j+1<=n&&a[i]==a[j+1]) j++;
if(i!=1&&a[i]) ans++;
i=j;
}
}
} else{
if(b[1]!=b[3]){
if(!b[2]){
for(int i=1;i<=n;i++) a[i]^=1;
for(int i=1;i<=m;i++) b[i]^=1;
reverse(a+1,a+n+1);
reverse(b+1,b+m+1);
}
for(int i=1;i<=n;i++){
int j=i;
while(j+1<=n&&a[i]==a[j+1]) j++;
if(i!=1&&a[i]&&i<j) ans++;
i=j;
}
} else if(b[2]){
for(int i=2;i<n;i++) if(!a[i-1]&&a[i]&&!a[i+1]) ans++;
ans=(ans+1)/2;
}
}
cout<<ans;
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
264 KB |
Output is correct |
3 |
Correct |
2 ms |
1372 KB |
Output is correct |
4 |
Correct |
1 ms |
1372 KB |
Output is correct |
5 |
Correct |
2 ms |
1500 KB |
Output is correct |
6 |
Correct |
2 ms |
1372 KB |
Output is correct |
7 |
Correct |
2 ms |
1352 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 |
1 ms |
212 KB |
Output is correct |
4 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
328 KB |
Output is correct |
6 |
Correct |
1 ms |
1448 KB |
Output is correct |
7 |
Correct |
2 ms |
1372 KB |
Output is correct |
8 |
Correct |
2 ms |
1372 KB |
Output is correct |
9 |
Correct |
3 ms |
1372 KB |
Output is correct |
10 |
Correct |
3 ms |
1372 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 |
1 ms |
212 KB |
Output is correct |
4 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
328 KB |
Output is correct |
6 |
Correct |
1 ms |
1448 KB |
Output is correct |
7 |
Correct |
2 ms |
1372 KB |
Output is correct |
8 |
Correct |
2 ms |
1372 KB |
Output is correct |
9 |
Correct |
3 ms |
1372 KB |
Output is correct |
10 |
Correct |
3 ms |
1372 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 |
1 ms |
212 KB |
Output is correct |
15 |
Correct |
0 ms |
212 KB |
Output is correct |
16 |
Correct |
0 ms |
324 KB |
Output is correct |
17 |
Correct |
1 ms |
328 KB |
Output is correct |
18 |
Correct |
1 ms |
212 KB |
Output is correct |
19 |
Correct |
1 ms |
212 KB |
Output is correct |
20 |
Correct |
1 ms |
1372 KB |
Output is correct |
21 |
Correct |
1 ms |
1500 KB |
Output is correct |
22 |
Correct |
2 ms |
1392 KB |
Output is correct |
23 |
Correct |
3 ms |
1352 KB |
Output is correct |
24 |
Correct |
2 ms |
1372 KB |
Output is correct |
25 |
Correct |
1 ms |
212 KB |
Output is correct |
26 |
Correct |
2 ms |
1404 KB |
Output is correct |
27 |
Correct |
3 ms |
1372 KB |
Output is correct |
28 |
Correct |
3 ms |
1484 KB |
Output is correct |
29 |
Correct |
2 ms |
1328 KB |
Output is correct |
30 |
Correct |
1 ms |
1372 KB |
Output is correct |
31 |
Correct |
2 ms |
1372 KB |
Output is correct |
32 |
Correct |
2 ms |
1372 KB |
Output is correct |
33 |
Correct |
0 ms |
212 KB |
Output is correct |
34 |
Correct |
0 ms |
212 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 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 |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
1 ms |
212 KB |
Output is correct |
7 |
Correct |
2 ms |
1388 KB |
Output is correct |
8 |
Correct |
2 ms |
1356 KB |
Output is correct |
9 |
Correct |
3 ms |
1500 KB |
Output is correct |
10 |
Correct |
2 ms |
1424 KB |
Output is correct |
11 |
Correct |
2 ms |
1372 KB |
Output is correct |
12 |
Correct |
2 ms |
1372 KB |
Output is correct |
13 |
Correct |
2 ms |
1372 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
328 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
324 KB |
Output is correct |
4 |
Correct |
1 ms |
324 KB |
Output is correct |
5 |
Correct |
0 ms |
212 KB |
Output is correct |
6 |
Correct |
1 ms |
212 KB |
Output is correct |
7 |
Correct |
0 ms |
336 KB |
Output is correct |
8 |
Correct |
1 ms |
212 KB |
Output is correct |
9 |
Correct |
0 ms |
212 KB |
Output is correct |
10 |
Correct |
2 ms |
1500 KB |
Output is correct |
11 |
Correct |
1 ms |
1372 KB |
Output is correct |
12 |
Correct |
4 ms |
1368 KB |
Output is correct |
13 |
Correct |
2 ms |
1372 KB |
Output is correct |
14 |
Correct |
2 ms |
1372 KB |
Output is correct |
15 |
Correct |
2 ms |
1372 KB |
Output is correct |
16 |
Correct |
2 ms |
1372 KB |
Output is correct |
17 |
Correct |
3 ms |
1372 KB |
Output is correct |
18 |
Correct |
1 ms |
1372 KB |
Output is correct |
19 |
Correct |
2 ms |
1372 KB |
Output is correct |
20 |
Correct |
2 ms |
1372 KB |
Output is correct |
21 |
Correct |
1 ms |
1372 KB |
Output is correct |
22 |
Correct |
2 ms |
1372 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 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 |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
1 ms |
212 KB |
Output is correct |
7 |
Correct |
2 ms |
1388 KB |
Output is correct |
8 |
Correct |
2 ms |
1356 KB |
Output is correct |
9 |
Correct |
3 ms |
1500 KB |
Output is correct |
10 |
Correct |
2 ms |
1424 KB |
Output is correct |
11 |
Correct |
2 ms |
1372 KB |
Output is correct |
12 |
Correct |
2 ms |
1372 KB |
Output is correct |
13 |
Correct |
2 ms |
1372 KB |
Output is correct |
14 |
Correct |
1 ms |
328 KB |
Output is correct |
15 |
Correct |
1 ms |
212 KB |
Output is correct |
16 |
Correct |
0 ms |
324 KB |
Output is correct |
17 |
Correct |
1 ms |
324 KB |
Output is correct |
18 |
Correct |
0 ms |
212 KB |
Output is correct |
19 |
Correct |
1 ms |
212 KB |
Output is correct |
20 |
Correct |
0 ms |
336 KB |
Output is correct |
21 |
Correct |
1 ms |
212 KB |
Output is correct |
22 |
Correct |
0 ms |
212 KB |
Output is correct |
23 |
Correct |
2 ms |
1500 KB |
Output is correct |
24 |
Correct |
1 ms |
1372 KB |
Output is correct |
25 |
Correct |
4 ms |
1368 KB |
Output is correct |
26 |
Correct |
2 ms |
1372 KB |
Output is correct |
27 |
Correct |
2 ms |
1372 KB |
Output is correct |
28 |
Correct |
2 ms |
1372 KB |
Output is correct |
29 |
Correct |
2 ms |
1372 KB |
Output is correct |
30 |
Correct |
3 ms |
1372 KB |
Output is correct |
31 |
Correct |
1 ms |
1372 KB |
Output is correct |
32 |
Correct |
2 ms |
1372 KB |
Output is correct |
33 |
Correct |
2 ms |
1372 KB |
Output is correct |
34 |
Correct |
1 ms |
1372 KB |
Output is correct |
35 |
Correct |
2 ms |
1372 KB |
Output is correct |
36 |
Incorrect |
0 ms |
212 KB |
Output isn't correct |
37 |
Halted |
0 ms |
0 KB |
- |