#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]==1) 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]==1){
cur++;
if(i<j){
ans+=cur;
cur=0;
}
}
i=j;
}
}
}
cout<<ans;
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
1372 KB |
Output is correct |
4 |
Correct |
2 ms |
1372 KB |
Output is correct |
5 |
Correct |
1 ms |
1372 KB |
Output is correct |
6 |
Correct |
2 ms |
1372 KB |
Output is correct |
7 |
Correct |
2 ms |
1372 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Incorrect |
1 ms |
212 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Incorrect |
1 ms |
212 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
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 |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
1 ms |
212 KB |
Output is correct |
7 |
Correct |
1 ms |
1372 KB |
Output is correct |
8 |
Correct |
2 ms |
1372 KB |
Output is correct |
9 |
Incorrect |
2 ms |
1372 KB |
Output isn't correct |
10 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
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 |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
0 ms |
212 KB |
Output is correct |
7 |
Incorrect |
1 ms |
212 KB |
Output isn't correct |
8 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
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 |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
1 ms |
212 KB |
Output is correct |
7 |
Correct |
1 ms |
1372 KB |
Output is correct |
8 |
Correct |
2 ms |
1372 KB |
Output is correct |
9 |
Incorrect |
2 ms |
1372 KB |
Output isn't correct |
10 |
Halted |
0 ms |
0 KB |
- |