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
T = int(input()) for _ in range(T): s = input() x = int(input()) n = len(s) 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 < n: ans[i + x] = "0" f = 1 for i in range(len(s)): if s[i] == "1": if i - x >= 0 and ans[i - x] == "1" or i + x < n and ans[i + x] == "1": continue else: f = 0 break a = "" if f: print(a.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 FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR 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 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 VAR BIN_OP VAR VAR STRING BIN_OP VAR VAR VAR VAR BIN_OP VAR VAR STRING ASSIGN VAR NUMBER ASSIGN VAR STRING IF VAR EXPR FUNC_CALL VAR 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
import sys from _collections import deque input = lambda: sys.stdin.readline().rstrip("\r\n") for _ in range(int(input())): a = input() n = len(a) x = int(input()) b = [1] * n ans = 1 for i in range(1, n + 1): if a[i - 1] == "0": if i + x <= n: b[i + x - 1] = 0 if i > x: b[i - x - 1] = 0 for i in range(1, n + 1): if a[i - 1] == "1": if i + x <= n and b[i + x - 1] or i > x and b[i - x - 1]: continue else: ans = 0 break if ans: for i in b: if i == 1: print(1, end="") else: print(0, end="") print() else: print(-1)
IMPORT ASSIGN VAR FUNC_CALL FUNC_CALL VAR STRING 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 NUMBER VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER IF VAR BIN_OP VAR NUMBER STRING IF BIN_OP VAR VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER NUMBER IF VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER IF VAR BIN_OP VAR NUMBER STRING IF BIN_OP VAR VAR VAR VAR BIN_OP BIN_OP VAR VAR NUMBER VAR VAR VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR NUMBER IF VAR FOR VAR VAR IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER STRING EXPR FUNC_CALL VAR NUMBER 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
def answer(A, x): dp = [-1] * len(A) for i in range(len(A)): if i + 1 - x > 0 and i + 1 + x <= len(A): if A[i] == "0": if dp[i - x] == -1: dp[i - x] = "0" elif dp[i - x] != A[i]: return -1 if dp[i + x] == -1: dp[i + x] = "0" elif dp[i + x] != A[i]: return -1 elif dp[i - x] == -1: dp[i - x] = "1" elif dp[i - x] == "0": dp[i + x] = "1" elif i + 1 - x > 0: if dp[i - x] == -1: dp[i - x] = A[i] elif dp[i - x] != A[i]: return -1 elif i + 1 + x <= len(A): if dp[i + x] == -1: dp[i + x] = A[i] elif dp[i + x] != A[i]: return -1 elif A[i] == "1": return -1 for i in range(len(A)): if dp[i] == -1: dp[i] = "1" return "".join(dp) t = int(input()) for i in range(t): s = input() n = int(input()) print(answer(s, n))
FUNC_DEF ASSIGN VAR BIN_OP LIST NUMBER FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF BIN_OP BIN_OP VAR NUMBER VAR NUMBER BIN_OP BIN_OP VAR NUMBER VAR FUNC_CALL VAR VAR IF VAR VAR STRING IF VAR BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP VAR VAR STRING IF VAR BIN_OP VAR VAR VAR VAR RETURN NUMBER IF VAR BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP VAR VAR STRING IF VAR BIN_OP VAR VAR VAR VAR RETURN NUMBER IF VAR BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP VAR VAR STRING IF VAR BIN_OP VAR VAR STRING ASSIGN VAR BIN_OP VAR VAR STRING IF BIN_OP BIN_OP VAR NUMBER VAR NUMBER IF VAR BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP VAR VAR VAR VAR IF VAR BIN_OP VAR VAR VAR VAR RETURN NUMBER IF BIN_OP BIN_OP VAR NUMBER VAR FUNC_CALL VAR VAR IF VAR BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP VAR VAR VAR VAR IF VAR BIN_OP VAR VAR VAR VAR RETURN NUMBER IF VAR VAR STRING RETURN NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR NUMBER 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 t 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" for i in range(n): if s[i] == "1": wi = "0" if i >= x and w[i - x] == "1": wi = "1" if i + x < n and w[i + x] == "1": wi = "1" if wi != "1": w = ["-1"] break print("".join(w))
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 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 ASSIGN VAR STRING IF VAR VAR 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 STRING 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())): flag = 1 s = input() x = int(input()) n = len(s) l = ["1" for i in range(n)] for i in range(n): if s[i] == "0" and i + x < n: l[i + x] = "0" if s[i] == "0" and i - x >= 0: l[i - x] = "0" for i in range(n): if s[i] == "1": if x + i < n and l[i + x] == "1" or i - x >= 0 and l[i - x] == "1": continue else: print(-1) flag = 0 break if flag: print("".join(l))
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR NUMBER 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 BIN_OP VAR VAR VAR ASSIGN VAR BIN_OP VAR VAR STRING IF VAR VAR STRING 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 VAR BIN_OP VAR VAR STRING BIN_OP VAR VAR NUMBER 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
for _ in range(int(input())): s = input() x = int(input()) n = len(s) f0 = [1] * n for i in range(n): if s[i] == "0": if i >= x: f0[i - x] = 0 if i + x < n: f0[i + x] = 0 u = 0 for i in range(n): if s[i] == "1": if i >= x: if f0[i - x] == 0: if i + x >= n: u = 1 elif f0[i + x] == 0: u = 1 elif i + x < n: if f0[i + x] == 0: u = 1 else: u = 1 f0 = list(map(str, f0)) if u == 0: print("".join(f0)) 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 NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR STRING IF VAR VAR IF VAR BIN_OP VAR VAR NUMBER IF BIN_OP VAR VAR VAR ASSIGN 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 ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR IF VAR NUMBER 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 parse(w, x): s = [] for i in range(len(w)): b = 0 if i >= x and w[i - x] == 1: b = 1 if i < len(w) - x and w[i + x] == 1: b = 1 s.append(b) return s def u(r, i, v): if r[i] not in (-1, v): raise ArithmeticError r[i] = v for _ in range(int(input())): s, x = list(map(int, input())), int(input()) n = len(s) r = [-1] * n try: for i in range(n): if s[i] < 1: if i >= x: u(r, i - x, 0) if i + x < n: u(r, i + x, 0) for i in range(x): if i + x < n: u(r, i + x, s[i]) if n - i - 1 - x >= 0: u(r, -i - 1 - x, s[-i - 1]) for i in range(x, n - x): if s[i] < 1: continue if r[i - x] == 0: u(r, i + x, 1) elif r[i + x] == 0: u(r, i - x, 1) else: u(r, i - x, 1), u(r, i + x, 1) for i in range(n): r[i] = max(0, r[i]) if parse(r, x) != s: print(-1) else: print("".join(map(str, r))) except ArithmeticError: print(-1)
FUNC_DEF ASSIGN VAR LIST FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER IF VAR VAR VAR BIN_OP VAR VAR NUMBER ASSIGN VAR NUMBER IF VAR BIN_OP FUNC_CALL VAR VAR VAR VAR BIN_OP VAR VAR NUMBER ASSIGN VAR NUMBER EXPR FUNC_CALL VAR VAR RETURN VAR FUNC_DEF IF VAR VAR NUMBER VAR VAR ASSIGN VAR VAR VAR 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 EXPR FUNC_CALL VAR VAR BIN_OP VAR VAR NUMBER IF BIN_OP VAR VAR VAR EXPR FUNC_CALL VAR VAR BIN_OP VAR VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF BIN_OP VAR VAR VAR EXPR FUNC_CALL VAR VAR BIN_OP VAR VAR VAR VAR IF BIN_OP BIN_OP BIN_OP VAR VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR BIN_OP BIN_OP VAR NUMBER VAR VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR VAR BIN_OP VAR VAR IF VAR VAR NUMBER IF VAR BIN_OP VAR VAR NUMBER EXPR FUNC_CALL VAR VAR BIN_OP VAR VAR NUMBER IF VAR BIN_OP VAR VAR NUMBER EXPR FUNC_CALL VAR VAR BIN_OP VAR VAR NUMBER EXPR FUNC_CALL VAR VAR BIN_OP VAR VAR NUMBER FUNC_CALL VAR VAR BIN_OP VAR VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR NUMBER VAR VAR 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 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() x = int(input()) n = len(s) wArr = [(-1) for __ in range(n)] ok = True for i in range(n): if s[i] == "0": if i - x > -1: wArr[i - x] = 0 if i + x < n: wArr[i + x] = 0 for i in range(n): if s[i] == "1": l = i - x r = i + x if l < 0 and r > n - 1: ok = False break if l >= 0 and r < n: if wArr[l] == wArr[r] == 0: ok = False break elif l >= 0: if wArr[l] == 0: ok = False break elif r < n: if wArr[r] == 0: ok = False break if l >= 0 and wArr[l] == -1: wArr[l] = 1 if r < n and wArr[r] == -1: wArr[r] = 1 for i in range(n): if wArr[i] == -1: wArr[i] = 1 if ok == False: print(-1) else: print("".join([str(x) for x in wArr]))
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 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 ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP VAR VAR IF VAR NUMBER VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER IF VAR NUMBER VAR VAR IF VAR VAR VAR VAR NUMBER ASSIGN VAR NUMBER IF VAR NUMBER IF VAR VAR NUMBER ASSIGN VAR NUMBER IF VAR VAR IF VAR VAR NUMBER ASSIGN VAR NUMBER IF VAR NUMBER VAR VAR NUMBER ASSIGN VAR VAR NUMBER IF VAR VAR VAR VAR NUMBER ASSIGN VAR VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR NUMBER ASSIGN VAR VAR NUMBER IF VAR NUMBER 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
rr = lambda: input().strip() def constu(w, n, x): sx = list(w) for i in range(n): if i - x >= 0 and w[i - x] == "1" or i + x < n and w[i + x] == "1": sx[i] = "1" else: sx[i] = "0" sx = "".join(sx) return sx def solve(s): x = int(rr()) 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" te = constu(w, n, x) if s == te: w = "".join(w) return w else: return -1 T = int(rr()) for _ in range(T): s = rr() ans = solve(s) print(ans)
ASSIGN VAR FUNC_CALL FUNC_CALL VAR FUNC_DEF ASSIGN VAR FUNC_CALL VAR 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 VAR STRING ASSIGN VAR FUNC_CALL STRING VAR RETURN VAR FUNC_DEF 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 VAR VAR VAR VAR IF VAR VAR ASSIGN VAR FUNC_CALL STRING VAR RETURN VAR RETURN NUMBER 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 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())): string = list(input()) x = int(input()) len_str = len(string) w = ["1" for _ in range(len_str)] for ind, s in enumerate(string): if s == "0": if ind - x >= 0: w[ind - x] = "0" if ind + x < len_str: w[ind + x] = "0" test = ["0" for _ in range(len_str)] for ind in range(0, len_str): if ind + x < len_str: if w[ind + x] == "1": test[ind] = "1" continue if ind - x >= 0: if w[ind - x] == "1": test[ind] = "1" continue if test == string: print("".join(w)) 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 FUNC_CALL VAR VAR ASSIGN VAR STRING VAR 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 VAR ASSIGN VAR BIN_OP VAR VAR STRING ASSIGN VAR STRING VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR NUMBER 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 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
for _ in range(int(input())): s = input() x = int(input()) ls = len(s) a = [1] * ls for i, k in enumerate(s): if k == "0": if i - x >= 0: a[i - x] = 0 if i + x < ls: a[i + x] = 0 for i, k in enumerate(s): if k == "1": f = 0 if i - x >= 0: f |= a[i - x] if i + x < ls: f |= a[i + x] if not f: print(-1) break else: print("".join(str(a) for a in a))
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 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 VAR FUNC_CALL VAR VAR IF VAR STRING 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 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
T = int(input()) for t in range(T): s = input() x = int(input()) n = len(s) ans = [(1) for i in range(n)] for i, a in enumerate(s): if a == "1": continue if i - x >= 0: ans[i - x] = 0 if i + x < n: ans[i + x] = 0 impossible = False for i, a in enumerate(s): if a == "0": continue if i - x >= 0 and ans[i - x] == 1: continue if i + x < n and ans[i + x] == 1: continue impossible = True break if impossible: print("-1") continue print("".join(str(x) for x in 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 NUMBER VAR 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 NUMBER IF BIN_OP VAR VAR VAR ASSIGN VAR BIN_OP VAR VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR FUNC_CALL VAR VAR IF VAR STRING IF BIN_OP VAR VAR NUMBER VAR BIN_OP VAR VAR NUMBER IF BIN_OP VAR VAR VAR VAR BIN_OP VAR VAR NUMBER ASSIGN VAR NUMBER IF VAR EXPR FUNC_CALL VAR STRING 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
from sys import stdin T = int(stdin.readline().strip()) for caso in range(T): s = stdin.readline().strip() n = int(stdin.readline().strip()) ans = [(1) for i in range(len(s))] can = True res = "" for i in range(len(s)): if s[i] == "0": if i - n >= 0: ans[i - n] = 0 if i + n < len(s): ans[i + n] = 0 for i in range(len(s)): res += str(ans[i]) t = 0 if i - n >= 0 and ans[i - n] == 1: t = 1 if i + n < len(s) and ans[i + n] == 1: t = 1 if t != int(s[i]): can = False break if can: print(res) else: print(-1)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER 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 NUMBER IF BIN_OP VAR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR VAR ASSIGN VAR 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 VAR FUNC_CALL VAR VAR VAR ASSIGN VAR NUMBER IF 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 func(): n = len(s) w = ["_"] * n for i in range(n): if s[i] == "0": flag = True if i + x < n: w[i + x] = "0" flag = False if i - x > -1: w[i - x] = "0" flag = False if (i - x > -1 or i + x < n) and flag: print(-1) return for i in range(n): if s[i] == "1": flag = True if i + x < n and w[i + x] != "0": w[i + x] = "1" flag = False if i - x > -1 and w[i - x] != "0": w[i - x] = "1" flag = False if flag: print(-1) return for i in range(n): if w[i] == "_": w[i] = "1" print("".join(w)) for _ in range(int(input())): s = list(input()) x = int(input()) func()
FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP LIST STRING VAR FOR VAR FUNC_CALL VAR VAR IF VAR VAR STRING ASSIGN VAR NUMBER IF BIN_OP VAR VAR VAR ASSIGN VAR BIN_OP VAR VAR STRING ASSIGN VAR NUMBER IF BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP VAR VAR STRING ASSIGN VAR NUMBER IF BIN_OP VAR VAR NUMBER BIN_OP VAR VAR VAR VAR EXPR FUNC_CALL VAR NUMBER RETURN 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 ASSIGN VAR NUMBER IF BIN_OP VAR VAR NUMBER VAR BIN_OP VAR VAR STRING ASSIGN VAR BIN_OP VAR VAR STRING ASSIGN VAR NUMBER IF VAR EXPR FUNC_CALL VAR NUMBER RETURN FOR VAR FUNC_CALL VAR VAR IF VAR VAR STRING ASSIGN VAR VAR STRING EXPR FUNC_CALL VAR FUNC_CALL STRING 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 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 = list(input().strip()) x = int(input()) n = len(s) f = 0 res = ["1"] * n for i in range(n): if s[i] == "0": if i - x >= 0: res[i - x] = "0" if i + x < n: res[i + x] = "0" for i in range(n): if s[i] == "1": done = 0 if i - x >= 0 and res[i - x] != "0": res[i - x] = "1" done = 1 if i + x < n and res[i + x] != "0": res[i + x] = "1" done = 1 if not done: f = 1 if f: print(-1) else: print("".join(res))
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL 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 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 BIN_OP VAR VAR STRING ASSIGN VAR BIN_OP 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 ASSIGN VAR NUMBER IF VAR ASSIGN VAR NUMBER 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
def dfs(s1, s, x, index, visited): orig = index while index < len(s): visited.add(index) if s[index] == "0": if index - x >= 0: s1[index - x] = "0" if index + x < len(s): s1[index + x] = "0" index += 1 index = orig while index < len(s): if s[index] == "1": if index - x >= 0: if s1[index - x] == -1: s1[index - x] = "1" if index + x < len(s): if s1[index + x] == -1: s1[index + x] = "1" index += 1 def good(s1, s, x): for i in range(len(s)): if s[i] == "0": if i + x < len(s) and s1[i + x] != "0": return False if i - x >= 0 and s1[i - x] != "0": return False elif (i + x < len(s) and s1[i + x] != "1" or i + x >= len(s)) and ( i - x >= 0 and s1[i - x] != "1" or i - x < 0 ): return False return True def solve(s, x, ans): s1 = [-1] * len(s) visited = set() for i in range(len(s)): if i not in visited: dfs(s1, s, x, i, visited) for i in range(len(s)): if s1[i] == -1: s1[i] = "1" if good(s1, s, x): ans.append(s1) else: ans.append(["-1"]) def main(): t = int(input()) ans = [] for i in range(t): s = input() x = int(input()) solve(s, x, ans) for i in ans: print("".join(i)) main()
FUNC_DEF ASSIGN VAR VAR WHILE VAR FUNC_CALL VAR VAR EXPR 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 VAR NUMBER ASSIGN VAR VAR WHILE VAR FUNC_CALL VAR VAR IF VAR VAR STRING IF BIN_OP VAR VAR NUMBER IF VAR BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP VAR VAR STRING IF BIN_OP VAR VAR FUNC_CALL VAR VAR IF VAR BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP VAR VAR STRING VAR NUMBER FUNC_DEF FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR STRING IF BIN_OP VAR VAR FUNC_CALL VAR VAR VAR BIN_OP VAR VAR STRING RETURN NUMBER IF BIN_OP VAR VAR NUMBER VAR BIN_OP VAR VAR STRING RETURN NUMBER IF BIN_OP VAR VAR FUNC_CALL VAR VAR VAR BIN_OP VAR VAR STRING BIN_OP VAR VAR FUNC_CALL VAR VAR BIN_OP VAR VAR NUMBER VAR BIN_OP VAR VAR STRING BIN_OP VAR VAR NUMBER RETURN NUMBER RETURN NUMBER FUNC_DEF ASSIGN VAR BIN_OP LIST NUMBER FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR EXPR FUNC_CALL VAR VAR VAR VAR VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR NUMBER ASSIGN VAR VAR STRING IF FUNC_CALL VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR LIST STRING 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 VAR VAR VAR FOR VAR VAR EXPR FUNC_CALL VAR FUNC_CALL STRING 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()) answer = [] for _ in range(t): string = input() x = int(input()) n = len(string) tempo = ["1" for i in range(n)] for i in range(n): if string[i] == "0": if i + x < n: tempo[i + x] = "0" if i - x >= 0: tempo[i - x] = "0" for i in range(n): if string[i] == "1": bool = False if i + x < n: bool = bool or tempo[i + x] != "0" if i - x >= 0: bool = bool or tempo[i - x] != "0" if not bool: tempo = "-1" break if tempo != "-1": tempo = "".join(tempo) answer.append(tempo) print("\n".join(answer))
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 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 IF VAR VAR STRING ASSIGN VAR NUMBER IF BIN_OP VAR VAR VAR ASSIGN VAR VAR VAR BIN_OP VAR VAR STRING IF BIN_OP VAR VAR NUMBER ASSIGN VAR VAR VAR BIN_OP VAR VAR STRING IF VAR ASSIGN VAR STRING IF VAR STRING ASSIGN VAR FUNC_CALL STRING VAR EXPR FUNC_CALL VAR 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 w in range(t): q = str(input("")) x = int(input()) n = len(q) ans = ["1" for i in q] for i in range(0, n): if q[i] == "0": if i - x >= 0: ans[i - x] = "0" if i + x < n: ans[i + x] = "0" ll = False rr = False flag = True for i in range(0, n): if q[i] == "1": ll = False rr = False if i - x >= 0: if ans[i - x] == "1": ll = True if i + x < n: if ans[i + x] == "1": rr = True if (ll or rr) == False: flag = False break if flag: 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 FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR STRING VAR VAR FOR VAR FUNC_CALL VAR NUMBER 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 ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR IF VAR VAR STRING ASSIGN VAR NUMBER ASSIGN VAR NUMBER IF BIN_OP VAR VAR NUMBER IF 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 VAR VAR NUMBER ASSIGN VAR NUMBER IF 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
import sys tc = int(sys.stdin.readline()) for _ in range(tc): s = list(sys.stdin.readline().rstrip()) x = int(sys.stdin.readline()) n = len(s) s = ["-1"] + s w = ["-1"] + ["1"] * n temp = ["-1"] + ["0"] * n match = True for i in range(1, n + 1): if s[i] == "0": if i > x: w[i - x] = "0" if i + x <= n: w[i + x] = "0" for i in range(1, n + 1): if i > x and w[i - x] == "1": temp[i] = "1" if i + x <= n and w[i + x] == "1": temp[i] = "1" for i in range(1, n + 1): if temp[i] != s[i]: match = False break if match: print("".join(w[1:])) else: print(-1)
IMPORT ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL 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 ASSIGN VAR BIN_OP LIST STRING BIN_OP LIST STRING VAR ASSIGN VAR BIN_OP LIST STRING BIN_OP LIST STRING VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER 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 NUMBER BIN_OP VAR NUMBER IF VAR VAR 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 FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER IF VAR VAR VAR VAR ASSIGN VAR NUMBER IF 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
import sys input = sys.stdin.readline def const(S): n = len(S) ANS = ["0"] * n for i in range(n): if i - x >= 0 and S[i - x] == "1": ANS[i] = "1" if i + x < n and S[i + x] == "1": ANS[i] = "1" return "".join(ANS) t = int(input()) for tests in range(t): S = input().strip() 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" A = "".join(ANS) if const(A) == S: print(A) else: print(-1)
IMPORT ASSIGN VAR VAR FUNC_DEF ASSIGN VAR FUNC_CALL VAR 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 RETURN FUNC_CALL STRING 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 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 IF 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
def solve(string, x): n = len(string) possible = [{(0): True, (1): True} for i in range(n)] for i in range(n): if string[i] == "0": if i >= x: possible[i - x][1] = False if i + x < n: possible[i + x][1] = False elif i < x and i + x >= n: return -1 elif i < x: possible[i + x][0] = False elif i + x >= n: possible[i - x][0] = False elif not possible[i - x][1] and not possible[i + x][1]: return -1 elif not possible[i - x][1]: possible[i + x][0] = False elif not possible[i + x][1]: possible[i - x][0] = False output = "" for p in possible: if not p[0] and not p[1]: return -1 elif not p[0]: output += "1" elif not p[1]: output += "0" else: output += "1" return output def main(): t = int(input()) for _ in range(t): string = input() x = int(input()) answer = solve(string, x) print(answer) main()
FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR DICT NUMBER NUMBER NUMBER NUMBER VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR IF VAR VAR STRING IF VAR VAR ASSIGN VAR BIN_OP VAR VAR NUMBER NUMBER IF BIN_OP VAR VAR VAR ASSIGN VAR BIN_OP VAR VAR NUMBER NUMBER IF VAR VAR BIN_OP VAR VAR VAR RETURN NUMBER IF VAR VAR ASSIGN VAR BIN_OP VAR VAR NUMBER NUMBER IF BIN_OP VAR VAR VAR ASSIGN VAR BIN_OP VAR VAR NUMBER NUMBER IF VAR BIN_OP VAR VAR NUMBER VAR BIN_OP VAR VAR NUMBER RETURN NUMBER IF VAR BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP VAR VAR NUMBER NUMBER IF VAR BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP VAR VAR NUMBER NUMBER ASSIGN VAR STRING FOR VAR VAR IF VAR NUMBER VAR NUMBER RETURN NUMBER IF VAR NUMBER VAR STRING IF VAR NUMBER VAR STRING VAR STRING RETURN VAR FUNC_DEF 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 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()) num = [(1) for i in range(n)] f1 = 0 for i in range(n): di = int(s[i]) if i - x < 0 and i + x >= n: if di == 0: num[i] = 0 elif i - x < 0 and i + x < n: if di == 0: num[i + x] = 0 elif i - x >= 0 and i + x >= n: if di == 0: num[i - x] = 0 elif i - x >= 0 and i + x < n: if di == 0: num[i - x] = 0 num[i + x] = 0 lis = [] for i in range(n): if i - x >= 0 and num[i - x] == 1: lis.append(1) elif i + x < n and num[i + x] == 1: lis.append(1) else: lis.append(0) st = "" for i in lis: st += str(i) if st == s: for i in num: print(i, end="") print() 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 NUMBER VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR IF BIN_OP VAR VAR NUMBER BIN_OP VAR VAR VAR IF VAR NUMBER ASSIGN VAR VAR NUMBER IF BIN_OP VAR VAR NUMBER BIN_OP VAR VAR VAR IF VAR NUMBER ASSIGN VAR BIN_OP VAR VAR NUMBER IF BIN_OP VAR VAR NUMBER BIN_OP VAR VAR VAR IF VAR NUMBER ASSIGN VAR BIN_OP VAR VAR NUMBER IF BIN_OP VAR VAR NUMBER BIN_OP VAR VAR VAR IF VAR NUMBER ASSIGN VAR BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP VAR VAR NUMBER ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR IF BIN_OP VAR VAR NUMBER VAR BIN_OP VAR VAR NUMBER EXPR FUNC_CALL VAR NUMBER IF BIN_OP VAR VAR VAR VAR BIN_OP VAR VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR NUMBER ASSIGN VAR STRING FOR VAR VAR VAR FUNC_CALL VAR VAR 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 = list(input()) x = int(input()) temp = [(1) for j in range(len(s))] for j in range(len(s)): if s[j] == "0": if j + x < len(s): temp[j + x] = 0 if j - x >= 0: temp[j - x] = 0 flag = 0 for j in range(len(s)): if s[j] == "1": if j + x < len(s) and temp[j + x] == 1 or j - x >= 0 and temp[j - x] == 1: continue else: flag = 1 break if flag == 1: print(-1) else: print(*temp, 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 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 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 NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR STRING IF BIN_OP VAR VAR FUNC_CALL VAR VAR VAR BIN_OP VAR VAR NUMBER BIN_OP VAR VAR NUMBER VAR BIN_OP VAR VAR NUMBER ASSIGN 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 input = sys.stdin.readline t = int(input()) for _ in range(t): s = [int(item) for item in input().rstrip()] x = int(input()) n = len(s) ret1 = [-1] * n for i in range(x, n): if not s[i]: ret1[i - x] = 0 for i in range(n - x): if not s[i]: ret1[i + x] = 0 for i in range(n): if ret1[i] == -1: ret1[i] = 1 ret2 = [-1] * n for i in range(n): if i - x < 0: l = 0 else: l = ret1[i - x] if i + x > n - 1: r = 0 else: r = ret1[i + x] ret2[i] = l or r if ret2 != s: print(-1) else: print("".join([str(item) for item in ret1]))
IMPORT ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR 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 NUMBER VAR FOR VAR FUNC_CALL VAR VAR VAR IF VAR VAR ASSIGN VAR BIN_OP VAR VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR VAR IF 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 BIN_OP LIST NUMBER VAR FOR VAR FUNC_CALL VAR VAR IF BIN_OP VAR VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR VAR BIN_OP VAR VAR IF BIN_OP VAR VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR VAR BIN_OP VAR VAR ASSIGN VAR VAR VAR VAR IF 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
from sys import stdin, stdout t = int(stdin.readline()) for _ in range(t): arr = stdin.readline() arr = arr[: len(arr) - 1] w = int(stdin.readline()) n = len(arr) pc = [1] * n counter = 0 for i in range(n): if counter == 1: break if arr[i] == "0": if i - w >= 0: pc[i - w] = 0 if i + w < n: pc[i + w] = 0 nc = [i for i in pc] for i in range(n): c1, c2 = 0, 0 if i + w < n and i - w >= 0 and pc[i + w] == 1 and pc[i - w] == 1: nc[i] = 1 elif i + w < n and pc[i + w] == 1 or i - w >= 0 and pc[i - w] == 1: nc[i] = 1 else: nc[i] = 0 if int(arr[i]) != nc[i]: print(-1) counter = 1 break if counter == 0: for i in range(n): print(pc[i], end="") print()
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR VAR BIN_OP FUNC_CALL VAR VAR NUMBER 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 VAR NUMBER 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 ASSIGN VAR VAR VAR VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR NUMBER NUMBER IF BIN_OP VAR VAR VAR BIN_OP VAR VAR NUMBER VAR 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 BIN_OP VAR VAR NUMBER VAR BIN_OP VAR VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR VAR NUMBER IF FUNC_CALL VAR VAR VAR VAR VAR EXPR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER IF VAR NUMBER FOR VAR FUNC_CALL VAR VAR 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
from sys import stdin, stdout def input(): return stdin.readline().strip() def s_of(w): ret = [] for i in range(len(w)): anchors = [] for j in [i - x, i + x]: if 0 <= j < len(w): anchors += [w[j]] if 1 in anchors: ret += [1] else: ret += [0] return ret def ans(S, x): ret = [1] * len(S) for i, s in enumerate(S): if s == "0": for j in [i - x, i + x]: if 0 <= j < len(ret): ret[j] = 0 if "".join(map(str, s_of(ret))) == S: return "".join(map(str, ret)) else: return "-1" T = int(input()) for t in range(T): S = input() x = int(input()) print(ans(S, x))
FUNC_DEF RETURN FUNC_CALL FUNC_CALL VAR FUNC_DEF ASSIGN VAR LIST FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR LIST FOR VAR LIST BIN_OP VAR VAR BIN_OP VAR VAR IF NUMBER VAR FUNC_CALL VAR VAR VAR LIST VAR VAR IF NUMBER VAR VAR LIST NUMBER VAR LIST NUMBER RETURN VAR FUNC_DEF ASSIGN VAR BIN_OP LIST NUMBER FUNC_CALL VAR VAR FOR VAR VAR FUNC_CALL VAR VAR IF VAR STRING FOR VAR LIST BIN_OP VAR VAR BIN_OP VAR VAR IF NUMBER VAR FUNC_CALL VAR VAR ASSIGN VAR VAR NUMBER IF FUNC_CALL STRING FUNC_CALL VAR VAR FUNC_CALL VAR VAR VAR RETURN FUNC_CALL STRING FUNC_CALL VAR VAR VAR RETURN STRING 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())): ar = input().rstrip() x = int(input()) n = len(ar) ans = [1] * n for j in range(n): if ar[j] == "0": if j - x >= 0: ans[j - x] = 0 if j + x < n: ans[j + x] = 0 mk = ["0"] * n for i in range(n): if ans[i] == 1: if i - x >= 0: mk[i - x] = "1" if i + x < n: mk[i + x] = "1" mk = "".join(mk) if mk == ar: for i in ans: print(i, end="") print() else: print("-1")
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 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 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 FUNC_CALL STRING VAR IF VAR VAR FOR VAR VAR EXPR FUNC_CALL VAR VAR STRING EXPR FUNC_CALL 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
import sys def i(): return sys.stdin.readline()[:-1] def getOutList(n, x, binList): outList = [False] * n for b in range(n - x): outList[b] = binList[b + x] for b in range(x, n): outList[b] = outList[b] or binList[b - x] return outList cases = int(i()) for a in range(cases): inStr = i() binList = list(x == "1" for x in inStr) x = int(i()) n = len(binList) posIn = [True] * n for b in range(n - x): if not binList[b]: posIn[b + x] = False for b in range(x, n): if not binList[b]: posIn[b - x] = False if not getOutList(n, x, posIn) == binList: print(-1) else: outStr = "" for bit in posIn: outStr += "1" if bit else "0" print(outStr)
IMPORT FUNC_DEF RETURN FUNC_CALL VAR NUMBER FUNC_DEF ASSIGN VAR BIN_OP LIST NUMBER VAR FOR VAR FUNC_CALL VAR BIN_OP VAR VAR ASSIGN VAR VAR VAR BIN_OP VAR VAR FOR VAR FUNC_CALL VAR VAR VAR ASSIGN VAR VAR VAR VAR VAR BIN_OP VAR VAR RETURN 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 VAR STRING VAR 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 BIN_OP VAR VAR IF VAR VAR ASSIGN VAR BIN_OP VAR VAR NUMBER FOR VAR FUNC_CALL VAR VAR VAR IF VAR VAR ASSIGN VAR BIN_OP VAR VAR NUMBER IF FUNC_CALL VAR VAR VAR VAR VAR EXPR FUNC_CALL VAR NUMBER ASSIGN VAR STRING FOR VAR VAR VAR VAR STRING STRING 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 binaryRecon(s, k): r = ["1"] * len(s) for i in range(len(s)): if i - k >= 0 and s[i] == "0": r[i - k] = "0" if i + k < len(s) and s[i] == "0": r[i + k] = "0" flag = checker(r, s, k) if flag: print("".join(r)) return print(-1) def checker(lis, s, x): for i in range(len(lis)): flag = False if i - x >= 0 and lis[i - x] == "1": flag = True if i + x < len(s) and lis[i + x] == "1": flag = True if s[i] != str(int(flag)): return False return True k = int(input()) for i in range(k): s = input() k = int(input()) binaryRecon(s, k)
FUNC_DEF 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 VAR STRING ASSIGN VAR BIN_OP VAR VAR STRING IF BIN_OP VAR VAR FUNC_CALL VAR VAR VAR VAR STRING ASSIGN VAR BIN_OP VAR VAR STRING ASSIGN VAR FUNC_CALL VAR VAR VAR VAR IF VAR EXPR FUNC_CALL VAR FUNC_CALL STRING VAR RETURN EXPR FUNC_CALL VAR NUMBER FUNC_DEF FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER 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 IF VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR RETURN NUMBER RETURN NUMBER 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 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, stdout input = stdin.readline for _ in range(int(input())): s = input().strip() x = int(input()) w = ["1"] * len(s) for idx, ch in enumerate(s): if ch == "0": if idx - x >= 0: w[idx - x] = "0" if idx + x <= len(s) - 1: w[idx + x] = "0" w = "".join(w) for idx, ch in enumerate(s): if ch == "1": if idx - x < 0 and idx + x > len(s) - 1: print(-1) break if idx - x >= 0 and idx + x > len(s) - 1 and w[idx - x] != "1": print(-1) break if idx + x < len(s) and idx - x < 0 and w[idx + x] != "1": print(-1) break if (idx + x < len(s) and w[idx + x] != "1") and ( idx - x >= 0 and w[idx - x] != "1" ): print(-1) break else: print(w)
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 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 BIN_OP FUNC_CALL VAR VAR NUMBER ASSIGN VAR BIN_OP VAR VAR STRING ASSIGN VAR FUNC_CALL STRING VAR FOR VAR VAR FUNC_CALL VAR VAR IF VAR STRING IF BIN_OP VAR VAR NUMBER BIN_OP VAR VAR BIN_OP FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR NUMBER IF BIN_OP VAR VAR NUMBER BIN_OP VAR VAR BIN_OP FUNC_CALL VAR VAR NUMBER VAR BIN_OP VAR VAR STRING EXPR FUNC_CALL VAR NUMBER IF BIN_OP VAR VAR FUNC_CALL VAR VAR BIN_OP VAR VAR NUMBER VAR BIN_OP VAR VAR STRING EXPR FUNC_CALL VAR NUMBER IF BIN_OP VAR VAR FUNC_CALL VAR VAR VAR BIN_OP VAR VAR STRING BIN_OP VAR VAR NUMBER VAR BIN_OP VAR VAR STRING 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
t = int(input()) for i in range(t): s = input() x = int(input()) w = ["1"] * len(s) for j in range(len(s)): if s[j] == "0": if j + x < len(s): w[j + x] = "0" if j - x >= 0: w[j - x] = "0" c = 0 for j in range(len(s)): if s[j] == "1": if j + x < len(s) and w[j + x] == "1": continue elif j - x >= 0 and w[j - x] == "1": continue else: c = -1 break if s[j] == "0": if j + x < len(s): if w[j + x] != "0": c = -1 break if j - x >= 0: if w[j - x] != "0": c = -1 break r = "" r = r.join(w) if c == -1: print(c) else: print(r)
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 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 STRING IF BIN_OP VAR VAR NUMBER 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 FUNC_CALL VAR VAR VAR BIN_OP VAR VAR STRING IF BIN_OP VAR VAR NUMBER VAR BIN_OP VAR VAR STRING ASSIGN VAR NUMBER IF VAR VAR STRING IF BIN_OP VAR VAR FUNC_CALL 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 ASSIGN VAR STRING ASSIGN VAR FUNC_CALL VAR VAR IF VAR NUMBER EXPR 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
for _ in range(int(input())): s = input() x = int(input()) w = [] w = [-1] * len(s) n = len(s) flag = False for i in range(n): if s[i] == "0": if i - x >= 0: w[i - x] = 0 if i + x <= n - 1: w[i + x] = 0 for i in range(n): if s[i] == "1": if i - x >= 0: if w[i - x] == 0: if i + x < n: if w[i + x] == 0: flag = True break else: flag = True break elif i + x < n: if w[i + x] == 0: flag = True break else: flag = True break if flag: print(-1) else: for i in range(n): if w[i] == -1: w[i] = 1 print(w[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 LIST ASSIGN VAR BIN_OP LIST NUMBER FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR 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 IF VAR BIN_OP VAR VAR NUMBER IF BIN_OP VAR VAR VAR IF VAR BIN_OP VAR VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER IF BIN_OP VAR VAR VAR IF VAR BIN_OP VAR VAR NUMBER ASSIGN 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 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
for u in range(int(input())): s = input() n = len(s) x = int(input()) d = ["1"] * n f = 0 for i in range(n): if s[i] == "0": if i + x < n: d[i + x] = "0" if i - x >= 0: d[i - x] = "0" for i in range(n): c = 0 if s[i] == "1": if i + x < n: if d[i + x] == "1": c = 1 if i - x >= 0: if d[i - x] == "1": c = 1 if c == 0: f = 1 break if f == 0: print("".join(d)) 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 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 IF VAR VAR STRING 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 ASSIGN VAR NUMBER IF VAR NUMBER 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 main(): s = input() n = len(s) x = int(input()) t = ["1"] * n for i in range(n): if 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 s[i] == "1": one = False if i - x >= 0: if t[i - x] == "1": one = True if i + x < n: if t[i + x] == "1": one = True if one == False: print("-1") return print("".join(t)) for _ in range(int(input())): main()
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 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 IF 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 VAR NUMBER EXPR FUNC_CALL VAR STRING RETURN EXPR FUNC_CALL VAR FUNC_CALL STRING VAR 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
tests = int(input()) for t in range(tests): string = list(input()) x = int(input()) string_len = len(string) res = [(-1) for _ in range(string_len)] check = True for idx, item in enumerate(string): if item == "0": if idx >= x: if res[idx - x] == -1 or res[idx - x] == 0: res[idx - x] = 0 else: check = False break if idx <= string_len - x - 1: if res[idx + x] == -1 or res[idx + x] == 0: res[idx + x] = 0 else: check = False break if item == "1": if idx >= x: if res[idx - x] == -1 or res[idx - x] == 1: res[idx - x] = 1 elif idx <= string_len - x - 1 and ( res[idx + x] == -1 or res[idx + x] == 1 ): res[idx + x] = 1 else: check = False break elif idx <= string_len - x - 1: if res[idx + x] == -1 or res[idx + x] == 1: res[idx + x] = 1 else: check = False break else: check = False break if not check: print(-1) else: for idx in range(string_len): if res[idx] == -1: res[idx] = 1 res = list(map(str, res)) print("".join(res))
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 NUMBER VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR VAR FUNC_CALL VAR VAR IF VAR STRING IF VAR VAR 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 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 STRING IF VAR VAR IF VAR BIN_OP VAR VAR NUMBER VAR BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP VAR VAR NUMBER IF VAR BIN_OP 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 NUMBER IF VAR BIN_OP 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 EXPR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR 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
for _ in range(int(input())): s = [x for x in input()] h = s.copy() n = int(input()) dicti = {} come = 0 for i in range(len(s)): if s[i] == "0": if i < n and i > len(s) - n - 1: continue elif i < n: h[i + n] = "0" if i + n not in dicti: dicti[i + n] = 0 elif i > len(s) - n - 1: h[i - n] = "0" if i - n not in dicti: dicti[i - n] = 0 else: h[i - n] = "0" h[i + n] = "0" if i + n not in dicti: dicti[i + n] = 0 if i - n not in dicti: dicti[i - n] = 0 for i in range(len(s)): if s[i] == "1": if i < n and i > len(s) - 1 - n: come = 1 break elif i < n: if i + n in dicti: come = 1 break else: h[i + n] = "1" elif i > len(s) - 1 - n: if i - n in dicti: come = 1 break else: h[i - n] = "1" elif i - n in dicti and i + n in dicti: come = 1 break elif i - n in dicti: h[i + n] = "1" elif i + n in dicti: h[i - n] = "1" else: h[i - n] = "1" h[i + n] = "1" if come == 1: print(-1) else: hh = "" print(hh.join(h))
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR DICT ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR STRING IF VAR VAR VAR BIN_OP BIN_OP FUNC_CALL VAR VAR VAR NUMBER IF VAR VAR ASSIGN VAR BIN_OP VAR VAR STRING IF BIN_OP VAR VAR VAR ASSIGN VAR BIN_OP VAR VAR NUMBER IF VAR BIN_OP BIN_OP FUNC_CALL VAR VAR VAR NUMBER ASSIGN VAR BIN_OP VAR VAR STRING IF BIN_OP VAR VAR VAR ASSIGN VAR BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP VAR VAR STRING ASSIGN VAR BIN_OP VAR VAR STRING IF BIN_OP VAR VAR VAR 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 FUNC_CALL VAR VAR IF VAR VAR STRING IF VAR VAR VAR BIN_OP BIN_OP FUNC_CALL VAR VAR NUMBER VAR ASSIGN VAR NUMBER IF VAR VAR IF BIN_OP VAR VAR VAR ASSIGN VAR NUMBER ASSIGN VAR BIN_OP VAR VAR STRING IF VAR BIN_OP BIN_OP FUNC_CALL VAR VAR NUMBER VAR IF BIN_OP VAR VAR VAR ASSIGN VAR NUMBER ASSIGN VAR BIN_OP VAR VAR STRING IF BIN_OP VAR VAR VAR BIN_OP VAR VAR VAR ASSIGN VAR NUMBER IF BIN_OP VAR VAR VAR ASSIGN VAR BIN_OP VAR VAR STRING IF BIN_OP VAR VAR VAR ASSIGN VAR BIN_OP VAR VAR STRING ASSIGN VAR BIN_OP VAR VAR STRING ASSIGN VAR BIN_OP VAR VAR STRING IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER ASSIGN VAR STRING EXPR FUNC_CALL 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()) for i in range(t): s = input() n = int(input()) l = len(s) arr = ["1"] * l flag = 1 for i in range(l): if s[i] == "0": if i - n >= 0: arr[i - n] = "0" if i + n < l: arr[i + n] = "0" for i in range(l): if s[i] == "1": slag = 0 if i - n >= 0 and arr[i - n] == "1": slag = 1 if i + n < l and arr[i + n] == "1": slag = 1 if slag == 0: print(-1) flag = 0 break if flag == 1: s1 = "" for i in range(l): s1 = s1 + arr[i] print(s1)
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 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 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 BIN_OP VAR VAR STRING ASSIGN VAR NUMBER IF BIN_OP VAR VAR VAR VAR BIN_OP VAR VAR STRING ASSIGN VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER IF VAR NUMBER ASSIGN VAR STRING FOR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP 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
def process(): li = list(input()) x = int(input()) n = len(li) ans = ["1" for i in range(n)] for i in range(0, n): if li[i] == "0": if i - x >= 0: ans[i - x] = "0" if i + x < n: ans[i + x] = "0" for i in range(0, n): chr = "0" if i - x >= 0 and ans[i - x] == "1": chr = "1" if i + x < n and ans[i + x] == "1": chr = "1" if li[i] == chr: pass else: print(-1) return print("".join(ans)) tests = int(input()) for i in range(tests): process()
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 STRING VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR NUMBER 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 NUMBER 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 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
from sys import * ws = lambda: map(int, stdin.readline().strip().split()) li = lambda: list(map(int, stdin.readline().strip().split())) mod = 1000000007 def ncr(n, r, p): num = den = 1 for i in range(r): num = num * (n - i) % p den = den * (i + 1) % p return num * pow(den, p - 2, p) % p def gcd(a, b): if b == 0: return a return gcd(b, a % b) def prod(l): ans = 1 for i in range(len(l)): ans = ans * l[i] return ans for testcases in range(int(input())): a = list(map(int, list(stdin.readline().strip()))) b = int(input()) c = len(a) ans = [1] * c for i in range(c): if a[i] == 0: if i + b < c: ans[i + b] = 0 if i - b >= 0: ans[i - b] = 0 flag = 1 for i in range(c): flags = 0 if i + b < c: flags += ans[i + b] if i - b >= 0: flags += ans[i - b] if a[i] == 1 and flags == 0: flag = -1 break if flag == -1: print(-1) else: for m in ans: print(m, end="") print()
ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER FUNC_DEF ASSIGN VAR VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR BIN_OP VAR VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR BIN_OP VAR NUMBER VAR RETURN BIN_OP BIN_OP VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER VAR VAR FUNC_DEF IF VAR NUMBER RETURN VAR RETURN FUNC_CALL VAR VAR BIN_OP VAR VAR FUNC_DEF ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR VAR VAR 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 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 NUMBER 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 ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER IF BIN_OP VAR VAR VAR VAR VAR BIN_OP VAR VAR IF BIN_OP VAR VAR NUMBER VAR VAR BIN_OP VAR VAR IF VAR VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER 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()) for j 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 >= 0: w[i - x] = "0" if i + x < n: w[i + x] = "0" p = [-1] * n for i in range(n): if i >= x and w[i - x] == "1": p[i] = "1" elif i + x < n and w[i + x] == "1": p[i] = "1" else: p[i] = "0" s1 = "" for i in p: s1 += i if s1 != s: print(-1, end="") else: for i in w: print(i, 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 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 NUMBER VAR FOR VAR FUNC_CALL VAR VAR IF VAR VAR 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 VAR STRING ASSIGN VAR STRING FOR VAR VAR VAR VAR IF VAR VAR EXPR FUNC_CALL VAR NUMBER STRING 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()) for i in range(t): s = input() x = int(input()) n = len(s) l = ["2"] * n check = True for i in range(n): if s[i] == "1": if i - x < 0 and i + x < n: if l[i + x] == "0": check = False l[i + x] = "1" if i + x >= n and i - x >= 0: if l[i - x] == "0": check = False l[i - x] = "1" else: if i - x >= 0: if l[i - x] == "1": check = False l[i - x] = "0" if i + x < n: if l[i + x] == "1": check = False l[i + x] = "0" nat = -1 if check == True: for i in range(n): if s[i] == "1": t = 0 z = 0 if i - x >= 0: z += 1 if l[i - x] == "0": t += 1 if i + x < n: z += 1 if l[i + x] == "0": t += 1 if t == z: check = False if check == True: nat = "" for i in range(n): if l[i] != "0": nat += "1" else: nat += "0" print(nat)
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 ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR STRING IF BIN_OP VAR VAR NUMBER 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 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 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 ASSIGN VAR NUMBER IF VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR STRING ASSIGN VAR NUMBER ASSIGN VAR NUMBER IF BIN_OP VAR VAR NUMBER VAR NUMBER IF VAR BIN_OP VAR VAR STRING VAR NUMBER IF BIN_OP VAR VAR VAR VAR NUMBER IF VAR BIN_OP VAR VAR STRING VAR NUMBER IF VAR VAR ASSIGN VAR NUMBER IF VAR NUMBER ASSIGN VAR STRING FOR VAR FUNC_CALL VAR VAR IF VAR VAR STRING VAR STRING VAR STRING 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()) output = ["0"] * T for t in range(T): s = input() n = len(s) x = int(input()) w = ["1"] * n s_new = ["0"] * n for i, si in enumerate(s): if si == "0": if i >= x: w[i - x] = "0" if i + x < n: w[i + x] = "0" for i in range(n): if i >= x and w[i - x] == "1" or i + x < n and w[i + x] == "1": s_new[i] = "1" output[t] = "".join(w) if s == "".join(s_new) else "-1" print("\n".join(output))
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR BIN_OP LIST STRING 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 BIN_OP LIST STRING VAR FOR VAR VAR FUNC_CALL VAR VAR IF 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 VAR BIN_OP VAR VAR STRING BIN_OP VAR VAR VAR VAR BIN_OP VAR VAR STRING ASSIGN VAR VAR STRING ASSIGN VAR VAR VAR FUNC_CALL STRING VAR FUNC_CALL STRING 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()) while t: s = input() x = int(input()) n = len(s) l1 = ["2" for i in range(0, n)] check = 0 for i in range(0, n): if i + x < n and i - x > -1: if s[i] == "0": if l1[i - x] == "1" or l1[i + x] == "1": check = 1 break else: l1[i - x] = "0" l1[i + x] = "0" elif l1[i - x] != "0" or l1[i + x] != "0": if l1[i - x] != "0": l1[i - x] = "1" elif l1[i + x] != "0": l1[i + x] = "1" else: check = 1 break elif i + x < n: if l1[i + x] == "2": l1[i + x] = s[i] elif l1[i + x] != s[i]: check = 1 break elif i - x > -1: if l1[i - x] == "2": l1[i - x] = s[i] elif l1[i - x] != s[i]: check = 1 break elif s[i] == "1": check = 1 break if check: print(-1) else: for i in range(0, n): if l1[i] == "2": l1[i] = "1" w = "" w = w.join(l1) print(w) t = t - 1
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR WHILE 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 NUMBER VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR IF BIN_OP VAR VAR VAR BIN_OP VAR VAR NUMBER IF VAR VAR STRING IF VAR BIN_OP VAR VAR STRING VAR BIN_OP VAR VAR STRING ASSIGN VAR NUMBER ASSIGN VAR BIN_OP VAR VAR STRING ASSIGN VAR BIN_OP VAR VAR STRING IF VAR BIN_OP VAR VAR STRING 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 ASSIGN VAR NUMBER IF BIN_OP VAR 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 BIN_OP VAR VAR NUMBER 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 VAR STRING ASSIGN VAR NUMBER IF VAR EXPR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR IF VAR VAR STRING ASSIGN VAR VAR STRING ASSIGN VAR STRING ASSIGN VAR FUNC_CALL 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 fun(): s = input() x = int(input()) ls = [(1) for i in range(len(s))] for i in range(len(s)): if s[i] == "0": if i - x >= 0: ls[i - x] = 0 if i + x < len(s): ls[i + x] = 0 f = True for i in range(len(s)): if s[i] == "1": f2 = False if i - x >= 0 and ls[i - x] == 1: f2 = True if i + x < len(s) and ls[i + x] == 1: f2 = True if f2 == False: f = False if f == True: str = "" for i in range(len(s)): if ls[i] == 1: str += "1" else: str += "0" return str return "-1" def solve(): t = int(input()) for i in range(t): print(fun()) solve()
FUNC_DEF ASSIGN 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 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 NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR STRING ASSIGN VAR 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 VAR NUMBER ASSIGN VAR NUMBER IF VAR NUMBER ASSIGN VAR STRING FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR NUMBER VAR STRING VAR STRING RETURN VAR RETURN STRING FUNC_DEF ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR EXPR 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() x = int(input()) ans = ["1"] * len(s) for i in range(len(s)): if s[i] == "0": if i < len(s) - x: ans[i + x] = "0" if i >= x: ans[i - x] = "0" correct = True for j in range(len(s)): result = "0" if j < len(s) - x and ans[j + x] == "1": result = "1" if j >= x and ans[j - x] == "1": result = "1" if result != s[j]: correct = False if correct: print(*ans, 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 FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR STRING IF VAR BIN_OP FUNC_CALL VAR VAR VAR ASSIGN VAR BIN_OP VAR VAR STRING IF VAR VAR ASSIGN VAR BIN_OP VAR VAR STRING ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR STRING IF VAR BIN_OP FUNC_CALL VAR VAR VAR VAR BIN_OP VAR VAR STRING ASSIGN VAR STRING IF VAR VAR VAR BIN_OP VAR VAR STRING ASSIGN VAR STRING IF VAR VAR VAR ASSIGN VAR NUMBER IF VAR EXPR FUNC_CALL VAR VAR STRING 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()) s = "" n = len(S) for i in range(n): if x <= i and S[i - x] == "0" or i < n - x and S[i + x] == "0": s += "0" else: s += "1" for i in range(n): if S[i] == "1": if x <= i and s[i - x] == "1" or i < n - x and s[i + x] == "1": continue else: s = -1 break print(s)
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 ASSIGN VAR FUNC_CALL VAR 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 VAR STRING VAR STRING FOR VAR FUNC_CALL VAR VAR IF VAR VAR STRING IF VAR VAR VAR BIN_OP VAR VAR STRING VAR BIN_OP VAR VAR VAR BIN_OP VAR VAR STRING ASSIGN 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
gans = [] for _ in range(int(input())): s = list(map(int, list(input()))) n = len(s) x = int(input()) 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 ok = False for i in range(n): if s[i] == 1: cur = [] if i - x >= 0: cur.append(w[i - x]) if i + x < n: cur.append(w[i + x]) if 1 not in cur: ok = True break if ok: gans.append("-1") else: gans.append("".join(map(str, w))) print("\n".join(gans))
ASSIGN VAR LIST 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 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 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 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 NUMBER VAR ASSIGN VAR NUMBER IF VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR FUNC_CALL STRING FUNC_CALL VAR VAR 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
import sys t = int(input()) def solve(): w = input() n = len(w) x = int(input()) print("[LOG] solve(w=", w, ", x=", x, ")", file=sys.stderr) def is_zero(pos): if pos <= 0 or pos > n: return True before = pos + x <= n and w[pos + x - 1] == "0" after = pos - x >= 1 and w[pos - x - 1] == "0" print( "[LOG] is_zero(", pos, ") returns (", before, ", ", after, ") =", before or after, file=sys.stderr, ) return before or after for i in range(1, n + 1): if w[i - 1] == "1": if is_zero(i - x) and is_zero(i + x): print(-1) break else: for i in range(1, n + 1): print(0 if is_zero(i) else 1, end="") print() for _ in range(t): solve()
IMPORT 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 EXPR FUNC_CALL VAR STRING VAR STRING VAR STRING VAR FUNC_DEF IF VAR NUMBER VAR VAR RETURN NUMBER ASSIGN VAR BIN_OP VAR VAR VAR VAR BIN_OP BIN_OP VAR VAR NUMBER STRING ASSIGN VAR BIN_OP VAR VAR NUMBER VAR BIN_OP BIN_OP VAR VAR NUMBER STRING EXPR FUNC_CALL VAR STRING VAR STRING VAR STRING VAR STRING VAR VAR VAR RETURN VAR VAR FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER IF VAR BIN_OP VAR NUMBER STRING IF FUNC_CALL VAR BIN_OP VAR VAR FUNC_CALL VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER NUMBER STRING EXPR 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
for _ in range(int(input())): s = input() x = int(input()) n = len(s) w = [""] * n f = True 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 s[i] == "1": ct = 0 if i >= x: if w[i - x] == "": w[i - x] = "1" ct += int(w[i - x]) if i < n - x: if w[i + x] == "": w[i + x] = "1" ct += int(w[i + x]) if ct == 0: f = False break if w[i] == "": w[i] = "1" print("".join(w) if f 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 FUNC_CALL VAR VAR ASSIGN VAR BIN_OP LIST STRING 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 VAR VAR ASSIGN VAR BIN_OP VAR VAR STRING FOR VAR FUNC_CALL VAR VAR IF VAR VAR STRING ASSIGN VAR NUMBER IF VAR VAR IF VAR BIN_OP VAR VAR STRING ASSIGN VAR BIN_OP VAR VAR STRING VAR FUNC_CALL VAR VAR BIN_OP VAR VAR IF VAR BIN_OP VAR VAR IF VAR BIN_OP VAR VAR STRING ASSIGN VAR BIN_OP VAR VAR STRING VAR FUNC_CALL VAR VAR BIN_OP VAR VAR IF VAR NUMBER ASSIGN VAR NUMBER IF VAR VAR STRING ASSIGN VAR VAR STRING 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 p in range(int(input())): st = input() x = int(input()) n = len(st) w = [1] * n for i in range(n): if st[i] == "0": if i - x >= 0: w[i - x] = 0 if i + x < n: w[i + x] = 0 ans = "" for i in range(n): if i - x >= 0 and w[i - x] == 1 or i + x < n and w[i + x] == 1: ans += "1" else: ans += "0" if ans == st: w = list(map(str, w)) print("".join(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 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 STRING FOR VAR FUNC_CALL VAR VAR IF BIN_OP VAR VAR NUMBER VAR BIN_OP VAR VAR NUMBER BIN_OP VAR VAR VAR VAR BIN_OP VAR VAR NUMBER VAR STRING VAR STRING IF VAR VAR ASSIGN VAR FUNC_CALL VAR 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
for _ in range(int(input())): s = input() x = int(input()) s = " " + s prev = [0] * (len(s) + 1) prev[0] = -1 prev[-1] = -1 for i in range(1, len(s)): if s[i] == "0": prev[max(i - x, 0)] = -1 prev[min(i + x, len(s))] = -1 ok = True for i in range(1, len(s)): if s[i] == "1" and prev[max(i - x, 0)] == -1 and prev[min(i + x, len(s))] == -1: print(-1) ok = False break if ok: for i in range(1, len(s)): print(prev[i] + 1, 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 BIN_OP STRING VAR ASSIGN VAR BIN_OP LIST NUMBER BIN_OP FUNC_CALL VAR VAR NUMBER ASSIGN VAR NUMBER NUMBER ASSIGN VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR IF VAR VAR STRING ASSIGN VAR FUNC_CALL VAR BIN_OP VAR VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR BIN_OP VAR VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR IF VAR VAR STRING VAR FUNC_CALL VAR BIN_OP VAR VAR NUMBER NUMBER VAR FUNC_CALL VAR BIN_OP VAR VAR FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER IF VAR FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR VAR NUMBER STRING 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
T = int(input()) for _ in range(T): S = input() N = int(input()) L = len(S) arr = [0] * L iszero = [False] * L for i in range(L): if S[i] == "0": if i - N >= 0: iszero[i - N] = True if i + N < L: iszero[i + N] = True used = False for i in range(L): if S[i] == "1": used = False if i - N >= 0: if not iszero[i - N]: used = True arr[i - N] = 1 if i + N < L: if not iszero[i + N]: used = True arr[i + N] = 1 if not used: print(-1) break else: for i in range(L): print(arr[i], 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 BIN_OP LIST NUMBER VAR 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 ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR STRING ASSIGN VAR NUMBER IF BIN_OP VAR VAR NUMBER IF VAR BIN_OP VAR VAR ASSIGN VAR NUMBER ASSIGN VAR BIN_OP VAR VAR NUMBER IF BIN_OP VAR VAR VAR IF VAR BIN_OP VAR VAR ASSIGN VAR NUMBER ASSIGN VAR BIN_OP VAR VAR NUMBER IF VAR EXPR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR VAR STRING 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
import sys input = sys.stdin.readline for _ in range(int(input())): s = list(input().strip()) n = len(s) x = int(input()) r = [-1] * n for i in range(n): if s[i] == "0": if i - x >= 0: r[i - x] = "0" if i + x < n: r[i + x] = "0" for i in range(n): if r[i] == -1: r[i] = "1" for i in range(n): if s[i] == "1": if i - x >= 0 and r[i - x] == "1" or i + x < n and r[i + x] == "1": continue print(-1) break else: print("".join(r))
IMPORT ASSIGN VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL 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 NUMBER 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 NUMBER ASSIGN VAR VAR STRING FOR 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 VAR VAR BIN_OP VAR VAR 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
t = int(input()) while t > 0: s = input() x = int(input()) n = len(s) def helper(n, s, x): w = "1" * n w = list(w) 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): if s[i] == "1": if i + x < n and w[i + x] == "1" or i - x >= 0 and w[i - x] == "1": continue else: return -1 elif i + x < n and w[i + x] == "1" or i - x >= 0 and w[i - x] == "1": return -1 return "".join(w) print(helper(n, s, x)) t -= 1
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 FUNC_DEF ASSIGN VAR BIN_OP STRING 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 STRING IF BIN_OP VAR VAR VAR VAR BIN_OP VAR VAR STRING BIN_OP VAR VAR NUMBER VAR BIN_OP VAR VAR STRING RETURN NUMBER IF BIN_OP VAR VAR VAR VAR BIN_OP VAR VAR STRING BIN_OP VAR VAR NUMBER VAR BIN_OP VAR VAR STRING RETURN NUMBER RETURN FUNC_CALL STRING VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR 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 def input(): return sys.stdin.readline().rstrip("\r\n") def maps(): return [int(i) for i in input().split()] def check(s, w, n, x): for i in range(n): ok = False if s[i] == "1": if i >= x and w[i - x] == "1": ok = True elif i + x < n and w[i + x] == "1": ok = True elif i - x < 0 and i + x >= n: ok = True elif i - x >= 0 and i + x < n: if w[i - x] == w[i + x] == "0": ok = True elif i >= x and w[i - x] == "0": ok = True elif i + x < n and w[i + x] == "0": ok = True if not ok: return False return True for _ in range(*maps()): s = input() n = len(s) (x,) = maps() 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" if check(s, w, n, x): print("".join(w)) else: print("-1")
IMPORT FUNC_DEF RETURN FUNC_CALL FUNC_CALL VAR STRING FUNC_DEF RETURN FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR FUNC_DEF FOR VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER IF VAR VAR STRING IF VAR VAR VAR BIN_OP VAR VAR STRING ASSIGN VAR NUMBER IF BIN_OP VAR VAR VAR VAR BIN_OP VAR VAR STRING ASSIGN VAR NUMBER 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 IF VAR BIN_OP VAR VAR VAR BIN_OP VAR VAR STRING ASSIGN VAR NUMBER IF VAR VAR VAR BIN_OP VAR VAR STRING ASSIGN VAR NUMBER IF BIN_OP VAR VAR VAR VAR BIN_OP VAR VAR STRING ASSIGN VAR NUMBER IF VAR RETURN NUMBER RETURN NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR BIN_OP LIST STRING VAR 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 IF FUNC_CALL VAR VAR VAR 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
t = int(input()) for i in range(t): s = input() n = len(s) x = int(input()) w = ["1" for j in range(n)] for j in range(n - x): if s[j + x] == "0": w[j] = "0" f = True for j in range(x, n): if s[j - x] == "0": w[j] = "0" for j in range(n): if n > j + x: if s[j] == "1" and w[j + x] == "0": if j - x >= 0 and w[j - x] == "0" or j - x < 0: f = False elif j - x >= 0: if s[j] == "1" and w[j - x] == "0": f = False elif s[j] == "1": f = False if f: ans = "" for j in w: ans += j print(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 STRING VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR VAR IF VAR BIN_OP VAR VAR STRING ASSIGN VAR VAR STRING ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR VAR IF VAR BIN_OP VAR VAR STRING ASSIGN VAR VAR STRING FOR VAR FUNC_CALL VAR VAR IF VAR BIN_OP VAR VAR IF VAR VAR STRING VAR BIN_OP VAR VAR STRING IF BIN_OP VAR VAR NUMBER VAR BIN_OP VAR VAR STRING BIN_OP VAR VAR NUMBER ASSIGN VAR NUMBER IF BIN_OP VAR VAR NUMBER IF VAR VAR STRING VAR BIN_OP VAR VAR STRING ASSIGN VAR NUMBER IF VAR VAR STRING ASSIGN VAR NUMBER IF VAR ASSIGN VAR STRING FOR VAR 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
def solve(s, x, n, w): for i in range(n): if s[i] == "0": if i >= x: w[i - x] = "0" if i + x < n: w[i + x] = "0" for i in range(n): if s[i] == "1": works = False if i >= x: if w[i - x] == "1": works = True if i + x < n: if w[i + x] == "1": works = True if not works: return -1 return "".join(w) t = int(input()) for t in range(t): s = input() x = int(input()) n = len(s) w = ["1" for i in range(n)] result = solve(s, x, n, w) print(result)
FUNC_DEF 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 ASSIGN VAR NUMBER IF VAR VAR IF 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 VAR RETURN NUMBER 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 ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR STRING VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR 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
for _ in range(int(input())): s = list(map(int, list(input()))) n = len(s) x = int(input()) res = [1] * 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 bad = False for i in range(n): acc = 0 if i + x < n: acc += res[i + x] if i - x >= 0: acc += res[i - x] if s[i] == 1 and acc == 0: bad = True break if bad: print(-1) else: print("".join(map(str, res)))
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 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 NUMBER 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 ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER IF BIN_OP VAR VAR VAR VAR VAR BIN_OP VAR VAR IF BIN_OP VAR VAR NUMBER VAR VAR BIN_OP VAR VAR IF VAR VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER IF 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
t = int(input()) while t: s = input() n = len(s) x = int(input()) a = ["_" for i in range(n)] for i in range(n): if s[i] == "0": if i - x >= 0: a[i - x] = "0" if i + x < n: a[i + x] = "0" flag = True for i in range(n): if s[i] == "1": if i - x >= 0 and a[i - x] == "_": a[i - x] = "1" if i + x < n and a[i + x] == "_": a[i + x] = "1" if (i < x or a[i - x] == "0") and (i + x >= n or a[i + x] == "0"): flag = False break if not flag: print(-1) else: for i in range(n): if a[i] == "_": a[i] = "0" print("".join(a)) t -= 1
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR WHILE 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 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 IF BIN_OP VAR VAR NUMBER 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 IF VAR VAR VAR BIN_OP VAR VAR STRING BIN_OP VAR VAR VAR VAR BIN_OP VAR VAR STRING ASSIGN VAR NUMBER IF VAR EXPR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR STRING ASSIGN VAR VAR STRING EXPR FUNC_CALL 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
import sys def controller(s, x): n = len(s) s = tuple(i == "1" for i in s) w = [None] * n constraints = [] for i, si in enumerate(s): a = i - x b = i + x has_a = 0 <= a has_b = b < n if has_a: if has_b: if si: constraints.append(i) else: if w[a] is None: w[a] = False elif w[a] is True: return -1 if w[b] is None: w[b] = False elif w[b] is True: return -1 elif w[a] is None: w[a] = si elif w[a] is not si: return -1 elif has_b: if w[b] is None: w[b] = si elif w[b] is not si: return -1 elif si: return -1 for i in constraints: a = w[i - x] b = w[i + x] if a is True or b is True: pass elif a is False and b is False: return -1 return "".join("0" if i is False else "1" for i in w) def c_in(): import sys file = sys.stdin n_test_case = int(file.readline()) for i in range(n_test_case): s = file.readline().rstrip() x = int(file.readline()) print(controller(s, x)) c_in()
IMPORT FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR STRING VAR VAR ASSIGN VAR BIN_OP LIST NONE VAR ASSIGN VAR LIST FOR VAR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR NUMBER VAR ASSIGN VAR VAR VAR IF VAR IF VAR IF VAR EXPR FUNC_CALL VAR VAR IF VAR VAR NONE ASSIGN VAR VAR NUMBER IF VAR VAR NUMBER RETURN NUMBER IF VAR VAR NONE ASSIGN VAR VAR NUMBER IF VAR VAR NUMBER RETURN NUMBER IF VAR VAR NONE ASSIGN VAR VAR VAR IF VAR VAR VAR RETURN NUMBER IF VAR IF VAR VAR NONE ASSIGN VAR VAR VAR IF VAR VAR VAR RETURN NUMBER IF VAR RETURN NUMBER FOR VAR VAR ASSIGN VAR VAR BIN_OP VAR VAR ASSIGN VAR VAR BIN_OP VAR VAR IF VAR NUMBER VAR NUMBER IF VAR NUMBER VAR NUMBER RETURN NUMBER RETURN FUNC_CALL STRING VAR NUMBER STRING STRING VAR VAR FUNC_DEF 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 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
t = int(input()) for _ in range(t): flag = True w = str(input()) x = int(input()) s = [-1] * len(w) for i, ch in enumerate(w): if ch == "0": if i - x >= 0: s[i - x] = 0 if i + x < len(w): s[i + x] = 0 for i, ch in enumerate(w): if ch == "1": if i - x < 0 and i + x < len(w): if s[i + x] == 0: flag = 0 break else: s[i + x] = 1 elif i - x >= 0 and i + x >= len(w): if s[i - x] == 0: flag = 0 break else: s[i - x] = 1 elif i - x >= 0 and i + x < len(w): if s[i - x] == 0 and s[i + x] == 0: flag = 0 break elif s[i - x] == 0: s[i + x] = 1 elif s[i + x] == 0: s[i - x] = 1 else: s[i + x] = 1 s[i - x] = 1 for i, ch in enumerate(s): if s[i] == -1 and w[i] == "1": flag = 0 if flag == False: print(-1) else: for i in s: if i == -1: print(0, end="") else: print(i, end="") print(end="\n")
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER 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 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 FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR VAR NUMBER FOR VAR VAR FUNC_CALL VAR VAR IF VAR STRING IF BIN_OP VAR VAR NUMBER 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 BIN_OP VAR VAR NUMBER 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 BIN_OP VAR VAR NUMBER BIN_OP VAR VAR FUNC_CALL VAR VAR 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 ASSIGN VAR BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP VAR VAR NUMBER FOR VAR VAR FUNC_CALL VAR VAR IF VAR VAR NUMBER VAR VAR STRING ASSIGN VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER FOR VAR VAR IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER STRING EXPR FUNC_CALL VAR VAR STRING 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() 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 > -1: w[i - x] = "0" check = ["0"] * n for i in range(n): if i - x > -1 and w[i - x] == "1": check[i] = "1" elif i + x < n and w[i + x] == "1": check[i] = "1" ans = "".join(check) if s == ans: print("".join(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 VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL 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 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 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()) while T > 0: str = [] w = input() x = int(input()) n = len(w) - 1 flag = False for i in range(0, 2 * n + 1): str.append(-1) for i in range(0, x): for j in range(i, n + 1, x): if j == i: if j + x > n and w[j] == "1": flag = False break elif j + x > n: break str[j + x] = int(w[j]) continue if w[j] == "0": if str[j - x] == 1: flag = False break str[j - x] = 0 str[j + x] = 0 else: if str[j - x] == 1: continue if str[j - x] == -1: str[j - x] = 1 else: str[j + x] = 1 for i in range(0, n + 1): if str[i] == -1: str[i] = 0 res = "" for i in range(0, n + 1): if i - x >= 0 and str[i - x] == 1 or i + x <= n and str[i + x] == 1: res += "1" else: res += "0" if res != w: print(-1) else: for i in range(0, n + 1): print(str[i], end="") print() T -= 1
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR WHILE VAR NUMBER ASSIGN VAR LIST ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP BIN_OP NUMBER VAR NUMBER EXPR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR FOR VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER VAR IF VAR VAR IF BIN_OP VAR VAR VAR VAR VAR STRING ASSIGN VAR NUMBER IF BIN_OP VAR VAR VAR ASSIGN VAR BIN_OP VAR VAR FUNC_CALL VAR VAR VAR IF VAR VAR STRING IF VAR BIN_OP VAR VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP VAR VAR NUMBER IF VAR BIN_OP VAR VAR NUMBER IF VAR BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP VAR VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER IF VAR VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR STRING FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER IF BIN_OP VAR VAR NUMBER VAR BIN_OP VAR VAR NUMBER BIN_OP VAR VAR VAR VAR BIN_OP VAR VAR NUMBER VAR STRING VAR STRING IF VAR VAR EXPR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR VAR STRING 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 _ in range(t): s = list(input()) x = int(input()) n = len(s) res = ["1"] * 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" flag = True for i in range(n): if s[i] == "1": a = True b = True if i + x >= n: b = False if i - x < 0: a = False if i + x < n and res[i + x] == "0": b = False if i - x >= 0 and res[i - x] == "0": a = False if a == False and b == False: flag = False break if flag == 0: print(-1) else: print("".join(res))
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 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 ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR STRING ASSIGN VAR NUMBER ASSIGN VAR NUMBER IF BIN_OP VAR VAR VAR ASSIGN VAR NUMBER IF BIN_OP VAR VAR NUMBER ASSIGN VAR NUMBER IF BIN_OP VAR VAR VAR VAR BIN_OP VAR VAR STRING ASSIGN VAR NUMBER IF BIN_OP VAR VAR NUMBER VAR BIN_OP VAR VAR STRING ASSIGN VAR NUMBER IF VAR NUMBER VAR NUMBER ASSIGN 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
t = int(input()) for tt in range(0, t): sti = input() s = list(sti) n = len(s) x = int(input()) ans = ["0"] * n for i in range(0, n): j = i - x fut = i + x if j >= 0 and fut < n: if s[j] == "1" and s[fut] == "1": ans[i] = "1" elif j >= 0: if s[j] == "1": ans[i] = "1" elif fut < n: if s[fut] == "1": ans[i] = "1" list2 = ["0"] * n for i in range(0, n): if ans[i] == "1": j = i - x fut = i + x if j >= 0: list2[j] = "1" if fut < n: list2[fut] = "1" if s == list2: print("".join(ans)) 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 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 NUMBER VAR ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP VAR VAR IF VAR NUMBER VAR VAR IF VAR VAR STRING VAR VAR STRING ASSIGN VAR VAR STRING IF VAR NUMBER IF VAR VAR STRING ASSIGN VAR VAR STRING IF VAR VAR IF VAR VAR STRING ASSIGN VAR VAR STRING ASSIGN VAR BIN_OP LIST STRING VAR FOR VAR FUNC_CALL VAR NUMBER VAR IF VAR VAR STRING ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP VAR VAR IF VAR NUMBER ASSIGN VAR VAR STRING IF VAR VAR ASSIGN VAR VAR STRING 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 case in range(t): s = list(map(int, list(input()))) x = int(input()) n = len(s) w = [1] * n for i in range(n): if s[i] == 0: if i + 1 > x: w[i - x] = 0 if i + 1 + x <= n: w[i + x] = 0 newS = [0] * n for i in range(n): if i + 1 > x and w[i - x] == 1: newS[i] = 1 if i + 1 + x <= n and w[i + x] == 1: newS[i] = 1 equal = True for i in range(n): if newS[i] != s[i]: equal = False break if equal: print("".join(map(str, 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 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 VAR VAR NUMBER IF BIN_OP VAR NUMBER VAR ASSIGN VAR BIN_OP VAR VAR NUMBER IF BIN_OP BIN_OP VAR NUMBER VAR VAR ASSIGN VAR BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER VAR FOR VAR FUNC_CALL VAR VAR IF BIN_OP VAR NUMBER VAR VAR BIN_OP VAR VAR NUMBER ASSIGN VAR VAR NUMBER IF BIN_OP BIN_OP VAR NUMBER VAR VAR VAR BIN_OP VAR VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR ASSIGN VAR NUMBER IF VAR 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
for _ in range(int(input())): s = input() x = int(input()) w1 = "1" * len(s) w = list(w1) f = 0 for i in range(len(s)): if s[i] == "0": if i - x >= 0 and i + x <= len(s) - 1: w[i - x] = "0" w[i + x] = "0" elif i - x < 0 and i + x <= len(s) - 1: w[i + x] = "0" elif i - x >= 0 and i + x > len(s) - 1: w[i - x] = "0" for i in range(len(s)): if s[i] == "1": if i - x >= 0 and i + x <= len(s) - 1: if w[i - x] == "0" and w[i + x] == "0": f = 1 elif i - x < 0 and i + x <= len(s) - 1: if w[i + x] == "0": f = 1 elif i - x >= 0 and i + x > len(s) - 1: if w[i - x] == "0": f = 1 else: f = 1 if f == 1: print(-1) else: print("".join(w))
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 STRING 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 FUNC_CALL VAR VAR NUMBER ASSIGN VAR BIN_OP VAR VAR STRING ASSIGN VAR BIN_OP VAR VAR STRING IF BIN_OP VAR VAR NUMBER BIN_OP VAR VAR BIN_OP FUNC_CALL VAR VAR NUMBER ASSIGN VAR BIN_OP VAR VAR STRING IF BIN_OP VAR VAR NUMBER BIN_OP VAR VAR BIN_OP FUNC_CALL VAR VAR NUMBER 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 BIN_OP VAR VAR BIN_OP FUNC_CALL VAR VAR NUMBER IF VAR BIN_OP VAR VAR STRING VAR BIN_OP VAR VAR STRING ASSIGN VAR NUMBER IF BIN_OP VAR VAR NUMBER BIN_OP VAR VAR BIN_OP FUNC_CALL VAR VAR NUMBER IF VAR BIN_OP VAR VAR STRING ASSIGN VAR NUMBER IF BIN_OP VAR VAR NUMBER BIN_OP VAR VAR BIN_OP FUNC_CALL VAR VAR NUMBER IF VAR BIN_OP VAR VAR STRING ASSIGN VAR NUMBER ASSIGN 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
for _ in range(int(input())): s = list(map(int, input())) x = int(input()) n = len(s) dp = [(-1) for i in range(n)] vis = [(0) for i in range(n)] f = 0 for i in range(n): if s[i] == 0: if i - x >= 0: dp[i - x] = 0 if i + x < n: dp[i + x] = 0 elif i + x < n: dp[i + x] = 0 for i in range(n): if s[i] == 1: if i - x >= 0: if dp[i - x] == -1 or dp[i - x] == 1: dp[i - x] = 1 elif i + x < n: if dp[i + x] == -1 or dp[i + x] == 1: dp[i + x] = 1 else: f = 1 else: f = 1 elif i + x < n: if dp[i + x] == -1 or dp[i + x] == 1: dp[i + x] = 1 else: f = 1 else: f = 1 for i in range(n): if dp[i] == -1: dp[i] = 0 if f == 1: print(-1) else: for i in dp: print(i, end="") print()
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 ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER 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 IF BIN_OP VAR VAR VAR ASSIGN VAR BIN_OP VAR VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF 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 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 ASSIGN VAR NUMBER ASSIGN 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 ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR NUMBER ASSIGN VAR VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER 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()) for _ in range(t): s = list(str(input())) x = int(input()) w = ["1" for _ in range(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" flag = False for i in range(len(s)): if s[i] == "1": if i - x >= 0 and i + x < len(s): if w[i - x] == "0" and w[i + x] == "0": flag = True elif i - x >= 0 and i + x >= len(s): if w[i - x] == "0": flag = True elif i - x < 0 and i + x < len(s): if w[i + x] == "0": flag = True elif i - x < 0 and i + x >= len(s): flag = True if flag == True: print(-1) else: res = "" for i in range(len(w)): res += w[i] print(res)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL 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 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 BIN_OP VAR VAR FUNC_CALL VAR VAR IF VAR BIN_OP VAR VAR STRING VAR BIN_OP VAR VAR STRING ASSIGN VAR NUMBER IF BIN_OP VAR VAR NUMBER BIN_OP VAR VAR FUNC_CALL VAR VAR IF VAR BIN_OP VAR VAR STRING ASSIGN VAR NUMBER IF BIN_OP VAR VAR NUMBER BIN_OP VAR VAR FUNC_CALL VAR VAR IF VAR BIN_OP VAR VAR STRING ASSIGN VAR NUMBER IF BIN_OP VAR VAR NUMBER BIN_OP VAR VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER ASSIGN VAR STRING FOR VAR FUNC_CALL VAR FUNC_CALL VAR 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("")) arr = [] x = [] for i in range(t): arr.append(input("")) x.append(int(input(""))) for i in range(t): s = list(arr[i]) y = x[i] n = len(s) dp = ["1"] * n flag = 0 for j in range(n): if s[j] == "0": if j - y >= 0: dp[j - y] = "0" if j + y < n: dp[j + y] = "0" sol = "" for j in range(n): flag = 0 if j - y >= 0: if dp[j - y] == "1": flag = 1 if j + y < n: if dp[j + y] == "1": flag = 1 if flag: sol += "1" else: sol += "0" if s == list(sol): print("".join(dp)) else: print(-1)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR STRING ASSIGN VAR LIST ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR STRING FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR FUNC_CALL VAR 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 STRING IF BIN_OP VAR VAR VAR ASSIGN VAR BIN_OP VAR VAR STRING ASSIGN VAR STRING FOR VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER IF BIN_OP VAR VAR NUMBER IF 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 VAR VAR STRING VAR STRING IF VAR FUNC_CALL 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
for _ in range(int(input())): s = input() x = int(input()) n = len(s) ans = ["1"] * n ok = 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): one = False one = one | (i > x - 1 and ans[i - x] == "1") one = one | (i + x < n and ans[i + x] == "1") if one: l = "1" else: l = "0" if s[i] != l: ok = False if ok: print("".join(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 FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR 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 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 BIN_OP VAR VAR BIN_OP VAR NUMBER VAR BIN_OP VAR VAR STRING ASSIGN VAR BIN_OP VAR BIN_OP VAR VAR VAR VAR BIN_OP VAR VAR STRING IF VAR ASSIGN VAR STRING ASSIGN VAR STRING IF VAR 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 run(s, x): n = len(s) ans = ["2" 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": flag = False if i - x >= 0: if ans[i - x] != "0": flag = True if i + x < n: if ans[i + x] != "0": flag = True if not flag: return ["-1"] for i in range(n): if ans[i] == "2": ans[i] = "1" return ans for _ in range(int(input())): s = input() x = int(input()) [print(i, end="") for i in run(s, x)] print()
FUNC_DEF 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 IF 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 VAR RETURN LIST STRING FOR VAR FUNC_CALL VAR VAR IF VAR VAR STRING ASSIGN VAR VAR STRING RETURN 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 EXPR FUNC_CALL VAR VAR STRING 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
for _ in range(int(input())): s = input() x = int(input()) n = len(s) w = ["1" for _ in range(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" check = True for i in range(n): if i >= x and w[i - x] == "1" or i + x < n and w[i + x] == "1": if s[i] != "1": check = False break elif s[i] != "0": check = False break if check: for i in w: print(i, end="") print() 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 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 BIN_OP VAR VAR VAR ASSIGN VAR BIN_OP VAR VAR STRING ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR BIN_OP VAR VAR STRING BIN_OP VAR VAR VAR VAR BIN_OP VAR VAR STRING 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 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
from sys import * input = stdin.readline for _ in range(int(input())): s = input() x = int(input()) n = len(s) - 1 w = ["-1"] * n for i in range(n): if s[i] == "0": if 0 <= i + x < n: w[i + x] = "0" if 0 <= i - x < n: w[i - x] = "0" flag = 1 for i in range(n): if s[i] == "1": c = 0 if 0 <= i + x < n and w[i + x] == "-1": c += 1 w[i + x] = "1" if 0 <= i - x < n and (w[i - x] == "-1" or w[i - x] == "1"): c += 1 w[i - x] = "1" if c == 0: flag = 0 if flag == 0: stdout.write("-1\n") else: for i in range(n): if w[i] == "-1": w[i] = "0" s = "".join(w) stdout.write(s + "\n")
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 NUMBER BIN_OP VAR VAR VAR ASSIGN VAR BIN_OP VAR VAR STRING IF NUMBER 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 NUMBER BIN_OP VAR VAR VAR VAR BIN_OP VAR VAR STRING VAR NUMBER ASSIGN VAR BIN_OP VAR VAR STRING IF NUMBER BIN_OP VAR VAR VAR VAR BIN_OP VAR VAR STRING VAR BIN_OP VAR VAR STRING VAR NUMBER ASSIGN VAR BIN_OP VAR VAR STRING IF VAR NUMBER ASSIGN VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR STRING FOR VAR FUNC_CALL VAR VAR IF VAR VAR STRING ASSIGN VAR VAR STRING ASSIGN VAR FUNC_CALL STRING 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
def solve(): T = int(input()) def f(s, x): res = ["0" for i in range(len(s))] for i in range(len(res)): if i - x >= 0 and s[i - x] == "1" or i + x < len(s) and s[i + x] == "1": res[i] = "1" else: res[i] = "0" return "".join(res) for i in range(T): w = input() x = int(input()) n = len(w) s = ["1" for _ in range(n)] for i, c in enumerate(w): l_index, r_index = i - x, i + x if c == "0": if l_index >= 0: s[l_index] = "0" if r_index < n: s[r_index] = "0" ns = "".join(s) if f(ns, x) == w: print(ns) else: print(str(-1)) solve()
FUNC_DEF ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_DEF ASSIGN VAR STRING 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 STRING BIN_OP VAR VAR FUNC_CALL VAR VAR VAR BIN_OP VAR VAR STRING ASSIGN VAR VAR STRING ASSIGN VAR VAR 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 ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR STRING VAR FUNC_CALL VAR VAR FOR VAR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR BIN_OP VAR VAR BIN_OP VAR VAR IF VAR STRING IF VAR NUMBER ASSIGN VAR VAR STRING IF VAR VAR ASSIGN VAR VAR STRING ASSIGN VAR FUNC_CALL STRING VAR IF FUNC_CALL VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR 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
dx = [0, 0, -1, 1] dy = [1, -1, 0, 0] 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 work = True 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 work = False if work: print("".join(map(str, ans))) else: print(-1) t = int(input()) for _ in range(t): s = input() x = int(input()) solve(s, x)
ASSIGN VAR LIST NUMBER NUMBER NUMBER NUMBER ASSIGN VAR LIST NUMBER NUMBER NUMBER NUMBER FUNC_DEF 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 NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR STRING IF BIN_OP VAR VAR NUMBER VAR BIN_OP VAR VAR NUMBER IF BIN_OP VAR VAR FUNC_CALL VAR VAR VAR BIN_OP VAR VAR NUMBER ASSIGN VAR NUMBER IF VAR EXPR FUNC_CALL VAR FUNC_CALL STRING FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR NUMBER 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 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 def inp(): return stdin.buffer.readline().rstrip().decode("utf8") def itg(): return int(stdin.buffer.readline()) def mpint(): return map(int, stdin.buffer.readline().split()) def solve(): s = inp() x = itg() n = len(s) w = ["1"] * n for i in range(n): if s[i] == "0": if 0 <= i - x < n: w[i - x] = "0" if 0 <= i + x < n: w[i + x] = "0" w = "".join(w) for i in range(n): if s[i] == "1": if not ( 0 <= i - x < n and w[i - x] == "1" or 0 <= i + x < n and w[i + x] == "1" ): return "-1" return w for __ in range(itg()): print(solve())
FUNC_DEF RETURN FUNC_CALL FUNC_CALL FUNC_CALL VAR STRING FUNC_DEF RETURN FUNC_CALL VAR FUNC_CALL VAR FUNC_DEF RETURN FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FUNC_DEF ASSIGN VAR FUNC_CALL VAR ASSIGN 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 NUMBER BIN_OP VAR VAR VAR ASSIGN VAR BIN_OP VAR VAR STRING IF NUMBER BIN_OP VAR VAR VAR ASSIGN VAR BIN_OP VAR VAR STRING ASSIGN VAR FUNC_CALL STRING VAR FOR VAR FUNC_CALL VAR VAR IF VAR VAR STRING IF NUMBER BIN_OP VAR VAR VAR VAR BIN_OP VAR VAR STRING NUMBER BIN_OP VAR VAR VAR VAR BIN_OP VAR VAR STRING RETURN STRING RETURN VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR EXPR 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
t = int(input()) for g in range(0, t): s = list(input()) a = [] for i in range(0, len(s)): a.append(-1) x = int(input()) ans = 1 for i in range(0, len(s)): if s[i] == "0": if i + x < len(s): a[i + x] = "0" if i - x >= 0: a[i - x] = "0" else: done = 0 if i - x >= 0: if a[i - x] == -1 or a[i - x] == "1": done = 1 a[i - x] = "1" if i + x < len(s) and done == 0: if a[i + x] == -1: done = 1 a[i + x] = "1" if done == 0: ans = 0 break if ans == 0: print(-1) else: ans = 1 for i in range(len(s)): if s[i] == "0": done = 1 if i + x < len(s) and a[i + x] != "0": done = 0 if i - x >= 0 and a[i - x] != "0": done = 0 if done == 0: ans = 0 break else: done = 0 if i + x < len(s) and a[i + x] == "1": done = 1 if i - x >= 0 and a[i - x] == "1": done = 1 if done == 0: ans = 0 break final = "" if ans == 0: print(-1) else: for i in range(0, len(s)): if a[i] == -1: a[i] = "1" final += a[i] print(final)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR EXPR FUNC_CALL VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR IF VAR 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 IF BIN_OP VAR VAR NUMBER IF VAR BIN_OP VAR VAR NUMBER 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 VAR NUMBER IF VAR BIN_OP VAR VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR BIN_OP VAR VAR STRING IF VAR NUMBER ASSIGN VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER ASSIGN 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 VAR BIN_OP VAR VAR STRING ASSIGN VAR NUMBER IF BIN_OP VAR VAR NUMBER VAR BIN_OP VAR VAR STRING ASSIGN VAR NUMBER IF VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER IF BIN_OP VAR VAR FUNC_CALL VAR VAR VAR BIN_OP VAR VAR STRING ASSIGN VAR NUMBER IF BIN_OP VAR VAR NUMBER VAR BIN_OP VAR VAR STRING ASSIGN VAR NUMBER IF VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR STRING IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR IF VAR VAR NUMBER ASSIGN VAR VAR STRING 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
for i in range(int(input())): s = list(str(input())) x = int(input()) ss = "1" * len(s) s = list(s) ss = list(ss) for i in range(len(s)): if s[i] == "0": if i - x >= 0 and i - x < len(s): ss[i - x] = "0" if i + x <= len(s) - 1 and i + x >= 0: ss[i + x] = "0" ansc = "0" * len(ss) ansc = list(ansc) for i in range(len(ss)): if ss[i] == "1": if i - x >= 0 and i - x < len(s): ansc[i - x] = "1" if i + x < len(s) and i + x >= 0: ansc[i + x] = "1" ansc = "".join(ansc) s = "".join(s) if ansc == s: an = "".join(ss) print(an) else: print(-1)
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR BIN_OP STRING FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR STRING IF BIN_OP VAR VAR NUMBER BIN_OP VAR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR VAR STRING IF BIN_OP VAR VAR BIN_OP FUNC_CALL VAR VAR NUMBER BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP VAR VAR STRING ASSIGN VAR BIN_OP STRING FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR STRING IF BIN_OP VAR VAR NUMBER BIN_OP VAR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR VAR STRING IF BIN_OP VAR VAR FUNC_CALL VAR VAR BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP VAR VAR STRING ASSIGN VAR FUNC_CALL STRING VAR ASSIGN VAR FUNC_CALL STRING VAR IF VAR VAR ASSIGN VAR FUNC_CALL STRING 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
from sys import stdin nii = lambda: map(int, stdin.readline().split()) lnii = lambda: list(map(int, stdin.readline().split())) t = int(input()) for tt in range(t): s = list(map(lambda x: int(x), list(input()))) 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: if (i - x < 0 or ans[i - x] == 0) and (i + x >= n or ans[i + x] == 0): ans = [-1] break print("".join([str(i) for i in ans]))
ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL 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 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 NUMBER 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 LIST 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
t = int(input()) while t: s = input() x = int(input()) ans = ["1" for i in range(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" ans2 = ["1" for i in range(len(ans))] for i in range(len(ans)): if (i < x or ans[i - x] == "0") and (i + x >= len(ans) or ans[i + x] == "0"): ans2[i] = "0" s2 = "".join(ans2) if s == s2: print("".join(ans)) else: print("-1") t = t - 1
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR WHILE 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 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 ASSIGN VAR STRING VAR FUNC_CALL VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR VAR BIN_OP VAR VAR STRING BIN_OP VAR VAR FUNC_CALL VAR VAR VAR BIN_OP 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 STRING 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
import sys sys.setrecursionlimit(10000) t = int(input()) for _ in range(t): s = input() x = int(input()) n = len(s) sed = False w = ["0"] * n fixed = [0] * n for i in range(x): if i + x < n: w[i + x] = s[i] fixed[i + x] = 1 elif s[i] == "1": sed = True break if sed is True: print("-1") continue sed = False for i in range(x, n): if s[i] == "1": if fixed[i - x] == 0 or w[i - x] == "1": w[i - x] = "1" fixed[i - x] = 1 elif i + x < n and (fixed[i + x] == 0 or w[i + x] == "1"): w[i + x] = "1" fixed[i + x] = 1 else: sed = True break elif w[i - x] == "1" or i + x < n and w[i + x] == "1": sed = True break else: fixed[i - x] = 1 if i + x < n: fixed[i + x] = 1 if sed is True: print("-1") else: print("".join(w))
IMPORT EXPR FUNC_CALL VAR NUMBER 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 BIN_OP LIST STRING VAR ASSIGN VAR BIN_OP LIST NUMBER VAR FOR VAR FUNC_CALL VAR VAR IF BIN_OP VAR VAR VAR ASSIGN VAR BIN_OP VAR VAR VAR VAR ASSIGN VAR BIN_OP VAR VAR NUMBER IF VAR VAR STRING ASSIGN VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR STRING ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR VAR IF VAR VAR STRING IF VAR BIN_OP VAR VAR NUMBER VAR BIN_OP VAR VAR STRING ASSIGN VAR BIN_OP VAR VAR STRING ASSIGN VAR BIN_OP VAR VAR NUMBER IF BIN_OP VAR VAR VAR VAR BIN_OP VAR VAR NUMBER VAR BIN_OP VAR VAR STRING ASSIGN VAR BIN_OP VAR VAR STRING ASSIGN VAR BIN_OP VAR VAR NUMBER ASSIGN VAR NUMBER IF VAR BIN_OP VAR VAR STRING BIN_OP VAR VAR VAR VAR BIN_OP VAR VAR STRING ASSIGN 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 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()) n = len(s) w = [1] * n for i in range(n): if i - x >= 0 and s[i] == "0": w[i - x] = 0 if i + x < n and s[i] == "0": w[i + x] = 0 f = 0 for i in range(n): if s[i] == "1": if i - x >= 0 and w[i - x] == 1 or i + x < n and w[i + x] == 1: continue else: f = 1 if f == 1: print(-1) else: for i in range(n): print(w[i], end="") print()
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 BIN_OP LIST NUMBER VAR FOR VAR FUNC_CALL VAR VAR IF BIN_OP VAR VAR NUMBER VAR VAR STRING ASSIGN VAR BIN_OP VAR VAR NUMBER IF BIN_OP VAR VAR VAR VAR VAR STRING ASSIGN VAR BIN_OP VAR VAR NUMBER 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 VAR NUMBER EXPR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR VAR 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
for _ in range(int(input())): s = input() x = int(input()) l = [1] * len(s) for i in range(len(s)): if s[i] == "0": if i + x < len(s): l[i + x] = 0 if i - x >= 0: l[i - x] = 0 ans = [0] * len(s) for i in range(len(s)): if l[i] == 1: flag = 0 if i + x < len(l): ans[i + x] = 1 if i - x >= 0: ans[i - x] = 1 s = list(map(int, s)) if ans == s: print(*l, 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 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 IF VAR VAR NUMBER 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 ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR 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
t = int(input()) for i in range(t): s = input() x = int(input()) l = len(s) val = ["1" for j in range(l)] for j in range(l): if s[j] == "0": if j - x >= 0: val[j - x] = "0" if j + x < l: val[j + x] = "0" f = 0 for j in range(l): if s[j] == "1": if j - x >= 0: f += int(val[j - x]) if j + x < l: f += int(val[j + x]) if f == 0: f = 1 break else: f = 0 if f == 0: print("".join(val)) 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 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 IF BIN_OP VAR VAR NUMBER VAR FUNC_CALL VAR VAR BIN_OP VAR VAR IF BIN_OP VAR VAR VAR VAR FUNC_CALL VAR VAR BIN_OP VAR VAR IF VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER IF VAR NUMBER 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 = str(input()) x = int(input()) n = len(s) temp = True ans = [(1) for l in range(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 for i in range(n): if s[i] == "1": if i < x and i + x >= n: temp = False break elif i >= x and i + x >= n and ans[i - x] == 0: temp = False break elif i < x and i + x < n and ans[i + x] == 0: temp = False break elif i >= x and i + x < n and ans[i + x] == 0 and ans[i - x] == 0: temp = False break else: pass if temp: ans = list(map(str, ans)) res = "".join(ans) print(res) 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 FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER VAR FUNC_CALL VAR 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 FOR VAR FUNC_CALL VAR VAR IF VAR VAR STRING IF VAR VAR BIN_OP VAR VAR VAR ASSIGN VAR NUMBER IF VAR VAR BIN_OP VAR VAR VAR VAR BIN_OP VAR VAR NUMBER ASSIGN VAR NUMBER IF VAR VAR BIN_OP VAR VAR VAR VAR BIN_OP VAR VAR NUMBER ASSIGN VAR NUMBER IF VAR VAR BIN_OP VAR VAR VAR VAR BIN_OP VAR VAR NUMBER VAR BIN_OP VAR VAR NUMBER ASSIGN VAR NUMBER IF VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL STRING 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
t = int(input()) for _ in range(t): s = list(input()) n = len(s) x = int(input()) ans = [1] * n flag = 0 for i in range(n): if s[i] == "0": if i + x < n: ans[x + i] = 0 if i - x >= 0: ans[i - x] = 0 res = [-1] * n for i in range(n): if i - x >= 0 and ans[i - x] == 1: res[i] = "1" elif i + x < n and ans[i + x] == 1: res[i] = "1" else: res[i] = "0" for i in range(n): if s[i] != res[i]: print(-1) flag = 1 break if flag: continue 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 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 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 VAR FOR VAR FUNC_CALL VAR VAR IF BIN_OP VAR VAR NUMBER VAR BIN_OP VAR VAR NUMBER ASSIGN VAR VAR STRING IF BIN_OP VAR VAR VAR VAR BIN_OP VAR VAR NUMBER ASSIGN VAR VAR STRING ASSIGN VAR VAR STRING FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR EXPR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER IF VAR 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())): str = input() x = int(input()) n = len(str) ans = ["1"] * n for i in range(n): if str[i] == "0": if i - x >= 0: ans[i - x] = "0" if i + x < n: ans[i + x] = "0" cnd = True for i in range(n): one = False one = one or i - x >= 0 and ans[i - x] == "1" one = one or i + x < n and ans[i + x] == "1" if str[i] != ("1" if one else "0"): print(-1) cnd = False break if cnd: for i in ans: print(i, end="") print("\n", end="")
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 NUMBER 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 VAR VAR STRING STRING EXPR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER IF VAR FOR VAR VAR EXPR FUNC_CALL VAR VAR STRING EXPR FUNC_CALL VAR STRING 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
n = int(input()) for i in range(1, n + 1): s = input() nn = len(s) x = int(input()) ans = "1" * nn for i in range(nn): if s[i] == "0": if i - x >= 0: index = i - x ans = ans[:index] + "0" + ans[index + 1 :] if i + x < nn: index = i + x ans = ans[:index] + "0" + ans[index + 1 :] ff = 0 for i in range(nn): flag = False flag = flag or i - x >= 0 and ans[i - x] == "1" flag = flag or i + x < nn and ans[i + x] == "1" if not flag: if s[i] == "1": print("-1") ff = 1 break if ff == 0: print(ans)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN 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 ASSIGN VAR BIN_OP BIN_OP VAR VAR STRING VAR BIN_OP VAR NUMBER IF BIN_OP VAR VAR VAR ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR STRING VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER 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 IF VAR VAR STRING EXPR FUNC_CALL VAR STRING ASSIGN VAR NUMBER IF 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
t = int(input()) for ii in range(t): s = input() x = int(input()) ans = [-1] * len(s) can = True for i in range(len(s)): back = i - x front = i + x sor = False if s[i] == "1": if back >= 0: if ans[back] == -1 or ans[back] == 1: ans[back] = 1 sor = True if not sor: if front < len(ans): if ans[front] == -1 or ans[front] == 1: ans[front] = 1 sor = True if not sor: can = False break else: if back >= 0: if ans[back] == 1: can = False break ans[back] = 0 if front < len(ans): if ans[front] == 1: can = False break ans[front] = 0 if not can: print(-1) else: for i in range(len(ans)): if ans[i] == -1: ans[i] = 1 print(ans[i], 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 BIN_OP LIST NUMBER FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR NUMBER IF VAR VAR STRING IF VAR NUMBER IF VAR VAR NUMBER VAR VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR NUMBER IF VAR IF VAR FUNC_CALL VAR VAR IF VAR VAR NUMBER VAR VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR NUMBER IF VAR ASSIGN VAR NUMBER IF VAR NUMBER IF VAR VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR VAR NUMBER IF VAR FUNC_CALL VAR VAR IF VAR VAR NUMBER ASSIGN VAR NUMBER ASSIGN 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 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 = input() x = int(input()) w = [-1] * len(s) for i in range(len(s)): ch = s[i] if ch == "0": if i - x >= 0: w[i - x] = 0 if i + x < len(s): w[i + x] = 0 for i in range(len(s)): ch = s[i] if ch == "1": if ( i - x < 0 and i + x >= len(s) or i - x >= 0 and w[i - x] == 0 and i + x >= len(s) or i - x < 0 and i + x < len(s) and w[i + x] == 0 or i - x >= 0 and i + x < len(s) and w[i + x] == 0 and w[i - x] == 0 ): print(-1) break else: for i in range(len(w)): if w[i] == -1: w[i] = 1 w[i] = str(w[i]) 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 NUMBER FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR IF 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 FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR IF VAR STRING IF BIN_OP VAR VAR NUMBER BIN_OP VAR VAR FUNC_CALL VAR VAR BIN_OP VAR VAR NUMBER VAR BIN_OP VAR VAR NUMBER BIN_OP VAR VAR FUNC_CALL VAR VAR BIN_OP VAR VAR NUMBER BIN_OP VAR VAR FUNC_CALL VAR VAR VAR BIN_OP VAR VAR NUMBER BIN_OP VAR VAR NUMBER BIN_OP VAR VAR FUNC_CALL VAR VAR VAR BIN_OP VAR VAR NUMBER VAR BIN_OP VAR 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 VAR FUNC_CALL VAR VAR 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(t): s = str(input()) x = int(input()) n = len(s) lis = [-1] * n z = 0 for j in range(n): if s[j] == "0": if j + x <= n - 1: lis[j + x] = 0 if j - x >= 0: lis[j - x] = 0 for j in range(n): if s[j] == "1": if j - x >= 0 and j + x <= n - 1: if lis[j - x] == 0 and lis[j + x] == 0: z += 1 break elif lis[j - x] == 0 and lis[j + x] != 0: lis[j + x] = 1 elif lis[j - x] != 0 and lis[j + x] == 0: lis[j - x] = 1 elif lis[j - x] != 0 and lis[j + x] != 0: lis[j - x] = 1 elif j - x >= 0 and j + x > n - 1: if lis[j - x] == 0: z += 1 break else: lis[j - x] = 1 elif j - x < 0 and j + x <= n - 1: if lis[j + x] == 0: z += 1 break else: lis[j + x] = 1 else: z += 1 break if z == 1: print(-1) else: ans = "" for j in range(n): if lis[j] == -1: ans += "1" else: ans += str(lis[j]) print(ans)
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 ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR STRING IF BIN_OP VAR VAR BIN_OP VAR NUMBER 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 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 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 IF VAR BIN_OP VAR VAR NUMBER VAR BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP VAR VAR NUMBER IF BIN_OP VAR VAR NUMBER BIN_OP VAR VAR BIN_OP VAR NUMBER IF VAR BIN_OP VAR VAR NUMBER VAR NUMBER ASSIGN VAR BIN_OP VAR VAR NUMBER IF BIN_OP VAR VAR NUMBER BIN_OP VAR VAR BIN_OP VAR NUMBER IF VAR BIN_OP VAR VAR NUMBER VAR NUMBER ASSIGN VAR BIN_OP VAR VAR NUMBER VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER ASSIGN VAR STRING FOR VAR FUNC_CALL VAR VAR IF VAR VAR NUMBER VAR STRING 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
test = int(input()) for _ in range(test): w = list(input()) x = int(input()) n = len(w) s = [-1] * n for i in range(n): w[i] = int(w[i]) if w[i] == 0: if i - x >= 0: s[i - x] = 0 if i + x < n: s[i + x] = 0 resflag = True for i in range(n): if w[i] == 1: flag = False if i - x >= 0 and s[i - x] != 0: flag = True s[i - x] = 1 if i + x < n and s[i + x] != 0: flag = True s[i + x] = 1 if flag == False: resflag = False break if resflag: for c in s: if c == 1 or c == 0: print(str(c), end="") else: print("1", end="") print() 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 VAR FUNC_CALL VAR 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 ASSIGN VAR NUMBER IF BIN_OP VAR VAR NUMBER VAR BIN_OP VAR VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR BIN_OP VAR VAR NUMBER IF BIN_OP VAR VAR VAR VAR BIN_OP VAR VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR BIN_OP VAR VAR NUMBER IF VAR NUMBER ASSIGN VAR NUMBER IF VAR FOR VAR VAR IF VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR STRING EXPR FUNC_CALL VAR STRING 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
def solve(): s = input() x = int(input()) w = ["."] * 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" for i in range(len(s)): if s[i] == "1": if i - x >= 0 and w[i - x] != "0": w[i - x] = "1" continue if i + x < len(s) and w[i + x] != "0": w[i + x] = "1" continue print(-1) return for i in range(len(s)): if w[i] == ".": w[i] = "1" print(*w, sep="") for t in range(int(input())): solve()
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 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 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 EXPR FUNC_CALL VAR NUMBER RETURN FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR STRING ASSIGN VAR VAR STRING 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
for _ in range(int(input())): s = input() x = int(input()) n = len(s) dp = [-1] * n flag = 0 for i in range(n): if s[i] == "0": if i - x >= 0: dp[i - x] = 0 if i + x < n: dp[i + x] = 0 def check(arr): for i in range(n): if s[i] == "1": if not ( i - x >= 0 and arr[i - x] != 0 or i + x < n and arr[i + x] != 0 ): return False return True if not check(dp): print(-1) else: for i in dp: if i == 0: print("0", end="") else: print("1", 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 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 FUNC_DEF 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 RETURN NUMBER RETURN NUMBER IF FUNC_CALL VAR VAR EXPR FUNC_CALL VAR NUMBER FOR VAR VAR IF VAR NUMBER EXPR FUNC_CALL VAR STRING STRING EXPR FUNC_CALL VAR STRING 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()) ans = ["1"] * len(s) fc = ["x"] * len(s) flag = 0 n = len(s) 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 i - x >= 0 and ans[i - x] == "1": fc[i] = "1" elif i + x < n and ans[i + x] == "1": fc[i] = "1" else: fc[i] = "0" fc = "".join(fc) if fc == s: ans = "".join(ans) print(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 FUNC_CALL VAR ASSIGN VAR BIN_OP LIST STRING FUNC_CALL VAR VAR ASSIGN VAR BIN_OP LIST STRING FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN 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 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 VAR STRING ASSIGN VAR FUNC_CALL STRING VAR IF VAR VAR ASSIGN VAR FUNC_CALL STRING 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
for i in range(int(input())): s = input() x = int(input()) n = len(s) w = ["#"] * n flag = True for j in range(n): if j + 1 - x <= 0: if j + 1 + x > n: if s[j] == "1": flag = False break elif s[j] == "0": if w[j + x] not in ["0", "#"]: flag = False break w[j + x] = "0" else: if w[j + x] not in ["1", "#"]: flag = False break w[j + x] = "1" elif j + 1 + x > n: if s[j] == "0": if w[j - x] not in ["0", "#"]: flag = False break w[j - x] = "0" else: if w[j - x] not in ["1", "#"]: flag = False break w[j - x] = "1" elif s[j] == "0": if w[j + x] not in ["#", "0"] or w[j - x] not in ["#", "0"]: flag = False break w[j + x] = w[j - x] = "0" elif w[j + x] == "0": if w[j - x] == "0": flag = False break w[j - x] = "1" elif w[j - x] == "0": w[j + x] = "1" if not flag: print(-1) continue for j in range(n): if w[j] == "#": w[j] = "1" print("".join(w))
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 ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF BIN_OP BIN_OP VAR NUMBER VAR NUMBER IF BIN_OP BIN_OP VAR NUMBER VAR VAR IF VAR VAR STRING ASSIGN VAR NUMBER IF VAR VAR STRING IF VAR BIN_OP VAR VAR LIST STRING STRING ASSIGN VAR NUMBER ASSIGN VAR BIN_OP VAR VAR STRING IF VAR BIN_OP VAR VAR LIST STRING STRING ASSIGN VAR NUMBER ASSIGN VAR BIN_OP VAR VAR STRING IF BIN_OP BIN_OP VAR NUMBER VAR VAR IF VAR VAR STRING IF VAR BIN_OP VAR VAR LIST STRING STRING ASSIGN VAR NUMBER ASSIGN VAR BIN_OP VAR VAR STRING IF VAR BIN_OP VAR VAR LIST STRING STRING ASSIGN VAR NUMBER ASSIGN VAR BIN_OP VAR VAR STRING IF VAR VAR STRING IF VAR BIN_OP VAR VAR LIST STRING STRING VAR BIN_OP VAR VAR LIST STRING STRING ASSIGN VAR NUMBER ASSIGN VAR BIN_OP VAR VAR VAR BIN_OP VAR VAR STRING IF VAR BIN_OP VAR VAR STRING IF VAR BIN_OP VAR VAR STRING ASSIGN VAR NUMBER ASSIGN VAR BIN_OP VAR VAR STRING IF VAR BIN_OP VAR VAR STRING ASSIGN VAR BIN_OP VAR VAR STRING IF VAR EXPR FUNC_CALL VAR NUMBER FOR 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
for _ in range(int(input())): s = input() x = int(input()) n = len(s) dp = [(1) for i in range(n)] for i in range(n): if s[i] == "0": if i - x >= 0: dp[i - x] = 0 if i + x < n: dp[i + x] = 0 w = "" for i in range(n): b = "0" if i >= x and dp[i - x] == 1: b = "1" if i < n - x and dp[i + x] == 1: b = "1" w += b if w != s: print(-1) else: ans = "" for i in dp: ans += str(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 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 NUMBER IF BIN_OP VAR VAR VAR ASSIGN VAR BIN_OP VAR VAR NUMBER ASSIGN VAR STRING FOR VAR FUNC_CALL VAR VAR ASSIGN VAR STRING IF VAR VAR VAR BIN_OP VAR VAR NUMBER ASSIGN VAR STRING IF VAR BIN_OP VAR VAR VAR BIN_OP VAR VAR NUMBER ASSIGN VAR STRING VAR VAR IF VAR VAR EXPR FUNC_CALL VAR NUMBER ASSIGN VAR STRING FOR VAR VAR 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
a = int(input()) for i in range(a): s = input() ans = [] flag = 1 for i in range(len(s)): ans.append(s[i]) x = int(input()) te = [1] * len(s) for i in range(len(s)): if s[i] == "0": if i - x >= 0: te[i - x] = 0 if i + x < len(s): te[i + x] = 0 else: a1 = 0 if i - x >= 0 and te[i - x] == 0: a1 += 1 if i + x < len(s) and te[i + x] == 0: a1 += 1 if a1 == 2: flag = 0 break for i in range(len(te)): if s[i] == "1": a1 = 0 if i + x < len(te): if te[i + x] == 1: a1 += 1 if i - x >= 0: if te[i - x] == 1: a1 += 1 if a1 == 0: flag = 0 break if flag == 0: print(-1) else: print("".join(map(str, te)))
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR 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 NUMBER IF BIN_OP VAR VAR NUMBER VAR BIN_OP VAR VAR NUMBER VAR NUMBER IF BIN_OP VAR VAR FUNC_CALL VAR VAR VAR BIN_OP VAR VAR NUMBER VAR NUMBER IF VAR NUMBER ASSIGN 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 ASSIGN VAR NUMBER 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
def solve(): s = input() n = len(s) x = int(input()) ans = ["0" for i in range(n)] for i in range(n): if s[i] == "1": if i >= 2 * x and s[i - 2 * x] == "1": ans[i - x] = "1" elif i >= x and i < 2 * x: ans[i - x] = "1" elif i + x < n: ans[i + x] = "1" else: print(-1) return elif i - x >= 0 and ans[i - x] == "1": print(-1) return print(*ans, sep="") for i in range(int(input())): 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 BIN_OP NUMBER VAR VAR BIN_OP VAR BIN_OP NUMBER VAR STRING ASSIGN VAR BIN_OP VAR VAR STRING IF VAR VAR VAR BIN_OP NUMBER VAR ASSIGN VAR BIN_OP VAR VAR STRING IF BIN_OP VAR VAR VAR ASSIGN VAR BIN_OP VAR VAR STRING EXPR FUNC_CALL VAR NUMBER RETURN IF BIN_OP VAR VAR NUMBER VAR BIN_OP VAR VAR STRING EXPR FUNC_CALL VAR NUMBER RETURN EXPR FUNC_CALL VAR VAR STRING FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR EXPR FUNC_CALL VAR