output_description
stringlengths
15
956
submission_id
stringlengths
10
10
status
stringclasses
3 values
problem_id
stringlengths
6
6
input_description
stringlengths
9
2.55k
attempt
stringlengths
1
13.7k
problem_description
stringlengths
7
5.24k
samples
stringlengths
2
2.72k
Print the distance in real number. The output should not contain an absolute error greater than 10-4.
s258591116
Accepted
p02379
Four real numbers x1, y1, x2 and y2 are given in a line.
r = list(map(float, input().split())) print("{0:f}".format(((r[2] - r[0]) ** 2 + (r[3] - r[1]) ** 2) ** 0.5))
Distance Write a program which calculates the distance between two points P1(x1, y1) and P2(x2, y2).
[{"input": "0 1 1", "output": ".41421356"}]
For each dataset, output a single line containing an integer which is the length of the shortest expression that has the same value as the given expression for all combinations of values in the variables.
s956724924
Accepted
p01105
The input consists of multiple datasets. A dataset consists of one line, containing an expression conforming to the grammar described above. The length of the expression is less than or equal to 16 characters. The end of the input is indicated by a line containing one ‘`.`’ (period). The number of datasets in the input is at most 200.
a = 65280 b = 61680 c = 52428 d = 43690 e = 65535 def calc(s): res = eval(s.replace("-", "~").replace("*", "&").replace("1", "e")) return e ^ ~res if res < 0 else res base = [a, b, c, d, e, 0] L = {el: 1 for el in base} for i in range(6): R = dict(L) for p in R: if R[p] < 16: L[p ^ e] = min(L.get(p ^ e, 16), R[p] + 1) if R[p] + 3 < 16: for q in R: if R[p] + R[q] + 3 <= 16: L[p & q] = min(L.get(p & q, 16), R[p] + R[q] + 3) L[p ^ q] = min(L.get(p ^ q, 16), R[p] + R[q] + 3) while 1: s = input() if s == ".": break print(L[calc(s)])
_Boolean Expression Compressor_ You are asked to build a compressor for Boolean expressions that transforms expressions to the shortest form keeping their meaning. The grammar of the Boolean expressions has terminals `0` `1` `a` `b` `c` `d` `-` `^` `*` `(` `)`, start symbol <E> and the following production rule: > <E> ::= `0` | `1` | `a` | `b` | `c` | `d` | `-`<E> | `(`<E>`^`<E>`)` | `(`<E>`*`<E>`)` Letters `a`, `b`, `c` and `d` represent Boolean variables that have values of either `0` or `1`. Operators are evaluated as shown in the Table below. In other words, `-` means negation (NOT), `^` means exclusive disjunction (XOR), and `*` means logical conjunction (AND). Table: Evaluations of operators ![](https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE2_ICPCDomestic2017_E01) Write a program that calculates the length of the shortest expression that evaluates equal to the given expression with whatever values of the four variables. For example, `0`, that is the first expression in the sample input, cannot be shortened further. Therefore the shortest length for this expression is 1. For another example, `(a*(1*b))`, the second in the sample input, always evaluates equal to `(a*b)` and `(b*a)`, which are the shortest. The output for this expression, thus, should be `5`.
[{"input": "(a*(1*b))\n (1^a)\n (-(-a*-b)*a)\n (a^(b^(c^d)))\n .", "output": "5\n 2\n 1\n 13"}]
Print the minimum total cost required to sort p in ascending order. * * *
s635483763
Wrong Answer
p03092
Input is given from Standard Input in the following format: N A B p_1 \cdots p_N
n, a, b = 5000, 10000000, 10000000 p = list(range(n, 0, -1)) q = [0] * n for i, x in enumerate(p): q[x - 1] = i dp = [[0] * (n + 1) for _ in range(n + 1)] mi = [[n] * (n + 1) for _ in range(n + 1)] ma = [[0] * (n + 1) for _ in range(n + 1)] for i in range(n + 1): for j in range(i + 1, n + 1): mi[i][j] = min(mi[i][j - 1], q[j - 1]) ma[i][j] = max(ma[i][j - 1], q[j - 1]) for i in range(1, n + 1): for j in range(i + 1): k = i - j s, t = 1, 1 if j > 0 and j == p[mi[j - 1][n - k]]: s = 0 if k > 0 and n - k + 1 == p[ma[j][n - k + 1]]: t = 0 if j == 0: dp[j][k] = dp[j][k - 1] + a * t elif k == 0: dp[j][k] = dp[j - 1][k] + b * s else: dp[j][k] = min(dp[j - 1][k] + b * s, dp[j][k - 1] + a * t) ans = float("inf") for i in range(n + 1): ans = min(ans, dp[i][n - i]) print(ans)
Statement You are given a permutation p = (p_1, \ldots, p_N) of \\{ 1, \ldots, N \\}. You can perform the following two kinds of operations repeatedly in any order: * Pay a cost A. Choose integers l and r (1 \leq l < r \leq N), and shift (p_l, \ldots, p_r) to the left by one. That is, replace p_l, p_{l + 1}, \ldots, p_{r - 1}, p_r with p_{l + 1}, p_{l + 2}, \ldots, p_r, p_l, respectively. * Pay a cost B. Choose integers l and r (1 \leq l < r \leq N), and shift (p_l, \ldots, p_r) to the right by one. That is, replace p_l, p_{l + 1}, \ldots, p_{r - 1}, p_r with p_r, p_l, \ldots, p_{r - 2}, p_{r - 1}, respectively. Find the minimum total cost required to sort p in ascending order.
[{"input": "3 20 30\n 3 1 2", "output": "20\n \n\nShifting (p_1, p_2, p_3) to the left by one results in p = (1, 2, 3).\n\n* * *"}, {"input": "4 20 30\n 4 2 3 1", "output": "50\n \n\nOne possible sequence of operations is as follows:\n\n * Shift (p_1, p_2, p_3, p_4) to the left by one. Now we have p = (2, 3, 1, 4).\n * Shift (p_1, p_2, p_3) to the right by one. Now we have p = (1, 2, 3, 4).\n\nHere, the total cost is 20 + 30 = 50.\n\n* * *"}, {"input": "1 10 10\n 1", "output": "0\n \n\n* * *"}, {"input": "4 1000000000 1000000000\n 4 3 2 1", "output": "3000000000\n \n\n* * *"}, {"input": "9 40 50\n 5 3 4 7 6 1 2 9 8", "output": "220"}]
Print the minimum total cost required to sort p in ascending order. * * *
s463991303
Runtime Error
p03092
Input is given from Standard Input in the following format: N A B p_1 \cdots p_N
def solve(p): print(p) if len(p) < 2: return 0 i = p.index(max(p)) return min(solve(p[:i]) + (len(p) - 1 - i) * b, solve(p[:i] + p[i + 1 :]) + a) n, a, b, *p = map(int, open(0).read().split()) print(solve(p))
Statement You are given a permutation p = (p_1, \ldots, p_N) of \\{ 1, \ldots, N \\}. You can perform the following two kinds of operations repeatedly in any order: * Pay a cost A. Choose integers l and r (1 \leq l < r \leq N), and shift (p_l, \ldots, p_r) to the left by one. That is, replace p_l, p_{l + 1}, \ldots, p_{r - 1}, p_r with p_{l + 1}, p_{l + 2}, \ldots, p_r, p_l, respectively. * Pay a cost B. Choose integers l and r (1 \leq l < r \leq N), and shift (p_l, \ldots, p_r) to the right by one. That is, replace p_l, p_{l + 1}, \ldots, p_{r - 1}, p_r with p_r, p_l, \ldots, p_{r - 2}, p_{r - 1}, respectively. Find the minimum total cost required to sort p in ascending order.
[{"input": "3 20 30\n 3 1 2", "output": "20\n \n\nShifting (p_1, p_2, p_3) to the left by one results in p = (1, 2, 3).\n\n* * *"}, {"input": "4 20 30\n 4 2 3 1", "output": "50\n \n\nOne possible sequence of operations is as follows:\n\n * Shift (p_1, p_2, p_3, p_4) to the left by one. Now we have p = (2, 3, 1, 4).\n * Shift (p_1, p_2, p_3) to the right by one. Now we have p = (1, 2, 3, 4).\n\nHere, the total cost is 20 + 30 = 50.\n\n* * *"}, {"input": "1 10 10\n 1", "output": "0\n \n\n* * *"}, {"input": "4 1000000000 1000000000\n 4 3 2 1", "output": "3000000000\n \n\n* * *"}, {"input": "9 40 50\n 5 3 4 7 6 1 2 9 8", "output": "220"}]
Print the minimum total cost required to sort p in ascending order. * * *
s055872817
Runtime Error
p03092
Input is given from Standard Input in the following format: N A B p_1 \cdots p_N
ri = lambda: int(input()) rl = lambda: list(map(int, input().split())) rr = lambda N: [ri() for _ in range(N)] YN = lambda b: print("YES") if b else print("NO") yn = lambda b: print("Yes") if b else print("No") OE = lambda x: print("Odd") if x % 2 else print("Even") INF = 10**18 N, A, B = rl() P = rl() for i in range(N): P[i] -= i + 1 ans = 0 while True: abs_max = -1 ind = 0 for i in range(N): a_p = abs(P[i]) if abs_max < a_p: abs_max = a_p ind = i if abs_max == 0: break if P[ind] > 0: ans += min(B, A * P[ind]) for i in range(ind + 1, ind + P[ind] + 1): P[i] += 1 P[ind] = 0 else: ans += min(A, B * (-P[ind])) for i in range(ind + P[ind], ind): P[i] -= 1 P[ind] = 0 print(ans)
Statement You are given a permutation p = (p_1, \ldots, p_N) of \\{ 1, \ldots, N \\}. You can perform the following two kinds of operations repeatedly in any order: * Pay a cost A. Choose integers l and r (1 \leq l < r \leq N), and shift (p_l, \ldots, p_r) to the left by one. That is, replace p_l, p_{l + 1}, \ldots, p_{r - 1}, p_r with p_{l + 1}, p_{l + 2}, \ldots, p_r, p_l, respectively. * Pay a cost B. Choose integers l and r (1 \leq l < r \leq N), and shift (p_l, \ldots, p_r) to the right by one. That is, replace p_l, p_{l + 1}, \ldots, p_{r - 1}, p_r with p_r, p_l, \ldots, p_{r - 2}, p_{r - 1}, respectively. Find the minimum total cost required to sort p in ascending order.
[{"input": "3 20 30\n 3 1 2", "output": "20\n \n\nShifting (p_1, p_2, p_3) to the left by one results in p = (1, 2, 3).\n\n* * *"}, {"input": "4 20 30\n 4 2 3 1", "output": "50\n \n\nOne possible sequence of operations is as follows:\n\n * Shift (p_1, p_2, p_3, p_4) to the left by one. Now we have p = (2, 3, 1, 4).\n * Shift (p_1, p_2, p_3) to the right by one. Now we have p = (1, 2, 3, 4).\n\nHere, the total cost is 20 + 30 = 50.\n\n* * *"}, {"input": "1 10 10\n 1", "output": "0\n \n\n* * *"}, {"input": "4 1000000000 1000000000\n 4 3 2 1", "output": "3000000000\n \n\n* * *"}, {"input": "9 40 50\n 5 3 4 7 6 1 2 9 8", "output": "220"}]
Print the minimum total cost required to sort p in ascending order. * * *
s337604789
Accepted
p03092
Input is given from Standard Input in the following format: N A B p_1 \cdots p_N
def main(): import sys input = sys.stdin.readline N, R, L = map(int, input().split()) P = list(map(int, input().split())) val2idx = [0] * (N + 1) for i, p in enumerate(P): val2idx[p] = i + 1 bigger = [[0] * (N + 1) for _ in range(N + 1)] for p in range(1, N + 1): for j in range(N): if P[j] > p: bigger[p][j + 1] = bigger[p][j] + 1 else: bigger[p][j + 1] = bigger[p][j] # print(bigger) inf = 10**14 dp = [[inf] * (N + 1) for _ in range(N + 1)] dp[0][0] = 0 for p in range(1, N + 1): i = val2idx[p] for j in range(N + 1): if i > j: dp[p][j] = min(dp[p][j], dp[p - 1][j] + L) dp[p][i] = min( dp[p][i], dp[p - 1][j] + R * (bigger[p][i] - bigger[p][j]) ) else: dp[p][j] = min(dp[p][j], dp[p - 1][j]) print(min(dp[-1])) # [print(i, dp[i]) for i in range(N+1)] if __name__ == "__main__": main()
Statement You are given a permutation p = (p_1, \ldots, p_N) of \\{ 1, \ldots, N \\}. You can perform the following two kinds of operations repeatedly in any order: * Pay a cost A. Choose integers l and r (1 \leq l < r \leq N), and shift (p_l, \ldots, p_r) to the left by one. That is, replace p_l, p_{l + 1}, \ldots, p_{r - 1}, p_r with p_{l + 1}, p_{l + 2}, \ldots, p_r, p_l, respectively. * Pay a cost B. Choose integers l and r (1 \leq l < r \leq N), and shift (p_l, \ldots, p_r) to the right by one. That is, replace p_l, p_{l + 1}, \ldots, p_{r - 1}, p_r with p_r, p_l, \ldots, p_{r - 2}, p_{r - 1}, respectively. Find the minimum total cost required to sort p in ascending order.
[{"input": "3 20 30\n 3 1 2", "output": "20\n \n\nShifting (p_1, p_2, p_3) to the left by one results in p = (1, 2, 3).\n\n* * *"}, {"input": "4 20 30\n 4 2 3 1", "output": "50\n \n\nOne possible sequence of operations is as follows:\n\n * Shift (p_1, p_2, p_3, p_4) to the left by one. Now we have p = (2, 3, 1, 4).\n * Shift (p_1, p_2, p_3) to the right by one. Now we have p = (1, 2, 3, 4).\n\nHere, the total cost is 20 + 30 = 50.\n\n* * *"}, {"input": "1 10 10\n 1", "output": "0\n \n\n* * *"}, {"input": "4 1000000000 1000000000\n 4 3 2 1", "output": "3000000000\n \n\n* * *"}, {"input": "9 40 50\n 5 3 4 7 6 1 2 9 8", "output": "220"}]
Print the minimum total cost required to sort p in ascending order. * * *
s905300378
Wrong Answer
p03092
Input is given from Standard Input in the following format: N A B p_1 \cdots p_N
from operator import itemgetter n, a, b = map(int, input().split()) ppp = list(map(int, input().split())) qqq = list(map(itemgetter(0), sorted(enumerate(ppp, start=1), key=itemgetter(1)))) INF = 10**15 print(qqq) # dp = {0: 0} # for i in qqq: # ndp = {} # tmp_min_cost = INF # stay_min_cost = INF # for j, cost in sorted(dp.items()): # if j <= i: # if j < i: # stay_min_cost = min(stay_min_cost, cost) # cost += b # if tmp_min_cost > cost: # ndp[j] = tmp_min_cost = cost # else: # cost += a # if tmp_min_cost > cost: # ndp[j] = tmp_min_cost = cost # if stay_min_cost < INF: # ndp[i] = min(ndp[i], stay_min_cost) if i in ndp else stay_min_cost # dp = ndp # # print(min(dp.values()))
Statement You are given a permutation p = (p_1, \ldots, p_N) of \\{ 1, \ldots, N \\}. You can perform the following two kinds of operations repeatedly in any order: * Pay a cost A. Choose integers l and r (1 \leq l < r \leq N), and shift (p_l, \ldots, p_r) to the left by one. That is, replace p_l, p_{l + 1}, \ldots, p_{r - 1}, p_r with p_{l + 1}, p_{l + 2}, \ldots, p_r, p_l, respectively. * Pay a cost B. Choose integers l and r (1 \leq l < r \leq N), and shift (p_l, \ldots, p_r) to the right by one. That is, replace p_l, p_{l + 1}, \ldots, p_{r - 1}, p_r with p_r, p_l, \ldots, p_{r - 2}, p_{r - 1}, respectively. Find the minimum total cost required to sort p in ascending order.
[{"input": "3 20 30\n 3 1 2", "output": "20\n \n\nShifting (p_1, p_2, p_3) to the left by one results in p = (1, 2, 3).\n\n* * *"}, {"input": "4 20 30\n 4 2 3 1", "output": "50\n \n\nOne possible sequence of operations is as follows:\n\n * Shift (p_1, p_2, p_3, p_4) to the left by one. Now we have p = (2, 3, 1, 4).\n * Shift (p_1, p_2, p_3) to the right by one. Now we have p = (1, 2, 3, 4).\n\nHere, the total cost is 20 + 30 = 50.\n\n* * *"}, {"input": "1 10 10\n 1", "output": "0\n \n\n* * *"}, {"input": "4 1000000000 1000000000\n 4 3 2 1", "output": "3000000000\n \n\n* * *"}, {"input": "9 40 50\n 5 3 4 7 6 1 2 9 8", "output": "220"}]
Print the minimum total cost required to sort p in ascending order. * * *
s610190989
Runtime Error
p03092
Input is given from Standard Input in the following format: N A B p_1 \cdots p_N
n, m = [int(i) for i in input().split()] E = [[] for i in range(n + 1)] used = [False] * (n + 1) IN = [0] * (n + 1) for i in range(m): a, b = [int(i) for i in input().split()] E[a].append(b) E[b].append(a) IN[a] += 1 IN[b] += 1 cnt_4 = 0 cnt_6 = 0 v_4 = [] for j, i in enumerate(IN[1:]): if i % 2 == 1 or i == 0: print("No") exit() if i >= 4: cnt_4 += 1 v_4.append(j + 1) if i >= 6: cnt_6 += 1 def dfs(p, v): if v == v_4[0]: return v_4[0] if v == v_4[1]: return v_4[1] for e in E[v]: if e == p: continue return dfs(v, e) if cnt_4 > 2 or cnt_6 >= 1: print("Yes") elif cnt_4 == 2: if all(dfs(v_4[0], e) == v_4[1] for e in E[v_4]): print("No") else: print("Yes") else: print("No")
Statement You are given a permutation p = (p_1, \ldots, p_N) of \\{ 1, \ldots, N \\}. You can perform the following two kinds of operations repeatedly in any order: * Pay a cost A. Choose integers l and r (1 \leq l < r \leq N), and shift (p_l, \ldots, p_r) to the left by one. That is, replace p_l, p_{l + 1}, \ldots, p_{r - 1}, p_r with p_{l + 1}, p_{l + 2}, \ldots, p_r, p_l, respectively. * Pay a cost B. Choose integers l and r (1 \leq l < r \leq N), and shift (p_l, \ldots, p_r) to the right by one. That is, replace p_l, p_{l + 1}, \ldots, p_{r - 1}, p_r with p_r, p_l, \ldots, p_{r - 2}, p_{r - 1}, respectively. Find the minimum total cost required to sort p in ascending order.
[{"input": "3 20 30\n 3 1 2", "output": "20\n \n\nShifting (p_1, p_2, p_3) to the left by one results in p = (1, 2, 3).\n\n* * *"}, {"input": "4 20 30\n 4 2 3 1", "output": "50\n \n\nOne possible sequence of operations is as follows:\n\n * Shift (p_1, p_2, p_3, p_4) to the left by one. Now we have p = (2, 3, 1, 4).\n * Shift (p_1, p_2, p_3) to the right by one. Now we have p = (1, 2, 3, 4).\n\nHere, the total cost is 20 + 30 = 50.\n\n* * *"}, {"input": "1 10 10\n 1", "output": "0\n \n\n* * *"}, {"input": "4 1000000000 1000000000\n 4 3 2 1", "output": "3000000000\n \n\n* * *"}, {"input": "9 40 50\n 5 3 4 7 6 1 2 9 8", "output": "220"}]
Print the number of integer sequences that satisfy the condition. * * *
s113642126
Accepted
p03568
Input is given from Standard Input in the following format: N A_1 A_2 ... A_N
N = int(input()) AAA = map(int, input().split()) AA = list(AAA) total = 3 ** len(AA) total2 = 0 total3 = 0 for i in AA: if i % 2 == 0: total2 += 1 total3 = 2**total2 ans = total - total3 print(ans)
Statement We will say that two integer sequences of length N, x_1, x_2, ..., x_N and y_1, y_2, ..., y_N, are _similar_ when |x_i - y_i| \leq 1 holds for all i (1 \leq i \leq N). In particular, any integer sequence is similar to itself. You are given an integer N and an integer sequence of length N, A_1, A_2, ..., A_N. How many integer sequences b_1, b_2, ..., b_N are there such that b_1, b_2, ..., b_N is similar to A and the product of all elements, b_1 b_2 ... b_N, is even?
[{"input": "2\n 2 3", "output": "7\n \n\nThere are seven integer sequences that satisfy the condition:\n\n * 1, 2\n * 1, 4\n * 2, 2\n * 2, 3\n * 2, 4\n * 3, 2\n * 3, 4\n\n* * *"}, {"input": "3\n 3 3 3", "output": "26\n \n\n* * *"}, {"input": "1\n 100", "output": "1\n \n\n* * *"}, {"input": "10\n 90 52 56 71 44 8 13 30 57 84", "output": "58921"}]
Print the number of integer sequences that satisfy the condition. * * *
s808389258
Accepted
p03568
Input is given from Standard Input in the following format: N A_1 A_2 ... A_N
import sys ## io ## def IS(): return sys.stdin.readline().rstrip() def II(): return int(IS()) def MII(): return list(map(int, IS().split())) def MIIZ(): return list(map(lambda x: x - 1, MII())) ## dp ## def DD2(d1, d2, init=0): return [[init] * d2 for _ in range(d1)] def DD3(d1, d2, d3, init=0): return [DD2(d2, d3, init) for _ in range(d1)] ## math ## def to_bin(x: int) -> str: return format(x, "b") # rev => int(res, 2) def to_oct(x: int) -> str: return format(x, "o") # rev => int(res, 8) def to_hex(x: int) -> str: return format(x, "x") # rev => int(res, 16) MOD = 10**9 + 7 def divc(x, y) -> int: return -(-x // y) def divf(x, y) -> int: return x // y def gcd(x, y): while y: x, y = y, x % y return x def lcm(x, y): return x * y // gcd(x, y) def enumerate_divs(n): """Return a tuple list of divisor of n""" return [(i, n // i) for i in range(1, int(n**0.5) + 1) if n % i == 0] def get_primes(MAX_NUM=10**3): """Return a list of prime numbers n or less""" is_prime = [True] * (MAX_NUM + 1) is_prime[0] = is_prime[1] = False for i in range(2, int(MAX_NUM**0.5) + 1): if not is_prime[i]: continue for j in range(i * 2, MAX_NUM + 1, i): is_prime[j] = False return [i for i in range(MAX_NUM + 1) if is_prime[i]] ## libs ## from itertools import accumulate as acc from collections import deque, Counter from heapq import heapify, heappop, heappush from bisect import bisect_left # ======================================================# def main(): n = II() aa = MII() cnt = 3**n m = list(acc([2 if a % 2 == 0 else 1 for a in aa], lambda x, y: x * y)) print(cnt - m[-1]) if __name__ == "__main__": main()
Statement We will say that two integer sequences of length N, x_1, x_2, ..., x_N and y_1, y_2, ..., y_N, are _similar_ when |x_i - y_i| \leq 1 holds for all i (1 \leq i \leq N). In particular, any integer sequence is similar to itself. You are given an integer N and an integer sequence of length N, A_1, A_2, ..., A_N. How many integer sequences b_1, b_2, ..., b_N are there such that b_1, b_2, ..., b_N is similar to A and the product of all elements, b_1 b_2 ... b_N, is even?
[{"input": "2\n 2 3", "output": "7\n \n\nThere are seven integer sequences that satisfy the condition:\n\n * 1, 2\n * 1, 4\n * 2, 2\n * 2, 3\n * 2, 4\n * 3, 2\n * 3, 4\n\n* * *"}, {"input": "3\n 3 3 3", "output": "26\n \n\n* * *"}, {"input": "1\n 100", "output": "1\n \n\n* * *"}, {"input": "10\n 90 52 56 71 44 8 13 30 57 84", "output": "58921"}]
Print the number of integer sequences that satisfy the condition. * * *
s167511029
Runtime Error
p03568
Input is given from Standard Input in the following format: N A_1 A_2 ... A_N
#ifndef LOCAL #pragma GCC optimize("O3") #include <bits/stdc++.h> #else #include <iostream> #include <iomanip> #include <sstream> #include <cstdio> #include <cstdlib> #include <cmath> #include <memory> #include <cctype> #include <cstring> #include <vector> #include <list> #include <queue> #include <deque> #include <stack> #include <map> #include <set> #include <algorithm> #include <numeric> #include <unordered_map> #include <unordered_set> #endif using namespace std; #define sim template < class c #define ris return * this #define dor > debug & operator << #define eni(x) sim > typename enable_if<sizeof dud<c>(0) x 1, debug&>::type operator<<(c i) { sim > struct rge { c b, e; }; sim > rge<c> range(c i, c j) { return rge<c>{i, j}; } sim > auto dud(c* x) -> decltype(cerr << *x, 0); sim > char dud(...); struct debug { #ifdef LOCAL ~debug() { cerr << endl; } eni(!=) cerr << boolalpha << i; ris; } eni(==) ris << range(begin(i), end(i)); } sim, class b dor(pair < b, c > d) { ris << "(" << d.first << ", " << d.second << ")"; } sim dor(rge<c> d) { *this << "["; for (auto it = d.b; it != d.e; ++it) *this << ", " + 2 * (it == d.b) << *it; ris << "]"; } #else sim dor(const c&) { ris; } #endif }; #define imie(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] " // #include <ext/pb_ds/assoc_container.hpp> // #include <ext/pb_ds/tree_policy.hpp> // using namespace __gnu_pbds; // #define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update> template<typename T> void setmax(T& x, T y) {x = max(x, y);} template<typename T> void setmin(T& x, T y) {x = min(x, y);} #define fix(a) fixed << setprecision(a) #define forn(i, n) for (int i = 0; i < int(n); i++) #define rep(i, a, b) for (int i = int(a); i < int(b); i++) #define all(V) V.begin(), V.end() #define rall(V) V.rbegin(), V.rend() #define len(V) (int)V.size() #define ll long long #define ld long double #define ff first #define ss second #define pb push_back #define mp make_pair #define endl '\n' void solve(){ int n; cin >> n; int total = 1; int bad = 1; forn(i,n){ int a; cin >> a; total *= 3; if (a%2){ bad *= 1; } else { bad *= 2; } } cout << total - bad; } int main() { ios::sync_with_stdio(false); // cin.tie(0); cout.tie(0); int t = 1; // cin >> t; forn(i, t){ solve(); } } /* k (k-1) (k-1) */
Statement We will say that two integer sequences of length N, x_1, x_2, ..., x_N and y_1, y_2, ..., y_N, are _similar_ when |x_i - y_i| \leq 1 holds for all i (1 \leq i \leq N). In particular, any integer sequence is similar to itself. You are given an integer N and an integer sequence of length N, A_1, A_2, ..., A_N. How many integer sequences b_1, b_2, ..., b_N are there such that b_1, b_2, ..., b_N is similar to A and the product of all elements, b_1 b_2 ... b_N, is even?
[{"input": "2\n 2 3", "output": "7\n \n\nThere are seven integer sequences that satisfy the condition:\n\n * 1, 2\n * 1, 4\n * 2, 2\n * 2, 3\n * 2, 4\n * 3, 2\n * 3, 4\n\n* * *"}, {"input": "3\n 3 3 3", "output": "26\n \n\n* * *"}, {"input": "1\n 100", "output": "1\n \n\n* * *"}, {"input": "10\n 90 52 56 71 44 8 13 30 57 84", "output": "58921"}]
Print the number of integer sequences that satisfy the condition. * * *
s965746483
Accepted
p03568
Input is given from Standard Input in the following format: N A_1 A_2 ... A_N
# -*- coding: utf-8 -*- ############# # Libraries # ############# import sys input = sys.stdin.readline import math # from math import gcd import bisect from collections import defaultdict from collections import deque from collections import Counter from functools import lru_cache ############# # Constants # ############# MOD = 10**9 + 7 INF = float("inf") ############# # Functions # ############# ######INPUT###### def I(): return int(input().strip()) def S(): return input().strip() def IL(): return list(map(int, input().split())) def SL(): return list(map(str, input().split())) def ILs(n): return list(int(input()) for _ in range(n)) def SLs(n): return list(input().strip() for _ in range(n)) def ILL(n): return [list(map(int, input().split())) for _ in range(n)] def SLL(n): return [list(map(str, input().split())) for _ in range(n)] ######OUTPUT###### def P(arg): print(arg) return def Y(): print("Yes") return def N(): print("No") return def E(): exit() def PE(arg): print(arg) exit() def YE(): print("Yes") exit() def NE(): print("No") exit() #####Shorten##### def DD(arg): return defaultdict(arg) #####Inverse##### def inv(n): return pow(n, MOD - 2, MOD) ######Combination###### kaijo_memo = [] def kaijo(n): if len(kaijo_memo) > n: return kaijo_memo[n] if len(kaijo_memo) == 0: kaijo_memo.append(1) while len(kaijo_memo) <= n: kaijo_memo.append(kaijo_memo[-1] * len(kaijo_memo) % MOD) return kaijo_memo[n] gyaku_kaijo_memo = [] def gyaku_kaijo(n): if len(gyaku_kaijo_memo) > n: return gyaku_kaijo_memo[n] if len(gyaku_kaijo_memo) == 0: gyaku_kaijo_memo.append(1) while len(gyaku_kaijo_memo) <= n: gyaku_kaijo_memo.append( gyaku_kaijo_memo[-1] * pow(len(gyaku_kaijo_memo), MOD - 2, MOD) % MOD ) return gyaku_kaijo_memo[n] def nCr(n, r): if n == r: return 1 if n < r or r < 0: return 0 ret = 1 ret = ret * kaijo(n) % MOD ret = ret * gyaku_kaijo(r) % MOD ret = ret * gyaku_kaijo(n - r) % MOD return ret ######Factorization###### def factorization(n): arr = [] temp = n for i in range(2, int(-(-(n**0.5) // 1)) + 1): if temp % i == 0: cnt = 0 while temp % i == 0: cnt += 1 temp //= i arr.append([i, cnt]) if temp != 1: arr.append([temp, 1]) if arr == []: arr.append([n, 1]) return arr #####MakeDivisors###### def make_divisors(n): divisors = [] for i in range(1, int(n**0.5) + 1): if n % i == 0: divisors.append(i) if i != n // i: divisors.append(n // i) return divisors #####MakePrimes###### def make_primes(N): max = int(math.sqrt(N)) seachList = [i for i in range(2, N + 1)] primeNum = [] while seachList[0] <= max: primeNum.append(seachList[0]) tmp = seachList[0] seachList = [i for i in seachList if i % tmp != 0] primeNum.extend(seachList) return primeNum #####GCD##### def gcd(a, b): while b: a, b = b, a % b return a #####LCM##### def lcm(a, b): return a * b // gcd(a, b) #####BitCount##### def count_bit(n): count = 0 while n: n &= n - 1 count += 1 return count #####ChangeBase##### def base_10_to_n(X, n): if X // n: return base_10_to_n(X // n, n) + [X % n] return [X % n] def base_n_to_10(X, n): return sum(int(str(X)[-i - 1]) * n**i for i in range(len(str(X)))) #####IntLog##### def int_log(n, a): count = 0 while n >= a: n //= a count += 1 return count ############# # Main Code # ############# N = I() A = IL() ans = 1 for a in A: if a % 2 == 0: ans *= 2 print(pow(3, N) - ans)
Statement We will say that two integer sequences of length N, x_1, x_2, ..., x_N and y_1, y_2, ..., y_N, are _similar_ when |x_i - y_i| \leq 1 holds for all i (1 \leq i \leq N). In particular, any integer sequence is similar to itself. You are given an integer N and an integer sequence of length N, A_1, A_2, ..., A_N. How many integer sequences b_1, b_2, ..., b_N are there such that b_1, b_2, ..., b_N is similar to A and the product of all elements, b_1 b_2 ... b_N, is even?
[{"input": "2\n 2 3", "output": "7\n \n\nThere are seven integer sequences that satisfy the condition:\n\n * 1, 2\n * 1, 4\n * 2, 2\n * 2, 3\n * 2, 4\n * 3, 2\n * 3, 4\n\n* * *"}, {"input": "3\n 3 3 3", "output": "26\n \n\n* * *"}, {"input": "1\n 100", "output": "1\n \n\n* * *"}, {"input": "10\n 90 52 56 71 44 8 13 30 57 84", "output": "58921"}]
Print the number of integer sequences that satisfy the condition. * * *
s061076003
Accepted
p03568
Input is given from Standard Input in the following format: N A_1 A_2 ... A_N
# coding: utf-8 import re import math from collections import defaultdict from collections import deque import itertools from copy import deepcopy import random import time import os import queue import sys import datetime from functools import lru_cache # @lru_cache(maxsize=None) readline = sys.stdin.readline sys.setrecursionlimit(2000000) # import numpy as np alphabet = "abcdefghijklmnopqrstuvwxyz" mod = int(10**9 + 7) inf = int(10**20) def yn(b): if b: print("yes") else: print("no") def Yn(b): if b: print("Yes") else: print("No") def YN(b): if b: print("YES") else: print("NO") class union_find: def __init__(self, n): self.n = n self.P = [a for a in range(N)] self.rank = [0] * n def find(self, x): if x != self.P[x]: self.P[x] = self.find(self.P[x]) return self.P[x] def same(self, x, y): return self.find(x) == self.find(y) def link(self, x, y): if self.rank[x] < self.rank[y]: self.P[x] = y elif self.rank[y] < self.rank[x]: self.P[y] = x else: self.P[x] = y self.rank[y] += 1 def unite(self, x, y): self.link(self.find(x), self.find(y)) def size(self): S = set() for a in range(self.n): S.add(self.find(a)) return len(S) def is_pow(a, b): # aはbの累乗数か now = b while now < a: now *= b if now == a: return True else: return False def bin_(num, size): A = [0] * size for a in range(size): if (num >> (size - a - 1)) & 1 == 1: A[a] = 1 else: A[a] = 0 return A def get_facs(n, mod_=0): A = [1] * (n + 1) for a in range(2, len(A)): A[a] = A[a - 1] * a if mod_ > 0: A[a] %= mod_ return A def comb(n, r, mod, fac): if n - r < 0: return 0 return (fac[n] * pow(fac[n - r], mod - 2, mod) * pow(fac[r], mod - 2, mod)) % mod def next_comb(num, size): x = num & (-num) y = num + x z = num & (~y) z //= x z = z >> 1 num = y | z if num >= (1 << size): return False else: return num def get_primes(n, type="int"): if n == 0: if type == "int": return [] else: return [False] A = [True] * (n + 1) A[0] = False A[1] = False for a in range(2, n + 1): if A[a]: for b in range(a * 2, n + 1, a): A[b] = False if type == "bool": return A B = [] for a in range(n + 1): if A[a]: B.append(a) return B def is_prime(num): if num <= 1: return False i = 2 while i * i <= num: if num % i == 0: return False i += 1 return True def ifelse(a, b, c): if a: return b else: return c def join(A, c=""): n = len(A) A = list(map(str, A)) s = "" for a in range(n): s += A[a] if a < n - 1: s += c return s def factorize(n, type_="dict"): b = 2 list_ = [] while b * b <= n: while n % b == 0: n //= b list_.append(b) b += 1 if n > 1: list_.append(n) if type_ == "dict": dic = {} for a in list_: if a in dic: dic[a] += 1 else: dic[a] = 1 return dic elif type_ == "list": return list_ else: return None def floor_(n, x=1): return x * (n // x) def ceil_(n, x=1): return x * ((n + x - 1) // x) return ret def seifu(x): return x // abs(x) ###################################################################################################### def main(): n = int(input()) A = list(map(int, input().split())) ans = 3**n mi = 1 for a in A: if a % 2 == 0: mi *= 2 else: mi *= 1 ans -= mi print(ans) main()
Statement We will say that two integer sequences of length N, x_1, x_2, ..., x_N and y_1, y_2, ..., y_N, are _similar_ when |x_i - y_i| \leq 1 holds for all i (1 \leq i \leq N). In particular, any integer sequence is similar to itself. You are given an integer N and an integer sequence of length N, A_1, A_2, ..., A_N. How many integer sequences b_1, b_2, ..., b_N are there such that b_1, b_2, ..., b_N is similar to A and the product of all elements, b_1 b_2 ... b_N, is even?
[{"input": "2\n 2 3", "output": "7\n \n\nThere are seven integer sequences that satisfy the condition:\n\n * 1, 2\n * 1, 4\n * 2, 2\n * 2, 3\n * 2, 4\n * 3, 2\n * 3, 4\n\n* * *"}, {"input": "3\n 3 3 3", "output": "26\n \n\n* * *"}, {"input": "1\n 100", "output": "1\n \n\n* * *"}, {"input": "10\n 90 52 56 71 44 8 13 30 57 84", "output": "58921"}]
Print the number of integer sequences that satisfy the condition. * * *
s403329960
Runtime Error
p03568
Input is given from Standard Input in the following format: N A_1 A_2 ... A_N
import itertools def solve(): N = int(input()) A = list(map(int, input().split(" "))) matrix = [[] for _ in range(N)] for i in range(N): matrix[i].append(A[i] - 1) matrix[i].append(A[i]) matrix[i].append(A[i] + 1) cnt = 0 for element in list(itertools.product(*matrix)): for i in range(N): if element[i] % 2 == 0: cnt += 1 break print(cnt) solve()
Statement We will say that two integer sequences of length N, x_1, x_2, ..., x_N and y_1, y_2, ..., y_N, are _similar_ when |x_i - y_i| \leq 1 holds for all i (1 \leq i \leq N). In particular, any integer sequence is similar to itself. You are given an integer N and an integer sequence of length N, A_1, A_2, ..., A_N. How many integer sequences b_1, b_2, ..., b_N are there such that b_1, b_2, ..., b_N is similar to A and the product of all elements, b_1 b_2 ... b_N, is even?
[{"input": "2\n 2 3", "output": "7\n \n\nThere are seven integer sequences that satisfy the condition:\n\n * 1, 2\n * 1, 4\n * 2, 2\n * 2, 3\n * 2, 4\n * 3, 2\n * 3, 4\n\n* * *"}, {"input": "3\n 3 3 3", "output": "26\n \n\n* * *"}, {"input": "1\n 100", "output": "1\n \n\n* * *"}, {"input": "10\n 90 52 56 71 44 8 13 30 57 84", "output": "58921"}]
Print the number of integer sequences that satisfy the condition. * * *
s432689004
Wrong Answer
p03568
Input is given from Standard Input in the following format: N A_1 A_2 ... A_N
i = int(input()) s = input().split() j = [] k = [] a = 0 for h in range(i): j.append(int(s[h]) % 2) for g in range(i): plus = 1 if j[g] == 0: if len(k) > 0: for h in k: plus = plus * h plus = plus * (3 ^ (9 - g)) a += plus k.append(2) else: if len(k) > 0: for h in k: plus = plus * h plus = 2 * plus * (3 ^ (9 - g)) a += plus k.append(1) print(str(a))
Statement We will say that two integer sequences of length N, x_1, x_2, ..., x_N and y_1, y_2, ..., y_N, are _similar_ when |x_i - y_i| \leq 1 holds for all i (1 \leq i \leq N). In particular, any integer sequence is similar to itself. You are given an integer N and an integer sequence of length N, A_1, A_2, ..., A_N. How many integer sequences b_1, b_2, ..., b_N are there such that b_1, b_2, ..., b_N is similar to A and the product of all elements, b_1 b_2 ... b_N, is even?
[{"input": "2\n 2 3", "output": "7\n \n\nThere are seven integer sequences that satisfy the condition:\n\n * 1, 2\n * 1, 4\n * 2, 2\n * 2, 3\n * 2, 4\n * 3, 2\n * 3, 4\n\n* * *"}, {"input": "3\n 3 3 3", "output": "26\n \n\n* * *"}, {"input": "1\n 100", "output": "1\n \n\n* * *"}, {"input": "10\n 90 52 56 71 44 8 13 30 57 84", "output": "58921"}]
Print the number of integer sequences that satisfy the condition. * * *
s308067090
Runtime Error
p03568
Input is given from Standard Input in the following format: N A_1 A_2 ... A_N
from functools import reduce n = int(input()) print(3**n - reduce(lambda x, y: x * y, 2 - int(s) % 2 for s in input().split()))
Statement We will say that two integer sequences of length N, x_1, x_2, ..., x_N and y_1, y_2, ..., y_N, are _similar_ when |x_i - y_i| \leq 1 holds for all i (1 \leq i \leq N). In particular, any integer sequence is similar to itself. You are given an integer N and an integer sequence of length N, A_1, A_2, ..., A_N. How many integer sequences b_1, b_2, ..., b_N are there such that b_1, b_2, ..., b_N is similar to A and the product of all elements, b_1 b_2 ... b_N, is even?
[{"input": "2\n 2 3", "output": "7\n \n\nThere are seven integer sequences that satisfy the condition:\n\n * 1, 2\n * 1, 4\n * 2, 2\n * 2, 3\n * 2, 4\n * 3, 2\n * 3, 4\n\n* * *"}, {"input": "3\n 3 3 3", "output": "26\n \n\n* * *"}, {"input": "1\n 100", "output": "1\n \n\n* * *"}, {"input": "10\n 90 52 56 71 44 8 13 30 57 84", "output": "58921"}]
Print the number of integer sequences that satisfy the condition. * * *
s390685931
Accepted
p03568
Input is given from Standard Input in the following format: N A_1 A_2 ... A_N
# (c) midandfeed n = int(input()) q = [int(x) for x in input().split()] nodd = 0 for i in q: if i & 1: nodd += 1 print(pow(3, n) - pow(2, n - nodd))
Statement We will say that two integer sequences of length N, x_1, x_2, ..., x_N and y_1, y_2, ..., y_N, are _similar_ when |x_i - y_i| \leq 1 holds for all i (1 \leq i \leq N). In particular, any integer sequence is similar to itself. You are given an integer N and an integer sequence of length N, A_1, A_2, ..., A_N. How many integer sequences b_1, b_2, ..., b_N are there such that b_1, b_2, ..., b_N is similar to A and the product of all elements, b_1 b_2 ... b_N, is even?
[{"input": "2\n 2 3", "output": "7\n \n\nThere are seven integer sequences that satisfy the condition:\n\n * 1, 2\n * 1, 4\n * 2, 2\n * 2, 3\n * 2, 4\n * 3, 2\n * 3, 4\n\n* * *"}, {"input": "3\n 3 3 3", "output": "26\n \n\n* * *"}, {"input": "1\n 100", "output": "1\n \n\n* * *"}, {"input": "10\n 90 52 56 71 44 8 13 30 57 84", "output": "58921"}]
Print the number of integer sequences that satisfy the condition. * * *
s768313539
Accepted
p03568
Input is given from Standard Input in the following format: N A_1 A_2 ... A_N
n = int(input()) li = list(map(int, input().split())) lee = len(li) base = 1 for l in li: if l % 2 == 0: base *= 2 print(3**lee - base)
Statement We will say that two integer sequences of length N, x_1, x_2, ..., x_N and y_1, y_2, ..., y_N, are _similar_ when |x_i - y_i| \leq 1 holds for all i (1 \leq i \leq N). In particular, any integer sequence is similar to itself. You are given an integer N and an integer sequence of length N, A_1, A_2, ..., A_N. How many integer sequences b_1, b_2, ..., b_N are there such that b_1, b_2, ..., b_N is similar to A and the product of all elements, b_1 b_2 ... b_N, is even?
[{"input": "2\n 2 3", "output": "7\n \n\nThere are seven integer sequences that satisfy the condition:\n\n * 1, 2\n * 1, 4\n * 2, 2\n * 2, 3\n * 2, 4\n * 3, 2\n * 3, 4\n\n* * *"}, {"input": "3\n 3 3 3", "output": "26\n \n\n* * *"}, {"input": "1\n 100", "output": "1\n \n\n* * *"}, {"input": "10\n 90 52 56 71 44 8 13 30 57 84", "output": "58921"}]
Print the number of integer sequences that satisfy the condition. * * *
s177395830
Runtime Error
p03568
Input is given from Standard Input in the following format: N A_1 A_2 ... A_N
#include <iostream> #include <iomanip> #include <string> #include <stack> #include <vector> #include <math.h> #include <stdio.h> #include <algorithm> #include <utility> #include <functional> #include <map> #include <set> #include <queue> #include <list> #include <regex> using namespace std; using pii = pair<int,int>; using ll=long long; using ld=long double; #define pb push_back #define mp make_pair #define sc second #define fr first #define stpr setprecision #define cYES cout<<"YES"<<endl #define cNO cout<<"NO"<<endl #define cYes cout<<"Yes"<<endl #define cNo cout<<"No"<<endl #define rep(i,n) for(ll i=0;i<(n);++i) #define Rep(i,a,b) for(ll i=(a);i<(b);++i) #define rrep(i,n) for(int i=n-1;i>=0;i--) #define rRep(i,a,b) for(int i=a;i>=b;i--) #define crep(i) for(char i='a';i<='z';++i) #define psortsecond(A,N) sort(A,A+N,[](const pii &a, const pii &b){return a.second<b.second;}); #define ALL(x) (x).begin(),(x).end() #define debug(v) cout<<#v<<":";for(auto x:v){cout<<x<<' ';}cout<<endl; #define endl '\n' int ctoi(const char c){ if('0' <= c && c <= '9') return (c-'0'); return -1; } ll gcd(ll a,ll b){return (b == 0 ? a : gcd(b, a%b));} ll lcm(ll a,ll b){return a*b/gcd(a,b);} constexpr ll MOD=1000000007; constexpr ll INF=1000000011; constexpr ll MOD2=998244353; constexpr ll LINF = 1001002003004005006ll; constexpr ld EPS=10e-8; template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; } template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; } template<typename T> istream& operator>>(istream& is,vector<T>& v){for(auto&& x:v)is >> x;return is;} template<typename T,typename U> istream& operator>>(istream& is, pair<T,U>& p){ is >> p.first; is >> p.second; return is;} template<typename T,typename U> ostream& operator>>(ostream& os, const pair<T,U>& p){ os << p.first << ' ' << p.second; return os;} template<class T> ostream& operator<<(ostream& os, vector<T>& v){ for(auto i=begin(v); i != end(v); ++i){ if(i !=begin(v)) os << ' '; os << *i; } return os; } ll ans,M[100007]; ll compME(ll b, ll e, ll m){ // bのe乗のmod m を返す if (e == 0) return 1; ans = compME(b, e / 2, m); ans = (ans * ans) % m; if (e % 2 == 1) ans = (ans * b) % m; return ans; } int main(){ ll N,A[100007],T=1,C=1; cin >> N; rep(i,N){ cin >> A[i]; if(A[i]%2==0){ T*=2; } C*=3; } cout << C-T << endl; }
Statement We will say that two integer sequences of length N, x_1, x_2, ..., x_N and y_1, y_2, ..., y_N, are _similar_ when |x_i - y_i| \leq 1 holds for all i (1 \leq i \leq N). In particular, any integer sequence is similar to itself. You are given an integer N and an integer sequence of length N, A_1, A_2, ..., A_N. How many integer sequences b_1, b_2, ..., b_N are there such that b_1, b_2, ..., b_N is similar to A and the product of all elements, b_1 b_2 ... b_N, is even?
[{"input": "2\n 2 3", "output": "7\n \n\nThere are seven integer sequences that satisfy the condition:\n\n * 1, 2\n * 1, 4\n * 2, 2\n * 2, 3\n * 2, 4\n * 3, 2\n * 3, 4\n\n* * *"}, {"input": "3\n 3 3 3", "output": "26\n \n\n* * *"}, {"input": "1\n 100", "output": "1\n \n\n* * *"}, {"input": "10\n 90 52 56 71 44 8 13 30 57 84", "output": "58921"}]
Print the number of integer sequences that satisfy the condition. * * *
s379569269
Runtime Error
p03568
Input is given from Standard Input in the following format: N A_1 A_2 ... A_N
macro_rules! get { (Vec<$t:ty>) => { { let mut line: String = String::new(); std::io::stdin().read_line(&mut line).unwrap(); line.split_whitespace() .map(|t| t.parse::<$t>().unwrap()) .collect::<Vec<_>>() } }; ($t:ty) => { { let mut line: String = String::new(); std::io::stdin().read_line(&mut line).unwrap(); line.trim().parse::<$t>().unwrap() } }; ($($t:ty),*) => { { let mut line: String = String::new(); std::io::stdin().read_line(&mut line).unwrap(); let mut iter = line.split_whitespace(); ( $(iter.next().unwrap().parse::<$t>().unwrap(),)* ) } }; ($t:ty; $n:expr) => { (0..$n).map(|_| get!($t) ).collect::<Vec<_>>() }; ($($t:ty),*; $n:expr) => { (0..$n).map(|_| get!($($t),*) ).collect::<Vec<_>>() }; } fn main() { let N = get!(u32); let A = get!(Vec<i64>); // 解は3^N - 2^(Aに含まれる偶数の個数) let M = A.iter() .filter(|&a| a % 2 == 0) .count(); let ans = 3_i64.pow(N) - 2_i64.pow(M as u32); println!("{}", ans); }
Statement We will say that two integer sequences of length N, x_1, x_2, ..., x_N and y_1, y_2, ..., y_N, are _similar_ when |x_i - y_i| \leq 1 holds for all i (1 \leq i \leq N). In particular, any integer sequence is similar to itself. You are given an integer N and an integer sequence of length N, A_1, A_2, ..., A_N. How many integer sequences b_1, b_2, ..., b_N are there such that b_1, b_2, ..., b_N is similar to A and the product of all elements, b_1 b_2 ... b_N, is even?
[{"input": "2\n 2 3", "output": "7\n \n\nThere are seven integer sequences that satisfy the condition:\n\n * 1, 2\n * 1, 4\n * 2, 2\n * 2, 3\n * 2, 4\n * 3, 2\n * 3, 4\n\n* * *"}, {"input": "3\n 3 3 3", "output": "26\n \n\n* * *"}, {"input": "1\n 100", "output": "1\n \n\n* * *"}, {"input": "10\n 90 52 56 71 44 8 13 30 57 84", "output": "58921"}]
Print the number of integer sequences that satisfy the condition. * * *
s713287492
Accepted
p03568
Input is given from Standard Input in the following format: N A_1 A_2 ... A_N
s = 3 ** int(input()) t = 1 for i in list(map(int, input().split())): t *= 1 + int(i % 2 == 0) print(s - t)
Statement We will say that two integer sequences of length N, x_1, x_2, ..., x_N and y_1, y_2, ..., y_N, are _similar_ when |x_i - y_i| \leq 1 holds for all i (1 \leq i \leq N). In particular, any integer sequence is similar to itself. You are given an integer N and an integer sequence of length N, A_1, A_2, ..., A_N. How many integer sequences b_1, b_2, ..., b_N are there such that b_1, b_2, ..., b_N is similar to A and the product of all elements, b_1 b_2 ... b_N, is even?
[{"input": "2\n 2 3", "output": "7\n \n\nThere are seven integer sequences that satisfy the condition:\n\n * 1, 2\n * 1, 4\n * 2, 2\n * 2, 3\n * 2, 4\n * 3, 2\n * 3, 4\n\n* * *"}, {"input": "3\n 3 3 3", "output": "26\n \n\n* * *"}, {"input": "1\n 100", "output": "1\n \n\n* * *"}, {"input": "10\n 90 52 56 71 44 8 13 30 57 84", "output": "58921"}]
Print the number of integer sequences that satisfy the condition. * * *
s077000690
Runtime Error
p03568
Input is given from Standard Input in the following format: N A_1 A_2 ... A_N
n = int(input()) l =0 for i in range(n): p=(int(input()) if p %2==0: l+=1 print(3**n-2**l)
Statement We will say that two integer sequences of length N, x_1, x_2, ..., x_N and y_1, y_2, ..., y_N, are _similar_ when |x_i - y_i| \leq 1 holds for all i (1 \leq i \leq N). In particular, any integer sequence is similar to itself. You are given an integer N and an integer sequence of length N, A_1, A_2, ..., A_N. How many integer sequences b_1, b_2, ..., b_N are there such that b_1, b_2, ..., b_N is similar to A and the product of all elements, b_1 b_2 ... b_N, is even?
[{"input": "2\n 2 3", "output": "7\n \n\nThere are seven integer sequences that satisfy the condition:\n\n * 1, 2\n * 1, 4\n * 2, 2\n * 2, 3\n * 2, 4\n * 3, 2\n * 3, 4\n\n* * *"}, {"input": "3\n 3 3 3", "output": "26\n \n\n* * *"}, {"input": "1\n 100", "output": "1\n \n\n* * *"}, {"input": "10\n 90 52 56 71 44 8 13 30 57 84", "output": "58921"}]
Print the number of integer sequences that satisfy the condition. * * *
s647417837
Wrong Answer
p03568
Input is given from Standard Input in the following format: N A_1 A_2 ... A_N
n = int(input()) print(2**n - 1)
Statement We will say that two integer sequences of length N, x_1, x_2, ..., x_N and y_1, y_2, ..., y_N, are _similar_ when |x_i - y_i| \leq 1 holds for all i (1 \leq i \leq N). In particular, any integer sequence is similar to itself. You are given an integer N and an integer sequence of length N, A_1, A_2, ..., A_N. How many integer sequences b_1, b_2, ..., b_N are there such that b_1, b_2, ..., b_N is similar to A and the product of all elements, b_1 b_2 ... b_N, is even?
[{"input": "2\n 2 3", "output": "7\n \n\nThere are seven integer sequences that satisfy the condition:\n\n * 1, 2\n * 1, 4\n * 2, 2\n * 2, 3\n * 2, 4\n * 3, 2\n * 3, 4\n\n* * *"}, {"input": "3\n 3 3 3", "output": "26\n \n\n* * *"}, {"input": "1\n 100", "output": "1\n \n\n* * *"}, {"input": "10\n 90 52 56 71 44 8 13 30 57 84", "output": "58921"}]
Print the number of integer sequences that satisfy the condition. * * *
s222017078
Runtime Error
p03568
Input is given from Standard Input in the following format: N A_1 A_2 ... A_N
n=int(input()) a=list(map(int,input().split())) cnt=0 for i range(n): if a[i]%2==0: cnt+=1 ans=(3*n)-2*cnt print(ans)
Statement We will say that two integer sequences of length N, x_1, x_2, ..., x_N and y_1, y_2, ..., y_N, are _similar_ when |x_i - y_i| \leq 1 holds for all i (1 \leq i \leq N). In particular, any integer sequence is similar to itself. You are given an integer N and an integer sequence of length N, A_1, A_2, ..., A_N. How many integer sequences b_1, b_2, ..., b_N are there such that b_1, b_2, ..., b_N is similar to A and the product of all elements, b_1 b_2 ... b_N, is even?
[{"input": "2\n 2 3", "output": "7\n \n\nThere are seven integer sequences that satisfy the condition:\n\n * 1, 2\n * 1, 4\n * 2, 2\n * 2, 3\n * 2, 4\n * 3, 2\n * 3, 4\n\n* * *"}, {"input": "3\n 3 3 3", "output": "26\n \n\n* * *"}, {"input": "1\n 100", "output": "1\n \n\n* * *"}, {"input": "10\n 90 52 56 71 44 8 13 30 57 84", "output": "58921"}]
Print the number of integer sequences that satisfy the condition. * * *
s787793564
Wrong Answer
p03568
Input is given from Standard Input in the following format: N A_1 A_2 ... A_N
print(3 ** int(input()) - 2 ** sum(int(s) % 2 for s in input().split()))
Statement We will say that two integer sequences of length N, x_1, x_2, ..., x_N and y_1, y_2, ..., y_N, are _similar_ when |x_i - y_i| \leq 1 holds for all i (1 \leq i \leq N). In particular, any integer sequence is similar to itself. You are given an integer N and an integer sequence of length N, A_1, A_2, ..., A_N. How many integer sequences b_1, b_2, ..., b_N are there such that b_1, b_2, ..., b_N is similar to A and the product of all elements, b_1 b_2 ... b_N, is even?
[{"input": "2\n 2 3", "output": "7\n \n\nThere are seven integer sequences that satisfy the condition:\n\n * 1, 2\n * 1, 4\n * 2, 2\n * 2, 3\n * 2, 4\n * 3, 2\n * 3, 4\n\n* * *"}, {"input": "3\n 3 3 3", "output": "26\n \n\n* * *"}, {"input": "1\n 100", "output": "1\n \n\n* * *"}, {"input": "10\n 90 52 56 71 44 8 13 30 57 84", "output": "58921"}]
Print the number of integer sequences that satisfy the condition. * * *
s620607993
Runtime Error
p03568
Input is given from Standard Input in the following format: N A_1 A_2 ... A_N
n = int(input()) l =0 for i in range(n): p=(int(input()) if p %==0: l+=1 print(3**n-2**l)
Statement We will say that two integer sequences of length N, x_1, x_2, ..., x_N and y_1, y_2, ..., y_N, are _similar_ when |x_i - y_i| \leq 1 holds for all i (1 \leq i \leq N). In particular, any integer sequence is similar to itself. You are given an integer N and an integer sequence of length N, A_1, A_2, ..., A_N. How many integer sequences b_1, b_2, ..., b_N are there such that b_1, b_2, ..., b_N is similar to A and the product of all elements, b_1 b_2 ... b_N, is even?
[{"input": "2\n 2 3", "output": "7\n \n\nThere are seven integer sequences that satisfy the condition:\n\n * 1, 2\n * 1, 4\n * 2, 2\n * 2, 3\n * 2, 4\n * 3, 2\n * 3, 4\n\n* * *"}, {"input": "3\n 3 3 3", "output": "26\n \n\n* * *"}, {"input": "1\n 100", "output": "1\n \n\n* * *"}, {"input": "10\n 90 52 56 71 44 8 13 30 57 84", "output": "58921"}]
Print the minimum number of elements that needs to be replaced. * * *
s974210925
Runtime Error
p03246
Input is given from Standard Input in the following format: n v_1 v_2 ... v_n
n=int(input()) m=list(map(int,input().split())) a=m[::2] b=m[1::2] aa={} bb={} for i in range(n//2): if not a[i] in aa: aa[a[i]]=0 aa[a[i]]+=1 if not b[i] in bb: bb[b[i]]=0 bb[b[i]]+=1 aaa=aa.values().sort(reverse=True) bbb=bb.values().sort(reverse=True) if not max(aa)==max(bb): print(n-aaa[0]-bbb[0]) else: print(min(n-aaa[1]-bbb[0],n-aaa[0]-bbb[1])
Statement A sequence a_1,a_2,... ,a_n is said to be /\/\/\/ when the following conditions are satisfied: * For each i = 1,2,..., n-2, a_i = a_{i+2}. * Exactly two different numbers appear in the sequence. You are given a sequence v_1,v_2,...,v_n whose length is even. We would like to make this sequence /\/\/\/ by replacing some of its elements. Find the minimum number of elements that needs to be replaced.
[{"input": "4\n 3 1 3 2", "output": "1\n \n\nThe sequence 3,1,3,2 is not /\\/\\/\\/, but we can make it /\\/\\/\\/ by replacing\none of its elements: for example, replace the fourth element to make it\n3,1,3,1.\n\n* * *"}, {"input": "6\n 105 119 105 119 105 119", "output": "0\n \n\nThe sequence 105,119,105,119,105,119 is /\\/\\/\\/.\n\n* * *"}, {"input": "4\n 1 1 1 1", "output": "2\n \n\nThe elements of the sequence 1,1,1,1 are all the same, so it is not /\\/\\/\\/."}]
Print the minimum number of elements that needs to be replaced. * * *
s551001722
Runtime Error
p03246
Input is given from Standard Input in the following format: n v_1 v_2 ... v_n
n=int(input()) v=list(map(int,input().split())) odd=[] even=[] for i in range(n): if (i+1)%2==1: odd.append(v[i]) else: even.append(v[i]) if set(odd)==set(even): print(min(len(odd),len(even))) else: #odd evenのそれぞれで最大回数出てくる要素を抜いて、残った要素の個数が答えになる #でも最大回数でてくる要素の抽出方法がわからない。ギブ
Statement A sequence a_1,a_2,... ,a_n is said to be /\/\/\/ when the following conditions are satisfied: * For each i = 1,2,..., n-2, a_i = a_{i+2}. * Exactly two different numbers appear in the sequence. You are given a sequence v_1,v_2,...,v_n whose length is even. We would like to make this sequence /\/\/\/ by replacing some of its elements. Find the minimum number of elements that needs to be replaced.
[{"input": "4\n 3 1 3 2", "output": "1\n \n\nThe sequence 3,1,3,2 is not /\\/\\/\\/, but we can make it /\\/\\/\\/ by replacing\none of its elements: for example, replace the fourth element to make it\n3,1,3,1.\n\n* * *"}, {"input": "6\n 105 119 105 119 105 119", "output": "0\n \n\nThe sequence 105,119,105,119,105,119 is /\\/\\/\\/.\n\n* * *"}, {"input": "4\n 1 1 1 1", "output": "2\n \n\nThe elements of the sequence 1,1,1,1 are all the same, so it is not /\\/\\/\\/."}]
Print the minimum number of elements that needs to be replaced. * * *
s434685409
Runtime Error
p03246
Input is given from Standard Input in the following format: n v_1 v_2 ... v_n
n=int(input()) m=list(map(int,input().split())) a=m[::2] b=m[1::2] aa={} bb={} for i in range(n//2): if not a[i] in aa: aa[a[i]]=0 aa[a[i]]+=1 if not b[i] in bb: bb[b[i]]=0 bb[b[i]]+=1 aaa=aa.values().sorted(reverse=True) bbb=bb.values().sorted(reverse=True) if not max(aa)==max(bb): print(n-aaa[0]-bbb[0]) else: print(min(n-aaa[1]-bbb[0],n-aaa[0]-bbb[1])
Statement A sequence a_1,a_2,... ,a_n is said to be /\/\/\/ when the following conditions are satisfied: * For each i = 1,2,..., n-2, a_i = a_{i+2}. * Exactly two different numbers appear in the sequence. You are given a sequence v_1,v_2,...,v_n whose length is even. We would like to make this sequence /\/\/\/ by replacing some of its elements. Find the minimum number of elements that needs to be replaced.
[{"input": "4\n 3 1 3 2", "output": "1\n \n\nThe sequence 3,1,3,2 is not /\\/\\/\\/, but we can make it /\\/\\/\\/ by replacing\none of its elements: for example, replace the fourth element to make it\n3,1,3,1.\n\n* * *"}, {"input": "6\n 105 119 105 119 105 119", "output": "0\n \n\nThe sequence 105,119,105,119,105,119 is /\\/\\/\\/.\n\n* * *"}, {"input": "4\n 1 1 1 1", "output": "2\n \n\nThe elements of the sequence 1,1,1,1 are all the same, so it is not /\\/\\/\\/."}]
Print the minimum number of elements that needs to be replaced. * * *
s189039726
Runtime Error
p03246
Input is given from Standard Input in the following format: n v_1 v_2 ... v_n
import collections n=int(input()) list=list(map(int,input().split())) #print(list) list_1=list[::2] list_2=list[1::2] if (list_1[0]==list_2[0] & all(list_1) & all(list_2)): print(n//2) #print(list_1) #print(list_2) a=collections.Counter(list_1) b=collections.Counter(list_2) elif(a==b): print(n//2) else #print(a) #print(b) #print(a.most_common()) #print(b.most_common()) #print(a.most_common()[0][1]) #print(b.most_common()[0][1]) print(n-a.most_common()[0][1]-b.most_common()[0][1])
Statement A sequence a_1,a_2,... ,a_n is said to be /\/\/\/ when the following conditions are satisfied: * For each i = 1,2,..., n-2, a_i = a_{i+2}. * Exactly two different numbers appear in the sequence. You are given a sequence v_1,v_2,...,v_n whose length is even. We would like to make this sequence /\/\/\/ by replacing some of its elements. Find the minimum number of elements that needs to be replaced.
[{"input": "4\n 3 1 3 2", "output": "1\n \n\nThe sequence 3,1,3,2 is not /\\/\\/\\/, but we can make it /\\/\\/\\/ by replacing\none of its elements: for example, replace the fourth element to make it\n3,1,3,1.\n\n* * *"}, {"input": "6\n 105 119 105 119 105 119", "output": "0\n \n\nThe sequence 105,119,105,119,105,119 is /\\/\\/\\/.\n\n* * *"}, {"input": "4\n 1 1 1 1", "output": "2\n \n\nThe elements of the sequence 1,1,1,1 are all the same, so it is not /\\/\\/\\/."}]
Print the minimum number of elements that needs to be replaced. * * *
s593382491
Runtime Error
p03246
Input is given from Standard Input in the following format: n v_1 v_2 ... v_n
import collections n = int(input()) v = list(map(int,input().split())) v1 = v[::2] v2 = v[1::2] c1 = collections.Counter(v1) c2 = collections.Counter(v2) if v1 == v2 and len(c1.most_common()) == 1 print(len(v1)) elif c1.most_common()[0][0] != c2.most_common()[0][0]: print(len(v1) - c1.most_common()[0][1] + len(v2) - c2.most_common()[0][1]) else: if c1.most_common()[1][1] < c2.most_common()[1][1]: print(len(v1) - c1.most_common()[0][1] + len(v2) - c2.most_common()[1][1]) else: print(len(v1) - c1.most_common()[1][1] + len(v2) - c2.most_common()[0][1])
Statement A sequence a_1,a_2,... ,a_n is said to be /\/\/\/ when the following conditions are satisfied: * For each i = 1,2,..., n-2, a_i = a_{i+2}. * Exactly two different numbers appear in the sequence. You are given a sequence v_1,v_2,...,v_n whose length is even. We would like to make this sequence /\/\/\/ by replacing some of its elements. Find the minimum number of elements that needs to be replaced.
[{"input": "4\n 3 1 3 2", "output": "1\n \n\nThe sequence 3,1,3,2 is not /\\/\\/\\/, but we can make it /\\/\\/\\/ by replacing\none of its elements: for example, replace the fourth element to make it\n3,1,3,1.\n\n* * *"}, {"input": "6\n 105 119 105 119 105 119", "output": "0\n \n\nThe sequence 105,119,105,119,105,119 is /\\/\\/\\/.\n\n* * *"}, {"input": "4\n 1 1 1 1", "output": "2\n \n\nThe elements of the sequence 1,1,1,1 are all the same, so it is not /\\/\\/\\/."}]
Print the minimum number of elements that needs to be replaced. * * *
s100801726
Runtime Error
p03246
Input is given from Standard Input in the following format: n v_1 v_2 ... v_n
import collections n = int(input()) v = list(map(int, input().split())) a = [] b = [] for i in range(n // 2): a.append(v[(i+1)*2-1]) b.append(v[(i+1)*2-2]) a = collections.Counter(a) b = collections.Counter(b) if a.most_common()[0][0] != b.most_common()[0][0]: print(n-a.most_common()[0][1]-b.most_common()[0][1]) elif a.most_common()[1][0] + b.most_common()[0][0] > a.most_common()[0][0] + b.most_common()[1][0] print(n-a.most_common()[1][0] - b.most_common()[0][0]) else: print(n-a.most_common()[0][0] - b.most_common()[1][0])
Statement A sequence a_1,a_2,... ,a_n is said to be /\/\/\/ when the following conditions are satisfied: * For each i = 1,2,..., n-2, a_i = a_{i+2}. * Exactly two different numbers appear in the sequence. You are given a sequence v_1,v_2,...,v_n whose length is even. We would like to make this sequence /\/\/\/ by replacing some of its elements. Find the minimum number of elements that needs to be replaced.
[{"input": "4\n 3 1 3 2", "output": "1\n \n\nThe sequence 3,1,3,2 is not /\\/\\/\\/, but we can make it /\\/\\/\\/ by replacing\none of its elements: for example, replace the fourth element to make it\n3,1,3,1.\n\n* * *"}, {"input": "6\n 105 119 105 119 105 119", "output": "0\n \n\nThe sequence 105,119,105,119,105,119 is /\\/\\/\\/.\n\n* * *"}, {"input": "4\n 1 1 1 1", "output": "2\n \n\nThe elements of the sequence 1,1,1,1 are all the same, so it is not /\\/\\/\\/."}]
Print the minimum number of elements that needs to be replaced. * * *
s710786224
Runtime Error
p03246
Input is given from Standard Input in the following format: n v_1 v_2 ... v_n
n=int(input()) v_list = list(map(int,input().split())) odd_list = [] even_list = [] for i in range(n): if i % 2 == 0: odd_list.append(v_list[i]) else: even_list.append(v_list[i]) import collections odd_list_c = collections.Counter(odd_list) even_list_c = collections.Counter(even_list) if odd_list_c.most_common()[0][0] != even_list_c.most_common()[0][0]: ans = n - odd_list_c.most_common()[0][1] - even_list_c.most_common()[0][1] else: if len(even_list_c) == 1 && len(odd_list_c) == 1: ans = n // 2 else: if odd_list_c.most_common()[0][1] >= even_list_c.most_common()[0][1]: ans = n - odd_list_c.most_common()[0][1] - even_list_c.most_common()[1][1] elif odd_list_c.most_common()[0][1] < even_list_c.most_common()[0][1]: ans = n - odd_list_c.most_common()[1][1] - even_list_c.most_common()[0][1] print(ans)
Statement A sequence a_1,a_2,... ,a_n is said to be /\/\/\/ when the following conditions are satisfied: * For each i = 1,2,..., n-2, a_i = a_{i+2}. * Exactly two different numbers appear in the sequence. You are given a sequence v_1,v_2,...,v_n whose length is even. We would like to make this sequence /\/\/\/ by replacing some of its elements. Find the minimum number of elements that needs to be replaced.
[{"input": "4\n 3 1 3 2", "output": "1\n \n\nThe sequence 3,1,3,2 is not /\\/\\/\\/, but we can make it /\\/\\/\\/ by replacing\none of its elements: for example, replace the fourth element to make it\n3,1,3,1.\n\n* * *"}, {"input": "6\n 105 119 105 119 105 119", "output": "0\n \n\nThe sequence 105,119,105,119,105,119 is /\\/\\/\\/.\n\n* * *"}, {"input": "4\n 1 1 1 1", "output": "2\n \n\nThe elements of the sequence 1,1,1,1 are all the same, so it is not /\\/\\/\\/."}]
Print the minimum number of elements that needs to be replaced. * * *
s841207387
Runtime Error
p03246
Input is given from Standard Input in the following format: n v_1 v_2 ... v_n
n = int(input()) p = list(map(int, input().split())) def count(in_list): # listを集計し、要素数が最小のものの個数 l = list(set(in_list)) # 重複を除く result = [in_list.count(x) for x in l] return min(list(result)) def method(in_list): l = list(set(in_list)) # 重複を除く result = [(in_list.count(x), x) for x in l] result.sort() return result[:2] def anser(n, p): # 例外① 全部同じ数 sp = set(p) if len(sp) == 1: return int(n/2) o = [t[1] for t in enumerate(p) if t[0] % 2 == 0] e = [t[1] for t in enumerate(p) if t[0] % 2 == 1] # 例外② すでにVMVMになっているもの ①以外なのでo!=e sp = set(o) se = set(e) if len(so)) == 1 and len(se) == 1: return 0 # case ① 片一方は0 if len(so) == 1: return count(e) if len(se) == 1: return count(o) ee = method(e) # e = (個数、値)、(個数、値) oo = method(o) # o = (個数、値)、(個数、値) if ee[0][1] != oo[0][1]: return ee[0][0] + oo[0][0] else: return min(ee[0][0]+oo[1][0], ee[0][1]+oo[0][0]) print(anser(n, p))
Statement A sequence a_1,a_2,... ,a_n is said to be /\/\/\/ when the following conditions are satisfied: * For each i = 1,2,..., n-2, a_i = a_{i+2}. * Exactly two different numbers appear in the sequence. You are given a sequence v_1,v_2,...,v_n whose length is even. We would like to make this sequence /\/\/\/ by replacing some of its elements. Find the minimum number of elements that needs to be replaced.
[{"input": "4\n 3 1 3 2", "output": "1\n \n\nThe sequence 3,1,3,2 is not /\\/\\/\\/, but we can make it /\\/\\/\\/ by replacing\none of its elements: for example, replace the fourth element to make it\n3,1,3,1.\n\n* * *"}, {"input": "6\n 105 119 105 119 105 119", "output": "0\n \n\nThe sequence 105,119,105,119,105,119 is /\\/\\/\\/.\n\n* * *"}, {"input": "4\n 1 1 1 1", "output": "2\n \n\nThe elements of the sequence 1,1,1,1 are all the same, so it is not /\\/\\/\\/."}]
Print the minimum number of elements that needs to be replaced. * * *
s304813934
Runtime Error
p03246
Input is given from Standard Input in the following format: n v_1 v_2 ... v_n
def DistanceFromVV(seq, el): """Return the numbers of edits required to make seq into a VV sequences using el as the first and second element, respectively. """ distA = 0 distB = 0 for i in range(0, len(seq), 2): if seq[i] != el: distA += 1 for j in range(1, len(seq), 2): if seq[j] != el: distB += 1 return (distA, distB) def CountElements(seq): """Count the number of occurrences of each element of seq, returning the result as a dictionary. """ count = {} for el in seq: if el in count: count[el] += 1 else: count[el] = 1 return count def MinChanges(seq): """Return the minimum number of changes which must be made to the given sequence in order to make it "VV". """ element_count = CountElements(seq) elements_descending = sorted( element_count, key=lambda key: element_count[key], reverse=True ) if len(elements_descending) == 1: return len(seq) // 2 best = [len(seq) + 1, len(seq) + 1] second_best = [len(seq) + 1, len(seq) + 1] best_elements = [-1, -1] for el in elements_descending: changes = DistanceFromVV(seq, el) for i in (0, 1): if changes[i] <= best[i]: second_best[i] = best[i] best[i] = changes[i] best_elements[i] = el elif changes[i] < second_best[i]: second_best[i] = changes[i] if best_elements[0] != best_elements[1]: if best[0] <= len(seq) // 4 and best[1] <= len(seq) // 4: break elif (best[0] <= len(seq) // 4 and second_best[1] <= len(seq) // 4) or ( best[1] <= len(seq) // 4 and second_best[0] <= len(seq) // 4 ): break if best_elements[0] != best_elements[1]: return sum(best) else: return min(best[0] + second_best[1], best[1] + second_best[0]) lines = sys.stdin.read().split("\n") n = int(lines[0]) entries = lines[1].split(" ") v = [] for e in entries: v += [int(e)] print(MinChanges(v))
Statement A sequence a_1,a_2,... ,a_n is said to be /\/\/\/ when the following conditions are satisfied: * For each i = 1,2,..., n-2, a_i = a_{i+2}. * Exactly two different numbers appear in the sequence. You are given a sequence v_1,v_2,...,v_n whose length is even. We would like to make this sequence /\/\/\/ by replacing some of its elements. Find the minimum number of elements that needs to be replaced.
[{"input": "4\n 3 1 3 2", "output": "1\n \n\nThe sequence 3,1,3,2 is not /\\/\\/\\/, but we can make it /\\/\\/\\/ by replacing\none of its elements: for example, replace the fourth element to make it\n3,1,3,1.\n\n* * *"}, {"input": "6\n 105 119 105 119 105 119", "output": "0\n \n\nThe sequence 105,119,105,119,105,119 is /\\/\\/\\/.\n\n* * *"}, {"input": "4\n 1 1 1 1", "output": "2\n \n\nThe elements of the sequence 1,1,1,1 are all the same, so it is not /\\/\\/\\/."}]
Print the minimum number of elements that needs to be replaced. * * *
s212720346
Wrong Answer
p03246
Input is given from Standard Input in the following format: n v_1 v_2 ... v_n
n = int(input()) v = list(int(v) for v in input().split()) v_max = max(v) v0 = v[::2] v1 = v[1::2] counter0 = [0] * (v_max + 1) counter1 = [0] * (v_max + 1) for v in v0: counter0[v] += 1 for v in v1: counter1[v] += 1 max0 = 0 for i in range(len(counter0)): if counter0[i] > max0: max0 = counter0[i] max1 = 0 for i in range(len(counter1)): if counter1[i] > max1: max1 = counter1[i] print(n - max0 - max1)
Statement A sequence a_1,a_2,... ,a_n is said to be /\/\/\/ when the following conditions are satisfied: * For each i = 1,2,..., n-2, a_i = a_{i+2}. * Exactly two different numbers appear in the sequence. You are given a sequence v_1,v_2,...,v_n whose length is even. We would like to make this sequence /\/\/\/ by replacing some of its elements. Find the minimum number of elements that needs to be replaced.
[{"input": "4\n 3 1 3 2", "output": "1\n \n\nThe sequence 3,1,3,2 is not /\\/\\/\\/, but we can make it /\\/\\/\\/ by replacing\none of its elements: for example, replace the fourth element to make it\n3,1,3,1.\n\n* * *"}, {"input": "6\n 105 119 105 119 105 119", "output": "0\n \n\nThe sequence 105,119,105,119,105,119 is /\\/\\/\\/.\n\n* * *"}, {"input": "4\n 1 1 1 1", "output": "2\n \n\nThe elements of the sequence 1,1,1,1 are all the same, so it is not /\\/\\/\\/."}]
Print the minimum number of elements that needs to be replaced. * * *
s674567815
Accepted
p03246
Input is given from Standard Input in the following format: n v_1 v_2 ... v_n
import sys import socket from collections import Counter if socket.gethostname() in ["N551J", "F551C"]: sys.stdin = open("c1.in") def read_int_list(): return list(map(int, input().split())) def read_int(): return int(input()) def read_str_list(): return input().split() def read_str(): return input() def solve(): n = read_int() a = read_int_list() c = [Counter(a[k::2]) for k in range(2)] a, b = [c[k].most_common(1)[0] for k in range(2)] if a[0] != b[0]: return n - a[1] - b[1] if a[1] == n // 2 and b[1] == n // 2: return n // 2 res = n if a[1] < n // 2: p, q = c[0].most_common(2) res = min(res, n - q[1] - b[1]) if b[1] < n // 2: p, q = c[1].most_common(2) res = min(res, n - a[1] - q[1]) return res def main(): res = solve() print(res) if __name__ == "__main__": main()
Statement A sequence a_1,a_2,... ,a_n is said to be /\/\/\/ when the following conditions are satisfied: * For each i = 1,2,..., n-2, a_i = a_{i+2}. * Exactly two different numbers appear in the sequence. You are given a sequence v_1,v_2,...,v_n whose length is even. We would like to make this sequence /\/\/\/ by replacing some of its elements. Find the minimum number of elements that needs to be replaced.
[{"input": "4\n 3 1 3 2", "output": "1\n \n\nThe sequence 3,1,3,2 is not /\\/\\/\\/, but we can make it /\\/\\/\\/ by replacing\none of its elements: for example, replace the fourth element to make it\n3,1,3,1.\n\n* * *"}, {"input": "6\n 105 119 105 119 105 119", "output": "0\n \n\nThe sequence 105,119,105,119,105,119 is /\\/\\/\\/.\n\n* * *"}, {"input": "4\n 1 1 1 1", "output": "2\n \n\nThe elements of the sequence 1,1,1,1 are all the same, so it is not /\\/\\/\\/."}]
Print the minimum number of elements that needs to be replaced. * * *
s755341865
Runtime Error
p03246
Input is given from Standard Input in the following format: n v_1 v_2 ... v_n
import collections n = int(input()) v = list(map(int, input().split())) count = 0 v1 = [] v2 = [] while count < n: v1.append(v[count]) v2.append(v[count + 1]) count += 2 c1 = collections.Counter(v1) c2 = collections.Counter(v2) num1, count1 = c1.most_common()[0] num2, count2 = c2.most_common()[0] if num1 != num2: min_count = (n // 2 - count1) + (n // 2 - count2) elif count1 == count2 and count1 == n // 2: min_count = (n // 2) else: if count1 == count2: for i in range(min(len(c1.most_common()), c2.most_common())): a = i + 1 if c1.most_common()[a][a] == c2.most_common()[a][a]: continue if c1.most_common()[a][a] > c2.most_common()[a][a]: num2, count2 = c2.most_common()[a] break else: num1, count1 = c1.most_common()[a] break min_count = (n // 2 - count1) + (n // 2 - count2) else: if len(c1.most_common()) > 1 and len(c2.most_common()) num3, count3 = c1.most_common()[1] num4, count4 = c2.most_common()[1] a = (n // 2 - count1) + (n // 2 -count4) b = (n // 2 - count2) + (n // 2 -count3) min_count = min(a,b) else: if count1 > count2: num2, count2 = c2.most_common()[1] min_count = (n // 2 - count1) + (n // 2 - count2) else: num1, count1 = c1.most_common()[1] min_count = (n // 2 - count2) + (n // 2 - count1) print(min_count)
Statement A sequence a_1,a_2,... ,a_n is said to be /\/\/\/ when the following conditions are satisfied: * For each i = 1,2,..., n-2, a_i = a_{i+2}. * Exactly two different numbers appear in the sequence. You are given a sequence v_1,v_2,...,v_n whose length is even. We would like to make this sequence /\/\/\/ by replacing some of its elements. Find the minimum number of elements that needs to be replaced.
[{"input": "4\n 3 1 3 2", "output": "1\n \n\nThe sequence 3,1,3,2 is not /\\/\\/\\/, but we can make it /\\/\\/\\/ by replacing\none of its elements: for example, replace the fourth element to make it\n3,1,3,1.\n\n* * *"}, {"input": "6\n 105 119 105 119 105 119", "output": "0\n \n\nThe sequence 105,119,105,119,105,119 is /\\/\\/\\/.\n\n* * *"}, {"input": "4\n 1 1 1 1", "output": "2\n \n\nThe elements of the sequence 1,1,1,1 are all the same, so it is not /\\/\\/\\/."}]
Print the minimum number of elements that needs to be replaced. * * *
s135269337
Accepted
p03246
Input is given from Standard Input in the following format: n v_1 v_2 ... v_n
iipt = lambda: int(input()) miipt = lambda: map(int, input().split(" ")) o = [0] * 112345 e = [0] * 112345 n = iipt() A = miipt() for i, a in enumerate(A): if i % 2: o[a] += 1 else: e[a] += 1 om = -1, 0 om2 = -1, 0 em = -1, 0 em2 = -1, 0 for i, v in enumerate(o): if v >= om[1]: om2 = om om = i, v elif v >= om2[1]: om2 = i, v for i, v in enumerate(e): if v >= em[1]: em2 = em em = i, v elif v >= em2[1]: em2 = i, v if om[0] == em[0]: print(min(n - om2[1] - em[1], n - om[1] - em2[1])) else: print(n - om[1] - em[1])
Statement A sequence a_1,a_2,... ,a_n is said to be /\/\/\/ when the following conditions are satisfied: * For each i = 1,2,..., n-2, a_i = a_{i+2}. * Exactly two different numbers appear in the sequence. You are given a sequence v_1,v_2,...,v_n whose length is even. We would like to make this sequence /\/\/\/ by replacing some of its elements. Find the minimum number of elements that needs to be replaced.
[{"input": "4\n 3 1 3 2", "output": "1\n \n\nThe sequence 3,1,3,2 is not /\\/\\/\\/, but we can make it /\\/\\/\\/ by replacing\none of its elements: for example, replace the fourth element to make it\n3,1,3,1.\n\n* * *"}, {"input": "6\n 105 119 105 119 105 119", "output": "0\n \n\nThe sequence 105,119,105,119,105,119 is /\\/\\/\\/.\n\n* * *"}, {"input": "4\n 1 1 1 1", "output": "2\n \n\nThe elements of the sequence 1,1,1,1 are all the same, so it is not /\\/\\/\\/."}]
Print the minimum number of elements that needs to be replaced. * * *
s605681646
Accepted
p03246
Input is given from Standard Input in the following format: n v_1 v_2 ... v_n
from collections import defaultdict def getN(): return int(input()) def getMN(): a = input().split() b = [int(i) for i in a] return b[0], b[1] def getlist(): a = input().split() b = [int(i) for i in a] return b n = getN() nums = getlist() lis1 = defaultdict(int) lis2 = defaultdict(int) for i, s in enumerate(nums): if i % 2 == 0: lis1[s] += 1 else: lis2[s] += 1 maxk1 = [] maxv1 = 0 for k in lis1.keys(): if lis1[k] == maxv1: maxk1.append(k) elif lis1[k] > maxv1: maxv1 = lis1[k] maxk1 = [k] maxk2 = [] maxv2 = 0 for k in lis2.keys(): if lis2[k] == maxv2: maxk2.append(k) elif lis2[k] > maxv2: maxv2 = lis2[k] maxk2 = [k] v1 = list(lis1.values()) v1.sort(reverse=True) v1 = v1 + [0] v2 = list(lis2.values()) v2.sort(reverse=True) v2 = v2 + [0] if (len(maxk1) == 1) and (len(maxk2) == 1) and (maxk1[0] == maxk2[0]): rem = max(v1[0] + v2[1], v2[0] + v1[1]) ans = n - rem else: ans = n - maxv1 - maxv2 print(ans)
Statement A sequence a_1,a_2,... ,a_n is said to be /\/\/\/ when the following conditions are satisfied: * For each i = 1,2,..., n-2, a_i = a_{i+2}. * Exactly two different numbers appear in the sequence. You are given a sequence v_1,v_2,...,v_n whose length is even. We would like to make this sequence /\/\/\/ by replacing some of its elements. Find the minimum number of elements that needs to be replaced.
[{"input": "4\n 3 1 3 2", "output": "1\n \n\nThe sequence 3,1,3,2 is not /\\/\\/\\/, but we can make it /\\/\\/\\/ by replacing\none of its elements: for example, replace the fourth element to make it\n3,1,3,1.\n\n* * *"}, {"input": "6\n 105 119 105 119 105 119", "output": "0\n \n\nThe sequence 105,119,105,119,105,119 is /\\/\\/\\/.\n\n* * *"}, {"input": "4\n 1 1 1 1", "output": "2\n \n\nThe elements of the sequence 1,1,1,1 are all the same, so it is not /\\/\\/\\/."}]
Print the minimum number of elements that needs to be replaced. * * *
s722802999
Wrong Answer
p03246
Input is given from Standard Input in the following format: n v_1 v_2 ... v_n
import collections sequence_num = int(input()) count = 0 even_sequence_list = [] odd_sequence_list = [] sequence_list = list(map(int, input().split())) for i in range(sequence_num): if i % 2 == 0: even_sequence_list.append(sequence_list[i]) else: odd_sequence_list.append(sequence_list[i]) even_most_num = (collections.Counter(even_sequence_list)).most_common()[0][0] odd_most_num = (collections.Counter(odd_sequence_list)).most_common()[0][0] even_num_num = collections.Counter(even_sequence_list).most_common()[0][1] odd_num_num = collections.Counter(odd_sequence_list).most_common()[0][1] if even_most_num == odd_most_num: if even_num_num > odd_num_num: odd_most_num = collections.Counter(odd_sequence_list).most_common()[1][0] elif even_num_num < odd_num_num: even_most_num = collections.Counter(even_sequence_list).most_common()[1][0] else: even_most_num = 0 """ if collections.Counter(odd_sequence_list).most_common()[0][1] == len(odd_sequence_list): odd_most_num=0 else: odd_most_num=collections.Counter(odd_sequence_list).most_common()[1][0] """ for j in even_sequence_list: if j != even_most_num: count += 1 for k in odd_sequence_list: if k != odd_most_num: count += 1 print(count)
Statement A sequence a_1,a_2,... ,a_n is said to be /\/\/\/ when the following conditions are satisfied: * For each i = 1,2,..., n-2, a_i = a_{i+2}. * Exactly two different numbers appear in the sequence. You are given a sequence v_1,v_2,...,v_n whose length is even. We would like to make this sequence /\/\/\/ by replacing some of its elements. Find the minimum number of elements that needs to be replaced.
[{"input": "4\n 3 1 3 2", "output": "1\n \n\nThe sequence 3,1,3,2 is not /\\/\\/\\/, but we can make it /\\/\\/\\/ by replacing\none of its elements: for example, replace the fourth element to make it\n3,1,3,1.\n\n* * *"}, {"input": "6\n 105 119 105 119 105 119", "output": "0\n \n\nThe sequence 105,119,105,119,105,119 is /\\/\\/\\/.\n\n* * *"}, {"input": "4\n 1 1 1 1", "output": "2\n \n\nThe elements of the sequence 1,1,1,1 are all the same, so it is not /\\/\\/\\/."}]
Print the minimum number of elements that needs to be replaced. * * *
s117121212
Wrong Answer
p03246
Input is given from Standard Input in the following format: n v_1 v_2 ... v_n
n = input() v = input() v = v.split(" ") v = [int(i) for i in v] odd_v = v[::2] even_v = v[1::2] counter_odd = {} for i in odd_v: if not i in counter_odd: counter_odd[i] = 1 else: counter_odd[i] += 1 counter_even = {} for i in even_v: if not i in counter_even: counter_even[i] = 1 else: counter_even[i] += 1 max_odd = -1e100 max_odd_idx = 0 for k, v in counter_odd.items(): if max(v, max_odd) == v: max_odd = v max_odd_idx = k max_even = -1e100 max_even_idx = 0 for k, v in counter_even.items(): if max(v, max_even) == v: max_even = v max_even_idx = k should_change_odd = None if max_odd_idx == max_even_idx: if max_odd <= max_even: should_change_odd = True else: should_change_odd = False nb_change = 0 m = int(n) / 2 if should_change_odd is None: nb_change += m - max_odd nb_change += m - max_even elif should_change_odd is True: # 2nd largest item if len(counter_odd.items()) == 1: nb_change += m else: s = sorted(counter_odd.items(), key=lambda x: x[1])[0][1] nb_change += m - s nb_change += m - max_even elif should_change_odd is False: # 2nd largest item if len(counter_even.items()) == 1: nb_change += m else: s = sorted(counter_even.items(), key=lambda x: x[1])[0][1] nb_change += m - s nb_change += m - max_odd print(int(nb_change))
Statement A sequence a_1,a_2,... ,a_n is said to be /\/\/\/ when the following conditions are satisfied: * For each i = 1,2,..., n-2, a_i = a_{i+2}. * Exactly two different numbers appear in the sequence. You are given a sequence v_1,v_2,...,v_n whose length is even. We would like to make this sequence /\/\/\/ by replacing some of its elements. Find the minimum number of elements that needs to be replaced.
[{"input": "4\n 3 1 3 2", "output": "1\n \n\nThe sequence 3,1,3,2 is not /\\/\\/\\/, but we can make it /\\/\\/\\/ by replacing\none of its elements: for example, replace the fourth element to make it\n3,1,3,1.\n\n* * *"}, {"input": "6\n 105 119 105 119 105 119", "output": "0\n \n\nThe sequence 105,119,105,119,105,119 is /\\/\\/\\/.\n\n* * *"}, {"input": "4\n 1 1 1 1", "output": "2\n \n\nThe elements of the sequence 1,1,1,1 are all the same, so it is not /\\/\\/\\/."}]
Print the minimum number of elements that needs to be replaced. * * *
s848288002
Accepted
p03246
Input is given from Standard Input in the following format: n v_1 v_2 ... v_n
def s0(): return input() def s1(): return input().split() def s2(n): return [input() for x in range(n)] def s3(n): return [input().split() for _ in range(n)] def s4(n): return [[x for x in s] for s in s2(n)] def n0(): return int(input()) def n1(): return [int(x) for x in input().split()] def n2(n): return [int(input()) for _ in range(n)] def n3(n): return [[int(x) for x in input().split()] for _ in range(n)] def t3(n): return [tuple(int(x) for x in input().split()) for _ in range(n)] def p0(b, yes="Yes", no="No"): print(yes if b else no) # from sys import setrecursionlimit # setrecursionlimit(1000000) from collections import Counter, deque, defaultdict # import itertools # import math # import networkx as nx # from bisect import bisect_left,bisect_right # from heapq import heapify,heappush,heappop n = n0() V = n1() V0 = [V[i] for i in range(n) if i % 2 == 0] V1 = [V[i] for i in range(n) if i % 2 == 1] c0 = list(Counter(V0).items()) c1 = list(Counter(V1).items()) c0.sort(key=lambda x: -x[1]) c1.sort(key=lambda x: -x[1]) if c0[0][0] != c1[0][0]: ans = n - c0[0][1] - c1[0][1] else: if len(c0) == 1 or len(c1) == 1: if len(c0) == len(c1) == 1: ans = n - c0[0][1] elif len(c0) == 1: ans = n - c1[1][1] else: ans = n - c0[1][1] elif c0[0][1] > c1[0][1]: ans = n - c0[0][1] - c1[1][1] elif c0[0][1] < c1[0][1]: ans = n - c0[1][1] - c1[0][1] else: if c0[1][1] > c1[1][1]: ans = n - c0[1][1] - c1[0][1] else: ans = n - c0[0][1] - c1[1][1] print(ans)
Statement A sequence a_1,a_2,... ,a_n is said to be /\/\/\/ when the following conditions are satisfied: * For each i = 1,2,..., n-2, a_i = a_{i+2}. * Exactly two different numbers appear in the sequence. You are given a sequence v_1,v_2,...,v_n whose length is even. We would like to make this sequence /\/\/\/ by replacing some of its elements. Find the minimum number of elements that needs to be replaced.
[{"input": "4\n 3 1 3 2", "output": "1\n \n\nThe sequence 3,1,3,2 is not /\\/\\/\\/, but we can make it /\\/\\/\\/ by replacing\none of its elements: for example, replace the fourth element to make it\n3,1,3,1.\n\n* * *"}, {"input": "6\n 105 119 105 119 105 119", "output": "0\n \n\nThe sequence 105,119,105,119,105,119 is /\\/\\/\\/.\n\n* * *"}, {"input": "4\n 1 1 1 1", "output": "2\n \n\nThe elements of the sequence 1,1,1,1 are all the same, so it is not /\\/\\/\\/."}]
Print the minimum number of elements that needs to be replaced. * * *
s855120849
Accepted
p03246
Input is given from Standard Input in the following format: n v_1 v_2 ... v_n
from collections import defaultdict _ = input() ns = list(map(int, input().split())) # ns = [4, 1, 3, 2] xs = ns[0::2] ys = ns[1::2] ans = 0 counts = defaultdict(int) for x in xs: counts[x] += 1 max_numx = -1 max_x = -1 for key in counts.keys(): if counts[key] > max_numx: max_numx = counts[key] max_x = key del counts[max_x] if counts: max_numx2 = max(counts.values()) else: max_numx2 = 0 counts = defaultdict(int) for y in ys: counts[y] += 1 max_numy = -1 max_y = -1 for key in counts.keys(): if counts[key] > max_numy: max_numy = counts[key] max_y = key del counts[max_y] if counts: max_numy2 = max(counts.values()) else: max_numy2 = 0 if max_x != max_y: print(len(ns) - max_numx - max_numy) else: print(min(len(ns) - max_numx - max_numy2, len(ns) - max_numx2 - max_numy))
Statement A sequence a_1,a_2,... ,a_n is said to be /\/\/\/ when the following conditions are satisfied: * For each i = 1,2,..., n-2, a_i = a_{i+2}. * Exactly two different numbers appear in the sequence. You are given a sequence v_1,v_2,...,v_n whose length is even. We would like to make this sequence /\/\/\/ by replacing some of its elements. Find the minimum number of elements that needs to be replaced.
[{"input": "4\n 3 1 3 2", "output": "1\n \n\nThe sequence 3,1,3,2 is not /\\/\\/\\/, but we can make it /\\/\\/\\/ by replacing\none of its elements: for example, replace the fourth element to make it\n3,1,3,1.\n\n* * *"}, {"input": "6\n 105 119 105 119 105 119", "output": "0\n \n\nThe sequence 105,119,105,119,105,119 is /\\/\\/\\/.\n\n* * *"}, {"input": "4\n 1 1 1 1", "output": "2\n \n\nThe elements of the sequence 1,1,1,1 are all the same, so it is not /\\/\\/\\/."}]
Print the minimum number of elements that needs to be replaced. * * *
s065180907
Wrong Answer
p03246
Input is given from Standard Input in the following format: n v_1 v_2 ... v_n
n = int(input()) list_all = list(map(int, input().split())) ans = 0 list_even = [] list_odd = [] max_even = 0 max_odd = 0 for i in range(0, n, 2): list_odd.append(list_all[i]) for i in range(1, n, 2): list_even.append(list_all[i]) dic_odd = {} dic_even = {} li_odd = [0] li_even = [0] for i in list_odd: if i not in dic_odd: dic_odd[i] = 1 else: dic_odd[i] += 1 for i in list_even: if i not in dic_even: dic_even[i] = 1 else: dic_even[i] += 1 for i in dic_odd.keys(): if dic_odd[i] > max_odd: max_odd = i li_odd.append(dic_odd[i]) for i in dic_even.keys(): if i > max_even: max_even = i li_even.append(dic_even[i]) li_even.sort(reverse=True) li_odd.sort(reverse=True) if max_odd == max_even: print(n - li_even[0] - max(li_even[1], li_odd[1])) else: print(n - li_even[0] - li_odd[0])
Statement A sequence a_1,a_2,... ,a_n is said to be /\/\/\/ when the following conditions are satisfied: * For each i = 1,2,..., n-2, a_i = a_{i+2}. * Exactly two different numbers appear in the sequence. You are given a sequence v_1,v_2,...,v_n whose length is even. We would like to make this sequence /\/\/\/ by replacing some of its elements. Find the minimum number of elements that needs to be replaced.
[{"input": "4\n 3 1 3 2", "output": "1\n \n\nThe sequence 3,1,3,2 is not /\\/\\/\\/, but we can make it /\\/\\/\\/ by replacing\none of its elements: for example, replace the fourth element to make it\n3,1,3,1.\n\n* * *"}, {"input": "6\n 105 119 105 119 105 119", "output": "0\n \n\nThe sequence 105,119,105,119,105,119 is /\\/\\/\\/.\n\n* * *"}, {"input": "4\n 1 1 1 1", "output": "2\n \n\nThe elements of the sequence 1,1,1,1 are all the same, so it is not /\\/\\/\\/."}]
Print the minimum number of elements that needs to be replaced. * * *
s411191912
Wrong Answer
p03246
Input is given from Standard Input in the following format: n v_1 v_2 ... v_n
from sys import stdin import collections n, v_list = stdin.readlines() n = int(n.rstrip()) v_list = [int(v) for v in v_list.rstrip().split()] # print(n, v_list) v_list_odd = [v_list[i] for i in range(1, n, 2)] v_list_even = [v_list[i] for i in range(0, n, 2)] c_odd = collections.Counter(v_list_odd) c_even = collections.Counter(v_list_even) most_common_odd = c_odd.most_common() most_common_even = c_even.most_common() # print(most_common_even) # print(most_common_odd) if most_common_odd[0][0] == most_common_even[0][0]: print(n / 2) else: odd_cnt = most_common_odd[0][1] even_cnt = most_common_even[0][1] print(n - odd_cnt - even_cnt)
Statement A sequence a_1,a_2,... ,a_n is said to be /\/\/\/ when the following conditions are satisfied: * For each i = 1,2,..., n-2, a_i = a_{i+2}. * Exactly two different numbers appear in the sequence. You are given a sequence v_1,v_2,...,v_n whose length is even. We would like to make this sequence /\/\/\/ by replacing some of its elements. Find the minimum number of elements that needs to be replaced.
[{"input": "4\n 3 1 3 2", "output": "1\n \n\nThe sequence 3,1,3,2 is not /\\/\\/\\/, but we can make it /\\/\\/\\/ by replacing\none of its elements: for example, replace the fourth element to make it\n3,1,3,1.\n\n* * *"}, {"input": "6\n 105 119 105 119 105 119", "output": "0\n \n\nThe sequence 105,119,105,119,105,119 is /\\/\\/\\/.\n\n* * *"}, {"input": "4\n 1 1 1 1", "output": "2\n \n\nThe elements of the sequence 1,1,1,1 are all the same, so it is not /\\/\\/\\/."}]
Print the minimum number of elements that needs to be replaced. * * *
s730500193
Wrong Answer
p03246
Input is given from Standard Input in the following format: n v_1 v_2 ... v_n
def put(len=int(input()), arys=input()): return [int(_) for _ in arys.split(" ")] def solve(ary): if len(set(ary)) < 2: return len(ary) // 2 freq = {} nums = list(set(ary)) for _ in nums: freq[_] = ary.count(_) even, odd = [], [] for i, _ in enumerate(ary): if i % 2 == 0: even.append(_) else: odd.append(_) if odd[0] != even[0] and len(set(odd)) == len(set(even)): return 0 curr_max = 0 most_freq_key = 0 for n, f in freq.items(): if curr_max < f: curr_max = f most_freq_key = n freq.pop(most_freq_key) curr_max = 0 sec_freq_key = 0 for n, f in freq.items(): if curr_max < f: curr_max = f sec_freq_key = n e_size, o_size = len(even), len(odd) return min( e_size - even.count(most_freq_key) + o_size - odd.count(sec_freq_key), e_size - even.count(sec_freq_key) + o_size - odd.count(most_freq_key), ) print(solve(put()))
Statement A sequence a_1,a_2,... ,a_n is said to be /\/\/\/ when the following conditions are satisfied: * For each i = 1,2,..., n-2, a_i = a_{i+2}. * Exactly two different numbers appear in the sequence. You are given a sequence v_1,v_2,...,v_n whose length is even. We would like to make this sequence /\/\/\/ by replacing some of its elements. Find the minimum number of elements that needs to be replaced.
[{"input": "4\n 3 1 3 2", "output": "1\n \n\nThe sequence 3,1,3,2 is not /\\/\\/\\/, but we can make it /\\/\\/\\/ by replacing\none of its elements: for example, replace the fourth element to make it\n3,1,3,1.\n\n* * *"}, {"input": "6\n 105 119 105 119 105 119", "output": "0\n \n\nThe sequence 105,119,105,119,105,119 is /\\/\\/\\/.\n\n* * *"}, {"input": "4\n 1 1 1 1", "output": "2\n \n\nThe elements of the sequence 1,1,1,1 are all the same, so it is not /\\/\\/\\/."}]
Print the minimum number of elements that needs to be replaced. * * *
s075831997
Wrong Answer
p03246
Input is given from Standard Input in the following format: n v_1 v_2 ... v_n
#
Statement A sequence a_1,a_2,... ,a_n is said to be /\/\/\/ when the following conditions are satisfied: * For each i = 1,2,..., n-2, a_i = a_{i+2}. * Exactly two different numbers appear in the sequence. You are given a sequence v_1,v_2,...,v_n whose length is even. We would like to make this sequence /\/\/\/ by replacing some of its elements. Find the minimum number of elements that needs to be replaced.
[{"input": "4\n 3 1 3 2", "output": "1\n \n\nThe sequence 3,1,3,2 is not /\\/\\/\\/, but we can make it /\\/\\/\\/ by replacing\none of its elements: for example, replace the fourth element to make it\n3,1,3,1.\n\n* * *"}, {"input": "6\n 105 119 105 119 105 119", "output": "0\n \n\nThe sequence 105,119,105,119,105,119 is /\\/\\/\\/.\n\n* * *"}, {"input": "4\n 1 1 1 1", "output": "2\n \n\nThe elements of the sequence 1,1,1,1 are all the same, so it is not /\\/\\/\\/."}]
Print the minimum number of elements that needs to be replaced. * * *
s688624721
Accepted
p03246
Input is given from Standard Input in the following format: n v_1 v_2 ... v_n
#!/usr/bin/env python import string import sys from collections import Counter from itertools import chain, dropwhile, takewhile def read( *shape, f=int, it=chain.from_iterable(sys.stdin), whitespaces=set(string.whitespace) ): def read_word(): w = lambda c: c in whitespaces nw = lambda c: c not in whitespaces return f("".join(takewhile(nw, dropwhile(w, it)))) if not shape: return read_word() elif len(shape) == 1: return [read_word() for _ in range(shape[0])] elif len(shape) == 2: return [[read_word() for _ in range(shape[1])] for _ in range(shape[0])] def readi(*shape): return read(*shape) def readi1(*shape): return [i - 1 for i in read(*shape)] def readf(*shape): return read(*shape, f=float) def reads(*shape): return read(*shape, f=str) def arr(*shape, fill_value=0): if len(shape) == 1: return [fill_value] * shape[fill_value] elif len(shape) == 2: return [[fill_value] * shape[1] for _ in range(shape[0])] def dbg(**kwargs): print( ", ".join("{} = {}".format(k, repr(v)) for k, v in kwargs.items()), file=sys.stderr, ) def main(): n = readi() v = readi(n) l1 = v[::2] l2 = v[1::2] mc1 = Counter(l1).most_common() mc2 = Counter(l2).most_common() if mc1[0][0] != mc2[0][0]: print((n // 2 - mc1[0][1]) + (n // 2 - mc2[0][1])) else: if len(mc1) > 1 and len(mc2) == 1: print((n // 2 - mc1[1][1]) + (n // 2 - mc2[0][1])) elif len(mc1) == 1 and len(mc2) > 1: print((n // 2 - mc1[0][1]) + (n // 2 - mc2[1][1])) elif len(mc1) > 1 and len(mc2) > 1: print( min( (n // 2 - mc1[1][1]) + (n // 2 - mc2[0][1]), (n // 2 - mc1[0][1]) + (n // 2 - mc2[1][1]), ) ) else: print(n // 2) if __name__ == "__main__": main()
Statement A sequence a_1,a_2,... ,a_n is said to be /\/\/\/ when the following conditions are satisfied: * For each i = 1,2,..., n-2, a_i = a_{i+2}. * Exactly two different numbers appear in the sequence. You are given a sequence v_1,v_2,...,v_n whose length is even. We would like to make this sequence /\/\/\/ by replacing some of its elements. Find the minimum number of elements that needs to be replaced.
[{"input": "4\n 3 1 3 2", "output": "1\n \n\nThe sequence 3,1,3,2 is not /\\/\\/\\/, but we can make it /\\/\\/\\/ by replacing\none of its elements: for example, replace the fourth element to make it\n3,1,3,1.\n\n* * *"}, {"input": "6\n 105 119 105 119 105 119", "output": "0\n \n\nThe sequence 105,119,105,119,105,119 is /\\/\\/\\/.\n\n* * *"}, {"input": "4\n 1 1 1 1", "output": "2\n \n\nThe elements of the sequence 1,1,1,1 are all the same, so it is not /\\/\\/\\/."}]
Print the minimum number of elements that needs to be replaced. * * *
s492151406
Accepted
p03246
Input is given from Standard Input in the following format: n v_1 v_2 ... v_n
# -*- coding: utf-8 -*- import sys import math import os import itertools import string import heapq import _collections from collections import Counter from collections import defaultdict from functools import lru_cache import bisect import re import queue class Scanner: @staticmethod def int(): return int(sys.stdin.readline().rstrip()) @staticmethod def string(): return sys.stdin.readline().rstrip() @staticmethod def map_int(): return [int(x) for x in Scanner.string().split()] @staticmethod def string_list(n): return [input() for i in range(n)] @staticmethod def int_list_list(n): return [Scanner.map_int() for i in range(n)] @staticmethod def int_cols_list(n): return [int(input()) for i in range(n)] class Math: @staticmethod def gcd(a, b): if b == 0: return a return Math.gcd(b, a % b) @staticmethod def lcm(a, b): return (a * b) // Math.gcd(a, b) @staticmethod def roundUp(a, b): return -(-a // b) @staticmethod def toUpperMultiple(a, x): return Math.roundUp(a, x) * x @staticmethod def toLowerMultiple(a, x): return (a // x) * x @staticmethod def nearPow2(n): if n <= 0: return 0 if n & (n - 1) == 0: return n ret = 1 while n > 0: ret <<= 1 n >>= 1 return ret @staticmethod def sign(n): if n == 0: return 0 if n < 0: return -1 return 1 @staticmethod def isPrime(n): if n < 2: return False if n == 2: return True if n % 2 == 0: return False d = int(n**0.5) + 1 for i in range(3, d + 1, 2): if n % i == 0: return False return True class PriorityQueue: def __init__(self, l=[]): self.__q = l heapq.heapify(self.__q) return def push(self, n): heapq.heappush(self.__q, n) return def pop(self): return heapq.heappop(self.__q) MOD = int(1e09) + 7 INF = int(1e15) def calc(N): return sum(int(x) for x in str(N)) def main(): # sys.stdin = open("sample.txt") N = Scanner.int() V = Scanner.map_int() V_MAX = int(1e05) + 1 mode1, mode2 = [0] * V_MAX, [0] * V_MAX for i in range(N): if i % 2 == 0: mode1[V[i]] += 1 else: mode2[V[i]] += 1 m1, m2 = mode1.index(max(mode1)), mode2.index(max(mode2)) if not m1 == m2: ans = 0 for i in range(N): if i % 2 == 0: if V[i] != m1: ans += 1 else: if V[i] != m2: ans += 1 print(ans) return m3 = mode1.index(sorted(mode1)[-2]) if len(mode1) != 1 else -1 m4 = mode2.index(sorted(mode2)[-2]) if len(mode2) != 1 else -1 c1, c2, c3, c4 = 0, 0, 0, 0 for i in range(N): if i % 2 == 0: if V[i] != m1: c1 += 1 if V[i] != m3: c3 += 1 else: if V[i] != m2: c2 += 1 if V[i] != m4: c4 += 1 print(min(c1 + c4, c2 + c3)) return if __name__ == "__main__": main()
Statement A sequence a_1,a_2,... ,a_n is said to be /\/\/\/ when the following conditions are satisfied: * For each i = 1,2,..., n-2, a_i = a_{i+2}. * Exactly two different numbers appear in the sequence. You are given a sequence v_1,v_2,...,v_n whose length is even. We would like to make this sequence /\/\/\/ by replacing some of its elements. Find the minimum number of elements that needs to be replaced.
[{"input": "4\n 3 1 3 2", "output": "1\n \n\nThe sequence 3,1,3,2 is not /\\/\\/\\/, but we can make it /\\/\\/\\/ by replacing\none of its elements: for example, replace the fourth element to make it\n3,1,3,1.\n\n* * *"}, {"input": "6\n 105 119 105 119 105 119", "output": "0\n \n\nThe sequence 105,119,105,119,105,119 is /\\/\\/\\/.\n\n* * *"}, {"input": "4\n 1 1 1 1", "output": "2\n \n\nThe elements of the sequence 1,1,1,1 are all the same, so it is not /\\/\\/\\/."}]
Print the minimum number of elements that needs to be replaced. * * *
s900664774
Wrong Answer
p03246
Input is given from Standard Input in the following format: n v_1 v_2 ... v_n
def check_num(numlist, num): index = len(numlist) if num in numlist: indexs = [i for i, x in enumerate(numlist) if x == num] for i in range(len(indexs)): if indexs[i] % 2 == 0: index = indexs[i] if index == len(numlist): numlist.append(num) numlist.append(1) else: numlist[index + 1] += 1 return numlist input = [input() for i in range(2)] n = int(input[0]) input = list(map(int, input[1].split())) numlist = [] for i in range(n): numlist = check_num(numlist, input[i]) del numlist[::2] numlistlen = len(numlist) if numlistlen == 1: if n % 2 == 0: print(n // 2) else: print((n - 1) // 2) else: maxindex = numlist.index(max(numlist)) maxval = numlist[maxindex] del numlist[maxindex] # max_t_index = numlist.index(max(numlist)) # max_t_val = numlist[max_t_index] print(n - maxval - 1)
Statement A sequence a_1,a_2,... ,a_n is said to be /\/\/\/ when the following conditions are satisfied: * For each i = 1,2,..., n-2, a_i = a_{i+2}. * Exactly two different numbers appear in the sequence. You are given a sequence v_1,v_2,...,v_n whose length is even. We would like to make this sequence /\/\/\/ by replacing some of its elements. Find the minimum number of elements that needs to be replaced.
[{"input": "4\n 3 1 3 2", "output": "1\n \n\nThe sequence 3,1,3,2 is not /\\/\\/\\/, but we can make it /\\/\\/\\/ by replacing\none of its elements: for example, replace the fourth element to make it\n3,1,3,1.\n\n* * *"}, {"input": "6\n 105 119 105 119 105 119", "output": "0\n \n\nThe sequence 105,119,105,119,105,119 is /\\/\\/\\/.\n\n* * *"}, {"input": "4\n 1 1 1 1", "output": "2\n \n\nThe elements of the sequence 1,1,1,1 are all the same, so it is not /\\/\\/\\/."}]
Print the minimum number of elements that needs to be replaced. * * *
s380912529
Accepted
p03246
Input is given from Standard Input in the following format: n v_1 v_2 ... v_n
from statistics import mode from collections import Counter # S = input() n = int(input()) # N, K = map(int, input().split()) v = list(map(int, input().split())) # LR = [list(map(int, input().split())) for _ in range(M)] guu = [] kii = [] for i in range(n): if (i % 2) == 0: guu.append(v[i]) else: kii.append(v[i]) counterK = Counter(guu) guuMaxCount = counterK.most_common()[0][1] counterG = Counter(kii) kiiMaxCount = counterG.most_common()[0][1] if counterK.most_common()[0][0] == counterG.most_common()[0][0]: if n == 2: kiiMaxCount = 0 elif n == 3: kiiMaxCount = 0 elif n >= 4: if len(counterK.most_common()) >= 2 and len(counterG.most_common()) >= 2: if ( kiiMaxCount - counterK.most_common()[1][1] >= guuMaxCount - counterG.most_common()[1][1] ): guuMaxCount = counterG.most_common()[1][1] else: kiiMaxCount = counterK.most_common()[1][1] elif len(counterK.most_common()) >= 2 and len(counterG.most_common()) == 1: kiiMaxCount = kiiMaxCount = counterK.most_common()[1][1] elif len(counterK.most_common()) == 1 and len(counterG.most_common()) >= 2: guuMaxCount = counterG.most_common()[1][1] else: kiiMaxCount = 0 ans = n print(ans - guuMaxCount - kiiMaxCount)
Statement A sequence a_1,a_2,... ,a_n is said to be /\/\/\/ when the following conditions are satisfied: * For each i = 1,2,..., n-2, a_i = a_{i+2}. * Exactly two different numbers appear in the sequence. You are given a sequence v_1,v_2,...,v_n whose length is even. We would like to make this sequence /\/\/\/ by replacing some of its elements. Find the minimum number of elements that needs to be replaced.
[{"input": "4\n 3 1 3 2", "output": "1\n \n\nThe sequence 3,1,3,2 is not /\\/\\/\\/, but we can make it /\\/\\/\\/ by replacing\none of its elements: for example, replace the fourth element to make it\n3,1,3,1.\n\n* * *"}, {"input": "6\n 105 119 105 119 105 119", "output": "0\n \n\nThe sequence 105,119,105,119,105,119 is /\\/\\/\\/.\n\n* * *"}, {"input": "4\n 1 1 1 1", "output": "2\n \n\nThe elements of the sequence 1,1,1,1 are all the same, so it is not /\\/\\/\\/."}]
Print the minimum number of elements that needs to be replaced. * * *
s578298163
Wrong Answer
p03246
Input is given from Standard Input in the following format: n v_1 v_2 ... v_n
import numpy as np n = int(input()) v = np.array(list(map(int, input().split()))) v1 = v.reshape(n // 2, 2)[:, 0] v2 = v.reshape(n // 2, 2)[:, 1] v1_unique = np.unique(v1) v2_unique = np.unique(v2) # 先に数字次に個数(新居まで) maxs1 = [0, 0, 0, 0] ma = 0 for i in range(v1_unique.shape[0]): num = v1[v1 == v1_unique[i]].shape[0] if num > maxs1[1]: maxs1[0] = v1_unique[i] maxs1[1] = num elif num > maxs1[3]: maxs1[2] = v1_unique[i] maxs1[3] = num maxs2 = [0, 0, 0, 0] for i in range(v2_unique.shape[0]): num = v2[v2 == v2_unique[i]].shape[0] if num > maxs2[1]: maxs2[0] = v2_unique[i] maxs2[1] = num elif num > maxs2[3]: maxs2[2] = v2_unique[i] maxs2[3] = num if maxs1[0] != maxs2[0]: ma = n - maxs1[1] - maxs2[1] elif (maxs1[1] + maxs2[3]) > (maxs2[1] + maxs1[3]): ma = n - maxs1[1] - maxs2[3] else: ma = n - maxs2[1] - maxs1[3] print(ma)
Statement A sequence a_1,a_2,... ,a_n is said to be /\/\/\/ when the following conditions are satisfied: * For each i = 1,2,..., n-2, a_i = a_{i+2}. * Exactly two different numbers appear in the sequence. You are given a sequence v_1,v_2,...,v_n whose length is even. We would like to make this sequence /\/\/\/ by replacing some of its elements. Find the minimum number of elements that needs to be replaced.
[{"input": "4\n 3 1 3 2", "output": "1\n \n\nThe sequence 3,1,3,2 is not /\\/\\/\\/, but we can make it /\\/\\/\\/ by replacing\none of its elements: for example, replace the fourth element to make it\n3,1,3,1.\n\n* * *"}, {"input": "6\n 105 119 105 119 105 119", "output": "0\n \n\nThe sequence 105,119,105,119,105,119 is /\\/\\/\\/.\n\n* * *"}, {"input": "4\n 1 1 1 1", "output": "2\n \n\nThe elements of the sequence 1,1,1,1 are all the same, so it is not /\\/\\/\\/."}]
Print the minimum number of elements that needs to be replaced. * * *
s040977263
Wrong Answer
p03246
Input is given from Standard Input in the following format: n v_1 v_2 ... v_n
import sys from functools import lru_cache, cmp_to_key from heapq import merge, heapify, heappop, heappush from math import * from collections import defaultdict as dd, deque, Counter as C from itertools import combinations as comb, permutations as perm from bisect import bisect_left as bl, bisect_right as br, bisect from time import perf_counter from fractions import Fraction # sys.setrecursionlimit(int(pow(10, 2))) # sys.stdin = open("input.txt", "r") # sys.stdout = open("output.txt", "w") mod = int(pow(10, 9) + 7) mod2 = 998244353 def data(): return sys.stdin.readline().strip() def out(*var, end="\n"): sys.stdout.write(" ".join(map(str, var)) + end) def l(): return list(sp()) def sl(): return list(ssp()) def sp(): return map(int, data().split()) def ssp(): return map(str, data().split()) def l1d(n, val=0): return [val for i in range(n)] def l2d(n, m, val=0): return [l1d(n, val) for j in range(m)] # @lru_cache(None) n = l()[0] A = l() e = [] o = [] for i in range(n): if i % 2: o.append(A[i]) else: e.append(A[i]) d = {} for i in range(n // 2): if o[i] not in d: d[o[i]] = 0 d[o[i]] += 1 mx = [] for ks in d: mx.append([d[ks], ks]) mx.sort(reverse=True) d = {} for i in range(n // 2): if e[i] not in d: d[e[i]] = 0 d[e[i]] += 1 mx1 = [] for ks in d: mx1.append([d[ks], ks]) mx1.sort(reverse=True) if mx[0][1] != mx1[0][1]: print(n - mx[0][0] - mx1[0][0]) elif mx[0][0] > mx1[0][0]: if len(mx1) == 1: print(n - mx[0][0]) else: print(n - mx[0][0] - mx1[1][0]) else: mx, mx1 = mx1, mx if len(mx1) == 1: print(n - mx[0][0]) else: print(n - mx[0][0] - mx1[1][0])
Statement A sequence a_1,a_2,... ,a_n is said to be /\/\/\/ when the following conditions are satisfied: * For each i = 1,2,..., n-2, a_i = a_{i+2}. * Exactly two different numbers appear in the sequence. You are given a sequence v_1,v_2,...,v_n whose length is even. We would like to make this sequence /\/\/\/ by replacing some of its elements. Find the minimum number of elements that needs to be replaced.
[{"input": "4\n 3 1 3 2", "output": "1\n \n\nThe sequence 3,1,3,2 is not /\\/\\/\\/, but we can make it /\\/\\/\\/ by replacing\none of its elements: for example, replace the fourth element to make it\n3,1,3,1.\n\n* * *"}, {"input": "6\n 105 119 105 119 105 119", "output": "0\n \n\nThe sequence 105,119,105,119,105,119 is /\\/\\/\\/.\n\n* * *"}, {"input": "4\n 1 1 1 1", "output": "2\n \n\nThe elements of the sequence 1,1,1,1 are all the same, so it is not /\\/\\/\\/."}]
Print the number of permutations that can be produced as P after the operation. * * *
s043577589
Accepted
p02904
Input is given from Standard Input in the following format: N K P_0 P_1 \cdots P_{N-1}
N, K = list(map(int, input().split())) P = list(map(int, input().split())) class BITmax: ini = 0 def __init__(s, num): s.N = 1 while s.N <= num: s.N *= 2 s.T = [s.ini] * s.N def set(s, L): for i in range(len(L)): s.update(i, L[i]) def update(s, t, x): k = t s.T[k - 1] = max(s.T[k - 1], x) k += k & -k while k <= s.N: s.T[k - 1] = max(s.T[k - 1], x) k += k & -k def getV(s, x): ans = s.T[x - 1] x -= x & -x while x != 0: ans = max(ans, s.T[x - 1]) x -= x & -x return ans class BITmin: ini = N def __init__(s, num): s.N = 1 while s.N <= num: s.N *= 2 s.T = [s.ini] * s.N def set(s, L): for i in range(len(L)): s.update(i, L[i]) def update(s, t, x): k = t s.T[k - 1] = min(s.T[k - 1], x) k += k & -k while k <= s.N: s.T[k - 1] = min(s.T[k - 1], x) k += k & -k def getV(s, x): ans = s.T[x - 1] x -= x & -x while x != 0: ans = min(ans, s.T[x - 1]) x -= x & -x return ans MA = BITmax(N) MI = BITmin(N) La = [0] * N Li = [0] * N for i in range(K - 1): t = N - i MA.update(t, P[t - 1]) MI.update(t, P[t - 1]) for i in range(K - 2, N): t = N - i MA.update(t, P[t - 1]) MI.update(t, P[t - 1]) La[t - 1] = MA.getV(t + K - 2) Li[t - 1] = MI.getV(t + K - 2) T = [0] * N cnt = 0 t = 0 for i in range(1, N): if P[i] > P[i - 1]: cnt += 1 if cnt >= K - 1: T[i - K + 1] = 1 t += 1 else: cnt = 0 if t != 0: t -= 1 for i in range(N - K): if T[i] == 1: continue if Li[i + 1] > P[i] and La[i + 1] < P[i + K]: t += 1 print(N - K - t + 1)
Statement Snuke has a permutation (P_0,P_1,\cdots,P_{N-1}) of (0,1,\cdots,N-1). Now, he will perform the following operation **exactly once** : * Choose K consecutive elements in P and sort them in ascending order. Find the number of permutations that can be produced as P after the operation.
[{"input": "5 3\n 0 2 1 4 3", "output": "2\n \n\nTwo permutations can be produced as P after the operation: (0,1,2,4,3) and\n(0,2,1,3,4).\n\n* * *"}, {"input": "4 4\n 0 1 2 3", "output": "1\n \n\n* * *"}, {"input": "10 4\n 2 0 1 3 7 5 4 6 8 9", "output": "6"}]
Print the number of permutations that can be produced as P after the operation. * * *
s581779408
Wrong Answer
p02904
Input is given from Standard Input in the following format: N K P_0 P_1 \cdots P_{N-1}
N, K = (int(i) for i in input().split()) n = [int(x) for x in input().split()] c = 1 for i in range(N - K): for j in range(K - 1): if n[i] - n[i + j + 1] < 0: c += 1 break print(c)
Statement Snuke has a permutation (P_0,P_1,\cdots,P_{N-1}) of (0,1,\cdots,N-1). Now, he will perform the following operation **exactly once** : * Choose K consecutive elements in P and sort them in ascending order. Find the number of permutations that can be produced as P after the operation.
[{"input": "5 3\n 0 2 1 4 3", "output": "2\n \n\nTwo permutations can be produced as P after the operation: (0,1,2,4,3) and\n(0,2,1,3,4).\n\n* * *"}, {"input": "4 4\n 0 1 2 3", "output": "1\n \n\n* * *"}, {"input": "10 4\n 2 0 1 3 7 5 4 6 8 9", "output": "6"}]
Print the number of permutations that can be produced as P after the operation. * * *
s510805599
Wrong Answer
p02904
Input is given from Standard Input in the following format: N K P_0 P_1 \cdots P_{N-1}
import unittest import collections def solve(n, k, ps): if n == k: return 1 valid_point = [False] * (n + k + 1) valid = [0] * (n + k + 1) for i in range(n - 1): if ps[i] > ps[i + 1]: valid_point[i + 1] = True valid[i] -= 1 valid[i + k - 1] += 1 for i in range(n + k - 1, -1, -1): valid[i] += valid[i + 1] min_dq = collections.deque() max_dq = collections.deque() min_dq.append(0) max_dq.append(0) for i in range(1, k - 1): if min_dq[0] < i - k + 1: min_dq.popleft() while min_dq and ps[min_dq[-1]] >= ps[i]: min_dq.pop() min_dq.append(i) if max_dq[0] < i - k + 1: max_dq.popleft() while max_dq and ps[max_dq[-1]] <= ps[i]: max_dq.pop() max_dq.append(i) pre_min = min_dq[0] pre_max = max_dq[0] cnt = 0 has_zero = False for i in range(k - 1, n): pre_min = ps[min_dq[0]] pre_max = ps[max_dq[0]] if min_dq[0] < i - k + 1: min_dq.popleft() while min_dq and ps[min_dq[-1]] >= ps[i]: min_dq.pop() min_dq.append(i) if max_dq[0] < i - k + 1: max_dq.popleft() while max_dq and ps[max_dq[-1]] <= ps[i]: max_dq.pop() max_dq.append(i) if valid[i] != 0: if cnt == 0: cnt += 1 continue if ( cnt == 0 or valid[i - 1] != valid[i] or (pre_max != ps[i - 1] and ps[min_dq[0]] != ps[i - k + 1]) or (pre_min != ps[i - k] and ps[max_dq[0]] != ps[i]) ): if pre_min == ps[i - k] and max_dq[0] == i: continue cnt += 1 else: has_zero = True if has_zero: cnt += 1 return cnt def main(): n, k = map(int, input().split()) ps = list(map(int, input().split())) print(solve(n, k, ps)) class TestAcd038B(unittest.TestCase): def test_agc038b(self): self.assertEqual(solve(5, 3, list(map(int, "0 2 1 4 3".split()))), 2) self.assertEqual(solve(4, 4, list(map(int, "0 1 2 3".split()))), 1) self.assertEqual(solve(10, 4, list(map(int, "2 0 1 3 7 5 4 6 8 9".split()))), 6) self.assertEqual(solve(10, 2, list(map(int, "1 2 3 4 5 6 7 8 9 0".split()))), 2) self.assertEqual(solve(10, 4, list(map(int, "0 1 2 4 3 5 6 8 7 9".split()))), 3) if __name__ == "__main__": # main() unittest.main()
Statement Snuke has a permutation (P_0,P_1,\cdots,P_{N-1}) of (0,1,\cdots,N-1). Now, he will perform the following operation **exactly once** : * Choose K consecutive elements in P and sort them in ascending order. Find the number of permutations that can be produced as P after the operation.
[{"input": "5 3\n 0 2 1 4 3", "output": "2\n \n\nTwo permutations can be produced as P after the operation: (0,1,2,4,3) and\n(0,2,1,3,4).\n\n* * *"}, {"input": "4 4\n 0 1 2 3", "output": "1\n \n\n* * *"}, {"input": "10 4\n 2 0 1 3 7 5 4 6 8 9", "output": "6"}]
Print the number of permutations that can be produced as P after the operation. * * *
s932880456
Runtime Error
p02904
Input is given from Standard Input in the following format: N K P_0 P_1 \cdots P_{N-1}
from heapq import heappush, heappop N, K, *P = map(int, open("0").read().split()) mhq = [] Mhq = [] for c in P[:K]: heappush(mhq, c) heappush(Mhq, -c) ans = 1 log = set() for i, c in enumerate(P[K:]): while mhq[0] in log: heappop(mhq) while -Mhq[0] in log: heappop(Mhq) d = P[i] m = mhq[0] M = -Mhq[0] log.add(d) heappush(mhq, c) heappush(Mhq, -c) if not (m == d and M < c): ans += 1 p = P[0] m = 1 x = 0 for c in P[1:]: if p < c: m += 1 else: if m >= K: x += 1 m = 1 p = c if m >= K: x += 1 print(ans - x + 1)
Statement Snuke has a permutation (P_0,P_1,\cdots,P_{N-1}) of (0,1,\cdots,N-1). Now, he will perform the following operation **exactly once** : * Choose K consecutive elements in P and sort them in ascending order. Find the number of permutations that can be produced as P after the operation.
[{"input": "5 3\n 0 2 1 4 3", "output": "2\n \n\nTwo permutations can be produced as P after the operation: (0,1,2,4,3) and\n(0,2,1,3,4).\n\n* * *"}, {"input": "4 4\n 0 1 2 3", "output": "1\n \n\n* * *"}, {"input": "10 4\n 2 0 1 3 7 5 4 6 8 9", "output": "6"}]
Print the number of permutations that can be produced as P after the operation. * * *
s174759417
Wrong Answer
p02904
Input is given from Standard Input in the following format: N K P_0 P_1 \cdots P_{N-1}
1
Statement Snuke has a permutation (P_0,P_1,\cdots,P_{N-1}) of (0,1,\cdots,N-1). Now, he will perform the following operation **exactly once** : * Choose K consecutive elements in P and sort them in ascending order. Find the number of permutations that can be produced as P after the operation.
[{"input": "5 3\n 0 2 1 4 3", "output": "2\n \n\nTwo permutations can be produced as P after the operation: (0,1,2,4,3) and\n(0,2,1,3,4).\n\n* * *"}, {"input": "4 4\n 0 1 2 3", "output": "1\n \n\n* * *"}, {"input": "10 4\n 2 0 1 3 7 5 4 6 8 9", "output": "6"}]
Print the number of permutations that can be produced as P after the operation. * * *
s172051759
Runtime Error
p02904
Input is given from Standard Input in the following format: N K P_0 P_1 \cdots P_{N-1}
import sys input = sys.stdin.readline sys.setrecursionlimit(pow(10, 6)) def dfs(digd, tmpk): if tmpk == k: ans = {} for i in range(n): tmp = 0 for dig in v[i]: if tmp + digd[int(dig)] > len(w[i]): return False, {} elif int(dig) not in ans: ans[int(dig)] = w[i][tmp : tmp + digd[int(dig)]] tmp += digd[int(dig)] else: if ans[int(dig)] != w[i][tmp : tmp + digd[int(dig)]]: return False, {} else: tmp += digd[int(dig)] if tmp != len(w[i]): return False, {} return True, ans else: for i in range(1, 4): digd[tmpk + 1] = i is_finished, ans = dfs(digd, tmpk + 1) if is_finished: return True, ans return False, {} k, n = map(int, input().split()) v, w = [], [] for _ in range(n): _v, _w = input().strip().split() v.append(_v) w.append(_w) digd = {} _, ans = dfs(digd, 0) for i in range(1, k + 1): print(ans[i])
Statement Snuke has a permutation (P_0,P_1,\cdots,P_{N-1}) of (0,1,\cdots,N-1). Now, he will perform the following operation **exactly once** : * Choose K consecutive elements in P and sort them in ascending order. Find the number of permutations that can be produced as P after the operation.
[{"input": "5 3\n 0 2 1 4 3", "output": "2\n \n\nTwo permutations can be produced as P after the operation: (0,1,2,4,3) and\n(0,2,1,3,4).\n\n* * *"}, {"input": "4 4\n 0 1 2 3", "output": "1\n \n\n* * *"}, {"input": "10 4\n 2 0 1 3 7 5 4 6 8 9", "output": "6"}]
Print the number of permutations that can be produced as P after the operation. * * *
s374470305
Runtime Error
p02904
Input is given from Standard Input in the following format: N K P_0 P_1 \cdots P_{N-1}
class MinSlideWindow: def __init__(self, p): self.pos_list = [] self.val_list = p def put(self, pos): val = self.val_list[pos] while len(self.pos_list) > 0: pos1 = self.pos_list[-1] val1 = self.val_list[pos1] if val1 >= val: del self.pos_list[-1] else: break self.pos_list.append(pos) def get(self, pos): while len(self.pos_list) > 0: pos1 = self.pos_list[0] if pos1 <= pos: del self.pos_list[0] else: break def min(self): pos1 = self.pos_list[0] val1 = self.val_list[pos1] return val1 class MaxSlideWindow: def __init__(self, p): self.pos_list = [] self.val_list = p def put(self, pos): val = self.val_list[pos] while len(self.pos_list) > 0: pos1 = self.pos_list[-1] val1 = self.val_list[pos1] if val1 <= val: del self.pos_list[-1] else: break self.pos_list.append(pos) def get(self, pos): while len(self.pos_list) > 0: pos1 = self.pos_list[0] if pos1 <= pos: del self.pos_list[0] else: break def max(self): pos1 = self.pos_list[0] val1 = self.val_list[pos1] return val1 s = input().split(" ") n = int(s[0]) k = int(s[1]) sp = input().split(" ") p = [int(pstr) for pstr in sp] num = 0 ident = False before_sort = False minw = MinSlideWindow maxw = MaxSlideWindow before_sort_i = 0 for i in range(k - 2): minw.put(i) maxw.put(i) for i in range(n - k + 1): maxw.put(i + k - 2) maxw.get(i - 1) minw.put(i + k - 2) minw.get(i - 1) if before_sort: if p[i + k - 1] < p[i + k - 2]: num += 1 before_sort = False else: before_sort_i += 1 continue else: if before_sort_i + k <= i or i <= k: for j in range(k - 1): if p[i + j] > p[i + j + 1]: break else: if not ident: ident = True num += 1 before_sort = True before_sort_i = i continue if i == 0: num += 1 continue if p[i - 1] > minw.min() or p[i + k - 1] < maxw.max(): num += 1 else: if p[i - 1] > minw.min() or p[i + k - 1] < maxw.max(): num += 1 if p[i + k - 1] < p[i + k - 2]: before_sort_i = i - 1 print(num)
Statement Snuke has a permutation (P_0,P_1,\cdots,P_{N-1}) of (0,1,\cdots,N-1). Now, he will perform the following operation **exactly once** : * Choose K consecutive elements in P and sort them in ascending order. Find the number of permutations that can be produced as P after the operation.
[{"input": "5 3\n 0 2 1 4 3", "output": "2\n \n\nTwo permutations can be produced as P after the operation: (0,1,2,4,3) and\n(0,2,1,3,4).\n\n* * *"}, {"input": "4 4\n 0 1 2 3", "output": "1\n \n\n* * *"}, {"input": "10 4\n 2 0 1 3 7 5 4 6 8 9", "output": "6"}]
Print the number of permutations that can be produced as P after the operation. * * *
s720832993
Runtime Error
p02904
Input is given from Standard Input in the following format: N K P_0 P_1 \cdots P_{N-1}
N, K = [int(i) for i in input().split()] data = [int(i) for i in input().split()] point = 1 x = -1 y = data[0] i = 0 m = 1 while i < len(data) - 1: while x > y: m += 1 i += 1 x, y = y, data[i] if m != 1: point += m + min(m, K) - 3 m = 1 i += 1 x, y = y, data[i] print(point)
Statement Snuke has a permutation (P_0,P_1,\cdots,P_{N-1}) of (0,1,\cdots,N-1). Now, he will perform the following operation **exactly once** : * Choose K consecutive elements in P and sort them in ascending order. Find the number of permutations that can be produced as P after the operation.
[{"input": "5 3\n 0 2 1 4 3", "output": "2\n \n\nTwo permutations can be produced as P after the operation: (0,1,2,4,3) and\n(0,2,1,3,4).\n\n* * *"}, {"input": "4 4\n 0 1 2 3", "output": "1\n \n\n* * *"}, {"input": "10 4\n 2 0 1 3 7 5 4 6 8 9", "output": "6"}]
Print the number of permutations that can be produced as P after the operation. * * *
s240973038
Runtime Error
p02904
Input is given from Standard Input in the following format: N K P_0 P_1 \cdots P_{N-1}
H, W, A, B = map(int, input().split()) a = [] for i in range(H - 1): for i in range(W - 1): a += [0]
Statement Snuke has a permutation (P_0,P_1,\cdots,P_{N-1}) of (0,1,\cdots,N-1). Now, he will perform the following operation **exactly once** : * Choose K consecutive elements in P and sort them in ascending order. Find the number of permutations that can be produced as P after the operation.
[{"input": "5 3\n 0 2 1 4 3", "output": "2\n \n\nTwo permutations can be produced as P after the operation: (0,1,2,4,3) and\n(0,2,1,3,4).\n\n* * *"}, {"input": "4 4\n 0 1 2 3", "output": "1\n \n\n* * *"}, {"input": "10 4\n 2 0 1 3 7 5 4 6 8 9", "output": "6"}]
Print the number of permutations that can be produced as P after the operation. * * *
s133627593
Wrong Answer
p02904
Input is given from Standard Input in the following format: N K P_0 P_1 \cdots P_{N-1}
n, k = map(int, input().split()) p_list = list(map(int, input().split())) counter = 1 for i in range(n - k): if ( (p_list[i] < min(p_list[i + 1 : i + k])) and (p_list[i + k] > max(p_list[i + 1 : i + k])) ) or p_list[i : i + k] == sorted(p_list[i : i + k]): counter += 0 else: counter += 1 print(counter)
Statement Snuke has a permutation (P_0,P_1,\cdots,P_{N-1}) of (0,1,\cdots,N-1). Now, he will perform the following operation **exactly once** : * Choose K consecutive elements in P and sort them in ascending order. Find the number of permutations that can be produced as P after the operation.
[{"input": "5 3\n 0 2 1 4 3", "output": "2\n \n\nTwo permutations can be produced as P after the operation: (0,1,2,4,3) and\n(0,2,1,3,4).\n\n* * *"}, {"input": "4 4\n 0 1 2 3", "output": "1\n \n\n* * *"}, {"input": "10 4\n 2 0 1 3 7 5 4 6 8 9", "output": "6"}]
Print the number of permutations that can be produced as P after the operation. * * *
s054357984
Wrong Answer
p02904
Input is given from Standard Input in the following format: N K P_0 P_1 \cdots P_{N-1}
a = list(map(int, input().split())) b = list(map(int, input().split())) n = 0 count = 0 for i in range(a[0] - a[1]): cnt = 0 flg = 0 for v in range(a[1]): if b[i + v] > b[i + v + 1]: flg = 1 count += flg if count == 0: count = 1 print(count)
Statement Snuke has a permutation (P_0,P_1,\cdots,P_{N-1}) of (0,1,\cdots,N-1). Now, he will perform the following operation **exactly once** : * Choose K consecutive elements in P and sort them in ascending order. Find the number of permutations that can be produced as P after the operation.
[{"input": "5 3\n 0 2 1 4 3", "output": "2\n \n\nTwo permutations can be produced as P after the operation: (0,1,2,4,3) and\n(0,2,1,3,4).\n\n* * *"}, {"input": "4 4\n 0 1 2 3", "output": "1\n \n\n* * *"}, {"input": "10 4\n 2 0 1 3 7 5 4 6 8 9", "output": "6"}]
Print the number of permutations that can be produced as P after the operation. * * *
s627257374
Accepted
p02904
Input is given from Standard Input in the following format: N K P_0 P_1 \cdots P_{N-1}
from heapq import heapify, heappush, heappop def solve(): N, K = map(int, input().split()) Ps = list(map(int, input().split())) ans = N - K + 1 numAsc = 0 num = 0 P0 = -1 for P in Ps + [-1]: if P0 < P: num += 1 else: if num >= K: numAsc += num - K + 1 num = 1 P0 = P if numAsc > 0: ans -= numAsc - 1 if K > 2: mins = [N] * N P = min(Ps[: K + 1]) mins[0] = P PQ = [(P, i) for i, P in enumerate(Ps[: K + 1])] heapify(PQ) for i in range(K + 1, N): heappush(PQ, (Ps[i], i)) while True: P, pos = heappop(PQ) if i - K <= pos: mins[i - K] = P heappush(PQ, (P, pos)) break maxs = [-1] * N P = max(Ps[: K + 1]) maxs[0] = P PQ = [(-P, i) for i, P in enumerate(Ps[: K + 1])] heapify(PQ) for i in range(K + 1, N): heappush(PQ, (-Ps[i], i)) while True: P, pos = heappop(PQ) if i - K <= pos: maxs[i - K] = -P heappush(PQ, (P, pos)) break isSorteds = [False] * N num = 0 P0 = -1 for i, P in enumerate(Ps + [-1]): if P0 < P: num += 1 if num >= K - 1: isSorteds[i - K + 1] = True ### else: if num >= K: numAsc += num - K + 1 num = 1 P0 = P for i in range(N - K): L, R = Ps[i], Ps[i + K] minK, maxK = mins[i], maxs[i] if L == minK and R == maxK and not isSorteds[i]: ans -= 1 print(ans) solve()
Statement Snuke has a permutation (P_0,P_1,\cdots,P_{N-1}) of (0,1,\cdots,N-1). Now, he will perform the following operation **exactly once** : * Choose K consecutive elements in P and sort them in ascending order. Find the number of permutations that can be produced as P after the operation.
[{"input": "5 3\n 0 2 1 4 3", "output": "2\n \n\nTwo permutations can be produced as P after the operation: (0,1,2,4,3) and\n(0,2,1,3,4).\n\n* * *"}, {"input": "4 4\n 0 1 2 3", "output": "1\n \n\n* * *"}, {"input": "10 4\n 2 0 1 3 7 5 4 6 8 9", "output": "6"}]
Print the number of permutations that can be produced as P after the operation. * * *
s865269712
Accepted
p02904
Input is given from Standard Input in the following format: N K P_0 P_1 \cdots P_{N-1}
n, k = map(int, input().split()) l = list(map(int, input().split())) sc = 0 ans = n - k + 1 INF = n + 1 No = 2 while No < n: No *= 2 tree = [[0, 0]] * (2 * No) for i in range(No - 1, No - 1 + n): tree[i] = [l[i - No + 1], l[i - No + 1]] for i in range(No - 2, -1, -1): a, b = tree[i * 2 + 1] c, d = tree[i * 2 + 2] tree[i] = [max(a, c), min(b, d)] def query(l, r): L = l + No - 1 R = r + No - 1 s = [-INF, INF] while L <= R: if R & 1: a, b = tree[R] c, d = s s = [max(a, c), min(b, d)] R -= 2 else: R -= 1 if L & 1: L -= 1 else: a, b = tree[L] c, d = s s = [max(a, c), min(b, d)] L >>= 1 R >>= 1 return s class unionfind: def __init__(self, n): self.n = n self.root = [-1] * (n + 1) self.rnk = [0] * (n + 1) def find(self, x): if self.root[x] < 0: return x else: self.root[x] = self.find(self.root[x]) return self.root[x] def unite(self, x, y): x = self.find(x) y = self.find(y) if x == y: return elif self.rnk[x] > self.rnk[y]: self.root[x] += self.root[y] self.root[y] = x else: self.root[y] += self.root[x] self.root[x] = y if self.rnk[x] == self.rnk[y]: self.rnk[y] += 1 def same(self, x, y): return self.find(x) == self.find(y) def count(self, x): return -self.root[self.find(x)] uf = unionfind(n) s = set() t = 1 for i in range(n - 1): if l[i] < l[i + 1]: t += 1 else: t = 1 if t >= k: s.add(i - k + 2) if len(s) > 1: a = s.pop() while s: uf.unite(a, s.pop()) for i in range(n - k): b, a = query(i, i + k) if l[i] == a and l[i + k] == b: uf.unite(i, i + 1) s = set() for i in range(n - k + 1): s.add(uf.find(i)) print(len(s))
Statement Snuke has a permutation (P_0,P_1,\cdots,P_{N-1}) of (0,1,\cdots,N-1). Now, he will perform the following operation **exactly once** : * Choose K consecutive elements in P and sort them in ascending order. Find the number of permutations that can be produced as P after the operation.
[{"input": "5 3\n 0 2 1 4 3", "output": "2\n \n\nTwo permutations can be produced as P after the operation: (0,1,2,4,3) and\n(0,2,1,3,4).\n\n* * *"}, {"input": "4 4\n 0 1 2 3", "output": "1\n \n\n* * *"}, {"input": "10 4\n 2 0 1 3 7 5 4 6 8 9", "output": "6"}]
Print the number of permutations that can be produced as P after the operation. * * *
s980512734
Wrong Answer
p02904
Input is given from Standard Input in the following format: N K P_0 P_1 \cdots P_{N-1}
INF = 10**30 class Rmax: def __init__(self, size): # the number of nodes is 2n-1 self.n = 1 while self.n < size: self.n *= 2 self.node = [-INF] * (2 * self.n - 1) def Access(self, x): return self.node[x + self.n - 1] def Update(self, x, val): x += self.n - 1 self.node[x] = val while x > 0: x = (x - 1) // 2 self.node[x] = max(self.node[2 * x + 1], self.node[2 * x + 2]) return # [l, r) def Get(self, l, r): L, R = l + self.n, r + self.n s = -INF while L < R: if R & 1: R -= 1 s = max(s, self.node[R - 1]) if L & 1: s = max(s, self.node[L - 1]) L += 1 L >>= 1 R >>= 1 return s class Rmin: def __init__(self, size): # the number of nodes is 2n-1 self.n = 1 while self.n < size: self.n *= 2 self.node = [INF] * (2 * self.n - 1) def Access(self, x): return self.node[x + self.n - 1] def Update(self, x, val): x += self.n - 1 self.node[x] = val while x > 0: x = (x - 1) // 2 self.node[x] = min(self.node[2 * x + 1], self.node[2 * x + 2]) return # [l, r) def Get(self, l, r): L, R = l + self.n, r + self.n s = INF while L < R: if R & 1: R -= 1 s = min(s, self.node[R - 1]) if L & 1: s = min(s, self.node[L - 1]) L += 1 L >>= 1 R >>= 1 return s n, k = map(int, input().split()) p = list(map(int, input().split())) ma, mi = Rmax(n), Rmin(n) for i in range(n): ma.Update(i, p[i]) mi.Update(i, p[i]) ans = n - k + 1 tmp, cnt = 0, 0 for i in range(1, n): if p[i - 1] < p[i]: tmp += 1 else: tmp = 0 if tmp >= k - 1: cnt += 1 ans -= max(0, cnt - 1) for i in range(k, n): if p[i - k] < mi.Get(i - k + 1, i) and ma.Get(i - k + 1, i) < p[i]: ans -= 1 print(ans)
Statement Snuke has a permutation (P_0,P_1,\cdots,P_{N-1}) of (0,1,\cdots,N-1). Now, he will perform the following operation **exactly once** : * Choose K consecutive elements in P and sort them in ascending order. Find the number of permutations that can be produced as P after the operation.
[{"input": "5 3\n 0 2 1 4 3", "output": "2\n \n\nTwo permutations can be produced as P after the operation: (0,1,2,4,3) and\n(0,2,1,3,4).\n\n* * *"}, {"input": "4 4\n 0 1 2 3", "output": "1\n \n\n* * *"}, {"input": "10 4\n 2 0 1 3 7 5 4 6 8 9", "output": "6"}]
For each query, print the answer in its own line. * * *
s183442738
Runtime Error
p03616
The input is given from Standard Input in the following format: X K r_1 r_2 .. r_K Q t_1 a_1 t_2 a_2 : t_Q a_Q
def read_data_f(filename="arc082-e.dat"): try: LOCAL_FLAG import codecs import os lines = [] file_path = os.path.join(os.path.dirname(__file__), filename) with codecs.open(file_path, "r", "utf-8") as f: for each in f: lines.append(each.rstrip("\r\n")) except NameError: lines = [] lines.append(input()) lines.append(input()) lines.append(input()) lines.append(input()) Q = int(lines[3]) for i in range(Q): lines.append(input()) return lines def F_Sandglass(): # # 180 # 3 # 60 120 180 # 3 # 30 90 # 61 1 # 180 180 raw_data = read_data_f("arc082-f.dat") X = int(raw_data[0]) K = int(raw_data[1]) r = list(map(int, raw_data[2].split())) Q = int(raw_data[3]) a = [] t = [] for i in range(Q): tt, aa = list(map(int, raw_data[i + 4].split())) a.append(aa) t.append(tt) # print(r) # print(t) # print(a) time = 0 i = j = 0 U = X L = 0 c = 0 isUp = True time_diff = 0 r.append(2000000000) t.append(1) while (i < K + 1) and (time < t[Q - 1]): while time <= t[j] and t[j] < r[i]: time_diff_temp = t[j] - time if isUp: c_temp = max(c - time_diff_temp, -X) U_temp = U L_temp = L if (L + c_temp) < 0: L_temp = min(L + time_diff_temp, X) else: c_temp = min(c + time_diff_temp, X) U_temp = U if (U + c_temp) > X: U_temp = max(U - time_diff_temp, 0) L_temp = L if a[j] > U_temp: print(min(U_temp + c_temp, X)) elif a[j] < L_temp: print(max(L_temp + c_temp, 0)) else: print(a[j] + c_temp) j += 1 time_diff = r[i] - time if isUp: c = max(c - time_diff, -X) if (L + c) < 0: L = -c if L > U: U = L else: c = min(c + time_diff, X) if (U + c) > X: U = X - c if L > U: L = U time = r[i] isUp = not isUp i += 1 # result = remain(X, A[start_time], t[j] - start_time, start_status) # print(result) F_Sandglass()
Statement We have a sandglass consisting of two bulbs, bulb A and bulb B. These bulbs contain some amount of sand. When we put the sandglass, either bulb A or B lies on top of the other and becomes the _upper bulb_. The other bulb becomes the _lower bulb_. The sand drops from the upper bulb to the lower bulb at a rate of 1 gram per second. When the upper bulb no longer contains any sand, nothing happens. Initially at time 0, bulb A is the upper bulb and contains a grams of sand; bulb B contains X-a grams of sand (for a total of X grams). We will turn over the sandglass at time r_1,r_2,..,r_K. Assume that this is an instantaneous action and takes no time. Here, time t refer to the time t seconds after time 0. You are given Q queries. Each query is in the form of (t_i,a_i). For each query, assume that a=a_i and find the amount of sand that would be contained in bulb A at time t_i.
[{"input": "180\n 3\n 60 120 180\n 3\n 30 90\n 61 1\n 180 180", "output": "60\n 1\n 120\n \n\nIn the first query, 30 out of the initial 90 grams of sand will drop from bulb\nA, resulting in 60 grams. In the second query, the initial 1 gram of sand will\ndrop from bulb A, and nothing will happen for the next 59 seconds. Then, we\nwill turn over the sandglass, and 1 second after this, bulb A contains 1 gram\nof sand at the time in question.\n\n* * *"}, {"input": "100\n 1\n 100000\n 4\n 0 100\n 90 100\n 100 100\n 101 100", "output": "100\n 10\n 0\n 0\n \n\nIn every query, the upper bulb initially contains 100 grams, and the question\nin time comes before we turn over the sandglass.\n\n* * *"}, {"input": "100\n 5\n 48 141 231 314 425\n 7\n 0 19\n 50 98\n 143 30\n 231 55\n 342 0\n 365 100\n 600 10", "output": "19\n 52\n 91\n 10\n 58\n 42\n 100"}]
For each query, print the answer in its own line. * * *
s003919337
Runtime Error
p03616
The input is given from Standard Input in the following format: X K r_1 r_2 .. r_K Q t_1 a_1 t_2 a_2 : t_Q a_Q
# coding: utf-8 def II(): return int(input()) def ILI(): return list(map(int, input().split())) def read(): X = II() K = II() r = ILI() Q = II() queries = [ILI() for __ in range(Q)] return X, K, r, Q, queries def solve(X, K, r, Q, queries): l_ans = [] r.insert(0, 0) dif_r = [r[i + 1] - r[i] for i in range(K)] for i in range(K): if i % 2 == 1: dif_r[i] = -dif_r[i] print(dif_r) # dif_r.append(10 ** 9) for query in queries: t, a = query dif_r_ind = 0 now_state = 0 now_time = 0 ans = a while True: if now_time + dif_r[dif_r_ind] > t: if now_state == 1: ans += t - now_time ans = min(X, ans) else: ans -= t - now_time ans = max(0, ans) break else: if now_state == 1: ans += dif_r[dif_r_ind] ans = min(X, ans) else: ans -= dif_r[dif_r_ind] ans = max(0, ans) now_time += dif_r[dif_r_ind] now_state = (now_state + 1) % 2 dif_r_ind += 1 continue l_ans.append(ans) ans = "\n".join(map(str, l_ans)) return ans def main(): params = read() print(solve(*params)) if __name__ == "__main__": main()
Statement We have a sandglass consisting of two bulbs, bulb A and bulb B. These bulbs contain some amount of sand. When we put the sandglass, either bulb A or B lies on top of the other and becomes the _upper bulb_. The other bulb becomes the _lower bulb_. The sand drops from the upper bulb to the lower bulb at a rate of 1 gram per second. When the upper bulb no longer contains any sand, nothing happens. Initially at time 0, bulb A is the upper bulb and contains a grams of sand; bulb B contains X-a grams of sand (for a total of X grams). We will turn over the sandglass at time r_1,r_2,..,r_K. Assume that this is an instantaneous action and takes no time. Here, time t refer to the time t seconds after time 0. You are given Q queries. Each query is in the form of (t_i,a_i). For each query, assume that a=a_i and find the amount of sand that would be contained in bulb A at time t_i.
[{"input": "180\n 3\n 60 120 180\n 3\n 30 90\n 61 1\n 180 180", "output": "60\n 1\n 120\n \n\nIn the first query, 30 out of the initial 90 grams of sand will drop from bulb\nA, resulting in 60 grams. In the second query, the initial 1 gram of sand will\ndrop from bulb A, and nothing will happen for the next 59 seconds. Then, we\nwill turn over the sandglass, and 1 second after this, bulb A contains 1 gram\nof sand at the time in question.\n\n* * *"}, {"input": "100\n 1\n 100000\n 4\n 0 100\n 90 100\n 100 100\n 101 100", "output": "100\n 10\n 0\n 0\n \n\nIn every query, the upper bulb initially contains 100 grams, and the question\nin time comes before we turn over the sandglass.\n\n* * *"}, {"input": "100\n 5\n 48 141 231 314 425\n 7\n 0 19\n 50 98\n 143 30\n 231 55\n 342 0\n 365 100\n 600 10", "output": "19\n 52\n 91\n 10\n 58\n 42\n 100"}]
For each insert operation, print the number of elements in $S$. For each find operation, print the number of specified elements in $S$. For each dump operation, print the corresponding elements in ascending order. Print an element in a line.
s961587120
Wrong Answer
p02457
The input is given in the following format. $q$ $query_1$ $query_2$ : $query_q$ Each query $query_i$ is given by 0 $x$ or 1 $x$ or 2 $x$ or 3 $L$ $R$ where the first digits 0, 1, 2 and 3 represent insert, find, delete and dump operations respectively.
# AOJ ITP2_7_C: Set: Range Search # Python3 2018.6.24 bal4u from bisect import bisect_left, bisect_right, insort_left dict = {} keytbl = [] cnt = 0 q = int(input()) for i in range(q): a = list(input().split()) ki = int(a[1]) if a[0] == "0": if ki not in dict: dict[ki] = 1 cnt += 1 insort_left(keytbl, ki) print(cnt) elif a[0] == "1": print(dict[ki] if ki in dict else 0) elif a[0] == "2": if ki in dict: cnt -= dict[ki] dict[ki] = 0 else: L = bisect_left(keytbl, int(a[1])) R = bisect_right(keytbl, int(a[2]), L) for j in range(L, R): if dict[keytbl[j]] == 1: print(keytbl[j])
Set: Range Search For a set $S$ of integers, perform a sequence of the following operations. Note that _each value in $S$ must be unique_. * insert($x$): Insert $x$ to $S$ and report the number of elements in $S$ after the operation. * find($x$): Report the number of $x$ in $S$ (0 or 1). * delete($x$): Delete $x$ from $S$. * dump($L$, $R$): Print elements $x$ in $S$ such that $L \leq x \leq R$.
[{"input": "9\n 0 1\n 0 2\n 0 3\n 2 2\n 1 1\n 1 2\n 1 3\n 0 4\n 3 2 4", "output": "1\n 2\n 3\n 1\n 0\n 1\n 3\n 3\n 4"}]
For each insert operation, print the number of elements in $S$. For each find operation, print the number of specified elements in $S$. For each dump operation, print the corresponding elements in ascending order. Print an element in a line.
s017215090
Runtime Error
p02457
The input is given in the following format. $q$ $query_1$ $query_2$ : $query_q$ Each query $query_i$ is given by 0 $x$ or 1 $x$ or 2 $x$ or 3 $L$ $R$ where the first digits 0, 1, 2 and 3 represent insert, find, delete and dump operations respectively.
numset = set([]) q = int(input()) for i in range(q): q, *val = list(map(int, input().split(" "))) if q == 0: numset.add(val[0]) print(len(numset)) elif q == 1: rst = 1 if val[0] in numset else 0 print(rst) elif q == 2: if val[0] in numset: numset.remove(val[0]) elif q == 3: L, R = val ans = [] for n in numset: if L <= n and n <= R: ans.append(n) ans = sorted(ans) for num in ans: print(num)
Set: Range Search For a set $S$ of integers, perform a sequence of the following operations. Note that _each value in $S$ must be unique_. * insert($x$): Insert $x$ to $S$ and report the number of elements in $S$ after the operation. * find($x$): Report the number of $x$ in $S$ (0 or 1). * delete($x$): Delete $x$ from $S$. * dump($L$, $R$): Print elements $x$ in $S$ such that $L \leq x \leq R$.
[{"input": "9\n 0 1\n 0 2\n 0 3\n 2 2\n 1 1\n 1 2\n 1 3\n 0 4\n 3 2 4", "output": "1\n 2\n 3\n 1\n 0\n 1\n 3\n 3\n 4"}]
Print the desired string in one line. * * *
s035471289
Accepted
p03303
Input is given from Standard Input in the following format: S w
import math, string, itertools, fractions, heapq, collections, re, array, bisect, sys, copy, functools, random from collections import deque, defaultdict, Counter from heapq import heappush, heappop from itertools import permutations, combinations, product, accumulate, groupby from bisect import bisect_left, bisect_right, insort_left, insort_right from operator import itemgetter as ig sys.setrecursionlimit(10**7) inf = 10**20 INF = float("INF") ans = 0 tmp = 0 ansli = [] tmpli = [] candili = [] eps = 1.0 / 10**10 mod = 10**9 + 7 dd = [(-1, 0), (0, 1), (1, 0), (0, -1)] ddn = dd + [(-1, 1), (1, 1), (1, -1), (-1, -1)] ddn9 = ddn + [(0, 0)] """for dx, dy in dd: nx = j + dx; ny = i + dy if 0 <= nx < w and 0 <= ny < h:""" def wi(): return list(map(int, sys.stdin.readline().split())) def wip(): return [int(x) - 1 for x in sys.stdin.readline().split()] # WideIntPoint def ws(): return sys.stdin.readline().split() def i(): return int(sys.stdin.readline()) def s(): return input() def hi(n): return [i() for _ in range(n)] def hs(n): return [s() for _ in range(n)] # HeightString def mi(n): return [wi() for _ in range(n)] # MatrixInt def mip(n): return [wip() for _ in range(n)] def ms(n): return [ws() for _ in range(n)] s = s() w = i() cnt = 1 t = "" for i in range(len(s)): if (cnt - 1) % w == 0: t += s[i] cnt += 1 print(t)
Statement You are given a string S consisting of lowercase English letters. We will write down this string, starting a new line after every w letters. Print the string obtained by concatenating the letters at the beginnings of these lines from top to bottom.
[{"input": "abcdefgh\n 3", "output": "adg\n \n\nWhen we write down `abcdefgh`, starting a new line after every three letters,\nwe get the following:\n\nabc \ndef \ngh\n\nConcatenating the letters at the beginnings of these lines, we obtain `adg`.\n\n* * *"}, {"input": "lllll\n 1", "output": "lllll\n \n\n* * *"}, {"input": "souuundhound\n 2", "output": "suudon"}]
Print the desired string in one line. * * *
s771601231
Accepted
p03303
Input is given from Standard Input in the following format: S w
print(*(list(input())[:: int(input())]), sep="")
Statement You are given a string S consisting of lowercase English letters. We will write down this string, starting a new line after every w letters. Print the string obtained by concatenating the letters at the beginnings of these lines from top to bottom.
[{"input": "abcdefgh\n 3", "output": "adg\n \n\nWhen we write down `abcdefgh`, starting a new line after every three letters,\nwe get the following:\n\nabc \ndef \ngh\n\nConcatenating the letters at the beginnings of these lines, we obtain `adg`.\n\n* * *"}, {"input": "lllll\n 1", "output": "lllll\n \n\n* * *"}, {"input": "souuundhound\n 2", "output": "suudon"}]
Print the desired string in one line. * * *
s255037855
Accepted
p03303
Input is given from Standard Input in the following format: S w
S, W = (input() for T in range(0, 2)) print("".join(S[TW] for TW in range(0, len(S), int(W))))
Statement You are given a string S consisting of lowercase English letters. We will write down this string, starting a new line after every w letters. Print the string obtained by concatenating the letters at the beginnings of these lines from top to bottom.
[{"input": "abcdefgh\n 3", "output": "adg\n \n\nWhen we write down `abcdefgh`, starting a new line after every three letters,\nwe get the following:\n\nabc \ndef \ngh\n\nConcatenating the letters at the beginnings of these lines, we obtain `adg`.\n\n* * *"}, {"input": "lllll\n 1", "output": "lllll\n \n\n* * *"}, {"input": "souuundhound\n 2", "output": "suudon"}]
Print the desired string in one line. * * *
s110799073
Accepted
p03303
Input is given from Standard Input in the following format: S w
import sys stdin = sys.stdin inf = 1 << 60 mod = 1000000007 ni = lambda: int(ns()) nin = lambda y: [ni() for _ in range(y)] na = lambda: list(map(int, stdin.readline().split())) nan = lambda y: [na() for _ in range(y)] nf = lambda: float(ns()) nfn = lambda y: [nf() for _ in range(y)] nfa = lambda: list(map(float, stdin.readline().split())) nfan = lambda y: [nfa() for _ in range(y)] ns = lambda: stdin.readline().rstrip() nsn = lambda y: [ns() for _ in range(y)] ncl = lambda y: [list(ns()) for _ in range(y)] nas = lambda: stdin.readline().split() s = ns() w = ni() i = 0 while i < len(s): print(s[i], end="") i += w print()
Statement You are given a string S consisting of lowercase English letters. We will write down this string, starting a new line after every w letters. Print the string obtained by concatenating the letters at the beginnings of these lines from top to bottom.
[{"input": "abcdefgh\n 3", "output": "adg\n \n\nWhen we write down `abcdefgh`, starting a new line after every three letters,\nwe get the following:\n\nabc \ndef \ngh\n\nConcatenating the letters at the beginnings of these lines, we obtain `adg`.\n\n* * *"}, {"input": "lllll\n 1", "output": "lllll\n \n\n* * *"}, {"input": "souuundhound\n 2", "output": "suudon"}]
Print the desired string in one line. * * *
s486448293
Accepted
p03303
Input is given from Standard Input in the following format: S w
S = str(input("")) w = int(input("")) length = len(S) max_l = length // w if not length % w == 0: max_l += 1 words = "" for i in range(max_l): words += S[i * w] print(words)
Statement You are given a string S consisting of lowercase English letters. We will write down this string, starting a new line after every w letters. Print the string obtained by concatenating the letters at the beginnings of these lines from top to bottom.
[{"input": "abcdefgh\n 3", "output": "adg\n \n\nWhen we write down `abcdefgh`, starting a new line after every three letters,\nwe get the following:\n\nabc \ndef \ngh\n\nConcatenating the letters at the beginnings of these lines, we obtain `adg`.\n\n* * *"}, {"input": "lllll\n 1", "output": "lllll\n \n\n* * *"}, {"input": "souuundhound\n 2", "output": "suudon"}]
Print the desired string in one line. * * *
s236540176
Accepted
p03303
Input is given from Standard Input in the following format: S w
a = list(input()) b = int(input()) if len(a) % b == 0: for i in range(len(a) // b): print(a[i * (b)], end="") else: for i in range(len(a) // b + 1): print(a[i * (b)], end="")
Statement You are given a string S consisting of lowercase English letters. We will write down this string, starting a new line after every w letters. Print the string obtained by concatenating the letters at the beginnings of these lines from top to bottom.
[{"input": "abcdefgh\n 3", "output": "adg\n \n\nWhen we write down `abcdefgh`, starting a new line after every three letters,\nwe get the following:\n\nabc \ndef \ngh\n\nConcatenating the letters at the beginnings of these lines, we obtain `adg`.\n\n* * *"}, {"input": "lllll\n 1", "output": "lllll\n \n\n* * *"}, {"input": "souuundhound\n 2", "output": "suudon"}]
Print the desired string in one line. * * *
s508063658
Accepted
p03303
Input is given from Standard Input in the following format: S w
def getinputdata(): # 配列初期化 array_result = [] data = input() array_result.append(data.split(" ")) flg = 1 try: while flg: data = input() if data != "": array_result.append(data.split(" ")) else: flg = 0 finally: return array_result arr_data = getinputdata() s = arr_data[0][0] w = int(arr_data[1][0]) result = [s[i] for i in range(0, len(s), w)] print("".join(result))
Statement You are given a string S consisting of lowercase English letters. We will write down this string, starting a new line after every w letters. Print the string obtained by concatenating the letters at the beginnings of these lines from top to bottom.
[{"input": "abcdefgh\n 3", "output": "adg\n \n\nWhen we write down `abcdefgh`, starting a new line after every three letters,\nwe get the following:\n\nabc \ndef \ngh\n\nConcatenating the letters at the beginnings of these lines, we obtain `adg`.\n\n* * *"}, {"input": "lllll\n 1", "output": "lllll\n \n\n* * *"}, {"input": "souuundhound\n 2", "output": "suudon"}]
Print the desired string in one line. * * *
s746582393
Runtime Error
p03303
Input is given from Standard Input in the following format: S w
#include <map> #include <set> #include <list> #include <cmath> #include <queue> #include <stack> #include <cstdio> #include <string> #include <vector> #include <complex> #include <cstdlib> #include <cstring> #include <numeric> #include <sstream> #include <iostream> #include <algorithm> #include <functional> #include <unordered_map> #include <random> #include <iomanip> #define mp make_pair #define pb push_back #define all(x) (x).begin(),(x).end() #define rep(i,n) for(int i=0;i<(n);i++) using namespace std; typedef long long ll; typedef unsigned long long ull; typedef vector<bool> vb; typedef vector<int> vi; typedef vector<vb> vvb; typedef vector<vi> vvi; typedef pair<int,int> pii; const int INF=1<<29; const double EPS=1e-9; const int dx[]={1,0,-1,0,1,1,-1,-1},dy[]={0,-1,0,1,1,-1,-1,1}; int main() { string s; cin >> s; int N; cin >> N; for(int i = 0; i < s.size(); i += N) { cout << s[i]; } cout << endl; return 0; }
Statement You are given a string S consisting of lowercase English letters. We will write down this string, starting a new line after every w letters. Print the string obtained by concatenating the letters at the beginnings of these lines from top to bottom.
[{"input": "abcdefgh\n 3", "output": "adg\n \n\nWhen we write down `abcdefgh`, starting a new line after every three letters,\nwe get the following:\n\nabc \ndef \ngh\n\nConcatenating the letters at the beginnings of these lines, we obtain `adg`.\n\n* * *"}, {"input": "lllll\n 1", "output": "lllll\n \n\n* * *"}, {"input": "souuundhound\n 2", "output": "suudon"}]
Print the desired string in one line. * * *
s475731214
Runtime Error
p03303
Input is given from Standard Input in the following format: S w
#define _CRT_SECURE_NO_WARNINGS #define _USE_MATH_DEFINES #include <stdio.h> #include <string.h> #include <stdlib.h> #include <math.h> #include <iostream> #include <vector> #include <algorithm> #include <string> #include <functional> #include <stack> #include <queue> #include <cstdio> #include <cstdlib> #include <cstring> #include <list> #include <set> using namespace std; typedef long long ll; int main(int argc, char *args[]) { string s; int w; int i = 0; int counter = 1; cin >> s >> w; while (counter <= s.size()) { cout << s[0 + i * w]; i++; counter = counter + w; } cout << endl; }
Statement You are given a string S consisting of lowercase English letters. We will write down this string, starting a new line after every w letters. Print the string obtained by concatenating the letters at the beginnings of these lines from top to bottom.
[{"input": "abcdefgh\n 3", "output": "adg\n \n\nWhen we write down `abcdefgh`, starting a new line after every three letters,\nwe get the following:\n\nabc \ndef \ngh\n\nConcatenating the letters at the beginnings of these lines, we obtain `adg`.\n\n* * *"}, {"input": "lllll\n 1", "output": "lllll\n \n\n* * *"}, {"input": "souuundhound\n 2", "output": "suudon"}]
Print the desired string in one line. * * *
s490062342
Runtime Error
p03303
Input is given from Standard Input in the following format: S w
import java.util.*; import java.io.*; class Main { public static void main(String[] args) throws Exception{ try (Scanner sc = new Scanner(System.in)){ String s = sc.next(); int w = sc.nextInt(); String out = ""; for (int i = 0; i < s.length(); i += w) { out = out + s.substring(i,i+1); } System.out.print(out); } } }
Statement You are given a string S consisting of lowercase English letters. We will write down this string, starting a new line after every w letters. Print the string obtained by concatenating the letters at the beginnings of these lines from top to bottom.
[{"input": "abcdefgh\n 3", "output": "adg\n \n\nWhen we write down `abcdefgh`, starting a new line after every three letters,\nwe get the following:\n\nabc \ndef \ngh\n\nConcatenating the letters at the beginnings of these lines, we obtain `adg`.\n\n* * *"}, {"input": "lllll\n 1", "output": "lllll\n \n\n* * *"}, {"input": "souuundhound\n 2", "output": "suudon"}]
Print the desired string in one line. * * *
s663312045
Accepted
p03303
Input is given from Standard Input in the following format: S w
str = input() window = int(input()) print(str[::window])
Statement You are given a string S consisting of lowercase English letters. We will write down this string, starting a new line after every w letters. Print the string obtained by concatenating the letters at the beginnings of these lines from top to bottom.
[{"input": "abcdefgh\n 3", "output": "adg\n \n\nWhen we write down `abcdefgh`, starting a new line after every three letters,\nwe get the following:\n\nabc \ndef \ngh\n\nConcatenating the letters at the beginnings of these lines, we obtain `adg`.\n\n* * *"}, {"input": "lllll\n 1", "output": "lllll\n \n\n* * *"}, {"input": "souuundhound\n 2", "output": "suudon"}]
Print the desired string in one line. * * *
s678274060
Runtime Error
p03303
Input is given from Standard Input in the following format: S w
print(input()[::int(input())]
Statement You are given a string S consisting of lowercase English letters. We will write down this string, starting a new line after every w letters. Print the string obtained by concatenating the letters at the beginnings of these lines from top to bottom.
[{"input": "abcdefgh\n 3", "output": "adg\n \n\nWhen we write down `abcdefgh`, starting a new line after every three letters,\nwe get the following:\n\nabc \ndef \ngh\n\nConcatenating the letters at the beginnings of these lines, we obtain `adg`.\n\n* * *"}, {"input": "lllll\n 1", "output": "lllll\n \n\n* * *"}, {"input": "souuundhound\n 2", "output": "suudon"}]
Print the desired string in one line. * * *
s924792819
Accepted
p03303
Input is given from Standard Input in the following format: S w
n = input() s = int(input()) t = len(n) // s c = "" for i in range((t + 1 if len(n) % s != 0 else t)): c += n[i * s] print(c)
Statement You are given a string S consisting of lowercase English letters. We will write down this string, starting a new line after every w letters. Print the string obtained by concatenating the letters at the beginnings of these lines from top to bottom.
[{"input": "abcdefgh\n 3", "output": "adg\n \n\nWhen we write down `abcdefgh`, starting a new line after every three letters,\nwe get the following:\n\nabc \ndef \ngh\n\nConcatenating the letters at the beginnings of these lines, we obtain `adg`.\n\n* * *"}, {"input": "lllll\n 1", "output": "lllll\n \n\n* * *"}, {"input": "souuundhound\n 2", "output": "suudon"}]
Print the desired string in one line. * * *
s053959336
Runtime Error
p03303
Input is given from Standard Input in the following format: S w
s=input().split() num=int(input()) ans = [] for i <= len(s) in range(0, len(s) / num + 1): ans = ans.append(s[i]) print(ans)
Statement You are given a string S consisting of lowercase English letters. We will write down this string, starting a new line after every w letters. Print the string obtained by concatenating the letters at the beginnings of these lines from top to bottom.
[{"input": "abcdefgh\n 3", "output": "adg\n \n\nWhen we write down `abcdefgh`, starting a new line after every three letters,\nwe get the following:\n\nabc \ndef \ngh\n\nConcatenating the letters at the beginnings of these lines, we obtain `adg`.\n\n* * *"}, {"input": "lllll\n 1", "output": "lllll\n \n\n* * *"}, {"input": "souuundhound\n 2", "output": "suudon"}]
Print the desired string in one line. * * *
s108354836
Runtime Error
p03303
Input is given from Standard Input in the following format: S w
s, w = input().split(" ") w = int(w) k = 0 while k < len(s): print(s[k], end="") k += w print()
Statement You are given a string S consisting of lowercase English letters. We will write down this string, starting a new line after every w letters. Print the string obtained by concatenating the letters at the beginnings of these lines from top to bottom.
[{"input": "abcdefgh\n 3", "output": "adg\n \n\nWhen we write down `abcdefgh`, starting a new line after every three letters,\nwe get the following:\n\nabc \ndef \ngh\n\nConcatenating the letters at the beginnings of these lines, we obtain `adg`.\n\n* * *"}, {"input": "lllll\n 1", "output": "lllll\n \n\n* * *"}, {"input": "souuundhound\n 2", "output": "suudon"}]
If the date 2019-M_1-D_1 is the last day of a month, print `1`; otherwise, print `0`. * * *
s518670155
Accepted
p02841
Input is given from Standard Input in the following format: M_1 D_1 M_2 D_2
print(1 if input().split()[0] != input().split()[0] else 0)
Statement In this problem, a date is written as Y-M-D. For example, 2019-11-30 means November 30, 2019. Integers M_1, D_1, M_2, and D_2 will be given as input. It is known that the date 2019-M_2-D_2 follows 2019-M_1-D_1. Determine whether the date 2019-M_1-D_1 is the last day of a month.
[{"input": "11 16\n 11 17", "output": "0\n \n\nNovember 16 is not the last day of a month.\n\n* * *"}, {"input": "11 30\n 12 1", "output": "1\n \n\nNovember 30 is the last day of November."}]
If the date 2019-M_1-D_1 is the last day of a month, print `1`; otherwise, print `0`. * * *
s223208338
Wrong Answer
p02841
Input is given from Standard Input in the following format: M_1 D_1 M_2 D_2
print(+("1\n" in [*open(0)][1]))
Statement In this problem, a date is written as Y-M-D. For example, 2019-11-30 means November 30, 2019. Integers M_1, D_1, M_2, and D_2 will be given as input. It is known that the date 2019-M_2-D_2 follows 2019-M_1-D_1. Determine whether the date 2019-M_1-D_1 is the last day of a month.
[{"input": "11 16\n 11 17", "output": "0\n \n\nNovember 16 is not the last day of a month.\n\n* * *"}, {"input": "11 30\n 12 1", "output": "1\n \n\nNovember 30 is the last day of November."}]
If the date 2019-M_1-D_1 is the last day of a month, print `1`; otherwise, print `0`. * * *
s136535001
Runtime Error
p02841
Input is given from Standard Input in the following format: M_1 D_1 M_2 D_2
def is_cross(la, lb, x1, x2): ya1 = la[0] * x1 + la[1] ya2 = la[0] * x2 + la[1] yb1 = lb[0] * x1 + lb[1] yb2 = lb[0] * x2 + lb[1] if ya1 == yb1: return False return (ya1 - yb1) * (ya2 - yb2) <= 0 def get_line(c, x, y): return [c, y - c * x] t = list(map(int, input().split())) a = list(map(int, input().split())) b = list(map(int, input().split())) xa = sum([ti * ai for ti, ai in zip(t, a)]) xb = sum([ti * bi for ti, bi in zip(t, b)]) if xa / sum(t) == xb / sum(t): print("infinity") else: ans = 0 t_pre = 0 da = 0 db = 0 while True: ans_t = 0 for ti, ai, bi in zip(t, a, b): t_post = t_pre + ti la = get_line(ai, t_pre, da) lb = get_line(bi, t_pre, db) ans_t += is_cross(la, lb, t_pre, t_post) t_pre = t_post da += ti * ai db += ti * bi if ans_t == 0: break ans += ans_t print(ans)
Statement In this problem, a date is written as Y-M-D. For example, 2019-11-30 means November 30, 2019. Integers M_1, D_1, M_2, and D_2 will be given as input. It is known that the date 2019-M_2-D_2 follows 2019-M_1-D_1. Determine whether the date 2019-M_1-D_1 is the last day of a month.
[{"input": "11 16\n 11 17", "output": "0\n \n\nNovember 16 is not the last day of a month.\n\n* * *"}, {"input": "11 30\n 12 1", "output": "1\n \n\nNovember 30 is the last day of November."}]
If the date 2019-M_1-D_1 is the last day of a month, print `1`; otherwise, print `0`. * * *
s682216908
Runtime Error
p02841
Input is given from Standard Input in the following format: M_1 D_1 M_2 D_2
T1, T2 = map(int, input().split()) A1, A2 = map(int, input().split()) B1, B2 = map(int, input().split()) D1 = T1 * A1 - T1 * B1 D2 = T1 * A1 + T2 * A2 - T1 * B1 - T2 * B2 if D1 * D2 > 0: print(0) elif D2 == 0: print("infinity") else: c = 1 D1 = abs(D2 - D1) D2 = abs(D2) Dp = D2 while True: Dp += D2 if Dp > D1: break elif Dp == D1: c += 1 break c += 2 print(c)
Statement In this problem, a date is written as Y-M-D. For example, 2019-11-30 means November 30, 2019. Integers M_1, D_1, M_2, and D_2 will be given as input. It is known that the date 2019-M_2-D_2 follows 2019-M_1-D_1. Determine whether the date 2019-M_1-D_1 is the last day of a month.
[{"input": "11 16\n 11 17", "output": "0\n \n\nNovember 16 is not the last day of a month.\n\n* * *"}, {"input": "11 30\n 12 1", "output": "1\n \n\nNovember 30 is the last day of November."}]
If the date 2019-M_1-D_1 is the last day of a month, print `1`; otherwise, print `0`. * * *
s103549481
Runtime Error
p02841
Input is given from Standard Input in the following format: M_1 D_1 M_2 D_2
import math X = int(input()) i1 = math.floor(X / 100) for i in range(i1 + 1): for j in range(i1 - i + 1): for k in range(i1 - i - j + 1 + 1): for l in range(i1 - i - j - k + 1 + 1): for m in range(i1 - i - j - k - l + 1): for n in range(i1 - i - j - k - l - m + 1): if ( X == 100 * i + 101 * j + 102 * k + 103 * l + 104 * m + 105 * n ): print(1) exit() print(0)
Statement In this problem, a date is written as Y-M-D. For example, 2019-11-30 means November 30, 2019. Integers M_1, D_1, M_2, and D_2 will be given as input. It is known that the date 2019-M_2-D_2 follows 2019-M_1-D_1. Determine whether the date 2019-M_1-D_1 is the last day of a month.
[{"input": "11 16\n 11 17", "output": "0\n \n\nNovember 16 is not the last day of a month.\n\n* * *"}, {"input": "11 30\n 12 1", "output": "1\n \n\nNovember 30 is the last day of November."}]
If the date 2019-M_1-D_1 is the last day of a month, print `1`; otherwise, print `0`. * * *
s481151083
Accepted
p02841
Input is given from Standard Input in the following format: M_1 D_1 M_2 D_2
m1, d1 = map(int, input().strip().split(" ")) m2, d2 = map(int, input().strip().split(" ")) print("1" if m1 != m2 else "0")
Statement In this problem, a date is written as Y-M-D. For example, 2019-11-30 means November 30, 2019. Integers M_1, D_1, M_2, and D_2 will be given as input. It is known that the date 2019-M_2-D_2 follows 2019-M_1-D_1. Determine whether the date 2019-M_1-D_1 is the last day of a month.
[{"input": "11 16\n 11 17", "output": "0\n \n\nNovember 16 is not the last day of a month.\n\n* * *"}, {"input": "11 30\n 12 1", "output": "1\n \n\nNovember 30 is the last day of November."}]
If the date 2019-M_1-D_1 is the last day of a month, print `1`; otherwise, print `0`. * * *
s777740009
Accepted
p02841
Input is given from Standard Input in the following format: M_1 D_1 M_2 D_2
a, _, b, _ = map(int, open(0).read().split()) print(int(a != b))
Statement In this problem, a date is written as Y-M-D. For example, 2019-11-30 means November 30, 2019. Integers M_1, D_1, M_2, and D_2 will be given as input. It is known that the date 2019-M_2-D_2 follows 2019-M_1-D_1. Determine whether the date 2019-M_1-D_1 is the last day of a month.
[{"input": "11 16\n 11 17", "output": "0\n \n\nNovember 16 is not the last day of a month.\n\n* * *"}, {"input": "11 30\n 12 1", "output": "1\n \n\nNovember 30 is the last day of November."}]
If the date 2019-M_1-D_1 is the last day of a month, print `1`; otherwise, print `0`. * * *
s911946869
Accepted
p02841
Input is given from Standard Input in the following format: M_1 D_1 M_2 D_2
print(1 - (input()[:2] in input()))
Statement In this problem, a date is written as Y-M-D. For example, 2019-11-30 means November 30, 2019. Integers M_1, D_1, M_2, and D_2 will be given as input. It is known that the date 2019-M_2-D_2 follows 2019-M_1-D_1. Determine whether the date 2019-M_1-D_1 is the last day of a month.
[{"input": "11 16\n 11 17", "output": "0\n \n\nNovember 16 is not the last day of a month.\n\n* * *"}, {"input": "11 30\n 12 1", "output": "1\n \n\nNovember 30 is the last day of November."}]
If the date 2019-M_1-D_1 is the last day of a month, print `1`; otherwise, print `0`. * * *
s684887612
Accepted
p02841
Input is given from Standard Input in the following format: M_1 D_1 M_2 D_2
_ = input() print(int(input().split()[1] == "1"))
Statement In this problem, a date is written as Y-M-D. For example, 2019-11-30 means November 30, 2019. Integers M_1, D_1, M_2, and D_2 will be given as input. It is known that the date 2019-M_2-D_2 follows 2019-M_1-D_1. Determine whether the date 2019-M_1-D_1 is the last day of a month.
[{"input": "11 16\n 11 17", "output": "0\n \n\nNovember 16 is not the last day of a month.\n\n* * *"}, {"input": "11 30\n 12 1", "output": "1\n \n\nNovember 30 is the last day of November."}]
If the date 2019-M_1-D_1 is the last day of a month, print `1`; otherwise, print `0`. * * *
s440282675
Accepted
p02841
Input is given from Standard Input in the following format: M_1 D_1 M_2 D_2
print(int(input().split()[0] < input().split()[0]))
Statement In this problem, a date is written as Y-M-D. For example, 2019-11-30 means November 30, 2019. Integers M_1, D_1, M_2, and D_2 will be given as input. It is known that the date 2019-M_2-D_2 follows 2019-M_1-D_1. Determine whether the date 2019-M_1-D_1 is the last day of a month.
[{"input": "11 16\n 11 17", "output": "0\n \n\nNovember 16 is not the last day of a month.\n\n* * *"}, {"input": "11 30\n 12 1", "output": "1\n \n\nNovember 30 is the last day of November."}]
If the date 2019-M_1-D_1 is the last day of a month, print `1`; otherwise, print `0`. * * *
s579784615
Accepted
p02841
Input is given from Standard Input in the following format: M_1 D_1 M_2 D_2
M1, _, M2, _ = map(int, open(0).read().split()) print(M2 - M1)
Statement In this problem, a date is written as Y-M-D. For example, 2019-11-30 means November 30, 2019. Integers M_1, D_1, M_2, and D_2 will be given as input. It is known that the date 2019-M_2-D_2 follows 2019-M_1-D_1. Determine whether the date 2019-M_1-D_1 is the last day of a month.
[{"input": "11 16\n 11 17", "output": "0\n \n\nNovember 16 is not the last day of a month.\n\n* * *"}, {"input": "11 30\n 12 1", "output": "1\n \n\nNovember 30 is the last day of November."}]
If the date 2019-M_1-D_1 is the last day of a month, print `1`; otherwise, print `0`. * * *
s208331272
Accepted
p02841
Input is given from Standard Input in the following format: M_1 D_1 M_2 D_2
print( 1 if list(map(int, input().split()))[0] != list(map(int, input().split()))[0] else 0 )
Statement In this problem, a date is written as Y-M-D. For example, 2019-11-30 means November 30, 2019. Integers M_1, D_1, M_2, and D_2 will be given as input. It is known that the date 2019-M_2-D_2 follows 2019-M_1-D_1. Determine whether the date 2019-M_1-D_1 is the last day of a month.
[{"input": "11 16\n 11 17", "output": "0\n \n\nNovember 16 is not the last day of a month.\n\n* * *"}, {"input": "11 30\n 12 1", "output": "1\n \n\nNovember 30 is the last day of November."}]
If the date 2019-M_1-D_1 is the last day of a month, print `1`; otherwise, print `0`. * * *
s478907540
Runtime Error
p02841
Input is given from Standard Input in the following format: M_1 D_1 M_2 D_2
a = eval()
Statement In this problem, a date is written as Y-M-D. For example, 2019-11-30 means November 30, 2019. Integers M_1, D_1, M_2, and D_2 will be given as input. It is known that the date 2019-M_2-D_2 follows 2019-M_1-D_1. Determine whether the date 2019-M_1-D_1 is the last day of a month.
[{"input": "11 16\n 11 17", "output": "0\n \n\nNovember 16 is not the last day of a month.\n\n* * *"}, {"input": "11 30\n 12 1", "output": "1\n \n\nNovember 30 is the last day of November."}]