codeforces 1186C

题目链接:http://codeforces.com/contest/1186/problem/C

C. Vus the Cossack and Strings

 

Vus the Cossack has two binary strings, that is, strings that consist only of "0" and "1". We call these strings aa and bb. It is known that |b|≤|a||b|≤|a|, that is, the length of bb is at most the length of aa.

The Cossack considers every substring of length |b||b| in string aa. Let's call this substring cc. He matches the corresponding characters in bband cc, after which he counts the number of positions where the two strings are different. We call this function f(b,c)f(b,c).

For example, let b=00110b=00110, and c=11000c=11000. In these strings, the first, second, third and fourth positions are different.

Vus the Cossack counts the number of such substrings cc such that f(b,c)f(b,c) is even.

For example, let a=01100010a=01100010 and b=00110b=00110. aa has four substrings of the length |b||b|: 0110001100, 1100011000, 1000110001, 0001000010.

  • f(00110,01100)=2f(00110,01100)=2;
  • f(00110,11000)=4f(00110,11000)=4;
  • f(00110,10001)=4f(00110,10001)=4;
  • f(00110,00010)=1f(00110,00010)=1.

Since in three substrings, f(b,c)f(b,c) is even, the answer is 33.

Vus can not find the answer for big strings. That is why he is asking you to help him.

Input

The first line contains a binary string aa (1≤|a|≤1061≤|a|≤106) — the first string.

The second line contains a binary string bb (1≤|b|≤|a|1≤|b|≤|a|) — the second string.

Output

Print one number — the answer.

Examples

input

01100010
00110

output

3

input

1010111110
0110

output

4

Note

The first example is explained in the legend.

In the second example, there are five substrings that satisfy us: 10101010, 01010101, 11111111, 11111111.

题意概括:有两个‘0’和‘1’构成的字符串a和b,求A的子串中和b串的不相等字符为偶数的子串个数。

解题思路:只要a的子串中‘1’的字符数和b中‘1’的字符数同为奇数,或者同为偶数,无论怎么排,不相等个数都为偶数

#include<iostream>
#include<queue>
#include<cstring> 
#include<cmath>
#include<map>
#include<algorithm>
#define up(i,x,y) for(i=x;i<=y;i++)  
#define down(i,x,y) for(i=x;i>=y;i--)  
#define MAX(a,b) a>b?a:b
#define MIN(a,b) a<b?a:b
#define MAX(a,b,c) (a>b?(a>c?a:c):(b>c?b:c))
#define MIN(a,b,c) (a<b?(a<c?a:c):(b<c?b:c))
using namespace std;

typedef long long ll;
const double PI = acos(-1.0);
const double eps = 1e-6;
const int INF = 1000000000;
const int maxn = 100;
const int MAXN = 2750131;
ll T,n,m,i,j;
ll gcd(ll p,ll q)
{return q==0?p:gcd(q,p%q);}

ll g[200005];

int main(){
	string a,b;
	cin>>a>>b;
	int na=a.length();
	int nb=b.length();
	int suma0=0,sumb0=0,suma1=0,sumb1=0;
	for(i=0;i<nb;i++){
		if(b[i]=='0'){
			sumb0++;
		}
		else if(b[i]=='1'){
			sumb1++;
		}
		if(a[i]=='0'){
			suma0++;
		}
		else{
			suma1++;
		}
	}
	
	ll ans=0;
	if(suma1%2==sumb1%2){
			ans++;
	}
	for(i;i<na;i++){
		if(a[i]=='1'){
			suma1++;
		}
		else{
			suma0++;
		}
		if(a[i-nb]=='1'){
			suma1--;
		}
		else{
			suma0--;
		}
		if(suma1%2==sumb1%2){
			ans++;
		}
	}
	cout<<ans<<endl;
}

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值