-
Notifications
You must be signed in to change notification settings - Fork 0
/
90939035.cpp
70 lines (70 loc) · 1.23 KB
/
90939035.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
#include<bits/stdc++.h>
using namespace std;
void func()
{
string str;
cin>>str;
int x;
cin>>x;
int brr[str.size()];
fill(brr,brr+str.size(),1);
for(int i=0;i<str.size();i++)
{
if(str[i]=='0')
{
if(i+x<str.size())
brr[i+x]=0;
if(i-x>=0)
brr[i-x]=0;
}
}
bool ok=true;
for(int i=0;i<str.size();i++)
{
if(brr[i]==1)
{
if(i+x<str.size())
{
if(str[i+x]!='1')
ok=false;
}
if(i-x>=0)
{
if(str[i-x]!='1')
ok=false;
}
}
if(str[i]=='1')
{
bool inerok=false;
if(i+x<str.size())
{
if(brr[i+x]==1)
inerok=true;
}
if(i-x>=0)
{
if(brr[i-x]==1)
inerok=true;
}
if(inerok==false)
ok=false;
}
}
if(ok)
{
for(int i=0;i<str.size();i++)
cout<<brr[i];
cout<<endl;
}
else
cout<<-1<<endl;
}
int main()
{
int t;
cin>>t;
for(int i=0;i<t;i++)
func();
return 0;
}