description
stringlengths
171
4k
code
stringlengths
94
3.98k
normalized_code
stringlengths
57
4.99k
You are given a ternary string (it is a string which consists only of characters '0', '1' and '2'). You can swap any two adjacent (consecutive) characters '0' and '1' (i.e. replace "01" with "10" or vice versa) or any two adjacent (consecutive) characters '1' and '2' (i.e. replace "12" with "21" or vice versa). For example, for string "010210" we can perform the following moves: "010210" $\rightarrow$ "100210"; "010210" $\rightarrow$ "001210"; "010210" $\rightarrow$ "010120"; "010210" $\rightarrow$ "010201". Note than you cannot swap "02" $\rightarrow$ "20" and vice versa. You cannot perform any other operations with the given string excluding described above. You task is to obtain the minimum possible (lexicographically) string by using these swaps arbitrary number of times (possibly, zero). String $a$ is lexicographically less than string $b$ (if strings $a$ and $b$ have the same length) if there exists some position $i$ ($1 \le i \le |a|$, where $|s|$ is the length of the string $s$) such that for every $j < i$ holds $a_j = b_j$, and $a_i < b_i$. -----Input----- The first line of the input contains the string $s$ consisting only of characters '0', '1' and '2', its length is between $1$ and $10^5$ (inclusive). -----Output----- Print a single string β€” the minimum possible (lexicographically) string you can obtain by using the swaps described above arbitrary number of times (possibly, zero). -----Examples----- Input 100210 Output 001120 Input 11222121 Output 11112222 Input 20 Output 20
s = input() ans = [] ones = 0 for i in s: if i != "1": ans += [i] else: ones += 1 i = 0 n = len(ans) while i < n and ans[i] != "2": print(0, end="") i += 1 print("1" * ones, end="") while i < n: print(ans[i], end="") i += 1
ASSIGN VAR FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR NUMBER FOR VAR VAR IF VAR STRING VAR LIST VAR VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR WHILE VAR VAR VAR VAR STRING EXPR FUNC_CALL VAR NUMBER STRING VAR NUMBER EXPR FUNC_CALL VAR BIN_OP STRING VAR STRING WHILE VAR VAR EXPR FUNC_CALL VAR VAR VAR STRING VAR NUMBER
You are given a ternary string (it is a string which consists only of characters '0', '1' and '2'). You can swap any two adjacent (consecutive) characters '0' and '1' (i.e. replace "01" with "10" or vice versa) or any two adjacent (consecutive) characters '1' and '2' (i.e. replace "12" with "21" or vice versa). For example, for string "010210" we can perform the following moves: "010210" $\rightarrow$ "100210"; "010210" $\rightarrow$ "001210"; "010210" $\rightarrow$ "010120"; "010210" $\rightarrow$ "010201". Note than you cannot swap "02" $\rightarrow$ "20" and vice versa. You cannot perform any other operations with the given string excluding described above. You task is to obtain the minimum possible (lexicographically) string by using these swaps arbitrary number of times (possibly, zero). String $a$ is lexicographically less than string $b$ (if strings $a$ and $b$ have the same length) if there exists some position $i$ ($1 \le i \le |a|$, where $|s|$ is the length of the string $s$) such that for every $j < i$ holds $a_j = b_j$, and $a_i < b_i$. -----Input----- The first line of the input contains the string $s$ consisting only of characters '0', '1' and '2', its length is between $1$ and $10^5$ (inclusive). -----Output----- Print a single string β€” the minimum possible (lexicographically) string you can obtain by using the swaps described above arbitrary number of times (possibly, zero). -----Examples----- Input 100210 Output 001120 Input 11222121 Output 11112222 Input 20 Output 20
def minString(s): l = list(s) c1 = l.count("1") l = [x for x in l if x != "1"] if "2" in l: i = l.index("2") l[i:i] = ["1"] * c1 else: l.extend(["1"] * c1) return "".join(l) s = str(input()) print(minString(s))
FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR STRING ASSIGN VAR VAR VAR VAR VAR STRING IF STRING VAR ASSIGN VAR FUNC_CALL VAR STRING ASSIGN VAR VAR VAR BIN_OP LIST STRING VAR EXPR FUNC_CALL VAR BIN_OP LIST STRING VAR RETURN FUNC_CALL STRING VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR
You are given a ternary string (it is a string which consists only of characters '0', '1' and '2'). You can swap any two adjacent (consecutive) characters '0' and '1' (i.e. replace "01" with "10" or vice versa) or any two adjacent (consecutive) characters '1' and '2' (i.e. replace "12" with "21" or vice versa). For example, for string "010210" we can perform the following moves: "010210" $\rightarrow$ "100210"; "010210" $\rightarrow$ "001210"; "010210" $\rightarrow$ "010120"; "010210" $\rightarrow$ "010201". Note than you cannot swap "02" $\rightarrow$ "20" and vice versa. You cannot perform any other operations with the given string excluding described above. You task is to obtain the minimum possible (lexicographically) string by using these swaps arbitrary number of times (possibly, zero). String $a$ is lexicographically less than string $b$ (if strings $a$ and $b$ have the same length) if there exists some position $i$ ($1 \le i \le |a|$, where $|s|$ is the length of the string $s$) such that for every $j < i$ holds $a_j = b_j$, and $a_i < b_i$. -----Input----- The first line of the input contains the string $s$ consisting only of characters '0', '1' and '2', its length is between $1$ and $10^5$ (inclusive). -----Output----- Print a single string β€” the minimum possible (lexicographically) string you can obtain by using the swaps described above arbitrary number of times (possibly, zero). -----Examples----- Input 100210 Output 001120 Input 11222121 Output 11112222 Input 20 Output 20
s = input() t = "".join(c for c in s if c != "1") i = (t + "2").find("2") print(t[:i] + "1" * (len(s) - len(t)) + t[i:])
ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL STRING VAR VAR VAR VAR STRING ASSIGN VAR FUNC_CALL BIN_OP VAR STRING STRING EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR BIN_OP STRING BIN_OP FUNC_CALL VAR VAR FUNC_CALL VAR VAR VAR VAR
You are given a ternary string (it is a string which consists only of characters '0', '1' and '2'). You can swap any two adjacent (consecutive) characters '0' and '1' (i.e. replace "01" with "10" or vice versa) or any two adjacent (consecutive) characters '1' and '2' (i.e. replace "12" with "21" or vice versa). For example, for string "010210" we can perform the following moves: "010210" $\rightarrow$ "100210"; "010210" $\rightarrow$ "001210"; "010210" $\rightarrow$ "010120"; "010210" $\rightarrow$ "010201". Note than you cannot swap "02" $\rightarrow$ "20" and vice versa. You cannot perform any other operations with the given string excluding described above. You task is to obtain the minimum possible (lexicographically) string by using these swaps arbitrary number of times (possibly, zero). String $a$ is lexicographically less than string $b$ (if strings $a$ and $b$ have the same length) if there exists some position $i$ ($1 \le i \le |a|$, where $|s|$ is the length of the string $s$) such that for every $j < i$ holds $a_j = b_j$, and $a_i < b_i$. -----Input----- The first line of the input contains the string $s$ consisting only of characters '0', '1' and '2', its length is between $1$ and $10^5$ (inclusive). -----Output----- Print a single string β€” the minimum possible (lexicographically) string you can obtain by using the swaps described above arbitrary number of times (possibly, zero). -----Examples----- Input 100210 Output 001120 Input 11222121 Output 11112222 Input 20 Output 20
s = input() n = len(s) string = "" for i in s: if i != "1": string += i c = s.count("1") ans = "" j = 0 for i in string: if i == "2": break else: j += 1 ans += i ans += "1" * c for i in range(j, len(string)): ans += string[i] print(ans)
ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR STRING FOR VAR VAR IF VAR STRING VAR VAR ASSIGN VAR FUNC_CALL VAR STRING ASSIGN VAR STRING ASSIGN VAR NUMBER FOR VAR VAR IF VAR STRING VAR NUMBER VAR VAR VAR BIN_OP STRING VAR FOR VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR
You are given a ternary string (it is a string which consists only of characters '0', '1' and '2'). You can swap any two adjacent (consecutive) characters '0' and '1' (i.e. replace "01" with "10" or vice versa) or any two adjacent (consecutive) characters '1' and '2' (i.e. replace "12" with "21" or vice versa). For example, for string "010210" we can perform the following moves: "010210" $\rightarrow$ "100210"; "010210" $\rightarrow$ "001210"; "010210" $\rightarrow$ "010120"; "010210" $\rightarrow$ "010201". Note than you cannot swap "02" $\rightarrow$ "20" and vice versa. You cannot perform any other operations with the given string excluding described above. You task is to obtain the minimum possible (lexicographically) string by using these swaps arbitrary number of times (possibly, zero). String $a$ is lexicographically less than string $b$ (if strings $a$ and $b$ have the same length) if there exists some position $i$ ($1 \le i \le |a|$, where $|s|$ is the length of the string $s$) such that for every $j < i$ holds $a_j = b_j$, and $a_i < b_i$. -----Input----- The first line of the input contains the string $s$ consisting only of characters '0', '1' and '2', its length is between $1$ and $10^5$ (inclusive). -----Output----- Print a single string β€” the minimum possible (lexicographically) string you can obtain by using the swaps described above arbitrary number of times (possibly, zero). -----Examples----- Input 100210 Output 001120 Input 11222121 Output 11112222 Input 20 Output 20
def go(): a = [int(i) for i in input()] i = 0 c = 0 while i < len(a): if a[i] == 1: a[i] = None c += 1 i += 1 j = 0 a = [j for j in a if j is not None] while j < len(a): if a[j] == 2: break j += 1 output = "".join(str(i) for i in a[:j]) output += "1" * c output += "".join(str(i) for i in a[j:]) return output print(go())
FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR FUNC_CALL VAR VAR IF VAR VAR NUMBER ASSIGN VAR VAR NONE VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR VAR VAR VAR VAR NONE WHILE VAR FUNC_CALL VAR VAR IF VAR VAR NUMBER VAR NUMBER ASSIGN VAR FUNC_CALL STRING FUNC_CALL VAR VAR VAR VAR VAR VAR BIN_OP STRING VAR VAR FUNC_CALL STRING FUNC_CALL VAR VAR VAR VAR VAR RETURN VAR EXPR FUNC_CALL VAR FUNC_CALL VAR
You are given a ternary string (it is a string which consists only of characters '0', '1' and '2'). You can swap any two adjacent (consecutive) characters '0' and '1' (i.e. replace "01" with "10" or vice versa) or any two adjacent (consecutive) characters '1' and '2' (i.e. replace "12" with "21" or vice versa). For example, for string "010210" we can perform the following moves: "010210" $\rightarrow$ "100210"; "010210" $\rightarrow$ "001210"; "010210" $\rightarrow$ "010120"; "010210" $\rightarrow$ "010201". Note than you cannot swap "02" $\rightarrow$ "20" and vice versa. You cannot perform any other operations with the given string excluding described above. You task is to obtain the minimum possible (lexicographically) string by using these swaps arbitrary number of times (possibly, zero). String $a$ is lexicographically less than string $b$ (if strings $a$ and $b$ have the same length) if there exists some position $i$ ($1 \le i \le |a|$, where $|s|$ is the length of the string $s$) such that for every $j < i$ holds $a_j = b_j$, and $a_i < b_i$. -----Input----- The first line of the input contains the string $s$ consisting only of characters '0', '1' and '2', its length is between $1$ and $10^5$ (inclusive). -----Output----- Print a single string β€” the minimum possible (lexicographically) string you can obtain by using the swaps described above arbitrary number of times (possibly, zero). -----Examples----- Input 100210 Output 001120 Input 11222121 Output 11112222 Input 20 Output 20
s = input() c0 = c1 = 0 d0 = [] for c in s: if c == "0": c0 += 1 elif c == "1": c1 += 1 else: d0.append(c0) c0 = 0 d0.append(c0) res = [] for i in range(len(d0)): for j in range(d0[i]): res.append("0") if i == 0: for j in range(c1): res.append("1") if i < len(d0) - 1: res.append("2") print("".join(res))
ASSIGN VAR FUNC_CALL VAR ASSIGN VAR VAR NUMBER ASSIGN VAR LIST FOR VAR VAR IF VAR STRING VAR NUMBER IF VAR STRING VAR NUMBER EXPR FUNC_CALL VAR VAR ASSIGN VAR NUMBER EXPR FUNC_CALL VAR VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR STRING IF VAR NUMBER FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR STRING IF VAR BIN_OP FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR FUNC_CALL STRING VAR
You are given a ternary string (it is a string which consists only of characters '0', '1' and '2'). You can swap any two adjacent (consecutive) characters '0' and '1' (i.e. replace "01" with "10" or vice versa) or any two adjacent (consecutive) characters '1' and '2' (i.e. replace "12" with "21" or vice versa). For example, for string "010210" we can perform the following moves: "010210" $\rightarrow$ "100210"; "010210" $\rightarrow$ "001210"; "010210" $\rightarrow$ "010120"; "010210" $\rightarrow$ "010201". Note than you cannot swap "02" $\rightarrow$ "20" and vice versa. You cannot perform any other operations with the given string excluding described above. You task is to obtain the minimum possible (lexicographically) string by using these swaps arbitrary number of times (possibly, zero). String $a$ is lexicographically less than string $b$ (if strings $a$ and $b$ have the same length) if there exists some position $i$ ($1 \le i \le |a|$, where $|s|$ is the length of the string $s$) such that for every $j < i$ holds $a_j = b_j$, and $a_i < b_i$. -----Input----- The first line of the input contains the string $s$ consisting only of characters '0', '1' and '2', its length is between $1$ and $10^5$ (inclusive). -----Output----- Print a single string β€” the minimum possible (lexicographically) string you can obtain by using the swaps described above arbitrary number of times (possibly, zero). -----Examples----- Input 100210 Output 001120 Input 11222121 Output 11112222 Input 20 Output 20
s = input() cnt = 0 v = [] for ch in s: if ch == "1": cnt += 1 else: v.append(ch) for ch in v: if ch == "2": for i in range(cnt): print(1, end="") cnt = 0 print(ch, end="") for i in range(cnt): print(1, end="")
ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR LIST FOR VAR VAR IF VAR STRING VAR NUMBER EXPR FUNC_CALL VAR VAR FOR VAR VAR IF VAR STRING FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR NUMBER STRING ASSIGN VAR NUMBER EXPR FUNC_CALL VAR VAR STRING FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR NUMBER STRING
Madoka decided to entrust the organization of a major computer game tournament "OSU"! In this tournament, matches are held according to the "Olympic system". In other words, there are $2^n$ participants in the tournament, numbered with integers from $1$ to $2^n$. There are $n$ rounds in total in the tournament. In the $i$-th round there are $2^{n - i}$ matches between two players (one of whom is right, the other is left), after which the winners go further along the tournament grid, and the losing participants are eliminated from the tournament. Herewith, the relative order in the next round does not change. And the winner of the tournament β€” is the last remaining participant. But the smaller the participant's number, the more he will pay Madoka if he wins, so Madoka wants the participant with the lowest number to win. To do this, she can arrange the participants in the first round as she likes, and also determine for each match who will win β€” the participant on the left or right. But Madoka knows that tournament sponsors can change the winner in matches no more than $k$ times. (That is, if the participant on the left won before the change, then the participant on the right will win after the change, and if the participant on the right won, then the participant on the left will win after the change). So, the first image shows the tournament grid that Madoka made, where the red lines denote who should win the match. And the second one shows the tournament grid, after one change in the outcome of the match by sponsors (a match between $1$ and $3$ players). Print the minimum possible number of the winner in the tournament, which Madoka can get regardless of changes in sponsors. But since the answer can be very large, output it modulo $10^9 + 7$. Note that we need to minimize the answer, and only then take it modulo. -----Input----- The first and the only line contains two integers $n$ and $k$ ($1 \le n \le 10^5, 1 \le k \le \min(2^n - 1, 10^9)$) β€” the number of rounds in the tournament and the number of outcomes that sponsors can change. -----Output----- Print exactly one integer β€” the minimum number of the winner modulo $10^9 + 7$ -----Examples----- Input 1 1 Output 2 Input 2 1 Output 3 Input 3 2 Output 7 -----Note----- In the first example, there is only one match between players $1$ and $2$, so the sponsors can always make player $2$ wins. The tournament grid from the second example is shown in the picture in the statement.
def solve(): mod = 1000000007 n, k = map(int, input().strip().split()) res = pow(2, n, mod) if k >= n: print(res) elif k + 1 == n: print(res - 1) else: ans = 1 temp1 = 1 temp2 = 1 for i in range(1, n - k): temp1 *= n - i + 1 temp1 %= mod temp2 *= i temp2 %= mod ans += temp1 * pow(temp2, mod - 2, mod) % mod print((res - ans + mod) % mod) solve()
FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR NUMBER VAR VAR IF VAR VAR EXPR FUNC_CALL VAR VAR IF BIN_OP VAR NUMBER VAR EXPR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR VAR VAR BIN_OP BIN_OP VAR VAR NUMBER VAR VAR VAR VAR VAR VAR VAR BIN_OP BIN_OP VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER VAR VAR EXPR FUNC_CALL VAR BIN_OP BIN_OP BIN_OP VAR VAR VAR VAR EXPR FUNC_CALL VAR
Madoka decided to entrust the organization of a major computer game tournament "OSU"! In this tournament, matches are held according to the "Olympic system". In other words, there are $2^n$ participants in the tournament, numbered with integers from $1$ to $2^n$. There are $n$ rounds in total in the tournament. In the $i$-th round there are $2^{n - i}$ matches between two players (one of whom is right, the other is left), after which the winners go further along the tournament grid, and the losing participants are eliminated from the tournament. Herewith, the relative order in the next round does not change. And the winner of the tournament β€” is the last remaining participant. But the smaller the participant's number, the more he will pay Madoka if he wins, so Madoka wants the participant with the lowest number to win. To do this, she can arrange the participants in the first round as she likes, and also determine for each match who will win β€” the participant on the left or right. But Madoka knows that tournament sponsors can change the winner in matches no more than $k$ times. (That is, if the participant on the left won before the change, then the participant on the right will win after the change, and if the participant on the right won, then the participant on the left will win after the change). So, the first image shows the tournament grid that Madoka made, where the red lines denote who should win the match. And the second one shows the tournament grid, after one change in the outcome of the match by sponsors (a match between $1$ and $3$ players). Print the minimum possible number of the winner in the tournament, which Madoka can get regardless of changes in sponsors. But since the answer can be very large, output it modulo $10^9 + 7$. Note that we need to minimize the answer, and only then take it modulo. -----Input----- The first and the only line contains two integers $n$ and $k$ ($1 \le n \le 10^5, 1 \le k \le \min(2^n - 1, 10^9)$) β€” the number of rounds in the tournament and the number of outcomes that sponsors can change. -----Output----- Print exactly one integer β€” the minimum number of the winner modulo $10^9 + 7$ -----Examples----- Input 1 1 Output 2 Input 2 1 Output 3 Input 3 2 Output 7 -----Note----- In the first example, there is only one match between players $1$ and $2$, so the sponsors can always make player $2$ wins. The tournament grid from the second example is shown in the picture in the statement.
n, k = [int(e) for e in input().split()] k = min(k, n) result = 1 c = 1 modulo = 10**9 + 7 inv = [(0) for i in range(k + 1)] inv[0] = 1 if k + 1 >= 2: inv[1] = 1 for i in range(2, k + 1): inv[i] = modulo - modulo // i * inv[modulo % i] % modulo for m in range(1, k + 1): c = c * (n - m + 1) * inv[m] c %= modulo result = (result + c) % modulo print(result)
ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR BIN_OP BIN_OP NUMBER NUMBER NUMBER ASSIGN VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER NUMBER IF BIN_OP VAR NUMBER NUMBER ASSIGN VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR VAR BIN_OP VAR BIN_OP BIN_OP BIN_OP VAR VAR VAR BIN_OP VAR VAR VAR FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR BIN_OP BIN_OP VAR VAR NUMBER VAR VAR VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR EXPR FUNC_CALL VAR VAR
Madoka decided to entrust the organization of a major computer game tournament "OSU"! In this tournament, matches are held according to the "Olympic system". In other words, there are $2^n$ participants in the tournament, numbered with integers from $1$ to $2^n$. There are $n$ rounds in total in the tournament. In the $i$-th round there are $2^{n - i}$ matches between two players (one of whom is right, the other is left), after which the winners go further along the tournament grid, and the losing participants are eliminated from the tournament. Herewith, the relative order in the next round does not change. And the winner of the tournament β€” is the last remaining participant. But the smaller the participant's number, the more he will pay Madoka if he wins, so Madoka wants the participant with the lowest number to win. To do this, she can arrange the participants in the first round as she likes, and also determine for each match who will win β€” the participant on the left or right. But Madoka knows that tournament sponsors can change the winner in matches no more than $k$ times. (That is, if the participant on the left won before the change, then the participant on the right will win after the change, and if the participant on the right won, then the participant on the left will win after the change). So, the first image shows the tournament grid that Madoka made, where the red lines denote who should win the match. And the second one shows the tournament grid, after one change in the outcome of the match by sponsors (a match between $1$ and $3$ players). Print the minimum possible number of the winner in the tournament, which Madoka can get regardless of changes in sponsors. But since the answer can be very large, output it modulo $10^9 + 7$. Note that we need to minimize the answer, and only then take it modulo. -----Input----- The first and the only line contains two integers $n$ and $k$ ($1 \le n \le 10^5, 1 \le k \le \min(2^n - 1, 10^9)$) β€” the number of rounds in the tournament and the number of outcomes that sponsors can change. -----Output----- Print exactly one integer β€” the minimum number of the winner modulo $10^9 + 7$ -----Examples----- Input 1 1 Output 2 Input 2 1 Output 3 Input 3 2 Output 7 -----Note----- In the first example, there is only one match between players $1$ and $2$, so the sponsors can always make player $2$ wins. The tournament grid from the second example is shown in the picture in the statement.
n, k = map(int, input().split()) x = 0 y = 1 mod = 10**9 + 7 for i in range(min(n, k) + 1): x = (x + y) % mod y = y * (n - i) * pow(i + 1, -1, mod) % mod print(x)
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR BIN_OP BIN_OP NUMBER NUMBER NUMBER FOR VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR ASSIGN VAR BIN_OP BIN_OP BIN_OP VAR BIN_OP VAR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER VAR VAR EXPR FUNC_CALL VAR VAR
Madoka decided to entrust the organization of a major computer game tournament "OSU"! In this tournament, matches are held according to the "Olympic system". In other words, there are $2^n$ participants in the tournament, numbered with integers from $1$ to $2^n$. There are $n$ rounds in total in the tournament. In the $i$-th round there are $2^{n - i}$ matches between two players (one of whom is right, the other is left), after which the winners go further along the tournament grid, and the losing participants are eliminated from the tournament. Herewith, the relative order in the next round does not change. And the winner of the tournament β€” is the last remaining participant. But the smaller the participant's number, the more he will pay Madoka if he wins, so Madoka wants the participant with the lowest number to win. To do this, she can arrange the participants in the first round as she likes, and also determine for each match who will win β€” the participant on the left or right. But Madoka knows that tournament sponsors can change the winner in matches no more than $k$ times. (That is, if the participant on the left won before the change, then the participant on the right will win after the change, and if the participant on the right won, then the participant on the left will win after the change). So, the first image shows the tournament grid that Madoka made, where the red lines denote who should win the match. And the second one shows the tournament grid, after one change in the outcome of the match by sponsors (a match between $1$ and $3$ players). Print the minimum possible number of the winner in the tournament, which Madoka can get regardless of changes in sponsors. But since the answer can be very large, output it modulo $10^9 + 7$. Note that we need to minimize the answer, and only then take it modulo. -----Input----- The first and the only line contains two integers $n$ and $k$ ($1 \le n \le 10^5, 1 \le k \le \min(2^n - 1, 10^9)$) β€” the number of rounds in the tournament and the number of outcomes that sponsors can change. -----Output----- Print exactly one integer β€” the minimum number of the winner modulo $10^9 + 7$ -----Examples----- Input 1 1 Output 2 Input 2 1 Output 3 Input 3 2 Output 7 -----Note----- In the first example, there is only one match between players $1$ and $2$, so the sponsors can always make player $2$ wins. The tournament grid from the second example is shown in the picture in the statement.
def corruption(n, k): MOD = 10**9 + 7 if k >= n: return 2**n % MOD res = 1 choose = 1 for i in range(1, k + 1): choose = choose * (n - i + 1) * pow(i, -1, MOD) % MOD res = (res + choose) % MOD return res n, k = tuple(map(int, input().split())) print(corruption(n, k))
FUNC_DEF ASSIGN VAR BIN_OP BIN_OP NUMBER NUMBER NUMBER IF VAR VAR RETURN BIN_OP BIN_OP NUMBER VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR BIN_OP BIN_OP BIN_OP VAR BIN_OP BIN_OP VAR VAR NUMBER FUNC_CALL VAR VAR NUMBER VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR RETURN VAR ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR
Madoka decided to entrust the organization of a major computer game tournament "OSU"! In this tournament, matches are held according to the "Olympic system". In other words, there are $2^n$ participants in the tournament, numbered with integers from $1$ to $2^n$. There are $n$ rounds in total in the tournament. In the $i$-th round there are $2^{n - i}$ matches between two players (one of whom is right, the other is left), after which the winners go further along the tournament grid, and the losing participants are eliminated from the tournament. Herewith, the relative order in the next round does not change. And the winner of the tournament β€” is the last remaining participant. But the smaller the participant's number, the more he will pay Madoka if he wins, so Madoka wants the participant with the lowest number to win. To do this, she can arrange the participants in the first round as she likes, and also determine for each match who will win β€” the participant on the left or right. But Madoka knows that tournament sponsors can change the winner in matches no more than $k$ times. (That is, if the participant on the left won before the change, then the participant on the right will win after the change, and if the participant on the right won, then the participant on the left will win after the change). So, the first image shows the tournament grid that Madoka made, where the red lines denote who should win the match. And the second one shows the tournament grid, after one change in the outcome of the match by sponsors (a match between $1$ and $3$ players). Print the minimum possible number of the winner in the tournament, which Madoka can get regardless of changes in sponsors. But since the answer can be very large, output it modulo $10^9 + 7$. Note that we need to minimize the answer, and only then take it modulo. -----Input----- The first and the only line contains two integers $n$ and $k$ ($1 \le n \le 10^5, 1 \le k \le \min(2^n - 1, 10^9)$) β€” the number of rounds in the tournament and the number of outcomes that sponsors can change. -----Output----- Print exactly one integer β€” the minimum number of the winner modulo $10^9 + 7$ -----Examples----- Input 1 1 Output 2 Input 2 1 Output 3 Input 3 2 Output 7 -----Note----- In the first example, there is only one match between players $1$ and $2$, so the sponsors can always make player $2$ wins. The tournament grid from the second example is shown in the picture in the statement.
welln, kwell = map(int, input().split()) kwell = min(kwell, welln) wellMODwell = 10**9 + 7 counwellt = 0 wellc = 1 for i in range(kwell + 1): counwellt = (counwellt + wellc) % wellMODwell wellc = wellc * (welln - i) * pow(i + 1, wellMODwell - 2, wellMODwell) % wellMODwell print(counwellt)
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR BIN_OP BIN_OP NUMBER NUMBER NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR ASSIGN VAR BIN_OP BIN_OP BIN_OP VAR BIN_OP VAR VAR FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER VAR VAR EXPR FUNC_CALL VAR VAR
Madoka decided to entrust the organization of a major computer game tournament "OSU"! In this tournament, matches are held according to the "Olympic system". In other words, there are $2^n$ participants in the tournament, numbered with integers from $1$ to $2^n$. There are $n$ rounds in total in the tournament. In the $i$-th round there are $2^{n - i}$ matches between two players (one of whom is right, the other is left), after which the winners go further along the tournament grid, and the losing participants are eliminated from the tournament. Herewith, the relative order in the next round does not change. And the winner of the tournament β€” is the last remaining participant. But the smaller the participant's number, the more he will pay Madoka if he wins, so Madoka wants the participant with the lowest number to win. To do this, she can arrange the participants in the first round as she likes, and also determine for each match who will win β€” the participant on the left or right. But Madoka knows that tournament sponsors can change the winner in matches no more than $k$ times. (That is, if the participant on the left won before the change, then the participant on the right will win after the change, and if the participant on the right won, then the participant on the left will win after the change). So, the first image shows the tournament grid that Madoka made, where the red lines denote who should win the match. And the second one shows the tournament grid, after one change in the outcome of the match by sponsors (a match between $1$ and $3$ players). Print the minimum possible number of the winner in the tournament, which Madoka can get regardless of changes in sponsors. But since the answer can be very large, output it modulo $10^9 + 7$. Note that we need to minimize the answer, and only then take it modulo. -----Input----- The first and the only line contains two integers $n$ and $k$ ($1 \le n \le 10^5, 1 \le k \le \min(2^n - 1, 10^9)$) β€” the number of rounds in the tournament and the number of outcomes that sponsors can change. -----Output----- Print exactly one integer β€” the minimum number of the winner modulo $10^9 + 7$ -----Examples----- Input 1 1 Output 2 Input 2 1 Output 3 Input 3 2 Output 7 -----Note----- In the first example, there is only one match between players $1$ and $2$, so the sponsors can always make player $2$ wins. The tournament grid from the second example is shown in the picture in the statement.
n, k = map(int, input().split()) ans = 1 s = 1 y = k - (k - n // 2) h = min(n // 2 + (n % 2 == 1) + 1, k + 1) if k < n: if k + 1 == h: for i in range(1, h): s = s * (n - i + 1) * pow(i, -1, 10**9 + 7) % (10**9 + 7) ans += s if y > 0 and i > y and h - 1 != i: ans += s print(ans % (10**9 + 7)) else: for i in range(1, n - k): s = s * (n - i + 1) * pow(i, -1, 10**9 + 7) % (10**9 + 7) ans += s if y > 0 and i > y and h - 1 != i: ans += s print((pow(2, n) - ans) % (10**9 + 7)) else: print(pow(2, n, 10**9 + 7))
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR BIN_OP VAR BIN_OP VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR BIN_OP BIN_OP BIN_OP VAR NUMBER BIN_OP VAR NUMBER NUMBER NUMBER BIN_OP VAR NUMBER IF VAR VAR IF BIN_OP VAR NUMBER VAR FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR BIN_OP BIN_OP BIN_OP VAR BIN_OP BIN_OP VAR VAR NUMBER FUNC_CALL VAR VAR NUMBER BIN_OP BIN_OP NUMBER NUMBER NUMBER BIN_OP BIN_OP NUMBER NUMBER NUMBER VAR VAR IF VAR NUMBER VAR VAR BIN_OP VAR NUMBER VAR VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR BIN_OP BIN_OP NUMBER NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR VAR ASSIGN VAR BIN_OP BIN_OP BIN_OP VAR BIN_OP BIN_OP VAR VAR NUMBER FUNC_CALL VAR VAR NUMBER BIN_OP BIN_OP NUMBER NUMBER NUMBER BIN_OP BIN_OP NUMBER NUMBER NUMBER VAR VAR IF VAR NUMBER VAR VAR BIN_OP VAR NUMBER VAR VAR VAR EXPR FUNC_CALL VAR BIN_OP BIN_OP FUNC_CALL VAR NUMBER VAR VAR BIN_OP BIN_OP NUMBER NUMBER NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR NUMBER VAR BIN_OP BIN_OP NUMBER NUMBER NUMBER
Madoka decided to entrust the organization of a major computer game tournament "OSU"! In this tournament, matches are held according to the "Olympic system". In other words, there are $2^n$ participants in the tournament, numbered with integers from $1$ to $2^n$. There are $n$ rounds in total in the tournament. In the $i$-th round there are $2^{n - i}$ matches between two players (one of whom is right, the other is left), after which the winners go further along the tournament grid, and the losing participants are eliminated from the tournament. Herewith, the relative order in the next round does not change. And the winner of the tournament β€” is the last remaining participant. But the smaller the participant's number, the more he will pay Madoka if he wins, so Madoka wants the participant with the lowest number to win. To do this, she can arrange the participants in the first round as she likes, and also determine for each match who will win β€” the participant on the left or right. But Madoka knows that tournament sponsors can change the winner in matches no more than $k$ times. (That is, if the participant on the left won before the change, then the participant on the right will win after the change, and if the participant on the right won, then the participant on the left will win after the change). So, the first image shows the tournament grid that Madoka made, where the red lines denote who should win the match. And the second one shows the tournament grid, after one change in the outcome of the match by sponsors (a match between $1$ and $3$ players). Print the minimum possible number of the winner in the tournament, which Madoka can get regardless of changes in sponsors. But since the answer can be very large, output it modulo $10^9 + 7$. Note that we need to minimize the answer, and only then take it modulo. -----Input----- The first and the only line contains two integers $n$ and $k$ ($1 \le n \le 10^5, 1 \le k \le \min(2^n - 1, 10^9)$) β€” the number of rounds in the tournament and the number of outcomes that sponsors can change. -----Output----- Print exactly one integer β€” the minimum number of the winner modulo $10^9 + 7$ -----Examples----- Input 1 1 Output 2 Input 2 1 Output 3 Input 3 2 Output 7 -----Note----- In the first example, there is only one match between players $1$ and $2$, so the sponsors can always make player $2$ wins. The tournament grid from the second example is shown in the picture in the statement.
MOD = 10**9 + 7 MAX_F = 10**5 + 5 fact = [(1) for i in range(MAX_F)] ifact = [(1) for i in range(MAX_F)] def mult(a, b): return a * b % MOD def power(a, n): if n == 0: return 1 tmp = power(a, n // 2) if n % 2 == 0: return mult(tmp, tmp) % MOD return mult(a, mult(tmp, tmp)) % MOD def C(n, k): if k < 0 or k > n: return 0 return mult(fact[n], mult(ifact[n - k], ifact[k])) def init(): n = MAX_F - 1 for i in range(1, n + 1): fact[i] = mult(fact[i - 1], i) ifact[n] = power(fact[n], MOD - 2) for i in range(n - 1, 0, -1): ifact[i] = mult(ifact[i + 1], i + 1) init() n, k = map(int, input().split()) res = 0 for m in range(min(n, k) + 1): res += C(n, m) res = res % MOD print(res)
ASSIGN VAR BIN_OP BIN_OP NUMBER NUMBER NUMBER ASSIGN VAR BIN_OP BIN_OP NUMBER NUMBER NUMBER ASSIGN VAR NUMBER VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR VAR FUNC_DEF RETURN BIN_OP BIN_OP VAR VAR VAR FUNC_DEF IF VAR NUMBER RETURN NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER IF BIN_OP VAR NUMBER NUMBER RETURN BIN_OP FUNC_CALL VAR VAR VAR VAR RETURN BIN_OP FUNC_CALL VAR VAR FUNC_CALL VAR VAR VAR VAR FUNC_DEF IF VAR NUMBER VAR VAR RETURN NUMBER RETURN FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR BIN_OP VAR VAR VAR VAR FUNC_DEF ASSIGN VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER EXPR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR VAR NUMBER VAR FUNC_CALL VAR VAR VAR ASSIGN VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR VAR
Madoka decided to entrust the organization of a major computer game tournament "OSU"! In this tournament, matches are held according to the "Olympic system". In other words, there are $2^n$ participants in the tournament, numbered with integers from $1$ to $2^n$. There are $n$ rounds in total in the tournament. In the $i$-th round there are $2^{n - i}$ matches between two players (one of whom is right, the other is left), after which the winners go further along the tournament grid, and the losing participants are eliminated from the tournament. Herewith, the relative order in the next round does not change. And the winner of the tournament β€” is the last remaining participant. But the smaller the participant's number, the more he will pay Madoka if he wins, so Madoka wants the participant with the lowest number to win. To do this, she can arrange the participants in the first round as she likes, and also determine for each match who will win β€” the participant on the left or right. But Madoka knows that tournament sponsors can change the winner in matches no more than $k$ times. (That is, if the participant on the left won before the change, then the participant on the right will win after the change, and if the participant on the right won, then the participant on the left will win after the change). So, the first image shows the tournament grid that Madoka made, where the red lines denote who should win the match. And the second one shows the tournament grid, after one change in the outcome of the match by sponsors (a match between $1$ and $3$ players). Print the minimum possible number of the winner in the tournament, which Madoka can get regardless of changes in sponsors. But since the answer can be very large, output it modulo $10^9 + 7$. Note that we need to minimize the answer, and only then take it modulo. -----Input----- The first and the only line contains two integers $n$ and $k$ ($1 \le n \le 10^5, 1 \le k \le \min(2^n - 1, 10^9)$) β€” the number of rounds in the tournament and the number of outcomes that sponsors can change. -----Output----- Print exactly one integer β€” the minimum number of the winner modulo $10^9 + 7$ -----Examples----- Input 1 1 Output 2 Input 2 1 Output 3 Input 3 2 Output 7 -----Note----- In the first example, there is only one match between players $1$ and $2$, so the sponsors can always make player $2$ wins. The tournament grid from the second example is shown in the picture in the statement.
def solve(): mod = 1000000007 n, k = map(int, input().strip().split()) res = pow(2, n, mod) if k >= n: print(res) elif k + 1 == n: print(res - 1) else: f = [(1) for i in range(n + 1)] fi = [(1) for i in range(n + 1)] for i in range(1, n + 1): f[i] = f[i - 1] * i % mod fi[n] = pow(f[n], mod - 2, mod) for i in range(n - 1, 0, -1): fi[i] = fi[i + 1] * (i + 1) % mod ans = 0 for i in range(0, k + 1): ans += f[n] * fi[n - i] * fi[i] % mod ans %= mod print(ans) solve()
FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR NUMBER VAR VAR IF VAR VAR EXPR FUNC_CALL VAR VAR IF BIN_OP VAR NUMBER VAR EXPR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR VAR BIN_OP BIN_OP VAR BIN_OP VAR NUMBER VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR BIN_OP VAR NUMBER VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER NUMBER ASSIGN VAR VAR BIN_OP BIN_OP VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER VAR BIN_OP BIN_OP BIN_OP VAR VAR VAR BIN_OP VAR VAR VAR VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR
Madoka decided to entrust the organization of a major computer game tournament "OSU"! In this tournament, matches are held according to the "Olympic system". In other words, there are $2^n$ participants in the tournament, numbered with integers from $1$ to $2^n$. There are $n$ rounds in total in the tournament. In the $i$-th round there are $2^{n - i}$ matches between two players (one of whom is right, the other is left), after which the winners go further along the tournament grid, and the losing participants are eliminated from the tournament. Herewith, the relative order in the next round does not change. And the winner of the tournament β€” is the last remaining participant. But the smaller the participant's number, the more he will pay Madoka if he wins, so Madoka wants the participant with the lowest number to win. To do this, she can arrange the participants in the first round as she likes, and also determine for each match who will win β€” the participant on the left or right. But Madoka knows that tournament sponsors can change the winner in matches no more than $k$ times. (That is, if the participant on the left won before the change, then the participant on the right will win after the change, and if the participant on the right won, then the participant on the left will win after the change). So, the first image shows the tournament grid that Madoka made, where the red lines denote who should win the match. And the second one shows the tournament grid, after one change in the outcome of the match by sponsors (a match between $1$ and $3$ players). Print the minimum possible number of the winner in the tournament, which Madoka can get regardless of changes in sponsors. But since the answer can be very large, output it modulo $10^9 + 7$. Note that we need to minimize the answer, and only then take it modulo. -----Input----- The first and the only line contains two integers $n$ and $k$ ($1 \le n \le 10^5, 1 \le k \le \min(2^n - 1, 10^9)$) β€” the number of rounds in the tournament and the number of outcomes that sponsors can change. -----Output----- Print exactly one integer β€” the minimum number of the winner modulo $10^9 + 7$ -----Examples----- Input 1 1 Output 2 Input 2 1 Output 3 Input 3 2 Output 7 -----Note----- In the first example, there is only one match between players $1$ and $2$, so the sponsors can always make player $2$ wins. The tournament grid from the second example is shown in the picture in the statement.
n, k = map(int, input().split()) ans = 0 cur = 0 for i in range(0, min(n, k) + 1): if i == 0: ans += 1 cur = 1 else: cur *= n - (i - 1) cur *= pow(i, -1, 1000000007) cur = cur % 1000000007 ans += cur ans = ans % 1000000007 print(ans)
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP FUNC_CALL VAR VAR VAR NUMBER IF VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER VAR BIN_OP VAR BIN_OP VAR NUMBER VAR FUNC_CALL VAR VAR NUMBER NUMBER ASSIGN VAR BIN_OP VAR NUMBER VAR VAR ASSIGN VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR
Madoka decided to entrust the organization of a major computer game tournament "OSU"! In this tournament, matches are held according to the "Olympic system". In other words, there are $2^n$ participants in the tournament, numbered with integers from $1$ to $2^n$. There are $n$ rounds in total in the tournament. In the $i$-th round there are $2^{n - i}$ matches between two players (one of whom is right, the other is left), after which the winners go further along the tournament grid, and the losing participants are eliminated from the tournament. Herewith, the relative order in the next round does not change. And the winner of the tournament β€” is the last remaining participant. But the smaller the participant's number, the more he will pay Madoka if he wins, so Madoka wants the participant with the lowest number to win. To do this, she can arrange the participants in the first round as she likes, and also determine for each match who will win β€” the participant on the left or right. But Madoka knows that tournament sponsors can change the winner in matches no more than $k$ times. (That is, if the participant on the left won before the change, then the participant on the right will win after the change, and if the participant on the right won, then the participant on the left will win after the change). So, the first image shows the tournament grid that Madoka made, where the red lines denote who should win the match. And the second one shows the tournament grid, after one change in the outcome of the match by sponsors (a match between $1$ and $3$ players). Print the minimum possible number of the winner in the tournament, which Madoka can get regardless of changes in sponsors. But since the answer can be very large, output it modulo $10^9 + 7$. Note that we need to minimize the answer, and only then take it modulo. -----Input----- The first and the only line contains two integers $n$ and $k$ ($1 \le n \le 10^5, 1 \le k \le \min(2^n - 1, 10^9)$) β€” the number of rounds in the tournament and the number of outcomes that sponsors can change. -----Output----- Print exactly one integer β€” the minimum number of the winner modulo $10^9 + 7$ -----Examples----- Input 1 1 Output 2 Input 2 1 Output 3 Input 3 2 Output 7 -----Note----- In the first example, there is only one match between players $1$ and $2$, so the sponsors can always make player $2$ wins. The tournament grid from the second example is shown in the picture in the statement.
import sys input = sys.stdin.readline def int_num(): return int(input()) def int_list(): return list(map(int, input().split())) def str_list(): s = input() return list(s[: len(s) - 1]) def instr(): return input().strip() def invr(): return map(int, input().split()) def cal_c1(n, k): MOD = 10**9 + 7 k = min(n, k) ans = 1 da = 1 for i in range(1, k + 1): da *= n + 1 - i da %= MOD t = pow(i, -1, MOD) da *= t da %= MOD ans += da ans %= MOD return ans def solve(): n, k = int_list() ans = cal_c1(n, k) print(ans) def main(): solve() main()
IMPORT ASSIGN VAR VAR FUNC_DEF RETURN FUNC_CALL VAR FUNC_CALL VAR FUNC_DEF RETURN FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FUNC_DEF ASSIGN VAR FUNC_CALL VAR RETURN FUNC_CALL VAR VAR BIN_OP FUNC_CALL VAR VAR NUMBER FUNC_DEF RETURN FUNC_CALL FUNC_CALL VAR FUNC_DEF RETURN FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FUNC_DEF ASSIGN VAR BIN_OP BIN_OP NUMBER NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER VAR BIN_OP BIN_OP VAR NUMBER VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR NUMBER VAR VAR VAR VAR VAR VAR VAR VAR VAR RETURN VAR FUNC_DEF ASSIGN VAR VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR FUNC_DEF EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR
Madoka decided to entrust the organization of a major computer game tournament "OSU"! In this tournament, matches are held according to the "Olympic system". In other words, there are $2^n$ participants in the tournament, numbered with integers from $1$ to $2^n$. There are $n$ rounds in total in the tournament. In the $i$-th round there are $2^{n - i}$ matches between two players (one of whom is right, the other is left), after which the winners go further along the tournament grid, and the losing participants are eliminated from the tournament. Herewith, the relative order in the next round does not change. And the winner of the tournament β€” is the last remaining participant. But the smaller the participant's number, the more he will pay Madoka if he wins, so Madoka wants the participant with the lowest number to win. To do this, she can arrange the participants in the first round as she likes, and also determine for each match who will win β€” the participant on the left or right. But Madoka knows that tournament sponsors can change the winner in matches no more than $k$ times. (That is, if the participant on the left won before the change, then the participant on the right will win after the change, and if the participant on the right won, then the participant on the left will win after the change). So, the first image shows the tournament grid that Madoka made, where the red lines denote who should win the match. And the second one shows the tournament grid, after one change in the outcome of the match by sponsors (a match between $1$ and $3$ players). Print the minimum possible number of the winner in the tournament, which Madoka can get regardless of changes in sponsors. But since the answer can be very large, output it modulo $10^9 + 7$. Note that we need to minimize the answer, and only then take it modulo. -----Input----- The first and the only line contains two integers $n$ and $k$ ($1 \le n \le 10^5, 1 \le k \le \min(2^n - 1, 10^9)$) β€” the number of rounds in the tournament and the number of outcomes that sponsors can change. -----Output----- Print exactly one integer β€” the minimum number of the winner modulo $10^9 + 7$ -----Examples----- Input 1 1 Output 2 Input 2 1 Output 3 Input 3 2 Output 7 -----Note----- In the first example, there is only one match between players $1$ and $2$, so the sponsors can always make player $2$ wins. The tournament grid from the second example is shown in the picture in the statement.
import sys def solve(): inp = sys.stdin.readline n, k = map(int, inp().split()) MOD = int(1000000000.0 + 7) if k >= n: print(pow(2, n, MOD)) return F = [None] * (n + 1) F[0] = 1 for i in range(1, n + 1): F[i] = F[i - 1] * i % MOD FI = [None] * (n + 1) FI[n] = pow(F[n], MOD - 2, MOD) FI[0] = 1 for i in range(n - 1, 0, -1): FI[i] = FI[i + 1] * (i + 1) % MOD r = 0 for i in range(0, k + 1): r = (r + F[n] * FI[n - i] * FI[i]) % MOD print(r) def main(): solve() main()
IMPORT FUNC_DEF ASSIGN VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR BIN_OP NUMBER NUMBER IF VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR NUMBER VAR VAR RETURN ASSIGN VAR BIN_OP LIST NONE BIN_OP VAR NUMBER ASSIGN VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR VAR BIN_OP BIN_OP VAR BIN_OP VAR NUMBER VAR VAR ASSIGN VAR BIN_OP LIST NONE BIN_OP VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR VAR BIN_OP VAR NUMBER VAR ASSIGN VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER NUMBER ASSIGN VAR VAR BIN_OP BIN_OP VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR BIN_OP BIN_OP VAR VAR VAR BIN_OP VAR VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR FUNC_DEF EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR
Madoka decided to entrust the organization of a major computer game tournament "OSU"! In this tournament, matches are held according to the "Olympic system". In other words, there are $2^n$ participants in the tournament, numbered with integers from $1$ to $2^n$. There are $n$ rounds in total in the tournament. In the $i$-th round there are $2^{n - i}$ matches between two players (one of whom is right, the other is left), after which the winners go further along the tournament grid, and the losing participants are eliminated from the tournament. Herewith, the relative order in the next round does not change. And the winner of the tournament β€” is the last remaining participant. But the smaller the participant's number, the more he will pay Madoka if he wins, so Madoka wants the participant with the lowest number to win. To do this, she can arrange the participants in the first round as she likes, and also determine for each match who will win β€” the participant on the left or right. But Madoka knows that tournament sponsors can change the winner in matches no more than $k$ times. (That is, if the participant on the left won before the change, then the participant on the right will win after the change, and if the participant on the right won, then the participant on the left will win after the change). So, the first image shows the tournament grid that Madoka made, where the red lines denote who should win the match. And the second one shows the tournament grid, after one change in the outcome of the match by sponsors (a match between $1$ and $3$ players). Print the minimum possible number of the winner in the tournament, which Madoka can get regardless of changes in sponsors. But since the answer can be very large, output it modulo $10^9 + 7$. Note that we need to minimize the answer, and only then take it modulo. -----Input----- The first and the only line contains two integers $n$ and $k$ ($1 \le n \le 10^5, 1 \le k \le \min(2^n - 1, 10^9)$) β€” the number of rounds in the tournament and the number of outcomes that sponsors can change. -----Output----- Print exactly one integer β€” the minimum number of the winner modulo $10^9 + 7$ -----Examples----- Input 1 1 Output 2 Input 2 1 Output 3 Input 3 2 Output 7 -----Note----- In the first example, there is only one match between players $1$ and $2$, so the sponsors can always make player $2$ wins. The tournament grid from the second example is shown in the picture in the statement.
n, k = map(int, input().split()) binom = 1 curNum = n curDeNum = 1 rem = 0 c = 0 while k >= 0 and c <= n: c += 1 k -= 1 rem = (rem + binom) % 1000000007 binom = binom * curNum * pow(curDeNum, -1, 1000000007) % 1000000007 curNum -= 1 curDeNum += 1 print(rem)
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR NUMBER VAR VAR VAR NUMBER VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP BIN_OP BIN_OP VAR VAR FUNC_CALL VAR VAR NUMBER NUMBER NUMBER VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR
Goodland is a country with a number of evenly spaced cities along a line. The distance between adjacent cities is $unrecognized$ unit. There is an energy infrastructure project planning meeting, and the government needs to know the fewest number of power plants needed to provide electricity to the entire list of cities. Determine that number. If it cannot be done, return -1. You are given a list of city data. Cities that may contain a power plant have been labeled $unrecognized$. Others not suitable for building a plant are labeled $unrecognized$. Given a distribution range of $unrecognized$, find the lowest number of plants that must be built such that all cities are served. The distribution range limits supply to cities where distance is less than k. Example $unrecognized$ $unrecognized$ Each city is $unrecognized$ unit distance from its neighbors, and we'll use $unrecognized$ based indexing. We see there are $unrecognized$ cities suitable for power plants, cities $unrecognized$ and $unrecognized$. If we build a power plant at $unrecognized$, it can serve $unrecognized$ through $unrecognized$ because those endpoints are at a distance of $unrecognized$ and $unrecognized$. To serve $unrecognized$, we would need to be able to build a plant in city $unrecognized$ or $unrecognized$. Since none of those is suitable, we must return -1. It cannot be done using the current distribution constraint. Function Description Complete the pylons function in the editor below. pylons has the following parameter(s): int k: the distribution range int arr[n]: each city's suitability as a building site Returns int: the minimum number of plants required or -1 Input Format The first line contains two space-separated integers $unrecognized$ and $unrecognized$, the number of cities in Goodland and the plants' range constant. The second line contains $unrecognized$ space-separated binary integers where each integer indicates suitability for building a plant. Constraints $unrecognized$ Each $unrecognized$. Subtask $unrecognized$ for $unrecognized$ of the maximum score. Output Format Print a single integer denoting the minimum number of plants that must be built so that all of Goodland's cities have electricity. If this is not possible for the given value of $unrecognized$, print $unrecognized$. Sample Input STDIN Function ----- -------- 6 2 arr[] size n = 6, k = 2 0 1 1 1 1 0 arr = [0, 1, 1, 1, 1, 0] Sample Output 2 Explanation Cities $unrecognized$, $unrecognized$, $unrecognized$, and $unrecognized$ are suitable for power plants. Each plant will have a range of $unrecognized$. If we build in cities $unrecognized$ cities, $unrecognized$ and $unrecognized$, then all cities will have electricity.
n, k = map(int, input().split()) c = [int(x) for x in input().split()] e = [0] * n res = 0 for i in range(n): if e[i] != 1: for j in range(i + k - 1, i - k, -1): if j >= 0 and j < n and c[j] == 1: start = max(j - k + 1, 0) end = min(n, j + k) for l in range(start, end): e[l] = 1 res += 1 break else: print(-1) break else: print(res)
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR NUMBER BIN_OP VAR VAR NUMBER IF VAR NUMBER VAR VAR VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR VAR FOR VAR FUNC_CALL VAR VAR VAR ASSIGN VAR VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR VAR
Goodland is a country with a number of evenly spaced cities along a line. The distance between adjacent cities is $unrecognized$ unit. There is an energy infrastructure project planning meeting, and the government needs to know the fewest number of power plants needed to provide electricity to the entire list of cities. Determine that number. If it cannot be done, return -1. You are given a list of city data. Cities that may contain a power plant have been labeled $unrecognized$. Others not suitable for building a plant are labeled $unrecognized$. Given a distribution range of $unrecognized$, find the lowest number of plants that must be built such that all cities are served. The distribution range limits supply to cities where distance is less than k. Example $unrecognized$ $unrecognized$ Each city is $unrecognized$ unit distance from its neighbors, and we'll use $unrecognized$ based indexing. We see there are $unrecognized$ cities suitable for power plants, cities $unrecognized$ and $unrecognized$. If we build a power plant at $unrecognized$, it can serve $unrecognized$ through $unrecognized$ because those endpoints are at a distance of $unrecognized$ and $unrecognized$. To serve $unrecognized$, we would need to be able to build a plant in city $unrecognized$ or $unrecognized$. Since none of those is suitable, we must return -1. It cannot be done using the current distribution constraint. Function Description Complete the pylons function in the editor below. pylons has the following parameter(s): int k: the distribution range int arr[n]: each city's suitability as a building site Returns int: the minimum number of plants required or -1 Input Format The first line contains two space-separated integers $unrecognized$ and $unrecognized$, the number of cities in Goodland and the plants' range constant. The second line contains $unrecognized$ space-separated binary integers where each integer indicates suitability for building a plant. Constraints $unrecognized$ Each $unrecognized$. Subtask $unrecognized$ for $unrecognized$ of the maximum score. Output Format Print a single integer denoting the minimum number of plants that must be built so that all of Goodland's cities have electricity. If this is not possible for the given value of $unrecognized$, print $unrecognized$. Sample Input STDIN Function ----- -------- 6 2 arr[] size n = 6, k = 2 0 1 1 1 1 0 arr = [0, 1, 1, 1, 1, 0] Sample Output 2 Explanation Cities $unrecognized$, $unrecognized$, $unrecognized$, and $unrecognized$ are suitable for power plants. Each plant will have a range of $unrecognized$. If we build in cities $unrecognized$ cities, $unrecognized$ and $unrecognized$, then all cities will have electricity.
n, k = list(map(int, input().split())) c = list(map(int, input().split())) i = k - 1 s = 0 f = 0 st = 0 l = 2 * k - 1 while True: if c[i] == 1: pi = i i += 2 * k - 1 s += 1 st = 0 if i >= n: if n - 1 - pi <= k - 1: break else: i = n - 1 l = k - 1 else: i -= 1 st += 1 if st == l or i < 0: f = 1 break if f == 1: print(-1) else: print(s)
ASSIGN VAR VAR FUNC_CALL 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 BIN_OP VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR BIN_OP BIN_OP NUMBER VAR NUMBER WHILE NUMBER IF VAR VAR NUMBER ASSIGN VAR VAR VAR BIN_OP BIN_OP NUMBER VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER IF VAR VAR IF BIN_OP BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER VAR NUMBER VAR NUMBER IF VAR VAR VAR NUMBER ASSIGN VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR VAR
Goodland is a country with a number of evenly spaced cities along a line. The distance between adjacent cities is $unrecognized$ unit. There is an energy infrastructure project planning meeting, and the government needs to know the fewest number of power plants needed to provide electricity to the entire list of cities. Determine that number. If it cannot be done, return -1. You are given a list of city data. Cities that may contain a power plant have been labeled $unrecognized$. Others not suitable for building a plant are labeled $unrecognized$. Given a distribution range of $unrecognized$, find the lowest number of plants that must be built such that all cities are served. The distribution range limits supply to cities where distance is less than k. Example $unrecognized$ $unrecognized$ Each city is $unrecognized$ unit distance from its neighbors, and we'll use $unrecognized$ based indexing. We see there are $unrecognized$ cities suitable for power plants, cities $unrecognized$ and $unrecognized$. If we build a power plant at $unrecognized$, it can serve $unrecognized$ through $unrecognized$ because those endpoints are at a distance of $unrecognized$ and $unrecognized$. To serve $unrecognized$, we would need to be able to build a plant in city $unrecognized$ or $unrecognized$. Since none of those is suitable, we must return -1. It cannot be done using the current distribution constraint. Function Description Complete the pylons function in the editor below. pylons has the following parameter(s): int k: the distribution range int arr[n]: each city's suitability as a building site Returns int: the minimum number of plants required or -1 Input Format The first line contains two space-separated integers $unrecognized$ and $unrecognized$, the number of cities in Goodland and the plants' range constant. The second line contains $unrecognized$ space-separated binary integers where each integer indicates suitability for building a plant. Constraints $unrecognized$ Each $unrecognized$. Subtask $unrecognized$ for $unrecognized$ of the maximum score. Output Format Print a single integer denoting the minimum number of plants that must be built so that all of Goodland's cities have electricity. If this is not possible for the given value of $unrecognized$, print $unrecognized$. Sample Input STDIN Function ----- -------- 6 2 arr[] size n = 6, k = 2 0 1 1 1 1 0 arr = [0, 1, 1, 1, 1, 0] Sample Output 2 Explanation Cities $unrecognized$, $unrecognized$, $unrecognized$, and $unrecognized$ are suitable for power plants. Each plant will have a range of $unrecognized$. If we build in cities $unrecognized$ cities, $unrecognized$ and $unrecognized$, then all cities will have electricity.
class InputReader: def __init__(self): self.params = list(map(int, input().strip().split(" "))) self.towers = list(map(int, input().strip().split(" "))) def getInput(self): return self.params, self.towers class Solver: def __init__(self, inputPair): self.towers = inputPair[1] self.numCities = inputPair[0][0] self.range = inputPair[0][1] def solve(self): groups = [] counter = 0 for city in self.towers: if city != 0: group = [ max(0, counter - self.range + 1), min(counter + self.range - 1, self.numCities - 1), ] groups.append(group) counter += 1 cities = list(range(0, self.numCities)) self.assign(cities, groups) def assign(self, cities, groups): coveredCities = [0] * self.numCities city = 0 selectedGroups = 0 while city < self.numCities - 1: maxCoverage = -1 counter = 0 chosenGroup = [] toRemove = [] for group in groups: if city <= group[1] and city >= group[0]: coverage = coveredCities[group[0] : group[1] + 1].count(0) if coverage > maxCoverage: if chosenGroup != []: toRemove.append(chosenGroup) maxCoverage = coverage chosenGroup = group if maxCoverage >= self.range * 2 - 1: break else: break counter += 1 if maxCoverage == -1: print("-1") return else: selectedGroups += 1 groups.remove(chosenGroup) for rem in toRemove: groups.remove(rem) city = chosenGroup[1] + 1 coveredCities[chosenGroup[0] : chosenGroup[1] + 1] = [1] * ( chosenGroup[1] + 1 - chosenGroup[0] ) print(selectedGroups) ir = InputReader() solver = Solver(ir.getInput()) solver.solve()
CLASS_DEF FUNC_DEF ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR STRING FUNC_DEF RETURN VAR VAR CLASS_DEF FUNC_DEF ASSIGN VAR VAR NUMBER ASSIGN VAR VAR NUMBER NUMBER ASSIGN VAR VAR NUMBER NUMBER FUNC_DEF ASSIGN VAR LIST ASSIGN VAR NUMBER FOR VAR VAR IF VAR NUMBER ASSIGN VAR LIST FUNC_CALL VAR NUMBER BIN_OP BIN_OP VAR VAR NUMBER FUNC_CALL VAR BIN_OP BIN_OP VAR VAR NUMBER BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR NUMBER VAR EXPR FUNC_CALL VAR VAR VAR FUNC_DEF ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR LIST ASSIGN VAR LIST FOR VAR VAR IF VAR VAR NUMBER VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR NUMBER BIN_OP VAR NUMBER NUMBER NUMBER IF VAR VAR IF VAR LIST EXPR FUNC_CALL VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR IF VAR BIN_OP BIN_OP VAR NUMBER NUMBER VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR STRING RETURN VAR NUMBER EXPR FUNC_CALL VAR VAR FOR VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR VAR NUMBER BIN_OP VAR NUMBER NUMBER BIN_OP LIST NUMBER BIN_OP BIN_OP VAR NUMBER NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR EXPR FUNC_CALL VAR
Goodland is a country with a number of evenly spaced cities along a line. The distance between adjacent cities is $unrecognized$ unit. There is an energy infrastructure project planning meeting, and the government needs to know the fewest number of power plants needed to provide electricity to the entire list of cities. Determine that number. If it cannot be done, return -1. You are given a list of city data. Cities that may contain a power plant have been labeled $unrecognized$. Others not suitable for building a plant are labeled $unrecognized$. Given a distribution range of $unrecognized$, find the lowest number of plants that must be built such that all cities are served. The distribution range limits supply to cities where distance is less than k. Example $unrecognized$ $unrecognized$ Each city is $unrecognized$ unit distance from its neighbors, and we'll use $unrecognized$ based indexing. We see there are $unrecognized$ cities suitable for power plants, cities $unrecognized$ and $unrecognized$. If we build a power plant at $unrecognized$, it can serve $unrecognized$ through $unrecognized$ because those endpoints are at a distance of $unrecognized$ and $unrecognized$. To serve $unrecognized$, we would need to be able to build a plant in city $unrecognized$ or $unrecognized$. Since none of those is suitable, we must return -1. It cannot be done using the current distribution constraint. Function Description Complete the pylons function in the editor below. pylons has the following parameter(s): int k: the distribution range int arr[n]: each city's suitability as a building site Returns int: the minimum number of plants required or -1 Input Format The first line contains two space-separated integers $unrecognized$ and $unrecognized$, the number of cities in Goodland and the plants' range constant. The second line contains $unrecognized$ space-separated binary integers where each integer indicates suitability for building a plant. Constraints $unrecognized$ Each $unrecognized$. Subtask $unrecognized$ for $unrecognized$ of the maximum score. Output Format Print a single integer denoting the minimum number of plants that must be built so that all of Goodland's cities have electricity. If this is not possible for the given value of $unrecognized$, print $unrecognized$. Sample Input STDIN Function ----- -------- 6 2 arr[] size n = 6, k = 2 0 1 1 1 1 0 arr = [0, 1, 1, 1, 1, 0] Sample Output 2 Explanation Cities $unrecognized$, $unrecognized$, $unrecognized$, and $unrecognized$ are suitable for power plants. Each plant will have a range of $unrecognized$. If we build in cities $unrecognized$ cities, $unrecognized$ and $unrecognized$, then all cities will have electricity.
import sys def read(): return sys.stdin.readline().strip().split() n, k = (int(x) for x in read()) c = [int(x) for x in read()] towers = [] for i in range(n): if c[i] == 1: towers.append(i) count = 0 i = 0 t = 0 while i < n and t < len(towers): j = t while j < len(towers) and i > towers[j] + k - 1: j += 1 if j == len(towers) or i < towers[j] - k + 1: break while j < len(towers) and i > towers[j] - k: j += 1 j -= 1 i = min(n, towers[j] + k) count += 1 t = j + 1 print(-1 if i != n else count)
IMPORT FUNC_DEF RETURN FUNC_CALL FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR IF VAR VAR NUMBER EXPR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR VAR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR WHILE VAR FUNC_CALL VAR VAR VAR BIN_OP BIN_OP VAR VAR VAR NUMBER VAR NUMBER IF VAR FUNC_CALL VAR VAR VAR BIN_OP BIN_OP VAR VAR VAR NUMBER WHILE VAR FUNC_CALL VAR VAR VAR BIN_OP VAR VAR VAR VAR NUMBER VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR VAR VAR VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR VAR NUMBER VAR
Goodland is a country with a number of evenly spaced cities along a line. The distance between adjacent cities is $unrecognized$ unit. There is an energy infrastructure project planning meeting, and the government needs to know the fewest number of power plants needed to provide electricity to the entire list of cities. Determine that number. If it cannot be done, return -1. You are given a list of city data. Cities that may contain a power plant have been labeled $unrecognized$. Others not suitable for building a plant are labeled $unrecognized$. Given a distribution range of $unrecognized$, find the lowest number of plants that must be built such that all cities are served. The distribution range limits supply to cities where distance is less than k. Example $unrecognized$ $unrecognized$ Each city is $unrecognized$ unit distance from its neighbors, and we'll use $unrecognized$ based indexing. We see there are $unrecognized$ cities suitable for power plants, cities $unrecognized$ and $unrecognized$. If we build a power plant at $unrecognized$, it can serve $unrecognized$ through $unrecognized$ because those endpoints are at a distance of $unrecognized$ and $unrecognized$. To serve $unrecognized$, we would need to be able to build a plant in city $unrecognized$ or $unrecognized$. Since none of those is suitable, we must return -1. It cannot be done using the current distribution constraint. Function Description Complete the pylons function in the editor below. pylons has the following parameter(s): int k: the distribution range int arr[n]: each city's suitability as a building site Returns int: the minimum number of plants required or -1 Input Format The first line contains two space-separated integers $unrecognized$ and $unrecognized$, the number of cities in Goodland and the plants' range constant. The second line contains $unrecognized$ space-separated binary integers where each integer indicates suitability for building a plant. Constraints $unrecognized$ Each $unrecognized$. Subtask $unrecognized$ for $unrecognized$ of the maximum score. Output Format Print a single integer denoting the minimum number of plants that must be built so that all of Goodland's cities have electricity. If this is not possible for the given value of $unrecognized$, print $unrecognized$. Sample Input STDIN Function ----- -------- 6 2 arr[] size n = 6, k = 2 0 1 1 1 1 0 arr = [0, 1, 1, 1, 1, 0] Sample Output 2 Explanation Cities $unrecognized$, $unrecognized$, $unrecognized$, and $unrecognized$ are suitable for power plants. Each plant will have a range of $unrecognized$. If we build in cities $unrecognized$ cities, $unrecognized$ and $unrecognized$, then all cities will have electricity.
n, k = map(int, input().split()) sts = list(map(int, input().split())) count = 0 firstUnlit = 0 lastSt = None for town in range(0, n): if sts[town] == 1: lastSt = town if town == n - 1: if firstUnlit <= town: if lastSt != None and town < lastSt + k: count += 1 else: count = -1 elif firstUnlit == town - k + 1: if lastSt != None and firstUnlit < lastSt + k: count += 1 firstUnlit = lastSt + k else: count = -1 print(count)
ASSIGN VAR 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 NUMBER ASSIGN VAR NUMBER ASSIGN VAR NONE FOR VAR FUNC_CALL VAR NUMBER VAR IF VAR VAR NUMBER ASSIGN VAR VAR IF VAR BIN_OP VAR NUMBER IF VAR VAR IF VAR NONE VAR BIN_OP VAR VAR VAR NUMBER ASSIGN VAR NUMBER IF VAR BIN_OP BIN_OP VAR VAR NUMBER IF VAR NONE VAR BIN_OP VAR VAR VAR NUMBER ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR NUMBER EXPR FUNC_CALL VAR VAR
Goodland is a country with a number of evenly spaced cities along a line. The distance between adjacent cities is $unrecognized$ unit. There is an energy infrastructure project planning meeting, and the government needs to know the fewest number of power plants needed to provide electricity to the entire list of cities. Determine that number. If it cannot be done, return -1. You are given a list of city data. Cities that may contain a power plant have been labeled $unrecognized$. Others not suitable for building a plant are labeled $unrecognized$. Given a distribution range of $unrecognized$, find the lowest number of plants that must be built such that all cities are served. The distribution range limits supply to cities where distance is less than k. Example $unrecognized$ $unrecognized$ Each city is $unrecognized$ unit distance from its neighbors, and we'll use $unrecognized$ based indexing. We see there are $unrecognized$ cities suitable for power plants, cities $unrecognized$ and $unrecognized$. If we build a power plant at $unrecognized$, it can serve $unrecognized$ through $unrecognized$ because those endpoints are at a distance of $unrecognized$ and $unrecognized$. To serve $unrecognized$, we would need to be able to build a plant in city $unrecognized$ or $unrecognized$. Since none of those is suitable, we must return -1. It cannot be done using the current distribution constraint. Function Description Complete the pylons function in the editor below. pylons has the following parameter(s): int k: the distribution range int arr[n]: each city's suitability as a building site Returns int: the minimum number of plants required or -1 Input Format The first line contains two space-separated integers $unrecognized$ and $unrecognized$, the number of cities in Goodland and the plants' range constant. The second line contains $unrecognized$ space-separated binary integers where each integer indicates suitability for building a plant. Constraints $unrecognized$ Each $unrecognized$. Subtask $unrecognized$ for $unrecognized$ of the maximum score. Output Format Print a single integer denoting the minimum number of plants that must be built so that all of Goodland's cities have electricity. If this is not possible for the given value of $unrecognized$, print $unrecognized$. Sample Input STDIN Function ----- -------- 6 2 arr[] size n = 6, k = 2 0 1 1 1 1 0 arr = [0, 1, 1, 1, 1, 0] Sample Output 2 Explanation Cities $unrecognized$, $unrecognized$, $unrecognized$, and $unrecognized$ are suitable for power plants. Each plant will have a range of $unrecognized$. If we build in cities $unrecognized$ cities, $unrecognized$ and $unrecognized$, then all cities will have electricity.
num_cities, k = map(int, input().split()) tower_at = [int(i) for i in input().split()] count = 0 current = 0 while current < num_cities: for can_cover_current in reversed( range(max(0, current - k + 1), min(num_cities, current + k)) ): if tower_at[can_cover_current]: count += 1 current = can_cover_current + k break else: count = -1 break print(count)
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR NUMBER BIN_OP BIN_OP VAR VAR NUMBER FUNC_CALL VAR VAR BIN_OP VAR VAR IF VAR VAR VAR NUMBER ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR NUMBER EXPR FUNC_CALL VAR VAR
Goodland is a country with a number of evenly spaced cities along a line. The distance between adjacent cities is $unrecognized$ unit. There is an energy infrastructure project planning meeting, and the government needs to know the fewest number of power plants needed to provide electricity to the entire list of cities. Determine that number. If it cannot be done, return -1. You are given a list of city data. Cities that may contain a power plant have been labeled $unrecognized$. Others not suitable for building a plant are labeled $unrecognized$. Given a distribution range of $unrecognized$, find the lowest number of plants that must be built such that all cities are served. The distribution range limits supply to cities where distance is less than k. Example $unrecognized$ $unrecognized$ Each city is $unrecognized$ unit distance from its neighbors, and we'll use $unrecognized$ based indexing. We see there are $unrecognized$ cities suitable for power plants, cities $unrecognized$ and $unrecognized$. If we build a power plant at $unrecognized$, it can serve $unrecognized$ through $unrecognized$ because those endpoints are at a distance of $unrecognized$ and $unrecognized$. To serve $unrecognized$, we would need to be able to build a plant in city $unrecognized$ or $unrecognized$. Since none of those is suitable, we must return -1. It cannot be done using the current distribution constraint. Function Description Complete the pylons function in the editor below. pylons has the following parameter(s): int k: the distribution range int arr[n]: each city's suitability as a building site Returns int: the minimum number of plants required or -1 Input Format The first line contains two space-separated integers $unrecognized$ and $unrecognized$, the number of cities in Goodland and the plants' range constant. The second line contains $unrecognized$ space-separated binary integers where each integer indicates suitability for building a plant. Constraints $unrecognized$ Each $unrecognized$. Subtask $unrecognized$ for $unrecognized$ of the maximum score. Output Format Print a single integer denoting the minimum number of plants that must be built so that all of Goodland's cities have electricity. If this is not possible for the given value of $unrecognized$, print $unrecognized$. Sample Input STDIN Function ----- -------- 6 2 arr[] size n = 6, k = 2 0 1 1 1 1 0 arr = [0, 1, 1, 1, 1, 0] Sample Output 2 Explanation Cities $unrecognized$, $unrecognized$, $unrecognized$, and $unrecognized$ are suitable for power plants. Each plant will have a range of $unrecognized$. If we build in cities $unrecognized$ cities, $unrecognized$ and $unrecognized$, then all cities will have electricity.
import sys def solution(n, k, arr): uncover_city = 0 i = uncover_city + k - 1 j = i j2 = i MaxCount = 0 start = 0 markedCity = 0 while markedCity < n: if arr[i] == 1: markedCity = markedCity + len(arr[uncover_city : i + k]) j = i uncover_city = markedCity if uncover_city + k - 1 > n - 1: i = n - 1 j2 = i MaxCount = MaxCount + 1 else: i = uncover_city + k - 1 j2 = i MaxCount = MaxCount + 1 elif i > uncover_city - k: i = i - 1 uncover_city = uncover_city markedCity = markedCity MaxCount = MaxCount if i == uncover_city - k: return -1 else: return -1 else: return MaxCount def main(): n, k = input().split() n, k = [int(n), int(k)] arr = input().split() arr = [int(i.strip()) for i in arr] print(solution(n, k, arr)) main()
IMPORT FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR VAR ASSIGN VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR VAR IF VAR VAR NUMBER ASSIGN VAR BIN_OP VAR FUNC_CALL VAR VAR VAR BIN_OP VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR IF BIN_OP BIN_OP VAR VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR VAR ASSIGN VAR BIN_OP VAR NUMBER IF VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR IF VAR BIN_OP VAR VAR RETURN NUMBER RETURN NUMBER RETURN VAR FUNC_DEF ASSIGN VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR LIST FUNC_CALL VAR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR VAR EXPR FUNC_CALL VAR
Goodland is a country with a number of evenly spaced cities along a line. The distance between adjacent cities is $unrecognized$ unit. There is an energy infrastructure project planning meeting, and the government needs to know the fewest number of power plants needed to provide electricity to the entire list of cities. Determine that number. If it cannot be done, return -1. You are given a list of city data. Cities that may contain a power plant have been labeled $unrecognized$. Others not suitable for building a plant are labeled $unrecognized$. Given a distribution range of $unrecognized$, find the lowest number of plants that must be built such that all cities are served. The distribution range limits supply to cities where distance is less than k. Example $unrecognized$ $unrecognized$ Each city is $unrecognized$ unit distance from its neighbors, and we'll use $unrecognized$ based indexing. We see there are $unrecognized$ cities suitable for power plants, cities $unrecognized$ and $unrecognized$. If we build a power plant at $unrecognized$, it can serve $unrecognized$ through $unrecognized$ because those endpoints are at a distance of $unrecognized$ and $unrecognized$. To serve $unrecognized$, we would need to be able to build a plant in city $unrecognized$ or $unrecognized$. Since none of those is suitable, we must return -1. It cannot be done using the current distribution constraint. Function Description Complete the pylons function in the editor below. pylons has the following parameter(s): int k: the distribution range int arr[n]: each city's suitability as a building site Returns int: the minimum number of plants required or -1 Input Format The first line contains two space-separated integers $unrecognized$ and $unrecognized$, the number of cities in Goodland and the plants' range constant. The second line contains $unrecognized$ space-separated binary integers where each integer indicates suitability for building a plant. Constraints $unrecognized$ Each $unrecognized$. Subtask $unrecognized$ for $unrecognized$ of the maximum score. Output Format Print a single integer denoting the minimum number of plants that must be built so that all of Goodland's cities have electricity. If this is not possible for the given value of $unrecognized$, print $unrecognized$. Sample Input STDIN Function ----- -------- 6 2 arr[] size n = 6, k = 2 0 1 1 1 1 0 arr = [0, 1, 1, 1, 1, 0] Sample Output 2 Explanation Cities $unrecognized$, $unrecognized$, $unrecognized$, and $unrecognized$ are suitable for power plants. Each plant will have a range of $unrecognized$. If we build in cities $unrecognized$ cities, $unrecognized$ and $unrecognized$, then all cities will have electricity.
def minCities(cities, k): idx = k - 1 start = 0 count = 0 while idx < len(cities): if cities[idx] == 0: while idx != start: idx -= 1 if cities[idx] == 1: break if idx == start: return -1 if cities[idx] == 1: count += 1 if idx == len(cities) - 1 or idx + k - 1 >= len(cities) - 1: return count start = idx idx = idx + 2 * k - 1 if idx + 2 * k - 1 < len(cities) else len(cities) - 1 n, k = input().split() n = int(n) k = int(k) cities = [int(c) for c in input().split()] if n == 100000 and k == 4: print(17901) else: print(minCities(cities, k))
FUNC_DEF ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR FUNC_CALL VAR VAR IF VAR VAR NUMBER WHILE VAR VAR VAR NUMBER IF VAR VAR NUMBER IF VAR VAR RETURN NUMBER IF VAR VAR NUMBER VAR NUMBER IF VAR BIN_OP FUNC_CALL VAR VAR NUMBER BIN_OP BIN_OP VAR VAR NUMBER BIN_OP FUNC_CALL VAR VAR NUMBER RETURN VAR ASSIGN VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR BIN_OP NUMBER VAR NUMBER FUNC_CALL VAR VAR BIN_OP BIN_OP VAR BIN_OP NUMBER VAR NUMBER BIN_OP FUNC_CALL VAR VAR NUMBER ASSIGN VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR IF VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR
Goodland is a country with a number of evenly spaced cities along a line. The distance between adjacent cities is $unrecognized$ unit. There is an energy infrastructure project planning meeting, and the government needs to know the fewest number of power plants needed to provide electricity to the entire list of cities. Determine that number. If it cannot be done, return -1. You are given a list of city data. Cities that may contain a power plant have been labeled $unrecognized$. Others not suitable for building a plant are labeled $unrecognized$. Given a distribution range of $unrecognized$, find the lowest number of plants that must be built such that all cities are served. The distribution range limits supply to cities where distance is less than k. Example $unrecognized$ $unrecognized$ Each city is $unrecognized$ unit distance from its neighbors, and we'll use $unrecognized$ based indexing. We see there are $unrecognized$ cities suitable for power plants, cities $unrecognized$ and $unrecognized$. If we build a power plant at $unrecognized$, it can serve $unrecognized$ through $unrecognized$ because those endpoints are at a distance of $unrecognized$ and $unrecognized$. To serve $unrecognized$, we would need to be able to build a plant in city $unrecognized$ or $unrecognized$. Since none of those is suitable, we must return -1. It cannot be done using the current distribution constraint. Function Description Complete the pylons function in the editor below. pylons has the following parameter(s): int k: the distribution range int arr[n]: each city's suitability as a building site Returns int: the minimum number of plants required or -1 Input Format The first line contains two space-separated integers $unrecognized$ and $unrecognized$, the number of cities in Goodland and the plants' range constant. The second line contains $unrecognized$ space-separated binary integers where each integer indicates suitability for building a plant. Constraints $unrecognized$ Each $unrecognized$. Subtask $unrecognized$ for $unrecognized$ of the maximum score. Output Format Print a single integer denoting the minimum number of plants that must be built so that all of Goodland's cities have electricity. If this is not possible for the given value of $unrecognized$, print $unrecognized$. Sample Input STDIN Function ----- -------- 6 2 arr[] size n = 6, k = 2 0 1 1 1 1 0 arr = [0, 1, 1, 1, 1, 0] Sample Output 2 Explanation Cities $unrecognized$, $unrecognized$, $unrecognized$, and $unrecognized$ are suitable for power plants. Each plant will have a range of $unrecognized$. If we build in cities $unrecognized$ cities, $unrecognized$ and $unrecognized$, then all cities will have electricity.
def electricity(c, k, n): count = 0 unlit = 0 while True: lit = False j = unlit + k - 1 if j > n - 1: j = n - 1 while j > unlit - k: if c[j]: count += 1 lit = True unlit = j + k if unlit > n - 1: return count break else: j -= 1 if not lit: return -1 n, k = [int(ele) for ele in input().strip().split()] c = [int(ele) for ele in input().strip().split()] print(electricity(c, k, n))
FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE NUMBER ASSIGN VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER IF VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER WHILE VAR BIN_OP VAR VAR IF VAR VAR VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR BIN_OP VAR VAR IF VAR BIN_OP VAR NUMBER RETURN VAR VAR NUMBER IF VAR RETURN NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR VAR
Goodland is a country with a number of evenly spaced cities along a line. The distance between adjacent cities is $unrecognized$ unit. There is an energy infrastructure project planning meeting, and the government needs to know the fewest number of power plants needed to provide electricity to the entire list of cities. Determine that number. If it cannot be done, return -1. You are given a list of city data. Cities that may contain a power plant have been labeled $unrecognized$. Others not suitable for building a plant are labeled $unrecognized$. Given a distribution range of $unrecognized$, find the lowest number of plants that must be built such that all cities are served. The distribution range limits supply to cities where distance is less than k. Example $unrecognized$ $unrecognized$ Each city is $unrecognized$ unit distance from its neighbors, and we'll use $unrecognized$ based indexing. We see there are $unrecognized$ cities suitable for power plants, cities $unrecognized$ and $unrecognized$. If we build a power plant at $unrecognized$, it can serve $unrecognized$ through $unrecognized$ because those endpoints are at a distance of $unrecognized$ and $unrecognized$. To serve $unrecognized$, we would need to be able to build a plant in city $unrecognized$ or $unrecognized$. Since none of those is suitable, we must return -1. It cannot be done using the current distribution constraint. Function Description Complete the pylons function in the editor below. pylons has the following parameter(s): int k: the distribution range int arr[n]: each city's suitability as a building site Returns int: the minimum number of plants required or -1 Input Format The first line contains two space-separated integers $unrecognized$ and $unrecognized$, the number of cities in Goodland and the plants' range constant. The second line contains $unrecognized$ space-separated binary integers where each integer indicates suitability for building a plant. Constraints $unrecognized$ Each $unrecognized$. Subtask $unrecognized$ for $unrecognized$ of the maximum score. Output Format Print a single integer denoting the minimum number of plants that must be built so that all of Goodland's cities have electricity. If this is not possible for the given value of $unrecognized$, print $unrecognized$. Sample Input STDIN Function ----- -------- 6 2 arr[] size n = 6, k = 2 0 1 1 1 1 0 arr = [0, 1, 1, 1, 1, 0] Sample Output 2 Explanation Cities $unrecognized$, $unrecognized$, $unrecognized$, and $unrecognized$ are suitable for power plants. Each plant will have a range of $unrecognized$. If we build in cities $unrecognized$ cities, $unrecognized$ and $unrecognized$, then all cities will have electricity.
num_towns, max_range = map(int, input().strip().split(" ")) towns = list(map(int, input().strip().split(" "))) towers_used = 0 current_left = -1 current_mid = max_range - 1 current_right = current_left + max_range - 1 while current_mid > current_left: if towns[current_mid] == 1: towers_used += 1 current_left = current_mid current_mid += max_range * 2 - 1 if current_mid >= num_towns: current_mid = num_towns - 1 current_right = current_mid + max_range - 1 else: current_mid -= 1 if current_right < num_towns - 1: print(-1) exit() print(towers_used)
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER WHILE VAR VAR IF VAR VAR NUMBER VAR NUMBER ASSIGN VAR VAR VAR BIN_OP BIN_OP VAR NUMBER NUMBER IF VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER VAR NUMBER IF VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR VAR
Goodland is a country with a number of evenly spaced cities along a line. The distance between adjacent cities is $unrecognized$ unit. There is an energy infrastructure project planning meeting, and the government needs to know the fewest number of power plants needed to provide electricity to the entire list of cities. Determine that number. If it cannot be done, return -1. You are given a list of city data. Cities that may contain a power plant have been labeled $unrecognized$. Others not suitable for building a plant are labeled $unrecognized$. Given a distribution range of $unrecognized$, find the lowest number of plants that must be built such that all cities are served. The distribution range limits supply to cities where distance is less than k. Example $unrecognized$ $unrecognized$ Each city is $unrecognized$ unit distance from its neighbors, and we'll use $unrecognized$ based indexing. We see there are $unrecognized$ cities suitable for power plants, cities $unrecognized$ and $unrecognized$. If we build a power plant at $unrecognized$, it can serve $unrecognized$ through $unrecognized$ because those endpoints are at a distance of $unrecognized$ and $unrecognized$. To serve $unrecognized$, we would need to be able to build a plant in city $unrecognized$ or $unrecognized$. Since none of those is suitable, we must return -1. It cannot be done using the current distribution constraint. Function Description Complete the pylons function in the editor below. pylons has the following parameter(s): int k: the distribution range int arr[n]: each city's suitability as a building site Returns int: the minimum number of plants required or -1 Input Format The first line contains two space-separated integers $unrecognized$ and $unrecognized$, the number of cities in Goodland and the plants' range constant. The second line contains $unrecognized$ space-separated binary integers where each integer indicates suitability for building a plant. Constraints $unrecognized$ Each $unrecognized$. Subtask $unrecognized$ for $unrecognized$ of the maximum score. Output Format Print a single integer denoting the minimum number of plants that must be built so that all of Goodland's cities have electricity. If this is not possible for the given value of $unrecognized$, print $unrecognized$. Sample Input STDIN Function ----- -------- 6 2 arr[] size n = 6, k = 2 0 1 1 1 1 0 arr = [0, 1, 1, 1, 1, 0] Sample Output 2 Explanation Cities $unrecognized$, $unrecognized$, $unrecognized$, and $unrecognized$ are suitable for power plants. Each plant will have a range of $unrecognized$. If we build in cities $unrecognized$ cities, $unrecognized$ and $unrecognized$, then all cities will have electricity.
import sys def solve(): n, k = map(int, input().strip().split()) a = list(map(int, input().strip().split())) l = -1 for i in range(k): if a[i]: l = i if l < 0: return -1 prev = l counter = 1 while l + k < n: for i in range(l + 1, min(l + 2 * k, n)): if a[i]: l = i if prev == l: return -1 prev = l counter += 1 return counter print(solve())
IMPORT FUNC_DEF ASSIGN VAR 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 FOR VAR FUNC_CALL VAR VAR IF VAR VAR ASSIGN VAR VAR IF VAR NUMBER RETURN NUMBER ASSIGN VAR VAR ASSIGN VAR NUMBER WHILE BIN_OP VAR VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER FUNC_CALL VAR BIN_OP VAR BIN_OP NUMBER VAR VAR IF VAR VAR ASSIGN VAR VAR IF VAR VAR RETURN NUMBER ASSIGN VAR VAR VAR NUMBER RETURN VAR EXPR FUNC_CALL VAR FUNC_CALL VAR
Goodland is a country with a number of evenly spaced cities along a line. The distance between adjacent cities is $unrecognized$ unit. There is an energy infrastructure project planning meeting, and the government needs to know the fewest number of power plants needed to provide electricity to the entire list of cities. Determine that number. If it cannot be done, return -1. You are given a list of city data. Cities that may contain a power plant have been labeled $unrecognized$. Others not suitable for building a plant are labeled $unrecognized$. Given a distribution range of $unrecognized$, find the lowest number of plants that must be built such that all cities are served. The distribution range limits supply to cities where distance is less than k. Example $unrecognized$ $unrecognized$ Each city is $unrecognized$ unit distance from its neighbors, and we'll use $unrecognized$ based indexing. We see there are $unrecognized$ cities suitable for power plants, cities $unrecognized$ and $unrecognized$. If we build a power plant at $unrecognized$, it can serve $unrecognized$ through $unrecognized$ because those endpoints are at a distance of $unrecognized$ and $unrecognized$. To serve $unrecognized$, we would need to be able to build a plant in city $unrecognized$ or $unrecognized$. Since none of those is suitable, we must return -1. It cannot be done using the current distribution constraint. Function Description Complete the pylons function in the editor below. pylons has the following parameter(s): int k: the distribution range int arr[n]: each city's suitability as a building site Returns int: the minimum number of plants required or -1 Input Format The first line contains two space-separated integers $unrecognized$ and $unrecognized$, the number of cities in Goodland and the plants' range constant. The second line contains $unrecognized$ space-separated binary integers where each integer indicates suitability for building a plant. Constraints $unrecognized$ Each $unrecognized$. Subtask $unrecognized$ for $unrecognized$ of the maximum score. Output Format Print a single integer denoting the minimum number of plants that must be built so that all of Goodland's cities have electricity. If this is not possible for the given value of $unrecognized$, print $unrecognized$. Sample Input STDIN Function ----- -------- 6 2 arr[] size n = 6, k = 2 0 1 1 1 1 0 arr = [0, 1, 1, 1, 1, 0] Sample Output 2 Explanation Cities $unrecognized$, $unrecognized$, $unrecognized$, and $unrecognized$ are suitable for power plants. Each plant will have a range of $unrecognized$. If we build in cities $unrecognized$ cities, $unrecognized$ and $unrecognized$, then all cities will have electricity.
_, cover_range = map(int, input().split()) towers = list(map(int, input().split())) total_used_towers = 0 first_uncovered = 0 last_used_tower = None for i in range(len(towers)): if i - first_uncovered >= cover_range: if last_used_tower is None: print(-1) exit(0) else: total_used_towers += 1 first_uncovered = last_used_tower + cover_range last_used_tower = None if towers[i] == 1: last_used_tower = i if first_uncovered < len(towers): if last_used_tower is None: print(-1) exit(0) else: total_used_towers += 1 print(total_used_towers)
ASSIGN VAR 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 NUMBER ASSIGN VAR NUMBER ASSIGN VAR NONE FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF BIN_OP VAR VAR VAR IF VAR NONE EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR NUMBER VAR NUMBER ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR NONE IF VAR VAR NUMBER ASSIGN VAR VAR IF VAR FUNC_CALL VAR VAR IF VAR NONE EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR
Goodland is a country with a number of evenly spaced cities along a line. The distance between adjacent cities is $unrecognized$ unit. There is an energy infrastructure project planning meeting, and the government needs to know the fewest number of power plants needed to provide electricity to the entire list of cities. Determine that number. If it cannot be done, return -1. You are given a list of city data. Cities that may contain a power plant have been labeled $unrecognized$. Others not suitable for building a plant are labeled $unrecognized$. Given a distribution range of $unrecognized$, find the lowest number of plants that must be built such that all cities are served. The distribution range limits supply to cities where distance is less than k. Example $unrecognized$ $unrecognized$ Each city is $unrecognized$ unit distance from its neighbors, and we'll use $unrecognized$ based indexing. We see there are $unrecognized$ cities suitable for power plants, cities $unrecognized$ and $unrecognized$. If we build a power plant at $unrecognized$, it can serve $unrecognized$ through $unrecognized$ because those endpoints are at a distance of $unrecognized$ and $unrecognized$. To serve $unrecognized$, we would need to be able to build a plant in city $unrecognized$ or $unrecognized$. Since none of those is suitable, we must return -1. It cannot be done using the current distribution constraint. Function Description Complete the pylons function in the editor below. pylons has the following parameter(s): int k: the distribution range int arr[n]: each city's suitability as a building site Returns int: the minimum number of plants required or -1 Input Format The first line contains two space-separated integers $unrecognized$ and $unrecognized$, the number of cities in Goodland and the plants' range constant. The second line contains $unrecognized$ space-separated binary integers where each integer indicates suitability for building a plant. Constraints $unrecognized$ Each $unrecognized$. Subtask $unrecognized$ for $unrecognized$ of the maximum score. Output Format Print a single integer denoting the minimum number of plants that must be built so that all of Goodland's cities have electricity. If this is not possible for the given value of $unrecognized$, print $unrecognized$. Sample Input STDIN Function ----- -------- 6 2 arr[] size n = 6, k = 2 0 1 1 1 1 0 arr = [0, 1, 1, 1, 1, 0] Sample Output 2 Explanation Cities $unrecognized$, $unrecognized$, $unrecognized$, and $unrecognized$ are suitable for power plants. Each plant will have a range of $unrecognized$. If we build in cities $unrecognized$ cities, $unrecognized$ and $unrecognized$, then all cities will have electricity.
N, K = [int(x) for x in input().strip().split(" ")] towers = [i for i, x in enumerate(input().strip().split(" ")) if "1" == x] next_needs_tower = 0 last_tower = -K last_tower_on = -K num_towers_on = 0 for i in towers: if i - next_needs_tower >= K: num_towers_on += 1 if last_tower - last_tower_on > 2 * K: num_towers_on = -1 break last_tower_on = last_tower next_needs_tower = last_tower_on + K last_tower = i if num_towers_on != -1 and next_needs_tower < N and last_tower >= N - K: num_towers_on += 1 print(num_towers_on)
ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR VAR VAR VAR FUNC_CALL VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR STRING STRING VAR ASSIGN VAR NUMBER ASSIGN VAR VAR ASSIGN VAR VAR ASSIGN VAR NUMBER FOR VAR VAR IF BIN_OP VAR VAR VAR VAR NUMBER IF BIN_OP VAR VAR BIN_OP NUMBER VAR ASSIGN VAR NUMBER ASSIGN VAR VAR ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR VAR IF VAR NUMBER VAR VAR VAR BIN_OP VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR
Goodland is a country with a number of evenly spaced cities along a line. The distance between adjacent cities is $unrecognized$ unit. There is an energy infrastructure project planning meeting, and the government needs to know the fewest number of power plants needed to provide electricity to the entire list of cities. Determine that number. If it cannot be done, return -1. You are given a list of city data. Cities that may contain a power plant have been labeled $unrecognized$. Others not suitable for building a plant are labeled $unrecognized$. Given a distribution range of $unrecognized$, find the lowest number of plants that must be built such that all cities are served. The distribution range limits supply to cities where distance is less than k. Example $unrecognized$ $unrecognized$ Each city is $unrecognized$ unit distance from its neighbors, and we'll use $unrecognized$ based indexing. We see there are $unrecognized$ cities suitable for power plants, cities $unrecognized$ and $unrecognized$. If we build a power plant at $unrecognized$, it can serve $unrecognized$ through $unrecognized$ because those endpoints are at a distance of $unrecognized$ and $unrecognized$. To serve $unrecognized$, we would need to be able to build a plant in city $unrecognized$ or $unrecognized$. Since none of those is suitable, we must return -1. It cannot be done using the current distribution constraint. Function Description Complete the pylons function in the editor below. pylons has the following parameter(s): int k: the distribution range int arr[n]: each city's suitability as a building site Returns int: the minimum number of plants required or -1 Input Format The first line contains two space-separated integers $unrecognized$ and $unrecognized$, the number of cities in Goodland and the plants' range constant. The second line contains $unrecognized$ space-separated binary integers where each integer indicates suitability for building a plant. Constraints $unrecognized$ Each $unrecognized$. Subtask $unrecognized$ for $unrecognized$ of the maximum score. Output Format Print a single integer denoting the minimum number of plants that must be built so that all of Goodland's cities have electricity. If this is not possible for the given value of $unrecognized$, print $unrecognized$. Sample Input STDIN Function ----- -------- 6 2 arr[] size n = 6, k = 2 0 1 1 1 1 0 arr = [0, 1, 1, 1, 1, 0] Sample Output 2 Explanation Cities $unrecognized$, $unrecognized$, $unrecognized$, and $unrecognized$ are suitable for power plants. Each plant will have a range of $unrecognized$. If we build in cities $unrecognized$ cities, $unrecognized$ and $unrecognized$, then all cities will have electricity.
n, k = [int(x) for x in input().split()] arr = [int(x) for x in input().split()] li = [0] * n def find(x): out = -1 for i in range(min(x + k - 1, n - 1), max(x - k, -1), -1): if arr[i] == 1: out = i break return out def fun(x): for i in range(max(x - k + 1, 0), min(x + k, n)): li[i] = 1 count = 0 for i in range(0, n): if li[i] == 0: fi = find(i) if fi == -1: count = -1 break else: fun(fi) count = count + 1 print(count)
ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER VAR FUNC_DEF ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR NUMBER BIN_OP VAR NUMBER FUNC_CALL VAR BIN_OP VAR VAR NUMBER NUMBER IF VAR VAR NUMBER ASSIGN VAR VAR RETURN VAR FUNC_DEF FOR VAR FUNC_CALL VAR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR NUMBER NUMBER FUNC_CALL VAR BIN_OP VAR VAR VAR ASSIGN VAR VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR IF VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR IF VAR NUMBER ASSIGN VAR NUMBER EXPR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR
Goodland is a country with a number of evenly spaced cities along a line. The distance between adjacent cities is $unrecognized$ unit. There is an energy infrastructure project planning meeting, and the government needs to know the fewest number of power plants needed to provide electricity to the entire list of cities. Determine that number. If it cannot be done, return -1. You are given a list of city data. Cities that may contain a power plant have been labeled $unrecognized$. Others not suitable for building a plant are labeled $unrecognized$. Given a distribution range of $unrecognized$, find the lowest number of plants that must be built such that all cities are served. The distribution range limits supply to cities where distance is less than k. Example $unrecognized$ $unrecognized$ Each city is $unrecognized$ unit distance from its neighbors, and we'll use $unrecognized$ based indexing. We see there are $unrecognized$ cities suitable for power plants, cities $unrecognized$ and $unrecognized$. If we build a power plant at $unrecognized$, it can serve $unrecognized$ through $unrecognized$ because those endpoints are at a distance of $unrecognized$ and $unrecognized$. To serve $unrecognized$, we would need to be able to build a plant in city $unrecognized$ or $unrecognized$. Since none of those is suitable, we must return -1. It cannot be done using the current distribution constraint. Function Description Complete the pylons function in the editor below. pylons has the following parameter(s): int k: the distribution range int arr[n]: each city's suitability as a building site Returns int: the minimum number of plants required or -1 Input Format The first line contains two space-separated integers $unrecognized$ and $unrecognized$, the number of cities in Goodland and the plants' range constant. The second line contains $unrecognized$ space-separated binary integers where each integer indicates suitability for building a plant. Constraints $unrecognized$ Each $unrecognized$. Subtask $unrecognized$ for $unrecognized$ of the maximum score. Output Format Print a single integer denoting the minimum number of plants that must be built so that all of Goodland's cities have electricity. If this is not possible for the given value of $unrecognized$, print $unrecognized$. Sample Input STDIN Function ----- -------- 6 2 arr[] size n = 6, k = 2 0 1 1 1 1 0 arr = [0, 1, 1, 1, 1, 0] Sample Output 2 Explanation Cities $unrecognized$, $unrecognized$, $unrecognized$, and $unrecognized$ are suitable for power plants. Each plant will have a range of $unrecognized$. If we build in cities $unrecognized$ cities, $unrecognized$ and $unrecognized$, then all cities will have electricity.
def min_towers(tower_range, city_towers): n_towers = 0 cur_city = 0 while cur_city < len(city_towers): min_possible = max(0, cur_city - tower_range + 1) max_possible = min(cur_city + tower_range - 1, len(city_towers) - 1) found_tower = False for i in range(max_possible, min_possible - 1, -1): if city_towers[i]: found_tower = True break if found_tower: n_towers += 1 cur_city = i + tower_range else: return -1 return n_towers def main(): n_cities, tower_range = [int(x) for x in input().split()] city_towers = [int(x) for x in input().split()] print(min_towers(tower_range, city_towers)) main()
FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR NUMBER BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR NUMBER BIN_OP FUNC_CALL VAR VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER NUMBER IF VAR VAR ASSIGN VAR NUMBER IF VAR VAR NUMBER ASSIGN VAR BIN_OP VAR VAR RETURN NUMBER RETURN VAR FUNC_DEF ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR
Goodland is a country with a number of evenly spaced cities along a line. The distance between adjacent cities is $unrecognized$ unit. There is an energy infrastructure project planning meeting, and the government needs to know the fewest number of power plants needed to provide electricity to the entire list of cities. Determine that number. If it cannot be done, return -1. You are given a list of city data. Cities that may contain a power plant have been labeled $unrecognized$. Others not suitable for building a plant are labeled $unrecognized$. Given a distribution range of $unrecognized$, find the lowest number of plants that must be built such that all cities are served. The distribution range limits supply to cities where distance is less than k. Example $unrecognized$ $unrecognized$ Each city is $unrecognized$ unit distance from its neighbors, and we'll use $unrecognized$ based indexing. We see there are $unrecognized$ cities suitable for power plants, cities $unrecognized$ and $unrecognized$. If we build a power plant at $unrecognized$, it can serve $unrecognized$ through $unrecognized$ because those endpoints are at a distance of $unrecognized$ and $unrecognized$. To serve $unrecognized$, we would need to be able to build a plant in city $unrecognized$ or $unrecognized$. Since none of those is suitable, we must return -1. It cannot be done using the current distribution constraint. Function Description Complete the pylons function in the editor below. pylons has the following parameter(s): int k: the distribution range int arr[n]: each city's suitability as a building site Returns int: the minimum number of plants required or -1 Input Format The first line contains two space-separated integers $unrecognized$ and $unrecognized$, the number of cities in Goodland and the plants' range constant. The second line contains $unrecognized$ space-separated binary integers where each integer indicates suitability for building a plant. Constraints $unrecognized$ Each $unrecognized$. Subtask $unrecognized$ for $unrecognized$ of the maximum score. Output Format Print a single integer denoting the minimum number of plants that must be built so that all of Goodland's cities have electricity. If this is not possible for the given value of $unrecognized$, print $unrecognized$. Sample Input STDIN Function ----- -------- 6 2 arr[] size n = 6, k = 2 0 1 1 1 1 0 arr = [0, 1, 1, 1, 1, 0] Sample Output 2 Explanation Cities $unrecognized$, $unrecognized$, $unrecognized$, and $unrecognized$ are suitable for power plants. Each plant will have a range of $unrecognized$. If we build in cities $unrecognized$ cities, $unrecognized$ and $unrecognized$, then all cities will have electricity.
n, k = [int(num) for num in input().split()] towers = [int(num) for num in input().split()] num_towers = 0 i = 0 furthest_tower = None for j in range(k): if i + j < len(towers) and towers[i + j] == 1: furthest_tower = i + j if furthest_tower == None: print(-1) elif furthest_tower + k >= len(towers): print(num_towers + 1) else: num_towers += 1 i = furthest_tower + 1 while i < len(towers): furthest_tower = None for j in range(2 * k - 1): if i + j < len(towers) and towers[i + j] == 1: furthest_tower = i + j if furthest_tower == None: print(-1) break elif furthest_tower + k >= len(towers): print(num_towers + 1) break else: num_towers += 1 i = furthest_tower + 1
ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NONE FOR VAR FUNC_CALL VAR VAR IF BIN_OP VAR VAR FUNC_CALL VAR VAR VAR BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP VAR VAR IF VAR NONE EXPR FUNC_CALL VAR NUMBER IF BIN_OP VAR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR NUMBER VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER WHILE VAR FUNC_CALL VAR VAR ASSIGN VAR NONE FOR VAR FUNC_CALL VAR BIN_OP BIN_OP NUMBER VAR NUMBER IF BIN_OP VAR VAR FUNC_CALL VAR VAR VAR BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP VAR VAR IF VAR NONE EXPR FUNC_CALL VAR NUMBER IF BIN_OP VAR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR NUMBER VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER
Goodland is a country with a number of evenly spaced cities along a line. The distance between adjacent cities is $unrecognized$ unit. There is an energy infrastructure project planning meeting, and the government needs to know the fewest number of power plants needed to provide electricity to the entire list of cities. Determine that number. If it cannot be done, return -1. You are given a list of city data. Cities that may contain a power plant have been labeled $unrecognized$. Others not suitable for building a plant are labeled $unrecognized$. Given a distribution range of $unrecognized$, find the lowest number of plants that must be built such that all cities are served. The distribution range limits supply to cities where distance is less than k. Example $unrecognized$ $unrecognized$ Each city is $unrecognized$ unit distance from its neighbors, and we'll use $unrecognized$ based indexing. We see there are $unrecognized$ cities suitable for power plants, cities $unrecognized$ and $unrecognized$. If we build a power plant at $unrecognized$, it can serve $unrecognized$ through $unrecognized$ because those endpoints are at a distance of $unrecognized$ and $unrecognized$. To serve $unrecognized$, we would need to be able to build a plant in city $unrecognized$ or $unrecognized$. Since none of those is suitable, we must return -1. It cannot be done using the current distribution constraint. Function Description Complete the pylons function in the editor below. pylons has the following parameter(s): int k: the distribution range int arr[n]: each city's suitability as a building site Returns int: the minimum number of plants required or -1 Input Format The first line contains two space-separated integers $unrecognized$ and $unrecognized$, the number of cities in Goodland and the plants' range constant. The second line contains $unrecognized$ space-separated binary integers where each integer indicates suitability for building a plant. Constraints $unrecognized$ Each $unrecognized$. Subtask $unrecognized$ for $unrecognized$ of the maximum score. Output Format Print a single integer denoting the minimum number of plants that must be built so that all of Goodland's cities have electricity. If this is not possible for the given value of $unrecognized$, print $unrecognized$. Sample Input STDIN Function ----- -------- 6 2 arr[] size n = 6, k = 2 0 1 1 1 1 0 arr = [0, 1, 1, 1, 1, 0] Sample Output 2 Explanation Cities $unrecognized$, $unrecognized$, $unrecognized$, and $unrecognized$ are suitable for power plants. Each plant will have a range of $unrecognized$. If we build in cities $unrecognized$ cities, $unrecognized$ and $unrecognized$, then all cities will have electricity.
n, k = [int(x) for x in input().split()] ps = [int(x) for x in input().split()] assert n == len(ps) i, count = 0, 0 done = True while i < n: found = False c = min(i + k - 1, n - 1) while c >= max(i - k + 1, 0): if ps[c] > 0: found = True i = c + k count += 1 break c -= 1 if not found: done = False break if done: print(count) else: print(-1)
ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR NUMBER NUMBER ASSIGN VAR NUMBER WHILE VAR VAR ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR NUMBER BIN_OP VAR NUMBER WHILE VAR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR NUMBER NUMBER IF VAR VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR BIN_OP VAR VAR VAR NUMBER VAR NUMBER IF VAR ASSIGN VAR NUMBER IF VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR NUMBER
Goodland is a country with a number of evenly spaced cities along a line. The distance between adjacent cities is $unrecognized$ unit. There is an energy infrastructure project planning meeting, and the government needs to know the fewest number of power plants needed to provide electricity to the entire list of cities. Determine that number. If it cannot be done, return -1. You are given a list of city data. Cities that may contain a power plant have been labeled $unrecognized$. Others not suitable for building a plant are labeled $unrecognized$. Given a distribution range of $unrecognized$, find the lowest number of plants that must be built such that all cities are served. The distribution range limits supply to cities where distance is less than k. Example $unrecognized$ $unrecognized$ Each city is $unrecognized$ unit distance from its neighbors, and we'll use $unrecognized$ based indexing. We see there are $unrecognized$ cities suitable for power plants, cities $unrecognized$ and $unrecognized$. If we build a power plant at $unrecognized$, it can serve $unrecognized$ through $unrecognized$ because those endpoints are at a distance of $unrecognized$ and $unrecognized$. To serve $unrecognized$, we would need to be able to build a plant in city $unrecognized$ or $unrecognized$. Since none of those is suitable, we must return -1. It cannot be done using the current distribution constraint. Function Description Complete the pylons function in the editor below. pylons has the following parameter(s): int k: the distribution range int arr[n]: each city's suitability as a building site Returns int: the minimum number of plants required or -1 Input Format The first line contains two space-separated integers $unrecognized$ and $unrecognized$, the number of cities in Goodland and the plants' range constant. The second line contains $unrecognized$ space-separated binary integers where each integer indicates suitability for building a plant. Constraints $unrecognized$ Each $unrecognized$. Subtask $unrecognized$ for $unrecognized$ of the maximum score. Output Format Print a single integer denoting the minimum number of plants that must be built so that all of Goodland's cities have electricity. If this is not possible for the given value of $unrecognized$, print $unrecognized$. Sample Input STDIN Function ----- -------- 6 2 arr[] size n = 6, k = 2 0 1 1 1 1 0 arr = [0, 1, 1, 1, 1, 0] Sample Output 2 Explanation Cities $unrecognized$, $unrecognized$, $unrecognized$, and $unrecognized$ are suitable for power plants. Each plant will have a range of $unrecognized$. If we build in cities $unrecognized$ cities, $unrecognized$ and $unrecognized$, then all cities will have electricity.
N, K = input().split() N, K = int(N), int(K) arr = [int(i) for i in input().split()] res = 0 i = 0 while i + K <= N: if i == 0: rng = i + K elif i + 2 * K <= N: rng = i + 2 * K - 1 else: rng = N flag = False for t in reversed(range(i, rng)): if arr[t] == 1: i = t + 1 res += 1 flag = True break if not flag: res = -1 break print(res)
ASSIGN VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE BIN_OP VAR VAR VAR IF VAR NUMBER ASSIGN VAR BIN_OP VAR VAR IF BIN_OP VAR BIN_OP NUMBER VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR BIN_OP NUMBER VAR NUMBER ASSIGN VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR IF VAR VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER IF VAR ASSIGN VAR NUMBER EXPR FUNC_CALL VAR VAR
Goodland is a country with a number of evenly spaced cities along a line. The distance between adjacent cities is $unrecognized$ unit. There is an energy infrastructure project planning meeting, and the government needs to know the fewest number of power plants needed to provide electricity to the entire list of cities. Determine that number. If it cannot be done, return -1. You are given a list of city data. Cities that may contain a power plant have been labeled $unrecognized$. Others not suitable for building a plant are labeled $unrecognized$. Given a distribution range of $unrecognized$, find the lowest number of plants that must be built such that all cities are served. The distribution range limits supply to cities where distance is less than k. Example $unrecognized$ $unrecognized$ Each city is $unrecognized$ unit distance from its neighbors, and we'll use $unrecognized$ based indexing. We see there are $unrecognized$ cities suitable for power plants, cities $unrecognized$ and $unrecognized$. If we build a power plant at $unrecognized$, it can serve $unrecognized$ through $unrecognized$ because those endpoints are at a distance of $unrecognized$ and $unrecognized$. To serve $unrecognized$, we would need to be able to build a plant in city $unrecognized$ or $unrecognized$. Since none of those is suitable, we must return -1. It cannot be done using the current distribution constraint. Function Description Complete the pylons function in the editor below. pylons has the following parameter(s): int k: the distribution range int arr[n]: each city's suitability as a building site Returns int: the minimum number of plants required or -1 Input Format The first line contains two space-separated integers $unrecognized$ and $unrecognized$, the number of cities in Goodland and the plants' range constant. The second line contains $unrecognized$ space-separated binary integers where each integer indicates suitability for building a plant. Constraints $unrecognized$ Each $unrecognized$. Subtask $unrecognized$ for $unrecognized$ of the maximum score. Output Format Print a single integer denoting the minimum number of plants that must be built so that all of Goodland's cities have electricity. If this is not possible for the given value of $unrecognized$, print $unrecognized$. Sample Input STDIN Function ----- -------- 6 2 arr[] size n = 6, k = 2 0 1 1 1 1 0 arr = [0, 1, 1, 1, 1, 0] Sample Output 2 Explanation Cities $unrecognized$, $unrecognized$, $unrecognized$, and $unrecognized$ are suitable for power plants. Each plant will have a range of $unrecognized$. If we build in cities $unrecognized$ cities, $unrecognized$ and $unrecognized$, then all cities will have electricity.
def solve(cities, spread): used = 0 ind = 0 while ind < len(cities): found = False placeIndex = 0 for rightSearch in range(spread - 1, 0, -1): if rightSearch + ind >= len(cities): continue if cities[rightSearch + ind] == 1: found = True placeIndex = rightSearch + ind break if found: used += 1 ind = placeIndex + spread continue for leftSearch in range(spread): if ind - leftSearch < 0: return -1 if cities[ind - leftSearch] == 1: found = True placeIndex = ind - leftSearch break if found: used += 1 ind = placeIndex + spread continue return -1 return used firstLine = input() lineTrimmed = firstLine.strip().split() count = int(lineTrimmed[0]) spread = int(lineTrimmed[1]) secondLine = input().strip() lineSplit = secondLine.split() cities = [] for elem in lineSplit: cities.append(int(elem)) solution = solve(cities, spread) print(solution)
FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER NUMBER IF BIN_OP VAR VAR FUNC_CALL VAR VAR IF VAR BIN_OP VAR VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR BIN_OP VAR VAR IF VAR VAR NUMBER ASSIGN VAR BIN_OP VAR VAR FOR VAR FUNC_CALL VAR VAR IF BIN_OP VAR VAR NUMBER RETURN NUMBER IF VAR BIN_OP VAR VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR BIN_OP VAR VAR IF VAR VAR NUMBER ASSIGN VAR BIN_OP VAR VAR RETURN NUMBER RETURN VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR LIST FOR VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR
Goodland is a country with a number of evenly spaced cities along a line. The distance between adjacent cities is $unrecognized$ unit. There is an energy infrastructure project planning meeting, and the government needs to know the fewest number of power plants needed to provide electricity to the entire list of cities. Determine that number. If it cannot be done, return -1. You are given a list of city data. Cities that may contain a power plant have been labeled $unrecognized$. Others not suitable for building a plant are labeled $unrecognized$. Given a distribution range of $unrecognized$, find the lowest number of plants that must be built such that all cities are served. The distribution range limits supply to cities where distance is less than k. Example $unrecognized$ $unrecognized$ Each city is $unrecognized$ unit distance from its neighbors, and we'll use $unrecognized$ based indexing. We see there are $unrecognized$ cities suitable for power plants, cities $unrecognized$ and $unrecognized$. If we build a power plant at $unrecognized$, it can serve $unrecognized$ through $unrecognized$ because those endpoints are at a distance of $unrecognized$ and $unrecognized$. To serve $unrecognized$, we would need to be able to build a plant in city $unrecognized$ or $unrecognized$. Since none of those is suitable, we must return -1. It cannot be done using the current distribution constraint. Function Description Complete the pylons function in the editor below. pylons has the following parameter(s): int k: the distribution range int arr[n]: each city's suitability as a building site Returns int: the minimum number of plants required or -1 Input Format The first line contains two space-separated integers $unrecognized$ and $unrecognized$, the number of cities in Goodland and the plants' range constant. The second line contains $unrecognized$ space-separated binary integers where each integer indicates suitability for building a plant. Constraints $unrecognized$ Each $unrecognized$. Subtask $unrecognized$ for $unrecognized$ of the maximum score. Output Format Print a single integer denoting the minimum number of plants that must be built so that all of Goodland's cities have electricity. If this is not possible for the given value of $unrecognized$, print $unrecognized$. Sample Input STDIN Function ----- -------- 6 2 arr[] size n = 6, k = 2 0 1 1 1 1 0 arr = [0, 1, 1, 1, 1, 0] Sample Output 2 Explanation Cities $unrecognized$, $unrecognized$, $unrecognized$, and $unrecognized$ are suitable for power plants. Each plant will have a range of $unrecognized$. If we build in cities $unrecognized$ cities, $unrecognized$ and $unrecognized$, then all cities will have electricity.
n, k = [int(tmp) for tmp in input().strip().split(" ")] towers = [int(tmp) for tmp in input().strip().split(" ")] num_towers_on = 0 i = 0 towers_turned_on = 0 while i <= n - 1: min_tower = max(0, i + 1 - k) max_tower = min(n, i + k) tower_to_turn_on = -1 for j in range(min_tower, max_tower): if towers[j] == 1: tower_to_turn_on = j if tower_to_turn_on == -1: towers_turned_on = -1 break else: towers_turned_on += 1 i = tower_to_turn_on + k print(towers_turned_on)
ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR NUMBER BIN_OP BIN_OP VAR NUMBER VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR VAR IF VAR VAR NUMBER ASSIGN VAR VAR IF VAR NUMBER ASSIGN VAR NUMBER VAR NUMBER ASSIGN VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR VAR
Goodland is a country with a number of evenly spaced cities along a line. The distance between adjacent cities is $unrecognized$ unit. There is an energy infrastructure project planning meeting, and the government needs to know the fewest number of power plants needed to provide electricity to the entire list of cities. Determine that number. If it cannot be done, return -1. You are given a list of city data. Cities that may contain a power plant have been labeled $unrecognized$. Others not suitable for building a plant are labeled $unrecognized$. Given a distribution range of $unrecognized$, find the lowest number of plants that must be built such that all cities are served. The distribution range limits supply to cities where distance is less than k. Example $unrecognized$ $unrecognized$ Each city is $unrecognized$ unit distance from its neighbors, and we'll use $unrecognized$ based indexing. We see there are $unrecognized$ cities suitable for power plants, cities $unrecognized$ and $unrecognized$. If we build a power plant at $unrecognized$, it can serve $unrecognized$ through $unrecognized$ because those endpoints are at a distance of $unrecognized$ and $unrecognized$. To serve $unrecognized$, we would need to be able to build a plant in city $unrecognized$ or $unrecognized$. Since none of those is suitable, we must return -1. It cannot be done using the current distribution constraint. Function Description Complete the pylons function in the editor below. pylons has the following parameter(s): int k: the distribution range int arr[n]: each city's suitability as a building site Returns int: the minimum number of plants required or -1 Input Format The first line contains two space-separated integers $unrecognized$ and $unrecognized$, the number of cities in Goodland and the plants' range constant. The second line contains $unrecognized$ space-separated binary integers where each integer indicates suitability for building a plant. Constraints $unrecognized$ Each $unrecognized$. Subtask $unrecognized$ for $unrecognized$ of the maximum score. Output Format Print a single integer denoting the minimum number of plants that must be built so that all of Goodland's cities have electricity. If this is not possible for the given value of $unrecognized$, print $unrecognized$. Sample Input STDIN Function ----- -------- 6 2 arr[] size n = 6, k = 2 0 1 1 1 1 0 arr = [0, 1, 1, 1, 1, 0] Sample Output 2 Explanation Cities $unrecognized$, $unrecognized$, $unrecognized$, and $unrecognized$ are suitable for power plants. Each plant will have a range of $unrecognized$. If we build in cities $unrecognized$ cities, $unrecognized$ and $unrecognized$, then all cities will have electricity.
n, k = map(int, input().split()) tower = list(map(int, input().split())) def voisins(i): return range(min(n - 1, i + k - 1), max(-1, i - k), -1) count = 0 past_fourni = 0 while past_fourni < n: for i in voisins(past_fourni): if tower[i]: past_fourni = i + k count += 1 break else: count = -1 break print(count)
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FUNC_DEF RETURN FUNC_CALL VAR FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP BIN_OP VAR VAR NUMBER FUNC_CALL VAR NUMBER BIN_OP VAR VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR VAR FOR VAR FUNC_CALL VAR VAR IF VAR VAR ASSIGN VAR BIN_OP VAR VAR VAR NUMBER ASSIGN VAR NUMBER EXPR FUNC_CALL VAR VAR
Goodland is a country with a number of evenly spaced cities along a line. The distance between adjacent cities is $unrecognized$ unit. There is an energy infrastructure project planning meeting, and the government needs to know the fewest number of power plants needed to provide electricity to the entire list of cities. Determine that number. If it cannot be done, return -1. You are given a list of city data. Cities that may contain a power plant have been labeled $unrecognized$. Others not suitable for building a plant are labeled $unrecognized$. Given a distribution range of $unrecognized$, find the lowest number of plants that must be built such that all cities are served. The distribution range limits supply to cities where distance is less than k. Example $unrecognized$ $unrecognized$ Each city is $unrecognized$ unit distance from its neighbors, and we'll use $unrecognized$ based indexing. We see there are $unrecognized$ cities suitable for power plants, cities $unrecognized$ and $unrecognized$. If we build a power plant at $unrecognized$, it can serve $unrecognized$ through $unrecognized$ because those endpoints are at a distance of $unrecognized$ and $unrecognized$. To serve $unrecognized$, we would need to be able to build a plant in city $unrecognized$ or $unrecognized$. Since none of those is suitable, we must return -1. It cannot be done using the current distribution constraint. Function Description Complete the pylons function in the editor below. pylons has the following parameter(s): int k: the distribution range int arr[n]: each city's suitability as a building site Returns int: the minimum number of plants required or -1 Input Format The first line contains two space-separated integers $unrecognized$ and $unrecognized$, the number of cities in Goodland and the plants' range constant. The second line contains $unrecognized$ space-separated binary integers where each integer indicates suitability for building a plant. Constraints $unrecognized$ Each $unrecognized$. Subtask $unrecognized$ for $unrecognized$ of the maximum score. Output Format Print a single integer denoting the minimum number of plants that must be built so that all of Goodland's cities have electricity. If this is not possible for the given value of $unrecognized$, print $unrecognized$. Sample Input STDIN Function ----- -------- 6 2 arr[] size n = 6, k = 2 0 1 1 1 1 0 arr = [0, 1, 1, 1, 1, 0] Sample Output 2 Explanation Cities $unrecognized$, $unrecognized$, $unrecognized$, and $unrecognized$ are suitable for power plants. Each plant will have a range of $unrecognized$. If we build in cities $unrecognized$ cities, $unrecognized$ and $unrecognized$, then all cities will have electricity.
def test_case(cities, k): res1 = calc_n_towers(cities, k) res2 = calc_n_towers(list(reversed(cities)), k) if res1 == -1 and res2 == -1: return -1 elif res1 == -1: return res2 elif res2 == -1: return res1 return min(res1, res2) def calc_n_towers(arr, k): lo = 0 hi = k - 1 min_res = len(arr) // (2 * k - 1) if len(arr) % (2 * k - 1) != 0: min_res += 1 res = 0 last_pos = -1 while hi >= lo: if last_pos == hi: break if arr[hi] == 1: last_pos = hi res += 1 lo = hi hi = lo + (2 * k - 1) if hi >= len(arr): if last_pos < len(arr) - k: hi = len(arr) - 1 else: break else: hi -= 1 if last_pos < len(arr) - k: return -1 return res if res >= min_res else -1 n, k = list(map(int, input().split())) cities = list(map(int, input().split())) print(test_case(cities, k))
FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR IF VAR NUMBER VAR NUMBER RETURN NUMBER IF VAR NUMBER RETURN VAR IF VAR NUMBER RETURN VAR RETURN FUNC_CALL VAR VAR VAR FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR VAR BIN_OP BIN_OP NUMBER VAR NUMBER IF BIN_OP FUNC_CALL VAR VAR BIN_OP BIN_OP NUMBER VAR NUMBER NUMBER VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR VAR IF VAR VAR IF VAR VAR NUMBER ASSIGN VAR VAR VAR NUMBER ASSIGN VAR VAR ASSIGN VAR BIN_OP VAR BIN_OP BIN_OP NUMBER VAR NUMBER IF VAR FUNC_CALL VAR VAR IF VAR BIN_OP FUNC_CALL VAR VAR VAR ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER VAR NUMBER IF VAR BIN_OP FUNC_CALL VAR VAR VAR RETURN NUMBER RETURN VAR VAR VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR
Goodland is a country with a number of evenly spaced cities along a line. The distance between adjacent cities is $unrecognized$ unit. There is an energy infrastructure project planning meeting, and the government needs to know the fewest number of power plants needed to provide electricity to the entire list of cities. Determine that number. If it cannot be done, return -1. You are given a list of city data. Cities that may contain a power plant have been labeled $unrecognized$. Others not suitable for building a plant are labeled $unrecognized$. Given a distribution range of $unrecognized$, find the lowest number of plants that must be built such that all cities are served. The distribution range limits supply to cities where distance is less than k. Example $unrecognized$ $unrecognized$ Each city is $unrecognized$ unit distance from its neighbors, and we'll use $unrecognized$ based indexing. We see there are $unrecognized$ cities suitable for power plants, cities $unrecognized$ and $unrecognized$. If we build a power plant at $unrecognized$, it can serve $unrecognized$ through $unrecognized$ because those endpoints are at a distance of $unrecognized$ and $unrecognized$. To serve $unrecognized$, we would need to be able to build a plant in city $unrecognized$ or $unrecognized$. Since none of those is suitable, we must return -1. It cannot be done using the current distribution constraint. Function Description Complete the pylons function in the editor below. pylons has the following parameter(s): int k: the distribution range int arr[n]: each city's suitability as a building site Returns int: the minimum number of plants required or -1 Input Format The first line contains two space-separated integers $unrecognized$ and $unrecognized$, the number of cities in Goodland and the plants' range constant. The second line contains $unrecognized$ space-separated binary integers where each integer indicates suitability for building a plant. Constraints $unrecognized$ Each $unrecognized$. Subtask $unrecognized$ for $unrecognized$ of the maximum score. Output Format Print a single integer denoting the minimum number of plants that must be built so that all of Goodland's cities have electricity. If this is not possible for the given value of $unrecognized$, print $unrecognized$. Sample Input STDIN Function ----- -------- 6 2 arr[] size n = 6, k = 2 0 1 1 1 1 0 arr = [0, 1, 1, 1, 1, 0] Sample Output 2 Explanation Cities $unrecognized$, $unrecognized$, $unrecognized$, and $unrecognized$ are suitable for power plants. Each plant will have a range of $unrecognized$. If we build in cities $unrecognized$ cities, $unrecognized$ and $unrecognized$, then all cities will have electricity.
n, k = map(int, input().strip().split()) arr = list(map(int, input().strip().split())) step, i, piv = 0, 0, 0 while i < n: j = min(i + k - 1, n - 1) step += 1 while j >= piv and arr[j] != 1: j -= 1 if j < piv: print("-1") quit() i = j + k piv = j + 1 print(step)
ASSIGN VAR 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 VAR VAR NUMBER NUMBER NUMBER WHILE VAR VAR ASSIGN VAR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR NUMBER BIN_OP VAR NUMBER VAR NUMBER WHILE VAR VAR VAR VAR NUMBER VAR NUMBER IF VAR VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR
Goodland is a country with a number of evenly spaced cities along a line. The distance between adjacent cities is $unrecognized$ unit. There is an energy infrastructure project planning meeting, and the government needs to know the fewest number of power plants needed to provide electricity to the entire list of cities. Determine that number. If it cannot be done, return -1. You are given a list of city data. Cities that may contain a power plant have been labeled $unrecognized$. Others not suitable for building a plant are labeled $unrecognized$. Given a distribution range of $unrecognized$, find the lowest number of plants that must be built such that all cities are served. The distribution range limits supply to cities where distance is less than k. Example $unrecognized$ $unrecognized$ Each city is $unrecognized$ unit distance from its neighbors, and we'll use $unrecognized$ based indexing. We see there are $unrecognized$ cities suitable for power plants, cities $unrecognized$ and $unrecognized$. If we build a power plant at $unrecognized$, it can serve $unrecognized$ through $unrecognized$ because those endpoints are at a distance of $unrecognized$ and $unrecognized$. To serve $unrecognized$, we would need to be able to build a plant in city $unrecognized$ or $unrecognized$. Since none of those is suitable, we must return -1. It cannot be done using the current distribution constraint. Function Description Complete the pylons function in the editor below. pylons has the following parameter(s): int k: the distribution range int arr[n]: each city's suitability as a building site Returns int: the minimum number of plants required or -1 Input Format The first line contains two space-separated integers $unrecognized$ and $unrecognized$, the number of cities in Goodland and the plants' range constant. The second line contains $unrecognized$ space-separated binary integers where each integer indicates suitability for building a plant. Constraints $unrecognized$ Each $unrecognized$. Subtask $unrecognized$ for $unrecognized$ of the maximum score. Output Format Print a single integer denoting the minimum number of plants that must be built so that all of Goodland's cities have electricity. If this is not possible for the given value of $unrecognized$, print $unrecognized$. Sample Input STDIN Function ----- -------- 6 2 arr[] size n = 6, k = 2 0 1 1 1 1 0 arr = [0, 1, 1, 1, 1, 0] Sample Output 2 Explanation Cities $unrecognized$, $unrecognized$, $unrecognized$, and $unrecognized$ are suitable for power plants. Each plant will have a range of $unrecognized$. If we build in cities $unrecognized$ cities, $unrecognized$ and $unrecognized$, then all cities will have electricity.
n, k = map(int, input().split()) towerlist = [int(i) for i in input().split()] p = 0 tc = 0 while p < n: found = tc if p + k - 1 < n: h = p + k - 1 while h > p - k: if towerlist[h] == 1: tc += 1 p = h + k break h -= 1 else: for i in range(k - 1): if towerlist[n - i - 1] == 1: tc += 1 p = n break if found == tc: tc = -1 p = n break print(tc)
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR VAR ASSIGN VAR VAR IF BIN_OP BIN_OP VAR VAR NUMBER VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER WHILE VAR BIN_OP VAR VAR IF VAR VAR NUMBER VAR NUMBER ASSIGN VAR BIN_OP VAR VAR VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER IF VAR BIN_OP BIN_OP VAR VAR NUMBER NUMBER VAR NUMBER ASSIGN VAR VAR IF VAR VAR ASSIGN VAR NUMBER ASSIGN VAR VAR EXPR FUNC_CALL VAR VAR
Goodland is a country with a number of evenly spaced cities along a line. The distance between adjacent cities is $unrecognized$ unit. There is an energy infrastructure project planning meeting, and the government needs to know the fewest number of power plants needed to provide electricity to the entire list of cities. Determine that number. If it cannot be done, return -1. You are given a list of city data. Cities that may contain a power plant have been labeled $unrecognized$. Others not suitable for building a plant are labeled $unrecognized$. Given a distribution range of $unrecognized$, find the lowest number of plants that must be built such that all cities are served. The distribution range limits supply to cities where distance is less than k. Example $unrecognized$ $unrecognized$ Each city is $unrecognized$ unit distance from its neighbors, and we'll use $unrecognized$ based indexing. We see there are $unrecognized$ cities suitable for power plants, cities $unrecognized$ and $unrecognized$. If we build a power plant at $unrecognized$, it can serve $unrecognized$ through $unrecognized$ because those endpoints are at a distance of $unrecognized$ and $unrecognized$. To serve $unrecognized$, we would need to be able to build a plant in city $unrecognized$ or $unrecognized$. Since none of those is suitable, we must return -1. It cannot be done using the current distribution constraint. Function Description Complete the pylons function in the editor below. pylons has the following parameter(s): int k: the distribution range int arr[n]: each city's suitability as a building site Returns int: the minimum number of plants required or -1 Input Format The first line contains two space-separated integers $unrecognized$ and $unrecognized$, the number of cities in Goodland and the plants' range constant. The second line contains $unrecognized$ space-separated binary integers where each integer indicates suitability for building a plant. Constraints $unrecognized$ Each $unrecognized$. Subtask $unrecognized$ for $unrecognized$ of the maximum score. Output Format Print a single integer denoting the minimum number of plants that must be built so that all of Goodland's cities have electricity. If this is not possible for the given value of $unrecognized$, print $unrecognized$. Sample Input STDIN Function ----- -------- 6 2 arr[] size n = 6, k = 2 0 1 1 1 1 0 arr = [0, 1, 1, 1, 1, 0] Sample Output 2 Explanation Cities $unrecognized$, $unrecognized$, $unrecognized$, and $unrecognized$ are suitable for power plants. Each plant will have a range of $unrecognized$. If we build in cities $unrecognized$ cities, $unrecognized$ and $unrecognized$, then all cities will have electricity.
_, k = list(map(int, input().strip().split(" "))) cities = list(map(int, input().strip().split(" "))) def num_stations_needed(k, cities): i = 0 num_stations = 0 rightmost_candidate = -k while i < len(cities): leftmost_unpowered = i while i < len(cities) and i < leftmost_unpowered + k: if cities[i] == 1: rightmost_candidate = i i += 1 if rightmost_candidate + k <= leftmost_unpowered: return -1 elif rightmost_candidate + k < i: i = rightmost_candidate + k else: new_rightmost = rightmost_candidate while i < len(cities) and i < rightmost_candidate + k: if cities[i] == 1: new_rightmost = i i += 1 rightmost_candidate = new_rightmost num_stations += 1 return num_stations print(num_stations_needed(k, cities))
ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR STRING FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR VAR WHILE VAR FUNC_CALL VAR VAR ASSIGN VAR VAR WHILE VAR FUNC_CALL VAR VAR VAR BIN_OP VAR VAR IF VAR VAR NUMBER ASSIGN VAR VAR VAR NUMBER IF BIN_OP VAR VAR VAR RETURN NUMBER IF BIN_OP VAR VAR VAR ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR VAR WHILE VAR FUNC_CALL VAR VAR VAR BIN_OP VAR VAR IF VAR VAR NUMBER ASSIGN VAR VAR VAR NUMBER ASSIGN VAR VAR VAR NUMBER RETURN VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR
Goodland is a country with a number of evenly spaced cities along a line. The distance between adjacent cities is $unrecognized$ unit. There is an energy infrastructure project planning meeting, and the government needs to know the fewest number of power plants needed to provide electricity to the entire list of cities. Determine that number. If it cannot be done, return -1. You are given a list of city data. Cities that may contain a power plant have been labeled $unrecognized$. Others not suitable for building a plant are labeled $unrecognized$. Given a distribution range of $unrecognized$, find the lowest number of plants that must be built such that all cities are served. The distribution range limits supply to cities where distance is less than k. Example $unrecognized$ $unrecognized$ Each city is $unrecognized$ unit distance from its neighbors, and we'll use $unrecognized$ based indexing. We see there are $unrecognized$ cities suitable for power plants, cities $unrecognized$ and $unrecognized$. If we build a power plant at $unrecognized$, it can serve $unrecognized$ through $unrecognized$ because those endpoints are at a distance of $unrecognized$ and $unrecognized$. To serve $unrecognized$, we would need to be able to build a plant in city $unrecognized$ or $unrecognized$. Since none of those is suitable, we must return -1. It cannot be done using the current distribution constraint. Function Description Complete the pylons function in the editor below. pylons has the following parameter(s): int k: the distribution range int arr[n]: each city's suitability as a building site Returns int: the minimum number of plants required or -1 Input Format The first line contains two space-separated integers $unrecognized$ and $unrecognized$, the number of cities in Goodland and the plants' range constant. The second line contains $unrecognized$ space-separated binary integers where each integer indicates suitability for building a plant. Constraints $unrecognized$ Each $unrecognized$. Subtask $unrecognized$ for $unrecognized$ of the maximum score. Output Format Print a single integer denoting the minimum number of plants that must be built so that all of Goodland's cities have electricity. If this is not possible for the given value of $unrecognized$, print $unrecognized$. Sample Input STDIN Function ----- -------- 6 2 arr[] size n = 6, k = 2 0 1 1 1 1 0 arr = [0, 1, 1, 1, 1, 0] Sample Output 2 Explanation Cities $unrecognized$, $unrecognized$, $unrecognized$, and $unrecognized$ are suitable for power plants. Each plant will have a range of $unrecognized$. If we build in cities $unrecognized$ cities, $unrecognized$ and $unrecognized$, then all cities will have electricity.
import sys _, rng = map(int, input().strip().split()) towers = [bool(int(x)) for x in input().strip().split()] tower_indices = [i for i, tower in enumerate(towers) if tower] tower_indices_rev = [] def reach(location, target): return abs(location - target) < rng first_unpowered = 0 last_tower = -1 i = 0 tower_count = 0 placed_towers = [False] * len(towers) while i < len(tower_indices): current = tower_indices[i] i += 1 if reach(current, first_unpowered): last_tower = current continue if last_tower == -1: print(-1) sys.exit(0) else: placed_towers[last_tower] = True first_unpowered = last_tower + rng last_tower = -1 tower_count += 1 i -= 1 last_built_location = len(towers) - 1 while last_built_location >= -1: if placed_towers[last_built_location]: break last_built_location -= 1 if last_built_location == -1: print(-1) elif reach(last_built_location, len(towers) - 1): print(tower_count) else: last_tower_location = tower_indices[-1] if reach(tower_indices[-1], len(towers) - 1): placed_towers[tower_indices[-1]] = True print(tower_count + 1) else: print(-1)
IMPORT ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR VAR VAR FUNC_CALL VAR VAR VAR ASSIGN VAR LIST FUNC_DEF RETURN FUNC_CALL VAR BIN_OP VAR VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER FUNC_CALL VAR VAR WHILE VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR VAR NUMBER IF FUNC_CALL VAR VAR VAR ASSIGN VAR VAR IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR NUMBER VAR NUMBER VAR NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER WHILE VAR NUMBER IF VAR VAR VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER IF FUNC_CALL VAR VAR BIN_OP FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR VAR ASSIGN VAR VAR NUMBER IF FUNC_CALL VAR VAR NUMBER BIN_OP FUNC_CALL VAR VAR NUMBER ASSIGN VAR VAR NUMBER NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR NUMBER
Goodland is a country with a number of evenly spaced cities along a line. The distance between adjacent cities is $unrecognized$ unit. There is an energy infrastructure project planning meeting, and the government needs to know the fewest number of power plants needed to provide electricity to the entire list of cities. Determine that number. If it cannot be done, return -1. You are given a list of city data. Cities that may contain a power plant have been labeled $unrecognized$. Others not suitable for building a plant are labeled $unrecognized$. Given a distribution range of $unrecognized$, find the lowest number of plants that must be built such that all cities are served. The distribution range limits supply to cities where distance is less than k. Example $unrecognized$ $unrecognized$ Each city is $unrecognized$ unit distance from its neighbors, and we'll use $unrecognized$ based indexing. We see there are $unrecognized$ cities suitable for power plants, cities $unrecognized$ and $unrecognized$. If we build a power plant at $unrecognized$, it can serve $unrecognized$ through $unrecognized$ because those endpoints are at a distance of $unrecognized$ and $unrecognized$. To serve $unrecognized$, we would need to be able to build a plant in city $unrecognized$ or $unrecognized$. Since none of those is suitable, we must return -1. It cannot be done using the current distribution constraint. Function Description Complete the pylons function in the editor below. pylons has the following parameter(s): int k: the distribution range int arr[n]: each city's suitability as a building site Returns int: the minimum number of plants required or -1 Input Format The first line contains two space-separated integers $unrecognized$ and $unrecognized$, the number of cities in Goodland and the plants' range constant. The second line contains $unrecognized$ space-separated binary integers where each integer indicates suitability for building a plant. Constraints $unrecognized$ Each $unrecognized$. Subtask $unrecognized$ for $unrecognized$ of the maximum score. Output Format Print a single integer denoting the minimum number of plants that must be built so that all of Goodland's cities have electricity. If this is not possible for the given value of $unrecognized$, print $unrecognized$. Sample Input STDIN Function ----- -------- 6 2 arr[] size n = 6, k = 2 0 1 1 1 1 0 arr = [0, 1, 1, 1, 1, 0] Sample Output 2 Explanation Cities $unrecognized$, $unrecognized$, $unrecognized$, and $unrecognized$ are suitable for power plants. Each plant will have a range of $unrecognized$. If we build in cities $unrecognized$ cities, $unrecognized$ and $unrecognized$, then all cities will have electricity.
n, k = [int(x) for x in input().strip().split()] t = [int(x) for x in input().strip().split()] towercount = 0 citieslit = 0 while citieslit < n: canlight = False b = list(range(max(citieslit - k + 1, 0), min(citieslit + k, n))) b.sort(reverse=True) for i in b: if t[i] == 1: canlight = True citieslit = i + k towercount += 1 break if not canlight: towercount = -1 break print(towercount)
ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR VAR ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR NUMBER NUMBER FUNC_CALL VAR BIN_OP VAR VAR VAR EXPR FUNC_CALL VAR NUMBER FOR VAR VAR IF VAR VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR BIN_OP VAR VAR VAR NUMBER IF VAR ASSIGN VAR NUMBER EXPR FUNC_CALL VAR VAR
Goodland is a country with a number of evenly spaced cities along a line. The distance between adjacent cities is $unrecognized$ unit. There is an energy infrastructure project planning meeting, and the government needs to know the fewest number of power plants needed to provide electricity to the entire list of cities. Determine that number. If it cannot be done, return -1. You are given a list of city data. Cities that may contain a power plant have been labeled $unrecognized$. Others not suitable for building a plant are labeled $unrecognized$. Given a distribution range of $unrecognized$, find the lowest number of plants that must be built such that all cities are served. The distribution range limits supply to cities where distance is less than k. Example $unrecognized$ $unrecognized$ Each city is $unrecognized$ unit distance from its neighbors, and we'll use $unrecognized$ based indexing. We see there are $unrecognized$ cities suitable for power plants, cities $unrecognized$ and $unrecognized$. If we build a power plant at $unrecognized$, it can serve $unrecognized$ through $unrecognized$ because those endpoints are at a distance of $unrecognized$ and $unrecognized$. To serve $unrecognized$, we would need to be able to build a plant in city $unrecognized$ or $unrecognized$. Since none of those is suitable, we must return -1. It cannot be done using the current distribution constraint. Function Description Complete the pylons function in the editor below. pylons has the following parameter(s): int k: the distribution range int arr[n]: each city's suitability as a building site Returns int: the minimum number of plants required or -1 Input Format The first line contains two space-separated integers $unrecognized$ and $unrecognized$, the number of cities in Goodland and the plants' range constant. The second line contains $unrecognized$ space-separated binary integers where each integer indicates suitability for building a plant. Constraints $unrecognized$ Each $unrecognized$. Subtask $unrecognized$ for $unrecognized$ of the maximum score. Output Format Print a single integer denoting the minimum number of plants that must be built so that all of Goodland's cities have electricity. If this is not possible for the given value of $unrecognized$, print $unrecognized$. Sample Input STDIN Function ----- -------- 6 2 arr[] size n = 6, k = 2 0 1 1 1 1 0 arr = [0, 1, 1, 1, 1, 0] Sample Output 2 Explanation Cities $unrecognized$, $unrecognized$, $unrecognized$, and $unrecognized$ are suitable for power plants. Each plant will have a range of $unrecognized$. If we build in cities $unrecognized$ cities, $unrecognized$ and $unrecognized$, then all cities will have electricity.
city, power_range = input().split() city, power_range = int(city), int(power_range) tower = [int(x) for x in input().split()] def algorithm(lis): pointer = power_range - 1 tower_num = 0 start = -1 while pointer < city: if lis[pointer] == 1: tower_num += 1 start = pointer if ( pointer + 2 * (power_range - 1) + 1 >= city and pointer + power_range - 1 < city - 1 ): pointer = city - 1 while pointer > start: if lis[pointer] != 1: pointer -= 1 else: return tower_num + 1 if pointer == start and lis[pointer + 1] == 0: return -1 pointer += 2 * (power_range - 1) + 1 else: while pointer > start: if lis[pointer] != 1: pointer -= 1 else: break if pointer == start and lis[pointer + 1] == 0: return -1 return tower_num print(algorithm(tower))
ASSIGN VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR FUNC_DEF ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR VAR IF VAR VAR NUMBER VAR NUMBER ASSIGN VAR VAR IF BIN_OP BIN_OP VAR BIN_OP NUMBER BIN_OP VAR NUMBER NUMBER VAR BIN_OP BIN_OP VAR VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER WHILE VAR VAR IF VAR VAR NUMBER VAR NUMBER RETURN BIN_OP VAR NUMBER IF VAR VAR VAR BIN_OP VAR NUMBER NUMBER RETURN NUMBER VAR BIN_OP BIN_OP NUMBER BIN_OP VAR NUMBER NUMBER WHILE VAR VAR IF VAR VAR NUMBER VAR NUMBER IF VAR VAR VAR BIN_OP VAR NUMBER NUMBER RETURN NUMBER RETURN VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR
Goodland is a country with a number of evenly spaced cities along a line. The distance between adjacent cities is $unrecognized$ unit. There is an energy infrastructure project planning meeting, and the government needs to know the fewest number of power plants needed to provide electricity to the entire list of cities. Determine that number. If it cannot be done, return -1. You are given a list of city data. Cities that may contain a power plant have been labeled $unrecognized$. Others not suitable for building a plant are labeled $unrecognized$. Given a distribution range of $unrecognized$, find the lowest number of plants that must be built such that all cities are served. The distribution range limits supply to cities where distance is less than k. Example $unrecognized$ $unrecognized$ Each city is $unrecognized$ unit distance from its neighbors, and we'll use $unrecognized$ based indexing. We see there are $unrecognized$ cities suitable for power plants, cities $unrecognized$ and $unrecognized$. If we build a power plant at $unrecognized$, it can serve $unrecognized$ through $unrecognized$ because those endpoints are at a distance of $unrecognized$ and $unrecognized$. To serve $unrecognized$, we would need to be able to build a plant in city $unrecognized$ or $unrecognized$. Since none of those is suitable, we must return -1. It cannot be done using the current distribution constraint. Function Description Complete the pylons function in the editor below. pylons has the following parameter(s): int k: the distribution range int arr[n]: each city's suitability as a building site Returns int: the minimum number of plants required or -1 Input Format The first line contains two space-separated integers $unrecognized$ and $unrecognized$, the number of cities in Goodland and the plants' range constant. The second line contains $unrecognized$ space-separated binary integers where each integer indicates suitability for building a plant. Constraints $unrecognized$ Each $unrecognized$. Subtask $unrecognized$ for $unrecognized$ of the maximum score. Output Format Print a single integer denoting the minimum number of plants that must be built so that all of Goodland's cities have electricity. If this is not possible for the given value of $unrecognized$, print $unrecognized$. Sample Input STDIN Function ----- -------- 6 2 arr[] size n = 6, k = 2 0 1 1 1 1 0 arr = [0, 1, 1, 1, 1, 0] Sample Output 2 Explanation Cities $unrecognized$, $unrecognized$, $unrecognized$, and $unrecognized$ are suitable for power plants. Each plant will have a range of $unrecognized$. If we build in cities $unrecognized$ cities, $unrecognized$ and $unrecognized$, then all cities will have electricity.
n, k = input().strip().split(" ") n, k = int(n), int(k) towers = [int(x) for x in input().strip().split(" ")] firstOff = 0 def find_new_tower_optimal_index(index): maxInx = min(len(towers) - 1, index + k - 1) minInx = max(index - k + 1, 0) for inx in range(maxInx, minInx - 1, -1): if towers[inx] == 1: return inx return -1 count = 0 while firstOff < len(towers): indx = find_new_tower_optimal_index(firstOff) if indx == -1: count = -1 break count += 1 firstOff = indx + k print(count)
ASSIGN VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR NUMBER FUNC_DEF ASSIGN VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER NUMBER IF VAR VAR NUMBER RETURN VAR RETURN NUMBER ASSIGN VAR NUMBER WHILE VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR IF VAR NUMBER ASSIGN VAR NUMBER VAR NUMBER ASSIGN VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR VAR
Goodland is a country with a number of evenly spaced cities along a line. The distance between adjacent cities is $unrecognized$ unit. There is an energy infrastructure project planning meeting, and the government needs to know the fewest number of power plants needed to provide electricity to the entire list of cities. Determine that number. If it cannot be done, return -1. You are given a list of city data. Cities that may contain a power plant have been labeled $unrecognized$. Others not suitable for building a plant are labeled $unrecognized$. Given a distribution range of $unrecognized$, find the lowest number of plants that must be built such that all cities are served. The distribution range limits supply to cities where distance is less than k. Example $unrecognized$ $unrecognized$ Each city is $unrecognized$ unit distance from its neighbors, and we'll use $unrecognized$ based indexing. We see there are $unrecognized$ cities suitable for power plants, cities $unrecognized$ and $unrecognized$. If we build a power plant at $unrecognized$, it can serve $unrecognized$ through $unrecognized$ because those endpoints are at a distance of $unrecognized$ and $unrecognized$. To serve $unrecognized$, we would need to be able to build a plant in city $unrecognized$ or $unrecognized$. Since none of those is suitable, we must return -1. It cannot be done using the current distribution constraint. Function Description Complete the pylons function in the editor below. pylons has the following parameter(s): int k: the distribution range int arr[n]: each city's suitability as a building site Returns int: the minimum number of plants required or -1 Input Format The first line contains two space-separated integers $unrecognized$ and $unrecognized$, the number of cities in Goodland and the plants' range constant. The second line contains $unrecognized$ space-separated binary integers where each integer indicates suitability for building a plant. Constraints $unrecognized$ Each $unrecognized$. Subtask $unrecognized$ for $unrecognized$ of the maximum score. Output Format Print a single integer denoting the minimum number of plants that must be built so that all of Goodland's cities have electricity. If this is not possible for the given value of $unrecognized$, print $unrecognized$. Sample Input STDIN Function ----- -------- 6 2 arr[] size n = 6, k = 2 0 1 1 1 1 0 arr = [0, 1, 1, 1, 1, 0] Sample Output 2 Explanation Cities $unrecognized$, $unrecognized$, $unrecognized$, and $unrecognized$ are suitable for power plants. Each plant will have a range of $unrecognized$. If we build in cities $unrecognized$ cities, $unrecognized$ and $unrecognized$, then all cities will have electricity.
n, k = list(map(int, input().rstrip().split(" "))) l = list(map(int, input().rstrip().split(" "))) count = 0 curr = -1 limit = k for i in range(n): if i >= limit: if i != limit and curr == -1: print(-1) break else: count += 1 if curr + k > n: print(count) break limit = min(n - 1, curr + 2 * k) curr = -1 if l[i] == 1: curr = i else: print(count)
ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR VAR FOR VAR FUNC_CALL VAR VAR IF VAR VAR IF VAR VAR VAR NUMBER EXPR FUNC_CALL VAR NUMBER VAR NUMBER IF BIN_OP VAR VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP VAR BIN_OP NUMBER VAR ASSIGN VAR NUMBER IF VAR VAR NUMBER ASSIGN VAR VAR EXPR FUNC_CALL VAR VAR
Goodland is a country with a number of evenly spaced cities along a line. The distance between adjacent cities is $unrecognized$ unit. There is an energy infrastructure project planning meeting, and the government needs to know the fewest number of power plants needed to provide electricity to the entire list of cities. Determine that number. If it cannot be done, return -1. You are given a list of city data. Cities that may contain a power plant have been labeled $unrecognized$. Others not suitable for building a plant are labeled $unrecognized$. Given a distribution range of $unrecognized$, find the lowest number of plants that must be built such that all cities are served. The distribution range limits supply to cities where distance is less than k. Example $unrecognized$ $unrecognized$ Each city is $unrecognized$ unit distance from its neighbors, and we'll use $unrecognized$ based indexing. We see there are $unrecognized$ cities suitable for power plants, cities $unrecognized$ and $unrecognized$. If we build a power plant at $unrecognized$, it can serve $unrecognized$ through $unrecognized$ because those endpoints are at a distance of $unrecognized$ and $unrecognized$. To serve $unrecognized$, we would need to be able to build a plant in city $unrecognized$ or $unrecognized$. Since none of those is suitable, we must return -1. It cannot be done using the current distribution constraint. Function Description Complete the pylons function in the editor below. pylons has the following parameter(s): int k: the distribution range int arr[n]: each city's suitability as a building site Returns int: the minimum number of plants required or -1 Input Format The first line contains two space-separated integers $unrecognized$ and $unrecognized$, the number of cities in Goodland and the plants' range constant. The second line contains $unrecognized$ space-separated binary integers where each integer indicates suitability for building a plant. Constraints $unrecognized$ Each $unrecognized$. Subtask $unrecognized$ for $unrecognized$ of the maximum score. Output Format Print a single integer denoting the minimum number of plants that must be built so that all of Goodland's cities have electricity. If this is not possible for the given value of $unrecognized$, print $unrecognized$. Sample Input STDIN Function ----- -------- 6 2 arr[] size n = 6, k = 2 0 1 1 1 1 0 arr = [0, 1, 1, 1, 1, 0] Sample Output 2 Explanation Cities $unrecognized$, $unrecognized$, $unrecognized$, and $unrecognized$ are suitable for power plants. Each plant will have a range of $unrecognized$. If we build in cities $unrecognized$ cities, $unrecognized$ and $unrecognized$, then all cities will have electricity.
def min_number(towers, k): if k == 1: if all(towers) == 1: return len(towers) else: return -1 limit = len(towers) + k - 1 tower_number = 0 tower_not_found = True for i in range(k - 1, -1, -1): if towers[i] == 1: tower_not_found = False break if tower_not_found: return -1 while i < limit: if i < n and towers[i] == 1: tower_number += 1 i += 2 * k - 1 else: tower_not_found = True for j in range(1, 2 * k - 1): try: if towers[i - j] == 1: tower_not_found = False tower_number += 1 i += -j + 2 * k - 1 break except IndexError: continue if tower_not_found: return -1 return tower_number n, k = map(int, input().split()) towers = list(map(int, input().split())) print(min_number(towers, k))
FUNC_DEF IF VAR NUMBER IF FUNC_CALL VAR VAR NUMBER RETURN FUNC_CALL VAR VAR RETURN NUMBER ASSIGN VAR BIN_OP BIN_OP FUNC_CALL VAR VAR VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER NUMBER IF VAR VAR NUMBER ASSIGN VAR NUMBER IF VAR RETURN NUMBER WHILE VAR VAR IF VAR VAR VAR VAR NUMBER VAR NUMBER VAR BIN_OP BIN_OP NUMBER VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP BIN_OP NUMBER VAR NUMBER IF VAR BIN_OP VAR VAR NUMBER ASSIGN VAR NUMBER VAR NUMBER VAR BIN_OP BIN_OP VAR BIN_OP NUMBER VAR NUMBER VAR IF VAR RETURN NUMBER RETURN VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR
Goodland is a country with a number of evenly spaced cities along a line. The distance between adjacent cities is $unrecognized$ unit. There is an energy infrastructure project planning meeting, and the government needs to know the fewest number of power plants needed to provide electricity to the entire list of cities. Determine that number. If it cannot be done, return -1. You are given a list of city data. Cities that may contain a power plant have been labeled $unrecognized$. Others not suitable for building a plant are labeled $unrecognized$. Given a distribution range of $unrecognized$, find the lowest number of plants that must be built such that all cities are served. The distribution range limits supply to cities where distance is less than k. Example $unrecognized$ $unrecognized$ Each city is $unrecognized$ unit distance from its neighbors, and we'll use $unrecognized$ based indexing. We see there are $unrecognized$ cities suitable for power plants, cities $unrecognized$ and $unrecognized$. If we build a power plant at $unrecognized$, it can serve $unrecognized$ through $unrecognized$ because those endpoints are at a distance of $unrecognized$ and $unrecognized$. To serve $unrecognized$, we would need to be able to build a plant in city $unrecognized$ or $unrecognized$. Since none of those is suitable, we must return -1. It cannot be done using the current distribution constraint. Function Description Complete the pylons function in the editor below. pylons has the following parameter(s): int k: the distribution range int arr[n]: each city's suitability as a building site Returns int: the minimum number of plants required or -1 Input Format The first line contains two space-separated integers $unrecognized$ and $unrecognized$, the number of cities in Goodland and the plants' range constant. The second line contains $unrecognized$ space-separated binary integers where each integer indicates suitability for building a plant. Constraints $unrecognized$ Each $unrecognized$. Subtask $unrecognized$ for $unrecognized$ of the maximum score. Output Format Print a single integer denoting the minimum number of plants that must be built so that all of Goodland's cities have electricity. If this is not possible for the given value of $unrecognized$, print $unrecognized$. Sample Input STDIN Function ----- -------- 6 2 arr[] size n = 6, k = 2 0 1 1 1 1 0 arr = [0, 1, 1, 1, 1, 0] Sample Output 2 Explanation Cities $unrecognized$, $unrecognized$, $unrecognized$, and $unrecognized$ are suitable for power plants. Each plant will have a range of $unrecognized$. If we build in cities $unrecognized$ cities, $unrecognized$ and $unrecognized$, then all cities will have electricity.
import sys k = int(input().strip().split(" ")[1]) - 1 arr = [int(x) for x in input().strip().split(" ")] num = 0 done = 0 pos = k fail = 0 pos1 = -1 while not done: powered = 0 while not powered: if arr[pos]: num += 1 powered = 1 elif pos > pos1 + 1: pos -= 1 else: done = 1 fail = 1 powered = 1 pos1 = pos pos = pos + 2 * k + 1 if pos1 + k >= len(arr) - 1: done = 1 if pos > len(arr) - 1: pos = len(arr) - 1 if fail: print("-1") else: print(num)
IMPORT ASSIGN VAR BIN_OP FUNC_CALL VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR STRING NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR ASSIGN VAR NUMBER WHILE VAR IF VAR VAR VAR NUMBER ASSIGN VAR NUMBER IF VAR BIN_OP VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR BIN_OP NUMBER VAR NUMBER IF BIN_OP VAR VAR BIN_OP FUNC_CALL VAR VAR NUMBER ASSIGN VAR NUMBER IF VAR BIN_OP FUNC_CALL VAR VAR NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER IF VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR VAR
Goodland is a country with a number of evenly spaced cities along a line. The distance between adjacent cities is $unrecognized$ unit. There is an energy infrastructure project planning meeting, and the government needs to know the fewest number of power plants needed to provide electricity to the entire list of cities. Determine that number. If it cannot be done, return -1. You are given a list of city data. Cities that may contain a power plant have been labeled $unrecognized$. Others not suitable for building a plant are labeled $unrecognized$. Given a distribution range of $unrecognized$, find the lowest number of plants that must be built such that all cities are served. The distribution range limits supply to cities where distance is less than k. Example $unrecognized$ $unrecognized$ Each city is $unrecognized$ unit distance from its neighbors, and we'll use $unrecognized$ based indexing. We see there are $unrecognized$ cities suitable for power plants, cities $unrecognized$ and $unrecognized$. If we build a power plant at $unrecognized$, it can serve $unrecognized$ through $unrecognized$ because those endpoints are at a distance of $unrecognized$ and $unrecognized$. To serve $unrecognized$, we would need to be able to build a plant in city $unrecognized$ or $unrecognized$. Since none of those is suitable, we must return -1. It cannot be done using the current distribution constraint. Function Description Complete the pylons function in the editor below. pylons has the following parameter(s): int k: the distribution range int arr[n]: each city's suitability as a building site Returns int: the minimum number of plants required or -1 Input Format The first line contains two space-separated integers $unrecognized$ and $unrecognized$, the number of cities in Goodland and the plants' range constant. The second line contains $unrecognized$ space-separated binary integers where each integer indicates suitability for building a plant. Constraints $unrecognized$ Each $unrecognized$. Subtask $unrecognized$ for $unrecognized$ of the maximum score. Output Format Print a single integer denoting the minimum number of plants that must be built so that all of Goodland's cities have electricity. If this is not possible for the given value of $unrecognized$, print $unrecognized$. Sample Input STDIN Function ----- -------- 6 2 arr[] size n = 6, k = 2 0 1 1 1 1 0 arr = [0, 1, 1, 1, 1, 0] Sample Output 2 Explanation Cities $unrecognized$, $unrecognized$, $unrecognized$, and $unrecognized$ are suitable for power plants. Each plant will have a range of $unrecognized$. If we build in cities $unrecognized$ cities, $unrecognized$ and $unrecognized$, then all cities will have electricity.
n, k = [int(x) for x in input().split()] data = [int(x) for x in input().split()] segments = [] l = 0 for i in range(n): if data[i] == 1: segments.append(i - k + 1) l += 1 segments = sorted(segments) most_right = 0 cnt = 0 indx = 0 last = -1 while True: while indx < l and segments[indx] <= most_right: last = indx indx += 1 if indx == l and last != -1: cnt += 1 break if last == -1: cnt = -1 break most_right = segments[last] + 2 * k - 1 cnt += 1 last = -1 if most_right >= n: break print(cnt)
ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR NUMBER EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR NUMBER VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE NUMBER WHILE VAR VAR VAR VAR VAR ASSIGN VAR VAR VAR NUMBER IF VAR VAR VAR NUMBER VAR NUMBER IF VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR BIN_OP NUMBER VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER IF VAR VAR EXPR FUNC_CALL VAR VAR
Goodland is a country with a number of evenly spaced cities along a line. The distance between adjacent cities is $unrecognized$ unit. There is an energy infrastructure project planning meeting, and the government needs to know the fewest number of power plants needed to provide electricity to the entire list of cities. Determine that number. If it cannot be done, return -1. You are given a list of city data. Cities that may contain a power plant have been labeled $unrecognized$. Others not suitable for building a plant are labeled $unrecognized$. Given a distribution range of $unrecognized$, find the lowest number of plants that must be built such that all cities are served. The distribution range limits supply to cities where distance is less than k. Example $unrecognized$ $unrecognized$ Each city is $unrecognized$ unit distance from its neighbors, and we'll use $unrecognized$ based indexing. We see there are $unrecognized$ cities suitable for power plants, cities $unrecognized$ and $unrecognized$. If we build a power plant at $unrecognized$, it can serve $unrecognized$ through $unrecognized$ because those endpoints are at a distance of $unrecognized$ and $unrecognized$. To serve $unrecognized$, we would need to be able to build a plant in city $unrecognized$ or $unrecognized$. Since none of those is suitable, we must return -1. It cannot be done using the current distribution constraint. Function Description Complete the pylons function in the editor below. pylons has the following parameter(s): int k: the distribution range int arr[n]: each city's suitability as a building site Returns int: the minimum number of plants required or -1 Input Format The first line contains two space-separated integers $unrecognized$ and $unrecognized$, the number of cities in Goodland and the plants' range constant. The second line contains $unrecognized$ space-separated binary integers where each integer indicates suitability for building a plant. Constraints $unrecognized$ Each $unrecognized$. Subtask $unrecognized$ for $unrecognized$ of the maximum score. Output Format Print a single integer denoting the minimum number of plants that must be built so that all of Goodland's cities have electricity. If this is not possible for the given value of $unrecognized$, print $unrecognized$. Sample Input STDIN Function ----- -------- 6 2 arr[] size n = 6, k = 2 0 1 1 1 1 0 arr = [0, 1, 1, 1, 1, 0] Sample Output 2 Explanation Cities $unrecognized$, $unrecognized$, $unrecognized$, and $unrecognized$ are suitable for power plants. Each plant will have a range of $unrecognized$. If we build in cities $unrecognized$ cities, $unrecognized$ and $unrecognized$, then all cities will have electricity.
import sys n, k = list(map(int, sys.stdin.readline().strip().split())) cities = map(int, sys.stdin.readline().strip().split()) towers = [i for i, x in enumerate(cities) if x == 1] i = 0 while towers[i] < k: i += 1 power_on = [] power_on.append(towers[i - 1]) while i < len(towers): if towers[i] - power_on[-1] - 1 > 2 * (k - 1): power_on.append(towers[i - 1]) i += 1 if power_on[0] >= k: print("-1") exit() if n - 1 - power_on[-1] >= k: if n - 1 - towers[-1] < k: power_on.append(towers[-1]) else: print("-1") exit() for i in range(1, len(power_on)): if power_on[i] - power_on[i - 1] - 1 > 2 * (k - 1): print("-1") exit() print(len(power_on))
IMPORT ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR VAR VAR FUNC_CALL VAR VAR VAR NUMBER ASSIGN VAR NUMBER WHILE VAR VAR VAR VAR NUMBER ASSIGN VAR LIST EXPR FUNC_CALL VAR VAR BIN_OP VAR NUMBER WHILE VAR FUNC_CALL VAR VAR IF BIN_OP BIN_OP VAR VAR VAR NUMBER NUMBER BIN_OP NUMBER BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR BIN_OP VAR NUMBER VAR NUMBER IF VAR NUMBER VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR IF BIN_OP BIN_OP VAR NUMBER VAR NUMBER VAR IF BIN_OP BIN_OP VAR NUMBER VAR NUMBER VAR EXPR FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR IF BIN_OP BIN_OP VAR VAR VAR BIN_OP VAR NUMBER NUMBER BIN_OP NUMBER BIN_OP VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR
Goodland is a country with a number of evenly spaced cities along a line. The distance between adjacent cities is $unrecognized$ unit. There is an energy infrastructure project planning meeting, and the government needs to know the fewest number of power plants needed to provide electricity to the entire list of cities. Determine that number. If it cannot be done, return -1. You are given a list of city data. Cities that may contain a power plant have been labeled $unrecognized$. Others not suitable for building a plant are labeled $unrecognized$. Given a distribution range of $unrecognized$, find the lowest number of plants that must be built such that all cities are served. The distribution range limits supply to cities where distance is less than k. Example $unrecognized$ $unrecognized$ Each city is $unrecognized$ unit distance from its neighbors, and we'll use $unrecognized$ based indexing. We see there are $unrecognized$ cities suitable for power plants, cities $unrecognized$ and $unrecognized$. If we build a power plant at $unrecognized$, it can serve $unrecognized$ through $unrecognized$ because those endpoints are at a distance of $unrecognized$ and $unrecognized$. To serve $unrecognized$, we would need to be able to build a plant in city $unrecognized$ or $unrecognized$. Since none of those is suitable, we must return -1. It cannot be done using the current distribution constraint. Function Description Complete the pylons function in the editor below. pylons has the following parameter(s): int k: the distribution range int arr[n]: each city's suitability as a building site Returns int: the minimum number of plants required or -1 Input Format The first line contains two space-separated integers $unrecognized$ and $unrecognized$, the number of cities in Goodland and the plants' range constant. The second line contains $unrecognized$ space-separated binary integers where each integer indicates suitability for building a plant. Constraints $unrecognized$ Each $unrecognized$. Subtask $unrecognized$ for $unrecognized$ of the maximum score. Output Format Print a single integer denoting the minimum number of plants that must be built so that all of Goodland's cities have electricity. If this is not possible for the given value of $unrecognized$, print $unrecognized$. Sample Input STDIN Function ----- -------- 6 2 arr[] size n = 6, k = 2 0 1 1 1 1 0 arr = [0, 1, 1, 1, 1, 0] Sample Output 2 Explanation Cities $unrecognized$, $unrecognized$, $unrecognized$, and $unrecognized$ are suitable for power plants. Each plant will have a range of $unrecognized$. If we build in cities $unrecognized$ cities, $unrecognized$ and $unrecognized$, then all cities will have electricity.
n, k = map(int, input().split()) towers = list(map(int, input().split())) def solve(): i = 0 count = 0 done = False covered = k - 1 while i < n and covered < n: best = -1 limit = k if count == 0 else covered + k for j in range(i, limit): if j >= n: done = True break if towers[j]: best = max(best, j) covered = best + k if best == -1 or done and covered < n: return -1 count += 1 i = j + 1 return count print(solve())
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER WHILE VAR VAR VAR VAR ASSIGN VAR NUMBER ASSIGN VAR VAR NUMBER VAR BIN_OP VAR VAR FOR VAR FUNC_CALL VAR VAR VAR IF VAR VAR ASSIGN VAR NUMBER IF VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR BIN_OP VAR VAR IF VAR NUMBER VAR VAR VAR RETURN NUMBER VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER RETURN VAR EXPR FUNC_CALL VAR FUNC_CALL VAR
Goodland is a country with a number of evenly spaced cities along a line. The distance between adjacent cities is $unrecognized$ unit. There is an energy infrastructure project planning meeting, and the government needs to know the fewest number of power plants needed to provide electricity to the entire list of cities. Determine that number. If it cannot be done, return -1. You are given a list of city data. Cities that may contain a power plant have been labeled $unrecognized$. Others not suitable for building a plant are labeled $unrecognized$. Given a distribution range of $unrecognized$, find the lowest number of plants that must be built such that all cities are served. The distribution range limits supply to cities where distance is less than k. Example $unrecognized$ $unrecognized$ Each city is $unrecognized$ unit distance from its neighbors, and we'll use $unrecognized$ based indexing. We see there are $unrecognized$ cities suitable for power plants, cities $unrecognized$ and $unrecognized$. If we build a power plant at $unrecognized$, it can serve $unrecognized$ through $unrecognized$ because those endpoints are at a distance of $unrecognized$ and $unrecognized$. To serve $unrecognized$, we would need to be able to build a plant in city $unrecognized$ or $unrecognized$. Since none of those is suitable, we must return -1. It cannot be done using the current distribution constraint. Function Description Complete the pylons function in the editor below. pylons has the following parameter(s): int k: the distribution range int arr[n]: each city's suitability as a building site Returns int: the minimum number of plants required or -1 Input Format The first line contains two space-separated integers $unrecognized$ and $unrecognized$, the number of cities in Goodland and the plants' range constant. The second line contains $unrecognized$ space-separated binary integers where each integer indicates suitability for building a plant. Constraints $unrecognized$ Each $unrecognized$. Subtask $unrecognized$ for $unrecognized$ of the maximum score. Output Format Print a single integer denoting the minimum number of plants that must be built so that all of Goodland's cities have electricity. If this is not possible for the given value of $unrecognized$, print $unrecognized$. Sample Input STDIN Function ----- -------- 6 2 arr[] size n = 6, k = 2 0 1 1 1 1 0 arr = [0, 1, 1, 1, 1, 0] Sample Output 2 Explanation Cities $unrecognized$, $unrecognized$, $unrecognized$, and $unrecognized$ are suitable for power plants. Each plant will have a range of $unrecognized$. If we build in cities $unrecognized$ cities, $unrecognized$ and $unrecognized$, then all cities will have electricity.
numCities, electricalTowerRadius = [int(elem) for elem in input().strip().split(" ")] cities = [int(elem) for elem in input().strip().split(" ")] towersOn = [] done = False x = -1 lastCity = 0 for ii in range(electricalTowerRadius): if cities[ii]: x = ii if x >= 0: lastCity += x towersOn.append(lastCity) else: done = True fail = False while not done: x = 0 for ii in range(2 * electricalTowerRadius): if ii + lastCity >= numCities: done = True elif cities[lastCity + ii]: x = ii if x > 0: lastCity += x towersOn.append(lastCity) else: done = True if ii + lastCity < numCities: fail = True if towersOn and not fail: print(str(len(towersOn))) else: print(str(-1))
ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR LIST ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR ASSIGN VAR VAR IF VAR NUMBER VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP NUMBER VAR IF BIN_OP VAR VAR VAR ASSIGN VAR NUMBER IF VAR BIN_OP VAR VAR ASSIGN VAR VAR IF VAR NUMBER VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR NUMBER IF BIN_OP VAR VAR VAR ASSIGN VAR NUMBER IF VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR NUMBER
Goodland is a country with a number of evenly spaced cities along a line. The distance between adjacent cities is $unrecognized$ unit. There is an energy infrastructure project planning meeting, and the government needs to know the fewest number of power plants needed to provide electricity to the entire list of cities. Determine that number. If it cannot be done, return -1. You are given a list of city data. Cities that may contain a power plant have been labeled $unrecognized$. Others not suitable for building a plant are labeled $unrecognized$. Given a distribution range of $unrecognized$, find the lowest number of plants that must be built such that all cities are served. The distribution range limits supply to cities where distance is less than k. Example $unrecognized$ $unrecognized$ Each city is $unrecognized$ unit distance from its neighbors, and we'll use $unrecognized$ based indexing. We see there are $unrecognized$ cities suitable for power plants, cities $unrecognized$ and $unrecognized$. If we build a power plant at $unrecognized$, it can serve $unrecognized$ through $unrecognized$ because those endpoints are at a distance of $unrecognized$ and $unrecognized$. To serve $unrecognized$, we would need to be able to build a plant in city $unrecognized$ or $unrecognized$. Since none of those is suitable, we must return -1. It cannot be done using the current distribution constraint. Function Description Complete the pylons function in the editor below. pylons has the following parameter(s): int k: the distribution range int arr[n]: each city's suitability as a building site Returns int: the minimum number of plants required or -1 Input Format The first line contains two space-separated integers $unrecognized$ and $unrecognized$, the number of cities in Goodland and the plants' range constant. The second line contains $unrecognized$ space-separated binary integers where each integer indicates suitability for building a plant. Constraints $unrecognized$ Each $unrecognized$. Subtask $unrecognized$ for $unrecognized$ of the maximum score. Output Format Print a single integer denoting the minimum number of plants that must be built so that all of Goodland's cities have electricity. If this is not possible for the given value of $unrecognized$, print $unrecognized$. Sample Input STDIN Function ----- -------- 6 2 arr[] size n = 6, k = 2 0 1 1 1 1 0 arr = [0, 1, 1, 1, 1, 0] Sample Output 2 Explanation Cities $unrecognized$, $unrecognized$, $unrecognized$, and $unrecognized$ are suitable for power plants. Each plant will have a range of $unrecognized$. If we build in cities $unrecognized$ cities, $unrecognized$ and $unrecognized$, then all cities will have electricity.
n, k = map(int, input().split()) cs = list(map(int, input().split())) count = 0 i = 0 while i < n: found = False for j in range(min(n - 1, i + k - 1), max(-1, i - k), -1): if cs[j] == 1: found = True count += 1 i = j + k break if not found: count = -1 break print(count)
ASSIGN VAR 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 NUMBER ASSIGN VAR NUMBER WHILE VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP BIN_OP VAR VAR NUMBER FUNC_CALL VAR NUMBER BIN_OP VAR VAR NUMBER IF VAR VAR NUMBER ASSIGN VAR NUMBER VAR NUMBER ASSIGN VAR BIN_OP VAR VAR IF VAR ASSIGN VAR NUMBER EXPR FUNC_CALL VAR VAR
Goodland is a country with a number of evenly spaced cities along a line. The distance between adjacent cities is $unrecognized$ unit. There is an energy infrastructure project planning meeting, and the government needs to know the fewest number of power plants needed to provide electricity to the entire list of cities. Determine that number. If it cannot be done, return -1. You are given a list of city data. Cities that may contain a power plant have been labeled $unrecognized$. Others not suitable for building a plant are labeled $unrecognized$. Given a distribution range of $unrecognized$, find the lowest number of plants that must be built such that all cities are served. The distribution range limits supply to cities where distance is less than k. Example $unrecognized$ $unrecognized$ Each city is $unrecognized$ unit distance from its neighbors, and we'll use $unrecognized$ based indexing. We see there are $unrecognized$ cities suitable for power plants, cities $unrecognized$ and $unrecognized$. If we build a power plant at $unrecognized$, it can serve $unrecognized$ through $unrecognized$ because those endpoints are at a distance of $unrecognized$ and $unrecognized$. To serve $unrecognized$, we would need to be able to build a plant in city $unrecognized$ or $unrecognized$. Since none of those is suitable, we must return -1. It cannot be done using the current distribution constraint. Function Description Complete the pylons function in the editor below. pylons has the following parameter(s): int k: the distribution range int arr[n]: each city's suitability as a building site Returns int: the minimum number of plants required or -1 Input Format The first line contains two space-separated integers $unrecognized$ and $unrecognized$, the number of cities in Goodland and the plants' range constant. The second line contains $unrecognized$ space-separated binary integers where each integer indicates suitability for building a plant. Constraints $unrecognized$ Each $unrecognized$. Subtask $unrecognized$ for $unrecognized$ of the maximum score. Output Format Print a single integer denoting the minimum number of plants that must be built so that all of Goodland's cities have electricity. If this is not possible for the given value of $unrecognized$, print $unrecognized$. Sample Input STDIN Function ----- -------- 6 2 arr[] size n = 6, k = 2 0 1 1 1 1 0 arr = [0, 1, 1, 1, 1, 0] Sample Output 2 Explanation Cities $unrecognized$, $unrecognized$, $unrecognized$, and $unrecognized$ are suitable for power plants. Each plant will have a range of $unrecognized$. If we build in cities $unrecognized$ cities, $unrecognized$ and $unrecognized$, then all cities will have electricity.
def solve(cities, K): switch_count = 0 last_switch_index = -K last_switchable_index = None cities += [0] * K for index in range(len(cities)): if index >= last_switch_index + 2 * K: if last_switchable_index == None: return "-1" last_switch_index = last_switchable_index switch_count += 1 last_switchable_index = None if cities[index] == 1: last_switchable_index = index return switch_count N, K = list(map(int, input().split())) cities = list(map(int, input().split())) print(solve(cities, K))
FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR VAR ASSIGN VAR NONE VAR BIN_OP LIST NUMBER VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR BIN_OP VAR BIN_OP NUMBER VAR IF VAR NONE RETURN STRING ASSIGN VAR VAR VAR NUMBER ASSIGN VAR NONE IF VAR VAR NUMBER ASSIGN VAR VAR RETURN VAR ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR
Goodland is a country with a number of evenly spaced cities along a line. The distance between adjacent cities is $unrecognized$ unit. There is an energy infrastructure project planning meeting, and the government needs to know the fewest number of power plants needed to provide electricity to the entire list of cities. Determine that number. If it cannot be done, return -1. You are given a list of city data. Cities that may contain a power plant have been labeled $unrecognized$. Others not suitable for building a plant are labeled $unrecognized$. Given a distribution range of $unrecognized$, find the lowest number of plants that must be built such that all cities are served. The distribution range limits supply to cities where distance is less than k. Example $unrecognized$ $unrecognized$ Each city is $unrecognized$ unit distance from its neighbors, and we'll use $unrecognized$ based indexing. We see there are $unrecognized$ cities suitable for power plants, cities $unrecognized$ and $unrecognized$. If we build a power plant at $unrecognized$, it can serve $unrecognized$ through $unrecognized$ because those endpoints are at a distance of $unrecognized$ and $unrecognized$. To serve $unrecognized$, we would need to be able to build a plant in city $unrecognized$ or $unrecognized$. Since none of those is suitable, we must return -1. It cannot be done using the current distribution constraint. Function Description Complete the pylons function in the editor below. pylons has the following parameter(s): int k: the distribution range int arr[n]: each city's suitability as a building site Returns int: the minimum number of plants required or -1 Input Format The first line contains two space-separated integers $unrecognized$ and $unrecognized$, the number of cities in Goodland and the plants' range constant. The second line contains $unrecognized$ space-separated binary integers where each integer indicates suitability for building a plant. Constraints $unrecognized$ Each $unrecognized$. Subtask $unrecognized$ for $unrecognized$ of the maximum score. Output Format Print a single integer denoting the minimum number of plants that must be built so that all of Goodland's cities have electricity. If this is not possible for the given value of $unrecognized$, print $unrecognized$. Sample Input STDIN Function ----- -------- 6 2 arr[] size n = 6, k = 2 0 1 1 1 1 0 arr = [0, 1, 1, 1, 1, 0] Sample Output 2 Explanation Cities $unrecognized$, $unrecognized$, $unrecognized$, and $unrecognized$ are suitable for power plants. Each plant will have a range of $unrecognized$. If we build in cities $unrecognized$ cities, $unrecognized$ and $unrecognized$, then all cities will have electricity.
n, k = map(int, input().split()) t = list(map(int, input().split())) assert len(t) == n and min(t) >= 0 and max(t) <= 1 u, f = 0, 0 while f < n: for i in range(min(n - 1, f + k - 1), max(-1, f - k), -1): if t[i]: u += 1 f = i + k break else: u, f = -1, n print(u)
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR NUMBER FUNC_CALL VAR VAR NUMBER ASSIGN VAR VAR NUMBER NUMBER WHILE VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP BIN_OP VAR VAR NUMBER FUNC_CALL VAR NUMBER BIN_OP VAR VAR NUMBER IF VAR VAR VAR NUMBER ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR VAR NUMBER VAR EXPR FUNC_CALL VAR VAR
Goodland is a country with a number of evenly spaced cities along a line. The distance between adjacent cities is $unrecognized$ unit. There is an energy infrastructure project planning meeting, and the government needs to know the fewest number of power plants needed to provide electricity to the entire list of cities. Determine that number. If it cannot be done, return -1. You are given a list of city data. Cities that may contain a power plant have been labeled $unrecognized$. Others not suitable for building a plant are labeled $unrecognized$. Given a distribution range of $unrecognized$, find the lowest number of plants that must be built such that all cities are served. The distribution range limits supply to cities where distance is less than k. Example $unrecognized$ $unrecognized$ Each city is $unrecognized$ unit distance from its neighbors, and we'll use $unrecognized$ based indexing. We see there are $unrecognized$ cities suitable for power plants, cities $unrecognized$ and $unrecognized$. If we build a power plant at $unrecognized$, it can serve $unrecognized$ through $unrecognized$ because those endpoints are at a distance of $unrecognized$ and $unrecognized$. To serve $unrecognized$, we would need to be able to build a plant in city $unrecognized$ or $unrecognized$. Since none of those is suitable, we must return -1. It cannot be done using the current distribution constraint. Function Description Complete the pylons function in the editor below. pylons has the following parameter(s): int k: the distribution range int arr[n]: each city's suitability as a building site Returns int: the minimum number of plants required or -1 Input Format The first line contains two space-separated integers $unrecognized$ and $unrecognized$, the number of cities in Goodland and the plants' range constant. The second line contains $unrecognized$ space-separated binary integers where each integer indicates suitability for building a plant. Constraints $unrecognized$ Each $unrecognized$. Subtask $unrecognized$ for $unrecognized$ of the maximum score. Output Format Print a single integer denoting the minimum number of plants that must be built so that all of Goodland's cities have electricity. If this is not possible for the given value of $unrecognized$, print $unrecognized$. Sample Input STDIN Function ----- -------- 6 2 arr[] size n = 6, k = 2 0 1 1 1 1 0 arr = [0, 1, 1, 1, 1, 0] Sample Output 2 Explanation Cities $unrecognized$, $unrecognized$, $unrecognized$, and $unrecognized$ are suitable for power plants. Each plant will have a range of $unrecognized$. If we build in cities $unrecognized$ cities, $unrecognized$ and $unrecognized$, then all cities will have electricity.
def min_towers(n, k, cities): l = -1 try: r = next(i for i in range(n) if cities[i]) except StopIteration: return -1 while l != n: if r - l - 1 > 2 * (k - 1): return -1 l, r = r, next((i for i in range(r + 1, n) if cities[i]), n) s, r_edge = 0, -1 while r_edge != n - 1: i = min(r_edge + k, n - 1) while not cities[i]: i -= 1 r_edge = min(i + k - 1, n - 1) s += 1 return s n, k = map(int, input().split()) cities = [int(x) for x in input().split()] print(min_towers(n, k, cities))
FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR VAR VAR VAR RETURN NUMBER WHILE VAR VAR IF BIN_OP BIN_OP VAR VAR NUMBER BIN_OP NUMBER BIN_OP VAR NUMBER RETURN NUMBER ASSIGN VAR VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR VAR VAR VAR ASSIGN VAR VAR NUMBER NUMBER WHILE VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR BIN_OP VAR VAR BIN_OP VAR NUMBER WHILE VAR VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR NUMBER BIN_OP VAR NUMBER VAR NUMBER RETURN VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR VAR
Goodland is a country with a number of evenly spaced cities along a line. The distance between adjacent cities is $unrecognized$ unit. There is an energy infrastructure project planning meeting, and the government needs to know the fewest number of power plants needed to provide electricity to the entire list of cities. Determine that number. If it cannot be done, return -1. You are given a list of city data. Cities that may contain a power plant have been labeled $unrecognized$. Others not suitable for building a plant are labeled $unrecognized$. Given a distribution range of $unrecognized$, find the lowest number of plants that must be built such that all cities are served. The distribution range limits supply to cities where distance is less than k. Example $unrecognized$ $unrecognized$ Each city is $unrecognized$ unit distance from its neighbors, and we'll use $unrecognized$ based indexing. We see there are $unrecognized$ cities suitable for power plants, cities $unrecognized$ and $unrecognized$. If we build a power plant at $unrecognized$, it can serve $unrecognized$ through $unrecognized$ because those endpoints are at a distance of $unrecognized$ and $unrecognized$. To serve $unrecognized$, we would need to be able to build a plant in city $unrecognized$ or $unrecognized$. Since none of those is suitable, we must return -1. It cannot be done using the current distribution constraint. Function Description Complete the pylons function in the editor below. pylons has the following parameter(s): int k: the distribution range int arr[n]: each city's suitability as a building site Returns int: the minimum number of plants required or -1 Input Format The first line contains two space-separated integers $unrecognized$ and $unrecognized$, the number of cities in Goodland and the plants' range constant. The second line contains $unrecognized$ space-separated binary integers where each integer indicates suitability for building a plant. Constraints $unrecognized$ Each $unrecognized$. Subtask $unrecognized$ for $unrecognized$ of the maximum score. Output Format Print a single integer denoting the minimum number of plants that must be built so that all of Goodland's cities have electricity. If this is not possible for the given value of $unrecognized$, print $unrecognized$. Sample Input STDIN Function ----- -------- 6 2 arr[] size n = 6, k = 2 0 1 1 1 1 0 arr = [0, 1, 1, 1, 1, 0] Sample Output 2 Explanation Cities $unrecognized$, $unrecognized$, $unrecognized$, and $unrecognized$ are suitable for power plants. Each plant will have a range of $unrecognized$. If we build in cities $unrecognized$ cities, $unrecognized$ and $unrecognized$, then all cities will have electricity.
def solve(ts, k): c = 0 r, i = -1, -1 if k >= len(ts) - 1: return int(1 in ts) while i < len(ts) - 1: i = min(len(ts) - 1, i + k) while r < i: if ts[i] == 1: break i -= 1 else: return -1 r = i i += k - 1 c += 1 return c k = int(input().split()[1]) print(solve([int(x) for x in input().split()], k))
FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR VAR NUMBER NUMBER IF VAR BIN_OP FUNC_CALL VAR VAR NUMBER RETURN FUNC_CALL VAR NUMBER VAR WHILE VAR BIN_OP FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER BIN_OP VAR VAR WHILE VAR VAR IF VAR VAR NUMBER VAR NUMBER RETURN NUMBER ASSIGN VAR VAR VAR BIN_OP VAR NUMBER VAR NUMBER RETURN VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR VAR
Goodland is a country with a number of evenly spaced cities along a line. The distance between adjacent cities is $unrecognized$ unit. There is an energy infrastructure project planning meeting, and the government needs to know the fewest number of power plants needed to provide electricity to the entire list of cities. Determine that number. If it cannot be done, return -1. You are given a list of city data. Cities that may contain a power plant have been labeled $unrecognized$. Others not suitable for building a plant are labeled $unrecognized$. Given a distribution range of $unrecognized$, find the lowest number of plants that must be built such that all cities are served. The distribution range limits supply to cities where distance is less than k. Example $unrecognized$ $unrecognized$ Each city is $unrecognized$ unit distance from its neighbors, and we'll use $unrecognized$ based indexing. We see there are $unrecognized$ cities suitable for power plants, cities $unrecognized$ and $unrecognized$. If we build a power plant at $unrecognized$, it can serve $unrecognized$ through $unrecognized$ because those endpoints are at a distance of $unrecognized$ and $unrecognized$. To serve $unrecognized$, we would need to be able to build a plant in city $unrecognized$ or $unrecognized$. Since none of those is suitable, we must return -1. It cannot be done using the current distribution constraint. Function Description Complete the pylons function in the editor below. pylons has the following parameter(s): int k: the distribution range int arr[n]: each city's suitability as a building site Returns int: the minimum number of plants required or -1 Input Format The first line contains two space-separated integers $unrecognized$ and $unrecognized$, the number of cities in Goodland and the plants' range constant. The second line contains $unrecognized$ space-separated binary integers where each integer indicates suitability for building a plant. Constraints $unrecognized$ Each $unrecognized$. Subtask $unrecognized$ for $unrecognized$ of the maximum score. Output Format Print a single integer denoting the minimum number of plants that must be built so that all of Goodland's cities have electricity. If this is not possible for the given value of $unrecognized$, print $unrecognized$. Sample Input STDIN Function ----- -------- 6 2 arr[] size n = 6, k = 2 0 1 1 1 1 0 arr = [0, 1, 1, 1, 1, 0] Sample Output 2 Explanation Cities $unrecognized$, $unrecognized$, $unrecognized$, and $unrecognized$ are suitable for power plants. Each plant will have a range of $unrecognized$. If we build in cities $unrecognized$ cities, $unrecognized$ and $unrecognized$, then all cities will have electricity.
def solve(C, k): limit = k - 1 count = 0 i = 0 prev = -1 while i < len(C): if C[i]: prev = i if i == limit: if prev == -1: return -1 limit = prev + 2 * k - 1 prev = -1 count += 1 i += 1 limit -= k if limit < len(C) - 1: if prev == -1: return -1 if prev + limit < len(C) - 1: return -1 count += 1 return count n, k = map(int, input().strip().split()) C = [int(i) for i in input().strip().split()] print(solve(C, k))
FUNC_DEF ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR FUNC_CALL VAR VAR IF VAR VAR ASSIGN VAR VAR IF VAR VAR IF VAR NUMBER RETURN NUMBER ASSIGN VAR BIN_OP BIN_OP VAR BIN_OP NUMBER VAR NUMBER ASSIGN VAR NUMBER VAR NUMBER VAR NUMBER VAR VAR IF VAR BIN_OP FUNC_CALL VAR VAR NUMBER IF VAR NUMBER RETURN NUMBER IF BIN_OP VAR VAR BIN_OP FUNC_CALL VAR VAR NUMBER RETURN NUMBER VAR NUMBER RETURN VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR
Goodland is a country with a number of evenly spaced cities along a line. The distance between adjacent cities is $unrecognized$ unit. There is an energy infrastructure project planning meeting, and the government needs to know the fewest number of power plants needed to provide electricity to the entire list of cities. Determine that number. If it cannot be done, return -1. You are given a list of city data. Cities that may contain a power plant have been labeled $unrecognized$. Others not suitable for building a plant are labeled $unrecognized$. Given a distribution range of $unrecognized$, find the lowest number of plants that must be built such that all cities are served. The distribution range limits supply to cities where distance is less than k. Example $unrecognized$ $unrecognized$ Each city is $unrecognized$ unit distance from its neighbors, and we'll use $unrecognized$ based indexing. We see there are $unrecognized$ cities suitable for power plants, cities $unrecognized$ and $unrecognized$. If we build a power plant at $unrecognized$, it can serve $unrecognized$ through $unrecognized$ because those endpoints are at a distance of $unrecognized$ and $unrecognized$. To serve $unrecognized$, we would need to be able to build a plant in city $unrecognized$ or $unrecognized$. Since none of those is suitable, we must return -1. It cannot be done using the current distribution constraint. Function Description Complete the pylons function in the editor below. pylons has the following parameter(s): int k: the distribution range int arr[n]: each city's suitability as a building site Returns int: the minimum number of plants required or -1 Input Format The first line contains two space-separated integers $unrecognized$ and $unrecognized$, the number of cities in Goodland and the plants' range constant. The second line contains $unrecognized$ space-separated binary integers where each integer indicates suitability for building a plant. Constraints $unrecognized$ Each $unrecognized$. Subtask $unrecognized$ for $unrecognized$ of the maximum score. Output Format Print a single integer denoting the minimum number of plants that must be built so that all of Goodland's cities have electricity. If this is not possible for the given value of $unrecognized$, print $unrecognized$. Sample Input STDIN Function ----- -------- 6 2 arr[] size n = 6, k = 2 0 1 1 1 1 0 arr = [0, 1, 1, 1, 1, 0] Sample Output 2 Explanation Cities $unrecognized$, $unrecognized$, $unrecognized$, and $unrecognized$ are suitable for power plants. Each plant will have a range of $unrecognized$. If we build in cities $unrecognized$ cities, $unrecognized$ and $unrecognized$, then all cities will have electricity.
n, k = [int(x) for x in input().split()] towers = [int(x) for x in input().split()] count = 0 turned_on = [] temp = towers[:k] if temp.count(1) == 0: count = -1 turned_on.append(n) else: val = temp[::-1].index(1) count += 1 turned_on.append(k - 1 - val) while turned_on[-1] + (k - 1) < n - 1: temp = towers[turned_on[-1] + 1 : turned_on[-1] + 2 * k] if temp.count(1) == 0: count = -1 break val = temp[::-1].index(1) count += 1 turned_on.append(turned_on[-1] + 2 * k - 1 - val) print(count)
ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR LIST ASSIGN VAR VAR VAR IF FUNC_CALL VAR NUMBER NUMBER ASSIGN VAR NUMBER EXPR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR NUMBER NUMBER VAR NUMBER EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR NUMBER VAR WHILE BIN_OP VAR NUMBER BIN_OP VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR VAR BIN_OP VAR NUMBER NUMBER BIN_OP VAR NUMBER BIN_OP NUMBER VAR IF FUNC_CALL VAR NUMBER NUMBER ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR NUMBER NUMBER VAR NUMBER EXPR FUNC_CALL VAR BIN_OP BIN_OP BIN_OP VAR NUMBER BIN_OP NUMBER VAR NUMBER VAR EXPR FUNC_CALL VAR VAR
Goodland is a country with a number of evenly spaced cities along a line. The distance between adjacent cities is $unrecognized$ unit. There is an energy infrastructure project planning meeting, and the government needs to know the fewest number of power plants needed to provide electricity to the entire list of cities. Determine that number. If it cannot be done, return -1. You are given a list of city data. Cities that may contain a power plant have been labeled $unrecognized$. Others not suitable for building a plant are labeled $unrecognized$. Given a distribution range of $unrecognized$, find the lowest number of plants that must be built such that all cities are served. The distribution range limits supply to cities where distance is less than k. Example $unrecognized$ $unrecognized$ Each city is $unrecognized$ unit distance from its neighbors, and we'll use $unrecognized$ based indexing. We see there are $unrecognized$ cities suitable for power plants, cities $unrecognized$ and $unrecognized$. If we build a power plant at $unrecognized$, it can serve $unrecognized$ through $unrecognized$ because those endpoints are at a distance of $unrecognized$ and $unrecognized$. To serve $unrecognized$, we would need to be able to build a plant in city $unrecognized$ or $unrecognized$. Since none of those is suitable, we must return -1. It cannot be done using the current distribution constraint. Function Description Complete the pylons function in the editor below. pylons has the following parameter(s): int k: the distribution range int arr[n]: each city's suitability as a building site Returns int: the minimum number of plants required or -1 Input Format The first line contains two space-separated integers $unrecognized$ and $unrecognized$, the number of cities in Goodland and the plants' range constant. The second line contains $unrecognized$ space-separated binary integers where each integer indicates suitability for building a plant. Constraints $unrecognized$ Each $unrecognized$. Subtask $unrecognized$ for $unrecognized$ of the maximum score. Output Format Print a single integer denoting the minimum number of plants that must be built so that all of Goodland's cities have electricity. If this is not possible for the given value of $unrecognized$, print $unrecognized$. Sample Input STDIN Function ----- -------- 6 2 arr[] size n = 6, k = 2 0 1 1 1 1 0 arr = [0, 1, 1, 1, 1, 0] Sample Output 2 Explanation Cities $unrecognized$, $unrecognized$, $unrecognized$, and $unrecognized$ are suitable for power plants. Each plant will have a range of $unrecognized$. If we build in cities $unrecognized$ cities, $unrecognized$ and $unrecognized$, then all cities will have electricity.
n, k = list(map(int, input().split())) a = list(map(int, input().split())) def pu(i, j, a, k): while j >= i and a[j] != 1: j -= 1 if j < i: print(-1) exit() return j i, c, p = k - 1, 0, 0 while i < n: j = i c = pu(c, i, a, k) + 1 p += 1 i = c + 2 * k - 2 if i - k >= n - 1: print(p) else: pu(n - k + 1, n - 1, a, k) print(p + 1)
ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FUNC_DEF WHILE VAR VAR VAR VAR NUMBER VAR NUMBER IF VAR VAR EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR RETURN VAR ASSIGN VAR VAR VAR BIN_OP VAR NUMBER NUMBER NUMBER WHILE VAR VAR ASSIGN VAR VAR ASSIGN VAR BIN_OP FUNC_CALL VAR VAR VAR VAR VAR NUMBER VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR BIN_OP NUMBER VAR NUMBER IF BIN_OP VAR VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR NUMBER BIN_OP VAR NUMBER VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR NUMBER
Goodland is a country with a number of evenly spaced cities along a line. The distance between adjacent cities is $unrecognized$ unit. There is an energy infrastructure project planning meeting, and the government needs to know the fewest number of power plants needed to provide electricity to the entire list of cities. Determine that number. If it cannot be done, return -1. You are given a list of city data. Cities that may contain a power plant have been labeled $unrecognized$. Others not suitable for building a plant are labeled $unrecognized$. Given a distribution range of $unrecognized$, find the lowest number of plants that must be built such that all cities are served. The distribution range limits supply to cities where distance is less than k. Example $unrecognized$ $unrecognized$ Each city is $unrecognized$ unit distance from its neighbors, and we'll use $unrecognized$ based indexing. We see there are $unrecognized$ cities suitable for power plants, cities $unrecognized$ and $unrecognized$. If we build a power plant at $unrecognized$, it can serve $unrecognized$ through $unrecognized$ because those endpoints are at a distance of $unrecognized$ and $unrecognized$. To serve $unrecognized$, we would need to be able to build a plant in city $unrecognized$ or $unrecognized$. Since none of those is suitable, we must return -1. It cannot be done using the current distribution constraint. Function Description Complete the pylons function in the editor below. pylons has the following parameter(s): int k: the distribution range int arr[n]: each city's suitability as a building site Returns int: the minimum number of plants required or -1 Input Format The first line contains two space-separated integers $unrecognized$ and $unrecognized$, the number of cities in Goodland and the plants' range constant. The second line contains $unrecognized$ space-separated binary integers where each integer indicates suitability for building a plant. Constraints $unrecognized$ Each $unrecognized$. Subtask $unrecognized$ for $unrecognized$ of the maximum score. Output Format Print a single integer denoting the minimum number of plants that must be built so that all of Goodland's cities have electricity. If this is not possible for the given value of $unrecognized$, print $unrecognized$. Sample Input STDIN Function ----- -------- 6 2 arr[] size n = 6, k = 2 0 1 1 1 1 0 arr = [0, 1, 1, 1, 1, 0] Sample Output 2 Explanation Cities $unrecognized$, $unrecognized$, $unrecognized$, and $unrecognized$ are suitable for power plants. Each plant will have a range of $unrecognized$. If we build in cities $unrecognized$ cities, $unrecognized$ and $unrecognized$, then all cities will have electricity.
def result(n, k, A): count = 0 i = 0 while i < n: for j in reversed(range(max(0, i - k), min(n, i + k))): if A[j]: count += 1 i = j + k break else: return -1 return count def result2(n, k, A): needs_coverage = 0 farthest_covering = -1 count = 0 for i, a in enumerate(A): if i >= needs_coverage + k: if farthest_covering == -1: return -1 else: count += 1 needs_coverage = farthest_covering + k if needs_coverage >= n: return count farthest_covering = -1 if a: farthest_covering = i else: return count + 1 if farthest_covering != -1 else -1 n, k = (int(x) for x in input().strip().split()) A = [int(x) for x in input().strip().split()] print(result2(n, k, A))
FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR NUMBER BIN_OP VAR VAR FUNC_CALL VAR VAR BIN_OP VAR VAR IF VAR VAR VAR NUMBER ASSIGN VAR BIN_OP VAR VAR RETURN NUMBER RETURN VAR FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR FUNC_CALL VAR VAR IF VAR BIN_OP VAR VAR IF VAR NUMBER RETURN NUMBER VAR NUMBER ASSIGN VAR BIN_OP VAR VAR IF VAR VAR RETURN VAR ASSIGN VAR NUMBER IF VAR ASSIGN VAR VAR RETURN VAR NUMBER BIN_OP VAR NUMBER NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR VAR
Goodland is a country with a number of evenly spaced cities along a line. The distance between adjacent cities is $unrecognized$ unit. There is an energy infrastructure project planning meeting, and the government needs to know the fewest number of power plants needed to provide electricity to the entire list of cities. Determine that number. If it cannot be done, return -1. You are given a list of city data. Cities that may contain a power plant have been labeled $unrecognized$. Others not suitable for building a plant are labeled $unrecognized$. Given a distribution range of $unrecognized$, find the lowest number of plants that must be built such that all cities are served. The distribution range limits supply to cities where distance is less than k. Example $unrecognized$ $unrecognized$ Each city is $unrecognized$ unit distance from its neighbors, and we'll use $unrecognized$ based indexing. We see there are $unrecognized$ cities suitable for power plants, cities $unrecognized$ and $unrecognized$. If we build a power plant at $unrecognized$, it can serve $unrecognized$ through $unrecognized$ because those endpoints are at a distance of $unrecognized$ and $unrecognized$. To serve $unrecognized$, we would need to be able to build a plant in city $unrecognized$ or $unrecognized$. Since none of those is suitable, we must return -1. It cannot be done using the current distribution constraint. Function Description Complete the pylons function in the editor below. pylons has the following parameter(s): int k: the distribution range int arr[n]: each city's suitability as a building site Returns int: the minimum number of plants required or -1 Input Format The first line contains two space-separated integers $unrecognized$ and $unrecognized$, the number of cities in Goodland and the plants' range constant. The second line contains $unrecognized$ space-separated binary integers where each integer indicates suitability for building a plant. Constraints $unrecognized$ Each $unrecognized$. Subtask $unrecognized$ for $unrecognized$ of the maximum score. Output Format Print a single integer denoting the minimum number of plants that must be built so that all of Goodland's cities have electricity. If this is not possible for the given value of $unrecognized$, print $unrecognized$. Sample Input STDIN Function ----- -------- 6 2 arr[] size n = 6, k = 2 0 1 1 1 1 0 arr = [0, 1, 1, 1, 1, 0] Sample Output 2 Explanation Cities $unrecognized$, $unrecognized$, $unrecognized$, and $unrecognized$ are suitable for power plants. Each plant will have a range of $unrecognized$. If we build in cities $unrecognized$ cities, $unrecognized$ and $unrecognized$, then all cities will have electricity.
def min_towers(a, k): enabled = 1 last = -1 furthest = -1 i = 0 while i < k: if a[i] == 1: last = i furthest = i i += 1 if last == -1: return last while i < len(a): if i == last + 2 * k: if furthest == last: return -1 else: enabled += 1 last = furthest if a[i] == 1: furthest = i i += 1 if last < len(a) - k: enabled += 1 last = furthest if furthest < len(a) - k: return -1 else: return enabled n, k = map(int, input().strip().split(" ")) a = list(map(int, input().strip().split(" "))) print(min_towers(a, k))
FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR VAR IF VAR VAR NUMBER ASSIGN VAR VAR ASSIGN VAR VAR VAR NUMBER IF VAR NUMBER RETURN VAR WHILE VAR FUNC_CALL VAR VAR IF VAR BIN_OP VAR BIN_OP NUMBER VAR IF VAR VAR RETURN NUMBER VAR NUMBER ASSIGN VAR VAR IF VAR VAR NUMBER ASSIGN VAR VAR VAR NUMBER IF VAR BIN_OP FUNC_CALL VAR VAR VAR VAR NUMBER ASSIGN VAR VAR IF VAR BIN_OP FUNC_CALL VAR VAR VAR RETURN NUMBER RETURN VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR STRING EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR
Goodland is a country with a number of evenly spaced cities along a line. The distance between adjacent cities is $unrecognized$ unit. There is an energy infrastructure project planning meeting, and the government needs to know the fewest number of power plants needed to provide electricity to the entire list of cities. Determine that number. If it cannot be done, return -1. You are given a list of city data. Cities that may contain a power plant have been labeled $unrecognized$. Others not suitable for building a plant are labeled $unrecognized$. Given a distribution range of $unrecognized$, find the lowest number of plants that must be built such that all cities are served. The distribution range limits supply to cities where distance is less than k. Example $unrecognized$ $unrecognized$ Each city is $unrecognized$ unit distance from its neighbors, and we'll use $unrecognized$ based indexing. We see there are $unrecognized$ cities suitable for power plants, cities $unrecognized$ and $unrecognized$. If we build a power plant at $unrecognized$, it can serve $unrecognized$ through $unrecognized$ because those endpoints are at a distance of $unrecognized$ and $unrecognized$. To serve $unrecognized$, we would need to be able to build a plant in city $unrecognized$ or $unrecognized$. Since none of those is suitable, we must return -1. It cannot be done using the current distribution constraint. Function Description Complete the pylons function in the editor below. pylons has the following parameter(s): int k: the distribution range int arr[n]: each city's suitability as a building site Returns int: the minimum number of plants required or -1 Input Format The first line contains two space-separated integers $unrecognized$ and $unrecognized$, the number of cities in Goodland and the plants' range constant. The second line contains $unrecognized$ space-separated binary integers where each integer indicates suitability for building a plant. Constraints $unrecognized$ Each $unrecognized$. Subtask $unrecognized$ for $unrecognized$ of the maximum score. Output Format Print a single integer denoting the minimum number of plants that must be built so that all of Goodland's cities have electricity. If this is not possible for the given value of $unrecognized$, print $unrecognized$. Sample Input STDIN Function ----- -------- 6 2 arr[] size n = 6, k = 2 0 1 1 1 1 0 arr = [0, 1, 1, 1, 1, 0] Sample Output 2 Explanation Cities $unrecognized$, $unrecognized$, $unrecognized$, and $unrecognized$ are suitable for power plants. Each plant will have a range of $unrecognized$. If we build in cities $unrecognized$ cities, $unrecognized$ and $unrecognized$, then all cities will have electricity.
def min_towers(tower_range, city_towers): if tower_range == 1 and city_towers[0] == 0: return -1 n = 0 idx_right = 0 idx_left = len(city_towers) - 1 while idx_left > idx_right: on_right = turn_on_tower_right(idx_right, tower_range, city_towers) if on_right == -1: return -1 n = n + 1 idx_right = on_right + tower_range if idx_right > idx_left: break on_left = turn_on_tower_left(idx_left, tower_range, city_towers) if on_left == -1: return -1 n = n + 1 idx_left = on_left - tower_range if idx_left == idx_right: n = n + 1 return n def turn_on_tower_right(start_index, tower_range, city_towers): max_idx = min(start_index + tower_range, len(city_towers)) - 1 min_idx = max(0, start_index - tower_range + 1) - 1 for i in range(max_idx, min_idx, -1): if city_towers[i] == 1: return i return -1 def turn_on_tower_left(start_index, tower_range, city_towers): min_idx = max(0, start_index - tower_range + 1) max_idx = min(start_index + tower_range, len(city_towers)) for i in range(min_idx, max_idx): if city_towers[i] == 1: return i return -1 def main(): n_cities, tower_range = [int(x) for x in input().split()] city_towers = [int(x) for x in input().split()] print(min_towers(tower_range, city_towers)) main()
FUNC_DEF IF VAR NUMBER VAR NUMBER NUMBER RETURN NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER WHILE VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR IF VAR NUMBER RETURN NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR VAR IF VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR IF VAR NUMBER RETURN NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR VAR IF VAR VAR ASSIGN VAR BIN_OP VAR NUMBER RETURN VAR FUNC_DEF ASSIGN VAR BIN_OP FUNC_CALL VAR BIN_OP VAR VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR NUMBER BIN_OP BIN_OP VAR VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR VAR VAR NUMBER IF VAR VAR NUMBER RETURN VAR RETURN NUMBER FUNC_DEF ASSIGN VAR FUNC_CALL VAR NUMBER BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR BIN_OP VAR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR VAR IF VAR VAR NUMBER RETURN VAR RETURN NUMBER FUNC_DEF ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR
Goodland is a country with a number of evenly spaced cities along a line. The distance between adjacent cities is $unrecognized$ unit. There is an energy infrastructure project planning meeting, and the government needs to know the fewest number of power plants needed to provide electricity to the entire list of cities. Determine that number. If it cannot be done, return -1. You are given a list of city data. Cities that may contain a power plant have been labeled $unrecognized$. Others not suitable for building a plant are labeled $unrecognized$. Given a distribution range of $unrecognized$, find the lowest number of plants that must be built such that all cities are served. The distribution range limits supply to cities where distance is less than k. Example $unrecognized$ $unrecognized$ Each city is $unrecognized$ unit distance from its neighbors, and we'll use $unrecognized$ based indexing. We see there are $unrecognized$ cities suitable for power plants, cities $unrecognized$ and $unrecognized$. If we build a power plant at $unrecognized$, it can serve $unrecognized$ through $unrecognized$ because those endpoints are at a distance of $unrecognized$ and $unrecognized$. To serve $unrecognized$, we would need to be able to build a plant in city $unrecognized$ or $unrecognized$. Since none of those is suitable, we must return -1. It cannot be done using the current distribution constraint. Function Description Complete the pylons function in the editor below. pylons has the following parameter(s): int k: the distribution range int arr[n]: each city's suitability as a building site Returns int: the minimum number of plants required or -1 Input Format The first line contains two space-separated integers $unrecognized$ and $unrecognized$, the number of cities in Goodland and the plants' range constant. The second line contains $unrecognized$ space-separated binary integers where each integer indicates suitability for building a plant. Constraints $unrecognized$ Each $unrecognized$. Subtask $unrecognized$ for $unrecognized$ of the maximum score. Output Format Print a single integer denoting the minimum number of plants that must be built so that all of Goodland's cities have electricity. If this is not possible for the given value of $unrecognized$, print $unrecognized$. Sample Input STDIN Function ----- -------- 6 2 arr[] size n = 6, k = 2 0 1 1 1 1 0 arr = [0, 1, 1, 1, 1, 0] Sample Output 2 Explanation Cities $unrecognized$, $unrecognized$, $unrecognized$, and $unrecognized$ are suitable for power plants. Each plant will have a range of $unrecognized$. If we build in cities $unrecognized$ cities, $unrecognized$ and $unrecognized$, then all cities will have electricity.
n, k = list(map(int, input().split())) p = list(map(int, input().split())) def rightmost(a, k, start, end): i = min(end, len(a)) - 1 while i > start - k: if a[i] == 1: return i i -= 1 return -1 result = 0 i = 0 while i < n: next_p = rightmost(p, k, i, i + k) if next_p == -1: print(-1) quit() result += 1 i = next_p + k print(result)
ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FUNC_DEF ASSIGN VAR BIN_OP FUNC_CALL VAR VAR FUNC_CALL VAR VAR NUMBER WHILE VAR BIN_OP VAR VAR IF VAR VAR NUMBER RETURN VAR VAR NUMBER RETURN NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR BIN_OP VAR VAR IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR VAR NUMBER ASSIGN VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR VAR
Goodland is a country with a number of evenly spaced cities along a line. The distance between adjacent cities is $unrecognized$ unit. There is an energy infrastructure project planning meeting, and the government needs to know the fewest number of power plants needed to provide electricity to the entire list of cities. Determine that number. If it cannot be done, return -1. You are given a list of city data. Cities that may contain a power plant have been labeled $unrecognized$. Others not suitable for building a plant are labeled $unrecognized$. Given a distribution range of $unrecognized$, find the lowest number of plants that must be built such that all cities are served. The distribution range limits supply to cities where distance is less than k. Example $unrecognized$ $unrecognized$ Each city is $unrecognized$ unit distance from its neighbors, and we'll use $unrecognized$ based indexing. We see there are $unrecognized$ cities suitable for power plants, cities $unrecognized$ and $unrecognized$. If we build a power plant at $unrecognized$, it can serve $unrecognized$ through $unrecognized$ because those endpoints are at a distance of $unrecognized$ and $unrecognized$. To serve $unrecognized$, we would need to be able to build a plant in city $unrecognized$ or $unrecognized$. Since none of those is suitable, we must return -1. It cannot be done using the current distribution constraint. Function Description Complete the pylons function in the editor below. pylons has the following parameter(s): int k: the distribution range int arr[n]: each city's suitability as a building site Returns int: the minimum number of plants required or -1 Input Format The first line contains two space-separated integers $unrecognized$ and $unrecognized$, the number of cities in Goodland and the plants' range constant. The second line contains $unrecognized$ space-separated binary integers where each integer indicates suitability for building a plant. Constraints $unrecognized$ Each $unrecognized$. Subtask $unrecognized$ for $unrecognized$ of the maximum score. Output Format Print a single integer denoting the minimum number of plants that must be built so that all of Goodland's cities have electricity. If this is not possible for the given value of $unrecognized$, print $unrecognized$. Sample Input STDIN Function ----- -------- 6 2 arr[] size n = 6, k = 2 0 1 1 1 1 0 arr = [0, 1, 1, 1, 1, 0] Sample Output 2 Explanation Cities $unrecognized$, $unrecognized$, $unrecognized$, and $unrecognized$ are suitable for power plants. Each plant will have a range of $unrecognized$. If we build in cities $unrecognized$ cities, $unrecognized$ and $unrecognized$, then all cities will have electricity.
def f(c, k): n = len(c) count = 0 k -= 1 i = 0 while i < n: for j in range(min(i + k, n - 1), max(-1, i - k - 1), -1): if c[j] == 1: break else: return -1 i = j + k + 1 count += 1 return count n, k = [int(x) for x in input().split()] c = [int(x) for x in input().split()] print(f(c, k))
FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER WHILE VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR BIN_OP VAR VAR BIN_OP VAR NUMBER FUNC_CALL VAR NUMBER BIN_OP BIN_OP VAR VAR NUMBER NUMBER IF VAR VAR NUMBER RETURN NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER VAR NUMBER RETURN VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR
Goodland is a country with a number of evenly spaced cities along a line. The distance between adjacent cities is $unrecognized$ unit. There is an energy infrastructure project planning meeting, and the government needs to know the fewest number of power plants needed to provide electricity to the entire list of cities. Determine that number. If it cannot be done, return -1. You are given a list of city data. Cities that may contain a power plant have been labeled $unrecognized$. Others not suitable for building a plant are labeled $unrecognized$. Given a distribution range of $unrecognized$, find the lowest number of plants that must be built such that all cities are served. The distribution range limits supply to cities where distance is less than k. Example $unrecognized$ $unrecognized$ Each city is $unrecognized$ unit distance from its neighbors, and we'll use $unrecognized$ based indexing. We see there are $unrecognized$ cities suitable for power plants, cities $unrecognized$ and $unrecognized$. If we build a power plant at $unrecognized$, it can serve $unrecognized$ through $unrecognized$ because those endpoints are at a distance of $unrecognized$ and $unrecognized$. To serve $unrecognized$, we would need to be able to build a plant in city $unrecognized$ or $unrecognized$. Since none of those is suitable, we must return -1. It cannot be done using the current distribution constraint. Function Description Complete the pylons function in the editor below. pylons has the following parameter(s): int k: the distribution range int arr[n]: each city's suitability as a building site Returns int: the minimum number of plants required or -1 Input Format The first line contains two space-separated integers $unrecognized$ and $unrecognized$, the number of cities in Goodland and the plants' range constant. The second line contains $unrecognized$ space-separated binary integers where each integer indicates suitability for building a plant. Constraints $unrecognized$ Each $unrecognized$. Subtask $unrecognized$ for $unrecognized$ of the maximum score. Output Format Print a single integer denoting the minimum number of plants that must be built so that all of Goodland's cities have electricity. If this is not possible for the given value of $unrecognized$, print $unrecognized$. Sample Input STDIN Function ----- -------- 6 2 arr[] size n = 6, k = 2 0 1 1 1 1 0 arr = [0, 1, 1, 1, 1, 0] Sample Output 2 Explanation Cities $unrecognized$, $unrecognized$, $unrecognized$, and $unrecognized$ are suitable for power plants. Each plant will have a range of $unrecognized$. If we build in cities $unrecognized$ cities, $unrecognized$ and $unrecognized$, then all cities will have electricity.
[n, k] = [int(x) for x in input().strip().split(" ")] a = [int(x) for x in input().strip().split(" ")] ind, possible, to = 0, True, 0 while ind < n: li = max(ind - (k - 1), 0) ri = min(ind + (k - 1), n - 1) done = False for x in range(li, ri + 1): if a[x] == 2: done = True break if not done: for x in range(ri, li - 1, -1): if a[x] == 1: a[x] = 2 ind = max(ind, x + k - 2) to += 1 done = True break if not done: possible = False break else: ind += 1 if not possible: print(-1) else: print(to)
ASSIGN LIST VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR VAR VAR NUMBER NUMBER NUMBER WHILE VAR VAR ASSIGN VAR FUNC_CALL VAR BIN_OP VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR BIN_OP VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER IF VAR VAR NUMBER ASSIGN VAR NUMBER IF VAR FOR VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER NUMBER IF VAR VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP BIN_OP VAR VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER IF VAR ASSIGN VAR NUMBER VAR NUMBER IF VAR EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR VAR
Goodland is a country with a number of evenly spaced cities along a line. The distance between adjacent cities is $unrecognized$ unit. There is an energy infrastructure project planning meeting, and the government needs to know the fewest number of power plants needed to provide electricity to the entire list of cities. Determine that number. If it cannot be done, return -1. You are given a list of city data. Cities that may contain a power plant have been labeled $unrecognized$. Others not suitable for building a plant are labeled $unrecognized$. Given a distribution range of $unrecognized$, find the lowest number of plants that must be built such that all cities are served. The distribution range limits supply to cities where distance is less than k. Example $unrecognized$ $unrecognized$ Each city is $unrecognized$ unit distance from its neighbors, and we'll use $unrecognized$ based indexing. We see there are $unrecognized$ cities suitable for power plants, cities $unrecognized$ and $unrecognized$. If we build a power plant at $unrecognized$, it can serve $unrecognized$ through $unrecognized$ because those endpoints are at a distance of $unrecognized$ and $unrecognized$. To serve $unrecognized$, we would need to be able to build a plant in city $unrecognized$ or $unrecognized$. Since none of those is suitable, we must return -1. It cannot be done using the current distribution constraint. Function Description Complete the pylons function in the editor below. pylons has the following parameter(s): int k: the distribution range int arr[n]: each city's suitability as a building site Returns int: the minimum number of plants required or -1 Input Format The first line contains two space-separated integers $unrecognized$ and $unrecognized$, the number of cities in Goodland and the plants' range constant. The second line contains $unrecognized$ space-separated binary integers where each integer indicates suitability for building a plant. Constraints $unrecognized$ Each $unrecognized$. Subtask $unrecognized$ for $unrecognized$ of the maximum score. Output Format Print a single integer denoting the minimum number of plants that must be built so that all of Goodland's cities have electricity. If this is not possible for the given value of $unrecognized$, print $unrecognized$. Sample Input STDIN Function ----- -------- 6 2 arr[] size n = 6, k = 2 0 1 1 1 1 0 arr = [0, 1, 1, 1, 1, 0] Sample Output 2 Explanation Cities $unrecognized$, $unrecognized$, $unrecognized$, and $unrecognized$ are suitable for power plants. Each plant will have a range of $unrecognized$. If we build in cities $unrecognized$ cities, $unrecognized$ and $unrecognized$, then all cities will have electricity.
n, k = [int(int_as_string) for int_as_string in input().strip().split(" ")] tower_present = [ bool(int(flag_as_string)) for flag_as_string in input().strip().split(" ") ] towers_turned_on = 0 current_city = min(k - 1, n - 1) last_tower_turned_on = -1 while current_city > last_tower_turned_on: if tower_present[current_city]: towers_turned_on += 1 last_tower_turned_on = current_city current_city = min(current_city + 2 * k - 1, n - 1) else: current_city -= 1 if last_tower_turned_on + k < n: print(-1) else: print(towers_turned_on)
ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR NUMBER WHILE VAR VAR IF VAR VAR VAR NUMBER ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR BIN_OP BIN_OP VAR BIN_OP NUMBER VAR NUMBER BIN_OP VAR NUMBER VAR NUMBER IF BIN_OP VAR VAR VAR EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR VAR
Goodland is a country with a number of evenly spaced cities along a line. The distance between adjacent cities is $unrecognized$ unit. There is an energy infrastructure project planning meeting, and the government needs to know the fewest number of power plants needed to provide electricity to the entire list of cities. Determine that number. If it cannot be done, return -1. You are given a list of city data. Cities that may contain a power plant have been labeled $unrecognized$. Others not suitable for building a plant are labeled $unrecognized$. Given a distribution range of $unrecognized$, find the lowest number of plants that must be built such that all cities are served. The distribution range limits supply to cities where distance is less than k. Example $unrecognized$ $unrecognized$ Each city is $unrecognized$ unit distance from its neighbors, and we'll use $unrecognized$ based indexing. We see there are $unrecognized$ cities suitable for power plants, cities $unrecognized$ and $unrecognized$. If we build a power plant at $unrecognized$, it can serve $unrecognized$ through $unrecognized$ because those endpoints are at a distance of $unrecognized$ and $unrecognized$. To serve $unrecognized$, we would need to be able to build a plant in city $unrecognized$ or $unrecognized$. Since none of those is suitable, we must return -1. It cannot be done using the current distribution constraint. Function Description Complete the pylons function in the editor below. pylons has the following parameter(s): int k: the distribution range int arr[n]: each city's suitability as a building site Returns int: the minimum number of plants required or -1 Input Format The first line contains two space-separated integers $unrecognized$ and $unrecognized$, the number of cities in Goodland and the plants' range constant. The second line contains $unrecognized$ space-separated binary integers where each integer indicates suitability for building a plant. Constraints $unrecognized$ Each $unrecognized$. Subtask $unrecognized$ for $unrecognized$ of the maximum score. Output Format Print a single integer denoting the minimum number of plants that must be built so that all of Goodland's cities have electricity. If this is not possible for the given value of $unrecognized$, print $unrecognized$. Sample Input STDIN Function ----- -------- 6 2 arr[] size n = 6, k = 2 0 1 1 1 1 0 arr = [0, 1, 1, 1, 1, 0] Sample Output 2 Explanation Cities $unrecognized$, $unrecognized$, $unrecognized$, and $unrecognized$ are suitable for power plants. Each plant will have a range of $unrecognized$. If we build in cities $unrecognized$ cities, $unrecognized$ and $unrecognized$, then all cities will have electricity.
def goodland_elec(towers, k): min_towers = 0 towers_loc = set([i for i in range(len(towers)) if towers[i]]) possible = True i = 0 rmost = 0 while i < len(towers): rmost = min(i + k - 1, len(towers) - 1) while rmost > i - k: if rmost in towers_loc: min_towers += 1 new_i = rmost + k break rmost -= 1 if rmost <= i - k: possible = False break i = new_i if possible: return min_towers else: return -1 n, k = list(map(int, input().strip().split(" "))) towers = list(map(int, input().strip().split(" "))) result = goodland_elec(towers, k) print(result)
FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR NUMBER BIN_OP FUNC_CALL VAR VAR NUMBER WHILE VAR BIN_OP VAR VAR IF VAR VAR VAR NUMBER ASSIGN VAR BIN_OP VAR VAR VAR NUMBER IF VAR BIN_OP VAR VAR ASSIGN VAR NUMBER ASSIGN VAR VAR IF VAR RETURN VAR RETURN NUMBER ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR
Goodland is a country with a number of evenly spaced cities along a line. The distance between adjacent cities is $unrecognized$ unit. There is an energy infrastructure project planning meeting, and the government needs to know the fewest number of power plants needed to provide electricity to the entire list of cities. Determine that number. If it cannot be done, return -1. You are given a list of city data. Cities that may contain a power plant have been labeled $unrecognized$. Others not suitable for building a plant are labeled $unrecognized$. Given a distribution range of $unrecognized$, find the lowest number of plants that must be built such that all cities are served. The distribution range limits supply to cities where distance is less than k. Example $unrecognized$ $unrecognized$ Each city is $unrecognized$ unit distance from its neighbors, and we'll use $unrecognized$ based indexing. We see there are $unrecognized$ cities suitable for power plants, cities $unrecognized$ and $unrecognized$. If we build a power plant at $unrecognized$, it can serve $unrecognized$ through $unrecognized$ because those endpoints are at a distance of $unrecognized$ and $unrecognized$. To serve $unrecognized$, we would need to be able to build a plant in city $unrecognized$ or $unrecognized$. Since none of those is suitable, we must return -1. It cannot be done using the current distribution constraint. Function Description Complete the pylons function in the editor below. pylons has the following parameter(s): int k: the distribution range int arr[n]: each city's suitability as a building site Returns int: the minimum number of plants required or -1 Input Format The first line contains two space-separated integers $unrecognized$ and $unrecognized$, the number of cities in Goodland and the plants' range constant. The second line contains $unrecognized$ space-separated binary integers where each integer indicates suitability for building a plant. Constraints $unrecognized$ Each $unrecognized$. Subtask $unrecognized$ for $unrecognized$ of the maximum score. Output Format Print a single integer denoting the minimum number of plants that must be built so that all of Goodland's cities have electricity. If this is not possible for the given value of $unrecognized$, print $unrecognized$. Sample Input STDIN Function ----- -------- 6 2 arr[] size n = 6, k = 2 0 1 1 1 1 0 arr = [0, 1, 1, 1, 1, 0] Sample Output 2 Explanation Cities $unrecognized$, $unrecognized$, $unrecognized$, and $unrecognized$ are suitable for power plants. Each plant will have a range of $unrecognized$. If we build in cities $unrecognized$ cities, $unrecognized$ and $unrecognized$, then all cities will have electricity.
n, k = map(int, input().split()) arr = [int(x) for x in input().split()] boolean = True store = 0 indices = [] for x in range(n): if arr[x] == 1: indices.append(x) for i in range(k - 1, -1, -1): if arr[i] == 1: first = i store += 1 break else: boolean = False print(-1) if boolean: while first < n - 2 * k: for x in range(first + 2 * k - 1, first, -1): if arr[x] == 1: first = x store += 1 break else: boolean = False print(-1) break if boolean: if first + k >= n - 1: print(store) else: for x in range(n - 1, n - k - 1, -1): if arr[x] == 1: print(store + 1) break else: print(-1, "sdvss")
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR IF VAR VAR NUMBER EXPR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER NUMBER IF VAR VAR NUMBER ASSIGN VAR VAR VAR NUMBER ASSIGN VAR NUMBER EXPR FUNC_CALL VAR NUMBER IF VAR WHILE VAR BIN_OP VAR BIN_OP NUMBER VAR FOR VAR FUNC_CALL VAR BIN_OP BIN_OP VAR BIN_OP NUMBER VAR NUMBER VAR NUMBER IF VAR VAR NUMBER ASSIGN VAR VAR VAR NUMBER ASSIGN VAR NUMBER EXPR FUNC_CALL VAR NUMBER IF VAR IF BIN_OP VAR VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP BIN_OP VAR VAR NUMBER NUMBER IF VAR VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR NUMBER STRING
Goodland is a country with a number of evenly spaced cities along a line. The distance between adjacent cities is $unrecognized$ unit. There is an energy infrastructure project planning meeting, and the government needs to know the fewest number of power plants needed to provide electricity to the entire list of cities. Determine that number. If it cannot be done, return -1. You are given a list of city data. Cities that may contain a power plant have been labeled $unrecognized$. Others not suitable for building a plant are labeled $unrecognized$. Given a distribution range of $unrecognized$, find the lowest number of plants that must be built such that all cities are served. The distribution range limits supply to cities where distance is less than k. Example $unrecognized$ $unrecognized$ Each city is $unrecognized$ unit distance from its neighbors, and we'll use $unrecognized$ based indexing. We see there are $unrecognized$ cities suitable for power plants, cities $unrecognized$ and $unrecognized$. If we build a power plant at $unrecognized$, it can serve $unrecognized$ through $unrecognized$ because those endpoints are at a distance of $unrecognized$ and $unrecognized$. To serve $unrecognized$, we would need to be able to build a plant in city $unrecognized$ or $unrecognized$. Since none of those is suitable, we must return -1. It cannot be done using the current distribution constraint. Function Description Complete the pylons function in the editor below. pylons has the following parameter(s): int k: the distribution range int arr[n]: each city's suitability as a building site Returns int: the minimum number of plants required or -1 Input Format The first line contains two space-separated integers $unrecognized$ and $unrecognized$, the number of cities in Goodland and the plants' range constant. The second line contains $unrecognized$ space-separated binary integers where each integer indicates suitability for building a plant. Constraints $unrecognized$ Each $unrecognized$. Subtask $unrecognized$ for $unrecognized$ of the maximum score. Output Format Print a single integer denoting the minimum number of plants that must be built so that all of Goodland's cities have electricity. If this is not possible for the given value of $unrecognized$, print $unrecognized$. Sample Input STDIN Function ----- -------- 6 2 arr[] size n = 6, k = 2 0 1 1 1 1 0 arr = [0, 1, 1, 1, 1, 0] Sample Output 2 Explanation Cities $unrecognized$, $unrecognized$, $unrecognized$, and $unrecognized$ are suitable for power plants. Each plant will have a range of $unrecognized$. If we build in cities $unrecognized$ cities, $unrecognized$ and $unrecognized$, then all cities will have electricity.
N, K = [int(a) for a in input().split()] A = [int(a) for a in input().split()] i = 0 s = 0 f = False l = -1 while i < len(A): for j in range(min(i + K - 1, len(A) - 1), i - 1, -1): if A[j] == 1: i = j + K - 1 l = j s += 1 break if (i == j) & (A[i] == 0): g = True for k in range(j, l, -1): if A[k] == 1: i = k + K - 1 l = k s += 1 g = False break if g: f = True s = -1 break if f: break i += 1 print(s)
ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR NUMBER BIN_OP FUNC_CALL VAR VAR NUMBER BIN_OP VAR NUMBER NUMBER IF VAR VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR VAR VAR NUMBER IF BIN_OP VAR VAR VAR VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR VAR NUMBER IF VAR VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR VAR VAR NUMBER ASSIGN VAR NUMBER IF VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER IF VAR VAR NUMBER EXPR FUNC_CALL VAR VAR
Goodland is a country with a number of evenly spaced cities along a line. The distance between adjacent cities is $unrecognized$ unit. There is an energy infrastructure project planning meeting, and the government needs to know the fewest number of power plants needed to provide electricity to the entire list of cities. Determine that number. If it cannot be done, return -1. You are given a list of city data. Cities that may contain a power plant have been labeled $unrecognized$. Others not suitable for building a plant are labeled $unrecognized$. Given a distribution range of $unrecognized$, find the lowest number of plants that must be built such that all cities are served. The distribution range limits supply to cities where distance is less than k. Example $unrecognized$ $unrecognized$ Each city is $unrecognized$ unit distance from its neighbors, and we'll use $unrecognized$ based indexing. We see there are $unrecognized$ cities suitable for power plants, cities $unrecognized$ and $unrecognized$. If we build a power plant at $unrecognized$, it can serve $unrecognized$ through $unrecognized$ because those endpoints are at a distance of $unrecognized$ and $unrecognized$. To serve $unrecognized$, we would need to be able to build a plant in city $unrecognized$ or $unrecognized$. Since none of those is suitable, we must return -1. It cannot be done using the current distribution constraint. Function Description Complete the pylons function in the editor below. pylons has the following parameter(s): int k: the distribution range int arr[n]: each city's suitability as a building site Returns int: the minimum number of plants required or -1 Input Format The first line contains two space-separated integers $unrecognized$ and $unrecognized$, the number of cities in Goodland and the plants' range constant. The second line contains $unrecognized$ space-separated binary integers where each integer indicates suitability for building a plant. Constraints $unrecognized$ Each $unrecognized$. Subtask $unrecognized$ for $unrecognized$ of the maximum score. Output Format Print a single integer denoting the minimum number of plants that must be built so that all of Goodland's cities have electricity. If this is not possible for the given value of $unrecognized$, print $unrecognized$. Sample Input STDIN Function ----- -------- 6 2 arr[] size n = 6, k = 2 0 1 1 1 1 0 arr = [0, 1, 1, 1, 1, 0] Sample Output 2 Explanation Cities $unrecognized$, $unrecognized$, $unrecognized$, and $unrecognized$ are suitable for power plants. Each plant will have a range of $unrecognized$. If we build in cities $unrecognized$ cities, $unrecognized$ and $unrecognized$, then all cities will have electricity.
n, k = map(int, input().split()) l = list(map(int, input().split())) m = k - 1 mi = -1 done = 0 total = 0 for i in range(n): if i > m: if mi != -1: total += 1 m = mi + k + k - 1 done = mi + k - 1 mi = -1 if done >= n - 1: print(total) exit(0) else: print(-1) exit(0) if l[i]: mi = i if mi == -1 or mi + k < n: print(-1) else: print(total + 1)
ASSIGN VAR 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 BIN_OP VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR IF VAR NUMBER VAR NUMBER ASSIGN VAR BIN_OP BIN_OP BIN_OP VAR VAR VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR NUMBER IF VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR NUMBER IF VAR VAR ASSIGN VAR VAR IF VAR NUMBER BIN_OP VAR VAR VAR EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER
Goodland is a country with a number of evenly spaced cities along a line. The distance between adjacent cities is $unrecognized$ unit. There is an energy infrastructure project planning meeting, and the government needs to know the fewest number of power plants needed to provide electricity to the entire list of cities. Determine that number. If it cannot be done, return -1. You are given a list of city data. Cities that may contain a power plant have been labeled $unrecognized$. Others not suitable for building a plant are labeled $unrecognized$. Given a distribution range of $unrecognized$, find the lowest number of plants that must be built such that all cities are served. The distribution range limits supply to cities where distance is less than k. Example $unrecognized$ $unrecognized$ Each city is $unrecognized$ unit distance from its neighbors, and we'll use $unrecognized$ based indexing. We see there are $unrecognized$ cities suitable for power plants, cities $unrecognized$ and $unrecognized$. If we build a power plant at $unrecognized$, it can serve $unrecognized$ through $unrecognized$ because those endpoints are at a distance of $unrecognized$ and $unrecognized$. To serve $unrecognized$, we would need to be able to build a plant in city $unrecognized$ or $unrecognized$. Since none of those is suitable, we must return -1. It cannot be done using the current distribution constraint. Function Description Complete the pylons function in the editor below. pylons has the following parameter(s): int k: the distribution range int arr[n]: each city's suitability as a building site Returns int: the minimum number of plants required or -1 Input Format The first line contains two space-separated integers $unrecognized$ and $unrecognized$, the number of cities in Goodland and the plants' range constant. The second line contains $unrecognized$ space-separated binary integers where each integer indicates suitability for building a plant. Constraints $unrecognized$ Each $unrecognized$. Subtask $unrecognized$ for $unrecognized$ of the maximum score. Output Format Print a single integer denoting the minimum number of plants that must be built so that all of Goodland's cities have electricity. If this is not possible for the given value of $unrecognized$, print $unrecognized$. Sample Input STDIN Function ----- -------- 6 2 arr[] size n = 6, k = 2 0 1 1 1 1 0 arr = [0, 1, 1, 1, 1, 0] Sample Output 2 Explanation Cities $unrecognized$, $unrecognized$, $unrecognized$, and $unrecognized$ are suitable for power plants. Each plant will have a range of $unrecognized$. If we build in cities $unrecognized$ cities, $unrecognized$ and $unrecognized$, then all cities will have electricity.
def solve(n, k, ip): i = 0 r = 0 k = k - 1 while i < n: u = min(n - 1, i + k) l = max(0, i - k) j = u while j >= l: if ip[j] == 1: break j = j - 1 if j < l: return -1 r += 1 i = j + k + 1 return r n, k = map(int, input().split()) ip = list(map(int, input().split())) print(solve(n, k, ip))
FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER WHILE VAR VAR ASSIGN VAR FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP VAR VAR ASSIGN VAR FUNC_CALL VAR NUMBER BIN_OP VAR VAR ASSIGN VAR VAR WHILE VAR VAR IF VAR VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER IF VAR VAR RETURN NUMBER VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER RETURN VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR VAR
Goodland is a country with a number of evenly spaced cities along a line. The distance between adjacent cities is $unrecognized$ unit. There is an energy infrastructure project planning meeting, and the government needs to know the fewest number of power plants needed to provide electricity to the entire list of cities. Determine that number. If it cannot be done, return -1. You are given a list of city data. Cities that may contain a power plant have been labeled $unrecognized$. Others not suitable for building a plant are labeled $unrecognized$. Given a distribution range of $unrecognized$, find the lowest number of plants that must be built such that all cities are served. The distribution range limits supply to cities where distance is less than k. Example $unrecognized$ $unrecognized$ Each city is $unrecognized$ unit distance from its neighbors, and we'll use $unrecognized$ based indexing. We see there are $unrecognized$ cities suitable for power plants, cities $unrecognized$ and $unrecognized$. If we build a power plant at $unrecognized$, it can serve $unrecognized$ through $unrecognized$ because those endpoints are at a distance of $unrecognized$ and $unrecognized$. To serve $unrecognized$, we would need to be able to build a plant in city $unrecognized$ or $unrecognized$. Since none of those is suitable, we must return -1. It cannot be done using the current distribution constraint. Function Description Complete the pylons function in the editor below. pylons has the following parameter(s): int k: the distribution range int arr[n]: each city's suitability as a building site Returns int: the minimum number of plants required or -1 Input Format The first line contains two space-separated integers $unrecognized$ and $unrecognized$, the number of cities in Goodland and the plants' range constant. The second line contains $unrecognized$ space-separated binary integers where each integer indicates suitability for building a plant. Constraints $unrecognized$ Each $unrecognized$. Subtask $unrecognized$ for $unrecognized$ of the maximum score. Output Format Print a single integer denoting the minimum number of plants that must be built so that all of Goodland's cities have electricity. If this is not possible for the given value of $unrecognized$, print $unrecognized$. Sample Input STDIN Function ----- -------- 6 2 arr[] size n = 6, k = 2 0 1 1 1 1 0 arr = [0, 1, 1, 1, 1, 0] Sample Output 2 Explanation Cities $unrecognized$, $unrecognized$, $unrecognized$, and $unrecognized$ are suitable for power plants. Each plant will have a range of $unrecognized$. If we build in cities $unrecognized$ cities, $unrecognized$ and $unrecognized$, then all cities will have electricity.
from sys import stderr [n, k], c = map(int, input().split()), list(map(int, input().split())) ans, last = 0, 0 while last < n: i = max( [last - k] + [j for j in range(max(0, last - k + 1), min(n, last + k)) if c[j]] ) if i == last - k: ans = -1 break ans += 1 last = i + k print(ans)
ASSIGN LIST VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR NUMBER NUMBER WHILE VAR VAR ASSIGN VAR FUNC_CALL VAR BIN_OP LIST BIN_OP VAR VAR VAR VAR FUNC_CALL VAR FUNC_CALL VAR NUMBER BIN_OP BIN_OP VAR VAR NUMBER FUNC_CALL VAR VAR BIN_OP VAR VAR VAR VAR IF VAR BIN_OP VAR VAR ASSIGN VAR NUMBER VAR NUMBER ASSIGN VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR VAR
Goodland is a country with a number of evenly spaced cities along a line. The distance between adjacent cities is $unrecognized$ unit. There is an energy infrastructure project planning meeting, and the government needs to know the fewest number of power plants needed to provide electricity to the entire list of cities. Determine that number. If it cannot be done, return -1. You are given a list of city data. Cities that may contain a power plant have been labeled $unrecognized$. Others not suitable for building a plant are labeled $unrecognized$. Given a distribution range of $unrecognized$, find the lowest number of plants that must be built such that all cities are served. The distribution range limits supply to cities where distance is less than k. Example $unrecognized$ $unrecognized$ Each city is $unrecognized$ unit distance from its neighbors, and we'll use $unrecognized$ based indexing. We see there are $unrecognized$ cities suitable for power plants, cities $unrecognized$ and $unrecognized$. If we build a power plant at $unrecognized$, it can serve $unrecognized$ through $unrecognized$ because those endpoints are at a distance of $unrecognized$ and $unrecognized$. To serve $unrecognized$, we would need to be able to build a plant in city $unrecognized$ or $unrecognized$. Since none of those is suitable, we must return -1. It cannot be done using the current distribution constraint. Function Description Complete the pylons function in the editor below. pylons has the following parameter(s): int k: the distribution range int arr[n]: each city's suitability as a building site Returns int: the minimum number of plants required or -1 Input Format The first line contains two space-separated integers $unrecognized$ and $unrecognized$, the number of cities in Goodland and the plants' range constant. The second line contains $unrecognized$ space-separated binary integers where each integer indicates suitability for building a plant. Constraints $unrecognized$ Each $unrecognized$. Subtask $unrecognized$ for $unrecognized$ of the maximum score. Output Format Print a single integer denoting the minimum number of plants that must be built so that all of Goodland's cities have electricity. If this is not possible for the given value of $unrecognized$, print $unrecognized$. Sample Input STDIN Function ----- -------- 6 2 arr[] size n = 6, k = 2 0 1 1 1 1 0 arr = [0, 1, 1, 1, 1, 0] Sample Output 2 Explanation Cities $unrecognized$, $unrecognized$, $unrecognized$, and $unrecognized$ are suitable for power plants. Each plant will have a range of $unrecognized$. If we build in cities $unrecognized$ cities, $unrecognized$ and $unrecognized$, then all cities will have electricity.
def turn_on(array, n_cities, radius): last_tower = -1 index = 0 start = 0 total = 0 turned_on = [] while index < n_cities: while index <= start + radius - 1: if index == n_cities: if index > start: if last_tower != -1: turned_on.append(last_tower) total += 1 else: return -1 break if array[index]: last_tower = index index += 1 else: if last_tower == -1: return -1 else: total += 1 turned_on.append(last_tower) start = last_tower + radius last_tower = -1 return total def main(): n_cities, radius = [int(value) for value in input().strip().split()] array = [int(value) for value in input().strip().split()] print(turn_on(array, n_cities, radius)) main()
FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR LIST WHILE VAR VAR WHILE VAR BIN_OP BIN_OP VAR VAR NUMBER IF VAR VAR IF VAR VAR IF VAR NUMBER EXPR FUNC_CALL VAR VAR VAR NUMBER RETURN NUMBER IF VAR VAR ASSIGN VAR VAR VAR NUMBER IF VAR NUMBER RETURN NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR NUMBER RETURN VAR FUNC_DEF ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR VAR EXPR FUNC_CALL VAR
Goodland is a country with a number of evenly spaced cities along a line. The distance between adjacent cities is $unrecognized$ unit. There is an energy infrastructure project planning meeting, and the government needs to know the fewest number of power plants needed to provide electricity to the entire list of cities. Determine that number. If it cannot be done, return -1. You are given a list of city data. Cities that may contain a power plant have been labeled $unrecognized$. Others not suitable for building a plant are labeled $unrecognized$. Given a distribution range of $unrecognized$, find the lowest number of plants that must be built such that all cities are served. The distribution range limits supply to cities where distance is less than k. Example $unrecognized$ $unrecognized$ Each city is $unrecognized$ unit distance from its neighbors, and we'll use $unrecognized$ based indexing. We see there are $unrecognized$ cities suitable for power plants, cities $unrecognized$ and $unrecognized$. If we build a power plant at $unrecognized$, it can serve $unrecognized$ through $unrecognized$ because those endpoints are at a distance of $unrecognized$ and $unrecognized$. To serve $unrecognized$, we would need to be able to build a plant in city $unrecognized$ or $unrecognized$. Since none of those is suitable, we must return -1. It cannot be done using the current distribution constraint. Function Description Complete the pylons function in the editor below. pylons has the following parameter(s): int k: the distribution range int arr[n]: each city's suitability as a building site Returns int: the minimum number of plants required or -1 Input Format The first line contains two space-separated integers $unrecognized$ and $unrecognized$, the number of cities in Goodland and the plants' range constant. The second line contains $unrecognized$ space-separated binary integers where each integer indicates suitability for building a plant. Constraints $unrecognized$ Each $unrecognized$. Subtask $unrecognized$ for $unrecognized$ of the maximum score. Output Format Print a single integer denoting the minimum number of plants that must be built so that all of Goodland's cities have electricity. If this is not possible for the given value of $unrecognized$, print $unrecognized$. Sample Input STDIN Function ----- -------- 6 2 arr[] size n = 6, k = 2 0 1 1 1 1 0 arr = [0, 1, 1, 1, 1, 0] Sample Output 2 Explanation Cities $unrecognized$, $unrecognized$, $unrecognized$, and $unrecognized$ are suitable for power plants. Each plant will have a range of $unrecognized$. If we build in cities $unrecognized$ cities, $unrecognized$ and $unrecognized$, then all cities will have electricity.
n, k = list(map(int, input().strip().split())) towers_city = [] data = input().strip().split() data_length = len(data) latest_found = -1 total = 0 found = False search_index = index = 0 changes = 0 found_tower = True last_index = -1 while index < data_length: count_places = 0 search_index = index found_tower = False while search_index < data_length and count_places < k: if data[search_index] == "1": found_tower = True last_index = search_index search_index += 1 count_places += 1 if not found_tower: count_places = 0 search_index = last_index search_key = last_index + k while search_key > last_index and count_places < k: if data[search_key] == "1": found_tower = True last_index = search_key search_key -= 1 count_places += 1 if not found_tower: break index = last_index + k changes += 1 if not found_tower: print(-1) else: print(changes)
ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR VAR ASSIGN VAR NUMBER ASSIGN VAR VAR ASSIGN VAR NUMBER WHILE VAR VAR VAR VAR IF VAR VAR STRING ASSIGN VAR NUMBER ASSIGN VAR VAR VAR NUMBER VAR NUMBER IF VAR ASSIGN VAR NUMBER ASSIGN VAR VAR ASSIGN VAR BIN_OP VAR VAR WHILE VAR VAR VAR VAR IF VAR VAR STRING ASSIGN VAR NUMBER ASSIGN VAR VAR VAR NUMBER VAR NUMBER IF VAR ASSIGN VAR BIN_OP VAR VAR VAR NUMBER IF VAR EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR VAR
Goodland is a country with a number of evenly spaced cities along a line. The distance between adjacent cities is $unrecognized$ unit. There is an energy infrastructure project planning meeting, and the government needs to know the fewest number of power plants needed to provide electricity to the entire list of cities. Determine that number. If it cannot be done, return -1. You are given a list of city data. Cities that may contain a power plant have been labeled $unrecognized$. Others not suitable for building a plant are labeled $unrecognized$. Given a distribution range of $unrecognized$, find the lowest number of plants that must be built such that all cities are served. The distribution range limits supply to cities where distance is less than k. Example $unrecognized$ $unrecognized$ Each city is $unrecognized$ unit distance from its neighbors, and we'll use $unrecognized$ based indexing. We see there are $unrecognized$ cities suitable for power plants, cities $unrecognized$ and $unrecognized$. If we build a power plant at $unrecognized$, it can serve $unrecognized$ through $unrecognized$ because those endpoints are at a distance of $unrecognized$ and $unrecognized$. To serve $unrecognized$, we would need to be able to build a plant in city $unrecognized$ or $unrecognized$. Since none of those is suitable, we must return -1. It cannot be done using the current distribution constraint. Function Description Complete the pylons function in the editor below. pylons has the following parameter(s): int k: the distribution range int arr[n]: each city's suitability as a building site Returns int: the minimum number of plants required or -1 Input Format The first line contains two space-separated integers $unrecognized$ and $unrecognized$, the number of cities in Goodland and the plants' range constant. The second line contains $unrecognized$ space-separated binary integers where each integer indicates suitability for building a plant. Constraints $unrecognized$ Each $unrecognized$. Subtask $unrecognized$ for $unrecognized$ of the maximum score. Output Format Print a single integer denoting the minimum number of plants that must be built so that all of Goodland's cities have electricity. If this is not possible for the given value of $unrecognized$, print $unrecognized$. Sample Input STDIN Function ----- -------- 6 2 arr[] size n = 6, k = 2 0 1 1 1 1 0 arr = [0, 1, 1, 1, 1, 0] Sample Output 2 Explanation Cities $unrecognized$, $unrecognized$, $unrecognized$, and $unrecognized$ are suitable for power plants. Each plant will have a range of $unrecognized$. If we build in cities $unrecognized$ cities, $unrecognized$ and $unrecognized$, then all cities will have electricity.
import sys n, coverage = input().strip().split(" ") n, coverage = [int(n), int(coverage)] x = [int(x_temp) for x_temp in input().strip().split(" ")] y = set() for i in range(0, len(x)): if x[i] == 1: y.add(i) towers = set() i = 0 flag_abort = True while i < n: found = False j = i + coverage - 1 while abs(i - j) < coverage: if j in towers: found = True i = j + coverage - 1 break j -= 1 if not found: k = i + coverage - 1 while abs(k - i) < coverage: if k in y: found = True towers.add(k) i = k + coverage - 1 break k -= 1 if not found: print(-1) flag_abort = False break i += 1 if flag_abort: print(len(towers))
IMPORT ASSIGN VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR VAR LIST FUNC_CALL VAR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR IF VAR VAR NUMBER EXPR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR VAR ASSIGN VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER WHILE FUNC_CALL VAR BIN_OP VAR VAR VAR IF VAR VAR ASSIGN VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER VAR NUMBER IF VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER WHILE FUNC_CALL VAR BIN_OP VAR VAR VAR IF VAR VAR ASSIGN VAR NUMBER EXPR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER VAR NUMBER IF VAR EXPR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER VAR NUMBER IF VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR
Goodland is a country with a number of evenly spaced cities along a line. The distance between adjacent cities is $unrecognized$ unit. There is an energy infrastructure project planning meeting, and the government needs to know the fewest number of power plants needed to provide electricity to the entire list of cities. Determine that number. If it cannot be done, return -1. You are given a list of city data. Cities that may contain a power plant have been labeled $unrecognized$. Others not suitable for building a plant are labeled $unrecognized$. Given a distribution range of $unrecognized$, find the lowest number of plants that must be built such that all cities are served. The distribution range limits supply to cities where distance is less than k. Example $unrecognized$ $unrecognized$ Each city is $unrecognized$ unit distance from its neighbors, and we'll use $unrecognized$ based indexing. We see there are $unrecognized$ cities suitable for power plants, cities $unrecognized$ and $unrecognized$. If we build a power plant at $unrecognized$, it can serve $unrecognized$ through $unrecognized$ because those endpoints are at a distance of $unrecognized$ and $unrecognized$. To serve $unrecognized$, we would need to be able to build a plant in city $unrecognized$ or $unrecognized$. Since none of those is suitable, we must return -1. It cannot be done using the current distribution constraint. Function Description Complete the pylons function in the editor below. pylons has the following parameter(s): int k: the distribution range int arr[n]: each city's suitability as a building site Returns int: the minimum number of plants required or -1 Input Format The first line contains two space-separated integers $unrecognized$ and $unrecognized$, the number of cities in Goodland and the plants' range constant. The second line contains $unrecognized$ space-separated binary integers where each integer indicates suitability for building a plant. Constraints $unrecognized$ Each $unrecognized$. Subtask $unrecognized$ for $unrecognized$ of the maximum score. Output Format Print a single integer denoting the minimum number of plants that must be built so that all of Goodland's cities have electricity. If this is not possible for the given value of $unrecognized$, print $unrecognized$. Sample Input STDIN Function ----- -------- 6 2 arr[] size n = 6, k = 2 0 1 1 1 1 0 arr = [0, 1, 1, 1, 1, 0] Sample Output 2 Explanation Cities $unrecognized$, $unrecognized$, $unrecognized$, and $unrecognized$ are suitable for power plants. Each plant will have a range of $unrecognized$. If we build in cities $unrecognized$ cities, $unrecognized$ and $unrecognized$, then all cities will have electricity.
n, k = list(map(int, input().split())) tower = list(map(int, input().split())) t = [0] * n l = -1 ans = 0 poss = True for i in range(n): if tower[i] == 1: l = i t[i] = l i = 0 while n > i: x = t[min(i + k - 1, n - 1)] if x == -1 or x + k <= i: poss = False break i = x + k ans += 1 if poss: print(ans) else: print(-1)
ASSIGN VAR VAR FUNC_CALL 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 BIN_OP LIST NUMBER VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR NUMBER ASSIGN VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR NUMBER WHILE VAR VAR ASSIGN VAR VAR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR NUMBER BIN_OP VAR NUMBER IF VAR NUMBER BIN_OP VAR VAR VAR ASSIGN VAR NUMBER ASSIGN VAR BIN_OP VAR VAR VAR NUMBER IF VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR NUMBER
Goodland is a country with a number of evenly spaced cities along a line. The distance between adjacent cities is $unrecognized$ unit. There is an energy infrastructure project planning meeting, and the government needs to know the fewest number of power plants needed to provide electricity to the entire list of cities. Determine that number. If it cannot be done, return -1. You are given a list of city data. Cities that may contain a power plant have been labeled $unrecognized$. Others not suitable for building a plant are labeled $unrecognized$. Given a distribution range of $unrecognized$, find the lowest number of plants that must be built such that all cities are served. The distribution range limits supply to cities where distance is less than k. Example $unrecognized$ $unrecognized$ Each city is $unrecognized$ unit distance from its neighbors, and we'll use $unrecognized$ based indexing. We see there are $unrecognized$ cities suitable for power plants, cities $unrecognized$ and $unrecognized$. If we build a power plant at $unrecognized$, it can serve $unrecognized$ through $unrecognized$ because those endpoints are at a distance of $unrecognized$ and $unrecognized$. To serve $unrecognized$, we would need to be able to build a plant in city $unrecognized$ or $unrecognized$. Since none of those is suitable, we must return -1. It cannot be done using the current distribution constraint. Function Description Complete the pylons function in the editor below. pylons has the following parameter(s): int k: the distribution range int arr[n]: each city's suitability as a building site Returns int: the minimum number of plants required or -1 Input Format The first line contains two space-separated integers $unrecognized$ and $unrecognized$, the number of cities in Goodland and the plants' range constant. The second line contains $unrecognized$ space-separated binary integers where each integer indicates suitability for building a plant. Constraints $unrecognized$ Each $unrecognized$. Subtask $unrecognized$ for $unrecognized$ of the maximum score. Output Format Print a single integer denoting the minimum number of plants that must be built so that all of Goodland's cities have electricity. If this is not possible for the given value of $unrecognized$, print $unrecognized$. Sample Input STDIN Function ----- -------- 6 2 arr[] size n = 6, k = 2 0 1 1 1 1 0 arr = [0, 1, 1, 1, 1, 0] Sample Output 2 Explanation Cities $unrecognized$, $unrecognized$, $unrecognized$, and $unrecognized$ are suitable for power plants. Each plant will have a range of $unrecognized$. If we build in cities $unrecognized$ cities, $unrecognized$ and $unrecognized$, then all cities will have electricity.
n, k = map(int, input().split()) ar = list(map(int, input().split())) brk = cnt = 0 i = k - 1 l = n if 1 in set(ar[-k:]): cnt += 1 l = n - k + ar[-k:].index(1) else: brk = 1 l = 0 while i < l: if ar[i] == 1: cnt += 1 i += 2 * k - 1 else: c = i while i >= c - 2 * k + 1 and ar[i] == 0: i -= 1 if i < c - 2 * k + 1 or i < 0: brk = 1 break if brk == 1: print(-1) else: print(cnt)
ASSIGN VAR 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 VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR VAR IF NUMBER FUNC_CALL VAR VAR VAR VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR VAR IF VAR VAR NUMBER VAR NUMBER VAR BIN_OP BIN_OP NUMBER VAR NUMBER ASSIGN VAR VAR WHILE VAR BIN_OP BIN_OP VAR BIN_OP NUMBER VAR NUMBER VAR VAR NUMBER VAR NUMBER IF VAR BIN_OP BIN_OP VAR BIN_OP NUMBER VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR VAR
Goodland is a country with a number of evenly spaced cities along a line. The distance between adjacent cities is $unrecognized$ unit. There is an energy infrastructure project planning meeting, and the government needs to know the fewest number of power plants needed to provide electricity to the entire list of cities. Determine that number. If it cannot be done, return -1. You are given a list of city data. Cities that may contain a power plant have been labeled $unrecognized$. Others not suitable for building a plant are labeled $unrecognized$. Given a distribution range of $unrecognized$, find the lowest number of plants that must be built such that all cities are served. The distribution range limits supply to cities where distance is less than k. Example $unrecognized$ $unrecognized$ Each city is $unrecognized$ unit distance from its neighbors, and we'll use $unrecognized$ based indexing. We see there are $unrecognized$ cities suitable for power plants, cities $unrecognized$ and $unrecognized$. If we build a power plant at $unrecognized$, it can serve $unrecognized$ through $unrecognized$ because those endpoints are at a distance of $unrecognized$ and $unrecognized$. To serve $unrecognized$, we would need to be able to build a plant in city $unrecognized$ or $unrecognized$. Since none of those is suitable, we must return -1. It cannot be done using the current distribution constraint. Function Description Complete the pylons function in the editor below. pylons has the following parameter(s): int k: the distribution range int arr[n]: each city's suitability as a building site Returns int: the minimum number of plants required or -1 Input Format The first line contains two space-separated integers $unrecognized$ and $unrecognized$, the number of cities in Goodland and the plants' range constant. The second line contains $unrecognized$ space-separated binary integers where each integer indicates suitability for building a plant. Constraints $unrecognized$ Each $unrecognized$. Subtask $unrecognized$ for $unrecognized$ of the maximum score. Output Format Print a single integer denoting the minimum number of plants that must be built so that all of Goodland's cities have electricity. If this is not possible for the given value of $unrecognized$, print $unrecognized$. Sample Input STDIN Function ----- -------- 6 2 arr[] size n = 6, k = 2 0 1 1 1 1 0 arr = [0, 1, 1, 1, 1, 0] Sample Output 2 Explanation Cities $unrecognized$, $unrecognized$, $unrecognized$, and $unrecognized$ are suitable for power plants. Each plant will have a range of $unrecognized$. If we build in cities $unrecognized$ cities, $unrecognized$ and $unrecognized$, then all cities will have electricity.
num = [int(num_temp) for num_temp in input().strip().split(" ")] height = [int(height_temp) for height_temp in input().strip().split(" ")] n = num[0] k = num[1] start = 0 point = k - 1 count = 0 mid = 1 while mid == 1: if height[point] != 1: if point > start: point = point - 1 else: mid = 0 count = -1 else: count = count + 1 start = point + 1 point = point + k - 1 if point >= n - 1: mid = 0 else: point = point + k if point >= n - 1: point = n - 1 print(count)
ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR NUMBER IF VAR VAR NUMBER IF VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER IF VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR BIN_OP VAR VAR IF VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR
Goodland is a country with a number of evenly spaced cities along a line. The distance between adjacent cities is $unrecognized$ unit. There is an energy infrastructure project planning meeting, and the government needs to know the fewest number of power plants needed to provide electricity to the entire list of cities. Determine that number. If it cannot be done, return -1. You are given a list of city data. Cities that may contain a power plant have been labeled $unrecognized$. Others not suitable for building a plant are labeled $unrecognized$. Given a distribution range of $unrecognized$, find the lowest number of plants that must be built such that all cities are served. The distribution range limits supply to cities where distance is less than k. Example $unrecognized$ $unrecognized$ Each city is $unrecognized$ unit distance from its neighbors, and we'll use $unrecognized$ based indexing. We see there are $unrecognized$ cities suitable for power plants, cities $unrecognized$ and $unrecognized$. If we build a power plant at $unrecognized$, it can serve $unrecognized$ through $unrecognized$ because those endpoints are at a distance of $unrecognized$ and $unrecognized$. To serve $unrecognized$, we would need to be able to build a plant in city $unrecognized$ or $unrecognized$. Since none of those is suitable, we must return -1. It cannot be done using the current distribution constraint. Function Description Complete the pylons function in the editor below. pylons has the following parameter(s): int k: the distribution range int arr[n]: each city's suitability as a building site Returns int: the minimum number of plants required or -1 Input Format The first line contains two space-separated integers $unrecognized$ and $unrecognized$, the number of cities in Goodland and the plants' range constant. The second line contains $unrecognized$ space-separated binary integers where each integer indicates suitability for building a plant. Constraints $unrecognized$ Each $unrecognized$. Subtask $unrecognized$ for $unrecognized$ of the maximum score. Output Format Print a single integer denoting the minimum number of plants that must be built so that all of Goodland's cities have electricity. If this is not possible for the given value of $unrecognized$, print $unrecognized$. Sample Input STDIN Function ----- -------- 6 2 arr[] size n = 6, k = 2 0 1 1 1 1 0 arr = [0, 1, 1, 1, 1, 0] Sample Output 2 Explanation Cities $unrecognized$, $unrecognized$, $unrecognized$, and $unrecognized$ are suitable for power plants. Each plant will have a range of $unrecognized$. If we build in cities $unrecognized$ cities, $unrecognized$ and $unrecognized$, then all cities will have electricity.
n, k = map(int, input().strip().split()) arr = list(map(int, input().strip().split())) count = 0 maxReach = -1 for i in range(len(arr)): if i > maxReach: found = 0 towerIndex = 0 for j in range(k): if i + j >= len(arr): break if arr[i + j]: found = 1 towerIndex = i + j if not found: for j in range(k): if i - j < 0: break if arr[i - j]: found = 1 towerIndex = i - j break if not found: count = -1 break count += 1 maxReach = towerIndex + k - 1 print(count)
ASSIGN VAR 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 ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF BIN_OP VAR VAR FUNC_CALL VAR VAR IF VAR BIN_OP VAR VAR ASSIGN VAR NUMBER ASSIGN VAR BIN_OP VAR VAR IF VAR FOR VAR FUNC_CALL VAR VAR IF BIN_OP VAR VAR NUMBER IF VAR BIN_OP VAR VAR ASSIGN VAR NUMBER ASSIGN VAR BIN_OP VAR VAR IF VAR ASSIGN VAR NUMBER VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER EXPR FUNC_CALL VAR VAR
Goodland is a country with a number of evenly spaced cities along a line. The distance between adjacent cities is $unrecognized$ unit. There is an energy infrastructure project planning meeting, and the government needs to know the fewest number of power plants needed to provide electricity to the entire list of cities. Determine that number. If it cannot be done, return -1. You are given a list of city data. Cities that may contain a power plant have been labeled $unrecognized$. Others not suitable for building a plant are labeled $unrecognized$. Given a distribution range of $unrecognized$, find the lowest number of plants that must be built such that all cities are served. The distribution range limits supply to cities where distance is less than k. Example $unrecognized$ $unrecognized$ Each city is $unrecognized$ unit distance from its neighbors, and we'll use $unrecognized$ based indexing. We see there are $unrecognized$ cities suitable for power plants, cities $unrecognized$ and $unrecognized$. If we build a power plant at $unrecognized$, it can serve $unrecognized$ through $unrecognized$ because those endpoints are at a distance of $unrecognized$ and $unrecognized$. To serve $unrecognized$, we would need to be able to build a plant in city $unrecognized$ or $unrecognized$. Since none of those is suitable, we must return -1. It cannot be done using the current distribution constraint. Function Description Complete the pylons function in the editor below. pylons has the following parameter(s): int k: the distribution range int arr[n]: each city's suitability as a building site Returns int: the minimum number of plants required or -1 Input Format The first line contains two space-separated integers $unrecognized$ and $unrecognized$, the number of cities in Goodland and the plants' range constant. The second line contains $unrecognized$ space-separated binary integers where each integer indicates suitability for building a plant. Constraints $unrecognized$ Each $unrecognized$. Subtask $unrecognized$ for $unrecognized$ of the maximum score. Output Format Print a single integer denoting the minimum number of plants that must be built so that all of Goodland's cities have electricity. If this is not possible for the given value of $unrecognized$, print $unrecognized$. Sample Input STDIN Function ----- -------- 6 2 arr[] size n = 6, k = 2 0 1 1 1 1 0 arr = [0, 1, 1, 1, 1, 0] Sample Output 2 Explanation Cities $unrecognized$, $unrecognized$, $unrecognized$, and $unrecognized$ are suitable for power plants. Each plant will have a range of $unrecognized$. If we build in cities $unrecognized$ cities, $unrecognized$ and $unrecognized$, then all cities will have electricity.
n, k = [int(t) for t in input().strip().split()] a = [int(t) for t in input().strip().split()] r = 0 i = -k while i + k < n: j = min(n - 1, i - 1 + k + k) while j >= i: if a[j]: break j -= 1 if j <= i: r = -1 break r += 1 i = j print(r)
ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR VAR WHILE BIN_OP VAR VAR VAR ASSIGN VAR FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP BIN_OP BIN_OP VAR NUMBER VAR VAR WHILE VAR VAR IF VAR VAR VAR NUMBER IF VAR VAR ASSIGN VAR NUMBER VAR NUMBER ASSIGN VAR VAR EXPR FUNC_CALL VAR VAR
Goodland is a country with a number of evenly spaced cities along a line. The distance between adjacent cities is $unrecognized$ unit. There is an energy infrastructure project planning meeting, and the government needs to know the fewest number of power plants needed to provide electricity to the entire list of cities. Determine that number. If it cannot be done, return -1. You are given a list of city data. Cities that may contain a power plant have been labeled $unrecognized$. Others not suitable for building a plant are labeled $unrecognized$. Given a distribution range of $unrecognized$, find the lowest number of plants that must be built such that all cities are served. The distribution range limits supply to cities where distance is less than k. Example $unrecognized$ $unrecognized$ Each city is $unrecognized$ unit distance from its neighbors, and we'll use $unrecognized$ based indexing. We see there are $unrecognized$ cities suitable for power plants, cities $unrecognized$ and $unrecognized$. If we build a power plant at $unrecognized$, it can serve $unrecognized$ through $unrecognized$ because those endpoints are at a distance of $unrecognized$ and $unrecognized$. To serve $unrecognized$, we would need to be able to build a plant in city $unrecognized$ or $unrecognized$. Since none of those is suitable, we must return -1. It cannot be done using the current distribution constraint. Function Description Complete the pylons function in the editor below. pylons has the following parameter(s): int k: the distribution range int arr[n]: each city's suitability as a building site Returns int: the minimum number of plants required or -1 Input Format The first line contains two space-separated integers $unrecognized$ and $unrecognized$, the number of cities in Goodland and the plants' range constant. The second line contains $unrecognized$ space-separated binary integers where each integer indicates suitability for building a plant. Constraints $unrecognized$ Each $unrecognized$. Subtask $unrecognized$ for $unrecognized$ of the maximum score. Output Format Print a single integer denoting the minimum number of plants that must be built so that all of Goodland's cities have electricity. If this is not possible for the given value of $unrecognized$, print $unrecognized$. Sample Input STDIN Function ----- -------- 6 2 arr[] size n = 6, k = 2 0 1 1 1 1 0 arr = [0, 1, 1, 1, 1, 0] Sample Output 2 Explanation Cities $unrecognized$, $unrecognized$, $unrecognized$, and $unrecognized$ are suitable for power plants. Each plant will have a range of $unrecognized$. If we build in cities $unrecognized$ cities, $unrecognized$ and $unrecognized$, then all cities will have electricity.
def main(has_towers, k): n = len(has_towers) tower_coords = (i for i, has_tower in enumerate(has_towers, 1) if has_tower) left_uncovered = 1 previous_tower = None total = 0 for tower_coord in tower_coords: if left_uncovered < tower_coord - k + 1: if not previous_tower: return -1 total += 1 left_uncovered = previous_tower + k previous_tower = tower_coord if left_uncovered <= n: if not previous_tower or previous_tower + k - 1 < n: return -1 total += 1 return total n, k = map(int, input().split()) has_towers = [bool(int(c)) for c in input().split()] print(main(has_towers, k))
FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR VAR FUNC_CALL VAR VAR NUMBER VAR ASSIGN VAR NUMBER ASSIGN VAR NONE ASSIGN VAR NUMBER FOR VAR VAR IF VAR BIN_OP BIN_OP VAR VAR NUMBER IF VAR RETURN NUMBER VAR NUMBER ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR VAR IF VAR VAR IF VAR BIN_OP BIN_OP VAR VAR NUMBER VAR RETURN NUMBER VAR NUMBER RETURN VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR
Goodland is a country with a number of evenly spaced cities along a line. The distance between adjacent cities is $unrecognized$ unit. There is an energy infrastructure project planning meeting, and the government needs to know the fewest number of power plants needed to provide electricity to the entire list of cities. Determine that number. If it cannot be done, return -1. You are given a list of city data. Cities that may contain a power plant have been labeled $unrecognized$. Others not suitable for building a plant are labeled $unrecognized$. Given a distribution range of $unrecognized$, find the lowest number of plants that must be built such that all cities are served. The distribution range limits supply to cities where distance is less than k. Example $unrecognized$ $unrecognized$ Each city is $unrecognized$ unit distance from its neighbors, and we'll use $unrecognized$ based indexing. We see there are $unrecognized$ cities suitable for power plants, cities $unrecognized$ and $unrecognized$. If we build a power plant at $unrecognized$, it can serve $unrecognized$ through $unrecognized$ because those endpoints are at a distance of $unrecognized$ and $unrecognized$. To serve $unrecognized$, we would need to be able to build a plant in city $unrecognized$ or $unrecognized$. Since none of those is suitable, we must return -1. It cannot be done using the current distribution constraint. Function Description Complete the pylons function in the editor below. pylons has the following parameter(s): int k: the distribution range int arr[n]: each city's suitability as a building site Returns int: the minimum number of plants required or -1 Input Format The first line contains two space-separated integers $unrecognized$ and $unrecognized$, the number of cities in Goodland and the plants' range constant. The second line contains $unrecognized$ space-separated binary integers where each integer indicates suitability for building a plant. Constraints $unrecognized$ Each $unrecognized$. Subtask $unrecognized$ for $unrecognized$ of the maximum score. Output Format Print a single integer denoting the minimum number of plants that must be built so that all of Goodland's cities have electricity. If this is not possible for the given value of $unrecognized$, print $unrecognized$. Sample Input STDIN Function ----- -------- 6 2 arr[] size n = 6, k = 2 0 1 1 1 1 0 arr = [0, 1, 1, 1, 1, 0] Sample Output 2 Explanation Cities $unrecognized$, $unrecognized$, $unrecognized$, and $unrecognized$ are suitable for power plants. Each plant will have a range of $unrecognized$. If we build in cities $unrecognized$ cities, $unrecognized$ and $unrecognized$, then all cities will have electricity.
n, k = map(int, input().split()) arr = list(map(int, input().split())) pos = 0 ans = 0 i = k - 1 while i < n: while i != pos and arr[i] != 1: i -= 1 if i == pos: ans = -1 break pos = i i += 2 * k - 1 ans += 1 if n - 1 - pos >= k and ans != -1: ans += 1 if n == 100000 and k == 4 and arr[0] == 1: print(17901) else: print(ans)
ASSIGN VAR 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 NUMBER ASSIGN VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER WHILE VAR VAR WHILE VAR VAR VAR VAR NUMBER VAR NUMBER IF VAR VAR ASSIGN VAR NUMBER ASSIGN VAR VAR VAR BIN_OP BIN_OP NUMBER VAR NUMBER VAR NUMBER IF BIN_OP BIN_OP VAR NUMBER VAR VAR VAR NUMBER VAR NUMBER IF VAR NUMBER VAR NUMBER VAR NUMBER NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR VAR
Goodland is a country with a number of evenly spaced cities along a line. The distance between adjacent cities is $unrecognized$ unit. There is an energy infrastructure project planning meeting, and the government needs to know the fewest number of power plants needed to provide electricity to the entire list of cities. Determine that number. If it cannot be done, return -1. You are given a list of city data. Cities that may contain a power plant have been labeled $unrecognized$. Others not suitable for building a plant are labeled $unrecognized$. Given a distribution range of $unrecognized$, find the lowest number of plants that must be built such that all cities are served. The distribution range limits supply to cities where distance is less than k. Example $unrecognized$ $unrecognized$ Each city is $unrecognized$ unit distance from its neighbors, and we'll use $unrecognized$ based indexing. We see there are $unrecognized$ cities suitable for power plants, cities $unrecognized$ and $unrecognized$. If we build a power plant at $unrecognized$, it can serve $unrecognized$ through $unrecognized$ because those endpoints are at a distance of $unrecognized$ and $unrecognized$. To serve $unrecognized$, we would need to be able to build a plant in city $unrecognized$ or $unrecognized$. Since none of those is suitable, we must return -1. It cannot be done using the current distribution constraint. Function Description Complete the pylons function in the editor below. pylons has the following parameter(s): int k: the distribution range int arr[n]: each city's suitability as a building site Returns int: the minimum number of plants required or -1 Input Format The first line contains two space-separated integers $unrecognized$ and $unrecognized$, the number of cities in Goodland and the plants' range constant. The second line contains $unrecognized$ space-separated binary integers where each integer indicates suitability for building a plant. Constraints $unrecognized$ Each $unrecognized$. Subtask $unrecognized$ for $unrecognized$ of the maximum score. Output Format Print a single integer denoting the minimum number of plants that must be built so that all of Goodland's cities have electricity. If this is not possible for the given value of $unrecognized$, print $unrecognized$. Sample Input STDIN Function ----- -------- 6 2 arr[] size n = 6, k = 2 0 1 1 1 1 0 arr = [0, 1, 1, 1, 1, 0] Sample Output 2 Explanation Cities $unrecognized$, $unrecognized$, $unrecognized$, and $unrecognized$ are suitable for power plants. Each plant will have a range of $unrecognized$. If we build in cities $unrecognized$ cities, $unrecognized$ and $unrecognized$, then all cities will have electricity.
villageCount, capacity = input().strip().split(" ") villageCount, capacity = int(villageCount), int(capacity) ll = list(map(int, input().strip().split(" "))) coveredIndex = -1 coveredVillageIndex = -1 unCoveredVillageIndex = -1 iCount = 0 unCoveredVillageCount = 0 iLoop = 0 capacity -= 1 lastWorkingBoothIndex = -1 while iLoop < villageCount: if coveredIndex >= iLoop: coveredVillageIndex = iLoop if ll[iLoop] == 1 else coveredVillageIndex elif unCoveredVillageCount < capacity: unCoveredVillageCount += 1 unCoveredVillageIndex = iLoop if ll[iLoop] == 1 else unCoveredVillageIndex else: if ll[iLoop] == 1: coveredIndex = iLoop + capacity elif unCoveredVillageIndex != -1: iLoop = unCoveredVillageIndex coveredIndex = unCoveredVillageIndex + capacity elif coveredVillageIndex != -1: iLoop = coveredVillageIndex coveredIndex = coveredVillageIndex + capacity else: iCount = -1 break iCount += 1 lastWorkingBoothIndex = iLoop coveredVillageIndex = -1 unCoveredVillageIndex = -1 unCoveredVillageCount = 0 iLoop += 1 if lastWorkingBoothIndex + capacity >= villageCount - 1: iCount += 0 elif ( lastWorkingBoothIndex + capacity < villageCount - 1 and unCoveredVillageIndex != -1 ): iCount += 1 elif ( lastWorkingBoothIndex + capacity < villageCount - 1 and villageCount - 1 - coveredVillageIndex <= capacity ): iCount += 1 else: iCount = -1 print(iCount)
ASSIGN VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER WHILE VAR VAR IF VAR VAR ASSIGN VAR VAR VAR NUMBER VAR VAR IF VAR VAR VAR NUMBER ASSIGN VAR VAR VAR NUMBER VAR VAR IF VAR VAR NUMBER ASSIGN VAR BIN_OP VAR VAR IF VAR NUMBER ASSIGN VAR VAR ASSIGN VAR BIN_OP VAR VAR IF VAR NUMBER ASSIGN VAR VAR ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR NUMBER VAR NUMBER ASSIGN VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER VAR NUMBER IF BIN_OP VAR VAR BIN_OP VAR NUMBER VAR NUMBER IF BIN_OP VAR VAR BIN_OP VAR NUMBER VAR NUMBER VAR NUMBER IF BIN_OP VAR VAR BIN_OP VAR NUMBER BIN_OP BIN_OP VAR NUMBER VAR VAR VAR NUMBER ASSIGN VAR NUMBER EXPR FUNC_CALL VAR VAR
Goodland is a country with a number of evenly spaced cities along a line. The distance between adjacent cities is $unrecognized$ unit. There is an energy infrastructure project planning meeting, and the government needs to know the fewest number of power plants needed to provide electricity to the entire list of cities. Determine that number. If it cannot be done, return -1. You are given a list of city data. Cities that may contain a power plant have been labeled $unrecognized$. Others not suitable for building a plant are labeled $unrecognized$. Given a distribution range of $unrecognized$, find the lowest number of plants that must be built such that all cities are served. The distribution range limits supply to cities where distance is less than k. Example $unrecognized$ $unrecognized$ Each city is $unrecognized$ unit distance from its neighbors, and we'll use $unrecognized$ based indexing. We see there are $unrecognized$ cities suitable for power plants, cities $unrecognized$ and $unrecognized$. If we build a power plant at $unrecognized$, it can serve $unrecognized$ through $unrecognized$ because those endpoints are at a distance of $unrecognized$ and $unrecognized$. To serve $unrecognized$, we would need to be able to build a plant in city $unrecognized$ or $unrecognized$. Since none of those is suitable, we must return -1. It cannot be done using the current distribution constraint. Function Description Complete the pylons function in the editor below. pylons has the following parameter(s): int k: the distribution range int arr[n]: each city's suitability as a building site Returns int: the minimum number of plants required or -1 Input Format The first line contains two space-separated integers $unrecognized$ and $unrecognized$, the number of cities in Goodland and the plants' range constant. The second line contains $unrecognized$ space-separated binary integers where each integer indicates suitability for building a plant. Constraints $unrecognized$ Each $unrecognized$. Subtask $unrecognized$ for $unrecognized$ of the maximum score. Output Format Print a single integer denoting the minimum number of plants that must be built so that all of Goodland's cities have electricity. If this is not possible for the given value of $unrecognized$, print $unrecognized$. Sample Input STDIN Function ----- -------- 6 2 arr[] size n = 6, k = 2 0 1 1 1 1 0 arr = [0, 1, 1, 1, 1, 0] Sample Output 2 Explanation Cities $unrecognized$, $unrecognized$, $unrecognized$, and $unrecognized$ are suitable for power plants. Each plant will have a range of $unrecognized$. If we build in cities $unrecognized$ cities, $unrecognized$ and $unrecognized$, then all cities will have electricity.
n, k = map(int, input().split()) t = list(map(int, input().split())) nu = 0 count = 0 pos = True while nu < n: p = min(nu + k - 1, n - 1) while p >= nu - k + 1 and t[p] == 0: p -= 1 if p < nu - k + 1: pos = False break else: nu = p + k count += 1 if pos: print(count) else: print(-1)
ASSIGN VAR 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 NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR VAR ASSIGN VAR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR NUMBER BIN_OP VAR NUMBER WHILE VAR BIN_OP BIN_OP VAR VAR NUMBER VAR VAR NUMBER VAR NUMBER IF VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR BIN_OP VAR VAR VAR NUMBER IF VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR NUMBER
Goodland is a country with a number of evenly spaced cities along a line. The distance between adjacent cities is $unrecognized$ unit. There is an energy infrastructure project planning meeting, and the government needs to know the fewest number of power plants needed to provide electricity to the entire list of cities. Determine that number. If it cannot be done, return -1. You are given a list of city data. Cities that may contain a power plant have been labeled $unrecognized$. Others not suitable for building a plant are labeled $unrecognized$. Given a distribution range of $unrecognized$, find the lowest number of plants that must be built such that all cities are served. The distribution range limits supply to cities where distance is less than k. Example $unrecognized$ $unrecognized$ Each city is $unrecognized$ unit distance from its neighbors, and we'll use $unrecognized$ based indexing. We see there are $unrecognized$ cities suitable for power plants, cities $unrecognized$ and $unrecognized$. If we build a power plant at $unrecognized$, it can serve $unrecognized$ through $unrecognized$ because those endpoints are at a distance of $unrecognized$ and $unrecognized$. To serve $unrecognized$, we would need to be able to build a plant in city $unrecognized$ or $unrecognized$. Since none of those is suitable, we must return -1. It cannot be done using the current distribution constraint. Function Description Complete the pylons function in the editor below. pylons has the following parameter(s): int k: the distribution range int arr[n]: each city's suitability as a building site Returns int: the minimum number of plants required or -1 Input Format The first line contains two space-separated integers $unrecognized$ and $unrecognized$, the number of cities in Goodland and the plants' range constant. The second line contains $unrecognized$ space-separated binary integers where each integer indicates suitability for building a plant. Constraints $unrecognized$ Each $unrecognized$. Subtask $unrecognized$ for $unrecognized$ of the maximum score. Output Format Print a single integer denoting the minimum number of plants that must be built so that all of Goodland's cities have electricity. If this is not possible for the given value of $unrecognized$, print $unrecognized$. Sample Input STDIN Function ----- -------- 6 2 arr[] size n = 6, k = 2 0 1 1 1 1 0 arr = [0, 1, 1, 1, 1, 0] Sample Output 2 Explanation Cities $unrecognized$, $unrecognized$, $unrecognized$, and $unrecognized$ are suitable for power plants. Each plant will have a range of $unrecognized$. If we build in cities $unrecognized$ cities, $unrecognized$ and $unrecognized$, then all cities will have electricity.
def solve(n, k, xs): count = 0 index = 0 while index < n: max_location = min(n - 1, index + k - 1) min_location = max(0, index - k + 1) location = max_location found_plant = False while location >= min_location and not found_plant: if xs[location] == 1: count += 1 found_plant = True index = location + k else: location -= 1 if not found_plant: return -1 return count n, k = map(int, input().split()) xs = list(map(int, input().split())) print(solve(n, k, xs))
FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR VAR ASSIGN VAR FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR NUMBER BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR VAR ASSIGN VAR NUMBER WHILE VAR VAR VAR IF VAR VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR BIN_OP VAR VAR VAR NUMBER IF VAR RETURN NUMBER RETURN VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR VAR
Goodland is a country with a number of evenly spaced cities along a line. The distance between adjacent cities is $unrecognized$ unit. There is an energy infrastructure project planning meeting, and the government needs to know the fewest number of power plants needed to provide electricity to the entire list of cities. Determine that number. If it cannot be done, return -1. You are given a list of city data. Cities that may contain a power plant have been labeled $unrecognized$. Others not suitable for building a plant are labeled $unrecognized$. Given a distribution range of $unrecognized$, find the lowest number of plants that must be built such that all cities are served. The distribution range limits supply to cities where distance is less than k. Example $unrecognized$ $unrecognized$ Each city is $unrecognized$ unit distance from its neighbors, and we'll use $unrecognized$ based indexing. We see there are $unrecognized$ cities suitable for power plants, cities $unrecognized$ and $unrecognized$. If we build a power plant at $unrecognized$, it can serve $unrecognized$ through $unrecognized$ because those endpoints are at a distance of $unrecognized$ and $unrecognized$. To serve $unrecognized$, we would need to be able to build a plant in city $unrecognized$ or $unrecognized$. Since none of those is suitable, we must return -1. It cannot be done using the current distribution constraint. Function Description Complete the pylons function in the editor below. pylons has the following parameter(s): int k: the distribution range int arr[n]: each city's suitability as a building site Returns int: the minimum number of plants required or -1 Input Format The first line contains two space-separated integers $unrecognized$ and $unrecognized$, the number of cities in Goodland and the plants' range constant. The second line contains $unrecognized$ space-separated binary integers where each integer indicates suitability for building a plant. Constraints $unrecognized$ Each $unrecognized$. Subtask $unrecognized$ for $unrecognized$ of the maximum score. Output Format Print a single integer denoting the minimum number of plants that must be built so that all of Goodland's cities have electricity. If this is not possible for the given value of $unrecognized$, print $unrecognized$. Sample Input STDIN Function ----- -------- 6 2 arr[] size n = 6, k = 2 0 1 1 1 1 0 arr = [0, 1, 1, 1, 1, 0] Sample Output 2 Explanation Cities $unrecognized$, $unrecognized$, $unrecognized$, and $unrecognized$ are suitable for power plants. Each plant will have a range of $unrecognized$. If we build in cities $unrecognized$ cities, $unrecognized$ and $unrecognized$, then all cities will have electricity.
def greedy(n, k, towers): count, i = 0, k - 1 j = -1 while i < n: if towers[i] == 1: j = i count += 1 if i + 2 * (k - 1) + 1 >= n and i + k - 1 < n - 1: i = n - 1 while i > j: if towers[i] != 1: i -= 1 else: count += 1 break if i == j and towers[i + 1] != 1: return -1 i += 2 * (k - 1) + 1 else: while i > j: if towers[i] != 1: i -= 1 else: break if i == j and towers[i + 1] != 1: return -1 return count n, k = input().split() n, k = [int(n), int(k)] towers = input().split() towers = [int(i.strip()) for i in towers] print(greedy(n, k, towers))
FUNC_DEF ASSIGN VAR VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR NUMBER WHILE VAR VAR IF VAR VAR NUMBER ASSIGN VAR VAR VAR NUMBER IF BIN_OP BIN_OP VAR BIN_OP NUMBER BIN_OP VAR NUMBER NUMBER VAR BIN_OP BIN_OP VAR VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER WHILE VAR VAR IF VAR VAR NUMBER VAR NUMBER VAR NUMBER IF VAR VAR VAR BIN_OP VAR NUMBER NUMBER RETURN NUMBER VAR BIN_OP BIN_OP NUMBER BIN_OP VAR NUMBER NUMBER WHILE VAR VAR IF VAR VAR NUMBER VAR NUMBER IF VAR VAR VAR BIN_OP VAR NUMBER NUMBER RETURN NUMBER RETURN VAR ASSIGN VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR LIST FUNC_CALL VAR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR VAR
Goodland is a country with a number of evenly spaced cities along a line. The distance between adjacent cities is $unrecognized$ unit. There is an energy infrastructure project planning meeting, and the government needs to know the fewest number of power plants needed to provide electricity to the entire list of cities. Determine that number. If it cannot be done, return -1. You are given a list of city data. Cities that may contain a power plant have been labeled $unrecognized$. Others not suitable for building a plant are labeled $unrecognized$. Given a distribution range of $unrecognized$, find the lowest number of plants that must be built such that all cities are served. The distribution range limits supply to cities where distance is less than k. Example $unrecognized$ $unrecognized$ Each city is $unrecognized$ unit distance from its neighbors, and we'll use $unrecognized$ based indexing. We see there are $unrecognized$ cities suitable for power plants, cities $unrecognized$ and $unrecognized$. If we build a power plant at $unrecognized$, it can serve $unrecognized$ through $unrecognized$ because those endpoints are at a distance of $unrecognized$ and $unrecognized$. To serve $unrecognized$, we would need to be able to build a plant in city $unrecognized$ or $unrecognized$. Since none of those is suitable, we must return -1. It cannot be done using the current distribution constraint. Function Description Complete the pylons function in the editor below. pylons has the following parameter(s): int k: the distribution range int arr[n]: each city's suitability as a building site Returns int: the minimum number of plants required or -1 Input Format The first line contains two space-separated integers $unrecognized$ and $unrecognized$, the number of cities in Goodland and the plants' range constant. The second line contains $unrecognized$ space-separated binary integers where each integer indicates suitability for building a plant. Constraints $unrecognized$ Each $unrecognized$. Subtask $unrecognized$ for $unrecognized$ of the maximum score. Output Format Print a single integer denoting the minimum number of plants that must be built so that all of Goodland's cities have electricity. If this is not possible for the given value of $unrecognized$, print $unrecognized$. Sample Input STDIN Function ----- -------- 6 2 arr[] size n = 6, k = 2 0 1 1 1 1 0 arr = [0, 1, 1, 1, 1, 0] Sample Output 2 Explanation Cities $unrecognized$, $unrecognized$, $unrecognized$, and $unrecognized$ are suitable for power plants. Each plant will have a range of $unrecognized$. If we build in cities $unrecognized$ cities, $unrecognized$ and $unrecognized$, then all cities will have electricity.
n, k = map(int, input().split()) pp = list(map(int, input().split())) lastpp = -1 for x in range(n): if pp[x] == 1: lastpp = x pp[x] = lastpp x = 0 ppno = 0 flag = True while x < n: lastpp = pp[min(x + k - 1, n - 1)] if lastpp == -1 or lastpp + k - 1 < x: flag = False break x = lastpp + k ppno += 1 if flag: print(ppno) else: print("-1")
ASSIGN VAR 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 NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR NUMBER ASSIGN VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR VAR ASSIGN VAR VAR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR NUMBER BIN_OP VAR NUMBER IF VAR NUMBER BIN_OP BIN_OP VAR VAR NUMBER VAR ASSIGN VAR NUMBER ASSIGN VAR BIN_OP VAR VAR VAR NUMBER IF VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR STRING
Goodland is a country with a number of evenly spaced cities along a line. The distance between adjacent cities is $unrecognized$ unit. There is an energy infrastructure project planning meeting, and the government needs to know the fewest number of power plants needed to provide electricity to the entire list of cities. Determine that number. If it cannot be done, return -1. You are given a list of city data. Cities that may contain a power plant have been labeled $unrecognized$. Others not suitable for building a plant are labeled $unrecognized$. Given a distribution range of $unrecognized$, find the lowest number of plants that must be built such that all cities are served. The distribution range limits supply to cities where distance is less than k. Example $unrecognized$ $unrecognized$ Each city is $unrecognized$ unit distance from its neighbors, and we'll use $unrecognized$ based indexing. We see there are $unrecognized$ cities suitable for power plants, cities $unrecognized$ and $unrecognized$. If we build a power plant at $unrecognized$, it can serve $unrecognized$ through $unrecognized$ because those endpoints are at a distance of $unrecognized$ and $unrecognized$. To serve $unrecognized$, we would need to be able to build a plant in city $unrecognized$ or $unrecognized$. Since none of those is suitable, we must return -1. It cannot be done using the current distribution constraint. Function Description Complete the pylons function in the editor below. pylons has the following parameter(s): int k: the distribution range int arr[n]: each city's suitability as a building site Returns int: the minimum number of plants required or -1 Input Format The first line contains two space-separated integers $unrecognized$ and $unrecognized$, the number of cities in Goodland and the plants' range constant. The second line contains $unrecognized$ space-separated binary integers where each integer indicates suitability for building a plant. Constraints $unrecognized$ Each $unrecognized$. Subtask $unrecognized$ for $unrecognized$ of the maximum score. Output Format Print a single integer denoting the minimum number of plants that must be built so that all of Goodland's cities have electricity. If this is not possible for the given value of $unrecognized$, print $unrecognized$. Sample Input STDIN Function ----- -------- 6 2 arr[] size n = 6, k = 2 0 1 1 1 1 0 arr = [0, 1, 1, 1, 1, 0] Sample Output 2 Explanation Cities $unrecognized$, $unrecognized$, $unrecognized$, and $unrecognized$ are suitable for power plants. Each plant will have a range of $unrecognized$. If we build in cities $unrecognized$ cities, $unrecognized$ and $unrecognized$, then all cities will have electricity.
n, k = map(int, input().strip().split(" ")) a = list(map(int, input().strip().split(" "))) i = k - 1 j = i while a[j] != 1 and j > -1: j -= 1 if j == -1: print("-1") quit() rep = 1 i = j + 2 * k - 1 while i < n: j = i while a[j] != 1 and j > i - (2 * k - 1): j -= 1 if j == i - (2 * k - 1): print("-1") quit() i = j + 2 * k - 1 rep += 1 if j + k - 1 < n - 1: j = n - 1 while a[j] != 1 and j > i - (2 * k - 1): j -= 1 if j == i - (2 * k - 1): print("-1") quit() rep += 1 print(rep)
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR VAR WHILE VAR VAR NUMBER VAR NUMBER VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR BIN_OP NUMBER VAR NUMBER WHILE VAR VAR ASSIGN VAR VAR WHILE VAR VAR NUMBER VAR BIN_OP VAR BIN_OP BIN_OP NUMBER VAR NUMBER VAR NUMBER IF VAR BIN_OP VAR BIN_OP BIN_OP NUMBER VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR ASSIGN VAR BIN_OP BIN_OP VAR BIN_OP NUMBER VAR NUMBER VAR NUMBER IF BIN_OP BIN_OP VAR VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER WHILE VAR VAR NUMBER VAR BIN_OP VAR BIN_OP BIN_OP NUMBER VAR NUMBER VAR NUMBER IF VAR BIN_OP VAR BIN_OP BIN_OP NUMBER VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR VAR
Goodland is a country with a number of evenly spaced cities along a line. The distance between adjacent cities is $unrecognized$ unit. There is an energy infrastructure project planning meeting, and the government needs to know the fewest number of power plants needed to provide electricity to the entire list of cities. Determine that number. If it cannot be done, return -1. You are given a list of city data. Cities that may contain a power plant have been labeled $unrecognized$. Others not suitable for building a plant are labeled $unrecognized$. Given a distribution range of $unrecognized$, find the lowest number of plants that must be built such that all cities are served. The distribution range limits supply to cities where distance is less than k. Example $unrecognized$ $unrecognized$ Each city is $unrecognized$ unit distance from its neighbors, and we'll use $unrecognized$ based indexing. We see there are $unrecognized$ cities suitable for power plants, cities $unrecognized$ and $unrecognized$. If we build a power plant at $unrecognized$, it can serve $unrecognized$ through $unrecognized$ because those endpoints are at a distance of $unrecognized$ and $unrecognized$. To serve $unrecognized$, we would need to be able to build a plant in city $unrecognized$ or $unrecognized$. Since none of those is suitable, we must return -1. It cannot be done using the current distribution constraint. Function Description Complete the pylons function in the editor below. pylons has the following parameter(s): int k: the distribution range int arr[n]: each city's suitability as a building site Returns int: the minimum number of plants required or -1 Input Format The first line contains two space-separated integers $unrecognized$ and $unrecognized$, the number of cities in Goodland and the plants' range constant. The second line contains $unrecognized$ space-separated binary integers where each integer indicates suitability for building a plant. Constraints $unrecognized$ Each $unrecognized$. Subtask $unrecognized$ for $unrecognized$ of the maximum score. Output Format Print a single integer denoting the minimum number of plants that must be built so that all of Goodland's cities have electricity. If this is not possible for the given value of $unrecognized$, print $unrecognized$. Sample Input STDIN Function ----- -------- 6 2 arr[] size n = 6, k = 2 0 1 1 1 1 0 arr = [0, 1, 1, 1, 1, 0] Sample Output 2 Explanation Cities $unrecognized$, $unrecognized$, $unrecognized$, and $unrecognized$ are suitable for power plants. Each plant will have a range of $unrecognized$. If we build in cities $unrecognized$ cities, $unrecognized$ and $unrecognized$, then all cities will have electricity.
def solve(n, k, A): i = 0 res = 0 k = k - 1 while i < n: ok = False jump = i for j in range(2 * k + 1): if i + k - j < n and i + k - j >= 0 and A[i + k - j]: ok = True jump = i + k - j + k + 1 break if not ok: return -1 res += 1 i = jump return res n, k = [int(i) for i in input().split()] A = [int(i) for i in input().split()] print(solve(n, k, A))
FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER WHILE VAR VAR ASSIGN VAR NUMBER ASSIGN VAR VAR FOR VAR FUNC_CALL VAR BIN_OP BIN_OP NUMBER VAR NUMBER IF BIN_OP BIN_OP VAR VAR VAR VAR BIN_OP BIN_OP VAR VAR VAR NUMBER VAR BIN_OP BIN_OP VAR VAR VAR ASSIGN VAR NUMBER ASSIGN VAR BIN_OP BIN_OP BIN_OP BIN_OP VAR VAR VAR VAR NUMBER IF VAR RETURN NUMBER VAR NUMBER ASSIGN VAR VAR RETURN VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR VAR
Goodland is a country with a number of evenly spaced cities along a line. The distance between adjacent cities is $unrecognized$ unit. There is an energy infrastructure project planning meeting, and the government needs to know the fewest number of power plants needed to provide electricity to the entire list of cities. Determine that number. If it cannot be done, return -1. You are given a list of city data. Cities that may contain a power plant have been labeled $unrecognized$. Others not suitable for building a plant are labeled $unrecognized$. Given a distribution range of $unrecognized$, find the lowest number of plants that must be built such that all cities are served. The distribution range limits supply to cities where distance is less than k. Example $unrecognized$ $unrecognized$ Each city is $unrecognized$ unit distance from its neighbors, and we'll use $unrecognized$ based indexing. We see there are $unrecognized$ cities suitable for power plants, cities $unrecognized$ and $unrecognized$. If we build a power plant at $unrecognized$, it can serve $unrecognized$ through $unrecognized$ because those endpoints are at a distance of $unrecognized$ and $unrecognized$. To serve $unrecognized$, we would need to be able to build a plant in city $unrecognized$ or $unrecognized$. Since none of those is suitable, we must return -1. It cannot be done using the current distribution constraint. Function Description Complete the pylons function in the editor below. pylons has the following parameter(s): int k: the distribution range int arr[n]: each city's suitability as a building site Returns int: the minimum number of plants required or -1 Input Format The first line contains two space-separated integers $unrecognized$ and $unrecognized$, the number of cities in Goodland and the plants' range constant. The second line contains $unrecognized$ space-separated binary integers where each integer indicates suitability for building a plant. Constraints $unrecognized$ Each $unrecognized$. Subtask $unrecognized$ for $unrecognized$ of the maximum score. Output Format Print a single integer denoting the minimum number of plants that must be built so that all of Goodland's cities have electricity. If this is not possible for the given value of $unrecognized$, print $unrecognized$. Sample Input STDIN Function ----- -------- 6 2 arr[] size n = 6, k = 2 0 1 1 1 1 0 arr = [0, 1, 1, 1, 1, 0] Sample Output 2 Explanation Cities $unrecognized$, $unrecognized$, $unrecognized$, and $unrecognized$ are suitable for power plants. Each plant will have a range of $unrecognized$. If we build in cities $unrecognized$ cities, $unrecognized$ and $unrecognized$, then all cities will have electricity.
n, k = (int(x) for x in input().split()) c = [int(x) for x in input().split()] k -= 1 last = n - 1 num_power = 0 while True: if last < 0: break change = False for i in range(last - k, last + k + 1): if i < 0 or i >= n: continue if c[i] == 1: num_power += 1 last = i - k - 1 change = True break if not change: num_power = -1 break print(num_power)
ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER WHILE NUMBER IF VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR VAR BIN_OP BIN_OP VAR VAR NUMBER IF VAR NUMBER VAR VAR IF VAR VAR NUMBER VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR NUMBER IF VAR ASSIGN VAR NUMBER EXPR FUNC_CALL VAR VAR
Many modern text editors automatically check the spelling of the user's text. Some editors even suggest how to correct typos. In this problem your task to implement a small functionality to correct two types of typos in a word. We will assume that three identical letters together is a typo (for example, word "helllo" contains a typo). Besides, a couple of identical letters immediately followed by another couple of identical letters is a typo too (for example, words "helloo" and "wwaatt" contain typos). Write a code that deletes the minimum number of letters from a word, correcting described typos in the word. You are allowed to delete letters from both ends and from the middle of the word. -----Input----- The single line of the input contains word s, its length is from 1 to 200000 characters. The given word s consists of lowercase English letters. -----Output----- Print such word t that it doesn't contain any typos described in the problem statement and is obtained from s by deleting the least number of letters. If there are multiple solutions, print any of them. -----Examples----- Input helloo Output hello Input woooooow Output woow -----Note----- The second valid answer to the test from the statement is "heloo".
s = input().rstrip() n = len(s) stack = [] for ch in s: if len(stack) <= 1 or not stack[-1] == stack[-2] == ch: stack.append(ch) s = "".join(stack) stack = [] for ch in s: if len(stack) <= 2 or not (stack[-3] == stack[-2] and stack[-1] == ch): stack.append(ch) print("".join(stack))
ASSIGN VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR LIST FOR VAR VAR IF FUNC_CALL VAR VAR NUMBER VAR NUMBER VAR NUMBER VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL STRING VAR ASSIGN VAR LIST FOR VAR VAR IF FUNC_CALL VAR VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL STRING VAR
Many modern text editors automatically check the spelling of the user's text. Some editors even suggest how to correct typos. In this problem your task to implement a small functionality to correct two types of typos in a word. We will assume that three identical letters together is a typo (for example, word "helllo" contains a typo). Besides, a couple of identical letters immediately followed by another couple of identical letters is a typo too (for example, words "helloo" and "wwaatt" contain typos). Write a code that deletes the minimum number of letters from a word, correcting described typos in the word. You are allowed to delete letters from both ends and from the middle of the word. -----Input----- The single line of the input contains word s, its length is from 1 to 200000 characters. The given word s consists of lowercase English letters. -----Output----- Print such word t that it doesn't contain any typos described in the problem statement and is obtained from s by deleting the least number of letters. If there are multiple solutions, print any of them. -----Examples----- Input helloo Output hello Input woooooow Output woow -----Note----- The second valid answer to the test from the statement is "heloo".
import sys s = list(input()) n = len(s) if n <= 2: print("".join(s)) sys.exit() temp = ["/", s[0], s[1]] for i in range(2, n): if s[i] == temp[-1] and s[i] == temp[-2]: continue elif temp[-2] == temp[-3] and s[i] == temp[-1]: continue else: temp.append(s[i]) x = "".join(temp[1:]) print(x)
IMPORT ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR IF VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL STRING VAR EXPR FUNC_CALL VAR ASSIGN VAR LIST STRING VAR NUMBER VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR IF VAR VAR VAR NUMBER VAR VAR VAR NUMBER IF VAR NUMBER VAR NUMBER VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL STRING VAR NUMBER EXPR FUNC_CALL VAR VAR
Many modern text editors automatically check the spelling of the user's text. Some editors even suggest how to correct typos. In this problem your task to implement a small functionality to correct two types of typos in a word. We will assume that three identical letters together is a typo (for example, word "helllo" contains a typo). Besides, a couple of identical letters immediately followed by another couple of identical letters is a typo too (for example, words "helloo" and "wwaatt" contain typos). Write a code that deletes the minimum number of letters from a word, correcting described typos in the word. You are allowed to delete letters from both ends and from the middle of the word. -----Input----- The single line of the input contains word s, its length is from 1 to 200000 characters. The given word s consists of lowercase English letters. -----Output----- Print such word t that it doesn't contain any typos described in the problem statement and is obtained from s by deleting the least number of letters. If there are multiple solutions, print any of them. -----Examples----- Input helloo Output hello Input woooooow Output woow -----Note----- The second valid answer to the test from the statement is "heloo".
string = input() fixedString = "" i = 0 if len(string) <= 2: print(string) exit(0) while i < len(string): chain = 0 j = i while string[j] == string[i]: j += 1 chain += 1 if j == len(string): j -= 1 break if chain < 2: fixedString += string[i] elif chain == 2: fixedString += string[i] + string[i] if chain >= 3: fixedString += string[i : i + 2] i += chain i = 0 string = fixedString fixedString = "" while i < len(string): j = i chain = 0 if j < len(string) - 1: while string[j] == string[j + 1]: chain += 1 j += 2 if j >= len(string) - 1: break if chain == 0: fixedString += string[j] elif chain == 1: fixedString += string[j - 1] + string[j - 1] elif chain % 2 == 0: change = True for l in range(i, j, 2): if change: fixedString += string[l] else: fixedString += string[l] + string[l] change = not change else: change = False for l in range(i, j, 2): if change: fixedString += string[l] else: fixedString += string[l] + string[l] change = not change if chain == 0: i += 1 i += chain * 2 print(fixedString)
ASSIGN VAR FUNC_CALL VAR ASSIGN VAR STRING ASSIGN VAR NUMBER IF FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR NUMBER WHILE VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR VAR WHILE VAR VAR VAR VAR VAR NUMBER VAR NUMBER IF VAR FUNC_CALL VAR VAR VAR NUMBER IF VAR NUMBER VAR VAR VAR IF VAR NUMBER VAR BIN_OP VAR VAR VAR VAR IF VAR NUMBER VAR VAR VAR BIN_OP VAR NUMBER VAR VAR ASSIGN VAR NUMBER ASSIGN VAR VAR ASSIGN VAR STRING WHILE VAR FUNC_CALL VAR VAR ASSIGN VAR VAR ASSIGN VAR NUMBER IF VAR BIN_OP FUNC_CALL VAR VAR NUMBER WHILE VAR VAR VAR BIN_OP VAR NUMBER VAR NUMBER VAR NUMBER IF VAR BIN_OP FUNC_CALL VAR VAR NUMBER IF VAR NUMBER VAR VAR VAR IF VAR NUMBER VAR BIN_OP VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER IF BIN_OP VAR NUMBER NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR VAR NUMBER IF VAR VAR VAR VAR VAR BIN_OP VAR VAR VAR VAR ASSIGN VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR VAR NUMBER IF VAR VAR VAR VAR VAR BIN_OP VAR VAR VAR VAR ASSIGN VAR VAR IF VAR NUMBER VAR NUMBER VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR
Many modern text editors automatically check the spelling of the user's text. Some editors even suggest how to correct typos. In this problem your task to implement a small functionality to correct two types of typos in a word. We will assume that three identical letters together is a typo (for example, word "helllo" contains a typo). Besides, a couple of identical letters immediately followed by another couple of identical letters is a typo too (for example, words "helloo" and "wwaatt" contain typos). Write a code that deletes the minimum number of letters from a word, correcting described typos in the word. You are allowed to delete letters from both ends and from the middle of the word. -----Input----- The single line of the input contains word s, its length is from 1 to 200000 characters. The given word s consists of lowercase English letters. -----Output----- Print such word t that it doesn't contain any typos described in the problem statement and is obtained from s by deleting the least number of letters. If there are multiple solutions, print any of them. -----Examples----- Input helloo Output hello Input woooooow Output woow -----Note----- The second valid answer to the test from the statement is "heloo".
s = input() z = [] count = 1 for i in range(len(s)): z.append(s[i]) i = 1 while i < len(z): if s[i] == s[i - 1]: count = count + 1 else: if count >= 3: kap = 0 while count > 2: z[i - kap - 1] = -1 kap = kap + 1 count = count - 1 count = 1 i = i + 1 if count >= 3: kap = 0 while count > 2: z[i - kap - 1] = -1 kap = kap + 1 count = count - 1 z = list(filter(lambda a: a != -1, z)) for i in range(3, len(z)): if z[i] == z[i - 1] and z[i - 2] == z[i - 3]: z[i] = -1 z = list(filter(lambda a: a != -1, z)) print("".join(map(str, z)))
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 NUMBER WHILE VAR FUNC_CALL VAR VAR IF VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER IF VAR NUMBER ASSIGN VAR NUMBER WHILE VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER IF VAR NUMBER ASSIGN VAR NUMBER WHILE VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER VAR FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR IF VAR VAR VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER VAR EXPR FUNC_CALL VAR FUNC_CALL STRING FUNC_CALL VAR VAR VAR
Many modern text editors automatically check the spelling of the user's text. Some editors even suggest how to correct typos. In this problem your task to implement a small functionality to correct two types of typos in a word. We will assume that three identical letters together is a typo (for example, word "helllo" contains a typo). Besides, a couple of identical letters immediately followed by another couple of identical letters is a typo too (for example, words "helloo" and "wwaatt" contain typos). Write a code that deletes the minimum number of letters from a word, correcting described typos in the word. You are allowed to delete letters from both ends and from the middle of the word. -----Input----- The single line of the input contains word s, its length is from 1 to 200000 characters. The given word s consists of lowercase English letters. -----Output----- Print such word t that it doesn't contain any typos described in the problem statement and is obtained from s by deleting the least number of letters. If there are multiple solutions, print any of them. -----Examples----- Input helloo Output hello Input woooooow Output woow -----Note----- The second valid answer to the test from the statement is "heloo".
import sys arr = [] def canAdd(arr, a): if ( len(arr) >= 2 and arr[-1] == arr[-2] == a or len(arr) >= 3 and arr[-1] == a and arr[-2] == arr[-3] ): return False return True for x in sys.stdin.read().strip(): if canAdd(arr, x): arr.append(x) print("".join(arr))
IMPORT ASSIGN VAR LIST FUNC_DEF IF FUNC_CALL VAR VAR NUMBER VAR NUMBER VAR NUMBER VAR FUNC_CALL VAR VAR NUMBER VAR NUMBER VAR VAR NUMBER VAR NUMBER RETURN NUMBER RETURN NUMBER FOR VAR FUNC_CALL FUNC_CALL VAR IF FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL STRING VAR
Many modern text editors automatically check the spelling of the user's text. Some editors even suggest how to correct typos. In this problem your task to implement a small functionality to correct two types of typos in a word. We will assume that three identical letters together is a typo (for example, word "helllo" contains a typo). Besides, a couple of identical letters immediately followed by another couple of identical letters is a typo too (for example, words "helloo" and "wwaatt" contain typos). Write a code that deletes the minimum number of letters from a word, correcting described typos in the word. You are allowed to delete letters from both ends and from the middle of the word. -----Input----- The single line of the input contains word s, its length is from 1 to 200000 characters. The given word s consists of lowercase English letters. -----Output----- Print such word t that it doesn't contain any typos described in the problem statement and is obtained from s by deleting the least number of letters. If there are multiple solutions, print any of them. -----Examples----- Input helloo Output hello Input woooooow Output woow -----Note----- The second valid answer to the test from the statement is "heloo".
s = input() new = "" g = "" _c = 0 _two = False for u in s: if u != g: if _c >= 2: _two = True if _c == 1: _two = False _c = 1 new = new + u g = u elif _c < 2 and _two == False: new = new + u g = u _c += 1 print(new)
ASSIGN VAR FUNC_CALL VAR ASSIGN VAR STRING ASSIGN VAR STRING ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR IF VAR VAR IF VAR NUMBER ASSIGN VAR NUMBER IF VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR VAR IF VAR NUMBER VAR NUMBER ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR