description stringlengths 171 4k | code stringlengths 94 3.98k | normalized_code stringlengths 57 4.99k |
|---|---|---|
Consider the following process. You have a binary string (a string where each character is either 0 or 1) $w$ of length $n$ and an integer $x$. You build a new binary string $s$ consisting of $n$ characters. The $i$-th character of $s$ is chosen as follows:
if the character $w_{i-x}$ exists and is equal to 1, then $s_i$ is 1 (formally, if $i > x$ and $w_{i-x} = $ 1, then $s_i = $ 1); if the character $w_{i+x}$ exists and is equal to 1, then $s_i$ is 1 (formally, if $i + x \le n$ and $w_{i+x} = $ 1, then $s_i = $ 1); if both of the aforementioned conditions are false, then $s_i$ is 0.
You are given the integer $x$ and the resulting string $s$. Reconstruct the original string $w$.
-----Input-----
The first line contains one integer $t$ ($1 \le t \le 1000$) β the number of test cases.
Each test case consists of two lines. The first line contains the resulting string $s$ ($2 \le |s| \le 10^5$, each character of $s$ is either 0 or 1). The second line contains one integer $x$ ($1 \le x \le |s| - 1$).
The total length of all strings $s$ in the input does not exceed $10^5$.
-----Output-----
For each test case, print the answer on a separate line as follows:
if no string $w$ can produce the string $s$ at the end of the process, print $-1$; otherwise, print the binary string $w$ consisting of $|s|$ characters. If there are multiple answers, print any of them.
-----Example-----
Input
3
101110
2
01
1
110
1
Output
111011
10
-1 | import sys
input = sys.stdin.readline
def process():
s = input().strip()
(x,) = map(int, input().split())
n = len(s)
t = [1] * n
for i in range(n):
if int(s[i]) == 0:
if i - x >= 0:
t[i - x] = 0
if i + x < n:
t[i + x] = 0
for i in range(n):
if int(s[i]) == 1:
r = 0
if i - x >= 0:
if t[i - x] == 1:
r = 1
if i + x < n:
if t[i + x] == 1:
r = 1
if not r:
print(-1)
return
print("".join(str(c) for c in t))
(T,) = map(int, input().split())
for _ in range(T):
process() | IMPORT ASSIGN VAR VAR FUNC_DEF ASSIGN VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP LIST NUMBER VAR FOR VAR FUNC_CALL VAR VAR IF FUNC_CALL VAR VAR VAR NUMBER IF BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP VAR VAR NUMBER IF BIN_OP VAR VAR VAR ASSIGN VAR BIN_OP VAR VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF FUNC_CALL VAR VAR VAR NUMBER ASSIGN VAR NUMBER IF BIN_OP VAR VAR NUMBER IF VAR BIN_OP VAR VAR NUMBER ASSIGN VAR NUMBER IF BIN_OP VAR VAR VAR IF VAR BIN_OP VAR VAR NUMBER ASSIGN VAR NUMBER IF VAR EXPR FUNC_CALL VAR NUMBER RETURN EXPR FUNC_CALL VAR FUNC_CALL STRING FUNC_CALL VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR |
Consider the following process. You have a binary string (a string where each character is either 0 or 1) $w$ of length $n$ and an integer $x$. You build a new binary string $s$ consisting of $n$ characters. The $i$-th character of $s$ is chosen as follows:
if the character $w_{i-x}$ exists and is equal to 1, then $s_i$ is 1 (formally, if $i > x$ and $w_{i-x} = $ 1, then $s_i = $ 1); if the character $w_{i+x}$ exists and is equal to 1, then $s_i$ is 1 (formally, if $i + x \le n$ and $w_{i+x} = $ 1, then $s_i = $ 1); if both of the aforementioned conditions are false, then $s_i$ is 0.
You are given the integer $x$ and the resulting string $s$. Reconstruct the original string $w$.
-----Input-----
The first line contains one integer $t$ ($1 \le t \le 1000$) β the number of test cases.
Each test case consists of two lines. The first line contains the resulting string $s$ ($2 \le |s| \le 10^5$, each character of $s$ is either 0 or 1). The second line contains one integer $x$ ($1 \le x \le |s| - 1$).
The total length of all strings $s$ in the input does not exceed $10^5$.
-----Output-----
For each test case, print the answer on a separate line as follows:
if no string $w$ can produce the string $s$ at the end of the process, print $-1$; otherwise, print the binary string $w$ consisting of $|s|$ characters. If there are multiple answers, print any of them.
-----Example-----
Input
3
101110
2
01
1
110
1
Output
111011
10
-1 | import sys
input = sys.stdin.readline
I = lambda: list(map(int, input().split()))
(t,) = I()
for _ in range(t):
s = input().strip()
(x,) = I()
n = len(s)
w = ["1"] * len(s)
pos = 1
for i in range(n):
if s[i] == "0":
if i >= x:
w[i - x] = "0"
if i <= n - x - 1:
w[i + x] = "0"
con = ""
for i in range(n):
st = 0
if i >= x:
st += int(w[i - x])
if i <= n - x - 1:
st += int(w[i + x])
con += "1" if st else "0"
if con != s:
pos = 0
if pos:
print("".join(w))
else:
print(-1) | IMPORT ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP LIST STRING FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR STRING IF VAR VAR ASSIGN VAR BIN_OP VAR VAR STRING IF VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP VAR VAR STRING ASSIGN VAR STRING FOR VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER IF VAR VAR VAR FUNC_CALL VAR VAR BIN_OP VAR VAR IF VAR BIN_OP BIN_OP VAR VAR NUMBER VAR FUNC_CALL VAR VAR BIN_OP VAR VAR VAR VAR STRING STRING IF VAR VAR ASSIGN VAR NUMBER IF VAR EXPR FUNC_CALL VAR FUNC_CALL STRING VAR EXPR FUNC_CALL VAR NUMBER |
Consider the following process. You have a binary string (a string where each character is either 0 or 1) $w$ of length $n$ and an integer $x$. You build a new binary string $s$ consisting of $n$ characters. The $i$-th character of $s$ is chosen as follows:
if the character $w_{i-x}$ exists and is equal to 1, then $s_i$ is 1 (formally, if $i > x$ and $w_{i-x} = $ 1, then $s_i = $ 1); if the character $w_{i+x}$ exists and is equal to 1, then $s_i$ is 1 (formally, if $i + x \le n$ and $w_{i+x} = $ 1, then $s_i = $ 1); if both of the aforementioned conditions are false, then $s_i$ is 0.
You are given the integer $x$ and the resulting string $s$. Reconstruct the original string $w$.
-----Input-----
The first line contains one integer $t$ ($1 \le t \le 1000$) β the number of test cases.
Each test case consists of two lines. The first line contains the resulting string $s$ ($2 \le |s| \le 10^5$, each character of $s$ is either 0 or 1). The second line contains one integer $x$ ($1 \le x \le |s| - 1$).
The total length of all strings $s$ in the input does not exceed $10^5$.
-----Output-----
For each test case, print the answer on a separate line as follows:
if no string $w$ can produce the string $s$ at the end of the process, print $-1$; otherwise, print the binary string $w$ consisting of $|s|$ characters. If there are multiple answers, print any of them.
-----Example-----
Input
3
101110
2
01
1
110
1
Output
111011
10
-1 | def solve(s, x):
ans = [None] * len(s)
for i, char in enumerate(s):
if char == "0":
if i + x < len(s):
ans[i + x] = "0"
if i - x >= 0:
ans[i - x] = "0"
for i, char in enumerate(s):
if char == "1":
if i + x < len(s) and ans[i + x] == "0" or i + x >= len(s):
if i - x >= 0 and ans[i - x] is None:
ans[i - x] = "1"
elif i - x >= 0 and ans[i - x] == "0" or i - x < 0:
return -1
elif i - x >= 0 and ans[i - x] == "0" or i - x < 0:
ans[i + x] = "1"
for i in range(len(ans)):
if ans[i] is None:
ans[i] = "1"
return "".join(ans)
t = int(input())
for _ in range(t):
s = input()
x = int(input())
print(solve(s, x)) | FUNC_DEF ASSIGN VAR BIN_OP LIST NONE FUNC_CALL VAR VAR FOR VAR VAR FUNC_CALL VAR VAR IF VAR STRING IF BIN_OP VAR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR VAR STRING IF BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP VAR VAR STRING FOR VAR VAR FUNC_CALL VAR VAR IF VAR STRING IF BIN_OP VAR VAR FUNC_CALL VAR VAR VAR BIN_OP VAR VAR STRING BIN_OP VAR VAR FUNC_CALL VAR VAR IF BIN_OP VAR VAR NUMBER VAR BIN_OP VAR VAR NONE ASSIGN VAR BIN_OP VAR VAR STRING IF BIN_OP VAR VAR NUMBER VAR BIN_OP VAR VAR STRING BIN_OP VAR VAR NUMBER RETURN NUMBER IF BIN_OP VAR VAR NUMBER VAR BIN_OP VAR VAR STRING BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP VAR VAR STRING FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR NONE ASSIGN VAR VAR STRING RETURN FUNC_CALL STRING VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR |
Consider the following process. You have a binary string (a string where each character is either 0 or 1) $w$ of length $n$ and an integer $x$. You build a new binary string $s$ consisting of $n$ characters. The $i$-th character of $s$ is chosen as follows:
if the character $w_{i-x}$ exists and is equal to 1, then $s_i$ is 1 (formally, if $i > x$ and $w_{i-x} = $ 1, then $s_i = $ 1); if the character $w_{i+x}$ exists and is equal to 1, then $s_i$ is 1 (formally, if $i + x \le n$ and $w_{i+x} = $ 1, then $s_i = $ 1); if both of the aforementioned conditions are false, then $s_i$ is 0.
You are given the integer $x$ and the resulting string $s$. Reconstruct the original string $w$.
-----Input-----
The first line contains one integer $t$ ($1 \le t \le 1000$) β the number of test cases.
Each test case consists of two lines. The first line contains the resulting string $s$ ($2 \le |s| \le 10^5$, each character of $s$ is either 0 or 1). The second line contains one integer $x$ ($1 \le x \le |s| - 1$).
The total length of all strings $s$ in the input does not exceed $10^5$.
-----Output-----
For each test case, print the answer on a separate line as follows:
if no string $w$ can produce the string $s$ at the end of the process, print $-1$; otherwise, print the binary string $w$ consisting of $|s|$ characters. If there are multiple answers, print any of them.
-----Example-----
Input
3
101110
2
01
1
110
1
Output
111011
10
-1 | for _ in range(int(input())):
s = input()
x = int(input())
w = ["1"] * len(s)
f = True
if x >= len(s):
print(-1)
else:
for i in range(len(s)):
if s[i] == "0":
if i - x >= 0:
w[i - x] = "0"
if i + x < len(s):
w[i + x] = "0"
chec = ["0"] * len(s)
for i in range(len(s)):
if i - x >= 0 and w[i - x] == "1":
chec[i] = "1"
if i + x < len(s) and w[i + x] == "1":
chec[i] = "1"
if "".join(chec) == s:
print(*w, sep="")
else:
print(-1) | FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR BIN_OP LIST STRING FUNC_CALL VAR VAR ASSIGN VAR NUMBER IF VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR STRING IF BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP VAR VAR STRING IF BIN_OP VAR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR VAR STRING ASSIGN VAR BIN_OP LIST STRING FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF BIN_OP VAR VAR NUMBER VAR BIN_OP VAR VAR STRING ASSIGN VAR VAR STRING IF BIN_OP VAR VAR FUNC_CALL VAR VAR VAR BIN_OP VAR VAR STRING ASSIGN VAR VAR STRING IF FUNC_CALL STRING VAR VAR EXPR FUNC_CALL VAR VAR STRING EXPR FUNC_CALL VAR NUMBER |
Consider the following process. You have a binary string (a string where each character is either 0 or 1) $w$ of length $n$ and an integer $x$. You build a new binary string $s$ consisting of $n$ characters. The $i$-th character of $s$ is chosen as follows:
if the character $w_{i-x}$ exists and is equal to 1, then $s_i$ is 1 (formally, if $i > x$ and $w_{i-x} = $ 1, then $s_i = $ 1); if the character $w_{i+x}$ exists and is equal to 1, then $s_i$ is 1 (formally, if $i + x \le n$ and $w_{i+x} = $ 1, then $s_i = $ 1); if both of the aforementioned conditions are false, then $s_i$ is 0.
You are given the integer $x$ and the resulting string $s$. Reconstruct the original string $w$.
-----Input-----
The first line contains one integer $t$ ($1 \le t \le 1000$) β the number of test cases.
Each test case consists of two lines. The first line contains the resulting string $s$ ($2 \le |s| \le 10^5$, each character of $s$ is either 0 or 1). The second line contains one integer $x$ ($1 \le x \le |s| - 1$).
The total length of all strings $s$ in the input does not exceed $10^5$.
-----Output-----
For each test case, print the answer on a separate line as follows:
if no string $w$ can produce the string $s$ at the end of the process, print $-1$; otherwise, print the binary string $w$ consisting of $|s|$ characters. If there are multiple answers, print any of them.
-----Example-----
Input
3
101110
2
01
1
110
1
Output
111011
10
-1 | for _ in range(int(input())):
s, x = input(), int(input())
n = len(s)
w = ["1" for i in range(n)]
for i in range(n):
if s[i] == "0":
if i - x >= 0:
w[i - x] = "0"
if i + x < n:
w[i + x] = "0"
valid = True
for i in range(n):
if s[i] == "1":
can = False
if i - x >= 0 and w[i - x] == "1":
can = True
if i + x < n and w[i + x] == "1":
can = True
valid &= can
print("".join(w)) if valid else print("-1") | FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR STRING VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR IF VAR VAR STRING IF BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP VAR VAR STRING IF BIN_OP VAR VAR VAR ASSIGN VAR BIN_OP VAR VAR STRING ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR STRING ASSIGN VAR NUMBER IF BIN_OP VAR VAR NUMBER VAR BIN_OP VAR VAR STRING ASSIGN VAR NUMBER IF BIN_OP VAR VAR VAR VAR BIN_OP VAR VAR STRING ASSIGN VAR NUMBER VAR VAR EXPR VAR FUNC_CALL VAR FUNC_CALL STRING VAR FUNC_CALL VAR STRING |
Consider the following process. You have a binary string (a string where each character is either 0 or 1) $w$ of length $n$ and an integer $x$. You build a new binary string $s$ consisting of $n$ characters. The $i$-th character of $s$ is chosen as follows:
if the character $w_{i-x}$ exists and is equal to 1, then $s_i$ is 1 (formally, if $i > x$ and $w_{i-x} = $ 1, then $s_i = $ 1); if the character $w_{i+x}$ exists and is equal to 1, then $s_i$ is 1 (formally, if $i + x \le n$ and $w_{i+x} = $ 1, then $s_i = $ 1); if both of the aforementioned conditions are false, then $s_i$ is 0.
You are given the integer $x$ and the resulting string $s$. Reconstruct the original string $w$.
-----Input-----
The first line contains one integer $t$ ($1 \le t \le 1000$) β the number of test cases.
Each test case consists of two lines. The first line contains the resulting string $s$ ($2 \le |s| \le 10^5$, each character of $s$ is either 0 or 1). The second line contains one integer $x$ ($1 \le x \le |s| - 1$).
The total length of all strings $s$ in the input does not exceed $10^5$.
-----Output-----
For each test case, print the answer on a separate line as follows:
if no string $w$ can produce the string $s$ at the end of the process, print $-1$; otherwise, print the binary string $w$ consisting of $|s|$ characters. If there are multiple answers, print any of them.
-----Example-----
Input
3
101110
2
01
1
110
1
Output
111011
10
-1 | import sys
for _ in range(int(input())):
s = input()
x = int(input())
n = len(s)
d = dict()
lol = [0] * n
lol[0] = 1
for i in range(-x, n + x):
if i < 0:
d[i] = 0
lol[0] = 1
elif i >= n:
d[i] = 0
lol[0] = 1
else:
d[i] = 1
lol[0] = 1
flag = 0
for i in range(n):
lol[0] = 1
if s[i] == "0":
lol[0] = 1
d[i + x] = 0
lol[0] = 1
d[i - x] = 0
lol[0] = 1
for i in range(n):
lol[0] = 1
if s[i] == "1":
lol[0] = 1
if d[i - x] == 0 and d[i + x] == 0:
lol[0] = 1
flag = 1
lol[0] = 1
break
elif d[i - x] == 0:
lol[0] = 0
d[i + x] = 1
lol[0] = 0
else:
lol[0] = 0
d[i - x] = 1
ans = []
lol[0] = 0
for i in range(n):
lol[0] = 0
ans.append(str(d[i]))
lol[0] = 0
lol.sort()
print("".join(ans) if flag == 0 else "-1") | IMPORT FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR VAR BIN_OP VAR VAR IF VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR NUMBER NUMBER IF VAR VAR ASSIGN VAR VAR NUMBER ASSIGN VAR NUMBER NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR NUMBER NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER NUMBER IF VAR VAR STRING ASSIGN VAR NUMBER NUMBER ASSIGN VAR BIN_OP VAR VAR NUMBER ASSIGN VAR NUMBER NUMBER ASSIGN VAR BIN_OP VAR VAR NUMBER ASSIGN VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER NUMBER IF VAR VAR STRING ASSIGN VAR NUMBER NUMBER IF VAR BIN_OP VAR VAR NUMBER VAR BIN_OP VAR VAR NUMBER ASSIGN VAR NUMBER NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER NUMBER IF VAR BIN_OP VAR VAR NUMBER ASSIGN VAR NUMBER NUMBER ASSIGN VAR BIN_OP VAR VAR NUMBER ASSIGN VAR NUMBER NUMBER ASSIGN VAR NUMBER NUMBER ASSIGN VAR BIN_OP VAR VAR NUMBER ASSIGN VAR LIST ASSIGN VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR ASSIGN VAR NUMBER NUMBER EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR VAR NUMBER FUNC_CALL STRING VAR STRING |
Consider the following process. You have a binary string (a string where each character is either 0 or 1) $w$ of length $n$ and an integer $x$. You build a new binary string $s$ consisting of $n$ characters. The $i$-th character of $s$ is chosen as follows:
if the character $w_{i-x}$ exists and is equal to 1, then $s_i$ is 1 (formally, if $i > x$ and $w_{i-x} = $ 1, then $s_i = $ 1); if the character $w_{i+x}$ exists and is equal to 1, then $s_i$ is 1 (formally, if $i + x \le n$ and $w_{i+x} = $ 1, then $s_i = $ 1); if both of the aforementioned conditions are false, then $s_i$ is 0.
You are given the integer $x$ and the resulting string $s$. Reconstruct the original string $w$.
-----Input-----
The first line contains one integer $t$ ($1 \le t \le 1000$) β the number of test cases.
Each test case consists of two lines. The first line contains the resulting string $s$ ($2 \le |s| \le 10^5$, each character of $s$ is either 0 or 1). The second line contains one integer $x$ ($1 \le x \le |s| - 1$).
The total length of all strings $s$ in the input does not exceed $10^5$.
-----Output-----
For each test case, print the answer on a separate line as follows:
if no string $w$ can produce the string $s$ at the end of the process, print $-1$; otherwise, print the binary string $w$ consisting of $|s|$ characters. If there are multiple answers, print any of them.
-----Example-----
Input
3
101110
2
01
1
110
1
Output
111011
10
-1 | from sys import stdin, stdout
input = stdin.readline
for _ in range(int(input())):
s = input()
x = int(input())
n = len(s) - 1
ans = [""] * n
for i in range(n):
if i >= x and i + x < n:
if ans[i - x]:
if ans[i - x] == "1" and s[i] == "0":
print(-1)
break
if s[i] == "0":
ans[i + x] = "0"
elif ans[i - x] == "0":
ans[i + x] = "1"
else:
ans[i - x] = s[i]
if s[i] == "0":
ans[i + x] = "0"
elif i >= x:
if ans[i - x]:
if ans[i - x] != s[i]:
print(-1)
break
ans[i - x] = s[i]
elif i + x < n:
ans[i + x] = s[i]
elif s[i] == "1":
print(-1)
break
else:
for i in range(n):
if not ans[i]:
ans[i] = "0"
print("".join(ans)) | ASSIGN VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER ASSIGN VAR BIN_OP LIST STRING VAR FOR VAR FUNC_CALL VAR VAR IF VAR VAR BIN_OP VAR VAR VAR IF VAR BIN_OP VAR VAR IF VAR BIN_OP VAR VAR STRING VAR VAR STRING EXPR FUNC_CALL VAR NUMBER IF VAR VAR STRING ASSIGN VAR BIN_OP VAR VAR STRING IF VAR BIN_OP VAR VAR STRING ASSIGN VAR BIN_OP VAR VAR STRING ASSIGN VAR BIN_OP VAR VAR VAR VAR IF VAR VAR STRING ASSIGN VAR BIN_OP VAR VAR STRING IF VAR VAR IF VAR BIN_OP VAR VAR IF VAR BIN_OP VAR VAR VAR VAR EXPR FUNC_CALL VAR NUMBER ASSIGN VAR BIN_OP VAR VAR VAR VAR IF BIN_OP VAR VAR VAR ASSIGN VAR BIN_OP VAR VAR VAR VAR IF VAR VAR STRING EXPR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR ASSIGN VAR VAR STRING EXPR FUNC_CALL VAR FUNC_CALL STRING VAR |
Consider the following process. You have a binary string (a string where each character is either 0 or 1) $w$ of length $n$ and an integer $x$. You build a new binary string $s$ consisting of $n$ characters. The $i$-th character of $s$ is chosen as follows:
if the character $w_{i-x}$ exists and is equal to 1, then $s_i$ is 1 (formally, if $i > x$ and $w_{i-x} = $ 1, then $s_i = $ 1); if the character $w_{i+x}$ exists and is equal to 1, then $s_i$ is 1 (formally, if $i + x \le n$ and $w_{i+x} = $ 1, then $s_i = $ 1); if both of the aforementioned conditions are false, then $s_i$ is 0.
You are given the integer $x$ and the resulting string $s$. Reconstruct the original string $w$.
-----Input-----
The first line contains one integer $t$ ($1 \le t \le 1000$) β the number of test cases.
Each test case consists of two lines. The first line contains the resulting string $s$ ($2 \le |s| \le 10^5$, each character of $s$ is either 0 or 1). The second line contains one integer $x$ ($1 \le x \le |s| - 1$).
The total length of all strings $s$ in the input does not exceed $10^5$.
-----Output-----
For each test case, print the answer on a separate line as follows:
if no string $w$ can produce the string $s$ at the end of the process, print $-1$; otherwise, print the binary string $w$ consisting of $|s|$ characters. If there are multiple answers, print any of them.
-----Example-----
Input
3
101110
2
01
1
110
1
Output
111011
10
-1 | for _ in range(int(input())):
s = list(map(int, list(input())))
x = int(input())
n = len(s)
a = [(1) for i in range(n)]
for i in range(n):
if i - x >= 0 and s[i] == 0:
a[i - x] = 0
if i + x < n and s[i] == 0:
a[i + x] = 0
temp = [(0) for i in range(n)]
flag = 1
for i in range(n):
if i - x >= 0:
temp[i] |= a[i - x]
if i + x < n:
temp[i] |= a[i + x]
if temp[i] != s[i]:
flag = 0
break
print("".join(list(map(str, a))) if flag == 1 else -1) | FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR IF BIN_OP VAR VAR NUMBER VAR VAR NUMBER ASSIGN VAR BIN_OP VAR VAR NUMBER IF BIN_OP VAR VAR VAR VAR VAR NUMBER ASSIGN VAR BIN_OP VAR VAR NUMBER ASSIGN VAR NUMBER VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF BIN_OP VAR VAR NUMBER VAR VAR VAR BIN_OP VAR VAR IF BIN_OP VAR VAR VAR VAR VAR VAR BIN_OP VAR VAR IF VAR VAR VAR VAR ASSIGN VAR NUMBER EXPR FUNC_CALL VAR VAR NUMBER FUNC_CALL STRING FUNC_CALL VAR FUNC_CALL VAR VAR VAR NUMBER |
Consider the following process. You have a binary string (a string where each character is either 0 or 1) $w$ of length $n$ and an integer $x$. You build a new binary string $s$ consisting of $n$ characters. The $i$-th character of $s$ is chosen as follows:
if the character $w_{i-x}$ exists and is equal to 1, then $s_i$ is 1 (formally, if $i > x$ and $w_{i-x} = $ 1, then $s_i = $ 1); if the character $w_{i+x}$ exists and is equal to 1, then $s_i$ is 1 (formally, if $i + x \le n$ and $w_{i+x} = $ 1, then $s_i = $ 1); if both of the aforementioned conditions are false, then $s_i$ is 0.
You are given the integer $x$ and the resulting string $s$. Reconstruct the original string $w$.
-----Input-----
The first line contains one integer $t$ ($1 \le t \le 1000$) β the number of test cases.
Each test case consists of two lines. The first line contains the resulting string $s$ ($2 \le |s| \le 10^5$, each character of $s$ is either 0 or 1). The second line contains one integer $x$ ($1 \le x \le |s| - 1$).
The total length of all strings $s$ in the input does not exceed $10^5$.
-----Output-----
For each test case, print the answer on a separate line as follows:
if no string $w$ can produce the string $s$ at the end of the process, print $-1$; otherwise, print the binary string $w$ consisting of $|s|$ characters. If there are multiple answers, print any of them.
-----Example-----
Input
3
101110
2
01
1
110
1
Output
111011
10
-1 | import sys
sys.setrecursionlimit(2147483647)
def solve(s, x):
l = len(s)
ans = [1] * l
flags = [0] * l
point = 0
searched = -1
for point in range(l):
a = s[point]
if a == "0":
if point - x >= 0:
if flags[point - x]:
if ans[point - x] != 0:
return -1
else:
ans[point - x] = 0
flags[point - x] = 1
if point + x < l:
ans[point + x] = 0
flags[point + x] = 1
elif point - x < 0:
if point + x >= l:
return -1
else:
ans[point + x] = 1
flags[point + x] = 1
elif point - 2 * x < 0:
ans[point - x] = 1
flags[point - x] = 1
elif flags[point - x] and ans[point - x] == 0:
if point + x >= l:
return -1
else:
ans[point + x] = 1
flags[point + x] = 1
else:
ans[point - x] = 1
flags[point - x] = 1
return "".join(list(map(str, ans)))
def main():
t = int(input())
ans = []
for _ in range(t):
s = input()
x = int(input())
ans.append(solve(s, x))
for r in ans:
print(r)
main() | IMPORT EXPR FUNC_CALL VAR NUMBER FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR IF VAR STRING IF BIN_OP VAR VAR NUMBER IF VAR BIN_OP VAR VAR IF VAR BIN_OP VAR VAR NUMBER RETURN NUMBER ASSIGN VAR BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP VAR VAR NUMBER IF BIN_OP VAR VAR VAR ASSIGN VAR BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP VAR VAR NUMBER IF BIN_OP VAR VAR NUMBER IF BIN_OP VAR VAR VAR RETURN NUMBER ASSIGN VAR BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP VAR VAR NUMBER IF BIN_OP VAR BIN_OP NUMBER VAR NUMBER ASSIGN VAR BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP VAR VAR NUMBER IF VAR BIN_OP VAR VAR VAR BIN_OP VAR VAR NUMBER IF BIN_OP VAR VAR VAR RETURN NUMBER ASSIGN VAR BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP VAR VAR NUMBER RETURN FUNC_CALL STRING FUNC_CALL VAR FUNC_CALL VAR VAR VAR FUNC_DEF ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR FOR VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR |
Consider the following process. You have a binary string (a string where each character is either 0 or 1) $w$ of length $n$ and an integer $x$. You build a new binary string $s$ consisting of $n$ characters. The $i$-th character of $s$ is chosen as follows:
if the character $w_{i-x}$ exists and is equal to 1, then $s_i$ is 1 (formally, if $i > x$ and $w_{i-x} = $ 1, then $s_i = $ 1); if the character $w_{i+x}$ exists and is equal to 1, then $s_i$ is 1 (formally, if $i + x \le n$ and $w_{i+x} = $ 1, then $s_i = $ 1); if both of the aforementioned conditions are false, then $s_i$ is 0.
You are given the integer $x$ and the resulting string $s$. Reconstruct the original string $w$.
-----Input-----
The first line contains one integer $t$ ($1 \le t \le 1000$) β the number of test cases.
Each test case consists of two lines. The first line contains the resulting string $s$ ($2 \le |s| \le 10^5$, each character of $s$ is either 0 or 1). The second line contains one integer $x$ ($1 \le x \le |s| - 1$).
The total length of all strings $s$ in the input does not exceed $10^5$.
-----Output-----
For each test case, print the answer on a separate line as follows:
if no string $w$ can produce the string $s$ at the end of the process, print $-1$; otherwise, print the binary string $w$ consisting of $|s|$ characters. If there are multiple answers, print any of them.
-----Example-----
Input
3
101110
2
01
1
110
1
Output
111011
10
-1 | cases = int(input())
def solve():
w = str(input())
x = int(input())
n = len(w)
s = list("1" * n)
for i in range(n):
if w[i] == "0":
if i - x >= 0:
s[i - x] = "0"
if i + x < n:
s[i + x] = "0"
for i in range(n):
one = False
one = one or i - x >= 0 and s[i - x] == "1"
one = one or i + x < n and s[i + x] == "1"
if one:
a = "0"
if not one:
a = "1"
if w[i] == a:
print(-1)
return
print("".join(s))
while cases:
solve()
cases -= 1 | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_DEF ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR BIN_OP STRING VAR FOR VAR FUNC_CALL VAR VAR IF VAR VAR STRING IF BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP VAR VAR STRING IF BIN_OP VAR VAR VAR ASSIGN VAR BIN_OP VAR VAR STRING FOR VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR VAR BIN_OP VAR VAR NUMBER VAR BIN_OP VAR VAR STRING ASSIGN VAR VAR BIN_OP VAR VAR VAR VAR BIN_OP VAR VAR STRING IF VAR ASSIGN VAR STRING IF VAR ASSIGN VAR STRING IF VAR VAR VAR EXPR FUNC_CALL VAR NUMBER RETURN EXPR FUNC_CALL VAR FUNC_CALL STRING VAR WHILE VAR EXPR FUNC_CALL VAR VAR NUMBER |
Consider the following process. You have a binary string (a string where each character is either 0 or 1) $w$ of length $n$ and an integer $x$. You build a new binary string $s$ consisting of $n$ characters. The $i$-th character of $s$ is chosen as follows:
if the character $w_{i-x}$ exists and is equal to 1, then $s_i$ is 1 (formally, if $i > x$ and $w_{i-x} = $ 1, then $s_i = $ 1); if the character $w_{i+x}$ exists and is equal to 1, then $s_i$ is 1 (formally, if $i + x \le n$ and $w_{i+x} = $ 1, then $s_i = $ 1); if both of the aforementioned conditions are false, then $s_i$ is 0.
You are given the integer $x$ and the resulting string $s$. Reconstruct the original string $w$.
-----Input-----
The first line contains one integer $t$ ($1 \le t \le 1000$) β the number of test cases.
Each test case consists of two lines. The first line contains the resulting string $s$ ($2 \le |s| \le 10^5$, each character of $s$ is either 0 or 1). The second line contains one integer $x$ ($1 \le x \le |s| - 1$).
The total length of all strings $s$ in the input does not exceed $10^5$.
-----Output-----
For each test case, print the answer on a separate line as follows:
if no string $w$ can produce the string $s$ at the end of the process, print $-1$; otherwise, print the binary string $w$ consisting of $|s|$ characters. If there are multiple answers, print any of them.
-----Example-----
Input
3
101110
2
01
1
110
1
Output
111011
10
-1 | t = int(input())
for o in range(t):
m = list(map(int, input()))
x = int(input())
n = len(m)
a = [0] * n
ans = [0] * n
for i in range(n):
if m[i] == 0:
if i - x >= 0:
a[i - x] = 1
if i + x < n:
a[i + x] = 1
for i in range(n):
f = 0
if m[i] == 1:
if i - x >= 0 and a[i - x] == 0:
ans[i - x] = 1
f = 1
if i + x < n and a[i + x] == 0:
ans[i + x] = 1
f = 1
else:
f = 1
if f == 0:
break
if f == 0:
print(-1)
else:
print(*ans, sep="") | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR BIN_OP LIST NUMBER VAR FOR VAR FUNC_CALL VAR VAR IF VAR VAR NUMBER IF BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP VAR VAR NUMBER IF BIN_OP VAR VAR VAR ASSIGN VAR BIN_OP VAR VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER IF VAR VAR NUMBER IF BIN_OP VAR VAR NUMBER VAR BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP VAR VAR NUMBER ASSIGN VAR NUMBER IF BIN_OP VAR VAR VAR VAR BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP VAR VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER IF VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR VAR STRING |
Consider the following process. You have a binary string (a string where each character is either 0 or 1) $w$ of length $n$ and an integer $x$. You build a new binary string $s$ consisting of $n$ characters. The $i$-th character of $s$ is chosen as follows:
if the character $w_{i-x}$ exists and is equal to 1, then $s_i$ is 1 (formally, if $i > x$ and $w_{i-x} = $ 1, then $s_i = $ 1); if the character $w_{i+x}$ exists and is equal to 1, then $s_i$ is 1 (formally, if $i + x \le n$ and $w_{i+x} = $ 1, then $s_i = $ 1); if both of the aforementioned conditions are false, then $s_i$ is 0.
You are given the integer $x$ and the resulting string $s$. Reconstruct the original string $w$.
-----Input-----
The first line contains one integer $t$ ($1 \le t \le 1000$) β the number of test cases.
Each test case consists of two lines. The first line contains the resulting string $s$ ($2 \le |s| \le 10^5$, each character of $s$ is either 0 or 1). The second line contains one integer $x$ ($1 \le x \le |s| - 1$).
The total length of all strings $s$ in the input does not exceed $10^5$.
-----Output-----
For each test case, print the answer on a separate line as follows:
if no string $w$ can produce the string $s$ at the end of the process, print $-1$; otherwise, print the binary string $w$ consisting of $|s|$ characters. If there are multiple answers, print any of them.
-----Example-----
Input
3
101110
2
01
1
110
1
Output
111011
10
-1 | import sys
def minp():
return sys.stdin.readline().strip()
def mint():
return int(minp())
def mints():
return map(int, minp().split())
def check(s, n, v):
for i in range(n):
if s[i : i + n].count(v) == 0:
return False
return True
def solve():
s = minp()
x = mint()
n = len(s)
a = [None] * n
for i in range(n):
if i - x >= 0:
if i + x < n:
if s[i] == "0":
if a[i + x] is not None and a[i + x] != "0":
print(-1)
return
if a[i - x] is not None and a[i - x] != "0":
print(-1)
return
a[i - x] = "0"
a[i + x] = "0"
else:
if a[i - x] is not None and a[i - x] != s[i]:
print(-1)
return
a[i - x] = s[i]
elif i + x < n:
if a[i + x] is not None and a[i + x] != s[i]:
print(-1)
return
a[i + x] = s[i]
for i in range(n):
if a[i] is None:
a[i] = "1"
for i in range(n):
c = "0"
if i - x >= 0 and a[i - x] == "1":
c = "1"
elif i + x < n and a[i + x] == "1":
c = "1"
if s[i] != c:
print(-1)
return
print("".join(a))
for i in range(mint()):
solve() | IMPORT FUNC_DEF RETURN FUNC_CALL FUNC_CALL VAR FUNC_DEF RETURN FUNC_CALL VAR FUNC_CALL VAR FUNC_DEF RETURN FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FUNC_DEF FOR VAR FUNC_CALL VAR VAR IF FUNC_CALL VAR VAR BIN_OP VAR VAR VAR NUMBER RETURN NUMBER RETURN NUMBER FUNC_DEF ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP LIST NONE VAR FOR VAR FUNC_CALL VAR VAR IF BIN_OP VAR VAR NUMBER IF BIN_OP VAR VAR VAR IF VAR VAR STRING IF VAR BIN_OP VAR VAR NONE VAR BIN_OP VAR VAR STRING EXPR FUNC_CALL VAR NUMBER RETURN IF VAR BIN_OP VAR VAR NONE VAR BIN_OP VAR VAR STRING EXPR FUNC_CALL VAR NUMBER RETURN ASSIGN VAR BIN_OP VAR VAR STRING ASSIGN VAR BIN_OP VAR VAR STRING IF VAR BIN_OP VAR VAR NONE VAR BIN_OP VAR VAR VAR VAR EXPR FUNC_CALL VAR NUMBER RETURN ASSIGN VAR BIN_OP VAR VAR VAR VAR IF BIN_OP VAR VAR VAR IF VAR BIN_OP VAR VAR NONE VAR BIN_OP VAR VAR VAR VAR EXPR FUNC_CALL VAR NUMBER RETURN ASSIGN VAR BIN_OP VAR VAR VAR VAR FOR VAR FUNC_CALL VAR VAR IF VAR VAR NONE ASSIGN VAR VAR STRING FOR VAR FUNC_CALL VAR VAR ASSIGN VAR STRING IF BIN_OP VAR VAR NUMBER VAR BIN_OP VAR VAR STRING ASSIGN VAR STRING IF BIN_OP VAR VAR VAR VAR BIN_OP VAR VAR STRING ASSIGN VAR STRING IF VAR VAR VAR EXPR FUNC_CALL VAR NUMBER RETURN EXPR FUNC_CALL VAR FUNC_CALL STRING VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR EXPR FUNC_CALL VAR |
Consider the following process. You have a binary string (a string where each character is either 0 or 1) $w$ of length $n$ and an integer $x$. You build a new binary string $s$ consisting of $n$ characters. The $i$-th character of $s$ is chosen as follows:
if the character $w_{i-x}$ exists and is equal to 1, then $s_i$ is 1 (formally, if $i > x$ and $w_{i-x} = $ 1, then $s_i = $ 1); if the character $w_{i+x}$ exists and is equal to 1, then $s_i$ is 1 (formally, if $i + x \le n$ and $w_{i+x} = $ 1, then $s_i = $ 1); if both of the aforementioned conditions are false, then $s_i$ is 0.
You are given the integer $x$ and the resulting string $s$. Reconstruct the original string $w$.
-----Input-----
The first line contains one integer $t$ ($1 \le t \le 1000$) β the number of test cases.
Each test case consists of two lines. The first line contains the resulting string $s$ ($2 \le |s| \le 10^5$, each character of $s$ is either 0 or 1). The second line contains one integer $x$ ($1 \le x \le |s| - 1$).
The total length of all strings $s$ in the input does not exceed $10^5$.
-----Output-----
For each test case, print the answer on a separate line as follows:
if no string $w$ can produce the string $s$ at the end of the process, print $-1$; otherwise, print the binary string $w$ consisting of $|s|$ characters. If there are multiple answers, print any of them.
-----Example-----
Input
3
101110
2
01
1
110
1
Output
111011
10
-1 | for _ in range(int(input())):
s = input()
n = len(s)
x = int(input())
a = [int(i) for i in s]
w = [None] * n
for i in range(n):
if a[i] == 0:
if i - x >= 0:
w[i - x] = 0
if i + x < n:
w[i + x] = 0
flag = 0
for i in range(n):
if a[i] == 1:
if i - x >= 0 and w[i - x] == 0:
if i + x < n and w[i + x] == 0 or i + x >= n:
flag = 1
break
if i + x < n and w[i + x] == 0:
if i - x >= 0 and w[i - x] == 0 or i - x < 0:
flag = 1
break
if i + x >= n and i - x < 0:
flag = 1
break
if flag == 1:
print(-1)
else:
t = w.copy()
for i in range(n):
if t[i] == None:
w[i] = str(1)
else:
w[i] = str(t[i])
st = "".join(w)
print(st) | FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR ASSIGN VAR BIN_OP LIST NONE VAR FOR VAR FUNC_CALL VAR VAR IF VAR VAR NUMBER IF BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP VAR VAR NUMBER IF BIN_OP VAR VAR VAR ASSIGN VAR BIN_OP VAR VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR NUMBER IF BIN_OP VAR VAR NUMBER VAR BIN_OP VAR VAR NUMBER IF BIN_OP VAR VAR VAR VAR BIN_OP VAR VAR NUMBER BIN_OP VAR VAR VAR ASSIGN VAR NUMBER IF BIN_OP VAR VAR VAR VAR BIN_OP VAR VAR NUMBER IF BIN_OP VAR VAR NUMBER VAR BIN_OP VAR VAR NUMBER BIN_OP VAR VAR NUMBER ASSIGN VAR NUMBER IF BIN_OP VAR VAR VAR BIN_OP VAR VAR NUMBER ASSIGN VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER ASSIGN VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR IF VAR VAR NONE ASSIGN VAR VAR FUNC_CALL VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL STRING VAR EXPR FUNC_CALL VAR VAR |
Consider the following process. You have a binary string (a string where each character is either 0 or 1) $w$ of length $n$ and an integer $x$. You build a new binary string $s$ consisting of $n$ characters. The $i$-th character of $s$ is chosen as follows:
if the character $w_{i-x}$ exists and is equal to 1, then $s_i$ is 1 (formally, if $i > x$ and $w_{i-x} = $ 1, then $s_i = $ 1); if the character $w_{i+x}$ exists and is equal to 1, then $s_i$ is 1 (formally, if $i + x \le n$ and $w_{i+x} = $ 1, then $s_i = $ 1); if both of the aforementioned conditions are false, then $s_i$ is 0.
You are given the integer $x$ and the resulting string $s$. Reconstruct the original string $w$.
-----Input-----
The first line contains one integer $t$ ($1 \le t \le 1000$) β the number of test cases.
Each test case consists of two lines. The first line contains the resulting string $s$ ($2 \le |s| \le 10^5$, each character of $s$ is either 0 or 1). The second line contains one integer $x$ ($1 \le x \le |s| - 1$).
The total length of all strings $s$ in the input does not exceed $10^5$.
-----Output-----
For each test case, print the answer on a separate line as follows:
if no string $w$ can produce the string $s$ at the end of the process, print $-1$; otherwise, print the binary string $w$ consisting of $|s|$ characters. If there are multiple answers, print any of them.
-----Example-----
Input
3
101110
2
01
1
110
1
Output
111011
10
-1 | def solv():
main = input()
x = int(input())
ans = ["-"] * len(main)
for i in range(len(main)):
if main[i] == "0":
if x <= i:
ans[i - x] = "0"
if x + i < len(ans):
ans[i + x] = "0"
for i in range(len(main)):
if ans[i] != "0":
ans[i] = "1"
for i in range(len(main)):
if main[i] == "1":
if not (
x <= i and ans[i - x] == "1" or x + i < len(ans) and ans[i + x] == "1"
):
print("-1")
return
print(*ans, sep="")
for _ in range(int(input())):
solv() | FUNC_DEF ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR BIN_OP LIST STRING FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR STRING IF VAR VAR ASSIGN VAR BIN_OP VAR VAR STRING IF BIN_OP VAR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR VAR STRING FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR STRING ASSIGN VAR VAR STRING FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR STRING IF VAR VAR VAR BIN_OP VAR VAR STRING BIN_OP VAR VAR FUNC_CALL VAR VAR VAR BIN_OP VAR VAR STRING EXPR FUNC_CALL VAR STRING RETURN EXPR FUNC_CALL VAR VAR STRING FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR EXPR FUNC_CALL VAR |
Consider the following process. You have a binary string (a string where each character is either 0 or 1) $w$ of length $n$ and an integer $x$. You build a new binary string $s$ consisting of $n$ characters. The $i$-th character of $s$ is chosen as follows:
if the character $w_{i-x}$ exists and is equal to 1, then $s_i$ is 1 (formally, if $i > x$ and $w_{i-x} = $ 1, then $s_i = $ 1); if the character $w_{i+x}$ exists and is equal to 1, then $s_i$ is 1 (formally, if $i + x \le n$ and $w_{i+x} = $ 1, then $s_i = $ 1); if both of the aforementioned conditions are false, then $s_i$ is 0.
You are given the integer $x$ and the resulting string $s$. Reconstruct the original string $w$.
-----Input-----
The first line contains one integer $t$ ($1 \le t \le 1000$) β the number of test cases.
Each test case consists of two lines. The first line contains the resulting string $s$ ($2 \le |s| \le 10^5$, each character of $s$ is either 0 or 1). The second line contains one integer $x$ ($1 \le x \le |s| - 1$).
The total length of all strings $s$ in the input does not exceed $10^5$.
-----Output-----
For each test case, print the answer on a separate line as follows:
if no string $w$ can produce the string $s$ at the end of the process, print $-1$; otherwise, print the binary string $w$ consisting of $|s|$ characters. If there are multiple answers, print any of them.
-----Example-----
Input
3
101110
2
01
1
110
1
Output
111011
10
-1 | t = int(input())
for you in range(t):
s = input()
n = len(s)
x = int(input())
arr = [(1) for i in range(n)]
poss = 1
for i in range(n):
if s[i] == "1":
if i - x >= 0 and arr[i - x] == 0 and i + x < n and arr[i + x] == 0:
poss = 0
break
else:
if i - x >= 0:
arr[i - x] = 0
if i + x < n:
arr[i + x] = 0
if poss == 0:
print(-1)
continue
isposs = ""
for i in range(n):
if i - x >= 0 and arr[i - x]:
isposs = isposs + "1"
elif i + x < n and arr[i + x]:
isposs = isposs + "1"
else:
isposs = isposs + "0"
if isposs == s:
for i in arr:
print(i, end="")
print()
else:
print(-1) | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR STRING IF BIN_OP VAR VAR NUMBER VAR BIN_OP VAR VAR NUMBER BIN_OP VAR VAR VAR VAR BIN_OP VAR VAR NUMBER ASSIGN VAR NUMBER IF BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP VAR VAR NUMBER IF BIN_OP VAR VAR VAR ASSIGN VAR BIN_OP VAR VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER ASSIGN VAR STRING FOR VAR FUNC_CALL VAR VAR IF BIN_OP VAR VAR NUMBER VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP VAR STRING IF BIN_OP VAR VAR VAR VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP VAR STRING ASSIGN VAR BIN_OP VAR STRING IF VAR VAR FOR VAR VAR EXPR FUNC_CALL VAR VAR STRING EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR NUMBER |
Consider the following process. You have a binary string (a string where each character is either 0 or 1) $w$ of length $n$ and an integer $x$. You build a new binary string $s$ consisting of $n$ characters. The $i$-th character of $s$ is chosen as follows:
if the character $w_{i-x}$ exists and is equal to 1, then $s_i$ is 1 (formally, if $i > x$ and $w_{i-x} = $ 1, then $s_i = $ 1); if the character $w_{i+x}$ exists and is equal to 1, then $s_i$ is 1 (formally, if $i + x \le n$ and $w_{i+x} = $ 1, then $s_i = $ 1); if both of the aforementioned conditions are false, then $s_i$ is 0.
You are given the integer $x$ and the resulting string $s$. Reconstruct the original string $w$.
-----Input-----
The first line contains one integer $t$ ($1 \le t \le 1000$) β the number of test cases.
Each test case consists of two lines. The first line contains the resulting string $s$ ($2 \le |s| \le 10^5$, each character of $s$ is either 0 or 1). The second line contains one integer $x$ ($1 \le x \le |s| - 1$).
The total length of all strings $s$ in the input does not exceed $10^5$.
-----Output-----
For each test case, print the answer on a separate line as follows:
if no string $w$ can produce the string $s$ at the end of the process, print $-1$; otherwise, print the binary string $w$ consisting of $|s|$ characters. If there are multiple answers, print any of them.
-----Example-----
Input
3
101110
2
01
1
110
1
Output
111011
10
-1 | t = int(input())
for i in range(t):
s = input()
x = int(input())
w = [1] * len(s)
for i in range(0, len(s)):
if int(s[i]) == 0:
if i - x >= 0:
w[i - x] = 0
if x + i < len(s):
w[i + x] = 0
for i in range(0, len(s)):
if int(s[i]) == 1:
sumation = 0
if i - x >= 0:
sumation += w[i - x]
if x + i < len(s):
sumation += w[i + x]
if sumation < 1:
print(-1)
break
else:
print("".join(map(str, w))) | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR IF FUNC_CALL VAR VAR VAR NUMBER IF BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP VAR VAR NUMBER IF BIN_OP VAR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR IF FUNC_CALL VAR VAR VAR NUMBER ASSIGN VAR NUMBER IF BIN_OP VAR VAR NUMBER VAR VAR BIN_OP VAR VAR IF BIN_OP VAR VAR FUNC_CALL VAR VAR VAR VAR BIN_OP VAR VAR IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL STRING FUNC_CALL VAR VAR VAR |
Consider the following process. You have a binary string (a string where each character is either 0 or 1) $w$ of length $n$ and an integer $x$. You build a new binary string $s$ consisting of $n$ characters. The $i$-th character of $s$ is chosen as follows:
if the character $w_{i-x}$ exists and is equal to 1, then $s_i$ is 1 (formally, if $i > x$ and $w_{i-x} = $ 1, then $s_i = $ 1); if the character $w_{i+x}$ exists and is equal to 1, then $s_i$ is 1 (formally, if $i + x \le n$ and $w_{i+x} = $ 1, then $s_i = $ 1); if both of the aforementioned conditions are false, then $s_i$ is 0.
You are given the integer $x$ and the resulting string $s$. Reconstruct the original string $w$.
-----Input-----
The first line contains one integer $t$ ($1 \le t \le 1000$) β the number of test cases.
Each test case consists of two lines. The first line contains the resulting string $s$ ($2 \le |s| \le 10^5$, each character of $s$ is either 0 or 1). The second line contains one integer $x$ ($1 \le x \le |s| - 1$).
The total length of all strings $s$ in the input does not exceed $10^5$.
-----Output-----
For each test case, print the answer on a separate line as follows:
if no string $w$ can produce the string $s$ at the end of the process, print $-1$; otherwise, print the binary string $w$ consisting of $|s|$ characters. If there are multiple answers, print any of them.
-----Example-----
Input
3
101110
2
01
1
110
1
Output
111011
10
-1 | from sys import stdin
input = stdin.readline
q = int(input())
for _ in range(q):
s = input()
n = len(s) - 1
x = int(input())
pocz = ["1"] * n
for i in range(n):
if i - x >= 0 and s[i - x] == "0":
pocz[i] = "0"
if i + x < n and s[i + x] == "0":
pocz[i] = "0"
odp = True
for i in range(n):
if s[i] == "1":
dupa = []
if i - x >= 0:
dupa.append(pocz[i - x])
if i + x < n:
dupa.append(pocz[i + x])
if dupa.count("1") == 0:
odp = False
if odp:
print("".join(pocz))
else:
print(-1) | ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR BIN_OP LIST STRING VAR FOR VAR FUNC_CALL VAR VAR IF BIN_OP VAR VAR NUMBER VAR BIN_OP VAR VAR STRING ASSIGN VAR VAR STRING IF BIN_OP VAR VAR VAR VAR BIN_OP VAR VAR STRING ASSIGN VAR VAR STRING ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR STRING ASSIGN VAR LIST IF BIN_OP VAR VAR NUMBER EXPR FUNC_CALL VAR VAR BIN_OP VAR VAR IF BIN_OP VAR VAR VAR EXPR FUNC_CALL VAR VAR BIN_OP VAR VAR IF FUNC_CALL VAR STRING NUMBER ASSIGN VAR NUMBER IF VAR EXPR FUNC_CALL VAR FUNC_CALL STRING VAR EXPR FUNC_CALL VAR NUMBER |
Consider the following process. You have a binary string (a string where each character is either 0 or 1) $w$ of length $n$ and an integer $x$. You build a new binary string $s$ consisting of $n$ characters. The $i$-th character of $s$ is chosen as follows:
if the character $w_{i-x}$ exists and is equal to 1, then $s_i$ is 1 (formally, if $i > x$ and $w_{i-x} = $ 1, then $s_i = $ 1); if the character $w_{i+x}$ exists and is equal to 1, then $s_i$ is 1 (formally, if $i + x \le n$ and $w_{i+x} = $ 1, then $s_i = $ 1); if both of the aforementioned conditions are false, then $s_i$ is 0.
You are given the integer $x$ and the resulting string $s$. Reconstruct the original string $w$.
-----Input-----
The first line contains one integer $t$ ($1 \le t \le 1000$) β the number of test cases.
Each test case consists of two lines. The first line contains the resulting string $s$ ($2 \le |s| \le 10^5$, each character of $s$ is either 0 or 1). The second line contains one integer $x$ ($1 \le x \le |s| - 1$).
The total length of all strings $s$ in the input does not exceed $10^5$.
-----Output-----
For each test case, print the answer on a separate line as follows:
if no string $w$ can produce the string $s$ at the end of the process, print $-1$; otherwise, print the binary string $w$ consisting of $|s|$ characters. If there are multiple answers, print any of them.
-----Example-----
Input
3
101110
2
01
1
110
1
Output
111011
10
-1 | for _ in range(int(input())):
s = str(input())
n = int(input())
l = [1] * len(s)
for i in range(len(s)):
if s[i] == "0":
if i - n >= 0:
l[i - n] = 0
if i + n < len(s):
l[i + n] = 0
a = ""
for i in range(len(l)):
a = a + str(l[i])
t = ""
k = 0
for i in range(len(a)):
if i - n >= 0 and a[i - n] == "1":
k = 1
if i + n < len(l) and a[i + n] == "1":
k = 1
t = t + str(k)
k = 0
if t == s:
print(a)
else:
print(-1) | FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR STRING IF BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP VAR VAR NUMBER IF BIN_OP VAR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR VAR NUMBER ASSIGN VAR STRING FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR FUNC_CALL VAR VAR VAR ASSIGN VAR STRING ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF BIN_OP VAR VAR NUMBER VAR BIN_OP VAR VAR STRING ASSIGN VAR NUMBER IF BIN_OP VAR VAR FUNC_CALL VAR VAR VAR BIN_OP VAR VAR STRING ASSIGN VAR NUMBER ASSIGN VAR BIN_OP VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER IF VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR NUMBER |
Consider the following process. You have a binary string (a string where each character is either 0 or 1) $w$ of length $n$ and an integer $x$. You build a new binary string $s$ consisting of $n$ characters. The $i$-th character of $s$ is chosen as follows:
if the character $w_{i-x}$ exists and is equal to 1, then $s_i$ is 1 (formally, if $i > x$ and $w_{i-x} = $ 1, then $s_i = $ 1); if the character $w_{i+x}$ exists and is equal to 1, then $s_i$ is 1 (formally, if $i + x \le n$ and $w_{i+x} = $ 1, then $s_i = $ 1); if both of the aforementioned conditions are false, then $s_i$ is 0.
You are given the integer $x$ and the resulting string $s$. Reconstruct the original string $w$.
-----Input-----
The first line contains one integer $t$ ($1 \le t \le 1000$) β the number of test cases.
Each test case consists of two lines. The first line contains the resulting string $s$ ($2 \le |s| \le 10^5$, each character of $s$ is either 0 or 1). The second line contains one integer $x$ ($1 \le x \le |s| - 1$).
The total length of all strings $s$ in the input does not exceed $10^5$.
-----Output-----
For each test case, print the answer on a separate line as follows:
if no string $w$ can produce the string $s$ at the end of the process, print $-1$; otherwise, print the binary string $w$ consisting of $|s|$ characters. If there are multiple answers, print any of them.
-----Example-----
Input
3
101110
2
01
1
110
1
Output
111011
10
-1 | def solve(s, x, n):
arr = [1] * n
for i in range(n):
if s[i] == "0":
if i - x >= 0:
arr[i - x] = 0
if i + x < n:
arr[i + x] = 0
for i in range(n):
if s[i] == "1":
if i - x < 0 and i + x >= n:
return -1
if i - x < 0:
if i + x < n:
if arr[i + x] == 0:
return -1
if i + x >= n:
if i - x >= 0:
if arr[i - x] == 0:
return -1
if i - x >= 0 and i + x < n:
if arr[i - x] == 0 and arr[i + x] == 0:
return -1
return "".join(map(str, arr))
t = int(input())
for i in range(t):
s = input()
x = int(input())
print(solve(s, x, len(s))) | FUNC_DEF ASSIGN VAR BIN_OP LIST NUMBER VAR FOR VAR FUNC_CALL VAR VAR IF VAR VAR STRING IF BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP VAR VAR NUMBER IF BIN_OP VAR VAR VAR ASSIGN VAR BIN_OP VAR VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR STRING IF BIN_OP VAR VAR NUMBER BIN_OP VAR VAR VAR RETURN NUMBER IF BIN_OP VAR VAR NUMBER IF BIN_OP VAR VAR VAR IF VAR BIN_OP VAR VAR NUMBER RETURN NUMBER IF BIN_OP VAR VAR VAR IF BIN_OP VAR VAR NUMBER IF VAR BIN_OP VAR VAR NUMBER RETURN NUMBER IF BIN_OP VAR VAR NUMBER BIN_OP VAR VAR VAR IF VAR BIN_OP VAR VAR NUMBER VAR BIN_OP VAR VAR NUMBER RETURN NUMBER RETURN FUNC_CALL STRING FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR |
Consider the following process. You have a binary string (a string where each character is either 0 or 1) $w$ of length $n$ and an integer $x$. You build a new binary string $s$ consisting of $n$ characters. The $i$-th character of $s$ is chosen as follows:
if the character $w_{i-x}$ exists and is equal to 1, then $s_i$ is 1 (formally, if $i > x$ and $w_{i-x} = $ 1, then $s_i = $ 1); if the character $w_{i+x}$ exists and is equal to 1, then $s_i$ is 1 (formally, if $i + x \le n$ and $w_{i+x} = $ 1, then $s_i = $ 1); if both of the aforementioned conditions are false, then $s_i$ is 0.
You are given the integer $x$ and the resulting string $s$. Reconstruct the original string $w$.
-----Input-----
The first line contains one integer $t$ ($1 \le t \le 1000$) β the number of test cases.
Each test case consists of two lines. The first line contains the resulting string $s$ ($2 \le |s| \le 10^5$, each character of $s$ is either 0 or 1). The second line contains one integer $x$ ($1 \le x \le |s| - 1$).
The total length of all strings $s$ in the input does not exceed $10^5$.
-----Output-----
For each test case, print the answer on a separate line as follows:
if no string $w$ can produce the string $s$ at the end of the process, print $-1$; otherwise, print the binary string $w$ consisting of $|s|$ characters. If there are multiple answers, print any of them.
-----Example-----
Input
3
101110
2
01
1
110
1
Output
111011
10
-1 | t = int(input().split()[0])
for case in range(t):
s = list(input().split()[0])
x = int(input().split()[0])
original = list("1" * len(s))
for c in range(len(s)):
if s[c] == "0":
if c - x >= 0:
original[c - x] = "0"
if c + x < len(s):
original[c + x] = "0"
check = []
for c in range(len(s)):
curr = "0"
if c - x >= 0 and original[c - x] == "1":
curr = "1"
if c + x < len(s) and original[c + x] == "1":
curr = "1"
check.append(curr)
if check == s:
print("".join(original))
else:
print("-1") | ASSIGN VAR FUNC_CALL VAR FUNC_CALL FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL FUNC_CALL VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL FUNC_CALL VAR NUMBER ASSIGN VAR FUNC_CALL VAR BIN_OP STRING FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR STRING IF BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP VAR VAR STRING IF BIN_OP VAR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR VAR STRING ASSIGN VAR LIST FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR STRING IF BIN_OP VAR VAR NUMBER VAR BIN_OP VAR VAR STRING ASSIGN VAR STRING IF BIN_OP VAR VAR FUNC_CALL VAR VAR VAR BIN_OP VAR VAR STRING ASSIGN VAR STRING EXPR FUNC_CALL VAR VAR IF VAR VAR EXPR FUNC_CALL VAR FUNC_CALL STRING VAR EXPR FUNC_CALL VAR STRING |
Consider the following process. You have a binary string (a string where each character is either 0 or 1) $w$ of length $n$ and an integer $x$. You build a new binary string $s$ consisting of $n$ characters. The $i$-th character of $s$ is chosen as follows:
if the character $w_{i-x}$ exists and is equal to 1, then $s_i$ is 1 (formally, if $i > x$ and $w_{i-x} = $ 1, then $s_i = $ 1); if the character $w_{i+x}$ exists and is equal to 1, then $s_i$ is 1 (formally, if $i + x \le n$ and $w_{i+x} = $ 1, then $s_i = $ 1); if both of the aforementioned conditions are false, then $s_i$ is 0.
You are given the integer $x$ and the resulting string $s$. Reconstruct the original string $w$.
-----Input-----
The first line contains one integer $t$ ($1 \le t \le 1000$) β the number of test cases.
Each test case consists of two lines. The first line contains the resulting string $s$ ($2 \le |s| \le 10^5$, each character of $s$ is either 0 or 1). The second line contains one integer $x$ ($1 \le x \le |s| - 1$).
The total length of all strings $s$ in the input does not exceed $10^5$.
-----Output-----
For each test case, print the answer on a separate line as follows:
if no string $w$ can produce the string $s$ at the end of the process, print $-1$; otherwise, print the binary string $w$ consisting of $|s|$ characters. If there are multiple answers, print any of them.
-----Example-----
Input
3
101110
2
01
1
110
1
Output
111011
10
-1 | for _ in range(int(input())):
s = input()
x = int(input())
flag = True
ans = ["2"] * len(s)
for i in range(len(s)):
if s[i] == "0":
if i + x < len(s):
if ans[i + x] == "1":
flag = False
break
ans[i + x] = "0"
if i - x >= 0:
if ans[i - x] == "1":
flag = False
break
ans[i - x] = "0"
elif s[i] == "1":
if i + x >= len(s) and i - x < 0:
flag = False
break
if i + x < len(s) and i - x < 0:
if ans[i + x] == "0":
flag = False
break
ans[i + x] = "1"
elif i + x >= len(s) and i - x >= 0:
if ans[i - x] == "0":
flag = False
break
ans[i - x] = "1"
elif i + x < len(s) and i - x >= 0:
if ans[i - x] == "0" and ans[i + x] == "0":
flag = False
break
elif ans[i - x] == "0":
ans[i + x] = "1"
elif ans[i + x] == "0":
ans[i - x] = "1"
temp = ""
for i in range(len(s)):
if ans[i] == "2":
ans[i] = "1"
temp += ans[i]
else:
temp += ans[i]
if flag:
print(temp)
else:
print("-1") | FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR BIN_OP LIST STRING FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR STRING IF BIN_OP VAR VAR FUNC_CALL VAR VAR IF VAR BIN_OP VAR VAR STRING ASSIGN VAR NUMBER ASSIGN VAR BIN_OP VAR VAR STRING IF BIN_OP VAR VAR NUMBER IF VAR BIN_OP VAR VAR STRING ASSIGN VAR NUMBER ASSIGN VAR BIN_OP VAR VAR STRING IF VAR VAR STRING IF BIN_OP VAR VAR FUNC_CALL VAR VAR BIN_OP VAR VAR NUMBER ASSIGN VAR NUMBER IF BIN_OP VAR VAR FUNC_CALL VAR VAR BIN_OP VAR VAR NUMBER IF VAR BIN_OP VAR VAR STRING ASSIGN VAR NUMBER ASSIGN VAR BIN_OP VAR VAR STRING IF BIN_OP VAR VAR FUNC_CALL VAR VAR BIN_OP VAR VAR NUMBER IF VAR BIN_OP VAR VAR STRING ASSIGN VAR NUMBER ASSIGN VAR BIN_OP VAR VAR STRING IF BIN_OP VAR VAR FUNC_CALL VAR VAR BIN_OP VAR VAR NUMBER IF VAR BIN_OP VAR VAR STRING VAR BIN_OP VAR VAR STRING ASSIGN VAR NUMBER IF VAR BIN_OP VAR VAR STRING ASSIGN VAR BIN_OP VAR VAR STRING IF VAR BIN_OP VAR VAR STRING ASSIGN VAR BIN_OP VAR VAR STRING ASSIGN VAR STRING FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR STRING ASSIGN VAR VAR STRING VAR VAR VAR VAR VAR VAR IF VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR STRING |
Consider the following process. You have a binary string (a string where each character is either 0 or 1) $w$ of length $n$ and an integer $x$. You build a new binary string $s$ consisting of $n$ characters. The $i$-th character of $s$ is chosen as follows:
if the character $w_{i-x}$ exists and is equal to 1, then $s_i$ is 1 (formally, if $i > x$ and $w_{i-x} = $ 1, then $s_i = $ 1); if the character $w_{i+x}$ exists and is equal to 1, then $s_i$ is 1 (formally, if $i + x \le n$ and $w_{i+x} = $ 1, then $s_i = $ 1); if both of the aforementioned conditions are false, then $s_i$ is 0.
You are given the integer $x$ and the resulting string $s$. Reconstruct the original string $w$.
-----Input-----
The first line contains one integer $t$ ($1 \le t \le 1000$) β the number of test cases.
Each test case consists of two lines. The first line contains the resulting string $s$ ($2 \le |s| \le 10^5$, each character of $s$ is either 0 or 1). The second line contains one integer $x$ ($1 \le x \le |s| - 1$).
The total length of all strings $s$ in the input does not exceed $10^5$.
-----Output-----
For each test case, print the answer on a separate line as follows:
if no string $w$ can produce the string $s$ at the end of the process, print $-1$; otherwise, print the binary string $w$ consisting of $|s|$ characters. If there are multiple answers, print any of them.
-----Example-----
Input
3
101110
2
01
1
110
1
Output
111011
10
-1 | for t in range(int(input())):
s = input()
x = int(input())
n = len(s)
a = ["1" for i in range(n)]
for i in range(n):
if i + x < n and s[i] == "0":
a[i + x] = "0"
if i - x >= 0 and s[i] == "0":
a[i - x] = "0"
f = True
for i in range(n):
flag = False
flag = flag or i + x < n and a[i + x] == "1"
flag = flag or i - x >= 0 and a[i - x] == "1"
if s[i] == "1" and flag == False or s[i] == "0" and flag:
f = False
print(-1)
break
if f:
for i in a:
print(i, end="")
print() | FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR STRING VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR IF BIN_OP VAR VAR VAR VAR VAR STRING ASSIGN VAR BIN_OP VAR VAR STRING IF BIN_OP VAR VAR NUMBER VAR VAR STRING ASSIGN VAR BIN_OP VAR VAR STRING ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR VAR BIN_OP VAR VAR VAR VAR BIN_OP VAR VAR STRING ASSIGN VAR VAR BIN_OP VAR VAR NUMBER VAR BIN_OP VAR VAR STRING IF VAR VAR STRING VAR NUMBER VAR VAR STRING VAR ASSIGN VAR NUMBER EXPR FUNC_CALL VAR NUMBER IF VAR FOR VAR VAR EXPR FUNC_CALL VAR VAR STRING EXPR FUNC_CALL VAR |
Consider the following process. You have a binary string (a string where each character is either 0 or 1) $w$ of length $n$ and an integer $x$. You build a new binary string $s$ consisting of $n$ characters. The $i$-th character of $s$ is chosen as follows:
if the character $w_{i-x}$ exists and is equal to 1, then $s_i$ is 1 (formally, if $i > x$ and $w_{i-x} = $ 1, then $s_i = $ 1); if the character $w_{i+x}$ exists and is equal to 1, then $s_i$ is 1 (formally, if $i + x \le n$ and $w_{i+x} = $ 1, then $s_i = $ 1); if both of the aforementioned conditions are false, then $s_i$ is 0.
You are given the integer $x$ and the resulting string $s$. Reconstruct the original string $w$.
-----Input-----
The first line contains one integer $t$ ($1 \le t \le 1000$) β the number of test cases.
Each test case consists of two lines. The first line contains the resulting string $s$ ($2 \le |s| \le 10^5$, each character of $s$ is either 0 or 1). The second line contains one integer $x$ ($1 \le x \le |s| - 1$).
The total length of all strings $s$ in the input does not exceed $10^5$.
-----Output-----
For each test case, print the answer on a separate line as follows:
if no string $w$ can produce the string $s$ at the end of the process, print $-1$; otherwise, print the binary string $w$ consisting of $|s|$ characters. If there are multiple answers, print any of them.
-----Example-----
Input
3
101110
2
01
1
110
1
Output
111011
10
-1 | t = int(input())
def solve():
s = input()
x = int(input())
w = [None] * len(s)
for i, dig in enumerate(s):
if dig == "0":
if i + x < len(s):
w[i + x] = 0
if i - x >= 0:
w[i - x] = 0
for i in range(len(s)):
if w[i] == None:
w[i] = 1
recreated_s = [None] * len(s)
for i in range(len(s)):
if i + x < len(s) and w[i + x] == 1:
recreated_s[i] = "1"
elif i - x >= 0 and w[i - x] == 1:
recreated_s[i] = "1"
else:
recreated_s[i] = "0"
if "".join(recreated_s) == s:
print("".join(map(str, w)))
else:
print(-1)
while t:
solve()
t -= 1 | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_DEF ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NONE FUNC_CALL VAR VAR FOR VAR VAR FUNC_CALL VAR VAR IF VAR STRING IF BIN_OP VAR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR VAR NUMBER IF BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP VAR VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR NONE ASSIGN VAR VAR NUMBER ASSIGN VAR BIN_OP LIST NONE FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF BIN_OP VAR VAR FUNC_CALL VAR VAR VAR BIN_OP VAR VAR NUMBER ASSIGN VAR VAR STRING IF BIN_OP VAR VAR NUMBER VAR BIN_OP VAR VAR NUMBER ASSIGN VAR VAR STRING ASSIGN VAR VAR STRING IF FUNC_CALL STRING VAR VAR EXPR FUNC_CALL VAR FUNC_CALL STRING FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR NUMBER WHILE VAR EXPR FUNC_CALL VAR VAR NUMBER |
Consider the following process. You have a binary string (a string where each character is either 0 or 1) $w$ of length $n$ and an integer $x$. You build a new binary string $s$ consisting of $n$ characters. The $i$-th character of $s$ is chosen as follows:
if the character $w_{i-x}$ exists and is equal to 1, then $s_i$ is 1 (formally, if $i > x$ and $w_{i-x} = $ 1, then $s_i = $ 1); if the character $w_{i+x}$ exists and is equal to 1, then $s_i$ is 1 (formally, if $i + x \le n$ and $w_{i+x} = $ 1, then $s_i = $ 1); if both of the aforementioned conditions are false, then $s_i$ is 0.
You are given the integer $x$ and the resulting string $s$. Reconstruct the original string $w$.
-----Input-----
The first line contains one integer $t$ ($1 \le t \le 1000$) β the number of test cases.
Each test case consists of two lines. The first line contains the resulting string $s$ ($2 \le |s| \le 10^5$, each character of $s$ is either 0 or 1). The second line contains one integer $x$ ($1 \le x \le |s| - 1$).
The total length of all strings $s$ in the input does not exceed $10^5$.
-----Output-----
For each test case, print the answer on a separate line as follows:
if no string $w$ can produce the string $s$ at the end of the process, print $-1$; otherwise, print the binary string $w$ consisting of $|s|$ characters. If there are multiple answers, print any of them.
-----Example-----
Input
3
101110
2
01
1
110
1
Output
111011
10
-1 | try:
for i in range(int(input())):
s = str(input())
x = int(input())
n = len(s)
z = x
st = ""
string = ["1"] * n
for i in range(len(s)):
if s[i] == "0":
if i >= z:
string[i - z] = "0"
if i + z < len(s):
string[i + z] = "0"
for i in range(len(s)):
if s[i] == "1":
count1 = 0
count2 = 0
if i >= z and string[i - z] == "1":
count1 += 1
else:
count2 += 1
if i + z < len(s) and string[i + z] == "1":
count1 += 1
else:
count2 += 1
if count1 == 0:
string = ["-1"]
break
for i in string:
st += i
print(st)
except Exception as e:
pass | FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR VAR ASSIGN VAR STRING ASSIGN VAR BIN_OP LIST STRING VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR STRING IF VAR VAR ASSIGN VAR BIN_OP VAR VAR STRING IF BIN_OP VAR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR VAR STRING FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR STRING ASSIGN VAR NUMBER ASSIGN VAR NUMBER IF VAR VAR VAR BIN_OP VAR VAR STRING VAR NUMBER VAR NUMBER IF BIN_OP VAR VAR FUNC_CALL VAR VAR VAR BIN_OP VAR VAR STRING VAR NUMBER VAR NUMBER IF VAR NUMBER ASSIGN VAR LIST STRING FOR VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR |
Consider the following process. You have a binary string (a string where each character is either 0 or 1) $w$ of length $n$ and an integer $x$. You build a new binary string $s$ consisting of $n$ characters. The $i$-th character of $s$ is chosen as follows:
if the character $w_{i-x}$ exists and is equal to 1, then $s_i$ is 1 (formally, if $i > x$ and $w_{i-x} = $ 1, then $s_i = $ 1); if the character $w_{i+x}$ exists and is equal to 1, then $s_i$ is 1 (formally, if $i + x \le n$ and $w_{i+x} = $ 1, then $s_i = $ 1); if both of the aforementioned conditions are false, then $s_i$ is 0.
You are given the integer $x$ and the resulting string $s$. Reconstruct the original string $w$.
-----Input-----
The first line contains one integer $t$ ($1 \le t \le 1000$) β the number of test cases.
Each test case consists of two lines. The first line contains the resulting string $s$ ($2 \le |s| \le 10^5$, each character of $s$ is either 0 or 1). The second line contains one integer $x$ ($1 \le x \le |s| - 1$).
The total length of all strings $s$ in the input does not exceed $10^5$.
-----Output-----
For each test case, print the answer on a separate line as follows:
if no string $w$ can produce the string $s$ at the end of the process, print $-1$; otherwise, print the binary string $w$ consisting of $|s|$ characters. If there are multiple answers, print any of them.
-----Example-----
Input
3
101110
2
01
1
110
1
Output
111011
10
-1 | import sys
input = sys.stdin.readline
for kek in range(int(input())):
s = input()
x = int(input())
flg = True
a = ["1" for j in range(len(s) - 1)]
for i in range(len(s) - 1):
if s[i] == "0":
if i + x < len(s) - 1:
a[i + x] = "0"
if i - x >= 0:
a[i - x] = "0"
for i in range(len(a)):
if i - x >= 0 and a[i - x] == "1":
if s[i] != "1":
flg = False
elif i + x < len(a) and a[i + x] == "1":
if s[i] != "1":
flg = False
elif s[i] != "0":
flg = False
if flg:
print("".join(a))
else:
print(-1) | IMPORT ASSIGN VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR STRING VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER IF VAR VAR STRING IF BIN_OP VAR VAR BIN_OP FUNC_CALL VAR VAR NUMBER ASSIGN VAR BIN_OP VAR VAR STRING IF BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP VAR VAR STRING FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF BIN_OP VAR VAR NUMBER VAR BIN_OP VAR VAR STRING IF VAR VAR STRING ASSIGN VAR NUMBER IF BIN_OP VAR VAR FUNC_CALL VAR VAR VAR BIN_OP VAR VAR STRING IF VAR VAR STRING ASSIGN VAR NUMBER IF VAR VAR STRING ASSIGN VAR NUMBER IF VAR EXPR FUNC_CALL VAR FUNC_CALL STRING VAR EXPR FUNC_CALL VAR NUMBER |
Consider the following process. You have a binary string (a string where each character is either 0 or 1) $w$ of length $n$ and an integer $x$. You build a new binary string $s$ consisting of $n$ characters. The $i$-th character of $s$ is chosen as follows:
if the character $w_{i-x}$ exists and is equal to 1, then $s_i$ is 1 (formally, if $i > x$ and $w_{i-x} = $ 1, then $s_i = $ 1); if the character $w_{i+x}$ exists and is equal to 1, then $s_i$ is 1 (formally, if $i + x \le n$ and $w_{i+x} = $ 1, then $s_i = $ 1); if both of the aforementioned conditions are false, then $s_i$ is 0.
You are given the integer $x$ and the resulting string $s$. Reconstruct the original string $w$.
-----Input-----
The first line contains one integer $t$ ($1 \le t \le 1000$) β the number of test cases.
Each test case consists of two lines. The first line contains the resulting string $s$ ($2 \le |s| \le 10^5$, each character of $s$ is either 0 or 1). The second line contains one integer $x$ ($1 \le x \le |s| - 1$).
The total length of all strings $s$ in the input does not exceed $10^5$.
-----Output-----
For each test case, print the answer on a separate line as follows:
if no string $w$ can produce the string $s$ at the end of the process, print $-1$; otherwise, print the binary string $w$ consisting of $|s|$ characters. If there are multiple answers, print any of them.
-----Example-----
Input
3
101110
2
01
1
110
1
Output
111011
10
-1 | import sys
input = sys.stdin.readline
for _ in range(int(input())):
s = input().rstrip()
x = int(input())
n = len(s)
ans = ["1" for i in range(n)]
for i in range(n):
if s[i] == "0":
if i - x >= 0:
ans[i - x] = "0"
if i + x < n:
ans[i + x] = "0"
for i in range(n):
if s[i] == "1":
check = False
if i - x >= 0:
check |= ans[i - x] == "1"
if i + x < n:
check |= ans[i + x] == "1"
if not check:
print(-1)
break
else:
print("".join(ans)) | IMPORT ASSIGN VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR STRING VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR IF VAR VAR STRING IF BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP VAR VAR STRING IF BIN_OP VAR VAR VAR ASSIGN VAR BIN_OP VAR VAR STRING FOR VAR FUNC_CALL VAR VAR IF VAR VAR STRING ASSIGN VAR NUMBER IF BIN_OP VAR VAR NUMBER VAR VAR BIN_OP VAR VAR STRING IF BIN_OP VAR VAR VAR VAR VAR BIN_OP VAR VAR STRING IF VAR EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL STRING VAR |
Consider the following process. You have a binary string (a string where each character is either 0 or 1) $w$ of length $n$ and an integer $x$. You build a new binary string $s$ consisting of $n$ characters. The $i$-th character of $s$ is chosen as follows:
if the character $w_{i-x}$ exists and is equal to 1, then $s_i$ is 1 (formally, if $i > x$ and $w_{i-x} = $ 1, then $s_i = $ 1); if the character $w_{i+x}$ exists and is equal to 1, then $s_i$ is 1 (formally, if $i + x \le n$ and $w_{i+x} = $ 1, then $s_i = $ 1); if both of the aforementioned conditions are false, then $s_i$ is 0.
You are given the integer $x$ and the resulting string $s$. Reconstruct the original string $w$.
-----Input-----
The first line contains one integer $t$ ($1 \le t \le 1000$) β the number of test cases.
Each test case consists of two lines. The first line contains the resulting string $s$ ($2 \le |s| \le 10^5$, each character of $s$ is either 0 or 1). The second line contains one integer $x$ ($1 \le x \le |s| - 1$).
The total length of all strings $s$ in the input does not exceed $10^5$.
-----Output-----
For each test case, print the answer on a separate line as follows:
if no string $w$ can produce the string $s$ at the end of the process, print $-1$; otherwise, print the binary string $w$ consisting of $|s|$ characters. If there are multiple answers, print any of them.
-----Example-----
Input
3
101110
2
01
1
110
1
Output
111011
10
-1 | for t in range(int(input())):
s = [int(c == "1") for c in input()]
x = int(input())
n = len(s)
sat = lambda i: s[i] if i in range(n) else 1
w = [(sat(i - x) & sat(i + x)) for i in range(n)]
wat = lambda i: w[i] if i in range(n) else 0
s_ref = [(wat(i - x) | wat(i + x)) for i in range(n)]
if s != s_ref:
print(-1)
else:
print("".join(map(str, w))) | FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR STRING VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR VAR NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR BIN_OP VAR VAR FUNC_CALL VAR BIN_OP VAR VAR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR VAR NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR BIN_OP VAR VAR FUNC_CALL VAR BIN_OP VAR VAR VAR FUNC_CALL VAR VAR IF VAR VAR EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL STRING FUNC_CALL VAR VAR VAR |
Consider the following process. You have a binary string (a string where each character is either 0 or 1) $w$ of length $n$ and an integer $x$. You build a new binary string $s$ consisting of $n$ characters. The $i$-th character of $s$ is chosen as follows:
if the character $w_{i-x}$ exists and is equal to 1, then $s_i$ is 1 (formally, if $i > x$ and $w_{i-x} = $ 1, then $s_i = $ 1); if the character $w_{i+x}$ exists and is equal to 1, then $s_i$ is 1 (formally, if $i + x \le n$ and $w_{i+x} = $ 1, then $s_i = $ 1); if both of the aforementioned conditions are false, then $s_i$ is 0.
You are given the integer $x$ and the resulting string $s$. Reconstruct the original string $w$.
-----Input-----
The first line contains one integer $t$ ($1 \le t \le 1000$) β the number of test cases.
Each test case consists of two lines. The first line contains the resulting string $s$ ($2 \le |s| \le 10^5$, each character of $s$ is either 0 or 1). The second line contains one integer $x$ ($1 \le x \le |s| - 1$).
The total length of all strings $s$ in the input does not exceed $10^5$.
-----Output-----
For each test case, print the answer on a separate line as follows:
if no string $w$ can produce the string $s$ at the end of the process, print $-1$; otherwise, print the binary string $w$ consisting of $|s|$ characters. If there are multiple answers, print any of them.
-----Example-----
Input
3
101110
2
01
1
110
1
Output
111011
10
-1 | for q in range(int(input())):
s = input()
s = "2" + s
x = int(input())
n = len(s) - 1
w = [2] * (n + 1)
res = 1
for i in range(1, n + 1):
if s[i] == "1":
if i > x:
if i + x > n:
if w[i - x] == 2:
w[i - x] = 1
elif w[i - x] == 0:
res = 0
break
else:
if w[i - x] == 0:
if w[i + x] == 2:
w[i + x] = 1
elif w[i + x] == 0:
res = 0
break
if w[i + x] == 0:
if w[i - x] == 2:
w[i - x] = 1
elif w[i - x] == 0:
res = 0
break
elif i + x > n:
res = 0
break
elif w[i + x] == 2:
w[i + x] = 1
elif w[i + x] == 0:
res = 0
break
else:
if i > x:
if w[i - x] == 2:
w[i - x] = 0
elif w[i - x] == 1:
res = 0
break
if i + x <= n:
if w[i + x] == 2:
w[i + x] = 0
elif w[i + x] == 1:
res = 0
break
if res == 0:
print(-1)
else:
for o in range(1, n + 1):
if w[o] == 2:
w[o] = 1
print(*w[1:], sep="") | FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR BIN_OP STRING VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER IF VAR VAR STRING IF VAR VAR IF BIN_OP VAR VAR VAR IF VAR BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP VAR VAR NUMBER IF VAR BIN_OP VAR VAR NUMBER ASSIGN VAR NUMBER IF VAR BIN_OP VAR VAR NUMBER IF VAR BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP VAR VAR NUMBER IF VAR BIN_OP VAR VAR NUMBER ASSIGN VAR NUMBER IF VAR BIN_OP VAR VAR NUMBER IF VAR BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP VAR VAR NUMBER IF VAR BIN_OP VAR VAR NUMBER ASSIGN VAR NUMBER IF BIN_OP VAR VAR VAR ASSIGN VAR NUMBER IF VAR BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP VAR VAR NUMBER IF VAR BIN_OP VAR VAR NUMBER ASSIGN VAR NUMBER IF VAR VAR IF VAR BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP VAR VAR NUMBER IF VAR BIN_OP VAR VAR NUMBER ASSIGN VAR NUMBER IF BIN_OP VAR VAR VAR IF VAR BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP VAR VAR NUMBER IF VAR BIN_OP VAR VAR NUMBER ASSIGN VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER IF VAR VAR NUMBER ASSIGN VAR VAR NUMBER EXPR FUNC_CALL VAR VAR NUMBER STRING |
Consider the following process. You have a binary string (a string where each character is either 0 or 1) $w$ of length $n$ and an integer $x$. You build a new binary string $s$ consisting of $n$ characters. The $i$-th character of $s$ is chosen as follows:
if the character $w_{i-x}$ exists and is equal to 1, then $s_i$ is 1 (formally, if $i > x$ and $w_{i-x} = $ 1, then $s_i = $ 1); if the character $w_{i+x}$ exists and is equal to 1, then $s_i$ is 1 (formally, if $i + x \le n$ and $w_{i+x} = $ 1, then $s_i = $ 1); if both of the aforementioned conditions are false, then $s_i$ is 0.
You are given the integer $x$ and the resulting string $s$. Reconstruct the original string $w$.
-----Input-----
The first line contains one integer $t$ ($1 \le t \le 1000$) β the number of test cases.
Each test case consists of two lines. The first line contains the resulting string $s$ ($2 \le |s| \le 10^5$, each character of $s$ is either 0 or 1). The second line contains one integer $x$ ($1 \le x \le |s| - 1$).
The total length of all strings $s$ in the input does not exceed $10^5$.
-----Output-----
For each test case, print the answer on a separate line as follows:
if no string $w$ can produce the string $s$ at the end of the process, print $-1$; otherwise, print the binary string $w$ consisting of $|s|$ characters. If there are multiple answers, print any of them.
-----Example-----
Input
3
101110
2
01
1
110
1
Output
111011
10
-1 | for _ in range(int(input())):
s = input()
x = int(input())
result = ["1" for _ in range(len(s))]
for i, c in enumerate(s):
if c == "0":
if i + x < len(s):
result[i + x] = "0"
if i - x >= 0:
result[i - x] = "0"
possible = True
for i, c in enumerate(s):
if c == "1":
bit1, bit2 = "0", "0"
if i + x < len(s):
bit1 = result[i + x]
if i - x >= 0:
bit2 = result[i - x]
if bit1 == "0" and bit2 == "0":
possible = False
break
print("".join(result) if possible else "-1") | FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR STRING VAR FUNC_CALL VAR FUNC_CALL VAR VAR FOR VAR VAR FUNC_CALL VAR VAR IF VAR STRING IF BIN_OP VAR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR VAR STRING IF BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP VAR VAR STRING ASSIGN VAR NUMBER FOR VAR VAR FUNC_CALL VAR VAR IF VAR STRING ASSIGN VAR VAR STRING STRING IF BIN_OP VAR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR BIN_OP VAR VAR IF BIN_OP VAR VAR NUMBER ASSIGN VAR VAR BIN_OP VAR VAR IF VAR STRING VAR STRING ASSIGN VAR NUMBER EXPR FUNC_CALL VAR VAR FUNC_CALL STRING VAR STRING |
Consider the following process. You have a binary string (a string where each character is either 0 or 1) $w$ of length $n$ and an integer $x$. You build a new binary string $s$ consisting of $n$ characters. The $i$-th character of $s$ is chosen as follows:
if the character $w_{i-x}$ exists and is equal to 1, then $s_i$ is 1 (formally, if $i > x$ and $w_{i-x} = $ 1, then $s_i = $ 1); if the character $w_{i+x}$ exists and is equal to 1, then $s_i$ is 1 (formally, if $i + x \le n$ and $w_{i+x} = $ 1, then $s_i = $ 1); if both of the aforementioned conditions are false, then $s_i$ is 0.
You are given the integer $x$ and the resulting string $s$. Reconstruct the original string $w$.
-----Input-----
The first line contains one integer $t$ ($1 \le t \le 1000$) β the number of test cases.
Each test case consists of two lines. The first line contains the resulting string $s$ ($2 \le |s| \le 10^5$, each character of $s$ is either 0 or 1). The second line contains one integer $x$ ($1 \le x \le |s| - 1$).
The total length of all strings $s$ in the input does not exceed $10^5$.
-----Output-----
For each test case, print the answer on a separate line as follows:
if no string $w$ can produce the string $s$ at the end of the process, print $-1$; otherwise, print the binary string $w$ consisting of $|s|$ characters. If there are multiple answers, print any of them.
-----Example-----
Input
3
101110
2
01
1
110
1
Output
111011
10
-1 | t = int(input())
for _ in range(t):
s = input()
x = int(input())
w = [1] * len(s)
for i in range(len(s)):
if s[i] == "0":
if i + x < len(s):
w[i + x] = 0
if i - x >= 0:
w[i - x] = 0
temp = [0] * len(s)
for i in range(len(w)):
f1 = 0
f2 = 0
if i + x < len(s):
if w[i + x] == 1:
f1 = 1
if i - x >= 0:
if w[i - x] == 1:
f2 = 1
if f1 or f2:
temp[i] = 1
ans = ""
for i in range(len(temp)):
ans += str(temp[i])
if ans == s:
e = ""
for i in range(len(w)):
e += str(w[i])
print(e)
else:
print(-1) | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR STRING IF BIN_OP VAR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR VAR NUMBER IF BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER IF BIN_OP VAR VAR FUNC_CALL VAR VAR IF VAR BIN_OP VAR VAR NUMBER ASSIGN VAR NUMBER IF BIN_OP VAR VAR NUMBER IF VAR BIN_OP VAR VAR NUMBER ASSIGN VAR NUMBER IF VAR VAR ASSIGN VAR VAR NUMBER ASSIGN VAR STRING FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR VAR IF VAR VAR ASSIGN VAR STRING FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR NUMBER |
Consider the following process. You have a binary string (a string where each character is either 0 or 1) $w$ of length $n$ and an integer $x$. You build a new binary string $s$ consisting of $n$ characters. The $i$-th character of $s$ is chosen as follows:
if the character $w_{i-x}$ exists and is equal to 1, then $s_i$ is 1 (formally, if $i > x$ and $w_{i-x} = $ 1, then $s_i = $ 1); if the character $w_{i+x}$ exists and is equal to 1, then $s_i$ is 1 (formally, if $i + x \le n$ and $w_{i+x} = $ 1, then $s_i = $ 1); if both of the aforementioned conditions are false, then $s_i$ is 0.
You are given the integer $x$ and the resulting string $s$. Reconstruct the original string $w$.
-----Input-----
The first line contains one integer $t$ ($1 \le t \le 1000$) β the number of test cases.
Each test case consists of two lines. The first line contains the resulting string $s$ ($2 \le |s| \le 10^5$, each character of $s$ is either 0 or 1). The second line contains one integer $x$ ($1 \le x \le |s| - 1$).
The total length of all strings $s$ in the input does not exceed $10^5$.
-----Output-----
For each test case, print the answer on a separate line as follows:
if no string $w$ can produce the string $s$ at the end of the process, print $-1$; otherwise, print the binary string $w$ consisting of $|s|$ characters. If there are multiple answers, print any of them.
-----Example-----
Input
3
101110
2
01
1
110
1
Output
111011
10
-1 | t = int(input())
for i in range(t):
s = input()
n = len(s)
x = int(input())
ans = [""] * n
flag = 0
for j in range(n):
if s[j] == "0":
if j - x >= 0:
ans[j - x] = 0
if j + x <= n - 1:
ans[j + x] = 0
for j in range(n):
if s[j] == "1":
if j - x < 0 and j + x > n - 1:
flag = 1
break
elif j - x >= 0 and j + x <= n - 1:
if ans[j - x] == 0 and ans[j + x] == 0:
flag = 1
break
else:
if ans[j - x] != 0:
ans[j - x] = 1
if ans[j + x] != 0:
ans[j + x] = 1
elif j - x >= 0:
if ans[j - x] == 0:
flag = 1
break
else:
ans[j - x] = 1
elif j + x <= n - 1:
if ans[j + x] == 0:
flag = 1
break
else:
ans[j + x] = 1
if flag == 0:
for j in range(n):
if ans[j] == "":
ans[j] = 1
ans = [str(cv) for cv in ans]
print("".join(ans))
else:
print(-1) | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR BIN_OP LIST STRING VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR STRING IF BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP VAR VAR NUMBER IF BIN_OP VAR VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR STRING IF BIN_OP VAR VAR NUMBER BIN_OP VAR VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER IF BIN_OP VAR VAR NUMBER BIN_OP VAR VAR BIN_OP VAR NUMBER IF VAR BIN_OP VAR VAR NUMBER VAR BIN_OP VAR VAR NUMBER ASSIGN VAR NUMBER IF VAR BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP VAR VAR NUMBER IF VAR BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP VAR VAR NUMBER IF BIN_OP VAR VAR NUMBER IF VAR BIN_OP VAR VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR BIN_OP VAR VAR NUMBER IF BIN_OP VAR VAR BIN_OP VAR NUMBER IF VAR BIN_OP VAR VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR BIN_OP VAR VAR NUMBER IF VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR STRING ASSIGN VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR VAR EXPR FUNC_CALL VAR FUNC_CALL STRING VAR EXPR FUNC_CALL VAR NUMBER |
Consider the following process. You have a binary string (a string where each character is either 0 or 1) $w$ of length $n$ and an integer $x$. You build a new binary string $s$ consisting of $n$ characters. The $i$-th character of $s$ is chosen as follows:
if the character $w_{i-x}$ exists and is equal to 1, then $s_i$ is 1 (formally, if $i > x$ and $w_{i-x} = $ 1, then $s_i = $ 1); if the character $w_{i+x}$ exists and is equal to 1, then $s_i$ is 1 (formally, if $i + x \le n$ and $w_{i+x} = $ 1, then $s_i = $ 1); if both of the aforementioned conditions are false, then $s_i$ is 0.
You are given the integer $x$ and the resulting string $s$. Reconstruct the original string $w$.
-----Input-----
The first line contains one integer $t$ ($1 \le t \le 1000$) β the number of test cases.
Each test case consists of two lines. The first line contains the resulting string $s$ ($2 \le |s| \le 10^5$, each character of $s$ is either 0 or 1). The second line contains one integer $x$ ($1 \le x \le |s| - 1$).
The total length of all strings $s$ in the input does not exceed $10^5$.
-----Output-----
For each test case, print the answer on a separate line as follows:
if no string $w$ can produce the string $s$ at the end of the process, print $-1$; otherwise, print the binary string $w$ consisting of $|s|$ characters. If there are multiple answers, print any of them.
-----Example-----
Input
3
101110
2
01
1
110
1
Output
111011
10
-1 | def solveCase():
res = input()
n = len(res)
prev = ["0" for i in range(n)]
x = int(input())
for i in range(n):
if res[i] == "0":
continue
ok = False
if i >= 2 * x and res[i - 2 * x] == "1" or i >= x and i < 2 * x:
prev[i - x] = "1"
ok = True
if i + 2 * x < n and res[i + 2 * x] == "1" or i + x < n and i + 2 * x >= n:
prev[i + x] = "1"
ok = True
if not ok:
print(-1)
return
astr = ""
print(astr.join(prev))
t = int(input())
for i in range(t):
solveCase() | FUNC_DEF ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR STRING VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR IF VAR VAR STRING ASSIGN VAR NUMBER IF VAR BIN_OP NUMBER VAR VAR BIN_OP VAR BIN_OP NUMBER VAR STRING VAR VAR VAR BIN_OP NUMBER VAR ASSIGN VAR BIN_OP VAR VAR STRING ASSIGN VAR NUMBER IF BIN_OP VAR BIN_OP NUMBER VAR VAR VAR BIN_OP VAR BIN_OP NUMBER VAR STRING BIN_OP VAR VAR VAR BIN_OP VAR BIN_OP NUMBER VAR VAR ASSIGN VAR BIN_OP VAR VAR STRING ASSIGN VAR NUMBER IF VAR EXPR FUNC_CALL VAR NUMBER RETURN ASSIGN VAR STRING EXPR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR |
Consider the following process. You have a binary string (a string where each character is either 0 or 1) $w$ of length $n$ and an integer $x$. You build a new binary string $s$ consisting of $n$ characters. The $i$-th character of $s$ is chosen as follows:
if the character $w_{i-x}$ exists and is equal to 1, then $s_i$ is 1 (formally, if $i > x$ and $w_{i-x} = $ 1, then $s_i = $ 1); if the character $w_{i+x}$ exists and is equal to 1, then $s_i$ is 1 (formally, if $i + x \le n$ and $w_{i+x} = $ 1, then $s_i = $ 1); if both of the aforementioned conditions are false, then $s_i$ is 0.
You are given the integer $x$ and the resulting string $s$. Reconstruct the original string $w$.
-----Input-----
The first line contains one integer $t$ ($1 \le t \le 1000$) β the number of test cases.
Each test case consists of two lines. The first line contains the resulting string $s$ ($2 \le |s| \le 10^5$, each character of $s$ is either 0 or 1). The second line contains one integer $x$ ($1 \le x \le |s| - 1$).
The total length of all strings $s$ in the input does not exceed $10^5$.
-----Output-----
For each test case, print the answer on a separate line as follows:
if no string $w$ can produce the string $s$ at the end of the process, print $-1$; otherwise, print the binary string $w$ consisting of $|s|$ characters. If there are multiple answers, print any of them.
-----Example-----
Input
3
101110
2
01
1
110
1
Output
111011
10
-1 | mod = 10**9 + 7
def solve():
s = input()
n = len(s)
x = int(input())
w = ["?"] * n
ok = True
for i in range(n):
if i + x < n and s[i] == "0":
w[i + x] = s[i]
if i - x >= 0 and s[i] == "0":
w[i - x] = "0"
for i in range(n):
if s[i] == "1":
ok1 = False
if i + x < n and w[i + x] == "?":
w[i + x] = "1"
if i - x >= 0 and w[i - x] == "?":
w[i - x] = "1"
for i in range(n):
if w[i] == "?":
w[i] = "0"
for i in range(n):
c = "0"
if i + x < n and w[i + x] == "1":
c = "1"
if i - x >= 0 and w[i - x] == "1":
c = "1"
if c != s[i]:
ok = False
break
print("".join(w) if ok else -1)
t = int(input())
while t > 0:
solve()
t -= 1 | ASSIGN VAR BIN_OP BIN_OP NUMBER NUMBER NUMBER FUNC_DEF ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR BIN_OP LIST STRING VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF BIN_OP VAR VAR VAR VAR VAR STRING ASSIGN VAR BIN_OP VAR VAR VAR VAR IF BIN_OP VAR VAR NUMBER VAR VAR STRING ASSIGN VAR BIN_OP VAR VAR STRING FOR VAR FUNC_CALL VAR VAR IF VAR VAR STRING ASSIGN VAR NUMBER IF BIN_OP VAR VAR VAR VAR BIN_OP VAR VAR STRING ASSIGN VAR BIN_OP VAR VAR STRING IF BIN_OP VAR VAR NUMBER VAR BIN_OP VAR VAR STRING ASSIGN VAR BIN_OP VAR VAR STRING FOR VAR FUNC_CALL VAR VAR IF VAR VAR STRING ASSIGN VAR VAR STRING FOR VAR FUNC_CALL VAR VAR ASSIGN VAR STRING IF BIN_OP VAR VAR VAR VAR BIN_OP VAR VAR STRING ASSIGN VAR STRING IF BIN_OP VAR VAR NUMBER VAR BIN_OP VAR VAR STRING ASSIGN VAR STRING IF VAR VAR VAR ASSIGN VAR NUMBER EXPR FUNC_CALL VAR VAR FUNC_CALL STRING VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR WHILE VAR NUMBER EXPR FUNC_CALL VAR VAR NUMBER |
Consider the following process. You have a binary string (a string where each character is either 0 or 1) $w$ of length $n$ and an integer $x$. You build a new binary string $s$ consisting of $n$ characters. The $i$-th character of $s$ is chosen as follows:
if the character $w_{i-x}$ exists and is equal to 1, then $s_i$ is 1 (formally, if $i > x$ and $w_{i-x} = $ 1, then $s_i = $ 1); if the character $w_{i+x}$ exists and is equal to 1, then $s_i$ is 1 (formally, if $i + x \le n$ and $w_{i+x} = $ 1, then $s_i = $ 1); if both of the aforementioned conditions are false, then $s_i$ is 0.
You are given the integer $x$ and the resulting string $s$. Reconstruct the original string $w$.
-----Input-----
The first line contains one integer $t$ ($1 \le t \le 1000$) β the number of test cases.
Each test case consists of two lines. The first line contains the resulting string $s$ ($2 \le |s| \le 10^5$, each character of $s$ is either 0 or 1). The second line contains one integer $x$ ($1 \le x \le |s| - 1$).
The total length of all strings $s$ in the input does not exceed $10^5$.
-----Output-----
For each test case, print the answer on a separate line as follows:
if no string $w$ can produce the string $s$ at the end of the process, print $-1$; otherwise, print the binary string $w$ consisting of $|s|$ characters. If there are multiple answers, print any of them.
-----Example-----
Input
3
101110
2
01
1
110
1
Output
111011
10
-1 | import sys
input = sys.stdin.readline
for _ in range(int(input())):
s = input()
x = int(input())
n = len(s) - 1
ans = ["1"] * n
for i in range(n):
if s[i] == "0":
if i - x > -1:
ans[i - x] = "0"
if i + x < n:
ans[i + x] = "0"
check = ["0"] * n
for i in range(n):
if i - x > -1 and ans[i - x] == "1" or i + x < n and ans[i + x] == "1":
check[i] = "1"
ans = "".join(ans)
print(ans if s[:n] == "".join(check) else -1) | IMPORT ASSIGN VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER ASSIGN VAR BIN_OP LIST STRING VAR FOR VAR FUNC_CALL VAR VAR IF VAR VAR STRING IF BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP VAR VAR STRING IF BIN_OP VAR VAR VAR ASSIGN VAR BIN_OP VAR VAR STRING ASSIGN VAR BIN_OP LIST STRING VAR FOR VAR FUNC_CALL VAR VAR IF BIN_OP VAR VAR NUMBER VAR BIN_OP VAR VAR STRING BIN_OP VAR VAR VAR VAR BIN_OP VAR VAR STRING ASSIGN VAR VAR STRING ASSIGN VAR FUNC_CALL STRING VAR EXPR FUNC_CALL VAR VAR VAR FUNC_CALL STRING VAR VAR NUMBER |
Consider the following process. You have a binary string (a string where each character is either 0 or 1) $w$ of length $n$ and an integer $x$. You build a new binary string $s$ consisting of $n$ characters. The $i$-th character of $s$ is chosen as follows:
if the character $w_{i-x}$ exists and is equal to 1, then $s_i$ is 1 (formally, if $i > x$ and $w_{i-x} = $ 1, then $s_i = $ 1); if the character $w_{i+x}$ exists and is equal to 1, then $s_i$ is 1 (formally, if $i + x \le n$ and $w_{i+x} = $ 1, then $s_i = $ 1); if both of the aforementioned conditions are false, then $s_i$ is 0.
You are given the integer $x$ and the resulting string $s$. Reconstruct the original string $w$.
-----Input-----
The first line contains one integer $t$ ($1 \le t \le 1000$) β the number of test cases.
Each test case consists of two lines. The first line contains the resulting string $s$ ($2 \le |s| \le 10^5$, each character of $s$ is either 0 or 1). The second line contains one integer $x$ ($1 \le x \le |s| - 1$).
The total length of all strings $s$ in the input does not exceed $10^5$.
-----Output-----
For each test case, print the answer on a separate line as follows:
if no string $w$ can produce the string $s$ at the end of the process, print $-1$; otherwise, print the binary string $w$ consisting of $|s|$ characters. If there are multiple answers, print any of them.
-----Example-----
Input
3
101110
2
01
1
110
1
Output
111011
10
-1 | def check(ans, s, x, n):
temp = ["0" for i in range(n)]
for i in range(1, n + 1):
if i - x > 0 and ans[i - x] == "1":
temp[i - 1] = "1"
if i + x <= n and ans[i + x] == "1":
temp[i - 1] = "1"
return temp == s
for _ in range(int(input())):
s = list(input())
x = int(input())
n = len(s)
ans = ["1" for i in range(n + 1)]
for i in range(1, n + 1):
if s[i - 1] == "0":
if i - x > 0:
ans[i - x] = "0"
if i + x <= n:
ans[i + x] = "0"
if check(ans, s, x, n):
print("".join(ans[1:]))
else:
print(-1) | FUNC_DEF ASSIGN VAR STRING VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER IF BIN_OP VAR VAR NUMBER VAR BIN_OP VAR VAR STRING ASSIGN VAR BIN_OP VAR NUMBER STRING IF BIN_OP VAR VAR VAR VAR BIN_OP VAR VAR STRING ASSIGN VAR BIN_OP VAR NUMBER STRING RETURN VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR STRING VAR FUNC_CALL VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER IF VAR BIN_OP VAR NUMBER STRING IF BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP VAR VAR STRING IF BIN_OP VAR VAR VAR ASSIGN VAR BIN_OP VAR VAR STRING IF FUNC_CALL VAR VAR VAR VAR VAR EXPR FUNC_CALL VAR FUNC_CALL STRING VAR NUMBER EXPR FUNC_CALL VAR NUMBER |
Consider the following process. You have a binary string (a string where each character is either 0 or 1) $w$ of length $n$ and an integer $x$. You build a new binary string $s$ consisting of $n$ characters. The $i$-th character of $s$ is chosen as follows:
if the character $w_{i-x}$ exists and is equal to 1, then $s_i$ is 1 (formally, if $i > x$ and $w_{i-x} = $ 1, then $s_i = $ 1); if the character $w_{i+x}$ exists and is equal to 1, then $s_i$ is 1 (formally, if $i + x \le n$ and $w_{i+x} = $ 1, then $s_i = $ 1); if both of the aforementioned conditions are false, then $s_i$ is 0.
You are given the integer $x$ and the resulting string $s$. Reconstruct the original string $w$.
-----Input-----
The first line contains one integer $t$ ($1 \le t \le 1000$) β the number of test cases.
Each test case consists of two lines. The first line contains the resulting string $s$ ($2 \le |s| \le 10^5$, each character of $s$ is either 0 or 1). The second line contains one integer $x$ ($1 \le x \le |s| - 1$).
The total length of all strings $s$ in the input does not exceed $10^5$.
-----Output-----
For each test case, print the answer on a separate line as follows:
if no string $w$ can produce the string $s$ at the end of the process, print $-1$; otherwise, print the binary string $w$ consisting of $|s|$ characters. If there are multiple answers, print any of them.
-----Example-----
Input
3
101110
2
01
1
110
1
Output
111011
10
-1 | def get():
n = len(s)
w = [1] * n
for i in range(n):
if s[i] == 0:
if i - x >= 0:
w[i - x] = 0
if i + x < n:
w[i + x] = 0
for i in range(n):
if s[i]:
if i - x >= 0 and w[i - x] == 1:
continue
elif i + x < n and w[i + x] == 1:
continue
else:
return [-1]
return w
for _ in range(int(input())):
s = list(map(int, input()))
x = int(input())
for i in get():
print(i, end="")
print() | FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP LIST NUMBER VAR FOR VAR FUNC_CALL VAR VAR IF VAR VAR NUMBER IF BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP VAR VAR NUMBER IF BIN_OP VAR VAR VAR ASSIGN VAR BIN_OP VAR VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR IF BIN_OP VAR VAR NUMBER VAR BIN_OP VAR VAR NUMBER IF BIN_OP VAR VAR VAR VAR BIN_OP VAR VAR NUMBER RETURN LIST NUMBER RETURN VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR EXPR FUNC_CALL VAR VAR STRING EXPR FUNC_CALL VAR |
Consider the following process. You have a binary string (a string where each character is either 0 or 1) $w$ of length $n$ and an integer $x$. You build a new binary string $s$ consisting of $n$ characters. The $i$-th character of $s$ is chosen as follows:
if the character $w_{i-x}$ exists and is equal to 1, then $s_i$ is 1 (formally, if $i > x$ and $w_{i-x} = $ 1, then $s_i = $ 1); if the character $w_{i+x}$ exists and is equal to 1, then $s_i$ is 1 (formally, if $i + x \le n$ and $w_{i+x} = $ 1, then $s_i = $ 1); if both of the aforementioned conditions are false, then $s_i$ is 0.
You are given the integer $x$ and the resulting string $s$. Reconstruct the original string $w$.
-----Input-----
The first line contains one integer $t$ ($1 \le t \le 1000$) β the number of test cases.
Each test case consists of two lines. The first line contains the resulting string $s$ ($2 \le |s| \le 10^5$, each character of $s$ is either 0 or 1). The second line contains one integer $x$ ($1 \le x \le |s| - 1$).
The total length of all strings $s$ in the input does not exceed $10^5$.
-----Output-----
For each test case, print the answer on a separate line as follows:
if no string $w$ can produce the string $s$ at the end of the process, print $-1$; otherwise, print the binary string $w$ consisting of $|s|$ characters. If there are multiple answers, print any of them.
-----Example-----
Input
3
101110
2
01
1
110
1
Output
111011
10
-1 | t = int(input())
for i in range(t):
s = input()
x = int(input())
n = len(s)
b = True
l = ["1" for i in range(n)]
for i in range(n):
if s[i] == "0":
if i + x < n:
l[i + x] = "0"
if i - x >= 0:
l[i - x] = "0"
w = "".join(l)
l = ["0" for i in range(n)]
for i in range(n):
if i + x < n:
if w[i + x] == "1":
l[i] = "1"
if i - x >= 0:
if w[i - x] == "1":
l[i] = "1"
r = "".join(l)
if r == s:
print(w)
else:
print(-1) | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR STRING VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR IF VAR VAR STRING IF BIN_OP VAR VAR VAR ASSIGN VAR BIN_OP VAR VAR STRING IF BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP VAR VAR STRING ASSIGN VAR FUNC_CALL STRING VAR ASSIGN VAR STRING VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR IF BIN_OP VAR VAR VAR IF VAR BIN_OP VAR VAR STRING ASSIGN VAR VAR STRING IF BIN_OP VAR VAR NUMBER IF VAR BIN_OP VAR VAR STRING ASSIGN VAR VAR STRING ASSIGN VAR FUNC_CALL STRING VAR IF VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR NUMBER |
Consider the following process. You have a binary string (a string where each character is either 0 or 1) $w$ of length $n$ and an integer $x$. You build a new binary string $s$ consisting of $n$ characters. The $i$-th character of $s$ is chosen as follows:
if the character $w_{i-x}$ exists and is equal to 1, then $s_i$ is 1 (formally, if $i > x$ and $w_{i-x} = $ 1, then $s_i = $ 1); if the character $w_{i+x}$ exists and is equal to 1, then $s_i$ is 1 (formally, if $i + x \le n$ and $w_{i+x} = $ 1, then $s_i = $ 1); if both of the aforementioned conditions are false, then $s_i$ is 0.
You are given the integer $x$ and the resulting string $s$. Reconstruct the original string $w$.
-----Input-----
The first line contains one integer $t$ ($1 \le t \le 1000$) β the number of test cases.
Each test case consists of two lines. The first line contains the resulting string $s$ ($2 \le |s| \le 10^5$, each character of $s$ is either 0 or 1). The second line contains one integer $x$ ($1 \le x \le |s| - 1$).
The total length of all strings $s$ in the input does not exceed $10^5$.
-----Output-----
For each test case, print the answer on a separate line as follows:
if no string $w$ can produce the string $s$ at the end of the process, print $-1$; otherwise, print the binary string $w$ consisting of $|s|$ characters. If there are multiple answers, print any of them.
-----Example-----
Input
3
101110
2
01
1
110
1
Output
111011
10
-1 | def process(n, x):
l = [(0) for i in range(len(n))]
for i in range(len(l)):
if i - x >= 0 and n[i - x] == 1:
l[i] = 1
if i + x < len(l) and n[i + x] == 1:
l[i] = 1
return l
for t in range(int(input())):
l = list(map(int, list(input())))
x = int(input())
n = [(1) for i in range(len(l))]
for i in range(len(n)):
if l[i] == 0:
if i + x < len(n):
n[i + x] = 0
if i - x > -1:
n[i - x] = 0
if process(n, x) != l:
print(-1)
else:
print("".join(map(str, n))) | FUNC_DEF ASSIGN VAR NUMBER VAR FUNC_CALL VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF BIN_OP VAR VAR NUMBER VAR BIN_OP VAR VAR NUMBER ASSIGN VAR VAR NUMBER IF BIN_OP VAR VAR FUNC_CALL VAR VAR VAR BIN_OP VAR VAR NUMBER ASSIGN VAR VAR NUMBER RETURN VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR NUMBER IF BIN_OP VAR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR VAR NUMBER IF BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP VAR VAR NUMBER IF FUNC_CALL VAR VAR VAR VAR EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL STRING FUNC_CALL VAR VAR VAR |
Consider the following process. You have a binary string (a string where each character is either 0 or 1) $w$ of length $n$ and an integer $x$. You build a new binary string $s$ consisting of $n$ characters. The $i$-th character of $s$ is chosen as follows:
if the character $w_{i-x}$ exists and is equal to 1, then $s_i$ is 1 (formally, if $i > x$ and $w_{i-x} = $ 1, then $s_i = $ 1); if the character $w_{i+x}$ exists and is equal to 1, then $s_i$ is 1 (formally, if $i + x \le n$ and $w_{i+x} = $ 1, then $s_i = $ 1); if both of the aforementioned conditions are false, then $s_i$ is 0.
You are given the integer $x$ and the resulting string $s$. Reconstruct the original string $w$.
-----Input-----
The first line contains one integer $t$ ($1 \le t \le 1000$) β the number of test cases.
Each test case consists of two lines. The first line contains the resulting string $s$ ($2 \le |s| \le 10^5$, each character of $s$ is either 0 or 1). The second line contains one integer $x$ ($1 \le x \le |s| - 1$).
The total length of all strings $s$ in the input does not exceed $10^5$.
-----Output-----
For each test case, print the answer on a separate line as follows:
if no string $w$ can produce the string $s$ at the end of the process, print $-1$; otherwise, print the binary string $w$ consisting of $|s|$ characters. If there are multiple answers, print any of them.
-----Example-----
Input
3
101110
2
01
1
110
1
Output
111011
10
-1 | for _ in range(int(input())):
s = str(input())
x = int(input())
w = [1] * len(s)
for i in range(len(s)):
if s[i] == "0":
k = i - x
if k >= 0:
w[k] = 0
k = i + x
if k < len(s):
w[k] = 0
else:
pass
for i in range(len(w)):
k = i - x
left = right = -1
flag = 1
if k >= 0:
left = w[k]
k = i + x
if k < len(s):
right = w[k]
if left == 1 or right == 1:
if s[i] == "1":
continue
else:
flag = 0
break
elif s[i] == "0":
continue
else:
flag = 0
break
if flag:
for x in w:
print(x, end="")
print("\n")
else:
print(-1) | FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR STRING ASSIGN VAR BIN_OP VAR VAR IF VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR BIN_OP VAR VAR IF VAR FUNC_CALL VAR VAR ASSIGN VAR VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR VAR NUMBER ASSIGN VAR NUMBER IF VAR NUMBER ASSIGN VAR VAR VAR ASSIGN VAR BIN_OP VAR VAR IF VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR IF VAR NUMBER VAR NUMBER IF VAR VAR STRING ASSIGN VAR NUMBER IF VAR VAR STRING ASSIGN VAR NUMBER IF VAR FOR VAR VAR EXPR FUNC_CALL VAR VAR STRING EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR NUMBER |
Consider the following process. You have a binary string (a string where each character is either 0 or 1) $w$ of length $n$ and an integer $x$. You build a new binary string $s$ consisting of $n$ characters. The $i$-th character of $s$ is chosen as follows:
if the character $w_{i-x}$ exists and is equal to 1, then $s_i$ is 1 (formally, if $i > x$ and $w_{i-x} = $ 1, then $s_i = $ 1); if the character $w_{i+x}$ exists and is equal to 1, then $s_i$ is 1 (formally, if $i + x \le n$ and $w_{i+x} = $ 1, then $s_i = $ 1); if both of the aforementioned conditions are false, then $s_i$ is 0.
You are given the integer $x$ and the resulting string $s$. Reconstruct the original string $w$.
-----Input-----
The first line contains one integer $t$ ($1 \le t \le 1000$) β the number of test cases.
Each test case consists of two lines. The first line contains the resulting string $s$ ($2 \le |s| \le 10^5$, each character of $s$ is either 0 or 1). The second line contains one integer $x$ ($1 \le x \le |s| - 1$).
The total length of all strings $s$ in the input does not exceed $10^5$.
-----Output-----
For each test case, print the answer on a separate line as follows:
if no string $w$ can produce the string $s$ at the end of the process, print $-1$; otherwise, print the binary string $w$ consisting of $|s|$ characters. If there are multiple answers, print any of them.
-----Example-----
Input
3
101110
2
01
1
110
1
Output
111011
10
-1 | t = int(input())
def solve(s, x):
ans = ["1"] * len(s)
for i in range(len(s)):
if s[i] == "0":
if i - x >= 0:
ans[i - x] = "0"
if i + x < len(s):
ans[i + x] = "0"
for i in range(len(s)):
if (
(ans[i + x] == "0" if i + x < len(s) else True)
and (ans[i - x] == "0" if i - x >= 0 else True)
and s[i] == "1"
):
print(-1)
break
else:
print("".join(ans))
for i in range(t):
solve(input(), int(input())) | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_DEF ASSIGN VAR BIN_OP LIST STRING FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR STRING IF BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP VAR VAR STRING IF BIN_OP VAR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR VAR STRING FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF BIN_OP VAR VAR FUNC_CALL VAR VAR VAR BIN_OP VAR VAR STRING NUMBER BIN_OP VAR VAR NUMBER VAR BIN_OP VAR VAR STRING NUMBER VAR VAR STRING EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL STRING VAR FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR |
Consider the following process. You have a binary string (a string where each character is either 0 or 1) $w$ of length $n$ and an integer $x$. You build a new binary string $s$ consisting of $n$ characters. The $i$-th character of $s$ is chosen as follows:
if the character $w_{i-x}$ exists and is equal to 1, then $s_i$ is 1 (formally, if $i > x$ and $w_{i-x} = $ 1, then $s_i = $ 1); if the character $w_{i+x}$ exists and is equal to 1, then $s_i$ is 1 (formally, if $i + x \le n$ and $w_{i+x} = $ 1, then $s_i = $ 1); if both of the aforementioned conditions are false, then $s_i$ is 0.
You are given the integer $x$ and the resulting string $s$. Reconstruct the original string $w$.
-----Input-----
The first line contains one integer $t$ ($1 \le t \le 1000$) β the number of test cases.
Each test case consists of two lines. The first line contains the resulting string $s$ ($2 \le |s| \le 10^5$, each character of $s$ is either 0 or 1). The second line contains one integer $x$ ($1 \le x \le |s| - 1$).
The total length of all strings $s$ in the input does not exceed $10^5$.
-----Output-----
For each test case, print the answer on a separate line as follows:
if no string $w$ can produce the string $s$ at the end of the process, print $-1$; otherwise, print the binary string $w$ consisting of $|s|$ characters. If there are multiple answers, print any of them.
-----Example-----
Input
3
101110
2
01
1
110
1
Output
111011
10
-1 | for _ in range(int(input())):
s = input()
n = len(s)
x = int(input())
w = [(0) for _ in range(n)]
for i, char in enumerate(s):
if char == "1":
if 0 <= i - x < n <= i + x:
w[i - x] = 1
if 0 <= i - 2 * x and s[i - 2 * x] != "1":
print(-1)
break
elif i - x < 0 <= i + x < n:
w[i + x] = 1
if i + 2 * x < n and s[i + 2 * x] != "1":
print(-1)
break
elif 0 <= i - x <= i + x < n:
if i + 2 * x >= n or s[i + 2 * x] == "1":
w[i + x] = 1
elif 0 > i - 2 * x or s[i - 2 * x] == "1":
w[i - x] = 1
else:
print(-1)
break
else:
print(-1)
break
elif 0 <= i - x and w[i - x] != 0 or i + x < n and w[i + x] != 0:
print(-1)
break
else:
print(*w, sep="") | FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR VAR FOR VAR VAR FUNC_CALL VAR VAR IF VAR STRING IF NUMBER BIN_OP VAR VAR VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP VAR VAR NUMBER IF NUMBER BIN_OP VAR BIN_OP NUMBER VAR VAR BIN_OP VAR BIN_OP NUMBER VAR STRING EXPR FUNC_CALL VAR NUMBER IF BIN_OP VAR VAR NUMBER BIN_OP VAR VAR VAR ASSIGN VAR BIN_OP VAR VAR NUMBER IF BIN_OP VAR BIN_OP NUMBER VAR VAR VAR BIN_OP VAR BIN_OP NUMBER VAR STRING EXPR FUNC_CALL VAR NUMBER IF NUMBER BIN_OP VAR VAR BIN_OP VAR VAR VAR IF BIN_OP VAR BIN_OP NUMBER VAR VAR VAR BIN_OP VAR BIN_OP NUMBER VAR STRING ASSIGN VAR BIN_OP VAR VAR NUMBER IF NUMBER BIN_OP VAR BIN_OP NUMBER VAR VAR BIN_OP VAR BIN_OP NUMBER VAR STRING ASSIGN VAR BIN_OP VAR VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR NUMBER IF NUMBER BIN_OP VAR VAR VAR BIN_OP VAR VAR NUMBER BIN_OP VAR VAR VAR VAR BIN_OP VAR VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR VAR STRING |
Consider the following process. You have a binary string (a string where each character is either 0 or 1) $w$ of length $n$ and an integer $x$. You build a new binary string $s$ consisting of $n$ characters. The $i$-th character of $s$ is chosen as follows:
if the character $w_{i-x}$ exists and is equal to 1, then $s_i$ is 1 (formally, if $i > x$ and $w_{i-x} = $ 1, then $s_i = $ 1); if the character $w_{i+x}$ exists and is equal to 1, then $s_i$ is 1 (formally, if $i + x \le n$ and $w_{i+x} = $ 1, then $s_i = $ 1); if both of the aforementioned conditions are false, then $s_i$ is 0.
You are given the integer $x$ and the resulting string $s$. Reconstruct the original string $w$.
-----Input-----
The first line contains one integer $t$ ($1 \le t \le 1000$) β the number of test cases.
Each test case consists of two lines. The first line contains the resulting string $s$ ($2 \le |s| \le 10^5$, each character of $s$ is either 0 or 1). The second line contains one integer $x$ ($1 \le x \le |s| - 1$).
The total length of all strings $s$ in the input does not exceed $10^5$.
-----Output-----
For each test case, print the answer on a separate line as follows:
if no string $w$ can produce the string $s$ at the end of the process, print $-1$; otherwise, print the binary string $w$ consisting of $|s|$ characters. If there are multiple answers, print any of them.
-----Example-----
Input
3
101110
2
01
1
110
1
Output
111011
10
-1 | t = int(input())
for i in range(t):
st = input()
x = int(input())
n = len(st)
arr = [(-1) for j in range(n)]
for j in range(n):
if st[j] == "1":
if j - x >= 0 and (arr[j - x] == -1 or arr[j - x] == 1):
arr[j - x] = 1
elif j + x < n and (arr[j + x] == -1 or arr[j + x] == 1):
arr[j + x] = 1
else:
print(-1)
break
else:
if j - x >= 0:
if arr[j - x] == -1 or arr[j - x] == 0:
arr[j - x] = 0
else:
print(-1)
break
if j + x < n:
if arr[j + x] == -1 or arr[j + x] == 0:
arr[j + x] = 0
else:
print(-1)
break
else:
for k in arr:
if k == -1 or k == 0:
print(0, end="")
else:
print(1, end="")
print() | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR IF VAR VAR STRING IF BIN_OP VAR VAR NUMBER VAR BIN_OP VAR VAR NUMBER VAR BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP VAR VAR NUMBER IF BIN_OP VAR VAR VAR VAR BIN_OP VAR VAR NUMBER VAR BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP VAR VAR NUMBER EXPR FUNC_CALL VAR NUMBER IF BIN_OP VAR VAR NUMBER IF VAR BIN_OP VAR VAR NUMBER VAR BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP VAR VAR NUMBER EXPR FUNC_CALL VAR NUMBER IF BIN_OP VAR VAR VAR IF VAR BIN_OP VAR VAR NUMBER VAR BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP VAR VAR NUMBER EXPR FUNC_CALL VAR NUMBER FOR VAR VAR IF VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR NUMBER STRING EXPR FUNC_CALL VAR NUMBER STRING EXPR FUNC_CALL VAR |
Consider the following process. You have a binary string (a string where each character is either 0 or 1) $w$ of length $n$ and an integer $x$. You build a new binary string $s$ consisting of $n$ characters. The $i$-th character of $s$ is chosen as follows:
if the character $w_{i-x}$ exists and is equal to 1, then $s_i$ is 1 (formally, if $i > x$ and $w_{i-x} = $ 1, then $s_i = $ 1); if the character $w_{i+x}$ exists and is equal to 1, then $s_i$ is 1 (formally, if $i + x \le n$ and $w_{i+x} = $ 1, then $s_i = $ 1); if both of the aforementioned conditions are false, then $s_i$ is 0.
You are given the integer $x$ and the resulting string $s$. Reconstruct the original string $w$.
-----Input-----
The first line contains one integer $t$ ($1 \le t \le 1000$) β the number of test cases.
Each test case consists of two lines. The first line contains the resulting string $s$ ($2 \le |s| \le 10^5$, each character of $s$ is either 0 or 1). The second line contains one integer $x$ ($1 \le x \le |s| - 1$).
The total length of all strings $s$ in the input does not exceed $10^5$.
-----Output-----
For each test case, print the answer on a separate line as follows:
if no string $w$ can produce the string $s$ at the end of the process, print $-1$; otherwise, print the binary string $w$ consisting of $|s|$ characters. If there are multiple answers, print any of them.
-----Example-----
Input
3
101110
2
01
1
110
1
Output
111011
10
-1 | def solve():
s = list(map(int, input()))
n = len(s)
x = int(input())
w = [0] * n
d = [False] * n
for i in range(n):
if s[i] == 0:
if i - x >= 0:
w[i - x] = 0
d[i - x] = True
if i + x < n:
w[i + x] = 0
d[i + x] = True
for i in range(n):
if not d[i]:
w[i] = 1
d[i] = True
t = [0] * n
for i in range(n):
if i - x >= 0 and w[i - x] == 1:
t[i] = 1
if i + x < n and w[i + x] == 1:
t[i] = 1
if s != t:
print("-1")
return
print("".join(map(str, w)))
t = int(input())
for _ in range(t):
solve() | FUNC_DEF ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR BIN_OP LIST NUMBER VAR FOR VAR FUNC_CALL VAR VAR IF VAR VAR NUMBER IF BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP VAR VAR NUMBER IF BIN_OP VAR VAR VAR ASSIGN VAR BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP VAR VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR ASSIGN VAR VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER VAR FOR VAR FUNC_CALL VAR VAR IF BIN_OP VAR VAR NUMBER VAR BIN_OP VAR VAR NUMBER ASSIGN VAR VAR NUMBER IF BIN_OP VAR VAR VAR VAR BIN_OP VAR VAR NUMBER ASSIGN VAR VAR NUMBER IF VAR VAR EXPR FUNC_CALL VAR STRING RETURN EXPR FUNC_CALL VAR FUNC_CALL STRING FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR |
Consider the following process. You have a binary string (a string where each character is either 0 or 1) $w$ of length $n$ and an integer $x$. You build a new binary string $s$ consisting of $n$ characters. The $i$-th character of $s$ is chosen as follows:
if the character $w_{i-x}$ exists and is equal to 1, then $s_i$ is 1 (formally, if $i > x$ and $w_{i-x} = $ 1, then $s_i = $ 1); if the character $w_{i+x}$ exists and is equal to 1, then $s_i$ is 1 (formally, if $i + x \le n$ and $w_{i+x} = $ 1, then $s_i = $ 1); if both of the aforementioned conditions are false, then $s_i$ is 0.
You are given the integer $x$ and the resulting string $s$. Reconstruct the original string $w$.
-----Input-----
The first line contains one integer $t$ ($1 \le t \le 1000$) β the number of test cases.
Each test case consists of two lines. The first line contains the resulting string $s$ ($2 \le |s| \le 10^5$, each character of $s$ is either 0 or 1). The second line contains one integer $x$ ($1 \le x \le |s| - 1$).
The total length of all strings $s$ in the input does not exceed $10^5$.
-----Output-----
For each test case, print the answer on a separate line as follows:
if no string $w$ can produce the string $s$ at the end of the process, print $-1$; otherwise, print the binary string $w$ consisting of $|s|$ characters. If there are multiple answers, print any of them.
-----Example-----
Input
3
101110
2
01
1
110
1
Output
111011
10
-1 | t = int(input())
for _ in range(t):
s = str(input())
n = len(s)
ans = [None] * n
x = int(input())
cek = False
for i in range(n):
if s[i] == "0":
if i >= x:
ans[i - x] = "0"
if i + x < n:
ans[i + x] = "0"
for i in range(n):
if s[i] == "1":
if i >= x and ans[i - x] != "0":
ans[i - x] = "1"
continue
if i + x < n and ans[i + x] != "0":
ans[i + x] = "1"
else:
print(-1)
cek = True
break
if cek:
continue
for i in range(n):
if ans[i] == None:
ans[i] = "1"
print(*ans, sep="") | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP LIST NONE VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR STRING IF VAR VAR ASSIGN VAR BIN_OP VAR VAR STRING IF BIN_OP VAR VAR VAR ASSIGN VAR BIN_OP VAR VAR STRING FOR VAR FUNC_CALL VAR VAR IF VAR VAR STRING IF VAR VAR VAR BIN_OP VAR VAR STRING ASSIGN VAR BIN_OP VAR VAR STRING IF BIN_OP VAR VAR VAR VAR BIN_OP VAR VAR STRING ASSIGN VAR BIN_OP VAR VAR STRING EXPR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER IF VAR FOR VAR FUNC_CALL VAR VAR IF VAR VAR NONE ASSIGN VAR VAR STRING EXPR FUNC_CALL VAR VAR STRING |
Consider the following process. You have a binary string (a string where each character is either 0 or 1) $w$ of length $n$ and an integer $x$. You build a new binary string $s$ consisting of $n$ characters. The $i$-th character of $s$ is chosen as follows:
if the character $w_{i-x}$ exists and is equal to 1, then $s_i$ is 1 (formally, if $i > x$ and $w_{i-x} = $ 1, then $s_i = $ 1); if the character $w_{i+x}$ exists and is equal to 1, then $s_i$ is 1 (formally, if $i + x \le n$ and $w_{i+x} = $ 1, then $s_i = $ 1); if both of the aforementioned conditions are false, then $s_i$ is 0.
You are given the integer $x$ and the resulting string $s$. Reconstruct the original string $w$.
-----Input-----
The first line contains one integer $t$ ($1 \le t \le 1000$) β the number of test cases.
Each test case consists of two lines. The first line contains the resulting string $s$ ($2 \le |s| \le 10^5$, each character of $s$ is either 0 or 1). The second line contains one integer $x$ ($1 \le x \le |s| - 1$).
The total length of all strings $s$ in the input does not exceed $10^5$.
-----Output-----
For each test case, print the answer on a separate line as follows:
if no string $w$ can produce the string $s$ at the end of the process, print $-1$; otherwise, print the binary string $w$ consisting of $|s|$ characters. If there are multiple answers, print any of them.
-----Example-----
Input
3
101110
2
01
1
110
1
Output
111011
10
-1 | t = int(input())
for a in range(t):
s = list(input())
x = int(input())
n = len(s)
w = list()
for tt in range(n):
w.append("1")
for i in range(n):
if "0" == s[i]:
if i >= x:
w[i - x] = "0"
if n > i + x:
w[i + x] = "0"
def f(qq):
ww = list()
for ii in range(n):
if ii >= x and qq[ii - x] == "1" or n > ii + x and qq[ii + x] == "1":
ww.append("1")
else:
ww.append("0")
return ww
if f(w) == s:
print("".join(w))
else:
print(-1) | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR STRING FOR VAR FUNC_CALL VAR VAR IF STRING VAR VAR IF VAR VAR ASSIGN VAR BIN_OP VAR VAR STRING IF VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP VAR VAR STRING FUNC_DEF ASSIGN VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR BIN_OP VAR VAR STRING VAR BIN_OP VAR VAR VAR BIN_OP VAR VAR STRING EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING RETURN VAR IF FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR FUNC_CALL STRING VAR EXPR FUNC_CALL VAR NUMBER |
Consider the following process. You have a binary string (a string where each character is either 0 or 1) $w$ of length $n$ and an integer $x$. You build a new binary string $s$ consisting of $n$ characters. The $i$-th character of $s$ is chosen as follows:
if the character $w_{i-x}$ exists and is equal to 1, then $s_i$ is 1 (formally, if $i > x$ and $w_{i-x} = $ 1, then $s_i = $ 1); if the character $w_{i+x}$ exists and is equal to 1, then $s_i$ is 1 (formally, if $i + x \le n$ and $w_{i+x} = $ 1, then $s_i = $ 1); if both of the aforementioned conditions are false, then $s_i$ is 0.
You are given the integer $x$ and the resulting string $s$. Reconstruct the original string $w$.
-----Input-----
The first line contains one integer $t$ ($1 \le t \le 1000$) β the number of test cases.
Each test case consists of two lines. The first line contains the resulting string $s$ ($2 \le |s| \le 10^5$, each character of $s$ is either 0 or 1). The second line contains one integer $x$ ($1 \le x \le |s| - 1$).
The total length of all strings $s$ in the input does not exceed $10^5$.
-----Output-----
For each test case, print the answer on a separate line as follows:
if no string $w$ can produce the string $s$ at the end of the process, print $-1$; otherwise, print the binary string $w$ consisting of $|s|$ characters. If there are multiple answers, print any of them.
-----Example-----
Input
3
101110
2
01
1
110
1
Output
111011
10
-1 | def fun(ans, s):
for i in range(len(s)):
if s[i] == "1":
if i - x >= 0 and ans[i - x] == "1":
continue
if i + x < len(s) and ans[i + x] == "1":
continue
return False
return True
for _ in range(int(input())):
s = input()
x = int(input())
n = len(s)
ans = ["1"] * n
for i in range(n):
if s[i] == "0":
if i - x >= 0:
ans[i - x] = "0"
if i + x < n:
ans[i + x] = "0"
ret = "".join(ans)
chk = fun(ans, s)
if not chk:
print(-1)
else:
print(ret) | FUNC_DEF FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR STRING IF BIN_OP VAR VAR NUMBER VAR BIN_OP VAR VAR STRING IF BIN_OP VAR VAR FUNC_CALL VAR VAR VAR BIN_OP VAR VAR STRING RETURN NUMBER RETURN NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP LIST STRING VAR FOR VAR FUNC_CALL VAR VAR IF VAR VAR STRING IF BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP VAR VAR STRING IF BIN_OP VAR VAR VAR ASSIGN VAR BIN_OP VAR VAR STRING ASSIGN VAR FUNC_CALL STRING VAR ASSIGN VAR FUNC_CALL VAR VAR VAR IF VAR EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR VAR |
Consider the following process. You have a binary string (a string where each character is either 0 or 1) $w$ of length $n$ and an integer $x$. You build a new binary string $s$ consisting of $n$ characters. The $i$-th character of $s$ is chosen as follows:
if the character $w_{i-x}$ exists and is equal to 1, then $s_i$ is 1 (formally, if $i > x$ and $w_{i-x} = $ 1, then $s_i = $ 1); if the character $w_{i+x}$ exists and is equal to 1, then $s_i$ is 1 (formally, if $i + x \le n$ and $w_{i+x} = $ 1, then $s_i = $ 1); if both of the aforementioned conditions are false, then $s_i$ is 0.
You are given the integer $x$ and the resulting string $s$. Reconstruct the original string $w$.
-----Input-----
The first line contains one integer $t$ ($1 \le t \le 1000$) β the number of test cases.
Each test case consists of two lines. The first line contains the resulting string $s$ ($2 \le |s| \le 10^5$, each character of $s$ is either 0 or 1). The second line contains one integer $x$ ($1 \le x \le |s| - 1$).
The total length of all strings $s$ in the input does not exceed $10^5$.
-----Output-----
For each test case, print the answer on a separate line as follows:
if no string $w$ can produce the string $s$ at the end of the process, print $-1$; otherwise, print the binary string $w$ consisting of $|s|$ characters. If there are multiple answers, print any of them.
-----Example-----
Input
3
101110
2
01
1
110
1
Output
111011
10
-1 | def solve(s, x):
n = len(s)
a = [None] * n
todos = []
for i, c in enumerate(s):
if i <= x - 1:
if i + x < n:
if a[i + x] == None:
a[i + x] = int(c)
elif int(c) != a[i + x]:
return -1
elif c == "1":
return -1
elif i >= n - x:
if i - x >= 0:
if a[i - x] == None:
a[i - x] = int(c)
elif int(c) != a[i - x]:
return -1
elif c == "1":
return -1
elif c == "0":
if a[i - x] == 1 or a[i + x] == 1:
return -1
a[i - x] = 0
a[i + x] = 0
else:
todos.append((i - x, i + x))
for i, j in todos:
if a[i] == 0 and a[j] == 0:
return -1
for i in range(n):
if a[i] == None:
a[i] = 1
return "".join(str(x) for x in a)
tn = int(input())
for ti in range(tn):
s = input()
x = int(input())
ans = solve(s, x)
print(ans) | FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP LIST NONE VAR ASSIGN VAR LIST FOR VAR VAR FUNC_CALL VAR VAR IF VAR BIN_OP VAR NUMBER IF BIN_OP VAR VAR VAR IF VAR BIN_OP VAR VAR NONE ASSIGN VAR BIN_OP VAR VAR FUNC_CALL VAR VAR IF FUNC_CALL VAR VAR VAR BIN_OP VAR VAR RETURN NUMBER IF VAR STRING RETURN NUMBER IF VAR BIN_OP VAR VAR IF BIN_OP VAR VAR NUMBER IF VAR BIN_OP VAR VAR NONE ASSIGN VAR BIN_OP VAR VAR FUNC_CALL VAR VAR IF FUNC_CALL VAR VAR VAR BIN_OP VAR VAR RETURN NUMBER IF VAR STRING RETURN NUMBER IF VAR STRING IF VAR BIN_OP VAR VAR NUMBER VAR BIN_OP VAR VAR NUMBER RETURN NUMBER ASSIGN VAR BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP VAR VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR VAR BIN_OP VAR VAR FOR VAR VAR VAR IF VAR VAR NUMBER VAR VAR NUMBER RETURN NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR NONE ASSIGN VAR VAR NUMBER RETURN FUNC_CALL STRING FUNC_CALL VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR |
Consider the following process. You have a binary string (a string where each character is either 0 or 1) $w$ of length $n$ and an integer $x$. You build a new binary string $s$ consisting of $n$ characters. The $i$-th character of $s$ is chosen as follows:
if the character $w_{i-x}$ exists and is equal to 1, then $s_i$ is 1 (formally, if $i > x$ and $w_{i-x} = $ 1, then $s_i = $ 1); if the character $w_{i+x}$ exists and is equal to 1, then $s_i$ is 1 (formally, if $i + x \le n$ and $w_{i+x} = $ 1, then $s_i = $ 1); if both of the aforementioned conditions are false, then $s_i$ is 0.
You are given the integer $x$ and the resulting string $s$. Reconstruct the original string $w$.
-----Input-----
The first line contains one integer $t$ ($1 \le t \le 1000$) β the number of test cases.
Each test case consists of two lines. The first line contains the resulting string $s$ ($2 \le |s| \le 10^5$, each character of $s$ is either 0 or 1). The second line contains one integer $x$ ($1 \le x \le |s| - 1$).
The total length of all strings $s$ in the input does not exceed $10^5$.
-----Output-----
For each test case, print the answer on a separate line as follows:
if no string $w$ can produce the string $s$ at the end of the process, print $-1$; otherwise, print the binary string $w$ consisting of $|s|$ characters. If there are multiple answers, print any of them.
-----Example-----
Input
3
101110
2
01
1
110
1
Output
111011
10
-1 | from sys import maxsize, stdin, stdout
input = stdin.readline
def solve():
pass
test = 1
test = int(input().strip())
for t in range(0, test):
s = [int(x) for x in list(input().strip())]
ans = [1] * len(s)
x = int(input().strip())
for i in range(len(s)):
if s[i] == 0:
if i - x >= 0:
ans[i - x] = 0
if i + x < len(s):
ans[i + x] = 0
flag = False
for i in range(len(s)):
if s[i] == 1:
a, b = 0, 0
if i - x >= 0 and ans[i - x] == 1:
a = 1
if i + x < len(s) and ans[i + x] == 1:
b = 1
if a + b == 0:
flag = True
if flag:
print(-1)
else:
print("".join([str(x) for x in ans]))
ans = solve() | ASSIGN VAR VAR FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL FUNC_CALL VAR FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL FUNC_CALL VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR NUMBER IF BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP VAR VAR NUMBER IF BIN_OP VAR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR NUMBER ASSIGN VAR VAR NUMBER NUMBER IF BIN_OP VAR VAR NUMBER VAR BIN_OP VAR VAR NUMBER ASSIGN VAR NUMBER IF BIN_OP VAR VAR FUNC_CALL VAR VAR VAR BIN_OP VAR VAR NUMBER ASSIGN VAR NUMBER IF BIN_OP VAR VAR NUMBER ASSIGN VAR NUMBER IF VAR EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL STRING FUNC_CALL VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR |
Consider the following process. You have a binary string (a string where each character is either 0 or 1) $w$ of length $n$ and an integer $x$. You build a new binary string $s$ consisting of $n$ characters. The $i$-th character of $s$ is chosen as follows:
if the character $w_{i-x}$ exists and is equal to 1, then $s_i$ is 1 (formally, if $i > x$ and $w_{i-x} = $ 1, then $s_i = $ 1); if the character $w_{i+x}$ exists and is equal to 1, then $s_i$ is 1 (formally, if $i + x \le n$ and $w_{i+x} = $ 1, then $s_i = $ 1); if both of the aforementioned conditions are false, then $s_i$ is 0.
You are given the integer $x$ and the resulting string $s$. Reconstruct the original string $w$.
-----Input-----
The first line contains one integer $t$ ($1 \le t \le 1000$) β the number of test cases.
Each test case consists of two lines. The first line contains the resulting string $s$ ($2 \le |s| \le 10^5$, each character of $s$ is either 0 or 1). The second line contains one integer $x$ ($1 \le x \le |s| - 1$).
The total length of all strings $s$ in the input does not exceed $10^5$.
-----Output-----
For each test case, print the answer on a separate line as follows:
if no string $w$ can produce the string $s$ at the end of the process, print $-1$; otherwise, print the binary string $w$ consisting of $|s|$ characters. If there are multiple answers, print any of them.
-----Example-----
Input
3
101110
2
01
1
110
1
Output
111011
10
-1 | import sys
input = sys.stdin.readline
T = int(input())
while T:
s = list(input())[:-1]
x = int(input())
n = len(s)
w = ["1" for i in range(n)]
r = ""
for i in range(n):
if s[i] == "0":
if i - x > -1:
w[i - x] = "0"
if i + x < n:
w[i + x] = "0"
for i in range(n):
if s[i] == "1":
if i + x >= n and i - x < 0:
r = -1
break
elif i + x < n and i - x > -1:
if w[i + x] == "0" and w[i - x] == "0":
r = -1
break
elif i + x < n:
if w[i + x] == "0":
r = -1
break
elif i - x > -1:
if w[i - x] == "0":
r = -1
break
if r == -1:
print(r)
else:
r = "".join(i for i in w)
print(r)
T = T - 1 | IMPORT ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR WHILE VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR STRING VAR FUNC_CALL VAR VAR ASSIGN VAR STRING FOR VAR FUNC_CALL VAR VAR IF VAR VAR STRING IF BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP VAR VAR STRING IF BIN_OP VAR VAR VAR ASSIGN VAR BIN_OP VAR VAR STRING FOR VAR FUNC_CALL VAR VAR IF VAR VAR STRING IF BIN_OP VAR VAR VAR BIN_OP VAR VAR NUMBER ASSIGN VAR NUMBER IF BIN_OP VAR VAR VAR BIN_OP VAR VAR NUMBER IF VAR BIN_OP VAR VAR STRING VAR BIN_OP VAR VAR STRING ASSIGN VAR NUMBER IF BIN_OP VAR VAR VAR IF VAR BIN_OP VAR VAR STRING ASSIGN VAR NUMBER IF BIN_OP VAR VAR NUMBER IF VAR BIN_OP VAR VAR STRING ASSIGN VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL STRING VAR VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR NUMBER |
Consider the following process. You have a binary string (a string where each character is either 0 or 1) $w$ of length $n$ and an integer $x$. You build a new binary string $s$ consisting of $n$ characters. The $i$-th character of $s$ is chosen as follows:
if the character $w_{i-x}$ exists and is equal to 1, then $s_i$ is 1 (formally, if $i > x$ and $w_{i-x} = $ 1, then $s_i = $ 1); if the character $w_{i+x}$ exists and is equal to 1, then $s_i$ is 1 (formally, if $i + x \le n$ and $w_{i+x} = $ 1, then $s_i = $ 1); if both of the aforementioned conditions are false, then $s_i$ is 0.
You are given the integer $x$ and the resulting string $s$. Reconstruct the original string $w$.
-----Input-----
The first line contains one integer $t$ ($1 \le t \le 1000$) β the number of test cases.
Each test case consists of two lines. The first line contains the resulting string $s$ ($2 \le |s| \le 10^5$, each character of $s$ is either 0 or 1). The second line contains one integer $x$ ($1 \le x \le |s| - 1$).
The total length of all strings $s$ in the input does not exceed $10^5$.
-----Output-----
For each test case, print the answer on a separate line as follows:
if no string $w$ can produce the string $s$ at the end of the process, print $-1$; otherwise, print the binary string $w$ consisting of $|s|$ characters. If there are multiple answers, print any of them.
-----Example-----
Input
3
101110
2
01
1
110
1
Output
111011
10
-1 | def solve():
t = int(input().strip())
for i in range(t):
s = [int(x) for x in input().strip()]
x = int(input())
n = len(s)
w = ["1"] * n
for i in range(n):
if s[i] == 0:
if i - x >= 0:
w[i - x] = "0"
if i + x < n:
w[i + x] = "0"
s_new = []
for i in range(n):
if i - x >= 0 and w[i - x] == "1":
s_new.append(1)
elif i + x < n and w[i + x] == "1":
s_new.append(1)
else:
s_new.append(0)
if s_new == s:
print("".join(w))
else:
print("-1")
solve() | FUNC_DEF ASSIGN VAR FUNC_CALL VAR FUNC_CALL FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP LIST STRING VAR FOR VAR FUNC_CALL VAR VAR IF VAR VAR NUMBER IF BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP VAR VAR STRING IF BIN_OP VAR VAR VAR ASSIGN VAR BIN_OP VAR VAR STRING ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR IF BIN_OP VAR VAR NUMBER VAR BIN_OP VAR VAR STRING EXPR FUNC_CALL VAR NUMBER IF BIN_OP VAR VAR VAR VAR BIN_OP VAR VAR STRING EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR NUMBER IF VAR VAR EXPR FUNC_CALL VAR FUNC_CALL STRING VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR |
Consider the following process. You have a binary string (a string where each character is either 0 or 1) $w$ of length $n$ and an integer $x$. You build a new binary string $s$ consisting of $n$ characters. The $i$-th character of $s$ is chosen as follows:
if the character $w_{i-x}$ exists and is equal to 1, then $s_i$ is 1 (formally, if $i > x$ and $w_{i-x} = $ 1, then $s_i = $ 1); if the character $w_{i+x}$ exists and is equal to 1, then $s_i$ is 1 (formally, if $i + x \le n$ and $w_{i+x} = $ 1, then $s_i = $ 1); if both of the aforementioned conditions are false, then $s_i$ is 0.
You are given the integer $x$ and the resulting string $s$. Reconstruct the original string $w$.
-----Input-----
The first line contains one integer $t$ ($1 \le t \le 1000$) β the number of test cases.
Each test case consists of two lines. The first line contains the resulting string $s$ ($2 \le |s| \le 10^5$, each character of $s$ is either 0 or 1). The second line contains one integer $x$ ($1 \le x \le |s| - 1$).
The total length of all strings $s$ in the input does not exceed $10^5$.
-----Output-----
For each test case, print the answer on a separate line as follows:
if no string $w$ can produce the string $s$ at the end of the process, print $-1$; otherwise, print the binary string $w$ consisting of $|s|$ characters. If there are multiple answers, print any of them.
-----Example-----
Input
3
101110
2
01
1
110
1
Output
111011
10
-1 | for _ in range(int(input())):
s = input()
x = int(input())
n = len(s)
w = [1] * n
for i in range(n):
if s[i] == "0":
if i >= x:
w[i - x] = 0
if i + x < n:
w[i + x] = 0
s1 = [1] * n
for i in range(n):
if i >= x and w[i - x] == 1 or i + x < n and w[i + x] == 1:
s1[i] = 1
else:
s1[i] = 0
w = "".join([str(i) for i in w])
s = "".join([str(i) for i in s])
s1 = "".join([str(i) for i in s1])
if s == s1:
print(w)
else:
print(-1) | FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP LIST NUMBER VAR FOR VAR FUNC_CALL VAR VAR IF VAR VAR STRING IF VAR VAR ASSIGN VAR BIN_OP VAR VAR NUMBER IF BIN_OP VAR VAR VAR ASSIGN VAR BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER VAR FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR BIN_OP VAR VAR NUMBER BIN_OP VAR VAR VAR VAR BIN_OP VAR VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR FUNC_CALL STRING FUNC_CALL VAR VAR VAR VAR ASSIGN VAR FUNC_CALL STRING FUNC_CALL VAR VAR VAR VAR ASSIGN VAR FUNC_CALL STRING FUNC_CALL VAR VAR VAR VAR IF VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR NUMBER |
Consider the following process. You have a binary string (a string where each character is either 0 or 1) $w$ of length $n$ and an integer $x$. You build a new binary string $s$ consisting of $n$ characters. The $i$-th character of $s$ is chosen as follows:
if the character $w_{i-x}$ exists and is equal to 1, then $s_i$ is 1 (formally, if $i > x$ and $w_{i-x} = $ 1, then $s_i = $ 1); if the character $w_{i+x}$ exists and is equal to 1, then $s_i$ is 1 (formally, if $i + x \le n$ and $w_{i+x} = $ 1, then $s_i = $ 1); if both of the aforementioned conditions are false, then $s_i$ is 0.
You are given the integer $x$ and the resulting string $s$. Reconstruct the original string $w$.
-----Input-----
The first line contains one integer $t$ ($1 \le t \le 1000$) β the number of test cases.
Each test case consists of two lines. The first line contains the resulting string $s$ ($2 \le |s| \le 10^5$, each character of $s$ is either 0 or 1). The second line contains one integer $x$ ($1 \le x \le |s| - 1$).
The total length of all strings $s$ in the input does not exceed $10^5$.
-----Output-----
For each test case, print the answer on a separate line as follows:
if no string $w$ can produce the string $s$ at the end of the process, print $-1$; otherwise, print the binary string $w$ consisting of $|s|$ characters. If there are multiple answers, print any of them.
-----Example-----
Input
3
101110
2
01
1
110
1
Output
111011
10
-1 | def check_strings(string, string2, k):
result = True
for index in range(len(string2)):
selected_char = int(string[index])
left_char = None
right_char = None
char_to_use = 0
if index - k >= 0:
left_char = string2[index - k]
if index + k < len(string):
right_char = string2[index + k]
if (
left_char != None
and left_char == 1
or right_char != None
and right_char == 1
):
char_to_use = 1
if selected_char != char_to_use:
result = False
break
return result
def make_string(string, k):
result = -1
new_string = []
for elem in string:
new_string.append(1)
for index in range(len(string)):
elem = int(string[index])
if elem == 0:
left_index = index - k
right_index = index + k
if left_index >= 0:
new_string[left_index] = 0
if right_index < len(string):
new_string[right_index] = 0
cres = check_strings(string, new_string, k)
if cres == True:
for index in range(len(new_string)):
digit = new_string[index]
new_string[index] = str(digit)
result = "".join(new_string)
return result
ammount = int(input())
for index in range(ammount):
string = str(input())
k = int(input())
cres = make_string(string, k)
print(cres) | FUNC_DEF ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR NONE ASSIGN VAR NONE ASSIGN VAR NUMBER IF BIN_OP VAR VAR NUMBER ASSIGN VAR VAR BIN_OP VAR VAR IF BIN_OP VAR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR BIN_OP VAR VAR IF VAR NONE VAR NUMBER VAR NONE VAR NUMBER ASSIGN VAR NUMBER IF VAR VAR ASSIGN VAR NUMBER RETURN VAR FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR LIST FOR VAR VAR EXPR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR IF VAR NUMBER ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP VAR VAR IF VAR NUMBER ASSIGN VAR VAR NUMBER IF VAR FUNC_CALL VAR VAR ASSIGN VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR VAR IF VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL STRING VAR RETURN VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR |
Consider the following process. You have a binary string (a string where each character is either 0 or 1) $w$ of length $n$ and an integer $x$. You build a new binary string $s$ consisting of $n$ characters. The $i$-th character of $s$ is chosen as follows:
if the character $w_{i-x}$ exists and is equal to 1, then $s_i$ is 1 (formally, if $i > x$ and $w_{i-x} = $ 1, then $s_i = $ 1); if the character $w_{i+x}$ exists and is equal to 1, then $s_i$ is 1 (formally, if $i + x \le n$ and $w_{i+x} = $ 1, then $s_i = $ 1); if both of the aforementioned conditions are false, then $s_i$ is 0.
You are given the integer $x$ and the resulting string $s$. Reconstruct the original string $w$.
-----Input-----
The first line contains one integer $t$ ($1 \le t \le 1000$) β the number of test cases.
Each test case consists of two lines. The first line contains the resulting string $s$ ($2 \le |s| \le 10^5$, each character of $s$ is either 0 or 1). The second line contains one integer $x$ ($1 \le x \le |s| - 1$).
The total length of all strings $s$ in the input does not exceed $10^5$.
-----Output-----
For each test case, print the answer on a separate line as follows:
if no string $w$ can produce the string $s$ at the end of the process, print $-1$; otherwise, print the binary string $w$ consisting of $|s|$ characters. If there are multiple answers, print any of them.
-----Example-----
Input
3
101110
2
01
1
110
1
Output
111011
10
-1 | import sys
def main():
tn = int(input())
for ti in range(tn):
S = input().strip()
n = len(S)
W = [""] * n
x = int(input())
is_ok = True
for i, s in enumerate(S):
if s == "1":
continue
if i - x >= 0:
W[i - x] = "0"
if i + x < n:
W[i + x] = "0"
for i, s in enumerate(S):
if s == "0":
continue
c = 0
if i - x >= 0 and W[i - x] == "":
c += 1
if i + x < n and W[i + x] == "":
c += 1
if c == 0:
is_ok = False
print("".join(map(lambda x: x if x == "0" else "1", W)) if is_ok else "-1")
main() | IMPORT FUNC_DEF ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP LIST STRING VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR NUMBER FOR VAR VAR FUNC_CALL VAR VAR IF VAR STRING IF BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP VAR VAR STRING IF BIN_OP VAR VAR VAR ASSIGN VAR BIN_OP VAR VAR STRING FOR VAR VAR FUNC_CALL VAR VAR IF VAR STRING ASSIGN VAR NUMBER IF BIN_OP VAR VAR NUMBER VAR BIN_OP VAR VAR STRING VAR NUMBER IF BIN_OP VAR VAR VAR VAR BIN_OP VAR VAR STRING VAR NUMBER IF VAR NUMBER ASSIGN VAR NUMBER EXPR FUNC_CALL VAR VAR FUNC_CALL STRING FUNC_CALL VAR VAR STRING VAR STRING VAR STRING EXPR FUNC_CALL VAR |
Consider the following process. You have a binary string (a string where each character is either 0 or 1) $w$ of length $n$ and an integer $x$. You build a new binary string $s$ consisting of $n$ characters. The $i$-th character of $s$ is chosen as follows:
if the character $w_{i-x}$ exists and is equal to 1, then $s_i$ is 1 (formally, if $i > x$ and $w_{i-x} = $ 1, then $s_i = $ 1); if the character $w_{i+x}$ exists and is equal to 1, then $s_i$ is 1 (formally, if $i + x \le n$ and $w_{i+x} = $ 1, then $s_i = $ 1); if both of the aforementioned conditions are false, then $s_i$ is 0.
You are given the integer $x$ and the resulting string $s$. Reconstruct the original string $w$.
-----Input-----
The first line contains one integer $t$ ($1 \le t \le 1000$) β the number of test cases.
Each test case consists of two lines. The first line contains the resulting string $s$ ($2 \le |s| \le 10^5$, each character of $s$ is either 0 or 1). The second line contains one integer $x$ ($1 \le x \le |s| - 1$).
The total length of all strings $s$ in the input does not exceed $10^5$.
-----Output-----
For each test case, print the answer on a separate line as follows:
if no string $w$ can produce the string $s$ at the end of the process, print $-1$; otherwise, print the binary string $w$ consisting of $|s|$ characters. If there are multiple answers, print any of them.
-----Example-----
Input
3
101110
2
01
1
110
1
Output
111011
10
-1 | import sys
input = sys.stdin.readline
INF = 10
def solution():
s = list(map(int, input().rstrip()))
x = int(input())
N = len(s)
ans = [-1] * N
flag = True
for i in range(N):
if i - x < 0:
L = INF
else:
L = ans[i - x]
if i + x >= N:
R = INF
else:
R = ans[i + x]
if s[i] == 1:
if L == 1 or R == 1:
continue
elif L == -1:
ans[i - x] = 1
elif R == -1:
ans[i + x] = 1
else:
flag = False
if s[i] == 0:
if L == 0 and R == 0:
continue
elif L != 1 and R != 1:
if L == -1:
ans[i - x] = 0
if R == -1:
ans[i + x] = 0
else:
flag = False
if not flag:
print(-1)
else:
for i in range(N):
if ans[i] == -1:
ans[i] = 1
print("".join(map(str, ans)))
T = int(input())
for _ in range(T):
solution() | IMPORT ASSIGN VAR VAR ASSIGN VAR NUMBER FUNC_DEF ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF BIN_OP VAR VAR NUMBER ASSIGN VAR VAR ASSIGN VAR VAR BIN_OP VAR VAR IF BIN_OP VAR VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR BIN_OP VAR VAR IF VAR VAR NUMBER IF VAR NUMBER VAR NUMBER IF VAR NUMBER ASSIGN VAR BIN_OP VAR VAR NUMBER IF VAR NUMBER ASSIGN VAR BIN_OP VAR VAR NUMBER ASSIGN VAR NUMBER IF VAR VAR NUMBER IF VAR NUMBER VAR NUMBER IF VAR NUMBER VAR NUMBER IF VAR NUMBER ASSIGN VAR BIN_OP VAR VAR NUMBER IF VAR NUMBER ASSIGN VAR BIN_OP VAR VAR NUMBER ASSIGN VAR NUMBER IF VAR EXPR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR NUMBER ASSIGN VAR VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL STRING FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR |
Consider the following process. You have a binary string (a string where each character is either 0 or 1) $w$ of length $n$ and an integer $x$. You build a new binary string $s$ consisting of $n$ characters. The $i$-th character of $s$ is chosen as follows:
if the character $w_{i-x}$ exists and is equal to 1, then $s_i$ is 1 (formally, if $i > x$ and $w_{i-x} = $ 1, then $s_i = $ 1); if the character $w_{i+x}$ exists and is equal to 1, then $s_i$ is 1 (formally, if $i + x \le n$ and $w_{i+x} = $ 1, then $s_i = $ 1); if both of the aforementioned conditions are false, then $s_i$ is 0.
You are given the integer $x$ and the resulting string $s$. Reconstruct the original string $w$.
-----Input-----
The first line contains one integer $t$ ($1 \le t \le 1000$) β the number of test cases.
Each test case consists of two lines. The first line contains the resulting string $s$ ($2 \le |s| \le 10^5$, each character of $s$ is either 0 or 1). The second line contains one integer $x$ ($1 \le x \le |s| - 1$).
The total length of all strings $s$ in the input does not exceed $10^5$.
-----Output-----
For each test case, print the answer on a separate line as follows:
if no string $w$ can produce the string $s$ at the end of the process, print $-1$; otherwise, print the binary string $w$ consisting of $|s|$ characters. If there are multiple answers, print any of them.
-----Example-----
Input
3
101110
2
01
1
110
1
Output
111011
10
-1 | def fun(s, x):
n = len(s)
ans = ""
for i in range(n):
if i - x >= 0 and s[i - x] == "1" or i + x < n and s[i + x] == "1":
ans = ans + "1"
else:
ans = ans + "0"
return ans
t = int(input())
while t > 0:
s = input()
x = int(input())
n = len(s)
flag = 0
ans = ["1" for _ in range(n)]
for i in range(n):
if s[i] == "0":
if i - x >= 0:
ans[i - x] = "0"
if i + x < n:
ans[i + x] = "0"
if fun(ans, x) == s:
print("".join(ans))
else:
print(-1)
t -= 1 | FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR STRING FOR VAR FUNC_CALL VAR VAR IF BIN_OP VAR VAR NUMBER VAR BIN_OP VAR VAR STRING BIN_OP VAR VAR VAR VAR BIN_OP VAR VAR STRING ASSIGN VAR BIN_OP VAR STRING ASSIGN VAR BIN_OP VAR STRING RETURN VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR WHILE VAR NUMBER ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR STRING VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR IF VAR VAR STRING IF BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP VAR VAR STRING IF BIN_OP VAR VAR VAR ASSIGN VAR BIN_OP VAR VAR STRING IF FUNC_CALL VAR VAR VAR VAR EXPR FUNC_CALL VAR FUNC_CALL STRING VAR EXPR FUNC_CALL VAR NUMBER VAR NUMBER |
Consider the following process. You have a binary string (a string where each character is either 0 or 1) $w$ of length $n$ and an integer $x$. You build a new binary string $s$ consisting of $n$ characters. The $i$-th character of $s$ is chosen as follows:
if the character $w_{i-x}$ exists and is equal to 1, then $s_i$ is 1 (formally, if $i > x$ and $w_{i-x} = $ 1, then $s_i = $ 1); if the character $w_{i+x}$ exists and is equal to 1, then $s_i$ is 1 (formally, if $i + x \le n$ and $w_{i+x} = $ 1, then $s_i = $ 1); if both of the aforementioned conditions are false, then $s_i$ is 0.
You are given the integer $x$ and the resulting string $s$. Reconstruct the original string $w$.
-----Input-----
The first line contains one integer $t$ ($1 \le t \le 1000$) β the number of test cases.
Each test case consists of two lines. The first line contains the resulting string $s$ ($2 \le |s| \le 10^5$, each character of $s$ is either 0 or 1). The second line contains one integer $x$ ($1 \le x \le |s| - 1$).
The total length of all strings $s$ in the input does not exceed $10^5$.
-----Output-----
For each test case, print the answer on a separate line as follows:
if no string $w$ can produce the string $s$ at the end of the process, print $-1$; otherwise, print the binary string $w$ consisting of $|s|$ characters. If there are multiple answers, print any of them.
-----Example-----
Input
3
101110
2
01
1
110
1
Output
111011
10
-1 | from sys import stdin
for _ in range(int(stdin.readline())):
s = stdin.readline().strip()
n = len(s)
x = int(stdin.readline())
res = ["1"] * n
for i, c in enumerate(s):
if c == "0":
if i + x < n:
res[i + x] = "0"
if i - x > -1:
res[i - x] = "0"
for i in range(n):
one = False
one = one or i - x >= 0 and res[i - x] == "1"
one = one or i + x < n and res[i + x] == "1"
cur = "1" if one else "0"
if s[i] != cur:
res = ["-1"]
break
print("".join(res)) | FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR BIN_OP LIST STRING VAR FOR VAR VAR FUNC_CALL VAR VAR IF VAR STRING IF BIN_OP VAR VAR VAR ASSIGN VAR BIN_OP VAR VAR STRING IF BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP VAR VAR STRING FOR VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR VAR BIN_OP VAR VAR NUMBER VAR BIN_OP VAR VAR STRING ASSIGN VAR VAR BIN_OP VAR VAR VAR VAR BIN_OP VAR VAR STRING ASSIGN VAR VAR STRING STRING IF VAR VAR VAR ASSIGN VAR LIST STRING EXPR FUNC_CALL VAR FUNC_CALL STRING VAR |
Consider the following process. You have a binary string (a string where each character is either 0 or 1) $w$ of length $n$ and an integer $x$. You build a new binary string $s$ consisting of $n$ characters. The $i$-th character of $s$ is chosen as follows:
if the character $w_{i-x}$ exists and is equal to 1, then $s_i$ is 1 (formally, if $i > x$ and $w_{i-x} = $ 1, then $s_i = $ 1); if the character $w_{i+x}$ exists and is equal to 1, then $s_i$ is 1 (formally, if $i + x \le n$ and $w_{i+x} = $ 1, then $s_i = $ 1); if both of the aforementioned conditions are false, then $s_i$ is 0.
You are given the integer $x$ and the resulting string $s$. Reconstruct the original string $w$.
-----Input-----
The first line contains one integer $t$ ($1 \le t \le 1000$) β the number of test cases.
Each test case consists of two lines. The first line contains the resulting string $s$ ($2 \le |s| \le 10^5$, each character of $s$ is either 0 or 1). The second line contains one integer $x$ ($1 \le x \le |s| - 1$).
The total length of all strings $s$ in the input does not exceed $10^5$.
-----Output-----
For each test case, print the answer on a separate line as follows:
if no string $w$ can produce the string $s$ at the end of the process, print $-1$; otherwise, print the binary string $w$ consisting of $|s|$ characters. If there are multiple answers, print any of them.
-----Example-----
Input
3
101110
2
01
1
110
1
Output
111011
10
-1 | for _ in range(int(input())):
s = str(input())
x = int(input())
l = [-1] * len(s)
n = len(s)
for i in range(n):
if s[i] == "0":
if i + x < n:
l[i + x] = "0"
if i - x >= 0:
l[i - x] = "0"
for i in range(n):
if l[i] == -1:
l[i] = "1"
t = 1
for i in range(n):
c = 0
if s[i] == "1":
if i + x < n:
if l[i + x] != "0":
c += 1
if i - x >= 0:
if l[i - x] != "0":
c += 1
if c == 0:
t = 0
break
if t:
print("".join(l))
else:
print(-1) | FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR IF VAR VAR STRING IF BIN_OP VAR VAR VAR ASSIGN VAR BIN_OP VAR VAR STRING IF BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP VAR VAR STRING FOR VAR FUNC_CALL VAR VAR IF VAR VAR NUMBER ASSIGN VAR VAR STRING ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER IF VAR VAR STRING IF BIN_OP VAR VAR VAR IF VAR BIN_OP VAR VAR STRING VAR NUMBER IF BIN_OP VAR VAR NUMBER IF VAR BIN_OP VAR VAR STRING VAR NUMBER IF VAR NUMBER ASSIGN VAR NUMBER IF VAR EXPR FUNC_CALL VAR FUNC_CALL STRING VAR EXPR FUNC_CALL VAR NUMBER |
Consider the following process. You have a binary string (a string where each character is either 0 or 1) $w$ of length $n$ and an integer $x$. You build a new binary string $s$ consisting of $n$ characters. The $i$-th character of $s$ is chosen as follows:
if the character $w_{i-x}$ exists and is equal to 1, then $s_i$ is 1 (formally, if $i > x$ and $w_{i-x} = $ 1, then $s_i = $ 1); if the character $w_{i+x}$ exists and is equal to 1, then $s_i$ is 1 (formally, if $i + x \le n$ and $w_{i+x} = $ 1, then $s_i = $ 1); if both of the aforementioned conditions are false, then $s_i$ is 0.
You are given the integer $x$ and the resulting string $s$. Reconstruct the original string $w$.
-----Input-----
The first line contains one integer $t$ ($1 \le t \le 1000$) β the number of test cases.
Each test case consists of two lines. The first line contains the resulting string $s$ ($2 \le |s| \le 10^5$, each character of $s$ is either 0 or 1). The second line contains one integer $x$ ($1 \le x \le |s| - 1$).
The total length of all strings $s$ in the input does not exceed $10^5$.
-----Output-----
For each test case, print the answer on a separate line as follows:
if no string $w$ can produce the string $s$ at the end of the process, print $-1$; otherwise, print the binary string $w$ consisting of $|s|$ characters. If there are multiple answers, print any of them.
-----Example-----
Input
3
101110
2
01
1
110
1
Output
111011
10
-1 | def stringmaker(string1, x):
finder = ["1"] * len(string1)
output = ""
for i in range(len(string1)):
if string1[i] == "0":
if i - x >= 0:
finder[i - x] = "0"
if i + x < len(string1):
finder[i + x] = "0"
for i in range(len(string1)):
flag = 0
output += finder[i]
if string1[i] == "1":
if i - x >= 0:
if finder[i - x] == "0":
flag += 1
else:
flag += 1
if i + x < len(string1):
if finder[i + x] == "0":
flag += 1
else:
flag += 1
if flag == 2:
return -1
return output
for i in range(int(input())):
string1 = str(input())
x = int(input())
output = stringmaker(string1, x)
print(output) | FUNC_DEF ASSIGN VAR BIN_OP LIST STRING FUNC_CALL VAR VAR ASSIGN VAR STRING FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR STRING IF BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP VAR VAR STRING IF BIN_OP VAR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR VAR STRING FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER VAR VAR VAR IF VAR VAR STRING IF BIN_OP VAR VAR NUMBER IF VAR BIN_OP VAR VAR STRING VAR NUMBER VAR NUMBER IF BIN_OP VAR VAR FUNC_CALL VAR VAR IF VAR BIN_OP VAR VAR STRING VAR NUMBER VAR NUMBER IF VAR NUMBER RETURN NUMBER RETURN VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR |
Consider the following process. You have a binary string (a string where each character is either 0 or 1) $w$ of length $n$ and an integer $x$. You build a new binary string $s$ consisting of $n$ characters. The $i$-th character of $s$ is chosen as follows:
if the character $w_{i-x}$ exists and is equal to 1, then $s_i$ is 1 (formally, if $i > x$ and $w_{i-x} = $ 1, then $s_i = $ 1); if the character $w_{i+x}$ exists and is equal to 1, then $s_i$ is 1 (formally, if $i + x \le n$ and $w_{i+x} = $ 1, then $s_i = $ 1); if both of the aforementioned conditions are false, then $s_i$ is 0.
You are given the integer $x$ and the resulting string $s$. Reconstruct the original string $w$.
-----Input-----
The first line contains one integer $t$ ($1 \le t \le 1000$) β the number of test cases.
Each test case consists of two lines. The first line contains the resulting string $s$ ($2 \le |s| \le 10^5$, each character of $s$ is either 0 or 1). The second line contains one integer $x$ ($1 \le x \le |s| - 1$).
The total length of all strings $s$ in the input does not exceed $10^5$.
-----Output-----
For each test case, print the answer on a separate line as follows:
if no string $w$ can produce the string $s$ at the end of the process, print $-1$; otherwise, print the binary string $w$ consisting of $|s|$ characters. If there are multiple answers, print any of them.
-----Example-----
Input
3
101110
2
01
1
110
1
Output
111011
10
-1 | import sys
input = sys.stdin.readline
t = int(input())
for i in range(t):
s = [i for i in input() if i != "\n"]
x = int(input())
ans = [1] * len(s)
for i in range(len(s)):
if s[i] == "0":
if i >= x:
ans[i - x] = 0
if i + x < len(s):
ans[i + x] = 0
ok = False
for i in range(len(s)):
if s[i] == "1":
ok1, ok2 = False, False
if i >= x:
if ans[i - x] == 1:
ok1 = True
if i + x < len(s):
if ans[i + x] == 1:
ok2 = True
if not ok1 and not ok2:
print(-1)
ok = True
break
if not ok:
ans = "".join(map(str, ans))
sys.stdout.write(ans + "\n") | IMPORT ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR FUNC_CALL VAR VAR STRING ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR STRING IF VAR VAR ASSIGN VAR BIN_OP VAR VAR NUMBER IF BIN_OP VAR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR STRING ASSIGN VAR VAR NUMBER NUMBER IF VAR VAR IF VAR BIN_OP VAR VAR NUMBER ASSIGN VAR NUMBER IF BIN_OP VAR VAR FUNC_CALL VAR VAR IF VAR BIN_OP VAR VAR NUMBER ASSIGN VAR NUMBER IF VAR VAR EXPR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER IF VAR ASSIGN VAR FUNC_CALL STRING FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR STRING |
Consider the following process. You have a binary string (a string where each character is either 0 or 1) $w$ of length $n$ and an integer $x$. You build a new binary string $s$ consisting of $n$ characters. The $i$-th character of $s$ is chosen as follows:
if the character $w_{i-x}$ exists and is equal to 1, then $s_i$ is 1 (formally, if $i > x$ and $w_{i-x} = $ 1, then $s_i = $ 1); if the character $w_{i+x}$ exists and is equal to 1, then $s_i$ is 1 (formally, if $i + x \le n$ and $w_{i+x} = $ 1, then $s_i = $ 1); if both of the aforementioned conditions are false, then $s_i$ is 0.
You are given the integer $x$ and the resulting string $s$. Reconstruct the original string $w$.
-----Input-----
The first line contains one integer $t$ ($1 \le t \le 1000$) β the number of test cases.
Each test case consists of two lines. The first line contains the resulting string $s$ ($2 \le |s| \le 10^5$, each character of $s$ is either 0 or 1). The second line contains one integer $x$ ($1 \le x \le |s| - 1$).
The total length of all strings $s$ in the input does not exceed $10^5$.
-----Output-----
For each test case, print the answer on a separate line as follows:
if no string $w$ can produce the string $s$ at the end of the process, print $-1$; otherwise, print the binary string $w$ consisting of $|s|$ characters. If there are multiple answers, print any of them.
-----Example-----
Input
3
101110
2
01
1
110
1
Output
111011
10
-1 | from sys import stdout
def function(inp, x):
output = []
n = len(inp)
for i in range(n):
pre_in = 0
if i > 2 * x - 1:
pre_in = inp[i - 2 * x]
post_in = 0
if i < n - 2 * x:
post_in = inp[i + 2 * x]
if (
inp[i] == "1"
and (pre_in == "0" or i - x < 0)
and (post_in == "0" or i + x >= n)
):
return "-1"
pre_in = None
if i > x - 1:
pre_in = inp[i - x]
post_in = None
if i < n - x:
post_in = inp[i + x]
if pre_in == "0" or post_in == "0":
output.append("0")
else:
output.append("1")
return "".join(output)
total = int(input())
inp = None
for index in range(2 * total):
line = input()
if index % 2 == 0:
inp = line
else:
x = int(line)
result = function(inp, x)
print(result)
stdout.flush() | FUNC_DEF ASSIGN VAR LIST ASSIGN VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER IF VAR BIN_OP BIN_OP NUMBER VAR NUMBER ASSIGN VAR VAR BIN_OP VAR BIN_OP NUMBER VAR ASSIGN VAR NUMBER IF VAR BIN_OP VAR BIN_OP NUMBER VAR ASSIGN VAR VAR BIN_OP VAR BIN_OP NUMBER VAR IF VAR VAR STRING VAR STRING BIN_OP VAR VAR NUMBER VAR STRING BIN_OP VAR VAR VAR RETURN STRING ASSIGN VAR NONE IF VAR BIN_OP VAR NUMBER ASSIGN VAR VAR BIN_OP VAR VAR ASSIGN VAR NONE IF VAR BIN_OP VAR VAR ASSIGN VAR VAR BIN_OP VAR VAR IF VAR STRING VAR STRING EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING RETURN FUNC_CALL STRING VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR NONE FOR VAR FUNC_CALL VAR BIN_OP NUMBER VAR ASSIGN VAR FUNC_CALL VAR IF BIN_OP VAR NUMBER NUMBER ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR |
Consider the following process. You have a binary string (a string where each character is either 0 or 1) $w$ of length $n$ and an integer $x$. You build a new binary string $s$ consisting of $n$ characters. The $i$-th character of $s$ is chosen as follows:
if the character $w_{i-x}$ exists and is equal to 1, then $s_i$ is 1 (formally, if $i > x$ and $w_{i-x} = $ 1, then $s_i = $ 1); if the character $w_{i+x}$ exists and is equal to 1, then $s_i$ is 1 (formally, if $i + x \le n$ and $w_{i+x} = $ 1, then $s_i = $ 1); if both of the aforementioned conditions are false, then $s_i$ is 0.
You are given the integer $x$ and the resulting string $s$. Reconstruct the original string $w$.
-----Input-----
The first line contains one integer $t$ ($1 \le t \le 1000$) β the number of test cases.
Each test case consists of two lines. The first line contains the resulting string $s$ ($2 \le |s| \le 10^5$, each character of $s$ is either 0 or 1). The second line contains one integer $x$ ($1 \le x \le |s| - 1$).
The total length of all strings $s$ in the input does not exceed $10^5$.
-----Output-----
For each test case, print the answer on a separate line as follows:
if no string $w$ can produce the string $s$ at the end of the process, print $-1$; otherwise, print the binary string $w$ consisting of $|s|$ characters. If there are multiple answers, print any of them.
-----Example-----
Input
3
101110
2
01
1
110
1
Output
111011
10
-1 | t = int(input())
while t > 0:
t -= 1
s = str(input())
x = int(input())
S = set()
for i in range(0, len(s)):
if s[i] == "0":
S.add(i + x)
S.add(i - x)
indicator = 0
for i in range(0, len(s)):
if s[i] == "1":
c = 0
if i - x >= 0 and i - x not in S:
c += 1
if i + x < len(s) and i + x not in S:
c += 1
if c == 0:
indicator = 1
if indicator == 0:
for i in range(0, len(s)):
if i in S:
print("0", end="")
else:
print("1", end="")
print("")
else:
print(-1) | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR WHILE VAR NUMBER VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR IF VAR VAR STRING EXPR FUNC_CALL VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR IF VAR VAR STRING ASSIGN VAR NUMBER IF BIN_OP VAR VAR NUMBER BIN_OP VAR VAR VAR VAR NUMBER IF BIN_OP VAR VAR FUNC_CALL VAR VAR BIN_OP VAR VAR VAR VAR NUMBER IF VAR NUMBER ASSIGN VAR NUMBER IF VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR IF VAR VAR EXPR FUNC_CALL VAR STRING STRING EXPR FUNC_CALL VAR STRING STRING EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR NUMBER |
Consider the following process. You have a binary string (a string where each character is either 0 or 1) $w$ of length $n$ and an integer $x$. You build a new binary string $s$ consisting of $n$ characters. The $i$-th character of $s$ is chosen as follows:
if the character $w_{i-x}$ exists and is equal to 1, then $s_i$ is 1 (formally, if $i > x$ and $w_{i-x} = $ 1, then $s_i = $ 1); if the character $w_{i+x}$ exists and is equal to 1, then $s_i$ is 1 (formally, if $i + x \le n$ and $w_{i+x} = $ 1, then $s_i = $ 1); if both of the aforementioned conditions are false, then $s_i$ is 0.
You are given the integer $x$ and the resulting string $s$. Reconstruct the original string $w$.
-----Input-----
The first line contains one integer $t$ ($1 \le t \le 1000$) β the number of test cases.
Each test case consists of two lines. The first line contains the resulting string $s$ ($2 \le |s| \le 10^5$, each character of $s$ is either 0 or 1). The second line contains one integer $x$ ($1 \le x \le |s| - 1$).
The total length of all strings $s$ in the input does not exceed $10^5$.
-----Output-----
For each test case, print the answer on a separate line as follows:
if no string $w$ can produce the string $s$ at the end of the process, print $-1$; otherwise, print the binary string $w$ consisting of $|s|$ characters. If there are multiple answers, print any of them.
-----Example-----
Input
3
101110
2
01
1
110
1
Output
111011
10
-1 | t = int(input())
for _ in range(t):
s = input()
n = len(s)
x = int(input())
w = [0] * n
for i in range(n):
if 0 <= i + x < n and 0 <= i - x < n:
if s[i + x] == "1" and s[i - x] == "1":
w[i] = 1
elif 0 <= i + x < n:
if s[i + x] == "1":
w[i] = 1
elif 0 <= i - x < n:
if s[i - x] == "1":
w[i] = 1
for i in range(n):
if 0 <= i - x < n and w[i - x] == 1:
if s[i] == "1":
continue
else:
print(-1)
break
if 0 <= i + x < n and w[i + x] == 1:
if s[i] == "1":
continue
else:
print(-1)
break
if s[i] == "1":
print(-1)
break
else:
print(*w, sep="") | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER VAR FOR VAR FUNC_CALL VAR VAR IF NUMBER BIN_OP VAR VAR VAR NUMBER BIN_OP VAR VAR VAR IF VAR BIN_OP VAR VAR STRING VAR BIN_OP VAR VAR STRING ASSIGN VAR VAR NUMBER IF NUMBER BIN_OP VAR VAR VAR IF VAR BIN_OP VAR VAR STRING ASSIGN VAR VAR NUMBER IF NUMBER BIN_OP VAR VAR VAR IF VAR BIN_OP VAR VAR STRING ASSIGN VAR VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF NUMBER BIN_OP VAR VAR VAR VAR BIN_OP VAR VAR NUMBER IF VAR VAR STRING EXPR FUNC_CALL VAR NUMBER IF NUMBER BIN_OP VAR VAR VAR VAR BIN_OP VAR VAR NUMBER IF VAR VAR STRING EXPR FUNC_CALL VAR NUMBER IF VAR VAR STRING EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR VAR STRING |
Consider the following process. You have a binary string (a string where each character is either 0 or 1) $w$ of length $n$ and an integer $x$. You build a new binary string $s$ consisting of $n$ characters. The $i$-th character of $s$ is chosen as follows:
if the character $w_{i-x}$ exists and is equal to 1, then $s_i$ is 1 (formally, if $i > x$ and $w_{i-x} = $ 1, then $s_i = $ 1); if the character $w_{i+x}$ exists and is equal to 1, then $s_i$ is 1 (formally, if $i + x \le n$ and $w_{i+x} = $ 1, then $s_i = $ 1); if both of the aforementioned conditions are false, then $s_i$ is 0.
You are given the integer $x$ and the resulting string $s$. Reconstruct the original string $w$.
-----Input-----
The first line contains one integer $t$ ($1 \le t \le 1000$) β the number of test cases.
Each test case consists of two lines. The first line contains the resulting string $s$ ($2 \le |s| \le 10^5$, each character of $s$ is either 0 or 1). The second line contains one integer $x$ ($1 \le x \le |s| - 1$).
The total length of all strings $s$ in the input does not exceed $10^5$.
-----Output-----
For each test case, print the answer on a separate line as follows:
if no string $w$ can produce the string $s$ at the end of the process, print $-1$; otherwise, print the binary string $w$ consisting of $|s|$ characters. If there are multiple answers, print any of them.
-----Example-----
Input
3
101110
2
01
1
110
1
Output
111011
10
-1 | for _ in range(int(input())):
s, x = list(map(int, input())), int(input())
n = len(s)
new = [1] * n
for i in range(n):
if s[i] == 0:
if i >= x:
new[i - x] = 0
if i + x < n:
new[i + x] = 0
w = []
for i in range(n):
temp = 0
if i >= x:
if new[i - x] == 1:
temp = 1
if i + x < n:
if new[i + x] == 1:
temp = 1
w.append(temp)
if w != s:
print(-1)
else:
print("".join(map(str, new))) | FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP LIST NUMBER VAR FOR VAR FUNC_CALL VAR VAR IF VAR VAR NUMBER IF VAR VAR ASSIGN VAR BIN_OP VAR VAR NUMBER IF BIN_OP VAR VAR VAR ASSIGN VAR BIN_OP VAR VAR NUMBER ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER IF VAR VAR IF VAR BIN_OP VAR VAR NUMBER ASSIGN VAR NUMBER IF BIN_OP VAR VAR VAR IF VAR BIN_OP VAR VAR NUMBER ASSIGN VAR NUMBER EXPR FUNC_CALL VAR VAR IF VAR VAR EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL STRING FUNC_CALL VAR VAR VAR |
Consider the following process. You have a binary string (a string where each character is either 0 or 1) $w$ of length $n$ and an integer $x$. You build a new binary string $s$ consisting of $n$ characters. The $i$-th character of $s$ is chosen as follows:
if the character $w_{i-x}$ exists and is equal to 1, then $s_i$ is 1 (formally, if $i > x$ and $w_{i-x} = $ 1, then $s_i = $ 1); if the character $w_{i+x}$ exists and is equal to 1, then $s_i$ is 1 (formally, if $i + x \le n$ and $w_{i+x} = $ 1, then $s_i = $ 1); if both of the aforementioned conditions are false, then $s_i$ is 0.
You are given the integer $x$ and the resulting string $s$. Reconstruct the original string $w$.
-----Input-----
The first line contains one integer $t$ ($1 \le t \le 1000$) β the number of test cases.
Each test case consists of two lines. The first line contains the resulting string $s$ ($2 \le |s| \le 10^5$, each character of $s$ is either 0 or 1). The second line contains one integer $x$ ($1 \le x \le |s| - 1$).
The total length of all strings $s$ in the input does not exceed $10^5$.
-----Output-----
For each test case, print the answer on a separate line as follows:
if no string $w$ can produce the string $s$ at the end of the process, print $-1$; otherwise, print the binary string $w$ consisting of $|s|$ characters. If there are multiple answers, print any of them.
-----Example-----
Input
3
101110
2
01
1
110
1
Output
111011
10
-1 | for _ in range(int(input())):
s = input()
x = int(input())
n = len(s)
flag = False
arr = ["1"] * n
for i in range(n):
if s[i] == "0":
if i + x < n:
arr[i + x] = "0"
if i - x >= 0:
arr[i - x] = "0"
for i in range(n):
if s[i] == "1":
if i + x < n and i - x < 0:
if arr[i + x] == "0":
flag = True
break
elif i - x >= 0 and i + x >= n:
if arr[i - x] == "0":
flag = True
break
elif i + x < n and i - x >= 0:
if arr[i - x] == "0" and arr[i + x] == "0":
flag = True
break
else:
flag = True
break
if flag:
print(-1)
continue
ans = ""
for i in arr:
ans += i
print(ans) | FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR BIN_OP LIST STRING VAR FOR VAR FUNC_CALL VAR VAR IF VAR VAR STRING IF BIN_OP VAR VAR VAR ASSIGN VAR BIN_OP VAR VAR STRING IF BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP VAR VAR STRING FOR VAR FUNC_CALL VAR VAR IF VAR VAR STRING IF BIN_OP VAR VAR VAR BIN_OP VAR VAR NUMBER IF VAR BIN_OP VAR VAR STRING ASSIGN VAR NUMBER IF BIN_OP VAR VAR NUMBER BIN_OP VAR VAR VAR IF VAR BIN_OP VAR VAR STRING ASSIGN VAR NUMBER IF BIN_OP VAR VAR VAR BIN_OP VAR VAR NUMBER IF VAR BIN_OP VAR VAR STRING VAR BIN_OP VAR VAR STRING ASSIGN VAR NUMBER ASSIGN VAR NUMBER IF VAR EXPR FUNC_CALL VAR NUMBER ASSIGN VAR STRING FOR VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR |
Consider the following process. You have a binary string (a string where each character is either 0 or 1) $w$ of length $n$ and an integer $x$. You build a new binary string $s$ consisting of $n$ characters. The $i$-th character of $s$ is chosen as follows:
if the character $w_{i-x}$ exists and is equal to 1, then $s_i$ is 1 (formally, if $i > x$ and $w_{i-x} = $ 1, then $s_i = $ 1); if the character $w_{i+x}$ exists and is equal to 1, then $s_i$ is 1 (formally, if $i + x \le n$ and $w_{i+x} = $ 1, then $s_i = $ 1); if both of the aforementioned conditions are false, then $s_i$ is 0.
You are given the integer $x$ and the resulting string $s$. Reconstruct the original string $w$.
-----Input-----
The first line contains one integer $t$ ($1 \le t \le 1000$) β the number of test cases.
Each test case consists of two lines. The first line contains the resulting string $s$ ($2 \le |s| \le 10^5$, each character of $s$ is either 0 or 1). The second line contains one integer $x$ ($1 \le x \le |s| - 1$).
The total length of all strings $s$ in the input does not exceed $10^5$.
-----Output-----
For each test case, print the answer on a separate line as follows:
if no string $w$ can produce the string $s$ at the end of the process, print $-1$; otherwise, print the binary string $w$ consisting of $|s|$ characters. If there are multiple answers, print any of them.
-----Example-----
Input
3
101110
2
01
1
110
1
Output
111011
10
-1 | t = int(input())
for _ in range(t):
s = [int(c) for c in input()]
n = len(s)
x = int(input())
w = [None] * n
bad = False
for i in range(0, x):
if i + x >= n:
if s[i] != 0:
print(-1)
bad = True
break
else:
w[i + x] = s[i]
if bad:
continue
for i in range(n - x, n):
if i - x < 0:
if s[i] != 0:
print(-1)
bad = True
break
else:
if w[i - x] is not None and w[i - x] != s[i]:
print(-1)
bad = True
break
w[i - x] = s[i]
if bad:
continue
for i in range(x, n - x):
if s[i] == 0:
if w[i - x] == 1 or w[i + x] == 1:
print(-1)
bad = True
break
w[i - x] = 0
w[i + x] = 0
if bad:
continue
for i in range(x, n - x):
if s[i] == 1:
if w[i - x] == 0 and w[i + x] == 0:
print(-1)
bad = True
break
if w[i - x] is None:
w[i - x] = 1
if w[i + x] is None:
w[i + x] = 1
if bad:
continue
print("".join(str(int(bool(c))) for c in w)) | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NONE VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR IF BIN_OP VAR VAR VAR IF VAR VAR NUMBER EXPR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR BIN_OP VAR VAR VAR VAR IF VAR FOR VAR FUNC_CALL VAR BIN_OP VAR VAR VAR IF BIN_OP VAR VAR NUMBER IF VAR VAR NUMBER EXPR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER IF VAR BIN_OP VAR VAR NONE VAR BIN_OP VAR VAR VAR VAR EXPR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR BIN_OP VAR VAR VAR VAR IF VAR FOR VAR FUNC_CALL VAR VAR BIN_OP VAR VAR IF VAR VAR NUMBER IF VAR BIN_OP VAR VAR NUMBER VAR BIN_OP VAR VAR NUMBER EXPR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP VAR VAR NUMBER IF VAR FOR VAR FUNC_CALL VAR VAR BIN_OP VAR VAR IF VAR VAR NUMBER IF VAR BIN_OP VAR VAR NUMBER VAR BIN_OP VAR VAR NUMBER EXPR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER IF VAR BIN_OP VAR VAR NONE ASSIGN VAR BIN_OP VAR VAR NUMBER IF VAR BIN_OP VAR VAR NONE ASSIGN VAR BIN_OP VAR VAR NUMBER IF VAR EXPR FUNC_CALL VAR FUNC_CALL STRING FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR VAR |
Consider the following process. You have a binary string (a string where each character is either 0 or 1) $w$ of length $n$ and an integer $x$. You build a new binary string $s$ consisting of $n$ characters. The $i$-th character of $s$ is chosen as follows:
if the character $w_{i-x}$ exists and is equal to 1, then $s_i$ is 1 (formally, if $i > x$ and $w_{i-x} = $ 1, then $s_i = $ 1); if the character $w_{i+x}$ exists and is equal to 1, then $s_i$ is 1 (formally, if $i + x \le n$ and $w_{i+x} = $ 1, then $s_i = $ 1); if both of the aforementioned conditions are false, then $s_i$ is 0.
You are given the integer $x$ and the resulting string $s$. Reconstruct the original string $w$.
-----Input-----
The first line contains one integer $t$ ($1 \le t \le 1000$) β the number of test cases.
Each test case consists of two lines. The first line contains the resulting string $s$ ($2 \le |s| \le 10^5$, each character of $s$ is either 0 or 1). The second line contains one integer $x$ ($1 \le x \le |s| - 1$).
The total length of all strings $s$ in the input does not exceed $10^5$.
-----Output-----
For each test case, print the answer on a separate line as follows:
if no string $w$ can produce the string $s$ at the end of the process, print $-1$; otherwise, print the binary string $w$ consisting of $|s|$ characters. If there are multiple answers, print any of them.
-----Example-----
Input
3
101110
2
01
1
110
1
Output
111011
10
-1 | from sys import gettrace, stdin
if gettrace():
inputi = input
else:
def input():
return next(stdin)[:-1]
def inputi():
return stdin.buffer.readline()
def solve():
ss = input()
n = len(ss)
x = int(input())
res = ["0"] * n
for i in range(n):
if (i - x < 0 or ss[i - x] == "1") and (i + x >= n or ss[i + x] == "1"):
res[i] = "1"
for i in range(n):
if (
ss[i] == "1"
and (i - x < 0 or res[i - x] == "0")
and (i + x >= n or res[i + x] == "0")
):
print(-1)
return
print("".join(res))
def main():
t = int(input())
for _ in range(t):
solve()
main() | IF FUNC_CALL VAR ASSIGN VAR VAR FUNC_DEF RETURN FUNC_CALL VAR VAR NUMBER FUNC_DEF RETURN FUNC_CALL VAR FUNC_DEF ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR BIN_OP LIST STRING VAR FOR VAR FUNC_CALL VAR VAR IF BIN_OP VAR VAR NUMBER VAR BIN_OP VAR VAR STRING BIN_OP VAR VAR VAR VAR BIN_OP VAR VAR STRING ASSIGN VAR VAR STRING FOR VAR FUNC_CALL VAR VAR IF VAR VAR STRING BIN_OP VAR VAR NUMBER VAR BIN_OP VAR VAR STRING BIN_OP VAR VAR VAR VAR BIN_OP VAR VAR STRING EXPR FUNC_CALL VAR NUMBER RETURN EXPR FUNC_CALL VAR FUNC_CALL STRING VAR FUNC_DEF ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR |
Consider the following process. You have a binary string (a string where each character is either 0 or 1) $w$ of length $n$ and an integer $x$. You build a new binary string $s$ consisting of $n$ characters. The $i$-th character of $s$ is chosen as follows:
if the character $w_{i-x}$ exists and is equal to 1, then $s_i$ is 1 (formally, if $i > x$ and $w_{i-x} = $ 1, then $s_i = $ 1); if the character $w_{i+x}$ exists and is equal to 1, then $s_i$ is 1 (formally, if $i + x \le n$ and $w_{i+x} = $ 1, then $s_i = $ 1); if both of the aforementioned conditions are false, then $s_i$ is 0.
You are given the integer $x$ and the resulting string $s$. Reconstruct the original string $w$.
-----Input-----
The first line contains one integer $t$ ($1 \le t \le 1000$) β the number of test cases.
Each test case consists of two lines. The first line contains the resulting string $s$ ($2 \le |s| \le 10^5$, each character of $s$ is either 0 or 1). The second line contains one integer $x$ ($1 \le x \le |s| - 1$).
The total length of all strings $s$ in the input does not exceed $10^5$.
-----Output-----
For each test case, print the answer on a separate line as follows:
if no string $w$ can produce the string $s$ at the end of the process, print $-1$; otherwise, print the binary string $w$ consisting of $|s|$ characters. If there are multiple answers, print any of them.
-----Example-----
Input
3
101110
2
01
1
110
1
Output
111011
10
-1 | for test in range(int(input())):
s = input().strip()
x = int(input())
w = [" "] * len(s)
for id, val in enumerate(s):
if val == "1":
continue
if id - x >= 0:
w[id - x] = "0"
if id + x < len(s):
w[id + x] = "0"
for id, val in enumerate(s):
if val == "0":
continue
if (id - x < 0 or w[id - x] == "0") and (id + x >= len(s) or w[id + x] == "0"):
w = ["-", "1"]
break
if id - x >= 0 and w[id - x] == " ":
w[id - x] = "1"
if id + x < len(s) and w[id + x] == " ":
w[id + x] = "1"
for i in range(len(w)):
if w[i] == " ":
w[i] = "1"
print("".join(w)) | FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR BIN_OP LIST STRING FUNC_CALL VAR VAR FOR VAR VAR FUNC_CALL VAR VAR IF VAR STRING IF BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP VAR VAR STRING IF BIN_OP VAR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR VAR STRING FOR VAR VAR FUNC_CALL VAR VAR IF VAR STRING IF BIN_OP VAR VAR NUMBER VAR BIN_OP VAR VAR STRING BIN_OP VAR VAR FUNC_CALL VAR VAR VAR BIN_OP VAR VAR STRING ASSIGN VAR LIST STRING STRING IF BIN_OP VAR VAR NUMBER VAR BIN_OP VAR VAR STRING ASSIGN VAR BIN_OP VAR VAR STRING IF BIN_OP VAR VAR FUNC_CALL VAR VAR VAR BIN_OP VAR VAR STRING ASSIGN VAR BIN_OP VAR VAR STRING FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR STRING ASSIGN VAR VAR STRING EXPR FUNC_CALL VAR FUNC_CALL STRING VAR |
Consider the following process. You have a binary string (a string where each character is either 0 or 1) $w$ of length $n$ and an integer $x$. You build a new binary string $s$ consisting of $n$ characters. The $i$-th character of $s$ is chosen as follows:
if the character $w_{i-x}$ exists and is equal to 1, then $s_i$ is 1 (formally, if $i > x$ and $w_{i-x} = $ 1, then $s_i = $ 1); if the character $w_{i+x}$ exists and is equal to 1, then $s_i$ is 1 (formally, if $i + x \le n$ and $w_{i+x} = $ 1, then $s_i = $ 1); if both of the aforementioned conditions are false, then $s_i$ is 0.
You are given the integer $x$ and the resulting string $s$. Reconstruct the original string $w$.
-----Input-----
The first line contains one integer $t$ ($1 \le t \le 1000$) β the number of test cases.
Each test case consists of two lines. The first line contains the resulting string $s$ ($2 \le |s| \le 10^5$, each character of $s$ is either 0 or 1). The second line contains one integer $x$ ($1 \le x \le |s| - 1$).
The total length of all strings $s$ in the input does not exceed $10^5$.
-----Output-----
For each test case, print the answer on a separate line as follows:
if no string $w$ can produce the string $s$ at the end of the process, print $-1$; otherwise, print the binary string $w$ consisting of $|s|$ characters. If there are multiple answers, print any of them.
-----Example-----
Input
3
101110
2
01
1
110
1
Output
111011
10
-1 | n = int(input())
for i in range(n):
s = input()
t = int(input())
w = ["1"] * len(s)
flag = True
for i in range(len(s)):
if s[i] == "0":
if i - t > -1:
w[i - t] = "0"
if i + t < len(s):
w[i + t] = "0"
for i in range(len(s)):
if s[i] == "1":
if i - t > -1 and w[i - t] == "1" or i + t < len(s) and w[i + t] == "1":
continue
else:
print(-1)
flag = False
break
elif i - t > -1 and w[i - t] == "1" or i + t < len(s) and w[i + t] == "1":
print(-1)
flag = False
break
if flag:
print("".join(w)) | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR BIN_OP LIST STRING FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR STRING IF BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP VAR VAR STRING IF BIN_OP VAR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR VAR STRING FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR STRING IF BIN_OP VAR VAR NUMBER VAR BIN_OP VAR VAR STRING BIN_OP VAR VAR FUNC_CALL VAR VAR VAR BIN_OP VAR VAR STRING EXPR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER IF BIN_OP VAR VAR NUMBER VAR BIN_OP VAR VAR STRING BIN_OP VAR VAR FUNC_CALL VAR VAR VAR BIN_OP VAR VAR STRING EXPR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER IF VAR EXPR FUNC_CALL VAR FUNC_CALL STRING VAR |
Consider the following process. You have a binary string (a string where each character is either 0 or 1) $w$ of length $n$ and an integer $x$. You build a new binary string $s$ consisting of $n$ characters. The $i$-th character of $s$ is chosen as follows:
if the character $w_{i-x}$ exists and is equal to 1, then $s_i$ is 1 (formally, if $i > x$ and $w_{i-x} = $ 1, then $s_i = $ 1); if the character $w_{i+x}$ exists and is equal to 1, then $s_i$ is 1 (formally, if $i + x \le n$ and $w_{i+x} = $ 1, then $s_i = $ 1); if both of the aforementioned conditions are false, then $s_i$ is 0.
You are given the integer $x$ and the resulting string $s$. Reconstruct the original string $w$.
-----Input-----
The first line contains one integer $t$ ($1 \le t \le 1000$) β the number of test cases.
Each test case consists of two lines. The first line contains the resulting string $s$ ($2 \le |s| \le 10^5$, each character of $s$ is either 0 or 1). The second line contains one integer $x$ ($1 \le x \le |s| - 1$).
The total length of all strings $s$ in the input does not exceed $10^5$.
-----Output-----
For each test case, print the answer on a separate line as follows:
if no string $w$ can produce the string $s$ at the end of the process, print $-1$; otherwise, print the binary string $w$ consisting of $|s|$ characters. If there are multiple answers, print any of them.
-----Example-----
Input
3
101110
2
01
1
110
1
Output
111011
10
-1 | t = int(input())
for i in range(0, t):
s = input()
x = int(input())
n = len(s)
ans = ["1"] * n
for i in range(0, n):
if s[i] == "0":
if i + x < n:
ans[i + x] = "0"
if i - x >= 0:
ans[i - x] = "0"
check = ""
for i in range(0, n):
if i - x >= 0 and ans[i - x] == "1" or i + x < n and ans[i + x] == "1":
check += "1"
else:
check += "0"
if check == s:
print(*ans, sep="")
else:
print(-1) | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP LIST STRING VAR FOR VAR FUNC_CALL VAR NUMBER VAR IF VAR VAR STRING IF BIN_OP VAR VAR VAR ASSIGN VAR BIN_OP VAR VAR STRING IF BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP VAR VAR STRING ASSIGN VAR STRING FOR VAR FUNC_CALL VAR NUMBER VAR IF BIN_OP VAR VAR NUMBER VAR BIN_OP VAR VAR STRING BIN_OP VAR VAR VAR VAR BIN_OP VAR VAR STRING VAR STRING VAR STRING IF VAR VAR EXPR FUNC_CALL VAR VAR STRING EXPR FUNC_CALL VAR NUMBER |
Consider the following process. You have a binary string (a string where each character is either 0 or 1) $w$ of length $n$ and an integer $x$. You build a new binary string $s$ consisting of $n$ characters. The $i$-th character of $s$ is chosen as follows:
if the character $w_{i-x}$ exists and is equal to 1, then $s_i$ is 1 (formally, if $i > x$ and $w_{i-x} = $ 1, then $s_i = $ 1); if the character $w_{i+x}$ exists and is equal to 1, then $s_i$ is 1 (formally, if $i + x \le n$ and $w_{i+x} = $ 1, then $s_i = $ 1); if both of the aforementioned conditions are false, then $s_i$ is 0.
You are given the integer $x$ and the resulting string $s$. Reconstruct the original string $w$.
-----Input-----
The first line contains one integer $t$ ($1 \le t \le 1000$) β the number of test cases.
Each test case consists of two lines. The first line contains the resulting string $s$ ($2 \le |s| \le 10^5$, each character of $s$ is either 0 or 1). The second line contains one integer $x$ ($1 \le x \le |s| - 1$).
The total length of all strings $s$ in the input does not exceed $10^5$.
-----Output-----
For each test case, print the answer on a separate line as follows:
if no string $w$ can produce the string $s$ at the end of the process, print $-1$; otherwise, print the binary string $w$ consisting of $|s|$ characters. If there are multiple answers, print any of them.
-----Example-----
Input
3
101110
2
01
1
110
1
Output
111011
10
-1 | for nt in range(int(input())):
s = input()
n = len(s)
x = int(input())
ans = [""] * n
flag = 1
for i in range(n):
if s[i] == "0":
if i - x >= 0:
if ans[i - x] == "1":
flag = 0
break
ans[i - x] = "0"
if i + x < n:
if ans[i + x] == "1":
flag = 0
break
ans[i + x] = "0"
elif i - x >= 0:
if ans[i - x] == "0":
if i + x < n:
if ans[i + x] == "0":
flag = 0
break
else:
ans[i + x] = "1"
else:
flag = 0
break
else:
ans[i - x] = "1"
elif i + x < n:
if ans[i + x] == "0":
flag = 0
break
else:
ans[i + x] = "1"
else:
flag = 0
break
if flag:
for i in range(n):
if ans[i] == "":
ans[i] = "0"
print("".join(map(str, ans)))
else:
print(-1) | FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR BIN_OP LIST STRING VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR STRING IF BIN_OP VAR VAR NUMBER IF VAR BIN_OP VAR VAR STRING ASSIGN VAR NUMBER ASSIGN VAR BIN_OP VAR VAR STRING IF BIN_OP VAR VAR VAR IF VAR BIN_OP VAR VAR STRING ASSIGN VAR NUMBER ASSIGN VAR BIN_OP VAR VAR STRING IF BIN_OP VAR VAR NUMBER IF VAR BIN_OP VAR VAR STRING IF BIN_OP VAR VAR VAR IF VAR BIN_OP VAR VAR STRING ASSIGN VAR NUMBER ASSIGN VAR BIN_OP VAR VAR STRING ASSIGN VAR NUMBER ASSIGN VAR BIN_OP VAR VAR STRING IF BIN_OP VAR VAR VAR IF VAR BIN_OP VAR VAR STRING ASSIGN VAR NUMBER ASSIGN VAR BIN_OP VAR VAR STRING ASSIGN VAR NUMBER IF VAR FOR VAR FUNC_CALL VAR VAR IF VAR VAR STRING ASSIGN VAR VAR STRING EXPR FUNC_CALL VAR FUNC_CALL STRING FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR NUMBER |
Consider the following process. You have a binary string (a string where each character is either 0 or 1) $w$ of length $n$ and an integer $x$. You build a new binary string $s$ consisting of $n$ characters. The $i$-th character of $s$ is chosen as follows:
if the character $w_{i-x}$ exists and is equal to 1, then $s_i$ is 1 (formally, if $i > x$ and $w_{i-x} = $ 1, then $s_i = $ 1); if the character $w_{i+x}$ exists and is equal to 1, then $s_i$ is 1 (formally, if $i + x \le n$ and $w_{i+x} = $ 1, then $s_i = $ 1); if both of the aforementioned conditions are false, then $s_i$ is 0.
You are given the integer $x$ and the resulting string $s$. Reconstruct the original string $w$.
-----Input-----
The first line contains one integer $t$ ($1 \le t \le 1000$) β the number of test cases.
Each test case consists of two lines. The first line contains the resulting string $s$ ($2 \le |s| \le 10^5$, each character of $s$ is either 0 or 1). The second line contains one integer $x$ ($1 \le x \le |s| - 1$).
The total length of all strings $s$ in the input does not exceed $10^5$.
-----Output-----
For each test case, print the answer on a separate line as follows:
if no string $w$ can produce the string $s$ at the end of the process, print $-1$; otherwise, print the binary string $w$ consisting of $|s|$ characters. If there are multiple answers, print any of them.
-----Example-----
Input
3
101110
2
01
1
110
1
Output
111011
10
-1 | t = int(input())
while t:
t -= 1
s = input()
x = int(input())
n = len(s)
l = [-1] * n
d = set()
for i in range(n):
if s[i] == "0":
d.add(i)
for i in d:
if i - x > -1:
l[i - x] = 0
if i + x < n:
l[i + x] = 0
ans = True
for i in range(n):
if i not in d:
if i - x > -1:
if l[i - x] != 0:
l[i - x] = 1
continue
if i + x < n:
if l[i + x] != 0:
l[i + x] = 1
continue
ans = False
break
if not ans:
print(-1)
else:
ans = ""
for i in l:
if i == -1:
ans += "1"
else:
ans += str(i)
print(ans) | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR WHILE VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR IF VAR VAR STRING EXPR FUNC_CALL VAR VAR FOR VAR VAR IF BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP VAR VAR NUMBER IF BIN_OP VAR VAR VAR ASSIGN VAR BIN_OP VAR VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR IF BIN_OP VAR VAR NUMBER IF VAR BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP VAR VAR NUMBER IF BIN_OP VAR VAR VAR IF VAR BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP VAR VAR NUMBER ASSIGN VAR NUMBER IF VAR EXPR FUNC_CALL VAR NUMBER ASSIGN VAR STRING FOR VAR VAR IF VAR NUMBER VAR STRING VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR |
Consider the following process. You have a binary string (a string where each character is either 0 or 1) $w$ of length $n$ and an integer $x$. You build a new binary string $s$ consisting of $n$ characters. The $i$-th character of $s$ is chosen as follows:
if the character $w_{i-x}$ exists and is equal to 1, then $s_i$ is 1 (formally, if $i > x$ and $w_{i-x} = $ 1, then $s_i = $ 1); if the character $w_{i+x}$ exists and is equal to 1, then $s_i$ is 1 (formally, if $i + x \le n$ and $w_{i+x} = $ 1, then $s_i = $ 1); if both of the aforementioned conditions are false, then $s_i$ is 0.
You are given the integer $x$ and the resulting string $s$. Reconstruct the original string $w$.
-----Input-----
The first line contains one integer $t$ ($1 \le t \le 1000$) β the number of test cases.
Each test case consists of two lines. The first line contains the resulting string $s$ ($2 \le |s| \le 10^5$, each character of $s$ is either 0 or 1). The second line contains one integer $x$ ($1 \le x \le |s| - 1$).
The total length of all strings $s$ in the input does not exceed $10^5$.
-----Output-----
For each test case, print the answer on a separate line as follows:
if no string $w$ can produce the string $s$ at the end of the process, print $-1$; otherwise, print the binary string $w$ consisting of $|s|$ characters. If there are multiple answers, print any of them.
-----Example-----
Input
3
101110
2
01
1
110
1
Output
111011
10
-1 | t = int(input())
for i in range(t):
s = input()
x = int(input())
n = len(s)
w = ["1"] * n
for i in range(n):
if s[i] == "0":
if i + x < n:
w[i + x] = "0"
if i - x >= 0:
w[i - x] = "0"
for i in range(n):
t = i + x < n and w[i + x] == "1" or i - x >= 0 and w[i - x] == "1"
c = "0"
if t:
c = "1"
if s[i] != c:
print(-1)
break
else:
print("".join(w)) | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP LIST STRING VAR FOR VAR FUNC_CALL VAR VAR IF VAR VAR STRING IF BIN_OP VAR VAR VAR ASSIGN VAR BIN_OP VAR VAR STRING IF BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP VAR VAR STRING FOR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR VAR VAR VAR BIN_OP VAR VAR STRING BIN_OP VAR VAR NUMBER VAR BIN_OP VAR VAR STRING ASSIGN VAR STRING IF VAR ASSIGN VAR STRING IF VAR VAR VAR EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL STRING VAR |
Consider the following process. You have a binary string (a string where each character is either 0 or 1) $w$ of length $n$ and an integer $x$. You build a new binary string $s$ consisting of $n$ characters. The $i$-th character of $s$ is chosen as follows:
if the character $w_{i-x}$ exists and is equal to 1, then $s_i$ is 1 (formally, if $i > x$ and $w_{i-x} = $ 1, then $s_i = $ 1); if the character $w_{i+x}$ exists and is equal to 1, then $s_i$ is 1 (formally, if $i + x \le n$ and $w_{i+x} = $ 1, then $s_i = $ 1); if both of the aforementioned conditions are false, then $s_i$ is 0.
You are given the integer $x$ and the resulting string $s$. Reconstruct the original string $w$.
-----Input-----
The first line contains one integer $t$ ($1 \le t \le 1000$) β the number of test cases.
Each test case consists of two lines. The first line contains the resulting string $s$ ($2 \le |s| \le 10^5$, each character of $s$ is either 0 or 1). The second line contains one integer $x$ ($1 \le x \le |s| - 1$).
The total length of all strings $s$ in the input does not exceed $10^5$.
-----Output-----
For each test case, print the answer on a separate line as follows:
if no string $w$ can produce the string $s$ at the end of the process, print $-1$; otherwise, print the binary string $w$ consisting of $|s|$ characters. If there are multiple answers, print any of them.
-----Example-----
Input
3
101110
2
01
1
110
1
Output
111011
10
-1 | from sys import stdin, stdout
def find(S, X):
N = len(S)
K = [1] * N
for i in range(N):
if S[i] == 0:
if i - X >= 0:
K[i - X] = 0
if i + X < N:
K[i + X] = 0
for i in range(N):
if i >= X and K[i - X] == 1 or i + X < N and K[i + X] == 1:
if S[i] == 0:
return -1
elif S[i] == 1:
return -1
return "".join(map(str, K))
def main():
for _ in range(int(stdin.readline())):
S = list(map(int, list(stdin.readline().strip())))
N = int(stdin.readline())
print(find(S, N))
main() | FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP LIST NUMBER VAR FOR VAR FUNC_CALL VAR VAR IF VAR VAR NUMBER IF BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP VAR VAR NUMBER IF BIN_OP VAR VAR VAR ASSIGN VAR BIN_OP VAR VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR BIN_OP VAR VAR NUMBER BIN_OP VAR VAR VAR VAR BIN_OP VAR VAR NUMBER IF VAR VAR NUMBER RETURN NUMBER IF VAR VAR NUMBER RETURN NUMBER RETURN FUNC_CALL STRING FUNC_CALL VAR VAR VAR FUNC_DEF FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR |
Consider the following process. You have a binary string (a string where each character is either 0 or 1) $w$ of length $n$ and an integer $x$. You build a new binary string $s$ consisting of $n$ characters. The $i$-th character of $s$ is chosen as follows:
if the character $w_{i-x}$ exists and is equal to 1, then $s_i$ is 1 (formally, if $i > x$ and $w_{i-x} = $ 1, then $s_i = $ 1); if the character $w_{i+x}$ exists and is equal to 1, then $s_i$ is 1 (formally, if $i + x \le n$ and $w_{i+x} = $ 1, then $s_i = $ 1); if both of the aforementioned conditions are false, then $s_i$ is 0.
You are given the integer $x$ and the resulting string $s$. Reconstruct the original string $w$.
-----Input-----
The first line contains one integer $t$ ($1 \le t \le 1000$) β the number of test cases.
Each test case consists of two lines. The first line contains the resulting string $s$ ($2 \le |s| \le 10^5$, each character of $s$ is either 0 or 1). The second line contains one integer $x$ ($1 \le x \le |s| - 1$).
The total length of all strings $s$ in the input does not exceed $10^5$.
-----Output-----
For each test case, print the answer on a separate line as follows:
if no string $w$ can produce the string $s$ at the end of the process, print $-1$; otherwise, print the binary string $w$ consisting of $|s|$ characters. If there are multiple answers, print any of them.
-----Example-----
Input
3
101110
2
01
1
110
1
Output
111011
10
-1 | import sys
input = sys.stdin.readline
T = int(input())
for t in range(T):
s = input()[:-1]
x = int(input())
w = ["1"] * len(s)
for i, c in enumerate(s):
pi = i + 1
if c == "0":
if pi > x:
ppw = pi - x
w[ppw - 1] = "0"
if pi + x <= len(s):
ppw = pi + x
w[ppw - 1] = "0"
for i, c in enumerate(s):
pi = i + 1
if c == "1":
if pi > x:
ppw = pi - x
if w[ppw - 1] == "1":
continue
if pi + x <= len(s):
ppw = pi + x
if w[ppw - 1] == "1":
continue
print(-1)
break
else:
print("".join(w)) | IMPORT ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR BIN_OP LIST STRING FUNC_CALL VAR VAR FOR VAR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR NUMBER IF VAR STRING IF VAR VAR ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP VAR NUMBER STRING IF BIN_OP VAR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP VAR NUMBER STRING FOR VAR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR NUMBER IF VAR STRING IF VAR VAR ASSIGN VAR BIN_OP VAR VAR IF VAR BIN_OP VAR NUMBER STRING IF BIN_OP VAR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR VAR IF VAR BIN_OP VAR NUMBER STRING EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL STRING VAR |
Consider the following process. You have a binary string (a string where each character is either 0 or 1) $w$ of length $n$ and an integer $x$. You build a new binary string $s$ consisting of $n$ characters. The $i$-th character of $s$ is chosen as follows:
if the character $w_{i-x}$ exists and is equal to 1, then $s_i$ is 1 (formally, if $i > x$ and $w_{i-x} = $ 1, then $s_i = $ 1); if the character $w_{i+x}$ exists and is equal to 1, then $s_i$ is 1 (formally, if $i + x \le n$ and $w_{i+x} = $ 1, then $s_i = $ 1); if both of the aforementioned conditions are false, then $s_i$ is 0.
You are given the integer $x$ and the resulting string $s$. Reconstruct the original string $w$.
-----Input-----
The first line contains one integer $t$ ($1 \le t \le 1000$) β the number of test cases.
Each test case consists of two lines. The first line contains the resulting string $s$ ($2 \le |s| \le 10^5$, each character of $s$ is either 0 or 1). The second line contains one integer $x$ ($1 \le x \le |s| - 1$).
The total length of all strings $s$ in the input does not exceed $10^5$.
-----Output-----
For each test case, print the answer on a separate line as follows:
if no string $w$ can produce the string $s$ at the end of the process, print $-1$; otherwise, print the binary string $w$ consisting of $|s|$ characters. If there are multiple answers, print any of them.
-----Example-----
Input
3
101110
2
01
1
110
1
Output
111011
10
-1 | def solve():
s = input()
n = len(s)
x = int(input())
w = ["1" for i in range(n)]
for i in range(n):
if s[i] == "0":
if i >= x:
w[i - x] = "0"
if i < n - x:
w[i + x] = "0"
for i in range(n):
if i >= x and w[i - x] == "1" or i < n - x and w[i + x] == "1":
if s[i] == "0":
print(-1)
return
elif s[i] == "1":
print(-1)
return
print("".join(w))
t = int(input())
for _ in range(t):
solve() | FUNC_DEF ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR STRING VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR IF VAR VAR STRING IF VAR VAR ASSIGN VAR BIN_OP VAR VAR STRING IF VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP VAR VAR STRING FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR BIN_OP VAR VAR STRING VAR BIN_OP VAR VAR VAR BIN_OP VAR VAR STRING IF VAR VAR STRING EXPR FUNC_CALL VAR NUMBER RETURN IF VAR VAR STRING EXPR FUNC_CALL VAR NUMBER RETURN EXPR FUNC_CALL VAR FUNC_CALL STRING VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR |
Consider the following process. You have a binary string (a string where each character is either 0 or 1) $w$ of length $n$ and an integer $x$. You build a new binary string $s$ consisting of $n$ characters. The $i$-th character of $s$ is chosen as follows:
if the character $w_{i-x}$ exists and is equal to 1, then $s_i$ is 1 (formally, if $i > x$ and $w_{i-x} = $ 1, then $s_i = $ 1); if the character $w_{i+x}$ exists and is equal to 1, then $s_i$ is 1 (formally, if $i + x \le n$ and $w_{i+x} = $ 1, then $s_i = $ 1); if both of the aforementioned conditions are false, then $s_i$ is 0.
You are given the integer $x$ and the resulting string $s$. Reconstruct the original string $w$.
-----Input-----
The first line contains one integer $t$ ($1 \le t \le 1000$) β the number of test cases.
Each test case consists of two lines. The first line contains the resulting string $s$ ($2 \le |s| \le 10^5$, each character of $s$ is either 0 or 1). The second line contains one integer $x$ ($1 \le x \le |s| - 1$).
The total length of all strings $s$ in the input does not exceed $10^5$.
-----Output-----
For each test case, print the answer on a separate line as follows:
if no string $w$ can produce the string $s$ at the end of the process, print $-1$; otherwise, print the binary string $w$ consisting of $|s|$ characters. If there are multiple answers, print any of them.
-----Example-----
Input
3
101110
2
01
1
110
1
Output
111011
10
-1 | T = int(input())
for t in range(T):
s = input()
n = len(s)
x = int(input())
w = [1] * n
for i in range(n):
if s[i] == "0":
if i + x < n:
w[i + x] = 0
if i - x >= 0:
w[i - x] = 0
for i in range(n):
expected = 0
if i - x >= 0:
expected += w[i - x]
if i + x < n:
expected += w[i + x]
if expected >= 1:
expected = 1
if int(s[i]) != expected:
print(-1)
break
else:
print("".join([str(i) for i in w])) | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER VAR FOR VAR FUNC_CALL VAR VAR IF VAR VAR STRING IF BIN_OP VAR VAR VAR ASSIGN VAR BIN_OP VAR VAR NUMBER IF BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP VAR VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER IF BIN_OP VAR VAR NUMBER VAR VAR BIN_OP VAR VAR IF BIN_OP VAR VAR VAR VAR VAR BIN_OP VAR VAR IF VAR NUMBER ASSIGN VAR NUMBER IF FUNC_CALL VAR VAR VAR VAR EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL STRING FUNC_CALL VAR VAR VAR VAR |
Consider the following process. You have a binary string (a string where each character is either 0 or 1) $w$ of length $n$ and an integer $x$. You build a new binary string $s$ consisting of $n$ characters. The $i$-th character of $s$ is chosen as follows:
if the character $w_{i-x}$ exists and is equal to 1, then $s_i$ is 1 (formally, if $i > x$ and $w_{i-x} = $ 1, then $s_i = $ 1); if the character $w_{i+x}$ exists and is equal to 1, then $s_i$ is 1 (formally, if $i + x \le n$ and $w_{i+x} = $ 1, then $s_i = $ 1); if both of the aforementioned conditions are false, then $s_i$ is 0.
You are given the integer $x$ and the resulting string $s$. Reconstruct the original string $w$.
-----Input-----
The first line contains one integer $t$ ($1 \le t \le 1000$) β the number of test cases.
Each test case consists of two lines. The first line contains the resulting string $s$ ($2 \le |s| \le 10^5$, each character of $s$ is either 0 or 1). The second line contains one integer $x$ ($1 \le x \le |s| - 1$).
The total length of all strings $s$ in the input does not exceed $10^5$.
-----Output-----
For each test case, print the answer on a separate line as follows:
if no string $w$ can produce the string $s$ at the end of the process, print $-1$; otherwise, print the binary string $w$ consisting of $|s|$ characters. If there are multiple answers, print any of them.
-----Example-----
Input
3
101110
2
01
1
110
1
Output
111011
10
-1 | for _ in range(int(input())):
data = list(map(int, list(input())))
x = int(input())
l = len(data)
w = [0] * l
for i in range(l):
if i + x < l:
w[i + x] += 1 if data[i] else -1
if i - x > -1:
w[i - x] += 1 if data[i] else -1
ans = [0] * l
for i in range(l):
if w[i] > 0:
ans[i] = 1
rec = [0] * l
for i in range(l):
if i + x < l:
rec[i] = rec[i] | ans[i + x]
if i - x > -1:
rec[i] = rec[i] | ans[i - x]
if rec != data:
print(-1)
else:
print(*ans, sep="") | FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP LIST NUMBER VAR FOR VAR FUNC_CALL VAR VAR IF BIN_OP VAR VAR VAR VAR BIN_OP VAR VAR VAR VAR NUMBER NUMBER IF BIN_OP VAR VAR NUMBER VAR BIN_OP VAR VAR VAR VAR NUMBER NUMBER ASSIGN VAR BIN_OP LIST NUMBER VAR FOR VAR FUNC_CALL VAR VAR IF VAR VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER VAR FOR VAR FUNC_CALL VAR VAR IF BIN_OP VAR VAR VAR ASSIGN VAR VAR BIN_OP VAR VAR VAR BIN_OP VAR VAR IF BIN_OP VAR VAR NUMBER ASSIGN VAR VAR BIN_OP VAR VAR VAR BIN_OP VAR VAR IF VAR VAR EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR VAR STRING |
Consider the following process. You have a binary string (a string where each character is either 0 or 1) $w$ of length $n$ and an integer $x$. You build a new binary string $s$ consisting of $n$ characters. The $i$-th character of $s$ is chosen as follows:
if the character $w_{i-x}$ exists and is equal to 1, then $s_i$ is 1 (formally, if $i > x$ and $w_{i-x} = $ 1, then $s_i = $ 1); if the character $w_{i+x}$ exists and is equal to 1, then $s_i$ is 1 (formally, if $i + x \le n$ and $w_{i+x} = $ 1, then $s_i = $ 1); if both of the aforementioned conditions are false, then $s_i$ is 0.
You are given the integer $x$ and the resulting string $s$. Reconstruct the original string $w$.
-----Input-----
The first line contains one integer $t$ ($1 \le t \le 1000$) β the number of test cases.
Each test case consists of two lines. The first line contains the resulting string $s$ ($2 \le |s| \le 10^5$, each character of $s$ is either 0 or 1). The second line contains one integer $x$ ($1 \le x \le |s| - 1$).
The total length of all strings $s$ in the input does not exceed $10^5$.
-----Output-----
For each test case, print the answer on a separate line as follows:
if no string $w$ can produce the string $s$ at the end of the process, print $-1$; otherwise, print the binary string $w$ consisting of $|s|$ characters. If there are multiple answers, print any of them.
-----Example-----
Input
3
101110
2
01
1
110
1
Output
111011
10
-1 | t = int(input())
for _ in range(t):
s = input()
x = int(input())
n = len(s)
ans = [1] * n
for i in range(n):
if s[i] == "0":
if i >= x:
ans[i - x] = 0
if i + x < n:
ans[i + x] = 0
f = True
for i in range(n):
if s[i] == "1":
f = False
if i >= x and ans[i - x] != 0:
f = True
if i + x < n and ans[i + x] != 0:
f = True
if not f:
break
if not f:
print(-1)
else:
for i in range(n):
ans[i] = "1" if ans[i] != 0 else "0"
print("".join(ans)) | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP LIST NUMBER VAR FOR VAR FUNC_CALL VAR VAR IF VAR VAR STRING IF VAR VAR ASSIGN VAR BIN_OP VAR VAR NUMBER IF BIN_OP VAR VAR VAR ASSIGN VAR BIN_OP VAR VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR STRING ASSIGN VAR NUMBER IF VAR VAR VAR BIN_OP VAR VAR NUMBER ASSIGN VAR NUMBER IF BIN_OP VAR VAR VAR VAR BIN_OP VAR VAR NUMBER ASSIGN VAR NUMBER IF VAR IF VAR EXPR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR VAR NUMBER STRING STRING EXPR FUNC_CALL VAR FUNC_CALL STRING VAR |
Consider the following process. You have a binary string (a string where each character is either 0 or 1) $w$ of length $n$ and an integer $x$. You build a new binary string $s$ consisting of $n$ characters. The $i$-th character of $s$ is chosen as follows:
if the character $w_{i-x}$ exists and is equal to 1, then $s_i$ is 1 (formally, if $i > x$ and $w_{i-x} = $ 1, then $s_i = $ 1); if the character $w_{i+x}$ exists and is equal to 1, then $s_i$ is 1 (formally, if $i + x \le n$ and $w_{i+x} = $ 1, then $s_i = $ 1); if both of the aforementioned conditions are false, then $s_i$ is 0.
You are given the integer $x$ and the resulting string $s$. Reconstruct the original string $w$.
-----Input-----
The first line contains one integer $t$ ($1 \le t \le 1000$) β the number of test cases.
Each test case consists of two lines. The first line contains the resulting string $s$ ($2 \le |s| \le 10^5$, each character of $s$ is either 0 or 1). The second line contains one integer $x$ ($1 \le x \le |s| - 1$).
The total length of all strings $s$ in the input does not exceed $10^5$.
-----Output-----
For each test case, print the answer on a separate line as follows:
if no string $w$ can produce the string $s$ at the end of the process, print $-1$; otherwise, print the binary string $w$ consisting of $|s|$ characters. If there are multiple answers, print any of them.
-----Example-----
Input
3
101110
2
01
1
110
1
Output
111011
10
-1 | import sys
for tt in range(int(input())):
s = input()
n = len(s)
x = int(input())
w = ["" for i in range(n)]
for i in range(n):
if s[i] == "1":
if i - x >= 0 and (w[i - x] == "" or w[i - x] == s[i]):
w[i - x] = s[i]
elif i + x < n:
w[i + x] = s[i]
else:
print(-1)
break
else:
if i - x >= 0:
if w[i - x] != "1":
w[i - x] = s[i]
else:
print(-1)
break
if i + x < n:
w[i + x] = s[i]
else:
for i in range(n):
if w[i] == "":
print(0, end="")
else:
print(w[i], end="")
print() | IMPORT FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR STRING VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR IF VAR VAR STRING IF BIN_OP VAR VAR NUMBER VAR BIN_OP VAR VAR STRING VAR BIN_OP VAR VAR VAR VAR ASSIGN VAR BIN_OP VAR VAR VAR VAR IF BIN_OP VAR VAR VAR ASSIGN VAR BIN_OP VAR VAR VAR VAR EXPR FUNC_CALL VAR NUMBER IF BIN_OP VAR VAR NUMBER IF VAR BIN_OP VAR VAR STRING ASSIGN VAR BIN_OP VAR VAR VAR VAR EXPR FUNC_CALL VAR NUMBER IF BIN_OP VAR VAR VAR ASSIGN VAR BIN_OP VAR VAR VAR VAR FOR VAR FUNC_CALL VAR VAR IF VAR VAR STRING EXPR FUNC_CALL VAR NUMBER STRING EXPR FUNC_CALL VAR VAR VAR STRING EXPR FUNC_CALL VAR |
Consider the following process. You have a binary string (a string where each character is either 0 or 1) $w$ of length $n$ and an integer $x$. You build a new binary string $s$ consisting of $n$ characters. The $i$-th character of $s$ is chosen as follows:
if the character $w_{i-x}$ exists and is equal to 1, then $s_i$ is 1 (formally, if $i > x$ and $w_{i-x} = $ 1, then $s_i = $ 1); if the character $w_{i+x}$ exists and is equal to 1, then $s_i$ is 1 (formally, if $i + x \le n$ and $w_{i+x} = $ 1, then $s_i = $ 1); if both of the aforementioned conditions are false, then $s_i$ is 0.
You are given the integer $x$ and the resulting string $s$. Reconstruct the original string $w$.
-----Input-----
The first line contains one integer $t$ ($1 \le t \le 1000$) β the number of test cases.
Each test case consists of two lines. The first line contains the resulting string $s$ ($2 \le |s| \le 10^5$, each character of $s$ is either 0 or 1). The second line contains one integer $x$ ($1 \le x \le |s| - 1$).
The total length of all strings $s$ in the input does not exceed $10^5$.
-----Output-----
For each test case, print the answer on a separate line as follows:
if no string $w$ can produce the string $s$ at the end of the process, print $-1$; otherwise, print the binary string $w$ consisting of $|s|$ characters. If there are multiple answers, print any of them.
-----Example-----
Input
3
101110
2
01
1
110
1
Output
111011
10
-1 | t = int(input())
for _ in range(t):
s = str(input())
x = int(input())
n = len(s)
w = [-1] * n
for i in range(n):
j = i - x
k = i + x
if 0 <= j < n and 0 <= k < n:
if s[i] == "0":
w[j] = "0"
w[k] = "0"
elif 0 <= j < n:
if s[i] == "1":
w[j] = "1"
else:
w[j] = "0"
elif 0 <= k < n:
if s[i] == "1":
w[k] = "1"
else:
w[k] = "0"
for i in range(n):
if w[i] == -1:
w[i] = "1"
t = [-1] * n
for i in range(n):
j = i - x
k = i + x
if 0 <= j < n and 0 <= k < n:
if w[j] == "1":
t[i] = "1"
elif w[k] == "1":
t[i] = "1"
else:
t[i] = "0"
elif 0 <= j < n:
if w[j] == "1":
t[i] = "1"
else:
t[i] = "0"
elif 0 <= k < n:
if w[k] == "1":
t[i] = "1"
else:
t[i] = "0"
else:
t[i] = "0"
t = "".join(t)
if s == t:
print("".join(w))
else:
print(-1) | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP LIST NUMBER VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP VAR VAR IF NUMBER VAR VAR NUMBER VAR VAR IF VAR VAR STRING ASSIGN VAR VAR STRING ASSIGN VAR VAR STRING IF NUMBER VAR VAR IF VAR VAR STRING ASSIGN VAR VAR STRING ASSIGN VAR VAR STRING IF NUMBER VAR VAR IF VAR VAR STRING ASSIGN VAR VAR STRING ASSIGN VAR VAR STRING FOR VAR FUNC_CALL VAR VAR IF VAR VAR NUMBER ASSIGN VAR VAR STRING ASSIGN VAR BIN_OP LIST NUMBER VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP VAR VAR IF NUMBER VAR VAR NUMBER VAR VAR IF VAR VAR STRING ASSIGN VAR VAR STRING IF VAR VAR STRING ASSIGN VAR VAR STRING ASSIGN VAR VAR STRING IF NUMBER VAR VAR IF VAR VAR STRING ASSIGN VAR VAR STRING ASSIGN VAR VAR STRING IF NUMBER VAR VAR IF VAR VAR STRING ASSIGN VAR VAR STRING ASSIGN VAR VAR STRING ASSIGN VAR VAR STRING ASSIGN VAR FUNC_CALL STRING VAR IF VAR VAR EXPR FUNC_CALL VAR FUNC_CALL STRING VAR EXPR FUNC_CALL VAR NUMBER |
Consider the following process. You have a binary string (a string where each character is either 0 or 1) $w$ of length $n$ and an integer $x$. You build a new binary string $s$ consisting of $n$ characters. The $i$-th character of $s$ is chosen as follows:
if the character $w_{i-x}$ exists and is equal to 1, then $s_i$ is 1 (formally, if $i > x$ and $w_{i-x} = $ 1, then $s_i = $ 1); if the character $w_{i+x}$ exists and is equal to 1, then $s_i$ is 1 (formally, if $i + x \le n$ and $w_{i+x} = $ 1, then $s_i = $ 1); if both of the aforementioned conditions are false, then $s_i$ is 0.
You are given the integer $x$ and the resulting string $s$. Reconstruct the original string $w$.
-----Input-----
The first line contains one integer $t$ ($1 \le t \le 1000$) β the number of test cases.
Each test case consists of two lines. The first line contains the resulting string $s$ ($2 \le |s| \le 10^5$, each character of $s$ is either 0 or 1). The second line contains one integer $x$ ($1 \le x \le |s| - 1$).
The total length of all strings $s$ in the input does not exceed $10^5$.
-----Output-----
For each test case, print the answer on a separate line as follows:
if no string $w$ can produce the string $s$ at the end of the process, print $-1$; otherwise, print the binary string $w$ consisting of $|s|$ characters. If there are multiple answers, print any of them.
-----Example-----
Input
3
101110
2
01
1
110
1
Output
111011
10
-1 | t = int(input())
for _ in range(t):
s = input()
n = len(s)
x = int(input())
ans = [1] * n
check = True
for i in range(n):
if s[i] == "0":
if i - x >= 0:
ans[i - x] = 0
if i + x < n:
ans[i + x] = 0
for i in range(n):
if s[i] == "1":
if i - x >= 0 and ans[i - x] == 1 or i + x < n and ans[i + x] == 1:
continue
check = False
break
if check:
print(*ans, sep="")
else:
print(-1) | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR STRING IF BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP VAR VAR NUMBER IF BIN_OP VAR VAR VAR ASSIGN VAR BIN_OP VAR VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR STRING IF BIN_OP VAR VAR NUMBER VAR BIN_OP VAR VAR NUMBER BIN_OP VAR VAR VAR VAR BIN_OP VAR VAR NUMBER ASSIGN VAR NUMBER IF VAR EXPR FUNC_CALL VAR VAR STRING EXPR FUNC_CALL VAR NUMBER |
Consider the following process. You have a binary string (a string where each character is either 0 or 1) $w$ of length $n$ and an integer $x$. You build a new binary string $s$ consisting of $n$ characters. The $i$-th character of $s$ is chosen as follows:
if the character $w_{i-x}$ exists and is equal to 1, then $s_i$ is 1 (formally, if $i > x$ and $w_{i-x} = $ 1, then $s_i = $ 1); if the character $w_{i+x}$ exists and is equal to 1, then $s_i$ is 1 (formally, if $i + x \le n$ and $w_{i+x} = $ 1, then $s_i = $ 1); if both of the aforementioned conditions are false, then $s_i$ is 0.
You are given the integer $x$ and the resulting string $s$. Reconstruct the original string $w$.
-----Input-----
The first line contains one integer $t$ ($1 \le t \le 1000$) β the number of test cases.
Each test case consists of two lines. The first line contains the resulting string $s$ ($2 \le |s| \le 10^5$, each character of $s$ is either 0 or 1). The second line contains one integer $x$ ($1 \le x \le |s| - 1$).
The total length of all strings $s$ in the input does not exceed $10^5$.
-----Output-----
For each test case, print the answer on a separate line as follows:
if no string $w$ can produce the string $s$ at the end of the process, print $-1$; otherwise, print the binary string $w$ consisting of $|s|$ characters. If there are multiple answers, print any of them.
-----Example-----
Input
3
101110
2
01
1
110
1
Output
111011
10
-1 | t = int(input())
for _ in range(t):
s = input().strip()
x = int(input())
w = ["1"] * len(s)
for i, digit in enumerate(s):
if digit == "1":
continue
j = i - x
if j >= 0:
w[j] = "0"
j = i + x
if j < len(s):
w[j] = "0"
new_s = ["0"] * len(s)
for i in range(len(s)):
j = i - x
if j >= 0 and w[j] == "1":
new_s[i] = "1"
j = i + x
if j < len(s) and w[j] == "1":
new_s[i] = "1"
if "".join(new_s) != s:
print(-1)
else:
print("".join(w)) | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR BIN_OP LIST STRING FUNC_CALL VAR VAR FOR VAR VAR FUNC_CALL VAR VAR IF VAR STRING ASSIGN VAR BIN_OP VAR VAR IF VAR NUMBER ASSIGN VAR VAR STRING ASSIGN VAR BIN_OP VAR VAR IF VAR FUNC_CALL VAR VAR ASSIGN VAR VAR STRING ASSIGN VAR BIN_OP LIST STRING FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR VAR IF VAR NUMBER VAR VAR STRING ASSIGN VAR VAR STRING ASSIGN VAR BIN_OP VAR VAR IF VAR FUNC_CALL VAR VAR VAR VAR STRING ASSIGN VAR VAR STRING IF FUNC_CALL STRING VAR VAR EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL STRING VAR |
Consider the following process. You have a binary string (a string where each character is either 0 or 1) $w$ of length $n$ and an integer $x$. You build a new binary string $s$ consisting of $n$ characters. The $i$-th character of $s$ is chosen as follows:
if the character $w_{i-x}$ exists and is equal to 1, then $s_i$ is 1 (formally, if $i > x$ and $w_{i-x} = $ 1, then $s_i = $ 1); if the character $w_{i+x}$ exists and is equal to 1, then $s_i$ is 1 (formally, if $i + x \le n$ and $w_{i+x} = $ 1, then $s_i = $ 1); if both of the aforementioned conditions are false, then $s_i$ is 0.
You are given the integer $x$ and the resulting string $s$. Reconstruct the original string $w$.
-----Input-----
The first line contains one integer $t$ ($1 \le t \le 1000$) β the number of test cases.
Each test case consists of two lines. The first line contains the resulting string $s$ ($2 \le |s| \le 10^5$, each character of $s$ is either 0 or 1). The second line contains one integer $x$ ($1 \le x \le |s| - 1$).
The total length of all strings $s$ in the input does not exceed $10^5$.
-----Output-----
For each test case, print the answer on a separate line as follows:
if no string $w$ can produce the string $s$ at the end of the process, print $-1$; otherwise, print the binary string $w$ consisting of $|s|$ characters. If there are multiple answers, print any of them.
-----Example-----
Input
3
101110
2
01
1
110
1
Output
111011
10
-1 | def solve():
s = input()
x = int(input())
ans = [1] * len(s)
for i in range(len(s)):
if s[i] == "0":
t = 0
if i + x < len(s):
ans[i + x] = 0
if i - x >= 0:
ans[i - x] = 0
for i in range(len(s)):
if s[i] == "1":
t = 0
if i + x < len(s):
if ans[i + x] == 1:
t += 1
if i - x >= 0:
if ans[i - x] == 1:
t += 1
if t == 0:
print(-1)
return
if s[i] == "0":
t = 0
if i + x < len(s):
if ans[i + x] == 1:
t += 1
if i - x >= 0:
if ans[i - x] == 1:
t += 1
if t > 0:
print(-1)
return
for i in range(len(ans)):
print(ans[i], end="")
print()
def main():
for i in range(int(input())):
solve()
main() | FUNC_DEF ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR STRING ASSIGN VAR NUMBER IF BIN_OP VAR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR VAR NUMBER IF BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP VAR VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR STRING ASSIGN VAR NUMBER IF BIN_OP VAR VAR FUNC_CALL VAR VAR IF VAR BIN_OP VAR VAR NUMBER VAR NUMBER IF BIN_OP VAR VAR NUMBER IF VAR BIN_OP VAR VAR NUMBER VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER RETURN IF VAR VAR STRING ASSIGN VAR NUMBER IF BIN_OP VAR VAR FUNC_CALL VAR VAR IF VAR BIN_OP VAR VAR NUMBER VAR NUMBER IF BIN_OP VAR VAR NUMBER IF VAR BIN_OP VAR VAR NUMBER VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER RETURN FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR VAR STRING EXPR FUNC_CALL VAR FUNC_DEF FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR |
Consider the following process. You have a binary string (a string where each character is either 0 or 1) $w$ of length $n$ and an integer $x$. You build a new binary string $s$ consisting of $n$ characters. The $i$-th character of $s$ is chosen as follows:
if the character $w_{i-x}$ exists and is equal to 1, then $s_i$ is 1 (formally, if $i > x$ and $w_{i-x} = $ 1, then $s_i = $ 1); if the character $w_{i+x}$ exists and is equal to 1, then $s_i$ is 1 (formally, if $i + x \le n$ and $w_{i+x} = $ 1, then $s_i = $ 1); if both of the aforementioned conditions are false, then $s_i$ is 0.
You are given the integer $x$ and the resulting string $s$. Reconstruct the original string $w$.
-----Input-----
The first line contains one integer $t$ ($1 \le t \le 1000$) β the number of test cases.
Each test case consists of two lines. The first line contains the resulting string $s$ ($2 \le |s| \le 10^5$, each character of $s$ is either 0 or 1). The second line contains one integer $x$ ($1 \le x \le |s| - 1$).
The total length of all strings $s$ in the input does not exceed $10^5$.
-----Output-----
For each test case, print the answer on a separate line as follows:
if no string $w$ can produce the string $s$ at the end of the process, print $-1$; otherwise, print the binary string $w$ consisting of $|s|$ characters. If there are multiple answers, print any of them.
-----Example-----
Input
3
101110
2
01
1
110
1
Output
111011
10
-1 | T = int(input())
for _ in range(T):
w = input()
x = int(input())
n = len(w)
l = ["1" for k in range(n)]
for i in range(n):
if w[i] == "0":
if i - x >= 0:
l[i - x] = "0"
if i + x < n:
l[i + x] = "0"
flag = 0
for i in range(n):
if i + x < n and l[i + x] == "1":
if w[i] == "0":
flag += 1
elif i - x >= 0 and l[i - x] == "1":
if w[i] == "0":
flag += 1
elif w[i] == "1":
flag += 1
if flag != 0:
print(-1)
else:
print("".join(l)) | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR STRING VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR IF VAR VAR STRING IF BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP VAR VAR STRING IF BIN_OP VAR VAR VAR ASSIGN VAR BIN_OP VAR VAR STRING ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF BIN_OP VAR VAR VAR VAR BIN_OP VAR VAR STRING IF VAR VAR STRING VAR NUMBER IF BIN_OP VAR VAR NUMBER VAR BIN_OP VAR VAR STRING IF VAR VAR STRING VAR NUMBER IF VAR VAR STRING VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL STRING VAR |
Consider the following process. You have a binary string (a string where each character is either 0 or 1) $w$ of length $n$ and an integer $x$. You build a new binary string $s$ consisting of $n$ characters. The $i$-th character of $s$ is chosen as follows:
if the character $w_{i-x}$ exists and is equal to 1, then $s_i$ is 1 (formally, if $i > x$ and $w_{i-x} = $ 1, then $s_i = $ 1); if the character $w_{i+x}$ exists and is equal to 1, then $s_i$ is 1 (formally, if $i + x \le n$ and $w_{i+x} = $ 1, then $s_i = $ 1); if both of the aforementioned conditions are false, then $s_i$ is 0.
You are given the integer $x$ and the resulting string $s$. Reconstruct the original string $w$.
-----Input-----
The first line contains one integer $t$ ($1 \le t \le 1000$) β the number of test cases.
Each test case consists of two lines. The first line contains the resulting string $s$ ($2 \le |s| \le 10^5$, each character of $s$ is either 0 or 1). The second line contains one integer $x$ ($1 \le x \le |s| - 1$).
The total length of all strings $s$ in the input does not exceed $10^5$.
-----Output-----
For each test case, print the answer on a separate line as follows:
if no string $w$ can produce the string $s$ at the end of the process, print $-1$; otherwise, print the binary string $w$ consisting of $|s|$ characters. If there are multiple answers, print any of them.
-----Example-----
Input
3
101110
2
01
1
110
1
Output
111011
10
-1 | def solve():
s = list(map(int, input()))
x = int(input())
w = [1] * len(s)
for i in range(len(s)):
if s[i] == 0:
if i + x < len(s):
w[i + x] = 0
if i - x >= 0:
w[i - x] = 0
s_2 = [1] * len(s)
for i in range(len(s)):
if i + x < len(s) and i - x >= 0:
if w[i - x] != 1 and w[i + x] != 1:
s_2[i] = 0
elif i + x < len(s) or i - x >= 0:
if i + x < len(s):
if w[i + x] != 1:
s_2[i] = 0
elif w[i - x] != 1:
s_2[i] = 0
else:
s_2[i] = 0
if s_2 == s:
print("".join(map(str, w)))
else:
print(-1)
for _ in range(int(input())):
solve() | FUNC_DEF ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR NUMBER IF BIN_OP VAR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR VAR NUMBER IF BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF BIN_OP VAR VAR FUNC_CALL VAR VAR BIN_OP VAR VAR NUMBER IF VAR BIN_OP VAR VAR NUMBER VAR BIN_OP VAR VAR NUMBER ASSIGN VAR VAR NUMBER IF BIN_OP VAR VAR FUNC_CALL VAR VAR BIN_OP VAR VAR NUMBER IF BIN_OP VAR VAR FUNC_CALL VAR VAR IF VAR BIN_OP VAR VAR NUMBER ASSIGN VAR VAR NUMBER IF VAR BIN_OP VAR VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR VAR NUMBER IF VAR VAR EXPR FUNC_CALL VAR FUNC_CALL STRING FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR EXPR FUNC_CALL VAR |
Consider the following process. You have a binary string (a string where each character is either 0 or 1) $w$ of length $n$ and an integer $x$. You build a new binary string $s$ consisting of $n$ characters. The $i$-th character of $s$ is chosen as follows:
if the character $w_{i-x}$ exists and is equal to 1, then $s_i$ is 1 (formally, if $i > x$ and $w_{i-x} = $ 1, then $s_i = $ 1); if the character $w_{i+x}$ exists and is equal to 1, then $s_i$ is 1 (formally, if $i + x \le n$ and $w_{i+x} = $ 1, then $s_i = $ 1); if both of the aforementioned conditions are false, then $s_i$ is 0.
You are given the integer $x$ and the resulting string $s$. Reconstruct the original string $w$.
-----Input-----
The first line contains one integer $t$ ($1 \le t \le 1000$) β the number of test cases.
Each test case consists of two lines. The first line contains the resulting string $s$ ($2 \le |s| \le 10^5$, each character of $s$ is either 0 or 1). The second line contains one integer $x$ ($1 \le x \le |s| - 1$).
The total length of all strings $s$ in the input does not exceed $10^5$.
-----Output-----
For each test case, print the answer on a separate line as follows:
if no string $w$ can produce the string $s$ at the end of the process, print $-1$; otherwise, print the binary string $w$ consisting of $|s|$ characters. If there are multiple answers, print any of them.
-----Example-----
Input
3
101110
2
01
1
110
1
Output
111011
10
-1 | import sys
input = lambda: sys.stdin.readline().rstrip()
t = int(input())
def solve():
s = input()
n = len(s)
x = int(input())
d = [None] * n
li = []
for i in range(n):
if i - x >= 0 and i + x < n:
if s[i] == "0":
if d[i - x] == 1 or d[i + x] == 1:
print(-1)
return
d[i - x] = 0
d[i + x] = 0
else:
li.append((i - x, i + x))
elif i - x >= 0:
if s[i] == "0":
if d[i - x] == 1:
print(-1)
return
d[i - x] = 0
else:
if d[i - x] == 0:
print(-1)
return
d[i - x] = 1
elif i + x < n:
if s[i] == "0":
if d[i + x] == 1:
print(-1)
return
d[i + x] = 0
else:
if d[i + x] == 0:
print(-1)
return
d[i + x] = 1
elif s[i] == "1":
print(-1)
return
for a, b in li:
if d[a] == 0 and d[b] == 0:
print(-1)
return
elif d[a] == 0:
d[b] = 1
elif d[b] == 0:
d[a] = 1
else:
d[a] = 1
d[b] = 1
for i in range(n):
if d[i] is None:
d[i] = 1
print(*d, sep="")
for _ in range(t):
solve() | IMPORT ASSIGN VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_DEF ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NONE VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR IF BIN_OP VAR VAR NUMBER BIN_OP VAR VAR VAR IF VAR VAR STRING IF VAR BIN_OP VAR VAR NUMBER VAR BIN_OP VAR VAR NUMBER EXPR FUNC_CALL VAR NUMBER RETURN ASSIGN VAR BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP VAR VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR VAR BIN_OP VAR VAR IF BIN_OP VAR VAR NUMBER IF VAR VAR STRING IF VAR BIN_OP VAR VAR NUMBER EXPR FUNC_CALL VAR NUMBER RETURN ASSIGN VAR BIN_OP VAR VAR NUMBER IF VAR BIN_OP VAR VAR NUMBER EXPR FUNC_CALL VAR NUMBER RETURN ASSIGN VAR BIN_OP VAR VAR NUMBER IF BIN_OP VAR VAR VAR IF VAR VAR STRING IF VAR BIN_OP VAR VAR NUMBER EXPR FUNC_CALL VAR NUMBER RETURN ASSIGN VAR BIN_OP VAR VAR NUMBER IF VAR BIN_OP VAR VAR NUMBER EXPR FUNC_CALL VAR NUMBER RETURN ASSIGN VAR BIN_OP VAR VAR NUMBER IF VAR VAR STRING EXPR FUNC_CALL VAR NUMBER RETURN FOR VAR VAR VAR IF VAR VAR NUMBER VAR VAR NUMBER EXPR FUNC_CALL VAR NUMBER RETURN IF VAR VAR NUMBER ASSIGN VAR VAR NUMBER IF VAR VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR NONE ASSIGN VAR VAR NUMBER EXPR FUNC_CALL VAR VAR STRING FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR |
Consider the following process. You have a binary string (a string where each character is either 0 or 1) $w$ of length $n$ and an integer $x$. You build a new binary string $s$ consisting of $n$ characters. The $i$-th character of $s$ is chosen as follows:
if the character $w_{i-x}$ exists and is equal to 1, then $s_i$ is 1 (formally, if $i > x$ and $w_{i-x} = $ 1, then $s_i = $ 1); if the character $w_{i+x}$ exists and is equal to 1, then $s_i$ is 1 (formally, if $i + x \le n$ and $w_{i+x} = $ 1, then $s_i = $ 1); if both of the aforementioned conditions are false, then $s_i$ is 0.
You are given the integer $x$ and the resulting string $s$. Reconstruct the original string $w$.
-----Input-----
The first line contains one integer $t$ ($1 \le t \le 1000$) β the number of test cases.
Each test case consists of two lines. The first line contains the resulting string $s$ ($2 \le |s| \le 10^5$, each character of $s$ is either 0 or 1). The second line contains one integer $x$ ($1 \le x \le |s| - 1$).
The total length of all strings $s$ in the input does not exceed $10^5$.
-----Output-----
For each test case, print the answer on a separate line as follows:
if no string $w$ can produce the string $s$ at the end of the process, print $-1$; otherwise, print the binary string $w$ consisting of $|s|$ characters. If there are multiple answers, print any of them.
-----Example-----
Input
3
101110
2
01
1
110
1
Output
111011
10
-1 | t = int(input())
def foo(s, x):
n = len(s)
y = n * ["1"]
for i in range(n - x):
if s[i] == "0":
y[i + x] = "0"
if s[n - 1 - i] == "0":
y[n - 1 - i - x] = "0"
for i in range(n):
if i - x >= 0 and y[i - x] == "1" or i + x < n and y[i + x] == "1":
if s[i] == "0":
return "-1"
elif s[i] == "1":
return "-1"
return "".join(y)
for _ in range(t):
s = input()
x = int(input())
print(foo(s, x)) | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR LIST STRING FOR VAR FUNC_CALL VAR BIN_OP VAR VAR IF VAR VAR STRING ASSIGN VAR BIN_OP VAR VAR STRING IF VAR BIN_OP BIN_OP VAR NUMBER VAR STRING ASSIGN VAR BIN_OP BIN_OP BIN_OP VAR NUMBER VAR VAR STRING FOR VAR FUNC_CALL VAR VAR IF BIN_OP VAR VAR NUMBER VAR BIN_OP VAR VAR STRING BIN_OP VAR VAR VAR VAR BIN_OP VAR VAR STRING IF VAR VAR STRING RETURN STRING IF VAR VAR STRING RETURN STRING RETURN FUNC_CALL STRING VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR |
Consider the following process. You have a binary string (a string where each character is either 0 or 1) $w$ of length $n$ and an integer $x$. You build a new binary string $s$ consisting of $n$ characters. The $i$-th character of $s$ is chosen as follows:
if the character $w_{i-x}$ exists and is equal to 1, then $s_i$ is 1 (formally, if $i > x$ and $w_{i-x} = $ 1, then $s_i = $ 1); if the character $w_{i+x}$ exists and is equal to 1, then $s_i$ is 1 (formally, if $i + x \le n$ and $w_{i+x} = $ 1, then $s_i = $ 1); if both of the aforementioned conditions are false, then $s_i$ is 0.
You are given the integer $x$ and the resulting string $s$. Reconstruct the original string $w$.
-----Input-----
The first line contains one integer $t$ ($1 \le t \le 1000$) β the number of test cases.
Each test case consists of two lines. The first line contains the resulting string $s$ ($2 \le |s| \le 10^5$, each character of $s$ is either 0 or 1). The second line contains one integer $x$ ($1 \le x \le |s| - 1$).
The total length of all strings $s$ in the input does not exceed $10^5$.
-----Output-----
For each test case, print the answer on a separate line as follows:
if no string $w$ can produce the string $s$ at the end of the process, print $-1$; otherwise, print the binary string $w$ consisting of $|s|$ characters. If there are multiple answers, print any of them.
-----Example-----
Input
3
101110
2
01
1
110
1
Output
111011
10
-1 | def main():
line = list(input())
n = len(line)
copy = list("?" * n)
x = int(input())
for i in range(n):
if i - x >= 0:
if copy[i - x] == "?" or copy[i - x] == line[i]:
copy[i - x] = line[i]
if line[i] == "0" and i + x < n:
copy[i + x] = line[i]
elif copy[i - x] != line[i]:
if line[i] == "0":
print(-1)
return
elif i + x < n:
if copy[i + x] == "?" or copy[i + x] == line[i]:
copy[i + x] = line[i]
else:
print(-1)
return
else:
print(-1)
return
else:
return 0
elif i + x < n:
if copy[i + x] == "?" or copy[i + x] == line[i]:
copy[i + x] = line[i]
else:
print(-1)
return
elif line[i] == "1":
print(-1)
return
for i in range(n):
if copy[i] == "?":
copy[i] = "0"
line = ""
for i in copy:
line += i
print(line)
t = int(input())
for i in range(t):
main() | FUNC_DEF ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR BIN_OP STRING VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR IF BIN_OP VAR VAR NUMBER IF VAR BIN_OP VAR VAR STRING VAR BIN_OP VAR VAR VAR VAR ASSIGN VAR BIN_OP VAR VAR VAR VAR IF VAR VAR STRING BIN_OP VAR VAR VAR ASSIGN VAR BIN_OP VAR VAR VAR VAR IF VAR BIN_OP VAR VAR VAR VAR IF VAR VAR STRING EXPR FUNC_CALL VAR NUMBER RETURN IF BIN_OP VAR VAR VAR IF VAR BIN_OP VAR VAR STRING VAR BIN_OP VAR VAR VAR VAR ASSIGN VAR BIN_OP VAR VAR VAR VAR EXPR FUNC_CALL VAR NUMBER RETURN EXPR FUNC_CALL VAR NUMBER RETURN RETURN NUMBER IF BIN_OP VAR VAR VAR IF VAR BIN_OP VAR VAR STRING VAR BIN_OP VAR VAR VAR VAR ASSIGN VAR BIN_OP VAR VAR VAR VAR EXPR FUNC_CALL VAR NUMBER RETURN IF VAR VAR STRING EXPR FUNC_CALL VAR NUMBER RETURN FOR VAR FUNC_CALL VAR VAR IF VAR VAR STRING ASSIGN VAR VAR STRING ASSIGN VAR STRING FOR VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR |
Consider the following process. You have a binary string (a string where each character is either 0 or 1) $w$ of length $n$ and an integer $x$. You build a new binary string $s$ consisting of $n$ characters. The $i$-th character of $s$ is chosen as follows:
if the character $w_{i-x}$ exists and is equal to 1, then $s_i$ is 1 (formally, if $i > x$ and $w_{i-x} = $ 1, then $s_i = $ 1); if the character $w_{i+x}$ exists and is equal to 1, then $s_i$ is 1 (formally, if $i + x \le n$ and $w_{i+x} = $ 1, then $s_i = $ 1); if both of the aforementioned conditions are false, then $s_i$ is 0.
You are given the integer $x$ and the resulting string $s$. Reconstruct the original string $w$.
-----Input-----
The first line contains one integer $t$ ($1 \le t \le 1000$) β the number of test cases.
Each test case consists of two lines. The first line contains the resulting string $s$ ($2 \le |s| \le 10^5$, each character of $s$ is either 0 or 1). The second line contains one integer $x$ ($1 \le x \le |s| - 1$).
The total length of all strings $s$ in the input does not exceed $10^5$.
-----Output-----
For each test case, print the answer on a separate line as follows:
if no string $w$ can produce the string $s$ at the end of the process, print $-1$; otherwise, print the binary string $w$ consisting of $|s|$ characters. If there are multiple answers, print any of them.
-----Example-----
Input
3
101110
2
01
1
110
1
Output
111011
10
-1 | import sys
input = sys.stdin.readline
t = int(input())
for _ in range(t):
s = input().rstrip()
x = int(input())
n = len(s)
ans = [1] * n
for i in range(n):
a = i + x
b = i - x
if s[i] == "0":
if a > -1 and a < n:
ans[a] = 0
if b > -1 and b < n:
ans[b] = 0
ok = 1
for i in range(n):
a = i + x
b = i - x
tot = 0
if a > -1 and a < n:
if ans[a] == 1:
tot += 1
if ans[a] == 1 and s[i] == "0":
ok = 0
break
if b > -1 and b < n:
if ans[b] == 1:
tot += 1
if ans[b] == 1 and s[i] == "0":
ok = 0
break
if s[i] == "1" and tot == 0:
ok = 0
break
if ok == 1:
print("".join([str(x) for x in ans]))
else:
print(-1) | IMPORT ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP LIST NUMBER VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP VAR VAR IF VAR VAR STRING IF VAR NUMBER VAR VAR ASSIGN VAR VAR NUMBER IF VAR NUMBER VAR VAR ASSIGN VAR VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR NUMBER IF VAR NUMBER VAR VAR IF VAR VAR NUMBER VAR NUMBER IF VAR VAR NUMBER VAR VAR STRING ASSIGN VAR NUMBER IF VAR NUMBER VAR VAR IF VAR VAR NUMBER VAR NUMBER IF VAR VAR NUMBER VAR VAR STRING ASSIGN VAR NUMBER IF VAR VAR STRING VAR NUMBER ASSIGN VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL STRING FUNC_CALL VAR VAR VAR VAR EXPR FUNC_CALL VAR NUMBER |
Consider the following process. You have a binary string (a string where each character is either 0 or 1) $w$ of length $n$ and an integer $x$. You build a new binary string $s$ consisting of $n$ characters. The $i$-th character of $s$ is chosen as follows:
if the character $w_{i-x}$ exists and is equal to 1, then $s_i$ is 1 (formally, if $i > x$ and $w_{i-x} = $ 1, then $s_i = $ 1); if the character $w_{i+x}$ exists and is equal to 1, then $s_i$ is 1 (formally, if $i + x \le n$ and $w_{i+x} = $ 1, then $s_i = $ 1); if both of the aforementioned conditions are false, then $s_i$ is 0.
You are given the integer $x$ and the resulting string $s$. Reconstruct the original string $w$.
-----Input-----
The first line contains one integer $t$ ($1 \le t \le 1000$) β the number of test cases.
Each test case consists of two lines. The first line contains the resulting string $s$ ($2 \le |s| \le 10^5$, each character of $s$ is either 0 or 1). The second line contains one integer $x$ ($1 \le x \le |s| - 1$).
The total length of all strings $s$ in the input does not exceed $10^5$.
-----Output-----
For each test case, print the answer on a separate line as follows:
if no string $w$ can produce the string $s$ at the end of the process, print $-1$; otherwise, print the binary string $w$ consisting of $|s|$ characters. If there are multiple answers, print any of them.
-----Example-----
Input
3
101110
2
01
1
110
1
Output
111011
10
-1 | t = int(input())
for _ in range(t):
f = True
f1 = "0"
f2 = "0"
s = input()
x = int(input())
n = len(s)
res = ["1" for i in range(n)]
for i in range(n):
if s[i] == "0":
if i + x < n:
res[i + x] = "0"
if i - x >= 0:
res[i - x] = "0"
for i in range(n):
f1 = "0"
f2 = "0"
if i + x < n and res[i + x] == "1":
f1 = "1"
if i - x >= 0 and res[i - x] == "1":
f2 = "1"
f = True if max(f1, f2) == s[i] else False
if not f:
break
print("".join(res) if f else -1) | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR STRING ASSIGN VAR STRING ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR STRING VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR IF VAR VAR STRING IF BIN_OP VAR VAR VAR ASSIGN VAR BIN_OP VAR VAR STRING IF BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP VAR VAR STRING FOR VAR FUNC_CALL VAR VAR ASSIGN VAR STRING ASSIGN VAR STRING IF BIN_OP VAR VAR VAR VAR BIN_OP VAR VAR STRING ASSIGN VAR STRING IF BIN_OP VAR VAR NUMBER VAR BIN_OP VAR VAR STRING ASSIGN VAR STRING ASSIGN VAR FUNC_CALL VAR VAR VAR VAR VAR NUMBER NUMBER IF VAR EXPR FUNC_CALL VAR VAR FUNC_CALL STRING VAR NUMBER |
Consider the following process. You have a binary string (a string where each character is either 0 or 1) $w$ of length $n$ and an integer $x$. You build a new binary string $s$ consisting of $n$ characters. The $i$-th character of $s$ is chosen as follows:
if the character $w_{i-x}$ exists and is equal to 1, then $s_i$ is 1 (formally, if $i > x$ and $w_{i-x} = $ 1, then $s_i = $ 1); if the character $w_{i+x}$ exists and is equal to 1, then $s_i$ is 1 (formally, if $i + x \le n$ and $w_{i+x} = $ 1, then $s_i = $ 1); if both of the aforementioned conditions are false, then $s_i$ is 0.
You are given the integer $x$ and the resulting string $s$. Reconstruct the original string $w$.
-----Input-----
The first line contains one integer $t$ ($1 \le t \le 1000$) β the number of test cases.
Each test case consists of two lines. The first line contains the resulting string $s$ ($2 \le |s| \le 10^5$, each character of $s$ is either 0 or 1). The second line contains one integer $x$ ($1 \le x \le |s| - 1$).
The total length of all strings $s$ in the input does not exceed $10^5$.
-----Output-----
For each test case, print the answer on a separate line as follows:
if no string $w$ can produce the string $s$ at the end of the process, print $-1$; otherwise, print the binary string $w$ consisting of $|s|$ characters. If there are multiple answers, print any of them.
-----Example-----
Input
3
101110
2
01
1
110
1
Output
111011
10
-1 | for i in range(int(input())):
s = input()
x = int(input())
w = ["x"] * len(s)
ip = 0
for j in range(len(s)):
if j - x < 0 and j + x >= len(s):
if s[j] == "1":
ip = 1
break
else:
w[j] = "0"
elif j - x < 0:
w[j + x] = s[j]
elif j - x >= 0 and j + x < len(s):
if s[j] == "0":
if w[j - x] == "1":
ip = 1
break
w[j - x] = w[j + x] = "0"
elif w[j - x] == "x":
w[j - x] = "1"
elif w[j - x] == "0":
w[j + x] = "1"
elif j + x >= len(s):
if w[j - x] == "x":
w[j - x] = s[j]
elif w[j - x] != s[j]:
ip = 1
break
if ip:
print(-1)
else:
ans = ""
for a in w:
if a == "x":
a = "1"
ans += a
print(ans) | FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR BIN_OP LIST STRING FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF BIN_OP VAR VAR NUMBER BIN_OP VAR VAR FUNC_CALL VAR VAR IF VAR VAR STRING ASSIGN VAR NUMBER ASSIGN VAR VAR STRING IF BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP VAR VAR VAR VAR IF BIN_OP VAR VAR NUMBER BIN_OP VAR VAR FUNC_CALL VAR VAR IF VAR VAR STRING IF VAR BIN_OP VAR VAR STRING ASSIGN VAR NUMBER ASSIGN VAR BIN_OP VAR VAR VAR BIN_OP VAR VAR STRING IF VAR BIN_OP VAR VAR STRING ASSIGN VAR BIN_OP VAR VAR STRING IF VAR BIN_OP VAR VAR STRING ASSIGN VAR BIN_OP VAR VAR STRING IF BIN_OP VAR VAR FUNC_CALL VAR VAR IF VAR BIN_OP VAR VAR STRING ASSIGN VAR BIN_OP VAR VAR VAR VAR IF VAR BIN_OP VAR VAR VAR VAR ASSIGN VAR NUMBER IF VAR EXPR FUNC_CALL VAR NUMBER ASSIGN VAR STRING FOR VAR VAR IF VAR STRING ASSIGN VAR STRING VAR VAR EXPR FUNC_CALL VAR VAR |
Consider the following process. You have a binary string (a string where each character is either 0 or 1) $w$ of length $n$ and an integer $x$. You build a new binary string $s$ consisting of $n$ characters. The $i$-th character of $s$ is chosen as follows:
if the character $w_{i-x}$ exists and is equal to 1, then $s_i$ is 1 (formally, if $i > x$ and $w_{i-x} = $ 1, then $s_i = $ 1); if the character $w_{i+x}$ exists and is equal to 1, then $s_i$ is 1 (formally, if $i + x \le n$ and $w_{i+x} = $ 1, then $s_i = $ 1); if both of the aforementioned conditions are false, then $s_i$ is 0.
You are given the integer $x$ and the resulting string $s$. Reconstruct the original string $w$.
-----Input-----
The first line contains one integer $t$ ($1 \le t \le 1000$) β the number of test cases.
Each test case consists of two lines. The first line contains the resulting string $s$ ($2 \le |s| \le 10^5$, each character of $s$ is either 0 or 1). The second line contains one integer $x$ ($1 \le x \le |s| - 1$).
The total length of all strings $s$ in the input does not exceed $10^5$.
-----Output-----
For each test case, print the answer on a separate line as follows:
if no string $w$ can produce the string $s$ at the end of the process, print $-1$; otherwise, print the binary string $w$ consisting of $|s|$ characters. If there are multiple answers, print any of them.
-----Example-----
Input
3
101110
2
01
1
110
1
Output
111011
10
-1 | for _ in range(int(input())):
s = input()
x = int(input())
s1 = [(-1) for i in range(len(s))]
n = len(s)
flag = 0
for i in range(len(s)):
if s[i] == "0":
if i - x >= 0 and i + x <= n - 1:
if s1[i - x] == 0 or s1[i - x] == -1:
s1[i - x] = 0
else:
flag = 1
break
if s1[i + x] == 0 or s1[i + x] == -1:
s1[i + x] = 0
else:
flag = 1
break
continue
if i - x < 0 and i + x > n - 1:
if s1[i] == -1 or s1[i] == 0:
s1[i] = 0
else:
flag = 1
break
continue
if i - x < 0:
if s1[i + x] == -1 or s1[i + x] == 0:
s1[i + x] = 0
else:
flag = 1
break
continue
elif s1[i - x] == -1 or s1[i - x] == 0:
s1[i - x] = 0
else:
flag = 1
break
if s[i] == "1":
if i - x < 0 and i + x > n - 1:
flag = 1
break
if i - x >= 0 and i + x <= n - 1:
if s1[i - x] == 0:
s1[i + x] = 1
else:
s1[i - x] = 1
continue
if i - x < 0:
if s1[i + x] == -1 or s1[i + x] == 1:
s1[i + x] = 1
else:
flag = 1
break
continue
if i + x > n - 1:
if s1[i - x] == -1 or s1[i - x] == 1:
s1[i - x] = 1
else:
flag = 1
break
if flag == 1:
print(-1)
continue
for i in range(len(s1)):
if s1[i] == -1:
s1[i] = 1
s3 = ""
for i in range(len(s1)):
s3 += str(s1[i])
print(s3) | FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR STRING IF BIN_OP VAR VAR NUMBER BIN_OP VAR VAR BIN_OP VAR NUMBER IF VAR BIN_OP VAR VAR NUMBER VAR BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP VAR VAR NUMBER ASSIGN VAR NUMBER IF VAR BIN_OP VAR VAR NUMBER VAR BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP VAR VAR NUMBER ASSIGN VAR NUMBER IF BIN_OP VAR VAR NUMBER BIN_OP VAR VAR BIN_OP VAR NUMBER IF VAR VAR NUMBER VAR VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR NUMBER IF BIN_OP VAR VAR NUMBER IF VAR BIN_OP VAR VAR NUMBER VAR BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP VAR VAR NUMBER ASSIGN VAR NUMBER IF VAR BIN_OP VAR VAR NUMBER VAR BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP VAR VAR NUMBER ASSIGN VAR NUMBER IF VAR VAR STRING IF BIN_OP VAR VAR NUMBER BIN_OP VAR VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER IF BIN_OP VAR VAR NUMBER BIN_OP VAR VAR BIN_OP VAR NUMBER IF VAR BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP VAR VAR NUMBER IF BIN_OP VAR VAR NUMBER IF VAR BIN_OP VAR VAR NUMBER VAR BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP VAR VAR NUMBER ASSIGN VAR NUMBER IF BIN_OP VAR VAR BIN_OP VAR NUMBER IF VAR BIN_OP VAR VAR NUMBER VAR BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP VAR VAR NUMBER ASSIGN VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR STRING FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR |
Consider the following process. You have a binary string (a string where each character is either 0 or 1) $w$ of length $n$ and an integer $x$. You build a new binary string $s$ consisting of $n$ characters. The $i$-th character of $s$ is chosen as follows:
if the character $w_{i-x}$ exists and is equal to 1, then $s_i$ is 1 (formally, if $i > x$ and $w_{i-x} = $ 1, then $s_i = $ 1); if the character $w_{i+x}$ exists and is equal to 1, then $s_i$ is 1 (formally, if $i + x \le n$ and $w_{i+x} = $ 1, then $s_i = $ 1); if both of the aforementioned conditions are false, then $s_i$ is 0.
You are given the integer $x$ and the resulting string $s$. Reconstruct the original string $w$.
-----Input-----
The first line contains one integer $t$ ($1 \le t \le 1000$) β the number of test cases.
Each test case consists of two lines. The first line contains the resulting string $s$ ($2 \le |s| \le 10^5$, each character of $s$ is either 0 or 1). The second line contains one integer $x$ ($1 \le x \le |s| - 1$).
The total length of all strings $s$ in the input does not exceed $10^5$.
-----Output-----
For each test case, print the answer on a separate line as follows:
if no string $w$ can produce the string $s$ at the end of the process, print $-1$; otherwise, print the binary string $w$ consisting of $|s|$ characters. If there are multiple answers, print any of them.
-----Example-----
Input
3
101110
2
01
1
110
1
Output
111011
10
-1 | import sys
def main():
T = int(sys.stdin.readline())
while T:
T -= 1
A = sys.stdin.readline().rstrip()
X = int(sys.stdin.readline())
ans = ["0"] * len(A)
FLAG = True
for i in range(len(A) - X, X):
if A[i] == "1":
print(-1)
FLAG = False
break
if not FLAG:
continue
for i in range(len(A)):
if not inBound(A, i - X):
if not inBound(A, i + X):
ans[i] = "0"
else:
ans[i] = A[i + X]
continue
if not inBound(A, i + X):
if not inBound(A, i - X):
ans[i] = "0"
else:
ans[i] = A[i - X]
continue
if A[i - X] == "1" and (
not inBound(A, i - (X << 1)) or ans[i - (X << 1)] == "0"
):
ans[i] = "1"
elif A[i - X] == "0":
ans[i] = "0"
else:
ans[i] = A[i + X]
if not verify_backward(A, X, i + X, ans):
print(-1)
FLAG = False
break
if FLAG:
print("".join(ans))
def inBound(A, i):
return 0 <= i < len(A)
def verify_backward(A, X, i, ans):
if ans[i - X] == "1" and A[i] == "0":
return False
return True if inBound(A, i + X) else A[i] == ans[i - X]
main() | IMPORT FUNC_DEF ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR WHILE VAR VAR NUMBER ASSIGN VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR BIN_OP LIST STRING FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR VAR VAR IF VAR VAR STRING EXPR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER IF VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF FUNC_CALL VAR VAR BIN_OP VAR VAR IF FUNC_CALL VAR VAR BIN_OP VAR VAR ASSIGN VAR VAR STRING ASSIGN VAR VAR VAR BIN_OP VAR VAR IF FUNC_CALL VAR VAR BIN_OP VAR VAR IF FUNC_CALL VAR VAR BIN_OP VAR VAR ASSIGN VAR VAR STRING ASSIGN VAR VAR VAR BIN_OP VAR VAR IF VAR BIN_OP VAR VAR STRING FUNC_CALL VAR VAR BIN_OP VAR BIN_OP VAR NUMBER VAR BIN_OP VAR BIN_OP VAR NUMBER STRING ASSIGN VAR VAR STRING IF VAR BIN_OP VAR VAR STRING ASSIGN VAR VAR STRING ASSIGN VAR VAR VAR BIN_OP VAR VAR IF FUNC_CALL VAR VAR VAR BIN_OP VAR VAR VAR EXPR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER IF VAR EXPR FUNC_CALL VAR FUNC_CALL STRING VAR FUNC_DEF RETURN NUMBER VAR FUNC_CALL VAR VAR FUNC_DEF IF VAR BIN_OP VAR VAR STRING VAR VAR STRING RETURN NUMBER RETURN FUNC_CALL VAR VAR BIN_OP VAR VAR NUMBER VAR VAR VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR |
Consider the following process. You have a binary string (a string where each character is either 0 or 1) $w$ of length $n$ and an integer $x$. You build a new binary string $s$ consisting of $n$ characters. The $i$-th character of $s$ is chosen as follows:
if the character $w_{i-x}$ exists and is equal to 1, then $s_i$ is 1 (formally, if $i > x$ and $w_{i-x} = $ 1, then $s_i = $ 1); if the character $w_{i+x}$ exists and is equal to 1, then $s_i$ is 1 (formally, if $i + x \le n$ and $w_{i+x} = $ 1, then $s_i = $ 1); if both of the aforementioned conditions are false, then $s_i$ is 0.
You are given the integer $x$ and the resulting string $s$. Reconstruct the original string $w$.
-----Input-----
The first line contains one integer $t$ ($1 \le t \le 1000$) β the number of test cases.
Each test case consists of two lines. The first line contains the resulting string $s$ ($2 \le |s| \le 10^5$, each character of $s$ is either 0 or 1). The second line contains one integer $x$ ($1 \le x \le |s| - 1$).
The total length of all strings $s$ in the input does not exceed $10^5$.
-----Output-----
For each test case, print the answer on a separate line as follows:
if no string $w$ can produce the string $s$ at the end of the process, print $-1$; otherwise, print the binary string $w$ consisting of $|s|$ characters. If there are multiple answers, print any of them.
-----Example-----
Input
3
101110
2
01
1
110
1
Output
111011
10
-1 | t = int(input())
for tt in range(t):
s = input()
x = int(input())
l = ["t"] * len(s)
f = 1
for i in range(len(s)):
if s[i] == "0":
if i - x >= 0:
if l[i - x] == "t" or l[i - x] == "0":
l[i - x] = "0"
else:
f = 0
break
if i + x < len(s):
l[i + x] = "0"
if s[i] == "1":
if i - x >= 0 and (l[i - x] == "t" or l[i - x] == "1"):
l[i - x] = "1"
if i + x * 2 >= len(s) and i + x < len(s):
l[i + x] = "1"
elif i + x < len(s):
l[i + x] = "1"
else:
f = 0
break
if f == 0:
print(-1)
continue
for i in range(len(l)):
if l[i] == "t":
l[i] = "1"
print("".join(l)) | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR BIN_OP LIST STRING FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR STRING IF BIN_OP VAR VAR NUMBER IF VAR BIN_OP VAR VAR STRING VAR BIN_OP VAR VAR STRING ASSIGN VAR BIN_OP VAR VAR STRING ASSIGN VAR NUMBER IF BIN_OP VAR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR VAR STRING IF VAR VAR STRING IF BIN_OP VAR VAR NUMBER VAR BIN_OP VAR VAR STRING VAR BIN_OP VAR VAR STRING ASSIGN VAR BIN_OP VAR VAR STRING IF BIN_OP VAR BIN_OP VAR NUMBER FUNC_CALL VAR VAR BIN_OP VAR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR VAR STRING IF BIN_OP VAR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR VAR STRING ASSIGN VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR STRING ASSIGN VAR VAR STRING EXPR FUNC_CALL VAR FUNC_CALL STRING VAR |
Consider the following process. You have a binary string (a string where each character is either 0 or 1) $w$ of length $n$ and an integer $x$. You build a new binary string $s$ consisting of $n$ characters. The $i$-th character of $s$ is chosen as follows:
if the character $w_{i-x}$ exists and is equal to 1, then $s_i$ is 1 (formally, if $i > x$ and $w_{i-x} = $ 1, then $s_i = $ 1); if the character $w_{i+x}$ exists and is equal to 1, then $s_i$ is 1 (formally, if $i + x \le n$ and $w_{i+x} = $ 1, then $s_i = $ 1); if both of the aforementioned conditions are false, then $s_i$ is 0.
You are given the integer $x$ and the resulting string $s$. Reconstruct the original string $w$.
-----Input-----
The first line contains one integer $t$ ($1 \le t \le 1000$) β the number of test cases.
Each test case consists of two lines. The first line contains the resulting string $s$ ($2 \le |s| \le 10^5$, each character of $s$ is either 0 or 1). The second line contains one integer $x$ ($1 \le x \le |s| - 1$).
The total length of all strings $s$ in the input does not exceed $10^5$.
-----Output-----
For each test case, print the answer on a separate line as follows:
if no string $w$ can produce the string $s$ at the end of the process, print $-1$; otherwise, print the binary string $w$ consisting of $|s|$ characters. If there are multiple answers, print any of them.
-----Example-----
Input
3
101110
2
01
1
110
1
Output
111011
10
-1 | T = int(input())
ans = []
for i in range(T):
s = list(input())
x = int(input())
w = ["1"] * len(s)
for i in range(len(s)):
if s[i] == "0":
if i - x >= 0:
w[i - x] = "0"
if i + x < len(s):
w[i + x] = "0"
is_Ok = True
for i in range(len(s)):
if s[i] == "1":
if i - x >= 0:
if w[i - x] == "1":
continue
if i + x < len(s):
if w[i + x] == "1":
continue
is_Ok = False
if is_Ok:
ans.append(w)
else:
ans.append(["-1"])
for i in range(T):
print("".join(ans[i])) | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR BIN_OP LIST STRING FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR STRING IF BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP VAR VAR STRING IF BIN_OP VAR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR VAR STRING ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR STRING IF BIN_OP VAR VAR NUMBER IF VAR BIN_OP VAR VAR STRING IF BIN_OP VAR VAR FUNC_CALL VAR VAR IF VAR BIN_OP VAR VAR STRING ASSIGN VAR NUMBER IF VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR LIST STRING FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL STRING VAR VAR |
Consider the following process. You have a binary string (a string where each character is either 0 or 1) $w$ of length $n$ and an integer $x$. You build a new binary string $s$ consisting of $n$ characters. The $i$-th character of $s$ is chosen as follows:
if the character $w_{i-x}$ exists and is equal to 1, then $s_i$ is 1 (formally, if $i > x$ and $w_{i-x} = $ 1, then $s_i = $ 1); if the character $w_{i+x}$ exists and is equal to 1, then $s_i$ is 1 (formally, if $i + x \le n$ and $w_{i+x} = $ 1, then $s_i = $ 1); if both of the aforementioned conditions are false, then $s_i$ is 0.
You are given the integer $x$ and the resulting string $s$. Reconstruct the original string $w$.
-----Input-----
The first line contains one integer $t$ ($1 \le t \le 1000$) β the number of test cases.
Each test case consists of two lines. The first line contains the resulting string $s$ ($2 \le |s| \le 10^5$, each character of $s$ is either 0 or 1). The second line contains one integer $x$ ($1 \le x \le |s| - 1$).
The total length of all strings $s$ in the input does not exceed $10^5$.
-----Output-----
For each test case, print the answer on a separate line as follows:
if no string $w$ can produce the string $s$ at the end of the process, print $-1$; otherwise, print the binary string $w$ consisting of $|s|$ characters. If there are multiple answers, print any of them.
-----Example-----
Input
3
101110
2
01
1
110
1
Output
111011
10
-1 | def main():
ntests = int(input())
S = []
W = []
x = []
for i in range(ntests):
S.append(list(input()))
x.append(int(input()))
W.append(["X" for x in range(len(S[i]))])
for i in range(ntests):
m = []
for letter in range(len(S[i])):
left = bounds(letter - x[i], len(W[i]))
right = bounds(letter + x[i], len(W[i]))
if left and not right:
if not adjust(W[i], S[i][letter], letter - x[i]):
break
if right and not left:
if not adjust(W[i], S[i][letter], letter + x[i]):
break
if right and left:
if S[i][letter] == "0":
if not adjust(W[i], S[i][letter], letter + x[i]) or not adjust(
W[i], S[i][letter], letter - x[i]
):
break
else:
m.append((letter + x[i], letter - x[i]))
if not left and not right and S[i][letter] == "1":
W[i] = "-1"
break
for pair in m:
if W[i] == list("-1"):
break
if conflict(W[i], pair[0], pair[1]):
W[i] = list("-1")
break
for word in range(len(W)):
for letter in range(len(W[word])):
if W[word][letter] == "X":
W[word][letter] = "1"
for word in W:
print("".join(word))
def adjust(W, adjustment, position):
if W[position] != "X":
if W[position] != adjustment:
W[:] = "-1"
return False
W[position] = adjustment
return True
def conflict(word, pos1, pos2):
if word[pos1] == "0" and word[pos2] == "0":
return True
else:
return False
def bounds(testcase, upperlimit, lowerlimit=0):
if testcase >= lowerlimit and testcase < upperlimit:
return True
else:
return False
main() | FUNC_DEF ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR LIST ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR EXPR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR EXPR FUNC_CALL VAR STRING VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR BIN_OP VAR VAR VAR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR BIN_OP VAR VAR VAR FUNC_CALL VAR VAR VAR IF VAR VAR IF FUNC_CALL VAR VAR VAR VAR VAR VAR BIN_OP VAR VAR VAR IF VAR VAR IF FUNC_CALL VAR VAR VAR VAR VAR VAR BIN_OP VAR VAR VAR IF VAR VAR IF VAR VAR VAR STRING IF FUNC_CALL VAR VAR VAR VAR VAR VAR BIN_OP VAR VAR VAR FUNC_CALL VAR VAR VAR VAR VAR VAR BIN_OP VAR VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR VAR VAR BIN_OP VAR VAR VAR IF VAR VAR VAR VAR VAR STRING ASSIGN VAR VAR STRING FOR VAR VAR IF VAR VAR FUNC_CALL VAR STRING IF FUNC_CALL VAR VAR VAR VAR NUMBER VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR STRING FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR IF VAR VAR VAR STRING ASSIGN VAR VAR VAR STRING FOR VAR VAR EXPR FUNC_CALL VAR FUNC_CALL STRING VAR FUNC_DEF IF VAR VAR STRING IF VAR VAR VAR ASSIGN VAR STRING RETURN NUMBER ASSIGN VAR VAR VAR RETURN NUMBER FUNC_DEF IF VAR VAR STRING VAR VAR STRING RETURN NUMBER RETURN NUMBER FUNC_DEF NUMBER IF VAR VAR VAR VAR RETURN NUMBER RETURN NUMBER EXPR FUNC_CALL VAR |
Consider the following process. You have a binary string (a string where each character is either 0 or 1) $w$ of length $n$ and an integer $x$. You build a new binary string $s$ consisting of $n$ characters. The $i$-th character of $s$ is chosen as follows:
if the character $w_{i-x}$ exists and is equal to 1, then $s_i$ is 1 (formally, if $i > x$ and $w_{i-x} = $ 1, then $s_i = $ 1); if the character $w_{i+x}$ exists and is equal to 1, then $s_i$ is 1 (formally, if $i + x \le n$ and $w_{i+x} = $ 1, then $s_i = $ 1); if both of the aforementioned conditions are false, then $s_i$ is 0.
You are given the integer $x$ and the resulting string $s$. Reconstruct the original string $w$.
-----Input-----
The first line contains one integer $t$ ($1 \le t \le 1000$) β the number of test cases.
Each test case consists of two lines. The first line contains the resulting string $s$ ($2 \le |s| \le 10^5$, each character of $s$ is either 0 or 1). The second line contains one integer $x$ ($1 \le x \le |s| - 1$).
The total length of all strings $s$ in the input does not exceed $10^5$.
-----Output-----
For each test case, print the answer on a separate line as follows:
if no string $w$ can produce the string $s$ at the end of the process, print $-1$; otherwise, print the binary string $w$ consisting of $|s|$ characters. If there are multiple answers, print any of them.
-----Example-----
Input
3
101110
2
01
1
110
1
Output
111011
10
-1 | t = int(input())
output = []
for i in range(t):
s = input()
x = int(input())
w = [-1] * len(s)
ans = 0
string = ""
for i in range(len(s)):
if s[i] == "0" and i + x < len(s):
w[i + x] = 0
if s[i] == "0" and i - x >= 0:
w[i - x] = 0
for i in range(len(s)):
if (
s[i] == "1"
and i + x < len(s)
and i - x >= 0
and (w[i - x] == -1 and w[i + x] == -1)
):
w[i - x] = 1
w[i + x] = 1
elif (
s[i] == "1"
and i + x < len(s)
and i - x >= 0
and (w[i - x] == -1 and w[i + x] == 0)
):
w[i - x] = 1
elif (
s[i] == "1"
and i + x < len(s)
and i - x >= 0
and (w[i - x] == 0 and w[i + x] == -1)
):
w[i + x] = 1
elif (
s[i] == "1"
and i + x < len(s)
and i - x >= 0
and (w[i - x] == 0 and w[i + x] == 0)
):
ans = -1
elif s[i] == "1" and i + x < len(s) and i - x < 0 and w[i + x] == -1:
w[i + x] = 1
elif s[i] == "1" and i + x < len(s) and i - x < 0 and w[i + x] == 0:
ans = -1
elif s[i] == "1" and i + x >= len(s) and i - x >= 0 and w[i - x] == -1:
w[i - x] = 1
elif s[i] == "1" and i + x >= len(s) and i - x >= 0 and w[i - x] == 0:
ans = -1
elif s[i] == "1" and i + x >= len(s) and i - x < 0:
ans = -1
if ans == 0:
for i in range(len(s)):
if w[i] == -1:
w[i] = 0
string = "".join([str(elem) for elem in w])
else:
string = "-1"
output.append(string)
for i in range(t):
print(output[i]) | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR STRING FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR STRING BIN_OP VAR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR VAR NUMBER IF VAR VAR STRING BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP VAR VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR STRING BIN_OP VAR VAR FUNC_CALL VAR VAR BIN_OP VAR VAR NUMBER VAR BIN_OP VAR VAR NUMBER VAR BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP VAR VAR NUMBER IF VAR VAR STRING BIN_OP VAR VAR FUNC_CALL VAR VAR BIN_OP VAR VAR NUMBER VAR BIN_OP VAR VAR NUMBER VAR BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP VAR VAR NUMBER IF VAR VAR STRING BIN_OP VAR VAR FUNC_CALL VAR VAR BIN_OP VAR VAR NUMBER VAR BIN_OP VAR VAR NUMBER VAR BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP VAR VAR NUMBER IF VAR VAR STRING BIN_OP VAR VAR FUNC_CALL VAR VAR BIN_OP VAR VAR NUMBER VAR BIN_OP VAR VAR NUMBER VAR BIN_OP VAR VAR NUMBER ASSIGN VAR NUMBER IF VAR VAR STRING BIN_OP VAR VAR FUNC_CALL VAR VAR BIN_OP VAR VAR NUMBER VAR BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP VAR VAR NUMBER IF VAR VAR STRING BIN_OP VAR VAR FUNC_CALL VAR VAR BIN_OP VAR VAR NUMBER VAR BIN_OP VAR VAR NUMBER ASSIGN VAR NUMBER IF VAR VAR STRING BIN_OP VAR VAR FUNC_CALL VAR VAR BIN_OP VAR VAR NUMBER VAR BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP VAR VAR NUMBER IF VAR VAR STRING BIN_OP VAR VAR FUNC_CALL VAR VAR BIN_OP VAR VAR NUMBER VAR BIN_OP VAR VAR NUMBER ASSIGN VAR NUMBER IF VAR VAR STRING BIN_OP VAR VAR FUNC_CALL VAR VAR BIN_OP VAR VAR NUMBER ASSIGN VAR NUMBER IF VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR FUNC_CALL STRING FUNC_CALL VAR VAR VAR VAR ASSIGN VAR STRING EXPR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR VAR |
Consider the following process. You have a binary string (a string where each character is either 0 or 1) $w$ of length $n$ and an integer $x$. You build a new binary string $s$ consisting of $n$ characters. The $i$-th character of $s$ is chosen as follows:
if the character $w_{i-x}$ exists and is equal to 1, then $s_i$ is 1 (formally, if $i > x$ and $w_{i-x} = $ 1, then $s_i = $ 1); if the character $w_{i+x}$ exists and is equal to 1, then $s_i$ is 1 (formally, if $i + x \le n$ and $w_{i+x} = $ 1, then $s_i = $ 1); if both of the aforementioned conditions are false, then $s_i$ is 0.
You are given the integer $x$ and the resulting string $s$. Reconstruct the original string $w$.
-----Input-----
The first line contains one integer $t$ ($1 \le t \le 1000$) β the number of test cases.
Each test case consists of two lines. The first line contains the resulting string $s$ ($2 \le |s| \le 10^5$, each character of $s$ is either 0 or 1). The second line contains one integer $x$ ($1 \le x \le |s| - 1$).
The total length of all strings $s$ in the input does not exceed $10^5$.
-----Output-----
For each test case, print the answer on a separate line as follows:
if no string $w$ can produce the string $s$ at the end of the process, print $-1$; otherwise, print the binary string $w$ consisting of $|s|$ characters. If there are multiple answers, print any of them.
-----Example-----
Input
3
101110
2
01
1
110
1
Output
111011
10
-1 | t = int(input())
for _ in range(t):
s = input()
x = int(input())
n = len(s)
w = [-1] * n
for i, c in enumerate(s):
if c == "0":
if i - x >= 0:
w[i - x] = 0
if i + x < n:
w[i + x] = 0
for i in range(n):
if w[i] == -1:
w[i] = 1
satisfies = True
for i, c in enumerate(s):
if c == "1":
if i - x < 0 and i + x >= n:
satisfies = False
if i - x < 0 and i + x < n and w[i + x] == 0:
satisfies = False
if i - x >= 0 and i + x >= n and w[i - x] == 0:
satisfies = False
if i - x >= 0 and i + x < n and w[i - x] == 0 and w[i + x] == 0:
satisfies = False
if c == "0":
if i - x >= 0 and w[i - x] == 1:
satisfies = False
if i + x < n and w[i + x] == 1:
satisfies = False
if satisfies:
print(*w, sep="")
else:
print(-1) | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP LIST NUMBER VAR FOR VAR VAR FUNC_CALL VAR VAR IF VAR STRING IF BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP VAR VAR NUMBER IF BIN_OP VAR VAR VAR ASSIGN VAR BIN_OP VAR VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR FUNC_CALL VAR VAR IF VAR STRING IF BIN_OP VAR VAR NUMBER BIN_OP VAR VAR VAR ASSIGN VAR NUMBER IF BIN_OP VAR VAR NUMBER BIN_OP VAR VAR VAR VAR BIN_OP VAR VAR NUMBER ASSIGN VAR NUMBER IF BIN_OP VAR VAR NUMBER BIN_OP VAR VAR VAR VAR BIN_OP VAR VAR NUMBER ASSIGN VAR NUMBER IF BIN_OP VAR VAR NUMBER BIN_OP VAR VAR VAR VAR BIN_OP VAR VAR NUMBER VAR BIN_OP VAR VAR NUMBER ASSIGN VAR NUMBER IF VAR STRING IF BIN_OP VAR VAR NUMBER VAR BIN_OP VAR VAR NUMBER ASSIGN VAR NUMBER IF BIN_OP VAR VAR VAR VAR BIN_OP VAR VAR NUMBER ASSIGN VAR NUMBER IF VAR EXPR FUNC_CALL VAR VAR STRING EXPR FUNC_CALL VAR NUMBER |
Consider the following process. You have a binary string (a string where each character is either 0 or 1) $w$ of length $n$ and an integer $x$. You build a new binary string $s$ consisting of $n$ characters. The $i$-th character of $s$ is chosen as follows:
if the character $w_{i-x}$ exists and is equal to 1, then $s_i$ is 1 (formally, if $i > x$ and $w_{i-x} = $ 1, then $s_i = $ 1); if the character $w_{i+x}$ exists and is equal to 1, then $s_i$ is 1 (formally, if $i + x \le n$ and $w_{i+x} = $ 1, then $s_i = $ 1); if both of the aforementioned conditions are false, then $s_i$ is 0.
You are given the integer $x$ and the resulting string $s$. Reconstruct the original string $w$.
-----Input-----
The first line contains one integer $t$ ($1 \le t \le 1000$) β the number of test cases.
Each test case consists of two lines. The first line contains the resulting string $s$ ($2 \le |s| \le 10^5$, each character of $s$ is either 0 or 1). The second line contains one integer $x$ ($1 \le x \le |s| - 1$).
The total length of all strings $s$ in the input does not exceed $10^5$.
-----Output-----
For each test case, print the answer on a separate line as follows:
if no string $w$ can produce the string $s$ at the end of the process, print $-1$; otherwise, print the binary string $w$ consisting of $|s|$ characters. If there are multiple answers, print any of them.
-----Example-----
Input
3
101110
2
01
1
110
1
Output
111011
10
-1 | def slv():
s = input()
k = int(input())
n = len(s)
pokita = 1
nes = ["?" for _ in range(n)]
for i in range(n):
if s[i] == "0":
if i + k < n:
nes[i + k] = "0"
if i - k >= 0:
nes[i - k] = "0"
gok = 1
for i in range(n):
if s[i] == "1":
pok = 0
if i + k < n and nes[i + k] != "0":
pok = 1
nes[i + k] = "1"
if i - k >= 0 and nes[i - k] != "0":
pok = 1
nes[i - k] = "1"
if not pok:
gok = 0
for i in range(n):
if nes[i] == "?":
nes[i] = "1"
if gok == 0:
print("-1")
else:
print("".join(map(str, nes)))
t = int(input())
for _ in range(t):
slv() | FUNC_DEF ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR STRING VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR IF VAR VAR STRING IF BIN_OP VAR VAR VAR ASSIGN VAR BIN_OP VAR VAR STRING IF BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP VAR VAR STRING ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR STRING ASSIGN VAR NUMBER IF BIN_OP VAR VAR VAR VAR BIN_OP VAR VAR STRING ASSIGN VAR NUMBER ASSIGN VAR BIN_OP VAR VAR STRING IF BIN_OP VAR VAR NUMBER VAR BIN_OP VAR VAR STRING ASSIGN VAR NUMBER ASSIGN VAR BIN_OP VAR VAR STRING IF VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR STRING ASSIGN VAR VAR STRING IF VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR FUNC_CALL STRING FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR |
Consider the following process. You have a binary string (a string where each character is either 0 or 1) $w$ of length $n$ and an integer $x$. You build a new binary string $s$ consisting of $n$ characters. The $i$-th character of $s$ is chosen as follows:
if the character $w_{i-x}$ exists and is equal to 1, then $s_i$ is 1 (formally, if $i > x$ and $w_{i-x} = $ 1, then $s_i = $ 1); if the character $w_{i+x}$ exists and is equal to 1, then $s_i$ is 1 (formally, if $i + x \le n$ and $w_{i+x} = $ 1, then $s_i = $ 1); if both of the aforementioned conditions are false, then $s_i$ is 0.
You are given the integer $x$ and the resulting string $s$. Reconstruct the original string $w$.
-----Input-----
The first line contains one integer $t$ ($1 \le t \le 1000$) β the number of test cases.
Each test case consists of two lines. The first line contains the resulting string $s$ ($2 \le |s| \le 10^5$, each character of $s$ is either 0 or 1). The second line contains one integer $x$ ($1 \le x \le |s| - 1$).
The total length of all strings $s$ in the input does not exceed $10^5$.
-----Output-----
For each test case, print the answer on a separate line as follows:
if no string $w$ can produce the string $s$ at the end of the process, print $-1$; otherwise, print the binary string $w$ consisting of $|s|$ characters. If there are multiple answers, print any of them.
-----Example-----
Input
3
101110
2
01
1
110
1
Output
111011
10
-1 | import sys
t = int(input())
i = 0
for line in sys.stdin:
if i == 0:
s = line[:-1]
else:
x = int(line)
impossible = False
w = [(-1) for _ in range(len(s))]
for j in range(len(s)):
if s[j] == "1":
if j - x < 0:
if j + x < len(s):
w[j + x] = 1
else:
impossible = True
break
elif j + x >= len(s):
if j - x >= 0:
if w[j - x] == 1 or w[j - x] == -1:
w[j - x] = 1
else:
impossible = True
break
else:
impossible = True
break
elif w[j - x] == -1 or w[j - x] == 1:
w[j - x] = 1
elif w[j + x] == -1 or w[j + x] == 1:
w[j + x] = 1
else:
impossible = True
break
else:
if j - x >= 0:
if w[j - x] == 1:
impossible = True
break
w[j - x] = 0
if j + x < len(s):
if w[j + x] == 1:
impossible = True
break
w[j + x] = 0
if impossible:
print(-1)
else:
for p in range(len(w)):
if w[p] == -1:
w[p] = 1
print(*w, sep="")
i = 1 - i | IMPORT ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR NUMBER FOR VAR VAR IF VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER VAR FUNC_CALL VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR STRING IF BIN_OP VAR VAR NUMBER IF BIN_OP VAR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR VAR NUMBER ASSIGN VAR NUMBER IF BIN_OP VAR VAR FUNC_CALL VAR VAR IF BIN_OP VAR VAR NUMBER IF VAR BIN_OP VAR VAR NUMBER VAR BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP VAR VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER IF VAR BIN_OP VAR VAR NUMBER VAR BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP VAR VAR NUMBER IF VAR BIN_OP VAR VAR NUMBER VAR BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP VAR VAR NUMBER ASSIGN VAR NUMBER IF BIN_OP VAR VAR NUMBER IF VAR BIN_OP VAR VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR BIN_OP VAR VAR NUMBER IF BIN_OP VAR VAR FUNC_CALL VAR VAR IF VAR BIN_OP VAR VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR BIN_OP VAR VAR NUMBER IF VAR EXPR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR NUMBER ASSIGN VAR VAR NUMBER EXPR FUNC_CALL VAR VAR STRING ASSIGN VAR BIN_OP NUMBER VAR |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.