Codeforces 989B A Tide of Riverscape

 

The records are expressed as a string ss of characters '0', '1' and '.', where '0' denotes a low tide, '1' denotes a high tide, and '.' denotes an unknown one (either high or low).

You are to help Mino determine whether it's possible that after replacing each '.' independently with '0' or '1', a given integer pp is not a period of the resulting string. In case the answer is yes, please also show such a replacement to Mino.

In this problem, a positive integer pp is considered a period of string ss, if for all 1≤i≤|s|−p1≤i≤|s|−p, the ii-th and (i+p)(i+p)-th characters of ss are the same. Here |s||s| is the length of ss.

Input

The first line contains two space-separated integers nn and pp (1≤p≤n≤20001≤p≤n≤2000) — the length of the given string and the supposed period, respectively.

The second line contains a string ss of nn characters — Mino's records. ss only contains characters '0', '1' and '.', and contains at least one '.' character.

Output

Output one line — if it's possible that pp is not a period of the resulting string, output any one of such strings; otherwise output "No" (without quotes, you can print letters in any case (upper or lower)).

Examples

input

Copy

10 7
1.0.1.0.1.

output

Copy

1000100010

input

Copy

10 6
1.0.1.1000

output

Copy

1001101000

input

Copy

10 9
1........1

output

Copy

No

Note

In the first example, 77 is not a period of the resulting string because the 11-st and 88-th characters of it are different.

In the second example, 66 is not a period of the resulting string because the 44-th and 1010-th characters of it are different.

In the third example, 99 is always a period because the only constraint that the first and last characters are the same is already satisfied.

Note that there are multiple acceptable answers for the first two examples, you can print any of them

按规律输出字符串,拿样例1来说,我们只需要判断一下第 1,7位2,8位,3,9位,4,10位是不是都各自相同(注意看我标的颜色,对比左右蓝色和橙色的),假如这3组都各自相等,就输出no,否则就把“.”用0或者1去填充,

#include<bits/stdc++.h>
using namespace std;
int main(){
	int m,n;
	cin>>m>>n;
	string a;
	cin>>a;
	int t=a.length();    //用一个string去读这个串
	int num[t];
	for(int i=0;i<t;i++){
		num[i]=3;
	}
	for(int i=0;i<t;i++){
	   if(a[i]=='1'){
	   	num[i]=1;
	   }
	   if(a[i]=='0'){     //用num数组储存结果
	   	num[i]=0;
	   }
	}                //之前这些步骤,是为了把“.”都换成3,其他不变
	if(t<=n){
		cout<<"No"<<endl;
		return 0;
	}
	bool f=false;int tot=0;
	for(int i=0;i<t-n;i++){
		if(num[i]!=3&&num[i]==num[i+n]){
			tot++;   //判断一下,我这里用了两个条件
	    }
	    if(num[i]==3&&num[i+n]==3){
	    	f=true;
	    	break;      //只要有一组(3,3)就符合条件,直接退出
		}
	}
	if(tot==(m-n)&&!f){
	   cout<<"No"<<endl;     //假如m-n组都相等,说明不和条件
	}
	else{    //符合条件,就先把这些组数先处理一下,中间的先不管
		for(int i=0;i<t-n;i++){
			 if(num[i]==num[i+n]&&num[i]==3){
			 	num[i]=1;
			 	num[i+n]=0;
			 }
			 else if(num[i]==1&&num[i+n]==3){
			 	num[i+n]=0;
			 }
			 else if(num[i]==0&&num[i+n]==3)
			 { num[i+n]=1;}
			 else if(num[i]==3){
			 	if(num[i+n]==1)
			 	num[i]=0;
			 	else num[i]=1;
			 }
		}
		for(int i=0;i<t;i++){
			if(num[i]==3)         //中间不管的那些部分,假如有3,就直接输出0,(1也行)
			cout<<0;
			else
			cout<<num[i];
		}
		cout<<endl;
	}
	return 0;
}

 

发布了153 篇原创文章 · 获赞 43 · 访问量 6万+
展开阅读全文

没有更多推荐了,返回首页

©️2019 CSDN 皮肤主题: 技术黑板 设计师: CSDN官方博客

分享到微信朋友圈

×

扫一扫,手机浏览