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
For each query, print "1" or "0".
s010790359
Accepted
p02294
The entire input looks like: q (the number of queries) 1st query 2nd query ... qth query Each query consists of integer coordinates of end points of s1 and s2 in the following format: xp0 yp0 xp1 yp1 xp2 yp2 xp3 yp3
def on_segment(u0, v0, u1, v1, u2, v2): return ( u1 <= max(u0, u2) and u1 >= min(u0, u2) and v1 <= max(v0, v2) and v1 >= min(v0, v2) ) def signed_area(x0, y0, x1, y1): return x0 * y1 - x1 * y0 q = int(input()) for _ in [0] * q: x0, y0, x1, y1, x2, y2, x3, y3 = map(int, input().split()) ta = signed_area(x1 - x0, y1 - y0, x2 - x0, y2 - y0) tb = signed_area(x1 - x0, y1 - y0, x3 - x0, y3 - y0) tc = signed_area(x3 - x2, y3 - y2, x0 - x2, y0 - y2) td = signed_area(x3 - x2, y3 - y2, x1 - x2, y1 - y2) """ print(ta/2) print(tb/2) print(tc/2) print(td/2) print(on_segment(x0,y0,x2,y2,x1,y1)) print(on_segment(x0,y0,x3,y3,x1,y1)) print(on_segment(x2,y2,x0,y0,x3,y3)) print(on_segment(x2,y2,x1,y1,x3,y3)) """ if ta * tb < 0 and tc * td < 0: print("1") elif ta == 0 and on_segment(x0, y0, x2, y2, x1, y1): print("1") elif tb == 0 and on_segment(x0, y0, x3, y3, x1, y1): print("1") elif tc == 0 and on_segment(x2, y2, x0, y0, x3, y3): print("1") elif td == 0 and on_segment(x2, y2, x1, y1, x3, y3): print("1") else: print("0")
Intersection For given two segments s1 and s2, print "1" if they are intersect, "0" otherwise. s1 is formed by end points p0 and p1, and s2 is formed by end points p2 and p3.
[{"input": "3\n 0 0 3 0 1 1 2 -1\n 0 0 3 0 3 1 3 -1\n 0 0 3 0 3 -2 5 0", "output": "1\n 1\n 0"}]
The output consists of $n$ lines. Print $c_i$ in a line.
s669173852
Accepted
p02410
In the first line, two integers $n$ and $m$ are given. In the following $n$ lines, $a_{ij}$ are given separated by a single space character. In the next $m$ lines, $b_i$ is given in a line.
num_nm = list(map(int, input().split())) A = [[0 for iA in range(num_nm[0])] for jA in range(num_nm[1])] b = [0 for ib in range(num_nm[1])] for i in range(num_nm[0]): num_A = list(map(int, input().split())) for j in range(num_nm[1]): A[j][i] = num_A[j] for k in range(num_nm[1]): num_b = int(input()) b[k] = num_b for l in range(num_nm[0]): ans_1 = 0 for m in range(num_nm[1]): ans_1 = ans_1 + A[m][l] * b[m] print(ans_1)
Matrix Vector Multiplication Write a program which reads a $ n \times m$ matrix $A$ and a $m \times 1$ vector $b$, and prints their product $Ab$. A column vector with m elements is represented by the following equation. \\[ b = \left( \begin{array}{c} b_1 \\\ b_2 \\\ : \\\ b_m \\\ \end{array} \right) \\] A $n \times m$ matrix with $m$ column vectors, each of which consists of $n$ elements, is represented by the following equation. \\[ A = \left( \begin{array}{cccc} a_{11} & a_{12} & ... & a_{1m} \\\ a_{21} & a_{22} & ... & a_{2m} \\\ : & : & : & : \\\ a_{n1} & a_{n2} & ... & a_{nm} \\\ \end{array} \right) \\] $i$-th element of a $m \times 1$ column vector $b$ is represented by $b_i$ ($i = 1, 2, ..., m$), and the element in $i$-th row and $j$-th column of a matrix $A$ is represented by $a_{ij}$ ($i = 1, 2, ..., n,$ $j = 1, 2, ..., m$). The product of a $n \times m$ matrix $A$ and a $m \times 1$ column vector $b$ is a $n \times 1$ column vector $c$, and $c_i$ is obtained by the following formula: \\[ c_i = \sum_{j=1}^m a_{ij}b_j = a_{i1}b_1 + a_{i2}b_2 + ... + a_{im}b_m \\]
[{"input": "4\n 1 2 0 1\n 0 3 0 1\n 4 1 1 0\n 1\n 2\n 3\n 0", "output": "6\n 9"}]
The output consists of $n$ lines. Print $c_i$ in a line.
s437456654
Accepted
p02410
In the first line, two integers $n$ and $m$ are given. In the following $n$ lines, $a_{ij}$ are given separated by a single space character. In the next $m$ lines, $b_i$ is given in a line.
n, m = map(int, input().split()) A = [[0 for aa in range(m)] for bb in range(n)] b = [0 for cc in range(m)] for zz in range(n): unko = list(map(int, input().split())) for yy in range(m): A[zz][yy] = unko[yy] for dd in range(m): b[dd] = int(input()) for aaa in range(n): ole = 0 for bbb in range(m): ole = ole + (A[aaa][bbb] * b[bbb]) print(ole)
Matrix Vector Multiplication Write a program which reads a $ n \times m$ matrix $A$ and a $m \times 1$ vector $b$, and prints their product $Ab$. A column vector with m elements is represented by the following equation. \\[ b = \left( \begin{array}{c} b_1 \\\ b_2 \\\ : \\\ b_m \\\ \end{array} \right) \\] A $n \times m$ matrix with $m$ column vectors, each of which consists of $n$ elements, is represented by the following equation. \\[ A = \left( \begin{array}{cccc} a_{11} & a_{12} & ... & a_{1m} \\\ a_{21} & a_{22} & ... & a_{2m} \\\ : & : & : & : \\\ a_{n1} & a_{n2} & ... & a_{nm} \\\ \end{array} \right) \\] $i$-th element of a $m \times 1$ column vector $b$ is represented by $b_i$ ($i = 1, 2, ..., m$), and the element in $i$-th row and $j$-th column of a matrix $A$ is represented by $a_{ij}$ ($i = 1, 2, ..., n,$ $j = 1, 2, ..., m$). The product of a $n \times m$ matrix $A$ and a $m \times 1$ column vector $b$ is a $n \times 1$ column vector $c$, and $c_i$ is obtained by the following formula: \\[ c_i = \sum_{j=1}^m a_{ij}b_j = a_{i1}b_1 + a_{i2}b_2 + ... + a_{im}b_m \\]
[{"input": "4\n 1 2 0 1\n 0 3 0 1\n 4 1 1 0\n 1\n 2\n 3\n 0", "output": "6\n 9"}]
The output consists of $n$ lines. Print $c_i$ in a line.
s686509475
Accepted
p02410
In the first line, two integers $n$ and $m$ are given. In the following $n$ lines, $a_{ij}$ are given separated by a single space character. In the next $m$ lines, $b_i$ is given in a line.
mn = input() mn = mn.split() m, n = int(mn[0]), int(mn[1]) A_array = list() for i in range(m): A = input() A = A.split() A_array.append(A) B_array = list() for j in range(n): b = input() B_array.append(int(b)) for i in A_array: result = 0 for A, B in zip(i, B_array): result += int(A) * int(B) else: print(result)
Matrix Vector Multiplication Write a program which reads a $ n \times m$ matrix $A$ and a $m \times 1$ vector $b$, and prints their product $Ab$. A column vector with m elements is represented by the following equation. \\[ b = \left( \begin{array}{c} b_1 \\\ b_2 \\\ : \\\ b_m \\\ \end{array} \right) \\] A $n \times m$ matrix with $m$ column vectors, each of which consists of $n$ elements, is represented by the following equation. \\[ A = \left( \begin{array}{cccc} a_{11} & a_{12} & ... & a_{1m} \\\ a_{21} & a_{22} & ... & a_{2m} \\\ : & : & : & : \\\ a_{n1} & a_{n2} & ... & a_{nm} \\\ \end{array} \right) \\] $i$-th element of a $m \times 1$ column vector $b$ is represented by $b_i$ ($i = 1, 2, ..., m$), and the element in $i$-th row and $j$-th column of a matrix $A$ is represented by $a_{ij}$ ($i = 1, 2, ..., n,$ $j = 1, 2, ..., m$). The product of a $n \times m$ matrix $A$ and a $m \times 1$ column vector $b$ is a $n \times 1$ column vector $c$, and $c_i$ is obtained by the following formula: \\[ c_i = \sum_{j=1}^m a_{ij}b_j = a_{i1}b_1 + a_{i2}b_2 + ... + a_{im}b_m \\]
[{"input": "4\n 1 2 0 1\n 0 3 0 1\n 4 1 1 0\n 1\n 2\n 3\n 0", "output": "6\n 9"}]
The output consists of $n$ lines. Print $c_i$ in a line.
s175400759
Wrong Answer
p02410
In the first line, two integers $n$ and $m$ are given. In the following $n$ lines, $a_{ij}$ are given separated by a single space character. In the next $m$ lines, $b_i$ is given in a line.
x, y = [int(i) for i in input().split()] date = [[int(i) for i in input().split()] for i in range(1, x + 1)] date2 = [int(input()) for i in range(1, y + 1)] date3 = [] for k in range(x): print(date[k]) print(date2) for a in range(0, x): for b in range(0, y): date3 += [date2[b] * date[a][b]] for h in range(0, len(date3) - 1): print(date3[h])
Matrix Vector Multiplication Write a program which reads a $ n \times m$ matrix $A$ and a $m \times 1$ vector $b$, and prints their product $Ab$. A column vector with m elements is represented by the following equation. \\[ b = \left( \begin{array}{c} b_1 \\\ b_2 \\\ : \\\ b_m \\\ \end{array} \right) \\] A $n \times m$ matrix with $m$ column vectors, each of which consists of $n$ elements, is represented by the following equation. \\[ A = \left( \begin{array}{cccc} a_{11} & a_{12} & ... & a_{1m} \\\ a_{21} & a_{22} & ... & a_{2m} \\\ : & : & : & : \\\ a_{n1} & a_{n2} & ... & a_{nm} \\\ \end{array} \right) \\] $i$-th element of a $m \times 1$ column vector $b$ is represented by $b_i$ ($i = 1, 2, ..., m$), and the element in $i$-th row and $j$-th column of a matrix $A$ is represented by $a_{ij}$ ($i = 1, 2, ..., n,$ $j = 1, 2, ..., m$). The product of a $n \times m$ matrix $A$ and a $m \times 1$ column vector $b$ is a $n \times 1$ column vector $c$, and $c_i$ is obtained by the following formula: \\[ c_i = \sum_{j=1}^m a_{ij}b_j = a_{i1}b_1 + a_{i2}b_2 + ... + a_{im}b_m \\]
[{"input": "4\n 1 2 0 1\n 0 3 0 1\n 4 1 1 0\n 1\n 2\n 3\n 0", "output": "6\n 9"}]
The output consists of $n$ lines. Print $c_i$ in a line.
s012986590
Accepted
p02410
In the first line, two integers $n$ and $m$ are given. In the following $n$ lines, $a_{ij}$ are given separated by a single space character. In the next $m$ lines, $b_i$ is given in a line.
n, m = map(int, input().split()) a = [input().split() for l in range(n)] b = [int(input()) for i in range(m)] du = 0 for v in range(n): for k in range(m): du += int(a[v][k]) * b[k] print(du) du = 0
Matrix Vector Multiplication Write a program which reads a $ n \times m$ matrix $A$ and a $m \times 1$ vector $b$, and prints their product $Ab$. A column vector with m elements is represented by the following equation. \\[ b = \left( \begin{array}{c} b_1 \\\ b_2 \\\ : \\\ b_m \\\ \end{array} \right) \\] A $n \times m$ matrix with $m$ column vectors, each of which consists of $n$ elements, is represented by the following equation. \\[ A = \left( \begin{array}{cccc} a_{11} & a_{12} & ... & a_{1m} \\\ a_{21} & a_{22} & ... & a_{2m} \\\ : & : & : & : \\\ a_{n1} & a_{n2} & ... & a_{nm} \\\ \end{array} \right) \\] $i$-th element of a $m \times 1$ column vector $b$ is represented by $b_i$ ($i = 1, 2, ..., m$), and the element in $i$-th row and $j$-th column of a matrix $A$ is represented by $a_{ij}$ ($i = 1, 2, ..., n,$ $j = 1, 2, ..., m$). The product of a $n \times m$ matrix $A$ and a $m \times 1$ column vector $b$ is a $n \times 1$ column vector $c$, and $c_i$ is obtained by the following formula: \\[ c_i = \sum_{j=1}^m a_{ij}b_j = a_{i1}b_1 + a_{i2}b_2 + ... + a_{im}b_m \\]
[{"input": "4\n 1 2 0 1\n 0 3 0 1\n 4 1 1 0\n 1\n 2\n 3\n 0", "output": "6\n 9"}]
The output consists of $n$ lines. Print $c_i$ in a line.
s451038298
Accepted
p02410
In the first line, two integers $n$ and $m$ are given. In the following $n$ lines, $a_{ij}$ are given separated by a single space character. In the next $m$ lines, $b_i$ is given in a line.
n, m = map(int, input().split()) kakeru = [list(map(int, input().split())) for _ in range(n)] kakerareru = [int(input()) for _ in range(m)] for a in range(n): kotae = 0 for b in range(m): kotae += kakeru[a][b] * kakerareru[b] print(kotae)
Matrix Vector Multiplication Write a program which reads a $ n \times m$ matrix $A$ and a $m \times 1$ vector $b$, and prints their product $Ab$. A column vector with m elements is represented by the following equation. \\[ b = \left( \begin{array}{c} b_1 \\\ b_2 \\\ : \\\ b_m \\\ \end{array} \right) \\] A $n \times m$ matrix with $m$ column vectors, each of which consists of $n$ elements, is represented by the following equation. \\[ A = \left( \begin{array}{cccc} a_{11} & a_{12} & ... & a_{1m} \\\ a_{21} & a_{22} & ... & a_{2m} \\\ : & : & : & : \\\ a_{n1} & a_{n2} & ... & a_{nm} \\\ \end{array} \right) \\] $i$-th element of a $m \times 1$ column vector $b$ is represented by $b_i$ ($i = 1, 2, ..., m$), and the element in $i$-th row and $j$-th column of a matrix $A$ is represented by $a_{ij}$ ($i = 1, 2, ..., n,$ $j = 1, 2, ..., m$). The product of a $n \times m$ matrix $A$ and a $m \times 1$ column vector $b$ is a $n \times 1$ column vector $c$, and $c_i$ is obtained by the following formula: \\[ c_i = \sum_{j=1}^m a_{ij}b_j = a_{i1}b_1 + a_{i2}b_2 + ... + a_{im}b_m \\]
[{"input": "4\n 1 2 0 1\n 0 3 0 1\n 4 1 1 0\n 1\n 2\n 3\n 0", "output": "6\n 9"}]
The output consists of $n$ lines. Print $c_i$ in a line.
s491547664
Wrong Answer
p02410
In the first line, two integers $n$ and $m$ are given. In the following $n$ lines, $a_{ij}$ are given separated by a single space character. In the next $m$ lines, $b_i$ is given in a line.
nums = list(map(int, input().split())) sum_li = [] for i in range(nums[0]): line = list(map(int, input().split())) sum_li.append(sum(line)) for i in range(nums[0]): n = int(input()) sum_li[i] += n input() for i in range(nums[0]): print(sum_li[i])
Matrix Vector Multiplication Write a program which reads a $ n \times m$ matrix $A$ and a $m \times 1$ vector $b$, and prints their product $Ab$. A column vector with m elements is represented by the following equation. \\[ b = \left( \begin{array}{c} b_1 \\\ b_2 \\\ : \\\ b_m \\\ \end{array} \right) \\] A $n \times m$ matrix with $m$ column vectors, each of which consists of $n$ elements, is represented by the following equation. \\[ A = \left( \begin{array}{cccc} a_{11} & a_{12} & ... & a_{1m} \\\ a_{21} & a_{22} & ... & a_{2m} \\\ : & : & : & : \\\ a_{n1} & a_{n2} & ... & a_{nm} \\\ \end{array} \right) \\] $i$-th element of a $m \times 1$ column vector $b$ is represented by $b_i$ ($i = 1, 2, ..., m$), and the element in $i$-th row and $j$-th column of a matrix $A$ is represented by $a_{ij}$ ($i = 1, 2, ..., n,$ $j = 1, 2, ..., m$). The product of a $n \times m$ matrix $A$ and a $m \times 1$ column vector $b$ is a $n \times 1$ column vector $c$, and $c_i$ is obtained by the following formula: \\[ c_i = \sum_{j=1}^m a_{ij}b_j = a_{i1}b_1 + a_{i2}b_2 + ... + a_{im}b_m \\]
[{"input": "4\n 1 2 0 1\n 0 3 0 1\n 4 1 1 0\n 1\n 2\n 3\n 0", "output": "6\n 9"}]
The output consists of $n$ lines. Print $c_i$ in a line.
s756645021
Runtime Error
p02410
In the first line, two integers $n$ and $m$ are given. In the following $n$ lines, $a_{ij}$ are given separated by a single space character. In the next $m$ lines, $b_i$ is given in a line.
n, m = [int(x) for x in input().split(" ")] a = [[0 for i in range(n)] for j in range(m)] b = [0 for i in range(m)] c = [0 for i in range(n)] for s in range(0, n): a[s] = [int(x) for x in input().split(" ")] for s in range(0, m): b[s] = int(input()) for s in range(0, n): for t in range(0, m): c[s] += a[s][t] * b[t] for t in range(0, n): print("%d" % c[t])
Matrix Vector Multiplication Write a program which reads a $ n \times m$ matrix $A$ and a $m \times 1$ vector $b$, and prints their product $Ab$. A column vector with m elements is represented by the following equation. \\[ b = \left( \begin{array}{c} b_1 \\\ b_2 \\\ : \\\ b_m \\\ \end{array} \right) \\] A $n \times m$ matrix with $m$ column vectors, each of which consists of $n$ elements, is represented by the following equation. \\[ A = \left( \begin{array}{cccc} a_{11} & a_{12} & ... & a_{1m} \\\ a_{21} & a_{22} & ... & a_{2m} \\\ : & : & : & : \\\ a_{n1} & a_{n2} & ... & a_{nm} \\\ \end{array} \right) \\] $i$-th element of a $m \times 1$ column vector $b$ is represented by $b_i$ ($i = 1, 2, ..., m$), and the element in $i$-th row and $j$-th column of a matrix $A$ is represented by $a_{ij}$ ($i = 1, 2, ..., n,$ $j = 1, 2, ..., m$). The product of a $n \times m$ matrix $A$ and a $m \times 1$ column vector $b$ is a $n \times 1$ column vector $c$, and $c_i$ is obtained by the following formula: \\[ c_i = \sum_{j=1}^m a_{ij}b_j = a_{i1}b_1 + a_{i2}b_2 + ... + a_{im}b_m \\]
[{"input": "4\n 1 2 0 1\n 0 3 0 1\n 4 1 1 0\n 1\n 2\n 3\n 0", "output": "6\n 9"}]
Print the maximum possible number of pairs such that the sum of the integers written on each pair of balls is a power of 2. * * *
s343650857
Wrong Answer
p03201
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 sys.setrecursionlimit(1000000) import math # from math import gcd import bisect import heapq 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") AZ = "abcdefghijklmnopqrstuvwxyz" ############# # 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)] #####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)))) def base_10_to_n_without_0(X, n): X -= 1 if X // n: return base_10_to_n_without_0(X // n, n) + [X % n] return [X % n] #####IntLog##### def int_log(n, a): count = 0 while n >= a: n //= a count += 1 return count ############# # Main Code # ############# N = I() A = IL() dic = DD(int) for a in A: dic[a] += 1 kieru = deque([]) A.sort(reverse=True) ans = 0 for a in A: if kieru and a == kieru[0]: kieru.popleft() continue dic[a] -= 1 if a == (1 << (a.bit_length() - 1)): if dic[a]: kieru.append(a) dic[a] -= 1 ans += 1 else: b = (1 << a.bit_length()) - a if dic[b]: kieru.append(b) dic[b] -= 1 ans += 1 print(ans)
Statement Takahashi has N balls with positive integers written on them. The integer written on the i-th ball is A_i. He would like to form some number of pairs such that the sum of the integers written on each pair of balls is a power of 2. Note that a ball cannot belong to multiple pairs. Find the maximum possible number of pairs that can be formed. Here, a positive integer is said to be a power of 2 when it can be written as 2^t using some non-negative integer t.
[{"input": "3\n 1 2 3", "output": "1\n \n\nWe can form one pair whose sum of the written numbers is 4 by pairing the\nfirst and third balls. Note that we cannot pair the second ball with itself.\n\n* * *"}, {"input": "5\n 3 11 14 5 13", "output": "2"}]
Print the maximum possible number of pairs such that the sum of the integers written on each pair of balls is a power of 2. * * *
s248142475
Runtime Error
p03201
Input is given from Standard Input in the following format: N A_1 A_2 ... A_N
from collections import defaultdict def twosum(n): now = 1 while n >= now: now *= 2 return now - n n=int(input()) a=sorted(list(map(int,input().split()))) d = defaultdict(int) for i in a: d[i] += 1 ans = 0 for i in a[::-1]: d[i] -= 1: find = twosum(i) if d[find] > 0 and d[i] >= 0: ans += 1 d[find] -= 1 else: d[i] += 1 print(ans)
Statement Takahashi has N balls with positive integers written on them. The integer written on the i-th ball is A_i. He would like to form some number of pairs such that the sum of the integers written on each pair of balls is a power of 2. Note that a ball cannot belong to multiple pairs. Find the maximum possible number of pairs that can be formed. Here, a positive integer is said to be a power of 2 when it can be written as 2^t using some non-negative integer t.
[{"input": "3\n 1 2 3", "output": "1\n \n\nWe can form one pair whose sum of the written numbers is 4 by pairing the\nfirst and third balls. Note that we cannot pair the second ball with itself.\n\n* * *"}, {"input": "5\n 3 11 14 5 13", "output": "2"}]
Print the maximum possible number of pairs such that the sum of the integers written on each pair of balls is a power of 2. * * *
s609216894
Runtime Error
p03201
Input is given from Standard Input in the following format: N A_1 A_2 ... A_N
_ = input() s = input() data = list(map(int, s.split())) even = [] odd = [] for it in data: if it % 2 == 0: even.append(it) else: odd.append(it) # src is sorted def get_pair(src, target): pair = [] pair_id = [] for i, first in enumerate(src): if first > target: break for j, second in enumerate(src[i + 1 :]): if first + second == target: pair.append([first, second]) pair_id.append([i, j + i + 1]) elif first + second > target: break # print('pair,',pair) # print('pair_id',pair_id) return pair, pair_id two = [] tmp = 1 while True: tmp *= 2 if tmp > max_num: break two.append(tmp) # for odd all_pair = [] all_pair_id = [] if len(odd) > 1: for target in two: pair, pair_id = get_pair(odd, target) all_pair += pair all_pair_id += pair_id # make list p_list = [[] for it in range(len(odd))] for it in all_pair_id: p_list[it[0]].append(it[1]) p_list[it[1]].append(it[0]) cnt = 0 while True: END = True for i, it in enumerate(p_list): if len(it) == 1: p_list[it[0]] = [] p_list[i] = [] END = False cnt += 1 break if END: break # for even all_pair = [] all_pair_id = [] if len(even) > 1: for target in two: pair, pair_id = get_pair(even, target) all_pair += pair all_pair_id += pair_id # make list p_list = [[] for it in range(len(even))] for it in all_pair_id: p_list[it[0]].append(it[1]) p_list[it[1]].append(it[0]) while True: END = True for i, it in enumerate(p_list): if len(it) == 1: p_list[it[0]] = [] p_list[i] = [] END = False cnt += 1 break if END: break print(cnt)
Statement Takahashi has N balls with positive integers written on them. The integer written on the i-th ball is A_i. He would like to form some number of pairs such that the sum of the integers written on each pair of balls is a power of 2. Note that a ball cannot belong to multiple pairs. Find the maximum possible number of pairs that can be formed. Here, a positive integer is said to be a power of 2 when it can be written as 2^t using some non-negative integer t.
[{"input": "3\n 1 2 3", "output": "1\n \n\nWe can form one pair whose sum of the written numbers is 4 by pairing the\nfirst and third balls. Note that we cannot pair the second ball with itself.\n\n* * *"}, {"input": "5\n 3 11 14 5 13", "output": "2"}]
Print the maximum possible number of pairs such that the sum of the integers written on each pair of balls is a power of 2. * * *
s683630076
Runtime Error
p03201
Input is given from Standard Input in the following format: N A_1 A_2 ... A_N
import bisect def number(num): #0bのぶんを引きます number_len = len(num)-2 #numと同じ桁数で各桁が全て1である数を求めます。 f = 2**number_len - 1 #排他的論理和をとって1を足したものを返します return (num^f)+1 n=int(input()) line=list(map(int,input().split)) count=0 while len(line)>0: #最後の数を取ってくる(最後尾なのでO(1)で済む) k=line.pop() #整数でないならその数は存在しないと同義なので処理を行わない if int(k) != k: continue x=number(k) #もしlineの最大値よりxが大きければ条件を満たすxは存在しないので処理を行わない if x>line[-1]: continue #その数が存在するならば、その数をlistから消去して、カウントする if line[bisect.bisect_left(line,x)]==x: #0.5を足すことでremoveの代わりとする line[bisect.bisect_left(line,x)] += 0.5 count+=1 print(count)
Statement Takahashi has N balls with positive integers written on them. The integer written on the i-th ball is A_i. He would like to form some number of pairs such that the sum of the integers written on each pair of balls is a power of 2. Note that a ball cannot belong to multiple pairs. Find the maximum possible number of pairs that can be formed. Here, a positive integer is said to be a power of 2 when it can be written as 2^t using some non-negative integer t.
[{"input": "3\n 1 2 3", "output": "1\n \n\nWe can form one pair whose sum of the written numbers is 4 by pairing the\nfirst and third balls. Note that we cannot pair the second ball with itself.\n\n* * *"}, {"input": "5\n 3 11 14 5 13", "output": "2"}]
Print the maximum possible number of pairs such that the sum of the integers written on each pair of balls is a power of 2. * * *
s606140987
Runtime Error
p03201
Input is given from Standard Input in the following format: N A_1 A_2 ... A_N
import bisect def number(num): #0bのぶんを引きます number_len = len(num)-2 #numと同じ桁数で各桁が全て1である数を求めます。 f = 2**number_len - 1 #排他的論理和をとって1を足したものを返します return (num^f)+1 line=list(map(int,input().split)) count=0 while len(line)>0: #最後の数を取ってくる(最後尾なのでO(1)で済む) k=line.pop() #整数でないならその数は存在しないと同義なので処理を行わない if int(k) != k: continue x=number(k) #もしlineの最大値よりxが大きければ条件を満たすxは存在しないので処理を行わない if x>line[-1]: continue #その数が存在するならば、その数をlistから消去して、カウントする if line[bisect.bisect_left(line,x)]==x: #0.5を足すことでremoveの代わりとする line[bisect.bisect_left(line,x)] += 0.5 count+=1 print(count)
Statement Takahashi has N balls with positive integers written on them. The integer written on the i-th ball is A_i. He would like to form some number of pairs such that the sum of the integers written on each pair of balls is a power of 2. Note that a ball cannot belong to multiple pairs. Find the maximum possible number of pairs that can be formed. Here, a positive integer is said to be a power of 2 when it can be written as 2^t using some non-negative integer t.
[{"input": "3\n 1 2 3", "output": "1\n \n\nWe can form one pair whose sum of the written numbers is 4 by pairing the\nfirst and third balls. Note that we cannot pair the second ball with itself.\n\n* * *"}, {"input": "5\n 3 11 14 5 13", "output": "2"}]
Print the maximum possible number of pairs such that the sum of the integers written on each pair of balls is a power of 2. * * *
s961480147
Runtime Error
p03201
Input is given from Standard Input in the following format: N A_1 A_2 ... A_N
from bisect import bisect_left, bisect_right from collections import deque N = int(input()) A = list(map(int, input().split(" "))) A.sort() A = deque(A) ans = 0 t_max = len(bin(A[-1])) - 2 for t in range(t_max, 0, -1): if len(A) < 2: break while len(bin(A[-1])) - 2 > t: A.pop() if len(A) < 2: break if len(A) < 2: break pow2 = 1 << t A_tmp = deque() while t == len(bin(A[-1])) - 2: r = A.pop() idx = bisect_left(A, pow2 - r) for _ in range(idx): A_tmp.appendleft(A.popleft()) if len(A) == 0: break if A[0] + r == pow2: A.popleft() ans += 1 if len(A) < 2: break A.extendleft(A_tmp) print(ans)
Statement Takahashi has N balls with positive integers written on them. The integer written on the i-th ball is A_i. He would like to form some number of pairs such that the sum of the integers written on each pair of balls is a power of 2. Note that a ball cannot belong to multiple pairs. Find the maximum possible number of pairs that can be formed. Here, a positive integer is said to be a power of 2 when it can be written as 2^t using some non-negative integer t.
[{"input": "3\n 1 2 3", "output": "1\n \n\nWe can form one pair whose sum of the written numbers is 4 by pairing the\nfirst and third balls. Note that we cannot pair the second ball with itself.\n\n* * *"}, {"input": "5\n 3 11 14 5 13", "output": "2"}]
Print the maximum possible number of pairs such that the sum of the integers written on each pair of balls is a power of 2. * * *
s004071628
Runtime Error
p03201
Input is given from Standard Input in the following format: N A_1 A_2 ... A_N
import copy N = int(input()) A = [int(i) for i in input().split()] ans = 0 even = [] odd = [] for i in range(N): if A[i] % 2 == 0: even.append(A[i]) else: odd.append(A[i]) even = sorted(even) odd = sorted(odd) even2 = copy.deepcopy(even) odd2 = copy.deepcopy(odd) for i in range(len(even)): for j in reversed(range((len(even2)))): if i >= j: break num = even[i] + even2[j] ans += 1 del even2[j] break for i in range(len(odd)): for j in reversed(range((len(odd2)))): if i >= j: break num = odd[i] + odd2[j] if not (num & (num - 1)): ans += 1 del odd2[j] break print(ans)
Statement Takahashi has N balls with positive integers written on them. The integer written on the i-th ball is A_i. He would like to form some number of pairs such that the sum of the integers written on each pair of balls is a power of 2. Note that a ball cannot belong to multiple pairs. Find the maximum possible number of pairs that can be formed. Here, a positive integer is said to be a power of 2 when it can be written as 2^t using some non-negative integer t.
[{"input": "3\n 1 2 3", "output": "1\n \n\nWe can form one pair whose sum of the written numbers is 4 by pairing the\nfirst and third balls. Note that we cannot pair the second ball with itself.\n\n* * *"}, {"input": "5\n 3 11 14 5 13", "output": "2"}]
Print the maximum possible number of pairs such that the sum of the integers written on each pair of balls is a power of 2. * * *
s675145764
Runtime Error
p03201
Input is given from Standard Input in the following format: N A_1 A_2 ... A_N
import math N=int(input()) A=list(map(int,input().split())) Ae=[] Ao=[] for i in range(N): if A[i]%2==0: Ae.append(A[i]) else: Ao.append(A[i]) if Ao!=[]: s=0 Ao.sort() i=1 while i<=len(Ao): a=int(math.log2(Ao[-i])) if 2**(a+1)-Ao[-i] in Ao[:-i]: s+=1 Ao.remove(2**(a+1)-Ao[-i]) i+=1 else: i+=1 else: s=0 if Ae!=[] t=0 j=1 Ae.sort() while j<=len(Ae): b=int(math.log2(Ae[-j])) if 2**(a+1)-Ae[-j] in Ae[:-j]: s+=1 Ae.remove(2**(a+1)-Ae[-j]) j+=1 else: j+=1 else: t=0 print(s+t)
Statement Takahashi has N balls with positive integers written on them. The integer written on the i-th ball is A_i. He would like to form some number of pairs such that the sum of the integers written on each pair of balls is a power of 2. Note that a ball cannot belong to multiple pairs. Find the maximum possible number of pairs that can be formed. Here, a positive integer is said to be a power of 2 when it can be written as 2^t using some non-negative integer t.
[{"input": "3\n 1 2 3", "output": "1\n \n\nWe can form one pair whose sum of the written numbers is 4 by pairing the\nfirst and third balls. Note that we cannot pair the second ball with itself.\n\n* * *"}, {"input": "5\n 3 11 14 5 13", "output": "2"}]
Print the maximum possible number of pairs such that the sum of the integers written on each pair of balls is a power of 2. * * *
s201755518
Runtime Error
p03201
Input is given from Standard Input in the following format: N A_1 A_2 ... A_N
#AGC030 B - Powers of two import collections import math N=int(input()) A=list(map(int,input().split())) A.sort(reverse=True) cnter=collections.Counter(A) ans=0 for a in A: inv=2**(int(math.log2(a))+1) if cnter[a]==0: continue if cnter[a]>=2 and a==inv//2:a cnter[a]=cnter[a]-2 ans=ans+1 continue if inv-a in cnter: cnter[inv-a]=cnter[inv-a]-1 ans=ans+1 print(ans)
Statement Takahashi has N balls with positive integers written on them. The integer written on the i-th ball is A_i. He would like to form some number of pairs such that the sum of the integers written on each pair of balls is a power of 2. Note that a ball cannot belong to multiple pairs. Find the maximum possible number of pairs that can be formed. Here, a positive integer is said to be a power of 2 when it can be written as 2^t using some non-negative integer t.
[{"input": "3\n 1 2 3", "output": "1\n \n\nWe can form one pair whose sum of the written numbers is 4 by pairing the\nfirst and third balls. Note that we cannot pair the second ball with itself.\n\n* * *"}, {"input": "5\n 3 11 14 5 13", "output": "2"}]
Print the maximum possible number of pairs such that the sum of the integers written on each pair of balls is a power of 2. * * *
s627266043
Runtime Error
p03201
Input is given from Standard Input in the following format: N A_1 A_2 ... A_N
#AGC030 B - Powers of two import collections import math N=int(input()) A=list(map(int,input().split())) A.sort(reverse=True) cnter=collections.Counter(A) ans=0 for a in A: inv=2**(int(math.log2(a))+1) if cnter[a]==0: continue if cnter[a]>=2 and a==inv//2:a cnter[a]=cnter[a]-2 ans=ans+1 continue if inv-a in cnter: cnter[inv-a]=cnter[inv-a]-1 ans=ans+1 print(ans)
Statement Takahashi has N balls with positive integers written on them. The integer written on the i-th ball is A_i. He would like to form some number of pairs such that the sum of the integers written on each pair of balls is a power of 2. Note that a ball cannot belong to multiple pairs. Find the maximum possible number of pairs that can be formed. Here, a positive integer is said to be a power of 2 when it can be written as 2^t using some non-negative integer t.
[{"input": "3\n 1 2 3", "output": "1\n \n\nWe can form one pair whose sum of the written numbers is 4 by pairing the\nfirst and third balls. Note that we cannot pair the second ball with itself.\n\n* * *"}, {"input": "5\n 3 11 14 5 13", "output": "2"}]
Print the maximum possible number of pairs such that the sum of the integers written on each pair of balls is a power of 2. * * *
s829118775
Runtime Error
p03201
Input is given from Standard Input in the following format: N A_1 A_2 ... A_N
import math N = int(input()) l = list(map(int, input().split())) ld = sorted(l, reverse=True) k = 0 two = [] while 2**k < ld[0] + ld[1]: k+=1 two.append(2**k) p = 0 while len(ld) > 0: for m in range(1,len(ld)): if (ld[0] + ld[m]) in two: del ld[m] p += 1 break if len(ld) > 0: del ld[0] if len(ld) = 0: break print(p)
Statement Takahashi has N balls with positive integers written on them. The integer written on the i-th ball is A_i. He would like to form some number of pairs such that the sum of the integers written on each pair of balls is a power of 2. Note that a ball cannot belong to multiple pairs. Find the maximum possible number of pairs that can be formed. Here, a positive integer is said to be a power of 2 when it can be written as 2^t using some non-negative integer t.
[{"input": "3\n 1 2 3", "output": "1\n \n\nWe can form one pair whose sum of the written numbers is 4 by pairing the\nfirst and third balls. Note that we cannot pair the second ball with itself.\n\n* * *"}, {"input": "5\n 3 11 14 5 13", "output": "2"}]
Print the maximum possible number of pairs such that the sum of the integers written on each pair of balls is a power of 2. * * *
s827922115
Runtime Error
p03201
Input is given from Standard Input in the following format: N A_1 A_2 ... A_N
n = input('') l = int(input('').split l = [int(l[i]) for i in range(len(l))] c = 0 for i in range(n): for j in range(n): if i>=j: pass else: while l[i] > 1.0: l[i] /= 2 if l[i] == 1: c += 1 else: pass
Statement Takahashi has N balls with positive integers written on them. The integer written on the i-th ball is A_i. He would like to form some number of pairs such that the sum of the integers written on each pair of balls is a power of 2. Note that a ball cannot belong to multiple pairs. Find the maximum possible number of pairs that can be formed. Here, a positive integer is said to be a power of 2 when it can be written as 2^t using some non-negative integer t.
[{"input": "3\n 1 2 3", "output": "1\n \n\nWe can form one pair whose sum of the written numbers is 4 by pairing the\nfirst and third balls. Note that we cannot pair the second ball with itself.\n\n* * *"}, {"input": "5\n 3 11 14 5 13", "output": "2"}]
Print the maximum possible number of pairs such that the sum of the integers written on each pair of balls is a power of 2. * * *
s425568348
Runtime Error
p03201
Input is given from Standard Input in the following format: N A_1 A_2 ... A_N
N=int(input()) lis=list(map(int,input().split())) lis.sort() sum=0 while(len(lis)>1): v=lis.pop() k=1 while k<=v: k*=2 m=k-v if m in lis: sum+=1 lis.remove(m) print(sum)
Statement Takahashi has N balls with positive integers written on them. The integer written on the i-th ball is A_i. He would like to form some number of pairs such that the sum of the integers written on each pair of balls is a power of 2. Note that a ball cannot belong to multiple pairs. Find the maximum possible number of pairs that can be formed. Here, a positive integer is said to be a power of 2 when it can be written as 2^t using some non-negative integer t.
[{"input": "3\n 1 2 3", "output": "1\n \n\nWe can form one pair whose sum of the written numbers is 4 by pairing the\nfirst and third balls. Note that we cannot pair the second ball with itself.\n\n* * *"}, {"input": "5\n 3 11 14 5 13", "output": "2"}]
Print the maximum possible number of pairs such that the sum of the integers written on each pair of balls is a power of 2. * * *
s617985211
Wrong Answer
p03201
Input is given from Standard Input in the following format: N A_1 A_2 ... A_N
N = int(input()) L = list(map(int, input().split())) B = [False] * N ans = 0 L.sort() for i in range(N): cur = L[N - i - 1] if B[N - i - 1] == True: None else: B[N - i - 1] = True for j in range(N - i - 1): if B[j] == False: S = cur + L[j] while S > 1: if S % 2 == 0: S = S / 2 else: break if S == 1: ans += 1 B[j] = True print(ans)
Statement Takahashi has N balls with positive integers written on them. The integer written on the i-th ball is A_i. He would like to form some number of pairs such that the sum of the integers written on each pair of balls is a power of 2. Note that a ball cannot belong to multiple pairs. Find the maximum possible number of pairs that can be formed. Here, a positive integer is said to be a power of 2 when it can be written as 2^t using some non-negative integer t.
[{"input": "3\n 1 2 3", "output": "1\n \n\nWe can form one pair whose sum of the written numbers is 4 by pairing the\nfirst and third balls. Note that we cannot pair the second ball with itself.\n\n* * *"}, {"input": "5\n 3 11 14 5 13", "output": "2"}]
Print the maximum possible number of pairs such that the sum of the integers written on each pair of balls is a power of 2. * * *
s636505416
Runtime Error
p03201
Input is given from Standard Input in the following format: N A_1 A_2 ... A_N
# AGC030 B - Powers of two import copy beki = [] for i in range(1, 32): beki.append(2**i) # bekiは2のべき乗の配列 N = int(input()) A = input().split() for i in range(N): A[i] = int(A[i]) for i in reversed(beki): B = copy.deepcopy(A) for j in B: if i // 2 < j < i: if i - j in B: A.remove(i - j) A.remove(j) if j == i // 2: if B.count(j) >= 2: A.remove(j) A.remove(j) print((N - len(A)) // 2)
Statement Takahashi has N balls with positive integers written on them. The integer written on the i-th ball is A_i. He would like to form some number of pairs such that the sum of the integers written on each pair of balls is a power of 2. Note that a ball cannot belong to multiple pairs. Find the maximum possible number of pairs that can be formed. Here, a positive integer is said to be a power of 2 when it can be written as 2^t using some non-negative integer t.
[{"input": "3\n 1 2 3", "output": "1\n \n\nWe can form one pair whose sum of the written numbers is 4 by pairing the\nfirst and third balls. Note that we cannot pair the second ball with itself.\n\n* * *"}, {"input": "5\n 3 11 14 5 13", "output": "2"}]
Print the maximum possible number of pairs such that the sum of the integers written on each pair of balls is a power of 2. * * *
s585636855
Accepted
p03201
Input is given from Standard Input in the following format: N A_1 A_2 ... A_N
import collections N = int(input()) A = list(map(int, input().split())) l = [] c = collections.Counter(A) values = list(c.values()) # aのCollectionのvalue値のリスト(n_1こ、n_2こ…) key = list(c.keys()) # 先のvalue値に相当する要素のリスト(要素1,要素2,…) for i in range(len(key)): l.append([key[i], values[i]]) # lは[要素i,n_i]の情報を詰めたmatrix # print(l) n = len(l) ans = 0 cnt = 0 d = dict(l) # print(d) ans = 0 for i in range(31, 0, -1): piv = pow(2, i) cnt = 0 for j in range(n): val1 = d.get(l[j][0]) val2 = d.get(piv - l[j][0]) if (val1 != None) and (val2 != None): add = min(val1, val2) if l[j][0] == piv - l[j][0]: add = add // 2 ans = ans + add add = add * 2 else: ans = ans + add d[l[j][0]] = val1 - add d[piv - l[j][0]] = val2 - add # print(d) # input() # ans=ans+(cnt-c[piv//2])//2 # print(i,ans) print(ans)
Statement Takahashi has N balls with positive integers written on them. The integer written on the i-th ball is A_i. He would like to form some number of pairs such that the sum of the integers written on each pair of balls is a power of 2. Note that a ball cannot belong to multiple pairs. Find the maximum possible number of pairs that can be formed. Here, a positive integer is said to be a power of 2 when it can be written as 2^t using some non-negative integer t.
[{"input": "3\n 1 2 3", "output": "1\n \n\nWe can form one pair whose sum of the written numbers is 4 by pairing the\nfirst and third balls. Note that we cannot pair the second ball with itself.\n\n* * *"}, {"input": "5\n 3 11 14 5 13", "output": "2"}]
Print the maximum possible number of pairs such that the sum of the integers written on each pair of balls is a power of 2. * * *
s302221398
Wrong Answer
p03201
Input is given from Standard Input in the following format: N A_1 A_2 ... A_N
# -*- coding: utf-8 -*- import sys from collections import Counter def input(): return sys.stdin.readline().strip() def list2d(a, b, c): return [[c] * b for i in range(a)] def list3d(a, b, c, d): return [[[d] * c for j in range(b)] for i in range(a)] def list4d(a, b, c, d, e): return [[[[e] * d for j in range(c)] for j in range(b)] for i in range(a)] def ceil(x, y=1): return int(-(-x // y)) def INT(): return int(input()) def MAP(): return map(int, input().split()) def LIST(N=None): return list(MAP()) if N is None else [INT() for i in range(N)] def Yes(): print("Yes") def No(): print("No") def YES(): print("YES") def NO(): print("NO") sys.setrecursionlimit(10**9) INF = 10**18 MOD = 10**9 + 7 N = INT() A = LIST() C = Counter(A) ans = 0 for i in range(30, 1, -1): x = 2**i for k in C.keys(): if x - k in C: p = min(C[k], C[x - k]) C[k] -= p C[x - k] -= p ans += p print(ans)
Statement Takahashi has N balls with positive integers written on them. The integer written on the i-th ball is A_i. He would like to form some number of pairs such that the sum of the integers written on each pair of balls is a power of 2. Note that a ball cannot belong to multiple pairs. Find the maximum possible number of pairs that can be formed. Here, a positive integer is said to be a power of 2 when it can be written as 2^t using some non-negative integer t.
[{"input": "3\n 1 2 3", "output": "1\n \n\nWe can form one pair whose sum of the written numbers is 4 by pairing the\nfirst and third balls. Note that we cannot pair the second ball with itself.\n\n* * *"}, {"input": "5\n 3 11 14 5 13", "output": "2"}]
Print the maximum possible number of pairs such that the sum of the integers written on each pair of balls is a power of 2. * * *
s090000416
Wrong Answer
p03201
Input is given from Standard Input in the following format: N A_1 A_2 ... A_N
input() A = list(map(int, input().split())) def add(i): global n # print("i=",i) if i in b: if b.get(i, 0) == m: b[i] = 0 add(i - 1) else: b[i] = b.get(i, b[i]) + 1 n = max(n, b[i]) else: b[i] = b.get(i, b[1]) + 1 n = max(n, b[i]) lo = 1 hi = 10**6 while lo < hi: m = (lo + hi) // 2 ba = 0 b = {} b[0] = 0 b[1] = 1 n = 1 for fr in A: # print(b,m,ba,fr) if fr == ba: add(fr) if fr < ba: c = {} for bb in list(b.keys()): if bb <= fr: c[bb] = b[bb] b = c add(fr) if b[0] >= 1: lo = m + 1 flag = 0 break ba = fr # print(b) hi = min(n, m) lo = 1 print(n)
Statement Takahashi has N balls with positive integers written on them. The integer written on the i-th ball is A_i. He would like to form some number of pairs such that the sum of the integers written on each pair of balls is a power of 2. Note that a ball cannot belong to multiple pairs. Find the maximum possible number of pairs that can be formed. Here, a positive integer is said to be a power of 2 when it can be written as 2^t using some non-negative integer t.
[{"input": "3\n 1 2 3", "output": "1\n \n\nWe can form one pair whose sum of the written numbers is 4 by pairing the\nfirst and third balls. Note that we cannot pair the second ball with itself.\n\n* * *"}, {"input": "5\n 3 11 14 5 13", "output": "2"}]
If it is possible for Snuke to reach the state where the box contains a ball on which the integer K is written, print `POSSIBLE`; if it is not possible, print `IMPOSSIBLE`. * * *
s538878184
Runtime Error
p03651
Input is given from Standard Input in the following format: N K A_1 A_2 ... A_N
def gcd(a,b) : while b : a,b = b, a % b return a N,K = map(int,input().split()) L = list(map(int,input().split())) p = 10**9 for i in range(N-1) : q = gcd(L[i],L[i+1]) if q < p : p = q if (K % p == 0) and (K <= max(L)) ans = "POSSIBLE" else : ans = "IMPOSSIBLE" print(ans)
Statement There is a box containing N balls. The i-th ball has the integer A_i written on it. Snuke can perform the following operation any number of times: * Take out two balls from the box. Then, return them to the box along with a new ball, on which the absolute difference of the integers written on the two balls is written. Determine whether it is possible for Snuke to reach the state where the box contains a ball on which the integer K is written.
[{"input": "3 7\n 9 3 4", "output": "POSSIBLE\n \n\nFirst, take out the two balls 9 and 4, and return them back along with a new\nball, abs(9-4)=5. Next, take out 3 and 5, and return them back along with\nabs(3-5)=2. Finally, take out 9 and 2, and return them back along with\nabs(9-2)=7. Now we have 7 in the box, and the answer is therefore `POSSIBLE`.\n\n* * *"}, {"input": "3 5\n 6 9 3", "output": "IMPOSSIBLE\n \n\nNo matter what we do, it is not possible to have 5 in the box. The answer is\ntherefore `IMPOSSIBLE`.\n\n* * *"}, {"input": "4 11\n 11 3 7 15", "output": "POSSIBLE\n \n\nThe box already contains 11 before we do anything. The answer is therefore\n`POSSIBLE`.\n\n* * *"}, {"input": "5 12\n 10 2 8 6 4", "output": "IMPOSSIBLE"}]
If it is possible for Snuke to reach the state where the box contains a ball on which the integer K is written, print `POSSIBLE`; if it is not possible, print `IMPOSSIBLE`. * * *
s548492198
Wrong Answer
p03651
Input is given from Standard Input in the following format: N K A_1 A_2 ... A_N
print("IMPOSSIBLE")
Statement There is a box containing N balls. The i-th ball has the integer A_i written on it. Snuke can perform the following operation any number of times: * Take out two balls from the box. Then, return them to the box along with a new ball, on which the absolute difference of the integers written on the two balls is written. Determine whether it is possible for Snuke to reach the state where the box contains a ball on which the integer K is written.
[{"input": "3 7\n 9 3 4", "output": "POSSIBLE\n \n\nFirst, take out the two balls 9 and 4, and return them back along with a new\nball, abs(9-4)=5. Next, take out 3 and 5, and return them back along with\nabs(3-5)=2. Finally, take out 9 and 2, and return them back along with\nabs(9-2)=7. Now we have 7 in the box, and the answer is therefore `POSSIBLE`.\n\n* * *"}, {"input": "3 5\n 6 9 3", "output": "IMPOSSIBLE\n \n\nNo matter what we do, it is not possible to have 5 in the box. The answer is\ntherefore `IMPOSSIBLE`.\n\n* * *"}, {"input": "4 11\n 11 3 7 15", "output": "POSSIBLE\n \n\nThe box already contains 11 before we do anything. The answer is therefore\n`POSSIBLE`.\n\n* * *"}, {"input": "5 12\n 10 2 8 6 4", "output": "IMPOSSIBLE"}]
If it is possible for Snuke to reach the state where the box contains a ball on which the integer K is written, print `POSSIBLE`; if it is not possible, print `IMPOSSIBLE`. * * *
s366613665
Runtime Error
p03651
Input is given from Standard Input in the following format: N K A_1 A_2 ... A_N
n,k=map(int,input().split()) a=list(map(int,input().split())) from fractions import gcd from functools import reduce def g(l): return reduce(gcd,l) if max(a)<k: print('IMPOSSIBLE') else: z=g(a) if k%z==0: print('POSSIBLE') else: print('IMPOSSIBLE')
Statement There is a box containing N balls. The i-th ball has the integer A_i written on it. Snuke can perform the following operation any number of times: * Take out two balls from the box. Then, return them to the box along with a new ball, on which the absolute difference of the integers written on the two balls is written. Determine whether it is possible for Snuke to reach the state where the box contains a ball on which the integer K is written.
[{"input": "3 7\n 9 3 4", "output": "POSSIBLE\n \n\nFirst, take out the two balls 9 and 4, and return them back along with a new\nball, abs(9-4)=5. Next, take out 3 and 5, and return them back along with\nabs(3-5)=2. Finally, take out 9 and 2, and return them back along with\nabs(9-2)=7. Now we have 7 in the box, and the answer is therefore `POSSIBLE`.\n\n* * *"}, {"input": "3 5\n 6 9 3", "output": "IMPOSSIBLE\n \n\nNo matter what we do, it is not possible to have 5 in the box. The answer is\ntherefore `IMPOSSIBLE`.\n\n* * *"}, {"input": "4 11\n 11 3 7 15", "output": "POSSIBLE\n \n\nThe box already contains 11 before we do anything. The answer is therefore\n`POSSIBLE`.\n\n* * *"}, {"input": "5 12\n 10 2 8 6 4", "output": "IMPOSSIBLE"}]
If it is possible for Snuke to reach the state where the box contains a ball on which the integer K is written, print `POSSIBLE`; if it is not possible, print `IMPOSSIBLE`. * * *
s157357644
Runtime Error
p03651
Input is given from Standard Input in the following format: N K A_1 A_2 ... A_N
#!/usr/bin/env python3 # -*- coding: utf-8 -*- import sys n,k = [int(i) for i in input().split()] a = [int(i) for i in input().split()] result="POSSIBLE" flag=True loop=True if k > max(a):    loop=False    flag=False    result="IMPOSSIBLE" if k % 2 == 1:    loop=False    flag=False    result="IMPOSSIBLE"    for i in range(len(a)):        if a[i]%2==1:            loop=False            flag=True            result="POSSIBLE"            break if not k in a:    b=[]    a.sort()    for i in range(1,len(a)):        if a[i]%a[0] !=0:            b.append(a[i])            break    if len(b)==0:        loop=False        flag=False        result="IMPOSSIBLE" if len(a) == 1 and not k in a:    result="IMPOSSIBLE"     
Statement There is a box containing N balls. The i-th ball has the integer A_i written on it. Snuke can perform the following operation any number of times: * Take out two balls from the box. Then, return them to the box along with a new ball, on which the absolute difference of the integers written on the two balls is written. Determine whether it is possible for Snuke to reach the state where the box contains a ball on which the integer K is written.
[{"input": "3 7\n 9 3 4", "output": "POSSIBLE\n \n\nFirst, take out the two balls 9 and 4, and return them back along with a new\nball, abs(9-4)=5. Next, take out 3 and 5, and return them back along with\nabs(3-5)=2. Finally, take out 9 and 2, and return them back along with\nabs(9-2)=7. Now we have 7 in the box, and the answer is therefore `POSSIBLE`.\n\n* * *"}, {"input": "3 5\n 6 9 3", "output": "IMPOSSIBLE\n \n\nNo matter what we do, it is not possible to have 5 in the box. The answer is\ntherefore `IMPOSSIBLE`.\n\n* * *"}, {"input": "4 11\n 11 3 7 15", "output": "POSSIBLE\n \n\nThe box already contains 11 before we do anything. The answer is therefore\n`POSSIBLE`.\n\n* * *"}, {"input": "5 12\n 10 2 8 6 4", "output": "IMPOSSIBLE"}]
If it is possible for Snuke to reach the state where the box contains a ball on which the integer K is written, print `POSSIBLE`; if it is not possible, print `IMPOSSIBLE`. * * *
s595810542
Runtime Error
p03651
Input is given from Standard Input in the following format: N K A_1 A_2 ... A_N
Python 3.7.0 (v3.7.0:1bf9cc5093, Jun 27 2018, 04:59:51) [MSC v.1914 64 bit (AMD64)] on win32 Type "copyright", "credits" or "license()" for more information. >>> ======= RESTART: C:\Users\mori-\OneDrive\Desktop\Python\abc\tenka1a.py ======= Traceback (most recent call last): File "C:\Users\mori-\OneDrive\Desktop\Python\abc\tenka1a.py", line 13, in <module> print(gcd_list(a)) File "C:\Users\mori-\OneDrive\Desktop\Python\abc\tenka1a.py", line 9, in gcd_list for i in range(len(n)): NameError: name 'n' is not defined >>> ======= RESTART: C:\Users\mori-\OneDrive\Desktop\Python\abc\tenka1a.py ======= None ======= RESTART: C:\Users\mori-\OneDrive\Desktop\Python\abc\tenka1a.py ======= 6 ======= RESTART: C:\Users\mori-\OneDrive\Desktop\Python\abc\tenka1a.py ======= 6 ======= RESTART: C:\Users\mori-\OneDrive\Desktop\Python\abc\tenka1a.py ======= 3 ======= RESTART: C:\Users\mori-\OneDrive\Desktop\Python\abc\tenka1a.py ======= 3 7 9 3 4 Traceback (most recent call last): File "C:\Users\mori-\OneDrive\Desktop\Python\abc\tenka1a.py", line 19, in <module> if A[-1] > k and (A[-1] - k) % gcd_lst(A) == 0: NameError: name 'gcd_lst' is not defined >>> ======= RESTART: C:\Users\mori-\OneDrive\Desktop\Python\abc\tenka1a.py ======= 3 7 9 3 4 POSSIBLE >>> ======= RESTART: C:\Users\mori-\OneDrive\Desktop\Python\abc\tenka1a.py ======= 3 5 6 9 3 IMPOSSIBLE >>> ======= RESTART: C:\Users\mori-\OneDrive\Desktop\Python\abc\tenka1a.py ======= 4 11 11 3 7 15 POSSIBLE >>> ======= RESTART: C:\Users\mori-\OneDrive\Desktop\Python\abc\tenka1a.py ======= 5 12 10 2 8 6 4 IMPOSSIBLE >>>
Statement There is a box containing N balls. The i-th ball has the integer A_i written on it. Snuke can perform the following operation any number of times: * Take out two balls from the box. Then, return them to the box along with a new ball, on which the absolute difference of the integers written on the two balls is written. Determine whether it is possible for Snuke to reach the state where the box contains a ball on which the integer K is written.
[{"input": "3 7\n 9 3 4", "output": "POSSIBLE\n \n\nFirst, take out the two balls 9 and 4, and return them back along with a new\nball, abs(9-4)=5. Next, take out 3 and 5, and return them back along with\nabs(3-5)=2. Finally, take out 9 and 2, and return them back along with\nabs(9-2)=7. Now we have 7 in the box, and the answer is therefore `POSSIBLE`.\n\n* * *"}, {"input": "3 5\n 6 9 3", "output": "IMPOSSIBLE\n \n\nNo matter what we do, it is not possible to have 5 in the box. The answer is\ntherefore `IMPOSSIBLE`.\n\n* * *"}, {"input": "4 11\n 11 3 7 15", "output": "POSSIBLE\n \n\nThe box already contains 11 before we do anything. The answer is therefore\n`POSSIBLE`.\n\n* * *"}, {"input": "5 12\n 10 2 8 6 4", "output": "IMPOSSIBLE"}]
If it is possible for Snuke to reach the state where the box contains a ball on which the integer K is written, print `POSSIBLE`; if it is not possible, print `IMPOSSIBLE`. * * *
s904876435
Runtime Error
p03651
Input is given from Standard Input in the following format: N K A_1 A_2 ... A_N
#!/usr/bin/env python3 # -*- coding: utf-8 -*- import sys n,k = [int(i) for i in input().split()] a = [int(i) for i in input().split()] result="POSSIBLE" flag=True loop=True if k > max(a):    loop=False    flag=False    result="IMPOSSIBLE" if k % 2 == 1:    loop=False    flag=False    result="IMPOSSIBLE"    for i in range(len(a)):        if a[i]%2==1:            loop=False            flag=True            result="POSSIBLE"            break if not k in a:    b=[]    a.sort()    for i in range(1,len(a)):        if a[i]%a[0] !=0:            b.append(a[i])            break    if len(b)==0:        loop=False        flag=False        result="IMPOSSIBLE" if len(a) == 1 and not k in a:    result="IMPOSSIBLE" print(result)
Statement There is a box containing N balls. The i-th ball has the integer A_i written on it. Snuke can perform the following operation any number of times: * Take out two balls from the box. Then, return them to the box along with a new ball, on which the absolute difference of the integers written on the two balls is written. Determine whether it is possible for Snuke to reach the state where the box contains a ball on which the integer K is written.
[{"input": "3 7\n 9 3 4", "output": "POSSIBLE\n \n\nFirst, take out the two balls 9 and 4, and return them back along with a new\nball, abs(9-4)=5. Next, take out 3 and 5, and return them back along with\nabs(3-5)=2. Finally, take out 9 and 2, and return them back along with\nabs(9-2)=7. Now we have 7 in the box, and the answer is therefore `POSSIBLE`.\n\n* * *"}, {"input": "3 5\n 6 9 3", "output": "IMPOSSIBLE\n \n\nNo matter what we do, it is not possible to have 5 in the box. The answer is\ntherefore `IMPOSSIBLE`.\n\n* * *"}, {"input": "4 11\n 11 3 7 15", "output": "POSSIBLE\n \n\nThe box already contains 11 before we do anything. The answer is therefore\n`POSSIBLE`.\n\n* * *"}, {"input": "5 12\n 10 2 8 6 4", "output": "IMPOSSIBLE"}]
If it is possible for Snuke to reach the state where the box contains a ball on which the integer K is written, print `POSSIBLE`; if it is not possible, print `IMPOSSIBLE`. * * *
s836208974
Runtime Error
p03651
Input is given from Standard Input in the following format: N K A_1 A_2 ... A_N
def main(): import sys def input(): return sys.stdin.readline().rstrip() def gcd(x,y): r = x%y if r==0: return y return gcd(y, r) n, k =map(int, input().split()) a = list(map(int, input().split())) a.sort(reverse=True) c = a[0] for i in range(n): c = gcd(a[i], c) if k%c == 0: print('POSSIBLE') else: print('IMPOSSIBLE') if __name__ == '__main__': main()
Statement There is a box containing N balls. The i-th ball has the integer A_i written on it. Snuke can perform the following operation any number of times: * Take out two balls from the box. Then, return them to the box along with a new ball, on which the absolute difference of the integers written on the two balls is written. Determine whether it is possible for Snuke to reach the state where the box contains a ball on which the integer K is written.
[{"input": "3 7\n 9 3 4", "output": "POSSIBLE\n \n\nFirst, take out the two balls 9 and 4, and return them back along with a new\nball, abs(9-4)=5. Next, take out 3 and 5, and return them back along with\nabs(3-5)=2. Finally, take out 9 and 2, and return them back along with\nabs(9-2)=7. Now we have 7 in the box, and the answer is therefore `POSSIBLE`.\n\n* * *"}, {"input": "3 5\n 6 9 3", "output": "IMPOSSIBLE\n \n\nNo matter what we do, it is not possible to have 5 in the box. The answer is\ntherefore `IMPOSSIBLE`.\n\n* * *"}, {"input": "4 11\n 11 3 7 15", "output": "POSSIBLE\n \n\nThe box already contains 11 before we do anything. The answer is therefore\n`POSSIBLE`.\n\n* * *"}, {"input": "5 12\n 10 2 8 6 4", "output": "IMPOSSIBLE"}]
If it is possible for Snuke to reach the state where the box contains a ball on which the integer K is written, print `POSSIBLE`; if it is not possible, print `IMPOSSIBLE`. * * *
s079573032
Runtime Error
p03651
Input is given from Standard Input in the following format: N K A_1 A_2 ... A_N
N,K = map(int, input().split()) A = list(map(int, input().split())) A.sort() if A[-1] < K: print("IMPOSSIBLE") exit() if K in A or 1 in A: print("POSSIBLE") exit() def gcd(a,b): x = max([a,b]) y = min([a,b]) while y: x, y = y, x % y return x g = A[0] for i in range(1,N): g = gcd(A[i], g) print("POSSIBLE" ig K % g == 9 else "IMPOSSIBLE")
Statement There is a box containing N balls. The i-th ball has the integer A_i written on it. Snuke can perform the following operation any number of times: * Take out two balls from the box. Then, return them to the box along with a new ball, on which the absolute difference of the integers written on the two balls is written. Determine whether it is possible for Snuke to reach the state where the box contains a ball on which the integer K is written.
[{"input": "3 7\n 9 3 4", "output": "POSSIBLE\n \n\nFirst, take out the two balls 9 and 4, and return them back along with a new\nball, abs(9-4)=5. Next, take out 3 and 5, and return them back along with\nabs(3-5)=2. Finally, take out 9 and 2, and return them back along with\nabs(9-2)=7. Now we have 7 in the box, and the answer is therefore `POSSIBLE`.\n\n* * *"}, {"input": "3 5\n 6 9 3", "output": "IMPOSSIBLE\n \n\nNo matter what we do, it is not possible to have 5 in the box. The answer is\ntherefore `IMPOSSIBLE`.\n\n* * *"}, {"input": "4 11\n 11 3 7 15", "output": "POSSIBLE\n \n\nThe box already contains 11 before we do anything. The answer is therefore\n`POSSIBLE`.\n\n* * *"}, {"input": "5 12\n 10 2 8 6 4", "output": "IMPOSSIBLE"}]
If it is possible for Snuke to reach the state where the box contains a ball on which the integer K is written, print `POSSIBLE`; if it is not possible, print `IMPOSSIBLE`. * * *
s890606622
Runtime Error
p03651
Input is given from Standard Input in the following format: N K A_1 A_2 ... A_N
from fractions import gcd n,k=map(int,input().split()) g=0 m=0 for a in map(int,input().split()): m=max(m,a) g=gcd(g,a) print("POSSIBLE" if(k%g==0 and k<=m) else "IMPOSSIBLE")
Statement There is a box containing N balls. The i-th ball has the integer A_i written on it. Snuke can perform the following operation any number of times: * Take out two balls from the box. Then, return them to the box along with a new ball, on which the absolute difference of the integers written on the two balls is written. Determine whether it is possible for Snuke to reach the state where the box contains a ball on which the integer K is written.
[{"input": "3 7\n 9 3 4", "output": "POSSIBLE\n \n\nFirst, take out the two balls 9 and 4, and return them back along with a new\nball, abs(9-4)=5. Next, take out 3 and 5, and return them back along with\nabs(3-5)=2. Finally, take out 9 and 2, and return them back along with\nabs(9-2)=7. Now we have 7 in the box, and the answer is therefore `POSSIBLE`.\n\n* * *"}, {"input": "3 5\n 6 9 3", "output": "IMPOSSIBLE\n \n\nNo matter what we do, it is not possible to have 5 in the box. The answer is\ntherefore `IMPOSSIBLE`.\n\n* * *"}, {"input": "4 11\n 11 3 7 15", "output": "POSSIBLE\n \n\nThe box already contains 11 before we do anything. The answer is therefore\n`POSSIBLE`.\n\n* * *"}, {"input": "5 12\n 10 2 8 6 4", "output": "IMPOSSIBLE"}]
If it is possible for Snuke to reach the state where the box contains a ball on which the integer K is written, print `POSSIBLE`; if it is not possible, print `IMPOSSIBLE`. * * *
s913722719
Runtime Error
p03651
Input is given from Standard Input in the following format: N K A_1 A_2 ... A_N
import math length,target = (int(n) for n in input().split(" ")) ball = [int(n) for n in input().split(" ")] gcd = ball[0] for i in range(1,length): gcd = math.gcd(gcd,ball[i]) if target % gcd == 0 and target <= max(ball)
Statement There is a box containing N balls. The i-th ball has the integer A_i written on it. Snuke can perform the following operation any number of times: * Take out two balls from the box. Then, return them to the box along with a new ball, on which the absolute difference of the integers written on the two balls is written. Determine whether it is possible for Snuke to reach the state where the box contains a ball on which the integer K is written.
[{"input": "3 7\n 9 3 4", "output": "POSSIBLE\n \n\nFirst, take out the two balls 9 and 4, and return them back along with a new\nball, abs(9-4)=5. Next, take out 3 and 5, and return them back along with\nabs(3-5)=2. Finally, take out 9 and 2, and return them back along with\nabs(9-2)=7. Now we have 7 in the box, and the answer is therefore `POSSIBLE`.\n\n* * *"}, {"input": "3 5\n 6 9 3", "output": "IMPOSSIBLE\n \n\nNo matter what we do, it is not possible to have 5 in the box. The answer is\ntherefore `IMPOSSIBLE`.\n\n* * *"}, {"input": "4 11\n 11 3 7 15", "output": "POSSIBLE\n \n\nThe box already contains 11 before we do anything. The answer is therefore\n`POSSIBLE`.\n\n* * *"}, {"input": "5 12\n 10 2 8 6 4", "output": "IMPOSSIBLE"}]
If it is possible for Snuke to reach the state where the box contains a ball on which the integer K is written, print `POSSIBLE`; if it is not possible, print `IMPOSSIBLE`. * * *
s827169306
Accepted
p03651
Input is given from Standard Input in the following format: N K A_1 A_2 ... A_N
import sys from sys import exit from collections import deque from bisect import bisect_left, bisect_right, insort_left, insort_right from heapq import heapify, heappop, heappush from itertools import product, permutations, combinations, combinations_with_replacement from functools import reduce from math import gcd, sin, cos, tan, asin, acos, atan, degrees, radians sys.setrecursionlimit(10**6) INF = 10**20 eps = 1.0e-20 MOD = 10**9 + 7 def lcm(x, y): return x * y // gcd(x, y) def lgcd(l): return reduce(gcd, l) def llcm(l): return reduce(lcm, l) def powmod(n, i, mod): return pow(n, mod - 1 + i, mod) if i < 0 else pow(n, i, mod) def div2(x): return x.bit_length() def div10(x): return len(str(x)) - (x == 0) def perm(n, mod=None): ans = 1 for i in range(1, n + 1): ans *= i if mod != None: ans %= mod return ans def intput(): return int(input()) def mint(): return map(int, input().split()) def lint(): return list(map(int, input().split())) def ilint(): return int(input()), list(map(int, input().split())) def judge(x, l=["Yes", "No"]): print(l[0] if x else l[1]) def lprint(l, sep="\n"): for x in l: print(x, end=sep) def ston(c, c0="a"): return ord(c) - ord(c0) def ntos(x, c0="a"): return chr(x + ord(c0)) class counter(dict): def __init__(self, *args): super().__init__(args) def add(self, x, d=1): self.setdefault(x, 0) self[x] += d def list(self): l = [] for k in self: l.extend([k] * self[k]) return l class comb: def __init__(self, n, mod=None): self.l = [1] self.n = n self.mod = mod def get(self, k): l, n, mod = self.l, self.n, self.mod k = n - k if k > n // 2 else k while len(l) <= k: i = len(l) l.append( l[i - 1] * (n + 1 - i) // i if mod == None else (l[i - 1] * (n + 1 - i) * powmod(i, -1, mod)) % mod ) return l[k] def pf(x): C = counter() p = 2 while x > 1: k = 0 while x % p == 0: x //= p k += 1 if k > 0: C.add(p, k) p = p + 2 - (p == 2) if p * p < x else x return C N, K = mint() A = lint() judge(K <= max(A) and K % lgcd(A) == 0, ["POSSIBLE", "IMPOSSIBLE"])
Statement There is a box containing N balls. The i-th ball has the integer A_i written on it. Snuke can perform the following operation any number of times: * Take out two balls from the box. Then, return them to the box along with a new ball, on which the absolute difference of the integers written on the two balls is written. Determine whether it is possible for Snuke to reach the state where the box contains a ball on which the integer K is written.
[{"input": "3 7\n 9 3 4", "output": "POSSIBLE\n \n\nFirst, take out the two balls 9 and 4, and return them back along with a new\nball, abs(9-4)=5. Next, take out 3 and 5, and return them back along with\nabs(3-5)=2. Finally, take out 9 and 2, and return them back along with\nabs(9-2)=7. Now we have 7 in the box, and the answer is therefore `POSSIBLE`.\n\n* * *"}, {"input": "3 5\n 6 9 3", "output": "IMPOSSIBLE\n \n\nNo matter what we do, it is not possible to have 5 in the box. The answer is\ntherefore `IMPOSSIBLE`.\n\n* * *"}, {"input": "4 11\n 11 3 7 15", "output": "POSSIBLE\n \n\nThe box already contains 11 before we do anything. The answer is therefore\n`POSSIBLE`.\n\n* * *"}, {"input": "5 12\n 10 2 8 6 4", "output": "IMPOSSIBLE"}]
If it is possible for Snuke to reach the state where the box contains a ball on which the integer K is written, print `POSSIBLE`; if it is not possible, print `IMPOSSIBLE`. * * *
s013579483
Runtime Error
p03651
Input is given from Standard Input in the following format: N K A_1 A_2 ... A_N
length, target = map(int, input().split(" ")) balls = sorted([int(n) for n in input().split(" ")]) minimum = balls[0] all_div = 1 if minimum > 1 else 0 all_even = 1 if target > balls[-1]: print("IMPOSSIBLE") else: for t in balls: if t == target: print("POSSIBLE") break if t % minimum != 0: all_div = 0 if t % 2 == 1: all_even = 0 else: if all_div: print("IMPOSSIBLE") elif all_even and target % 2 == 0: print("IMPOSSIBLE") elif: print("POSSIBLE")
Statement There is a box containing N balls. The i-th ball has the integer A_i written on it. Snuke can perform the following operation any number of times: * Take out two balls from the box. Then, return them to the box along with a new ball, on which the absolute difference of the integers written on the two balls is written. Determine whether it is possible for Snuke to reach the state where the box contains a ball on which the integer K is written.
[{"input": "3 7\n 9 3 4", "output": "POSSIBLE\n \n\nFirst, take out the two balls 9 and 4, and return them back along with a new\nball, abs(9-4)=5. Next, take out 3 and 5, and return them back along with\nabs(3-5)=2. Finally, take out 9 and 2, and return them back along with\nabs(9-2)=7. Now we have 7 in the box, and the answer is therefore `POSSIBLE`.\n\n* * *"}, {"input": "3 5\n 6 9 3", "output": "IMPOSSIBLE\n \n\nNo matter what we do, it is not possible to have 5 in the box. The answer is\ntherefore `IMPOSSIBLE`.\n\n* * *"}, {"input": "4 11\n 11 3 7 15", "output": "POSSIBLE\n \n\nThe box already contains 11 before we do anything. The answer is therefore\n`POSSIBLE`.\n\n* * *"}, {"input": "5 12\n 10 2 8 6 4", "output": "IMPOSSIBLE"}]
If it is possible for Snuke to reach the state where the box contains a ball on which the integer K is written, print `POSSIBLE`; if it is not possible, print `IMPOSSIBLE`. * * *
s653598700
Accepted
p03651
Input is given from Standard Input in the following format: N K A_1 A_2 ... A_N
from subprocess import * with open("Main.java", "w") as f: f.write( r""" import java.util.Scanner; public class Main { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int n = Integer.parseInt(sc.next()); int k = Integer.parseInt(sc.next()); int max = 0; int gcd = 0; for (int i = 0; i < n; i++) { int a = Integer.parseInt(sc.next()); max = Math.max(max, a); gcd = gcd(gcd, a); } if (k <= max && k % gcd == 0) System.out.println("POSSIBLE"); else System.out.println("IMPOSSIBLE"); } static int gcd(int a, int b) { if(b == 0) return a; return gcd(b, a%b); } } """ ) call(("javac", "Main.java")) call(("java", "Main"))
Statement There is a box containing N balls. The i-th ball has the integer A_i written on it. Snuke can perform the following operation any number of times: * Take out two balls from the box. Then, return them to the box along with a new ball, on which the absolute difference of the integers written on the two balls is written. Determine whether it is possible for Snuke to reach the state where the box contains a ball on which the integer K is written.
[{"input": "3 7\n 9 3 4", "output": "POSSIBLE\n \n\nFirst, take out the two balls 9 and 4, and return them back along with a new\nball, abs(9-4)=5. Next, take out 3 and 5, and return them back along with\nabs(3-5)=2. Finally, take out 9 and 2, and return them back along with\nabs(9-2)=7. Now we have 7 in the box, and the answer is therefore `POSSIBLE`.\n\n* * *"}, {"input": "3 5\n 6 9 3", "output": "IMPOSSIBLE\n \n\nNo matter what we do, it is not possible to have 5 in the box. The answer is\ntherefore `IMPOSSIBLE`.\n\n* * *"}, {"input": "4 11\n 11 3 7 15", "output": "POSSIBLE\n \n\nThe box already contains 11 before we do anything. The answer is therefore\n`POSSIBLE`.\n\n* * *"}, {"input": "5 12\n 10 2 8 6 4", "output": "IMPOSSIBLE"}]
Print the lexicographically smallest possible string that can be the string S after the K operations. * * *
s535117646
Wrong Answer
p02943
Input is given from Standard Input in the following format: N K S
N, K = map(int, input().split()) S = input() lex_min = "z" for char in S: lex_min = min(char, lex_min) if (1 << (K - 1)) > N: print(lex_min * N) else: U = S + S[::-1] candidates = [] for i in range(N, N << 1): if U[i] == lex_min: M = U[i - N + 1 : i + 1] if K > 1: candidates.append((1 << (K - 1)) * lex_min + M[: N - (1 << (K - 1))]) else: candidates.append(M) print(min(candidates))
Statement Takahashi has a string S of length N consisting of lowercase English letters. On this string, he will perform the following operation K times: * Let T be the string obtained by reversing S, and U be the string obtained by concatenating S and T in this order. * Let S' be some contiguous substring of U with length N, and replace S with S'. Among the strings that can be the string S after the K operations, find the lexicographically smallest possible one.
[{"input": "5 1\n bacba", "output": "aabca\n \n\nWhen S=`bacba`, T=`abcab`, U=`bacbaabcab`, and the optimal choice of S' is\nS'=`aabca`.\n\n* * *"}, {"input": "10 2\n bbaabbbaab", "output": "aaaabbaabb"}]
Print the lexicographically smallest possible string that can be the string S after the K operations. * * *
s916268329
Accepted
p02943
Input is given from Standard Input in the following format: N K S
N, K = map(int, input().split()) S = input() T = S[::-1] # 文字列反転 U = S + T D = [] for i in range(N): D.append(U[i : i + N]) D.sort() B = D[0] for i in range(N): if B[i] != B[0]: break if i * 1 << (K - 1) > N: print(B[0] * N) else: print((B[0] * (i * (1 << (K - 1))) + B[i:])[:N])
Statement Takahashi has a string S of length N consisting of lowercase English letters. On this string, he will perform the following operation K times: * Let T be the string obtained by reversing S, and U be the string obtained by concatenating S and T in this order. * Let S' be some contiguous substring of U with length N, and replace S with S'. Among the strings that can be the string S after the K operations, find the lexicographically smallest possible one.
[{"input": "5 1\n bacba", "output": "aabca\n \n\nWhen S=`bacba`, T=`abcab`, U=`bacbaabcab`, and the optimal choice of S' is\nS'=`aabca`.\n\n* * *"}, {"input": "10 2\n bbaabbbaab", "output": "aaaabbaabb"}]
Print the lexicographically smallest possible string that can be the string S after the K operations. * * *
s933585483
Wrong Answer
p02943
Input is given from Standard Input in the following format: N K S
# coding:utf-8 tp = input().split() N = int(tp[0]) K = int(tp[1]) S = input() Sd = "" for i in range(K): T = S[::-1] U = S + T rtp = [] for h in range(K): rtp.append(U[h : h + N]) rtp.sort() Sd = rtp[0] S = Sd print(Sd)
Statement Takahashi has a string S of length N consisting of lowercase English letters. On this string, he will perform the following operation K times: * Let T be the string obtained by reversing S, and U be the string obtained by concatenating S and T in this order. * Let S' be some contiguous substring of U with length N, and replace S with S'. Among the strings that can be the string S after the K operations, find the lexicographically smallest possible one.
[{"input": "5 1\n bacba", "output": "aabca\n \n\nWhen S=`bacba`, T=`abcab`, U=`bacbaabcab`, and the optimal choice of S' is\nS'=`aabca`.\n\n* * *"}, {"input": "10 2\n bbaabbbaab", "output": "aaaabbaabb"}]
Print the lexicographically smallest possible string that can be the string S after the K operations. * * *
s752849296
Wrong Answer
p02943
Input is given from Standard Input in the following format: N K S
U = "" arr = [] lines = input().split(" ") N = int(lines[0]) K = int(lines[1]) S = input() T = S[::-1] for i in range(K): U += S U += T num = len(U) for j in range(num): if j + N <= num: arr.append(U[j : (j + N)]) arr.sort() print(arr[0])
Statement Takahashi has a string S of length N consisting of lowercase English letters. On this string, he will perform the following operation K times: * Let T be the string obtained by reversing S, and U be the string obtained by concatenating S and T in this order. * Let S' be some contiguous substring of U with length N, and replace S with S'. Among the strings that can be the string S after the K operations, find the lexicographically smallest possible one.
[{"input": "5 1\n bacba", "output": "aabca\n \n\nWhen S=`bacba`, T=`abcab`, U=`bacbaabcab`, and the optimal choice of S' is\nS'=`aabca`.\n\n* * *"}, {"input": "10 2\n bbaabbbaab", "output": "aaaabbaabb"}]
Print the lexicographically smallest possible string that can be the string S after the K operations. * * *
s763438595
Wrong Answer
p02943
Input is given from Standard Input in the following format: N K S
N, K = map(int, input().split()) S = input() candidates = [] for i in range(K): S += S[::-1] for j in range(len(S)): if len(S) - (j + N) >= 0: candidates.append(S[j : j + N]) else: remain = len(S[j:]) S[: N - remain] candidates.append(S[j:] + S[: N - remain]) candidates = sorted(candidates) S = candidates[0] print(S)
Statement Takahashi has a string S of length N consisting of lowercase English letters. On this string, he will perform the following operation K times: * Let T be the string obtained by reversing S, and U be the string obtained by concatenating S and T in this order. * Let S' be some contiguous substring of U with length N, and replace S with S'. Among the strings that can be the string S after the K operations, find the lexicographically smallest possible one.
[{"input": "5 1\n bacba", "output": "aabca\n \n\nWhen S=`bacba`, T=`abcab`, U=`bacbaabcab`, and the optimal choice of S' is\nS'=`aabca`.\n\n* * *"}, {"input": "10 2\n bbaabbbaab", "output": "aaaabbaabb"}]
Print the lexicographically smallest possible string that can be the string S after the K operations. * * *
s968433079
Wrong Answer
p02943
Input is given from Standard Input in the following format: N K S
n, k = (int(i) for i in input().split()) s1 = input()
Statement Takahashi has a string S of length N consisting of lowercase English letters. On this string, he will perform the following operation K times: * Let T be the string obtained by reversing S, and U be the string obtained by concatenating S and T in this order. * Let S' be some contiguous substring of U with length N, and replace S with S'. Among the strings that can be the string S after the K operations, find the lexicographically smallest possible one.
[{"input": "5 1\n bacba", "output": "aabca\n \n\nWhen S=`bacba`, T=`abcab`, U=`bacbaabcab`, and the optimal choice of S' is\nS'=`aabca`.\n\n* * *"}, {"input": "10 2\n bbaabbbaab", "output": "aaaabbaabb"}]
Print the lexicographically smallest possible string that can be the string S after the K operations. * * *
s706033204
Wrong Answer
p02943
Input is given from Standard Input in the following format: N K S
n, k = map(int, input().split()) S = list(input()) for i in range(n): S[i] = ord(S[i]) - 97 T = S[::-1] U = S + T f = 0 for i in range(26): A = [] for j in range(2 * n): if U[j] == i: f = 1 A.append(j) if f == 1: c = i break B = [] for i in range(1, len(A)): a = 1 if A[i] == A[i - 1] + 1: a = a + 1 if A[i] >= n: B.append([a, A[i]]) else: a = 1 if A[i] >= n: B.append([a, A[i]]) C = [] b = max(B[i][0] for i in range(len(B))) for i in range(len(B)): if B[i][0] == b: C.append(B[i][1]) if b * 2 ** (k - 1) >= n: for i in range(n): print(chr(97 + c), end="") print() exit() Ans = [] d = n - b * 2 ** (k - 1) for i in range(len(C)): AAns = U[C[i] - d - 1 : C[i] - 1] Ans.append(AAns[::-1]) Ans.sort() for i in range(b * 2 ** (k - 1)): print(chr(97 + c), end="") for i in range(n - b * 2 ** (k - 1)): print(chr(97 + Ans[0][i]), end="") print()
Statement Takahashi has a string S of length N consisting of lowercase English letters. On this string, he will perform the following operation K times: * Let T be the string obtained by reversing S, and U be the string obtained by concatenating S and T in this order. * Let S' be some contiguous substring of U with length N, and replace S with S'. Among the strings that can be the string S after the K operations, find the lexicographically smallest possible one.
[{"input": "5 1\n bacba", "output": "aabca\n \n\nWhen S=`bacba`, T=`abcab`, U=`bacbaabcab`, and the optimal choice of S' is\nS'=`aabca`.\n\n* * *"}, {"input": "10 2\n bbaabbbaab", "output": "aaaabbaabb"}]
Print the smallest initial amount of money W that enables you to win the game. * * *
s731188787
Runtime Error
p03344
Input is given from Standard Input in the following format: N M A_1 B_1 A_2 B_2 : A_N B_N U_1 V_1 U_2 V_2 : U_M V_M
import sys, random, time, bisect input = sys.stdin.buffer.readline start = time.time() N = int(input()) vw = [(-1, -1)] for i in range(N): vw.append(tuple(map(int, input().split()))) dp = [[] for i in range(2**9)] def make_dp(v): t = [[0, 0] for i in range(15)] V = v id = 0 while v >= 1: t[id] = vw[v] id += 1 v //= 2 n = id temp = [[0, 0] for i in range(2**n)] for i in range(n): for j in range(2**i, 2 ** (i + 1)): temp[j][0] = temp[j - 2**i][0] + t[i][0] temp[j][1] = temp[j - 2**i][1] + t[i][1] temp.sort(key=lambda x: x[1]) for i in range(1, 2**n): temp[i][0] = max(temp[i][0], temp[i - 1][0]) dp[V] = [0] * (10**5 + 1) for i in range(2**n - 1): L = temp[i][1] R = temp[i + 1][1] if L > 10**5: break elif R > 10**5: R = 10**5 + 1 for j in range(L, R): dp[V][j] = temp[i][0] else: L = temp[-1][1] if L <= 10**5: for j in range(L, 10**5 + 1): dp[V][j] = temp[-1][0] MAX = min(2**9, N + 1) for i in range(1, MAX): make_dp(i) Q = int(input()) query = [[] for i in range(N + 1)] for i in range(Q): v, L = map(int, input().split()) query[v].append((L, i)) ans = [0] * Q temp = [[0, 0] for i in range(2**9)] solved = [False] * (N + 1) def solve(v): subq = [] t = [] check = [] id = 0 while v >= 2**9: t.append(vw[v]) subq.append(v) check.append(id) id += 1 v //= 2 if not subq: subq = [v] check = [0] t = t[::-1] n = len(t) for i in range(n): for j in range(2**i, 2 ** (i + 1)): temp[j][0] = temp[j - 2**i][0] + t[i][0] temp[j][1] = temp[j - 2**i][1] + t[i][1] for i in range(len(check)): V = subq[i] if not solved[V]: solved[V] = True for L, ID in query[V]: res = 0 m = n - check[i] for i in range(2**m): if L >= temp[i][1]: res = max(res, temp[i][0] + dp[v][L - temp[i][1]]) ans[ID] = res for i in range(1, N + 1): if query[i] and not solved[i]: solve(i) for i in range(Q): print(ans[i])
Statement There is a simple undirected graph with N vertices and M edges. The vertices are numbered 1 through N, and the edges are numbered 1 through M. Edge i connects Vertex U_i and V_i. Also, Vertex i has two predetermined integers A_i and B_i. You will play the following game on this graph. First, choose one vertex and stand on it, with W yen (the currency of Japan) in your pocket. Here, A_s \leq W must hold, where s is the vertex you choose. Then, perform the following two kinds of operations any number of times in any order: * Choose one vertex v that is directly connected by an edge to the vertex you are standing on, and move to vertex v. Here, you need to have at least A_v yen in your pocket when you perform this move. * Donate B_v yen to the vertex v you are standing on. Here, the amount of money in your pocket must not become less than 0 yen. You win the game when you donate once to every vertex. Find the smallest initial amount of money W that enables you to win the game.
[{"input": "4 5\n 3 1\n 1 2\n 4 1\n 6 2\n 1 2\n 2 3\n 2 4\n 1 4\n 3 4", "output": "6\n \n\nIf you have 6 yen initially, you can win the game as follows:\n\n * Stand on Vertex 4. This is possible since you have not less than 6 yen.\n * Donate 2 yen to Vertex 4. Now you have 4 yen.\n * Move to Vertex 3. This is possible since you have not less than 4 yen.\n * Donate 1 yen to Vertex 3. Now you have 3 yen.\n * Move to Vertex 2. This is possible since you have not less than 1 yen.\n * Move to Vertex 1. This is possible since you have not less than 3 yen.\n * Donate 1 yen to Vertex 1. Now you have 2 yen.\n * Move to Vertex 2. This is possible since you have not less than 1 yen.\n * Donate 2 yen to Vertex 2. Now you have 0 yen.\n\nIf you have less than 6 yen initially, you cannot win the game. Thus, the\nanswer is 6.\n\n* * *"}, {"input": "5 8\n 6 4\n 15 13\n 15 19\n 15 1\n 20 7\n 1 3\n 1 4\n 1 5\n 2 3\n 2 4\n 2 5\n 3 5\n 4 5", "output": "44\n \n\n* * *"}, {"input": "9 10\n 131 2\n 98 79\n 242 32\n 231 38\n 382 82\n 224 22\n 140 88\n 209 70\n 164 64\n 6 8\n 1 6\n 1 4\n 1 3\n 4 7\n 4 9\n 3 7\n 3 9\n 5 9\n 2 5", "output": "582"}]
Print the smallest initial amount of money W that enables you to win the game. * * *
s933646649
Runtime Error
p03344
Input is given from Standard Input in the following format: N M A_1 B_1 A_2 B_2 : A_N B_N U_1 V_1 U_2 V_2 : U_M V_M
N, K, Q = [int(i) for i in input().split(" ")] A = [int(a) for a in input().split(" ")] _min = min(A) A.sort() for k in range(K): _max = A.pop(0) print(_max - _min)
Statement There is a simple undirected graph with N vertices and M edges. The vertices are numbered 1 through N, and the edges are numbered 1 through M. Edge i connects Vertex U_i and V_i. Also, Vertex i has two predetermined integers A_i and B_i. You will play the following game on this graph. First, choose one vertex and stand on it, with W yen (the currency of Japan) in your pocket. Here, A_s \leq W must hold, where s is the vertex you choose. Then, perform the following two kinds of operations any number of times in any order: * Choose one vertex v that is directly connected by an edge to the vertex you are standing on, and move to vertex v. Here, you need to have at least A_v yen in your pocket when you perform this move. * Donate B_v yen to the vertex v you are standing on. Here, the amount of money in your pocket must not become less than 0 yen. You win the game when you donate once to every vertex. Find the smallest initial amount of money W that enables you to win the game.
[{"input": "4 5\n 3 1\n 1 2\n 4 1\n 6 2\n 1 2\n 2 3\n 2 4\n 1 4\n 3 4", "output": "6\n \n\nIf you have 6 yen initially, you can win the game as follows:\n\n * Stand on Vertex 4. This is possible since you have not less than 6 yen.\n * Donate 2 yen to Vertex 4. Now you have 4 yen.\n * Move to Vertex 3. This is possible since you have not less than 4 yen.\n * Donate 1 yen to Vertex 3. Now you have 3 yen.\n * Move to Vertex 2. This is possible since you have not less than 1 yen.\n * Move to Vertex 1. This is possible since you have not less than 3 yen.\n * Donate 1 yen to Vertex 1. Now you have 2 yen.\n * Move to Vertex 2. This is possible since you have not less than 1 yen.\n * Donate 2 yen to Vertex 2. Now you have 0 yen.\n\nIf you have less than 6 yen initially, you cannot win the game. Thus, the\nanswer is 6.\n\n* * *"}, {"input": "5 8\n 6 4\n 15 13\n 15 19\n 15 1\n 20 7\n 1 3\n 1 4\n 1 5\n 2 3\n 2 4\n 2 5\n 3 5\n 4 5", "output": "44\n \n\n* * *"}, {"input": "9 10\n 131 2\n 98 79\n 242 32\n 231 38\n 382 82\n 224 22\n 140 88\n 209 70\n 164 64\n 6 8\n 1 6\n 1 4\n 1 3\n 4 7\n 4 9\n 3 7\n 3 9\n 5 9\n 2 5", "output": "582"}]
Print the maximum possible score of a'. * * *
s354936525
Wrong Answer
p03714
Input is given from Standard Input in the following format: N a_1 a_2 ... a_{3N}
import sys input = sys.stdin.readline n = int(input()) a = list(map(int, input().split()))
Statement Let N be a positive integer. There is a numerical sequence of length 3N, a = (a_1, a_2, ..., a_{3N}). Snuke is constructing a new sequence of length 2N, a', by removing exactly N elements from a without changing the order of the remaining elements. Here, the score of a' is defined as follows: (the sum of the elements in the first half of a') - (the sum of the elements in the second half of a'). Find the maximum possible score of a'.
[{"input": "2\n 3 1 4 1 5 9", "output": "1\n \n\nWhen a_2 and a_6 are removed, a' will be (3, 4, 1, 5), which has a score of (3\n+ 4) - (1 + 5) = 1.\n\n* * *"}, {"input": "1\n 1 2 3", "output": "-1\n \n\nFor example, when a_1 are removed, a' will be (2, 3), which has a score of 2 -\n3 = -1.\n\n* * *"}, {"input": "3\n 8 2 2 7 4 6 5 3 8", "output": "5\n \n\nFor example, when a_2, a_3 and a_9 are removed, a' will be (8, 7, 4, 6, 5, 3),\nwhich has a score of (8 + 7 + 4) - (6 + 5 + 3) = 5."}]
Print the maximum possible score of a'. * * *
s907509554
Runtime Error
p03714
Input is given from Standard Input in the following format: N a_1 a_2 ... a_{3N}
import heapq n=int(input()) l=list(map(int,input().split())) q=[] for i in range(n): heapq.heappush(q,l[i]) a1=[0]*(n+1) a1[0]=sum(l[:n]) for i in range(n): p=heapq.heappop(q) a1[i+1]=a1[i]-p+max(p,l[i+n]) heapq.heappush(q,max(p,l[i+n])) q=[] l.reverse() for i in range(n): heapq.heappush(q,-l[i]) a1.reverse() a1[0]-=sum(l[:n]) z=sum(l[:n]) for i in range(n): p=heapq.heappop(q) z=z-min(-p,l[i+n]) a1[i+1]-=z heapq.heappush(q,max(p,-l[i+n]) print(max(a1))
Statement Let N be a positive integer. There is a numerical sequence of length 3N, a = (a_1, a_2, ..., a_{3N}). Snuke is constructing a new sequence of length 2N, a', by removing exactly N elements from a without changing the order of the remaining elements. Here, the score of a' is defined as follows: (the sum of the elements in the first half of a') - (the sum of the elements in the second half of a'). Find the maximum possible score of a'.
[{"input": "2\n 3 1 4 1 5 9", "output": "1\n \n\nWhen a_2 and a_6 are removed, a' will be (3, 4, 1, 5), which has a score of (3\n+ 4) - (1 + 5) = 1.\n\n* * *"}, {"input": "1\n 1 2 3", "output": "-1\n \n\nFor example, when a_1 are removed, a' will be (2, 3), which has a score of 2 -\n3 = -1.\n\n* * *"}, {"input": "3\n 8 2 2 7 4 6 5 3 8", "output": "5\n \n\nFor example, when a_2, a_3 and a_9 are removed, a' will be (8, 7, 4, 6, 5, 3),\nwhich has a score of (8 + 7 + 4) - (6 + 5 + 3) = 5."}]
Print the maximum possible score of a'. * * *
s382503192
Runtime Error
p03714
Input is given from Standard Input in the following format: N a_1 a_2 ... a_{3N}
from random import choice N = int(input()) lista = [] total = 0 for criando in range(0, 3 * N): a = int(input()) lista.append(a) for loop in range(0, N): escolhido = choice(lista) if escolhido in lista: lista.remove(escolhido) for conta in range(0, len(lista)): if conta < (len(lista)) / 2: total += lista[conta] else: total -= lista[conta] print(total)
Statement Let N be a positive integer. There is a numerical sequence of length 3N, a = (a_1, a_2, ..., a_{3N}). Snuke is constructing a new sequence of length 2N, a', by removing exactly N elements from a without changing the order of the remaining elements. Here, the score of a' is defined as follows: (the sum of the elements in the first half of a') - (the sum of the elements in the second half of a'). Find the maximum possible score of a'.
[{"input": "2\n 3 1 4 1 5 9", "output": "1\n \n\nWhen a_2 and a_6 are removed, a' will be (3, 4, 1, 5), which has a score of (3\n+ 4) - (1 + 5) = 1.\n\n* * *"}, {"input": "1\n 1 2 3", "output": "-1\n \n\nFor example, when a_1 are removed, a' will be (2, 3), which has a score of 2 -\n3 = -1.\n\n* * *"}, {"input": "3\n 8 2 2 7 4 6 5 3 8", "output": "5\n \n\nFor example, when a_2, a_3 and a_9 are removed, a' will be (8, 7, 4, 6, 5, 3),\nwhich has a score of (8 + 7 + 4) - (6 + 5 + 3) = 5."}]
Print the maximum possible score of a'. * * *
s873264593
Runtime Error
p03714
Input is given from Standard Input in the following format: N a_1 a_2 ... a_{3N}
def d_3n_numbers(N, A): import heapq left = A[:N] heapq.heapify(left) # heappopはキューの最小値を取り出すが、rightからは最大値を取り出したいので-1を掛ける # 後にマイナスが付いているところは、それの帳尻を合わせている right = [-i for i in A[2 * N :]] heapq.heapify(right) # 最初、leftには数列の先頭N個が、rightには末尾N個が格納されている # 数列のN番目から2N番目まで順に、leftに格納して最小値を捨てることを繰り返す # 数列の2N番目からN番目まで順に、rightに格納して最大値を捨てることを繰り返す left_sum = [sum(left)] right_sum = [-sum(right)] for k in range(N, 2 * N): heapq.heappush(left, A[k]) v = heapq.heappop(left) left_sum.append(left_sum[-1] + A[k] - v) for k in range(2 * N - 1, N - 1, -1): heapq.heappush(right, -A[k]) v = heapq.heappop(right) right_sum.append(right_sum[-1] + A[k] - (-v)) score = [a - b for a, b in zip(left_sum, right_sum[::-1])] return max(score) N = int(input()) A = [int(i) for i in input().split()] print(d_3N_Numbers(N, A))
Statement Let N be a positive integer. There is a numerical sequence of length 3N, a = (a_1, a_2, ..., a_{3N}). Snuke is constructing a new sequence of length 2N, a', by removing exactly N elements from a without changing the order of the remaining elements. Here, the score of a' is defined as follows: (the sum of the elements in the first half of a') - (the sum of the elements in the second half of a'). Find the maximum possible score of a'.
[{"input": "2\n 3 1 4 1 5 9", "output": "1\n \n\nWhen a_2 and a_6 are removed, a' will be (3, 4, 1, 5), which has a score of (3\n+ 4) - (1 + 5) = 1.\n\n* * *"}, {"input": "1\n 1 2 3", "output": "-1\n \n\nFor example, when a_1 are removed, a' will be (2, 3), which has a score of 2 -\n3 = -1.\n\n* * *"}, {"input": "3\n 8 2 2 7 4 6 5 3 8", "output": "5\n \n\nFor example, when a_2, a_3 and a_9 are removed, a' will be (8, 7, 4, 6, 5, 3),\nwhich has a score of (8 + 7 + 4) - (6 + 5 + 3) = 5."}]
Print the maximum possible score of a'. * * *
s633055241
Wrong Answer
p03714
Input is given from Standard Input in the following format: N a_1 a_2 ... a_{3N}
N = int(input()) A = [int(i) for i in input().split()] score = [0] * (N + 1) score[0] = sum(A[0:N]) - sum(sorted(A[N : 3 * N])[0:N]) former = sorted(A[0 : N - 1]) latter = A[N : 3 * N] sorted_latter = sorted(latter) for i in range(1, N + 1): score[i] = score[i - 1] + A[N + i - 1] - A[N + i - 2] if former != []: if former[0] < A[N + i - 2]: score[i] += A[N + i - 2] - former[0] del former[0] former.append(A[N + i - 2]) former.sort(key=lambda x: x) if sorted_latter[N - 1] >= A[N + i - 1]: score[i] += A[N + i - 1] - sorted_latter[N] del latter[0] sorted_latter = sorted(latter) print(max(score) - 1)
Statement Let N be a positive integer. There is a numerical sequence of length 3N, a = (a_1, a_2, ..., a_{3N}). Snuke is constructing a new sequence of length 2N, a', by removing exactly N elements from a without changing the order of the remaining elements. Here, the score of a' is defined as follows: (the sum of the elements in the first half of a') - (the sum of the elements in the second half of a'). Find the maximum possible score of a'.
[{"input": "2\n 3 1 4 1 5 9", "output": "1\n \n\nWhen a_2 and a_6 are removed, a' will be (3, 4, 1, 5), which has a score of (3\n+ 4) - (1 + 5) = 1.\n\n* * *"}, {"input": "1\n 1 2 3", "output": "-1\n \n\nFor example, when a_1 are removed, a' will be (2, 3), which has a score of 2 -\n3 = -1.\n\n* * *"}, {"input": "3\n 8 2 2 7 4 6 5 3 8", "output": "5\n \n\nFor example, when a_2, a_3 and a_9 are removed, a' will be (8, 7, 4, 6, 5, 3),\nwhich has a score of (8 + 7 + 4) - (6 + 5 + 3) = 5."}]
Print the maximum possible score of a'. * * *
s674703771
Runtime Error
p03714
Input is given from Standard Input in the following format: N a_1 a_2 ... a_{3N}
n = int(input()) a = list(map(int, input().split())) r = [] b = a[:n] bs = sum(b) c = sorted(a[n:]) cs = sum(c[:n]) print(b, c, bs, cs, bs - cs) r.append(bs - cs) for k in range(n, 2 * n): b.append(a[k]) bm = min(b) b.remove(bm) bs = bs + a[k] - bm if n <= 1000: ci = c.index(a[k]) if ci < n: cs = cs - a[k] + c[n] c.pop(ci) print(b, c, bs, cs, bs - cs) r.append(bs - cs) print(max(r))
Statement Let N be a positive integer. There is a numerical sequence of length 3N, a = (a_1, a_2, ..., a_{3N}). Snuke is constructing a new sequence of length 2N, a', by removing exactly N elements from a without changing the order of the remaining elements. Here, the score of a' is defined as follows: (the sum of the elements in the first half of a') - (the sum of the elements in the second half of a'). Find the maximum possible score of a'.
[{"input": "2\n 3 1 4 1 5 9", "output": "1\n \n\nWhen a_2 and a_6 are removed, a' will be (3, 4, 1, 5), which has a score of (3\n+ 4) - (1 + 5) = 1.\n\n* * *"}, {"input": "1\n 1 2 3", "output": "-1\n \n\nFor example, when a_1 are removed, a' will be (2, 3), which has a score of 2 -\n3 = -1.\n\n* * *"}, {"input": "3\n 8 2 2 7 4 6 5 3 8", "output": "5\n \n\nFor example, when a_2, a_3 and a_9 are removed, a' will be (8, 7, 4, 6, 5, 3),\nwhich has a score of (8 + 7 + 4) - (6 + 5 + 3) = 5."}]
Print the maximum possible score of a'. * * *
s919687989
Wrong Answer
p03714
Input is given from Standard Input in the following format: N a_1 a_2 ... a_{3N}
import sys readline = sys.stdin.readline MOD = 10**9 + 7 INF = float("INF") sys.setrecursionlimit(10**5) import heapq class PriorityQueue: class Reverse: def __init__(self, val): self.val = val def __lt__(self, other): return self.val > other.val def __repr__(self): return repr(self.val) def __init__(self, x=None, desc=False): if not x: x = [] if desc: for i in range(len(x)): x[i] = self.Reverse(x[i]) self._desc = desc self._container = x heapq.heapify(self._container) @property def is_empty(self): return not self._container def pop(self): if self._desc: return heapq.heappop(self._container).val else: return heapq.heappop(self._container) def push(self, item): if self._desc: heapq.heappush(self._container, self.Reverse(item)) else: heapq.heappush(self._container, item) def top(self): if self._desc: return self._container[0].val else: return self._container[0] def sum(self): return sum(self._container) def __len__(self): return len(self._container) def main(): n = int(readline()) a = list(map(int, readline().split())) first = a[:n] second = a[n : 2 * n] third = a[2 * n : 3 * n] first_max = [0] * (n + 1) third_min = [0] * (n + 1) first_max[0] = sum(first) third_min[0] = sum(third) pq_first = PriorityQueue(first) cur = first_max[0] for i, x in enumerate(second, 1): if pq_first.top() < x: cur -= pq_first.pop() cur += x pq_first.push(x) first_max[i] = cur pq_third = PriorityQueue(third, desc=True) cur = third_min[0] for i, x in enumerate(second[::-1], 1): if pq_third.top() > x: cur -= pq_third.pop() cur += x pq_third.push(x) third_min[i] = cur ans = -INF for i in range(n): fi_idx = i th_idx = n - i ans = max(ans, first_max[fi_idx] - third_min[th_idx]) print(ans) if __name__ == "__main__": main()
Statement Let N be a positive integer. There is a numerical sequence of length 3N, a = (a_1, a_2, ..., a_{3N}). Snuke is constructing a new sequence of length 2N, a', by removing exactly N elements from a without changing the order of the remaining elements. Here, the score of a' is defined as follows: (the sum of the elements in the first half of a') - (the sum of the elements in the second half of a'). Find the maximum possible score of a'.
[{"input": "2\n 3 1 4 1 5 9", "output": "1\n \n\nWhen a_2 and a_6 are removed, a' will be (3, 4, 1, 5), which has a score of (3\n+ 4) - (1 + 5) = 1.\n\n* * *"}, {"input": "1\n 1 2 3", "output": "-1\n \n\nFor example, when a_1 are removed, a' will be (2, 3), which has a score of 2 -\n3 = -1.\n\n* * *"}, {"input": "3\n 8 2 2 7 4 6 5 3 8", "output": "5\n \n\nFor example, when a_2, a_3 and a_9 are removed, a' will be (8, 7, 4, 6, 5, 3),\nwhich has a score of (8 + 7 + 4) - (6 + 5 + 3) = 5."}]
Print the maximum possible score of a'. * * *
s929818980
Wrong Answer
p03714
Input is given from Standard Input in the following format: N a_1 a_2 ... a_{3N}
#!/usr/bin/env python3 from collections import defaultdict from collections import deque from heapq import heappush, heappop import sys import math import bisect import random import itertools sys.setrecursionlimit(10**5) stdin = sys.stdin bisect_left = bisect.bisect_left bisect_right = bisect.bisect_right def LI(): return list(map(int, stdin.readline().split())) def LF(): return list(map(float, stdin.readline().split())) def LI_(): return list(map(lambda x: int(x) - 1, stdin.readline().split())) def II(): return int(stdin.readline()) def IF(): return float(stdin.readline()) def LS(): return list(map(list, stdin.readline().split())) def S(): return list(stdin.readline().rstrip()) def IR(n): return [II() for _ in range(n)] def LIR(n): return [LI() for _ in range(n)] def FR(n): return [IF() for _ in range(n)] def LFR(n): return [LI() for _ in range(n)] def LIR_(n): return [LI_() for _ in range(n)] def SR(n): return [S() for _ in range(n)] def LSR(n): return [LS() for _ in range(n)] mod = 1000000007 inf = float("INF") # A def A(): x, y = LI() a = [1, 3, 5, 7, 8, 10, 12] b = [4, 6, 9, 11] c = [2] if x in a and y in a: print("Yes") return if x in b and y in b: print("Yes") return if x in c and y in c: print("Yes") return print("No") return # B def B(): h, w = LI() print("#" * (w + 2)) for _ in range(h): a = ["#"] for s in S(): a.append(s) a.append("#") print("".join(a)) print("#" * (w + 2)) return # C def C(): h, w = LI() ans = inf for i in range(1, h): ans = min( ans, max(i * w, (h - i) * (w // 2), (h - i) * (w - w // 2)) - min(i * w, (h - i) * (w // 2), (h - i) * (w - w // 2)), ) ans = min( ans, max(i * w, (h - i) // 2 * w, (h - i - (h - i) // 2) * w) - min(i * w, (h - i) // 2 * w, (h - i - (h - i) // 2) * w), ) h, w = w, h for i in range(1, h): ans = min( ans, max(i * w, (h - i) * (w // 2), (h - i) * (w - w // 2)) - min(i * w, (h - i) * (w // 2), (h - i) * (w - w // 2)), ) ans = min( ans, max(i * w, (h - i) // 2 * w, (h - i - (h - i) // 2) * w) - min(i * w, (h - i) // 2 * w, (h - i - (h - i) // 2) * w), ) print(ans) return # D # 解説AC # ある点kにおいて2つに分けてa'の # 前後半の要素を考える # シンプルにわからなかった def D(): n = II() a = LI() first_half_list = [] final_half_list = [] first_half_sum = deque([0]) final_half_sum = deque([0]) ans = -inf for i in range(n): heappush(first_half_list, a[i]) first_half_sum[0] += a[i] heappush(final_half_list, -a[-i - 1]) final_half_sum[0] -= a[-i - 1] for i in range(1, n + 1): q = heappop(first_half_list) heappush(first_half_list, max(q, a[i + n - 1])) first_half_sum.append(first_half_sum[-1] - q + max(q, a[i + n - 1])) q = heappop(final_half_list) heappush(final_half_list, max(q, -a[-n - i])) final_half_sum.appendleft(final_half_sum[-1] - q + max(q, -a[-n - i])) for i in range(n + 1): ans = max(ans, first_half_sum[i] + final_half_sum[i]) print(ans) return # Solve if __name__ == "__main__": D()
Statement Let N be a positive integer. There is a numerical sequence of length 3N, a = (a_1, a_2, ..., a_{3N}). Snuke is constructing a new sequence of length 2N, a', by removing exactly N elements from a without changing the order of the remaining elements. Here, the score of a' is defined as follows: (the sum of the elements in the first half of a') - (the sum of the elements in the second half of a'). Find the maximum possible score of a'.
[{"input": "2\n 3 1 4 1 5 9", "output": "1\n \n\nWhen a_2 and a_6 are removed, a' will be (3, 4, 1, 5), which has a score of (3\n+ 4) - (1 + 5) = 1.\n\n* * *"}, {"input": "1\n 1 2 3", "output": "-1\n \n\nFor example, when a_1 are removed, a' will be (2, 3), which has a score of 2 -\n3 = -1.\n\n* * *"}, {"input": "3\n 8 2 2 7 4 6 5 3 8", "output": "5\n \n\nFor example, when a_2, a_3 and a_9 are removed, a' will be (8, 7, 4, 6, 5, 3),\nwhich has a score of (8 + 7 + 4) - (6 + 5 + 3) = 5."}]
Print the maximum possible score of a'. * * *
s945508935
Wrong Answer
p03714
Input is given from Standard Input in the following format: N a_1 a_2 ... a_{3N}
N = int(input()) l = list(map(int, input().split())) mi = 0 for _ in range(N + 1): l1 = sorted(l[: (_ + N)]) l2 = sorted(l[(_ + N) :]) df = sum(l1[-N:]) - sum(l2[:N]) if df > mi: mi = df print(mi)
Statement Let N be a positive integer. There is a numerical sequence of length 3N, a = (a_1, a_2, ..., a_{3N}). Snuke is constructing a new sequence of length 2N, a', by removing exactly N elements from a without changing the order of the remaining elements. Here, the score of a' is defined as follows: (the sum of the elements in the first half of a') - (the sum of the elements in the second half of a'). Find the maximum possible score of a'.
[{"input": "2\n 3 1 4 1 5 9", "output": "1\n \n\nWhen a_2 and a_6 are removed, a' will be (3, 4, 1, 5), which has a score of (3\n+ 4) - (1 + 5) = 1.\n\n* * *"}, {"input": "1\n 1 2 3", "output": "-1\n \n\nFor example, when a_1 are removed, a' will be (2, 3), which has a score of 2 -\n3 = -1.\n\n* * *"}, {"input": "3\n 8 2 2 7 4 6 5 3 8", "output": "5\n \n\nFor example, when a_2, a_3 and a_9 are removed, a' will be (8, 7, 4, 6, 5, 3),\nwhich has a score of (8 + 7 + 4) - (6 + 5 + 3) = 5."}]
Print the maximum possible score of a'. * * *
s938655265
Accepted
p03714
Input is given from Standard Input in the following format: N a_1 a_2 ... a_{3N}
import heapq N = int(input()) a = list(map(int, input().split())) # print(a) b = a[::-1] A = a[:N] # print(A) AR = [A[0]] for i in range(1, len(A) * 2): AR.append(a[i] + AR[i - 1]) # print("AR",AR) AL = [] heapq.heapify(A) for i in range(N, N * 2): heapq.heappush(A, a[i]) AL.append(A[0]) heapq.heappop(A) # print(AL) ALR = [AL[0]] for i in range(1, len(AL)): ALR.append(ALR[i - 1] + AL[i]) # print(ALR) ANSA = [AR[N - 1]] for i in range(len(ALR)): ANSA.append(AR[N + i] - ALR[i]) # print(ANSA) B = b[:N] for i in range(len(B)): B[i] *= -1 # print("B",B) BR = [B[0]] for i in range(1, len(B) * 2): BR.append(-b[i] + BR[i - 1]) # print("BR",BR) BL = [] # print("B",B) heapq.heapify(B) for i in range(N, N * 2): heapq.heappush(B, -b[i]) BL.append(-B[0]) heapq.heappop(B) # print("BL",BL) BLR = [BL[0]] for i in range(1, len(BL)): BLR.append(BLR[i - 1] + BL[i]) # print("BLR",BLR) BNSA = [BR[N - 1]] for i in range(len(BLR)): BNSA.append(BR[N + i] + BLR[i]) # print(BNSA) BNSA = BNSA[::-1] # print(BNSA) ANS = -(10**20) for i in range(len(BNSA)): if (ANSA[i] + BNSA[i]) > ANS: ANS = ANSA[i] + BNSA[i] print(ANS)
Statement Let N be a positive integer. There is a numerical sequence of length 3N, a = (a_1, a_2, ..., a_{3N}). Snuke is constructing a new sequence of length 2N, a', by removing exactly N elements from a without changing the order of the remaining elements. Here, the score of a' is defined as follows: (the sum of the elements in the first half of a') - (the sum of the elements in the second half of a'). Find the maximum possible score of a'.
[{"input": "2\n 3 1 4 1 5 9", "output": "1\n \n\nWhen a_2 and a_6 are removed, a' will be (3, 4, 1, 5), which has a score of (3\n+ 4) - (1 + 5) = 1.\n\n* * *"}, {"input": "1\n 1 2 3", "output": "-1\n \n\nFor example, when a_1 are removed, a' will be (2, 3), which has a score of 2 -\n3 = -1.\n\n* * *"}, {"input": "3\n 8 2 2 7 4 6 5 3 8", "output": "5\n \n\nFor example, when a_2, a_3 and a_9 are removed, a' will be (8, 7, 4, 6, 5, 3),\nwhich has a score of (8 + 7 + 4) - (6 + 5 + 3) = 5."}]
Print the maximum possible score of a'. * * *
s232380271
Wrong Answer
p03714
Input is given from Standard Input in the following format: N a_1 a_2 ... a_{3N}
# 3N numbers n = int(input()) lists = list(map(int, input().split())) second = lists.copy() second = second[::-1] for i in range(3 * n): second[i] = -second[i] MAX = sum(lists[:n]) MIN = -sum(second[:n]) MAXlist = [0 for i in range(n + 1)] MINlist = [0 for i in range(n + 1)] MAXlist[0] = MAX MINlist[0] = MIN ANS = -(10**100) import heapq a = lists[:n] b = second[:n] heapq.heapify(a) # リストを優先度付きキューへ for j in range(n, 2 * n): heapq.heappush(a, lists[j]) # 要素の挿入 heapq.heappush(b, second[j]) mini = heapq.heappop(a) # 最小値の取り出し mini2 = heapq.heappop(b) MAX -= mini MIN += mini2 MAX += lists[j] MIN -= second[j] MAXlist[j + 1 - n] = MAX MINlist[j + 1 - n] = MIN MINlist = MINlist[::-1] for i in range(n + 1): ANS = max(ANS, MAXlist[i] - MINlist[i]) print(ANS)
Statement Let N be a positive integer. There is a numerical sequence of length 3N, a = (a_1, a_2, ..., a_{3N}). Snuke is constructing a new sequence of length 2N, a', by removing exactly N elements from a without changing the order of the remaining elements. Here, the score of a' is defined as follows: (the sum of the elements in the first half of a') - (the sum of the elements in the second half of a'). Find the maximum possible score of a'.
[{"input": "2\n 3 1 4 1 5 9", "output": "1\n \n\nWhen a_2 and a_6 are removed, a' will be (3, 4, 1, 5), which has a score of (3\n+ 4) - (1 + 5) = 1.\n\n* * *"}, {"input": "1\n 1 2 3", "output": "-1\n \n\nFor example, when a_1 are removed, a' will be (2, 3), which has a score of 2 -\n3 = -1.\n\n* * *"}, {"input": "3\n 8 2 2 7 4 6 5 3 8", "output": "5\n \n\nFor example, when a_2, a_3 and a_9 are removed, a' will be (8, 7, 4, 6, 5, 3),\nwhich has a score of (8 + 7 + 4) - (6 + 5 + 3) = 5."}]
Print the maximum possible score of a'. * * *
s569753388
Accepted
p03714
Input is given from Standard Input in the following format: N a_1 a_2 ... a_{3N}
from heapq import * N = int(input()) a = list(map(int, input().split())) sumS1 = [0 for i in range(N + 1)] S1 = a[0:N] heapify(S1) sumS1[0] = sum(S1) for k in range(1, N + 1): if S1[0] < a[N + k - 1]: sumS1[k] = sumS1[k - 1] + a[N + k - 1] - S1[0] heapreplace(S1, a[N + k - 1]) else: sumS1[k] = sumS1[k - 1] sumS2 = [0 for i in range(N + 1)] S2 = [-1 * i for i in a[2 * N : 3 * N]] heapify(S2) sumS2[N] = sum(S2) for k in range(1, N + 1): if S2[0] < -1 * a[2 * N - k]: sumS2[N - k] = sumS2[N - k + 1] - a[2 * N - k] - S2[0] heapreplace(S2, -1 * a[2 * N - k]) else: sumS2[N - k] = sumS2[N - k + 1] res = [float("-inf")] * (N + 1) for i in range(N + 1): res[i] = sumS1[i] + sumS2[i] res.sort() print(res[N])
Statement Let N be a positive integer. There is a numerical sequence of length 3N, a = (a_1, a_2, ..., a_{3N}). Snuke is constructing a new sequence of length 2N, a', by removing exactly N elements from a without changing the order of the remaining elements. Here, the score of a' is defined as follows: (the sum of the elements in the first half of a') - (the sum of the elements in the second half of a'). Find the maximum possible score of a'.
[{"input": "2\n 3 1 4 1 5 9", "output": "1\n \n\nWhen a_2 and a_6 are removed, a' will be (3, 4, 1, 5), which has a score of (3\n+ 4) - (1 + 5) = 1.\n\n* * *"}, {"input": "1\n 1 2 3", "output": "-1\n \n\nFor example, when a_1 are removed, a' will be (2, 3), which has a score of 2 -\n3 = -1.\n\n* * *"}, {"input": "3\n 8 2 2 7 4 6 5 3 8", "output": "5\n \n\nFor example, when a_2, a_3 and a_9 are removed, a' will be (8, 7, 4, 6, 5, 3),\nwhich has a score of (8 + 7 + 4) - (6 + 5 + 3) = 5."}]
Print the maximum possible score of a'. * * *
s547011488
Accepted
p03714
Input is given from Standard Input in the following format: N a_1 a_2 ... a_{3N}
import heapq N = int(input()) A = [int(x) for x in input().split()] a = A[:N] b = A[-N:] c = A[N:-N] res = [sum(a)] heapq.heapify(a) for i in range(N): heapq.heappush(a, c[i]) k = heapq.heappop(a) res.append(res[-1] + c[i] - k) cnt = sum(b) for i in range(N): b[i] *= -1 max_ans = res[N] - cnt heapq.heapify(b) for i in range(N - 1, -1, -1): heapq.heappush(b, -c[i]) k = heapq.heappop(b) res[i] -= cnt + c[i] + k cnt = cnt + c[i] + k max_ans = max(max_ans, res[i]) print(max_ans)
Statement Let N be a positive integer. There is a numerical sequence of length 3N, a = (a_1, a_2, ..., a_{3N}). Snuke is constructing a new sequence of length 2N, a', by removing exactly N elements from a without changing the order of the remaining elements. Here, the score of a' is defined as follows: (the sum of the elements in the first half of a') - (the sum of the elements in the second half of a'). Find the maximum possible score of a'.
[{"input": "2\n 3 1 4 1 5 9", "output": "1\n \n\nWhen a_2 and a_6 are removed, a' will be (3, 4, 1, 5), which has a score of (3\n+ 4) - (1 + 5) = 1.\n\n* * *"}, {"input": "1\n 1 2 3", "output": "-1\n \n\nFor example, when a_1 are removed, a' will be (2, 3), which has a score of 2 -\n3 = -1.\n\n* * *"}, {"input": "3\n 8 2 2 7 4 6 5 3 8", "output": "5\n \n\nFor example, when a_2, a_3 and a_9 are removed, a' will be (8, 7, 4, 6, 5, 3),\nwhich has a score of (8 + 7 + 4) - (6 + 5 + 3) = 5."}]
Print the answer. * * *
s527205366
Wrong Answer
p02806
Input is given from Standard Input in the following format: N s_1 t_1 \vdots s_{N} t_N X
print(6348)
Statement Niwango created a playlist of N songs. The title and the duration of the i-th song are s_i and t_i seconds, respectively. It is guaranteed that s_1,\ldots,s_N are all distinct. Niwango was doing some work while playing this playlist. (That is, all the songs were played once, in the order they appear in the playlist, without any pause in between.) However, he fell asleep during his work, and he woke up after all the songs were played. According to his record, it turned out that he fell asleep at the very end of the song titled X. Find the duration of time when some song was played while Niwango was asleep.
[{"input": "3\n dwango 2\n sixth 5\n prelims 25\n dwango", "output": "30\n \n\n * While Niwango was asleep, two songs were played: `sixth` and `prelims`.\n * The answer is the total duration of these songs, 30.\n\n* * *"}, {"input": "1\n abcde 1000\n abcde", "output": "0\n \n\n * No songs were played while Niwango was asleep.\n * In such a case, the total duration of songs is 0.\n\n* * *"}, {"input": "15\n ypnxn 279\n kgjgwx 464\n qquhuwq 327\n rxing 549\n pmuduhznoaqu 832\n dagktgdarveusju 595\n wunfagppcoi 200\n dhavrncwfw 720\n jpcmigg 658\n wrczqxycivdqn 639\n mcmkkbnjfeod 992\n htqvkgkbhtytsz 130\n twflegsjz 467\n dswxxrxuzzfhkp 989\n szfwtzfpnscgue 958\n pmuduhznoaqu", "output": "6348"}]
Print the answer. * * *
s009956833
Wrong Answer
p02806
Input is given from Standard Input in the following format: N s_1 t_1 \vdots s_{N} t_N X
N = int(input()) songs = [] times = [] for _ in range(N): song, time = input().split() songs.append(song) times.append(int(time)) start = input() number = songs.index(start) if number == len(songs): print(0) else: print(sum(times[1:]))
Statement Niwango created a playlist of N songs. The title and the duration of the i-th song are s_i and t_i seconds, respectively. It is guaranteed that s_1,\ldots,s_N are all distinct. Niwango was doing some work while playing this playlist. (That is, all the songs were played once, in the order they appear in the playlist, without any pause in between.) However, he fell asleep during his work, and he woke up after all the songs were played. According to his record, it turned out that he fell asleep at the very end of the song titled X. Find the duration of time when some song was played while Niwango was asleep.
[{"input": "3\n dwango 2\n sixth 5\n prelims 25\n dwango", "output": "30\n \n\n * While Niwango was asleep, two songs were played: `sixth` and `prelims`.\n * The answer is the total duration of these songs, 30.\n\n* * *"}, {"input": "1\n abcde 1000\n abcde", "output": "0\n \n\n * No songs were played while Niwango was asleep.\n * In such a case, the total duration of songs is 0.\n\n* * *"}, {"input": "15\n ypnxn 279\n kgjgwx 464\n qquhuwq 327\n rxing 549\n pmuduhznoaqu 832\n dagktgdarveusju 595\n wunfagppcoi 200\n dhavrncwfw 720\n jpcmigg 658\n wrczqxycivdqn 639\n mcmkkbnjfeod 992\n htqvkgkbhtytsz 130\n twflegsjz 467\n dswxxrxuzzfhkp 989\n szfwtzfpnscgue 958\n pmuduhznoaqu", "output": "6348"}]
Print the answer. * * *
s531412196
Accepted
p02806
Input is given from Standard Input in the following format: N s_1 t_1 \vdots s_{N} t_N X
import sys s2nn = lambda s: [int(c) for c in s.split(" ")] ss2nn = lambda ss: [int(s) for s in list(ss)] ss2nnn = lambda ss: [s2nn(s) for s in list(ss)] i2s = lambda: sys.stdin.readline().rstrip() i2n = lambda: int(i2s()) i2nn = lambda: s2nn(i2s()) ii2ss = lambda n: [i2s() for _ in range(n)] ii2nn = lambda n: ss2nn(ii2ss(n)) ii2nnn = lambda n: ss2nnn(ii2ss(n)) s2ss = lambda s: [int(c) for c in s.split(" ")] def main(): N = i2n() t_total = 0 d = {} for _ in range(N): s, t = sys.stdin.readline().rstrip().split(" ") t_total += int(t) d[s] = t_total X = i2s() print(t_total - d[X]) main()
Statement Niwango created a playlist of N songs. The title and the duration of the i-th song are s_i and t_i seconds, respectively. It is guaranteed that s_1,\ldots,s_N are all distinct. Niwango was doing some work while playing this playlist. (That is, all the songs were played once, in the order they appear in the playlist, without any pause in between.) However, he fell asleep during his work, and he woke up after all the songs were played. According to his record, it turned out that he fell asleep at the very end of the song titled X. Find the duration of time when some song was played while Niwango was asleep.
[{"input": "3\n dwango 2\n sixth 5\n prelims 25\n dwango", "output": "30\n \n\n * While Niwango was asleep, two songs were played: `sixth` and `prelims`.\n * The answer is the total duration of these songs, 30.\n\n* * *"}, {"input": "1\n abcde 1000\n abcde", "output": "0\n \n\n * No songs were played while Niwango was asleep.\n * In such a case, the total duration of songs is 0.\n\n* * *"}, {"input": "15\n ypnxn 279\n kgjgwx 464\n qquhuwq 327\n rxing 549\n pmuduhznoaqu 832\n dagktgdarveusju 595\n wunfagppcoi 200\n dhavrncwfw 720\n jpcmigg 658\n wrczqxycivdqn 639\n mcmkkbnjfeod 992\n htqvkgkbhtytsz 130\n twflegsjz 467\n dswxxrxuzzfhkp 989\n szfwtzfpnscgue 958\n pmuduhznoaqu", "output": "6348"}]
Print the answer. * * *
s729529774
Accepted
p02806
Input is given from Standard Input in the following format: N s_1 t_1 \vdots s_{N} t_N X
N = int(input()) list = [] for i in range(N): # 因数注意! n = input() m = n.split() p = [i for i in m] # 1列の数列をリスト化 list.append(p) x = input() a = 0 A = 0 for i in list: if a == 0: if x == i[0]: a = 1 else: pass else: A = A + int(i[1]) print(A)
Statement Niwango created a playlist of N songs. The title and the duration of the i-th song are s_i and t_i seconds, respectively. It is guaranteed that s_1,\ldots,s_N are all distinct. Niwango was doing some work while playing this playlist. (That is, all the songs were played once, in the order they appear in the playlist, without any pause in between.) However, he fell asleep during his work, and he woke up after all the songs were played. According to his record, it turned out that he fell asleep at the very end of the song titled X. Find the duration of time when some song was played while Niwango was asleep.
[{"input": "3\n dwango 2\n sixth 5\n prelims 25\n dwango", "output": "30\n \n\n * While Niwango was asleep, two songs were played: `sixth` and `prelims`.\n * The answer is the total duration of these songs, 30.\n\n* * *"}, {"input": "1\n abcde 1000\n abcde", "output": "0\n \n\n * No songs were played while Niwango was asleep.\n * In such a case, the total duration of songs is 0.\n\n* * *"}, {"input": "15\n ypnxn 279\n kgjgwx 464\n qquhuwq 327\n rxing 549\n pmuduhznoaqu 832\n dagktgdarveusju 595\n wunfagppcoi 200\n dhavrncwfw 720\n jpcmigg 658\n wrczqxycivdqn 639\n mcmkkbnjfeod 992\n htqvkgkbhtytsz 130\n twflegsjz 467\n dswxxrxuzzfhkp 989\n szfwtzfpnscgue 958\n pmuduhznoaqu", "output": "6348"}]
Print the answer. * * *
s028486723
Accepted
p02806
Input is given from Standard Input in the following format: N s_1 t_1 \vdots s_{N} t_N X
# -*- coding: utf-8 -*- import sys def input(): return sys.stdin.readline().strip() def list2d(a, b, c): return [[c] * b for i in range(a)] def list3d(a, b, c, d): return [[[d] * c for j in range(b)] for i in range(a)] def list4d(a, b, c, d, e): return [[[[e] * d for j in range(c)] for j in range(b)] for i in range(a)] def ceil(x, y=1): return int(-(-x // y)) def INT(): return int(input()) def MAP(): return map(int, input().split()) def LIST(N=None): return list(MAP()) if N is None else [INT() for i in range(N)] def Yes(): print("Yes") def No(): print("No") def YES(): print("YES") def NO(): print("NO") sys.setrecursionlimit(10**9) INF = 10**18 MOD = 10**9 + 7 N = INT() ST = [] D = {} for i in range(N): s, t = input().split() t = int(t) ST.append((s, t)) D[s] = i X = input() idx = D[X] ans = 0 for i in range(idx + 1, N): ans += ST[i][1] print(ans)
Statement Niwango created a playlist of N songs. The title and the duration of the i-th song are s_i and t_i seconds, respectively. It is guaranteed that s_1,\ldots,s_N are all distinct. Niwango was doing some work while playing this playlist. (That is, all the songs were played once, in the order they appear in the playlist, without any pause in between.) However, he fell asleep during his work, and he woke up after all the songs were played. According to his record, it turned out that he fell asleep at the very end of the song titled X. Find the duration of time when some song was played while Niwango was asleep.
[{"input": "3\n dwango 2\n sixth 5\n prelims 25\n dwango", "output": "30\n \n\n * While Niwango was asleep, two songs were played: `sixth` and `prelims`.\n * The answer is the total duration of these songs, 30.\n\n* * *"}, {"input": "1\n abcde 1000\n abcde", "output": "0\n \n\n * No songs were played while Niwango was asleep.\n * In such a case, the total duration of songs is 0.\n\n* * *"}, {"input": "15\n ypnxn 279\n kgjgwx 464\n qquhuwq 327\n rxing 549\n pmuduhznoaqu 832\n dagktgdarveusju 595\n wunfagppcoi 200\n dhavrncwfw 720\n jpcmigg 658\n wrczqxycivdqn 639\n mcmkkbnjfeod 992\n htqvkgkbhtytsz 130\n twflegsjz 467\n dswxxrxuzzfhkp 989\n szfwtzfpnscgue 958\n pmuduhznoaqu", "output": "6348"}]
Print the answer. * * *
s916134615
Accepted
p02806
Input is given from Standard Input in the following format: N s_1 t_1 \vdots s_{N} t_N X
from collections import OrderedDict number_of_music = int(input()) dict = OrderedDict() for i in range(number_of_music): name, time = input().split() dict[name] = int(time) music_name_sleep = input() x = 0 sleeping_time = 0 for key, val in dict.items(): if x == 1: sleeping_time = sleeping_time + val if key == music_name_sleep: x = 1 print(sleeping_time)
Statement Niwango created a playlist of N songs. The title and the duration of the i-th song are s_i and t_i seconds, respectively. It is guaranteed that s_1,\ldots,s_N are all distinct. Niwango was doing some work while playing this playlist. (That is, all the songs were played once, in the order they appear in the playlist, without any pause in between.) However, he fell asleep during his work, and he woke up after all the songs were played. According to his record, it turned out that he fell asleep at the very end of the song titled X. Find the duration of time when some song was played while Niwango was asleep.
[{"input": "3\n dwango 2\n sixth 5\n prelims 25\n dwango", "output": "30\n \n\n * While Niwango was asleep, two songs were played: `sixth` and `prelims`.\n * The answer is the total duration of these songs, 30.\n\n* * *"}, {"input": "1\n abcde 1000\n abcde", "output": "0\n \n\n * No songs were played while Niwango was asleep.\n * In such a case, the total duration of songs is 0.\n\n* * *"}, {"input": "15\n ypnxn 279\n kgjgwx 464\n qquhuwq 327\n rxing 549\n pmuduhznoaqu 832\n dagktgdarveusju 595\n wunfagppcoi 200\n dhavrncwfw 720\n jpcmigg 658\n wrczqxycivdqn 639\n mcmkkbnjfeod 992\n htqvkgkbhtytsz 130\n twflegsjz 467\n dswxxrxuzzfhkp 989\n szfwtzfpnscgue 958\n pmuduhznoaqu", "output": "6348"}]
Print the answer. * * *
s545196663
Accepted
p02555
Input is given from Standard Input in the following format: S
s = int(input()) l = [0, 0, 1] for i in range(3, s): l.append((l[i - 1] + l[i - 3]) % (10**9 + 7)) print(l[s - 1] % (10**9 + 7))
Statement Given is an integer S. Find how many sequences there are whose terms are all integers greater than or equal to 3, and whose sum is equal to S. The answer can be very large, so output it modulo 10^9 + 7.
[{"input": "7", "output": "3\n \n\n3 sequences satisfy the condition: \\\\{3,4\\\\}, \\\\{4,3\\\\} and \\\\{7\\\\}.\n\n* * *"}, {"input": "2", "output": "0\n \n\nThere are no sequences that satisfy the condition.\n\n* * *"}, {"input": "1729", "output": "294867501"}]
Print the answer. * * *
s651509205
Accepted
p02555
Input is given from Standard Input in the following format: S
S = int(input()) x = 10**9 + 7 a = [0 for i in range(2001)] a[3] = 1 a[4] = 1 a[5] = 1 a[6] = 2 for i in range(7, S + 1): a[i] = (a[i - 1] + a[i - 3]) % x print(a[S])
Statement Given is an integer S. Find how many sequences there are whose terms are all integers greater than or equal to 3, and whose sum is equal to S. The answer can be very large, so output it modulo 10^9 + 7.
[{"input": "7", "output": "3\n \n\n3 sequences satisfy the condition: \\\\{3,4\\\\}, \\\\{4,3\\\\} and \\\\{7\\\\}.\n\n* * *"}, {"input": "2", "output": "0\n \n\nThere are no sequences that satisfy the condition.\n\n* * *"}, {"input": "1729", "output": "294867501"}]
Print the answer. * * *
s770069580
Wrong Answer
p02555
Input is given from Standard Input in the following format: S
S = lambda: input() I = lambda: int(input()) L = lambda: list(map(int, input().split())) LS = lambda: list(map(str, input().split())) s = I() mod = 10**9 + 7 div = s // 3 rem = s % 3 frac = [0] tmp1 = 1 tmp2 = 1 for i in range(div + 1): frac.append(tmp2) tmp1 += 1 tmp2 = frac[-1] * tmp1 frac[1] = 0 ans = 0 for i in range(div): tmp = div - i remnum = rem + (3 * (div - tmp)) p = pow(tmp, remnum, mod) m = (remnum // tmp) * frac[tmp] ans = (ans + p - m) % mod print(ans)
Statement Given is an integer S. Find how many sequences there are whose terms are all integers greater than or equal to 3, and whose sum is equal to S. The answer can be very large, so output it modulo 10^9 + 7.
[{"input": "7", "output": "3\n \n\n3 sequences satisfy the condition: \\\\{3,4\\\\}, \\\\{4,3\\\\} and \\\\{7\\\\}.\n\n* * *"}, {"input": "2", "output": "0\n \n\nThere are no sequences that satisfy the condition.\n\n* * *"}, {"input": "1729", "output": "294867501"}]
Print the answer. * * *
s919138808
Wrong Answer
p02555
Input is given from Standard Input in the following format: S
S = int(input()) P = 10**9 + 7 lists = [0, 0, 1, 1, 1, 2, 3] if S <= 7: print(lists[S - 1]) else: for i in range(7, S): s = 1 for j in range(3): s += lists[3 + j - 1] * lists[i + 1 - 3 - j - 1] s += i + 1 - 8 lists.append(s) print((lists[S - 1]) % P)
Statement Given is an integer S. Find how many sequences there are whose terms are all integers greater than or equal to 3, and whose sum is equal to S. The answer can be very large, so output it modulo 10^9 + 7.
[{"input": "7", "output": "3\n \n\n3 sequences satisfy the condition: \\\\{3,4\\\\}, \\\\{4,3\\\\} and \\\\{7\\\\}.\n\n* * *"}, {"input": "2", "output": "0\n \n\nThere are no sequences that satisfy the condition.\n\n* * *"}, {"input": "1729", "output": "294867501"}]
Print the answer. * * *
s843042687
Runtime Error
p02555
Input is given from Standard Input in the following format: S
n = int(input()) if n < 6: print(int(n > 2)) quit() M = 10**9 + 7 ln, hn, dp = n - 6, n - 5, 2 s = 0 n, d = n - 5, 1 while n: for i in range(3): n = (n * ln) % M ln -= 1 for i in range(2): n = (n * pow(hn, -1, M)) % M hn -= 1 d = (d * pow(dp, -1, M)) % M dp += 1 s = (s + n * d) % M print(s)
Statement Given is an integer S. Find how many sequences there are whose terms are all integers greater than or equal to 3, and whose sum is equal to S. The answer can be very large, so output it modulo 10^9 + 7.
[{"input": "7", "output": "3\n \n\n3 sequences satisfy the condition: \\\\{3,4\\\\}, \\\\{4,3\\\\} and \\\\{7\\\\}.\n\n* * *"}, {"input": "2", "output": "0\n \n\nThere are no sequences that satisfy the condition.\n\n* * *"}, {"input": "1729", "output": "294867501"}]
Print the answer. * * *
s820903659
Accepted
p02555
Input is given from Standard Input in the following format: S
n = int(input()) p = 10**9 + 7 l = [1] * (2001) l[1], l[2] = 0, 0 s = 1 for i in range(6, 2001): l[i] += s l[i] %= p s += l[i - 2] print(l[n])
Statement Given is an integer S. Find how many sequences there are whose terms are all integers greater than or equal to 3, and whose sum is equal to S. The answer can be very large, so output it modulo 10^9 + 7.
[{"input": "7", "output": "3\n \n\n3 sequences satisfy the condition: \\\\{3,4\\\\}, \\\\{4,3\\\\} and \\\\{7\\\\}.\n\n* * *"}, {"input": "2", "output": "0\n \n\nThere are no sequences that satisfy the condition.\n\n* * *"}, {"input": "1729", "output": "294867501"}]
Print the answer. * * *
s441974183
Wrong Answer
p02555
Input is given from Standard Input in the following format: S
x = int(input()) print(1 ^ x)
Statement Given is an integer S. Find how many sequences there are whose terms are all integers greater than or equal to 3, and whose sum is equal to S. The answer can be very large, so output it modulo 10^9 + 7.
[{"input": "7", "output": "3\n \n\n3 sequences satisfy the condition: \\\\{3,4\\\\}, \\\\{4,3\\\\} and \\\\{7\\\\}.\n\n* * *"}, {"input": "2", "output": "0\n \n\nThere are no sequences that satisfy the condition.\n\n* * *"}, {"input": "1729", "output": "294867501"}]
Print the answer. * * *
s118588058
Runtime Error
p02555
Input is given from Standard Input in the following format: S
mod = 10**9 + 7 class Solution: def FactorialMod(self, n): if n <= 1: return 1 else: return n * self.FactorialMod(n - 1) % mod def ModInv(self, p): if p <= 1: return 1 return (-self.ModInv(mod % p) * (mod // p)) % mod def FactorialModInv(self, p): if p <= 1: return 1 return modinv_table[p] * self.FactorialModInv(p - 1) def Solve(self, n): ans = 0 # Fill in the modinv_table for p in range(2, n + 1): modinv_table[p] = (-modinv_table[mod % p] * (mod // p)) % mod # print(modinv_table) for item in range(1, max_items + 1): print("----------------------------------") print("item", item) max_value = S - 3 * item print("max_value", max_value) add = self.CalculateAddition(max_value, item) print("add", add) ans += add ans %= mod return ans def CalculateAddition(self, max_value, item): if max_value == 0: return 1 add = 1 add = add * self.FactorialMod(max_value + item - 1) % mod add = add * self.FactorialModInv(max_value) % mod add = add * self.FactorialModInv(item - 1) % mod return add S = int(input()) if S <= 2: print(0) exit() max_items = S // 3 # print("max_items", max_items) modinv_table = [-1] * (S + 1) modinv_table[1] = 1 sol = Solution() print(sol.Solve(S))
Statement Given is an integer S. Find how many sequences there are whose terms are all integers greater than or equal to 3, and whose sum is equal to S. The answer can be very large, so output it modulo 10^9 + 7.
[{"input": "7", "output": "3\n \n\n3 sequences satisfy the condition: \\\\{3,4\\\\}, \\\\{4,3\\\\} and \\\\{7\\\\}.\n\n* * *"}, {"input": "2", "output": "0\n \n\nThere are no sequences that satisfy the condition.\n\n* * *"}, {"input": "1729", "output": "294867501"}]
Print the answer. * * *
s637763951
Wrong Answer
p02555
Input is given from Standard Input in the following format: S
N = int(input()) a = [0 for _ in range(2001)] a[:10] = [0, 0, 0, 1, 1, 1, 2, 3, 4, 4] for i in range(10, 2001): b = 0 for j in range(3, 10): if (i - j) >= 3: b += a[i - j] * a[j] % (10**9 + 7) a[i] = b % (10**9 + 7) print(a[N % (10**9 + 7)])
Statement Given is an integer S. Find how many sequences there are whose terms are all integers greater than or equal to 3, and whose sum is equal to S. The answer can be very large, so output it modulo 10^9 + 7.
[{"input": "7", "output": "3\n \n\n3 sequences satisfy the condition: \\\\{3,4\\\\}, \\\\{4,3\\\\} and \\\\{7\\\\}.\n\n* * *"}, {"input": "2", "output": "0\n \n\nThere are no sequences that satisfy the condition.\n\n* * *"}, {"input": "1729", "output": "294867501"}]
Print the answer. * * *
s073893351
Accepted
p02555
Input is given from Standard Input in the following format: S
a = 1 b = c = 0 exec("a,b,c=b,c,a+c;" * int(input())) print(a % (10**9 + 7))
Statement Given is an integer S. Find how many sequences there are whose terms are all integers greater than or equal to 3, and whose sum is equal to S. The answer can be very large, so output it modulo 10^9 + 7.
[{"input": "7", "output": "3\n \n\n3 sequences satisfy the condition: \\\\{3,4\\\\}, \\\\{4,3\\\\} and \\\\{7\\\\}.\n\n* * *"}, {"input": "2", "output": "0\n \n\nThere are no sequences that satisfy the condition.\n\n* * *"}, {"input": "1729", "output": "294867501"}]
Print the answer. * * *
s477923845
Runtime Error
p02555
Input is given from Standard Input in the following format: S
mod = 10**9 + 7 tot = 1 l = [1, 0, 0] for i in range(3, 2000): nex = (tot - l[-1] - l[-2]) % mod tot = (tot + nex) % mod l.append(nex) print(l[int(input())])
Statement Given is an integer S. Find how many sequences there are whose terms are all integers greater than or equal to 3, and whose sum is equal to S. The answer can be very large, so output it modulo 10^9 + 7.
[{"input": "7", "output": "3\n \n\n3 sequences satisfy the condition: \\\\{3,4\\\\}, \\\\{4,3\\\\} and \\\\{7\\\\}.\n\n* * *"}, {"input": "2", "output": "0\n \n\nThere are no sequences that satisfy the condition.\n\n* * *"}, {"input": "1729", "output": "294867501"}]
Print the answer. * * *
s120200002
Accepted
p02555
Input is given from Standard Input in the following format: S
(S,) = [int(x) for x in input().split()] MOD = 10**9 + 7 def modInverse(a, p): assert a % p != 0 return pow(a, p - 2, p) MAX_N = 10000 # Precompute all factorials: i! fact = [1] for i in range(1, MAX_N + 1): fact.append((fact[-1] * i) % MOD) # Precompute all inverse factorials: 1 / (i!) invFact = [0] * (MAX_N + 1) invFact[MAX_N] = modInverse(fact[MAX_N], MOD) for i in range(MAX_N - 1, -1, -1): invFact[i] = (invFact[i + 1] * (i + 1)) % MOD assert fact[i] * invFact[i] % MOD == 1 def nCr(n, r): # mod # Modulo binomial coefficients return (fact[n] * invFact[r] * invFact[n - r]) % MOD total = 0 for n in range(1, 1000): stars = S - n * 3 bars = n - 1 if stars >= 0: count = nCr(stars + bars, stars) total += count total %= MOD print(total)
Statement Given is an integer S. Find how many sequences there are whose terms are all integers greater than or equal to 3, and whose sum is equal to S. The answer can be very large, so output it modulo 10^9 + 7.
[{"input": "7", "output": "3\n \n\n3 sequences satisfy the condition: \\\\{3,4\\\\}, \\\\{4,3\\\\} and \\\\{7\\\\}.\n\n* * *"}, {"input": "2", "output": "0\n \n\nThere are no sequences that satisfy the condition.\n\n* * *"}, {"input": "1729", "output": "294867501"}]
Print the answer. * * *
s730310826
Wrong Answer
p02555
Input is given from Standard Input in the following format: S
class Combination: # 計算量は O(n_max + log(mod)) def __init__(self, n_max, mod=10**9 + 7): self.mod = mod f = 1 self.fac = fac = [f] for i in range(1, n_max + 1): # 階乗(= n_max !)の逆元を生成 f = f * i % mod # 動的計画法による階乗の高速計算 fac.append(f) # fac は階乗のリスト f = pow( f, mod - 2, mod ) # 階乗から階乗の逆元を計算。フェルマーの小定理より、 a^-1 = a^(p-2) (mod p) if p = prime number and p and a are coprime # python の pow 関数は自動的に mod の下での高速累乗を行ってくれる self.facinv = facinv = [f] for i in range( n_max, 0, -1 ): # 上記の階乗の逆元から階乗の逆元のリストを生成(= facinv ) f = f * i % mod facinv.append(f) facinv.reverse() def __call__(self, n, r): # self.C と同じ if not 0 <= r <= n: return 0 return self.fac[n] * self.facinv[r] % self.mod * self.facinv[n - r] % self.mod def C(self, n, r): if not 0 <= r <= n: return 0 # 範囲外という事はすなわち、そのような場合の数は無いはずなので、0を出力すればよい。(これが無いとREになる) return self.fac[n] * self.facinv[r] % self.mod * self.facinv[n - r] % self.mod def P(self, n, r): if not 0 <= r <= n: return 0 return self.fac[n] * self.facinv[n - r] % self.mod def H(self, n, r): # (箱区別:〇 ボール区別:× 空箱:〇) 重複組み合わせ nHm if (n == 0 and r > 0) or r < 0: return 0 return ( self.fac[n + r - 1] * self.facinv[r] % self.mod * self.facinv[n - 1] % self.mod ) from math import ceil MOD = 10**9 + 7 S = int(input()) C = Combination(S * 10) print(sum(C.H(n, S - 3 * n) for n in range(1, ceil(S / 3))) % MOD)
Statement Given is an integer S. Find how many sequences there are whose terms are all integers greater than or equal to 3, and whose sum is equal to S. The answer can be very large, so output it modulo 10^9 + 7.
[{"input": "7", "output": "3\n \n\n3 sequences satisfy the condition: \\\\{3,4\\\\}, \\\\{4,3\\\\} and \\\\{7\\\\}.\n\n* * *"}, {"input": "2", "output": "0\n \n\nThere are no sequences that satisfy the condition.\n\n* * *"}, {"input": "1729", "output": "294867501"}]
Print the answer. * * *
s272535525
Wrong Answer
p02555
Input is given from Standard Input in the following format: S
p = 10**9 + 7 def pow(x, m): if m == 0: return 1 if m == 1: return x if m % 2 == 0: return (pow(x, m // 2) ** 2) % p else: return (x * (pow(x, (m - 1) // 2) ** 2) % p) % p A = [1 for _ in range(10000)] for i in range(2, 10000): A[i] = (A[i - 1] * i) % p B = [1 for _ in range(10000)] B[9999] = pow(A[9999], p - 2) for i in range(9998, 1, -1): B[i] = (B[i + 1] * (i + 1)) % p def f(n, k): return (A[n] * B[k] * B[n - k]) % p S = int(input()) C = {} for i in range(3, S + 1): n = S // i k = S % i if n not in C: C[n] = [] C[n].append(k) cnt = 0 for n in C: C[n] = sorted(C[n]) k = C[n][-1] cnt = (cnt + f(k + n - 1, n - 1)) % p print(cnt)
Statement Given is an integer S. Find how many sequences there are whose terms are all integers greater than or equal to 3, and whose sum is equal to S. The answer can be very large, so output it modulo 10^9 + 7.
[{"input": "7", "output": "3\n \n\n3 sequences satisfy the condition: \\\\{3,4\\\\}, \\\\{4,3\\\\} and \\\\{7\\\\}.\n\n* * *"}, {"input": "2", "output": "0\n \n\nThere are no sequences that satisfy the condition.\n\n* * *"}, {"input": "1729", "output": "294867501"}]
Print the answer. * * *
s077713004
Accepted
p02555
Input is given from Standard Input in the following format: S
S = int(input()) f = [1, 0, 0] for i in range(S - 2): f.append(f[i] + f[i + 2]) print(f[S] % (10**9 + 7))
Statement Given is an integer S. Find how many sequences there are whose terms are all integers greater than or equal to 3, and whose sum is equal to S. The answer can be very large, so output it modulo 10^9 + 7.
[{"input": "7", "output": "3\n \n\n3 sequences satisfy the condition: \\\\{3,4\\\\}, \\\\{4,3\\\\} and \\\\{7\\\\}.\n\n* * *"}, {"input": "2", "output": "0\n \n\nThere are no sequences that satisfy the condition.\n\n* * *"}, {"input": "1729", "output": "294867501"}]
Print the answer. * * *
s111556452
Wrong Answer
p02555
Input is given from Standard Input in the following format: S
n = int(input()) print(n)
Statement Given is an integer S. Find how many sequences there are whose terms are all integers greater than or equal to 3, and whose sum is equal to S. The answer can be very large, so output it modulo 10^9 + 7.
[{"input": "7", "output": "3\n \n\n3 sequences satisfy the condition: \\\\{3,4\\\\}, \\\\{4,3\\\\} and \\\\{7\\\\}.\n\n* * *"}, {"input": "2", "output": "0\n \n\nThere are no sequences that satisfy the condition.\n\n* * *"}, {"input": "1729", "output": "294867501"}]
Print the answer. * * *
s356545873
Accepted
p02555
Input is given from Standard Input in the following format: S
S = int(input()) MOD = 10**9 + 7 class Mint: def __init__(self, value=0): self.value = value % MOD if self.value < 0: self.value += MOD @staticmethod def get_value(x): return x.value if isinstance(x, Mint) else x def inverse(self): a, b = self.value, MOD u, v = 1, 0 while b: t = a // b b, a = a - t * b, b v, u = u - t * v, v if u < 0: u += MOD return u def __repr__(self): return str(self.value) def __eq__(self, other): return self.value == other.value def __neg__(self): return Mint(-self.value) def __hash__(self): return hash(self.value) def __bool__(self): return self.value != 0 def __iadd__(self, other): self.value = (self.value + Mint.get_value(other)) % MOD return self def __add__(self, other): new_obj = Mint(self.value) new_obj += other return new_obj __radd__ = __add__ def __isub__(self, other): self.value = (self.value - Mint.get_value(other)) % MOD if self.value < 0: self.value += MOD return self def __sub__(self, other): new_obj = Mint(self.value) new_obj -= other return new_obj def __rsub__(self, other): new_obj = Mint(Mint.get_value(other)) new_obj -= self return new_obj def __imul__(self, other): self.value = self.value * Mint.get_value(other) % MOD return self def __mul__(self, other): new_obj = Mint(self.value) new_obj *= other return new_obj __rmul__ = __mul__ def __ifloordiv__(self, other): other = other if isinstance(other, Mint) else Mint(other) self *= other.inverse() return self def __floordiv__(self, other): new_obj = Mint(self.value) new_obj //= other return new_obj def __rfloordiv__(self, other): new_obj = Mint(Mint.get_value(other)) new_obj //= self return new_obj class FactorialUtils: def __init__(self, n): self.fac = [1] * (n + 1) self.ifac = [1] * (n + 1) for i in range(2, n + 1): self.fac[i] = self.fac[i - 1] * i % MOD self.ifac[n] = pow(self.fac[n], MOD - 2, MOD) for i in range(n, 1, -1): self.ifac[i - 1] = self.ifac[i] * i % MOD def choose(self, n, r): if r < 0 or r > n: return 0 return (self.fac[n] * self.ifac[n - r] % MOD) * self.ifac[r] % MOD def multichoose(self, u, k): return (self.fac[u + k - 1] * self.ifac[u - 1] % MOD) * self.ifac[k] % MOD def permutation(self, n, r): if r < 0 or r > n: return 0 return self.fac[n] * self.ifac[n - r] % MOD fu = FactorialUtils(S) ans = Mint() for n in range(1, S + 1): if S < 3 * n: break r = S - 3 * n ans += fu.multichoose(n, r) print(ans)
Statement Given is an integer S. Find how many sequences there are whose terms are all integers greater than or equal to 3, and whose sum is equal to S. The answer can be very large, so output it modulo 10^9 + 7.
[{"input": "7", "output": "3\n \n\n3 sequences satisfy the condition: \\\\{3,4\\\\}, \\\\{4,3\\\\} and \\\\{7\\\\}.\n\n* * *"}, {"input": "2", "output": "0\n \n\nThere are no sequences that satisfy the condition.\n\n* * *"}, {"input": "1729", "output": "294867501"}]
Print the answer. * * *
s339144390
Wrong Answer
p02555
Input is given from Standard Input in the following format: S
S=int(input()) MOD=10**9+7 dp=[0]*(S+1) dp[0]=1 for i in range(1,S+1): for j in range(0,S-2): dp[i]+=dp[j] dp[i]%=MOD print(dp[S])
Statement Given is an integer S. Find how many sequences there are whose terms are all integers greater than or equal to 3, and whose sum is equal to S. The answer can be very large, so output it modulo 10^9 + 7.
[{"input": "7", "output": "3\n \n\n3 sequences satisfy the condition: \\\\{3,4\\\\}, \\\\{4,3\\\\} and \\\\{7\\\\}.\n\n* * *"}, {"input": "2", "output": "0\n \n\nThere are no sequences that satisfy the condition.\n\n* * *"}, {"input": "1729", "output": "294867501"}]
Print the answer. * * *
s008345070
Wrong Answer
p02555
Input is given from Standard Input in the following format: S
S = int(input()) a = [0] * 2000 a[0] = 0 a[1] = 0 a[2] = 1 a[3] = 1 a[4] = 1 a[5] = 2 k = 0 for i in range(6, S): for l in range(2, i - 2): k += a[l] a[i] = 1 + k p = a[S - 1] % (10**9 + 7) print(p)
Statement Given is an integer S. Find how many sequences there are whose terms are all integers greater than or equal to 3, and whose sum is equal to S. The answer can be very large, so output it modulo 10^9 + 7.
[{"input": "7", "output": "3\n \n\n3 sequences satisfy the condition: \\\\{3,4\\\\}, \\\\{4,3\\\\} and \\\\{7\\\\}.\n\n* * *"}, {"input": "2", "output": "0\n \n\nThere are no sequences that satisfy the condition.\n\n* * *"}, {"input": "1729", "output": "294867501"}]
Print the answer. * * *
s738868592
Accepted
p02555
Input is given from Standard Input in the following format: S
from typing import List, Any def read_int() -> int: return int(input().strip()) def read_ints() -> List[int]: return list(map(int, input().strip().split(" "))) def solve() -> Any: S = read_int() dp = [[0 for _ in range(S + 1)] for _ in range(S // 3 + 1)] prefix = [1] * (S + 1) new_prefix = [0] * (S + 1) modulo = 10**9 + 7 for i in range(1, S // 3 + 1): for j in range(1, S + 1): if i > 0 and j >= 3: dp[i][j] = (dp[i][j] + prefix[j - 3]) % modulo new_prefix[j] = (new_prefix[j - 1] + dp[i][j]) % modulo prefix, new_prefix = new_prefix, prefix new_prefix[0] = 0 # dp[i][j] = dp[i-1][j-k] # i number of elements such that sum is j, 3 <= k <= 9 return sum(dp[i][S] for i in range(1, S // 3 + 1)) % modulo if __name__ == "__main__": print(solve())
Statement Given is an integer S. Find how many sequences there are whose terms are all integers greater than or equal to 3, and whose sum is equal to S. The answer can be very large, so output it modulo 10^9 + 7.
[{"input": "7", "output": "3\n \n\n3 sequences satisfy the condition: \\\\{3,4\\\\}, \\\\{4,3\\\\} and \\\\{7\\\\}.\n\n* * *"}, {"input": "2", "output": "0\n \n\nThere are no sequences that satisfy the condition.\n\n* * *"}, {"input": "1729", "output": "294867501"}]
Print the answer. * * *
s651521431
Accepted
p02555
Input is given from Standard Input in the following format: S
S = int(input()) count = 0 for size in range(1, S // 3 + 1): extra = S - 3 * size # 0以上の値をどう分配するか?数列なので純不動ではない total = extra + size - 1 # extra個の玉とsize-1個の棒の並び替え問題 number = 1 for n in range(extra + 1, total + 1): number *= n for n in range(1, size): number //= n count += number # print(size,number) print(count % (10**9 + 7))
Statement Given is an integer S. Find how many sequences there are whose terms are all integers greater than or equal to 3, and whose sum is equal to S. The answer can be very large, so output it modulo 10^9 + 7.
[{"input": "7", "output": "3\n \n\n3 sequences satisfy the condition: \\\\{3,4\\\\}, \\\\{4,3\\\\} and \\\\{7\\\\}.\n\n* * *"}, {"input": "2", "output": "0\n \n\nThere are no sequences that satisfy the condition.\n\n* * *"}, {"input": "1729", "output": "294867501"}]
Print the answer. * * *
s312461512
Runtime Error
p02555
Input is given from Standard Input in the following format: S
mod = 10**9 + 7 (N,) = map(int, input().split()) dp1 = [0] * N dp2 = [0] * N for i in range(N): if i < 3: dp1[i] = 1 dp2[i] = 0 else: dp1[i] = dp1[i - 1] + dp2[i - 1] dp2[i] = dp1[i - 3] + dp2[i - 3] dp1[i] %= mod dp2[i] %= mod print(dp1) print(dp2) print((dp1[-1] + dp2[-3]) % mod)
Statement Given is an integer S. Find how many sequences there are whose terms are all integers greater than or equal to 3, and whose sum is equal to S. The answer can be very large, so output it modulo 10^9 + 7.
[{"input": "7", "output": "3\n \n\n3 sequences satisfy the condition: \\\\{3,4\\\\}, \\\\{4,3\\\\} and \\\\{7\\\\}.\n\n* * *"}, {"input": "2", "output": "0\n \n\nThere are no sequences that satisfy the condition.\n\n* * *"}, {"input": "1729", "output": "294867501"}]
For each dataset, output the number of _clan_ modulo 10007.
s434871154
Wrong Answer
p00641
The input consists of several datasets. The first line of each dataset contains an integer _n_ , which indicates the number of members in the family. Next _n_ lines represents information of the _i_ -th member with four integers. The first two integers respectively represent _b_[0] (the partner of _i_) and f(_i_ , _b_[0]) (the calling fee per unit time between _i_ and _b_[0]). The following two integers represent _b_[1] and _f_(_i_ , _b_[1]) in the same manner. Input terminates with a dataset where n = 0.
while True: n = int(input()) if n == 0: break g = [[] for _ in range(n)] for u in range(n): v1, w1, v2, w2 = map(int, input().split()) g[u].append((v1, w1)) g[u].append((v2, w2)) res = 1 vis = [False] * n for i in range(n): if vis[i]: continue ws = [] p, u = -1, i while True: vis[u] = True for v, w in g[u]: if v != p: ws.append(w) p, u = u, v break if u == i: break res *= ws.count(max(ws)) print(res)
E: Huge Family Mr. Dango's family has extremely huge number of members. Once it had about 100 members, and now it has as many as population of a city. It is jokingly guessed that the member might fill this planet in near future. They all have warm and gracious personality and are close each other. They usually communicate by a phone. Of course, They are all taking a family plan. This family plan is such a thing: when _a_ choose _b_ , and _b_ choose _a_ as a partner, a family plan can be applied between them and then the calling fee per unit time between them discounted to _f_(_a_ , _b_), which is cheaper than a default fee. Each person can apply a family plan at most 2 times, but no same pair of persons can apply twice. Now, choosing their partner appropriately, all members of Mr. Dango's family applied twice. Since there are huge number of people, it is very difficult to send a message to all family members by a phone call. Mr. Dang have decided to make a phone calling network that is named '_clan_ ' using the family plan. Let us present a definition of _clan_. Let _S_ be an any subset of all phone calls that family plan is applied. _Clan_ is _S_ such that: 1. For any two persons (let them be _i_ and _j_), if _i_ can send a message to _j_ through phone calls that family plan is applied (directly or indirectly), then _i_ can send a message to _j_ through only phone calls in _S_ (directly or indirectly). 2. Meets condition 1 and a sum of the calling fee per unit time in _S_ is minimized. _Clan_ allows to send a message efficiently. For example, we suppose that one have sent a message through all calls related to him in the clan. Additionaly we suppose that every people follow a rule, "when he/she receives a message through a call in clan, he/she relays the message all other neibors in respect to clan." Then, we can prove that this message will surely be derivered to every people that is connected by all discounted calls, and that the message will never be derivered two or more times to same person. By the way, you are given information about application of family plan of Mr. Dango's family. Please write a program that calculates that in how many ways a different clan can be constructed. You should output the answer modulo 10007 because it may be very big.
[{"input": "1 1 2 3\n 0 1 2 2\n 1 2 0 3\n 7\n 1 2 2 1\n 0 2 3 2\n 0 1 3 1\n 2 1 1 2\n 5 3 6 2\n 4 3 6 1\n 4 2 5 1\n 0", "output": "2"}]
Print "Yes" if given dices are all different, otherwise "No" in a line.
s615737883
Accepted
p02386
In the first line, the number of dices $n$ is given. In the following $n$ lines, six integers assigned to the dice faces are given respectively in the same way as Dice III.
n = int(input()) d = {i: list(input().split()) for i in range(n)} def roll(Dice, Vector): if Vector == "N": c = Dice[0] Dice[0] = Dice[1] Dice[1] = Dice[5] Dice[5] = Dice[4] Dice[4] = c elif Vector == "W": c = Dice[0] Dice[0] = Dice[2] Dice[2] = Dice[5] Dice[5] = Dice[3] Dice[3] = c elif Vector == "E": c = Dice[0] Dice[0] = Dice[3] Dice[3] = Dice[5] Dice[5] = Dice[2] Dice[2] = c elif Vector == "S": c = Dice[0] Dice[0] = Dice[4] Dice[4] = Dice[5] Dice[5] = Dice[1] Dice[1] = c v = list("NNNNWNNNWNNNENNNENNNWNNN") f = 0 for i in range(n): if f == 0: for item in v: roll(d[i], item) if f == 0: for j in range(i + 1, n): if d[i] == d[j]: f += 1 break if f == 0: print("Yes") else: print("No")
Dice IV Write a program which reads $n$ dices constructed in the same way as Dice I, and determines whether they are all different. For the determination, use the same way as Dice III.
[{"input": "3\n 1 2 3 4 5 6\n 6 2 4 3 5 1\n 6 5 4 3 2 1", "output": "No"}, {"input": "3\n 1 2 3 4 5 6\n 6 5 4 3 2 1\n 5 4 3 2 1 6", "output": "Yes"}]
Print "Yes" if given dices are all different, otherwise "No" in a line.
s212671336
Runtime Error
p02386
In the first line, the number of dices $n$ is given. In the following $n$ lines, six integers assigned to the dice faces are given respectively in the same way as Dice III.
import math a, b, C = map(float, input().split()) C_rad = math.pi * C / 180 print("{0:.8f}".format(math.sin(C_rad) * a * b / 2)) print("{0:.8f}".format(a + b + math.sqrt(a**2 + b**2 - 2 * a * b * math.cos(C_rad)))) print("{0:.8f}".format(b * math.sin(C_rad)))
Dice IV Write a program which reads $n$ dices constructed in the same way as Dice I, and determines whether they are all different. For the determination, use the same way as Dice III.
[{"input": "3\n 1 2 3 4 5 6\n 6 2 4 3 5 1\n 6 5 4 3 2 1", "output": "No"}, {"input": "3\n 1 2 3 4 5 6\n 6 5 4 3 2 1\n 5 4 3 2 1 6", "output": "Yes"}]
Print "Yes" if given dices are all different, otherwise "No" in a line.
s372662836
Accepted
p02386
In the first line, the number of dices $n$ is given. In the following $n$ lines, six integers assigned to the dice faces are given respectively in the same way as Dice III.
class Dice: # 入力 def __init__(self, d1, d2, d3, d4, d5, d6): self.d1 = d1 self.d2 = d2 self.d3 = d3 self.d4 = d4 self.d5 = d5 self.d6 = d6 # 回転 def roll(self, c): if c == "N": self.d1, self.d5, self.d6, self.d2 = self.d2, self.d1, self.d5, self.d6 elif c == "S": self.d1, self.d5, self.d6, self.d2 = self.d5, self.d6, self.d2, self.d1 elif c == "E": self.d1, self.d3, self.d6, self.d4 = self.d4, self.d1, self.d3, self.d6 elif c == "W": self.d1, self.d3, self.d6, self.d4 = self.d3, self.d6, self.d4, self.d1 elif c == "R": self.d2, self.d3, self.d5, self.d4 = self.d4, self.d2, self.d3, self.d5 elif c == "L": self.d2, self.d3, self.d5, self.d4 = self.d3, self.d5, self.d4, self.d2 # 上の面に来る最小値 def minnum(self): return min(self.d1, self.d2, self.d3, self.d4, self.d5, self.d6) # 前の面に来る2つめに小さい値 def min2num(self): return min(self.d2, self.d3, self.d4, self.d5, self.d6) # 2つめが下の面に来るときに前の面に来る3番目に小さい値 def min3num(self): return min(self.d2, self.d3, self.d4, self.d5) # 回転動作 def rolling(self): m = self.minnum() if m == self.d3: self.roll("W") elif m == self.d6: self.roll("E") self.roll("E") elif m == self.d4: self.roll("E") elif m == self.d2: self.roll("N") elif m == self.d5: self.roll("S") m = self.min2num() if m == self.d3: self.roll("L") elif m == self.d5: self.roll("L") self.roll("L") elif m == self.d4: self.roll("R") elif m == self.d6: m = self.min3num() if m == self.d3: self.roll("L") elif m == self.d5: self.roll("L") self.roll("L") elif m == self.d4: self.roll("R") # 値をリストで返す def returnlist(self): l = [self.d1, self.d2, self.d3, self.d4, self.d5, self.d6] return l n = int(input()) check = True l = [] # ダイスの入力 for i in range(n): a, b, c, d, e, f = map(int, input().split()) D = Dice(a, b, c, d, e, f) D.rolling() # 今までのダイスと比較 for dice in l: if dice == D.returnlist(): check = False # リストに追加 l.append(D.returnlist()) if check: print("Yes") else: print("No")
Dice IV Write a program which reads $n$ dices constructed in the same way as Dice I, and determines whether they are all different. For the determination, use the same way as Dice III.
[{"input": "3\n 1 2 3 4 5 6\n 6 2 4 3 5 1\n 6 5 4 3 2 1", "output": "No"}, {"input": "3\n 1 2 3 4 5 6\n 6 5 4 3 2 1\n 5 4 3 2 1 6", "output": "Yes"}]
Print "Yes" if given dices are all different, otherwise "No" in a line.
s188874967
Accepted
p02386
In the first line, the number of dices $n$ is given. In the following $n$ lines, six integers assigned to the dice faces are given respectively in the same way as Dice III.
class Dice: def __init__(self, nums): self.top = nums[0] self.front = nums[1] self.right = nums[2] self.left = nums[3] self.back = nums[4] self.bottom = nums[5] def toN(self): tmp = self.top self.top = self.front self.front = self.bottom self.bottom = self.back self.back = tmp def toS(self): tmp = self.top self.top = self.back self.back = self.bottom self.bottom = self.front self.front = tmp def toE(self): tmp = self.top self.top = self.left self.left = self.bottom self.bottom = self.right self.right = tmp def toW(self): tmp = self.top self.top = self.right self.right = self.bottom self.bottom = self.left self.left = tmp def moveTo(self, ds): for d in ds: if d == "N": self.toN() if d == "S": self.toS() if d == "E": self.toE() if d == "W": self.toW() def getTop(self): return self.top def getBottom(self): return self.bottom def getFront(self): return self.front def getBack(self): return self.back def getLeft(self): return self.left def getRight(self): return self.right def __eq__(self, other): if self.top != other.top: return False if self.bottom != other.bottom: return False if self.front != other.front: return False if self.back != other.back: return False if self.left != other.left: return False if self.right != other.right: return False return True def moveTo(dice, top, front): if dice.getFront() != front: if dice.getTop() == front: dice.moveTo("S") elif dice.getBottom() == front: dice.moveTo("N") elif dice.getBack() == front: dice.moveTo("NN") elif dice.getLeft() == front: dice.moveTo("ES") elif dice.getRight() == front: dice.moveTo("WS") if dice.getTop() != top: if dice.getBottom() == top: dice.moveTo("EE") elif dice.getLeft() == top: dice.moveTo("E") elif dice.getRight() == top: dice.moveTo("W") return dice def equalDice(dice1, dice2): dice2 = moveTo(dice2, dice1.getTop(), dice1.getFront()) return dice1 == dice2 def main(): n = int(input()) dice1 = Dice(input().split()) ans = "Yes" for _ in range(n - 1): dice2 = Dice(input().split()) if equalDice(dice1, dice2): ans = "No" break print(ans) if __name__ == "__main__": main()
Dice IV Write a program which reads $n$ dices constructed in the same way as Dice I, and determines whether they are all different. For the determination, use the same way as Dice III.
[{"input": "3\n 1 2 3 4 5 6\n 6 2 4 3 5 1\n 6 5 4 3 2 1", "output": "No"}, {"input": "3\n 1 2 3 4 5 6\n 6 5 4 3 2 1\n 5 4 3 2 1 6", "output": "Yes"}]
Print "Yes" if given dices are all different, otherwise "No" in a line.
s567355496
Accepted
p02386
In the first line, the number of dices $n$ is given. In the following $n$ lines, six integers assigned to the dice faces are given respectively in the same way as Dice III.
class _Dice: def __init__(self, nums): self.nums = list(nums) @property def top(self): return self.nums[0] def _shift(self, *pairs): for pair in pairs: num = self.nums[pair[0]] self.nums[pair[0]] = self.nums[pair[1]] self.nums[pair[1]] = num def get_matches(self, num): return [i for i, m in enumerate(self.nums) if m == num] def go(self, opes: str): for ope in opes: if ope == "N": self.go_north() elif ope == "E": self.go_east() elif ope == "W": self.go_west() else: self.go_south() def go_top(self, index): if index == 1: self.go_north() elif index == 2: self.go_west() elif index == 3: self.go_east() elif index == 4: self.go_south() elif index == 5: self.go_north() self.go_north() def go_ahead(self, index): if index == 2: self.go_cw() elif index == 4: self.go_cw() self.go_cw() elif index == 3: self.go_ccw() def go_north(self): self._shift((0, 1), (1, 5), (5, 4)) def go_east(self): self._shift((0, 3), (3, 5), (5, 2)) def go_west(self): self._shift((0, 2), (2, 5), (5, 3)) def go_south(self): self._shift((0, 4), (4, 5), (5, 1)) def go_ccw(self): self._shift((3, 4), (4, 2), (2, 1)) def go_cw(self): self._shift((3, 1), (1, 2), (2, 4)) class Dice(_Dice): @classmethod def isequal(cls, a: _Dice, b: _Dice): a_clone = a.nums.copy() for top in a.get_matches(b.nums[0]): a.go_top(top) a_top_clone = a.nums.copy() for ahead in a.get_matches(b.nums[1]): a.go_ahead(ahead) for i, j in zip(a.nums, b.nums): if i != j: break else: return True a.nums = a_top_clone.copy() a.nums = a_clone.copy() else: return False def check(dices): for i, dice_A in enumerate(dices): if i == len(dices) - 1: break for dice_B in dices[i + 1 :]: if Dice.isequal(dice_A, dice_B): return False return True count = int(input()) dices = [Dice(map(int, input().split())) for _ in range(count)] print("Yes" if check(dices) else "No")
Dice IV Write a program which reads $n$ dices constructed in the same way as Dice I, and determines whether they are all different. For the determination, use the same way as Dice III.
[{"input": "3\n 1 2 3 4 5 6\n 6 2 4 3 5 1\n 6 5 4 3 2 1", "output": "No"}, {"input": "3\n 1 2 3 4 5 6\n 6 5 4 3 2 1\n 5 4 3 2 1 6", "output": "Yes"}]
Print "Yes" if given dices are all different, otherwise "No" in a line.
s060114942
Accepted
p02386
In the first line, the number of dices $n$ is given. In the following $n$ lines, six integers assigned to the dice faces are given respectively in the same way as Dice III.
#!/usr/bin/env python3 import sys import copy line = sys.stdin.readline() faces = [] def anydup(thelist): seen = set() for x in thelist: if x in seen: return True seen.add(x) return False while True: line = sys.stdin.readline() if not line: break line = line.rstrip("\r\n") faces.append(line.split()) for i in range(5): face = faces[-1] if face[0] != face[1]: break face_old = copy.deepcopy(face) face[0] = face_old[1] face[1] = face_old[5] face[2] = face_old[2] face[3] = face_old[3] face[4] = face_old[0] face[5] = face_old[4] else: face_old = copy.deepcopy(face) face[0] = face_old[3] face[1] = face_old[1] face[2] = face_old[0] face[3] = face_old[5] face[4] = face_old[4] face[5] = face_old[2] for i in range(5): if face[0] != face[1]: break face_old = copy.deepcopy(face) face[0] = face_old[1] face[1] = face_old[5] face[2] = face_old[2] face[3] = face_old[3] face[4] = face_old[0] face[5] = face_old[4] for i in range(5): if face[0] != face[1]: break face_old = copy.deepcopy(face) face[0] = face_old[3] face[1] = face_old[1] face[2] = face_old[0] face[3] = face_old[5] face[4] = face_old[4] face[5] = face_old[2] for j in range(len(faces) - 1): face = faces[j] face2 = faces[-1] for i in range(5): if face[1] == face2[1]: break face_old = copy.deepcopy(face) face[0] = face_old[1] face[1] = face_old[5] face[2] = face_old[2] face[3] = face_old[3] face[4] = face_old[0] face[5] = face_old[4] else: face_old = copy.deepcopy(face) face[0] = face_old[3] face[1] = face_old[1] face[2] = face_old[0] face[3] = face_old[5] face[4] = face_old[4] face[5] = face_old[2] for i in range(5): if face[1] == face2[1]: break face_old = copy.deepcopy(face) face[0] = face_old[1] face[1] = face_old[5] face[2] = face_old[2] face[3] = face_old[3] face[4] = face_old[0] face[5] = face_old[4] for i in range(5): if face[0] == face2[0]: break face_old = copy.deepcopy(face) face[0] = face_old[3] face[1] = face_old[1] face[2] = face_old[0] face[3] = face_old[5] face[4] = face_old[4] face[5] = face_old[2] # for f in faces: # print(f) if any(faces.count(x) > 1 for x in faces): print("No") else: print("Yes")
Dice IV Write a program which reads $n$ dices constructed in the same way as Dice I, and determines whether they are all different. For the determination, use the same way as Dice III.
[{"input": "3\n 1 2 3 4 5 6\n 6 2 4 3 5 1\n 6 5 4 3 2 1", "output": "No"}, {"input": "3\n 1 2 3 4 5 6\n 6 5 4 3 2 1\n 5 4 3 2 1 6", "output": "Yes"}]
Print "Yes" if given dices are all different, otherwise "No" in a line.
s262389605
Accepted
p02386
In the first line, the number of dices $n$ is given. In the following $n$ lines, six integers assigned to the dice faces are given respectively in the same way as Dice III.
from collections import deque def is_equal(dice1, dice2): equal = "No" if dice1.min != dice2.min or dice1.max != dice2.max: return "No" top0 = dice1.disp_top_face() front0 = dice1.disp_front_face() flag = 1 for _ in range(100): if dice2.disp_top_face() == top0: flag = 0 break for _ in range(4): dice2.lotate("S") if dice2.disp_top_face() == top0: flag = 0 break if flag: dice2.lotate("E") else: break for _ in range(4): if dice2.disp_front_face() == front0: break dice2.lotate("E") dice2.lotate("S") dice2.lotate("W") if ( dice1.disp_top_face() == dice2.disp_top_face() and dice1.disp_bottom_face() == dice2.disp_bottom_face() and dice1.disp_front_face() == dice2.disp_front_face() and dice1.disp_left_face() == dice2.disp_left_face() and dice1.disp_right_face() == dice2.disp_right_face() and dice1.disp_back_face() == dice2.disp_back_face() ): equal = "Yes" return equal class Dice: def __init__(self, seq): self.v = deque([seq[5], seq[4], seq[0], seq[1]]) self.h = deque([seq[3], seq[0], seq[2], seq[5]]) self.max = max(seq) self.min = min(seq) def lotate(self, direction): if direction == "E": self.h.rotate() self.v[2] = self.h[1] self.v[0] = self.h[3] elif direction == "W": self.h.rotate(-1) self.v[2] = self.h[1] self.v[0] = self.h[3] elif direction == "N": self.v.rotate(-1) self.h[1] = self.v[2] self.h[3] = self.v[0] elif direction == "S": self.v.rotate() self.h[1] = self.v[2] self.h[3] = self.v[0] else: pass def disp_top_face(self): return self.v[2] def disp_front_face(self): return self.v[3] def disp_back_face(self): return self.v[1] def disp_right_face(self): return self.h[2] def disp_left_face(self): return self.h[0] def disp_bottom_face(self): return self.h[3] if __name__ == "__main__": param = input() n = int(param) dices = list() for _ in range(n): param = input().split(" ") seq = [int(a) for a in param] d = Dice(seq) dices.append(d) different = "Yes" for i in range(len(dices) - 1): if len(dices) - 1 < 2: if is_equal(dices[i], dices[i + 1]) == "Yes": different = "No" else: for j in range(i + 1, len(dices) - 1): if is_equal(dices[i], dices[j]) == "Yes": different = "No" print(different)
Dice IV Write a program which reads $n$ dices constructed in the same way as Dice I, and determines whether they are all different. For the determination, use the same way as Dice III.
[{"input": "3\n 1 2 3 4 5 6\n 6 2 4 3 5 1\n 6 5 4 3 2 1", "output": "No"}, {"input": "3\n 1 2 3 4 5 6\n 6 5 4 3 2 1\n 5 4 3 2 1 6", "output": "Yes"}]
Print "Yes" if given dices are all different, otherwise "No" in a line.
s574363493
Accepted
p02386
In the first line, the number of dices $n$ is given. In the following $n$ lines, six integers assigned to the dice faces are given respectively in the same way as Dice III.
class Dice: __TOP = 0 __FRONT = 1 __RIGHT = 2 __LEFT = 3 __BACK = 4 __BOTTOM = 5 def __init__(self, face_val=None): self.f_keys = [ self.__TOP, # 0 self.__FRONT, # 1 self.__RIGHT, # 2 self.__LEFT, # 3 self.__BACK, # 4 self.__BOTTOM, # 5 ] if face_val is None or len(face_val) != 6: face_val = ["1", "2", "3", "4", "5", "6"] self.f_key_to_val = {} for f_key, val in zip(self.f_keys, face_val): self.f_key_to_val[f_key] = val MOVE_SWAP_FACES = { "S": [ (__BACK, __TOP), (__TOP, __FRONT), (__FRONT, __BOTTOM), (__BOTTOM, __BACK), ], "W": [ (__RIGHT, __TOP), (__TOP, __LEFT), (__LEFT, __BOTTOM), (__BOTTOM, __RIGHT), ], "E": [ (__LEFT, __TOP), (__TOP, __RIGHT), (__RIGHT, __BOTTOM), (__BOTTOM, __LEFT), ], "N": [ (__FRONT, __TOP), (__TOP, __BACK), (__BACK, __BOTTOM), (__BOTTOM, __FRONT), ], "RCW": [ (__LEFT, __FRONT), (__FRONT, __RIGHT), (__RIGHT, __BACK), (__BACK, __LEFT), ], # rotate clockwise "RCCW": [ (__RIGHT, __FRONT), (__FRONT, __LEFT), (__LEFT, __BACK), (__BACK, __RIGHT), ], # rotate counter clockwise } def dice_move(self, direction_list): for direction in direction_list: prev_faces = self.f_keys[:] for prev_f, next_f in self.MOVE_SWAP_FACES[direction]: self.f_keys[next_f] = prev_faces[prev_f] # print(self.f_keys) MOVE_TO_TOP = { __TOP: [], __FRONT: ["N"], __RIGHT: ["W"], __LEFT: ["E"], __BACK: ["S"], __BOTTOM: ["N", "N"], } def dice_fix(self, top: int, front: int): # 上面を指定された面にする if top != self.f_keys[self.__TOP]: now_top = self.f_keys.index(top) move = self.MOVE_TO_TOP[now_top] self.dice_move(move) if top != self.f_keys[self.__TOP]: raise AssertionError # not top # 前面を指定された面にする if front != self.f_keys[self.__FRONT]: for i in range(3): self.dice_move(["RCW"]) if front == self.f_keys[self.__FRONT]: break else: return False # 3回回転するうちに指定された面がfrontに来ないとおかしい return True def get_value(self, face): return self.f_key_to_val[self.f_keys[face]] OPPOSITE_AND_ROUNDS = { 0: (5, (1, 3, 4, 2)), 1: (4, (0, 2, 5, 3)), 2: (3, (0, 4, 5, 1)), 3: (2, (0, 1, 5, 4)), 4: (1, (0, 3, 5, 2)), 5: (0, (1, 2, 4, 3)), } def is_identical(self, other) -> bool: # 含まれるvalueが同じであることをチェック self_values = [self.get_value(x) for x in self.f_keys] other_values = [other.get_value(x) for x in other.f_keys] if set(self_values) != set(other_values): return False other_top = other.get_value(self.__TOP) # other_topと同じ値を持つselfの面を取得 self_top_faces = filter(lambda x: x[1] == other_top, self.f_key_to_val.items()) # for それぞれの面 other_rounds = [other.get_value(x) for x in self.OPPOSITE_AND_ROUNDS[0][1]] other_rounds += other_rounds for self_top in self_top_faces: # 対面が同じ値 and 側面を回る面の値の列の循環が一致 を満たす場合があったらTrueなかったらFalse opposite, rounds = self.OPPOSITE_AND_ROUNDS[self_top[0]] if self.get_value(opposite) != other.get_value(self.__BOTTOM): continue self_rounds = [] for face in rounds: self_rounds.append(self.get_value(face)) for i in range(4): if self_rounds == other_rounds[i : i + 4]: return True return False def __repr__(self): return f'({",".join(map(str, self.f_keys))})' def main(): n = int(input()) dice1 = Dice(input().split()) for i in range(n - 1): dice2 = Dice(input().split()) if dice1.is_identical(dice2): print("No") break else: print("Yes") main()
Dice IV Write a program which reads $n$ dices constructed in the same way as Dice I, and determines whether they are all different. For the determination, use the same way as Dice III.
[{"input": "3\n 1 2 3 4 5 6\n 6 2 4 3 5 1\n 6 5 4 3 2 1", "output": "No"}, {"input": "3\n 1 2 3 4 5 6\n 6 5 4 3 2 1\n 5 4 3 2 1 6", "output": "Yes"}]
Print "Yes" if given dices are all different, otherwise "No" in a line.
s379411449
Accepted
p02386
In the first line, the number of dices $n$ is given. In the following $n$ lines, six integers assigned to the dice faces are given respectively in the same way as Dice III.
d = [(0, 0, 1), (-1, 0, 0), (0, 1, 0), (0, -1, 0), (1, 0, 0), (0, 0, -1)] def crosspro(y, x): return ( y[1] * x[2] - y[2] * x[1], y[2] * x[0] - y[0] * x[2], y[0] * x[1] - y[1] * x[0], ) def north(r): res = [] for p in r: res.append((p[2], p[1], -p[0])) return res def south(r): res = [] for p in r: res.append((-p[2], p[1], p[0])) return res def east(r): res = [] for p in r: res.append((p[0], p[2], -p[1])) return res def west(r): res = [] for p in r: res.append((p[0], -p[2], p[1])) return res def left(r): res = [] for p in r: res.append((p[1], -p[0], p[2])) return res def right(r): res = [] for p in r: res.append((-p[1], p[0], p[2])) return res T = ["", "N", "E", "W", "S", "NN"] U = ["", "L", "LL", "LLL"] def change(S): D = d for i in S: if i == "N": D = north(D) elif i == "E": D = east(D) elif i == "W": D = west(D) elif i == "S": D = south(D) elif i == "L": D = left(D) else: D = right(D) return D def same(c1, c2): for i in T: for j in U: D = change(i + j) flag = 0 for x in range(6): for y in range(6): if d[x] == D[y]: if c1[x] != c2[y]: flag = 1 if flag == 0: return True return False N = int(input()) c = [[int(i) for i in input().split()] for j in range(N)] for i in range(N): for j in range(N): if i < j: if same(c[i], c[j]): print("No") exit() print("Yes")
Dice IV Write a program which reads $n$ dices constructed in the same way as Dice I, and determines whether they are all different. For the determination, use the same way as Dice III.
[{"input": "3\n 1 2 3 4 5 6\n 6 2 4 3 5 1\n 6 5 4 3 2 1", "output": "No"}, {"input": "3\n 1 2 3 4 5 6\n 6 5 4 3 2 1\n 5 4 3 2 1 6", "output": "Yes"}]