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;
}

 

全部评论

相关推荐

07-17 12:09
门头沟学院 Java
讲的口干舌燥,头都晕了怎么要讲这么长啊
码农索隆:没事,你口干舌燥,他不一定会看,
投递小鹏汽车等公司8个岗位
点赞 评论 收藏
分享
07-18 15:02
门头沟学院 Java
刚打开网申页面就不想填了,还是不要为难自己了
poppinzhan...:多益老行业毒瘤了,碰到徐波这种恶心的烂人,去了也是受罪。
点赞 评论 收藏
分享
头顶尖尖的程序员:我是26届的不太懂,25届不应该是找的正式工作吗?为什么还在找实习?大四还实习的话是为了能转正的的岗位吗
点赞 评论 收藏
分享
07-18 18:37
门头沟学院 Java
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务