output_description
stringlengths
15
956
submission_id
stringlengths
10
10
status
stringclasses
3 values
problem_id
stringlengths
6
6
input_description
stringlengths
9
2.55k
attempt
stringlengths
1
13.7k
problem_description
stringlengths
7
5.24k
samples
stringlengths
2
2.72k
Print a_i and a_j that you selected, with a space in between. * * *
s661575001
Wrong Answer
p03380
Input is given from Standard Input in the following format: n a_1 a_2 ... a_n
n = int(input()) x = [int(i) for i in input().split()] sortx = sorted(x) ai = sortx[n - 1] mid = float(ai) / 2 x2 = sorted(abs(k - mid) for k in x)[0] if (mid + x2) in x: aj = int(mid + x2) else: aj = int(mid - x2) print(ai, " ", aj)
Statement Let {\rm comb}(n,r) be the number of ways to choose r objects from among n objects, disregarding order. From n non-negative integers a_1, a_2, ..., a_n, select two numbers a_i > a_j so that {\rm comb}(a_i,a_j) is maximized. If there are multiple pairs that maximize the value, any of them is accepted.
[{"input": "5\n 6 9 4 2 11", "output": "11 6\n \n\n\\rm{comb}(a_i,a_j) for each possible selection is as follows:\n\n * \\rm{comb}(4,2)=6\n * \\rm{comb}(6,2)=15\n * \\rm{comb}(6,4)=15\n * \\rm{comb}(9,2)=36\n * \\rm{comb}(9,4)=126\n * \\rm{comb}(9,6)=84\n * \\rm{comb}(11,2)=55\n * \\rm{comb}(11,4)=330\n * \\rm{comb}(11,6)=462\n * \\rm{comb}(11,9)=55\n\nThus, we should print 11 and 6.\n\n* * *"}, {"input": "2\n 100 0", "output": "100 0"}]
Print a_i and a_j that you selected, with a space in between. * * *
s144065223
Accepted
p03380
Input is given from Standard Input in the following format: n a_1 a_2 ... a_n
n = int(input()) List = list(map(int, input().split())) List = sorted(List) a_j = List[-1] checker = a_j a_i = a_j for item in List: temp = abs(a_j / 2 - item) if temp < checker: checker = temp a_i = item Answer = [a_j, a_i] print(*Answer)
Statement Let {\rm comb}(n,r) be the number of ways to choose r objects from among n objects, disregarding order. From n non-negative integers a_1, a_2, ..., a_n, select two numbers a_i > a_j so that {\rm comb}(a_i,a_j) is maximized. If there are multiple pairs that maximize the value, any of them is accepted.
[{"input": "5\n 6 9 4 2 11", "output": "11 6\n \n\n\\rm{comb}(a_i,a_j) for each possible selection is as follows:\n\n * \\rm{comb}(4,2)=6\n * \\rm{comb}(6,2)=15\n * \\rm{comb}(6,4)=15\n * \\rm{comb}(9,2)=36\n * \\rm{comb}(9,4)=126\n * \\rm{comb}(9,6)=84\n * \\rm{comb}(11,2)=55\n * \\rm{comb}(11,4)=330\n * \\rm{comb}(11,6)=462\n * \\rm{comb}(11,9)=55\n\nThus, we should print 11 and 6.\n\n* * *"}, {"input": "2\n 100 0", "output": "100 0"}]
Print a_i and a_j that you selected, with a space in between. * * *
s914311287
Wrong Answer
p03380
Input is given from Standard Input in the following format: n a_1 a_2 ... a_n
n = int(input()) a = sorted(list(map(int, input().split()))) max_a = max(a) ans = [0, 10**9] for i in a[: n - 1]: if ans[1] > (max_a / 2 - i) ** 2: ans[0] = i ans[1] = (max_a / 2 - i) ** 2 print(max_a, ans[0])
Statement Let {\rm comb}(n,r) be the number of ways to choose r objects from among n objects, disregarding order. From n non-negative integers a_1, a_2, ..., a_n, select two numbers a_i > a_j so that {\rm comb}(a_i,a_j) is maximized. If there are multiple pairs that maximize the value, any of them is accepted.
[{"input": "5\n 6 9 4 2 11", "output": "11 6\n \n\n\\rm{comb}(a_i,a_j) for each possible selection is as follows:\n\n * \\rm{comb}(4,2)=6\n * \\rm{comb}(6,2)=15\n * \\rm{comb}(6,4)=15\n * \\rm{comb}(9,2)=36\n * \\rm{comb}(9,4)=126\n * \\rm{comb}(9,6)=84\n * \\rm{comb}(11,2)=55\n * \\rm{comb}(11,4)=330\n * \\rm{comb}(11,6)=462\n * \\rm{comb}(11,9)=55\n\nThus, we should print 11 and 6.\n\n* * *"}, {"input": "2\n 100 0", "output": "100 0"}]
Print a_i and a_j that you selected, with a space in between. * * *
s296793203
Wrong Answer
p03380
Input is given from Standard Input in the following format: n a_1 a_2 ... a_n
n = int(input()) a_list = list(map(int, input().split())) a_list.sort() max_num = max(a_list) a_list.pop() n_half = max_num / 2 a_list_dif = [abs(i - n_half) for i in a_list] min_idx = 0 min_val = float("inf") for idx, v in enumerate(a_list_dif): if v < min_val: min_idx = idx print(max_num, a_list[min_idx])
Statement Let {\rm comb}(n,r) be the number of ways to choose r objects from among n objects, disregarding order. From n non-negative integers a_1, a_2, ..., a_n, select two numbers a_i > a_j so that {\rm comb}(a_i,a_j) is maximized. If there are multiple pairs that maximize the value, any of them is accepted.
[{"input": "5\n 6 9 4 2 11", "output": "11 6\n \n\n\\rm{comb}(a_i,a_j) for each possible selection is as follows:\n\n * \\rm{comb}(4,2)=6\n * \\rm{comb}(6,2)=15\n * \\rm{comb}(6,4)=15\n * \\rm{comb}(9,2)=36\n * \\rm{comb}(9,4)=126\n * \\rm{comb}(9,6)=84\n * \\rm{comb}(11,2)=55\n * \\rm{comb}(11,4)=330\n * \\rm{comb}(11,6)=462\n * \\rm{comb}(11,9)=55\n\nThus, we should print 11 and 6.\n\n* * *"}, {"input": "2\n 100 0", "output": "100 0"}]
Print a_i and a_j that you selected, with a space in between. * * *
s986889591
Accepted
p03380
Input is given from Standard Input in the following format: n a_1 a_2 ... a_n
#!/usr/bin/env python3 n, *a = map(int, open(0).read().split()) nn = max(a) a.remove(nn) nr = min(a, key=lambda x: abs(x - nn / 2)) print(nn, nr)
Statement Let {\rm comb}(n,r) be the number of ways to choose r objects from among n objects, disregarding order. From n non-negative integers a_1, a_2, ..., a_n, select two numbers a_i > a_j so that {\rm comb}(a_i,a_j) is maximized. If there are multiple pairs that maximize the value, any of them is accepted.
[{"input": "5\n 6 9 4 2 11", "output": "11 6\n \n\n\\rm{comb}(a_i,a_j) for each possible selection is as follows:\n\n * \\rm{comb}(4,2)=6\n * \\rm{comb}(6,2)=15\n * \\rm{comb}(6,4)=15\n * \\rm{comb}(9,2)=36\n * \\rm{comb}(9,4)=126\n * \\rm{comb}(9,6)=84\n * \\rm{comb}(11,2)=55\n * \\rm{comb}(11,4)=330\n * \\rm{comb}(11,6)=462\n * \\rm{comb}(11,9)=55\n\nThus, we should print 11 and 6.\n\n* * *"}, {"input": "2\n 100 0", "output": "100 0"}]
Print a_i and a_j that you selected, with a space in between. * * *
s914347701
Accepted
p03380
Input is given from Standard Input in the following format: n a_1 a_2 ... a_n
n = int(input()) ls = list(map(int, input().split())) m = max(ls) ls.remove(m) ds = [abs(x - m / 2) for x in ls] print(m, ls[ds.index(min(ds))])
Statement Let {\rm comb}(n,r) be the number of ways to choose r objects from among n objects, disregarding order. From n non-negative integers a_1, a_2, ..., a_n, select two numbers a_i > a_j so that {\rm comb}(a_i,a_j) is maximized. If there are multiple pairs that maximize the value, any of them is accepted.
[{"input": "5\n 6 9 4 2 11", "output": "11 6\n \n\n\\rm{comb}(a_i,a_j) for each possible selection is as follows:\n\n * \\rm{comb}(4,2)=6\n * \\rm{comb}(6,2)=15\n * \\rm{comb}(6,4)=15\n * \\rm{comb}(9,2)=36\n * \\rm{comb}(9,4)=126\n * \\rm{comb}(9,6)=84\n * \\rm{comb}(11,2)=55\n * \\rm{comb}(11,4)=330\n * \\rm{comb}(11,6)=462\n * \\rm{comb}(11,9)=55\n\nThus, we should print 11 and 6.\n\n* * *"}, {"input": "2\n 100 0", "output": "100 0"}]
Print a_i and a_j that you selected, with a space in between. * * *
s923851049
Runtime Error
p03380
Input is given from Standard Input in the following format: n a_1 a_2 ... a_n
input();a=list(map(int,input().split()))[::-1];print(a[0],sorted(a,key=lambda x:abs(a[0]-2*x))
Statement Let {\rm comb}(n,r) be the number of ways to choose r objects from among n objects, disregarding order. From n non-negative integers a_1, a_2, ..., a_n, select two numbers a_i > a_j so that {\rm comb}(a_i,a_j) is maximized. If there are multiple pairs that maximize the value, any of them is accepted.
[{"input": "5\n 6 9 4 2 11", "output": "11 6\n \n\n\\rm{comb}(a_i,a_j) for each possible selection is as follows:\n\n * \\rm{comb}(4,2)=6\n * \\rm{comb}(6,2)=15\n * \\rm{comb}(6,4)=15\n * \\rm{comb}(9,2)=36\n * \\rm{comb}(9,4)=126\n * \\rm{comb}(9,6)=84\n * \\rm{comb}(11,2)=55\n * \\rm{comb}(11,4)=330\n * \\rm{comb}(11,6)=462\n * \\rm{comb}(11,9)=55\n\nThus, we should print 11 and 6.\n\n* * *"}, {"input": "2\n 100 0", "output": "100 0"}]
Print a_i and a_j that you selected, with a space in between. * * *
s217841770
Runtime Error
p03380
Input is given from Standard Input in the following format: n a_1 a_2 ... a_n
N = int(input()) a = tuple(int(x) for x in input().split()) def hoge(n, r): return n * (min(n-r, r)) n = max(a) ans = (n, a[0]) for i in a: if n = i: continue ans = (n, i) if hoge(*ans) < hoge(n, i) else ans print(*ans)
Statement Let {\rm comb}(n,r) be the number of ways to choose r objects from among n objects, disregarding order. From n non-negative integers a_1, a_2, ..., a_n, select two numbers a_i > a_j so that {\rm comb}(a_i,a_j) is maximized. If there are multiple pairs that maximize the value, any of them is accepted.
[{"input": "5\n 6 9 4 2 11", "output": "11 6\n \n\n\\rm{comb}(a_i,a_j) for each possible selection is as follows:\n\n * \\rm{comb}(4,2)=6\n * \\rm{comb}(6,2)=15\n * \\rm{comb}(6,4)=15\n * \\rm{comb}(9,2)=36\n * \\rm{comb}(9,4)=126\n * \\rm{comb}(9,6)=84\n * \\rm{comb}(11,2)=55\n * \\rm{comb}(11,4)=330\n * \\rm{comb}(11,6)=462\n * \\rm{comb}(11,9)=55\n\nThus, we should print 11 and 6.\n\n* * *"}, {"input": "2\n 100 0", "output": "100 0"}]
Print a_i and a_j that you selected, with a space in between. * * *
s848688456
Runtime Error
p03380
Input is given from Standard Input in the following format: n a_1 a_2 ... a_n
import math def cal(n ,r): if n == r: return 1 return math.factorial(n)/(math.factorial(r) * math.factorial(n-r)) def bin_search(in_list, val): cnt = len(in_list) mid = round(cnt/2) if cnt == 1: return in_list[0] if in_list[mid] > val: return bin_search(in_list[:mid], val) if in_list[mid] < val: return bin_search(in_list[mid:], val) if in_list[mid] == val: return val n = int(input()) A = sorted(list(map(int, input().split()))) m_combo = 0 ai = 0 aj = 0 for i in range(1,n): a = A[i] val = bin_search(A[:i], round(a/2)) upper = A[A.index(val) + 1] val = min(abs(val - round(a/2), upper - round(a/2)) combo = cal(a, val) if combo > m_combo: m_combo = combo ai = a aj = val print('{} {}'.format(ai, aj))
Statement Let {\rm comb}(n,r) be the number of ways to choose r objects from among n objects, disregarding order. From n non-negative integers a_1, a_2, ..., a_n, select two numbers a_i > a_j so that {\rm comb}(a_i,a_j) is maximized. If there are multiple pairs that maximize the value, any of them is accepted.
[{"input": "5\n 6 9 4 2 11", "output": "11 6\n \n\n\\rm{comb}(a_i,a_j) for each possible selection is as follows:\n\n * \\rm{comb}(4,2)=6\n * \\rm{comb}(6,2)=15\n * \\rm{comb}(6,4)=15\n * \\rm{comb}(9,2)=36\n * \\rm{comb}(9,4)=126\n * \\rm{comb}(9,6)=84\n * \\rm{comb}(11,2)=55\n * \\rm{comb}(11,4)=330\n * \\rm{comb}(11,6)=462\n * \\rm{comb}(11,9)=55\n\nThus, we should print 11 and 6.\n\n* * *"}, {"input": "2\n 100 0", "output": "100 0"}]
Print a_i and a_j that you selected, with a space in between. * * *
s498709098
Runtime Error
p03380
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())) a = sorted(a, reverse = True) f = True m = 0 hikaku = -1 syutu = 0 i = 1 while f and i <= n - 1: if a[0]//2 == a[i] or a[0]//2 == a[i] + 1: f = False m = a[i] else: i += 1 if f == True: for i in range(n): answer = 1 syutu = a[i + 1] answer = int(math.factorial(a[0]) / (math.factorial(a[i + 1]) * math.factorial(a[0] - m + 1)) if hikaku < = answer: hikaku = answer m = syutu print(a[0], syutu)
Statement Let {\rm comb}(n,r) be the number of ways to choose r objects from among n objects, disregarding order. From n non-negative integers a_1, a_2, ..., a_n, select two numbers a_i > a_j so that {\rm comb}(a_i,a_j) is maximized. If there are multiple pairs that maximize the value, any of them is accepted.
[{"input": "5\n 6 9 4 2 11", "output": "11 6\n \n\n\\rm{comb}(a_i,a_j) for each possible selection is as follows:\n\n * \\rm{comb}(4,2)=6\n * \\rm{comb}(6,2)=15\n * \\rm{comb}(6,4)=15\n * \\rm{comb}(9,2)=36\n * \\rm{comb}(9,4)=126\n * \\rm{comb}(9,6)=84\n * \\rm{comb}(11,2)=55\n * \\rm{comb}(11,4)=330\n * \\rm{comb}(11,6)=462\n * \\rm{comb}(11,9)=55\n\nThus, we should print 11 and 6.\n\n* * *"}, {"input": "2\n 100 0", "output": "100 0"}]
Print a_i and a_j that you selected, with a space in between. * * *
s136562567
Runtime Error
p03380
Input is given from Standard Input in the following format: n a_1 a_2 ... a_n
import math import numpy n=int(input()) a=list(map(int,input().split())) max_num=max(a) middle_num=math.ceil(max_num/2) middle_num_up=middle_num middle_num_down=middle_num if n>2: while True: if middle_num_up in a: ans=middle_num_up break if middle_num_down in a: ans=middle_num_down break else: middle_num_up+=1 middle_num_down-=1 else: ans=min(a) print("{} {}".format(max_num,ans)
Statement Let {\rm comb}(n,r) be the number of ways to choose r objects from among n objects, disregarding order. From n non-negative integers a_1, a_2, ..., a_n, select two numbers a_i > a_j so that {\rm comb}(a_i,a_j) is maximized. If there are multiple pairs that maximize the value, any of them is accepted.
[{"input": "5\n 6 9 4 2 11", "output": "11 6\n \n\n\\rm{comb}(a_i,a_j) for each possible selection is as follows:\n\n * \\rm{comb}(4,2)=6\n * \\rm{comb}(6,2)=15\n * \\rm{comb}(6,4)=15\n * \\rm{comb}(9,2)=36\n * \\rm{comb}(9,4)=126\n * \\rm{comb}(9,6)=84\n * \\rm{comb}(11,2)=55\n * \\rm{comb}(11,4)=330\n * \\rm{comb}(11,6)=462\n * \\rm{comb}(11,9)=55\n\nThus, we should print 11 and 6.\n\n* * *"}, {"input": "2\n 100 0", "output": "100 0"}]
Print a_i and a_j that you selected, with a space in between. * * *
s534523717
Runtime Error
p03380
Input is given from Standard Input in the following format: n a_1 a_2 ... a_n
import math import numpy n=int(input()) a=list(map(int,input().split())) max_num=max(a) middle_num=math.ceil(max_num/2) middle_num_up=middle_num middle_num_down=middle_num if n>2: while True: if middle_num_up in a: ans=middle_num_up break if middle_num_down in a: ans=middle_num_down break else: middle_num_up+=1 middle_num_down-=1 else: ans=min(a) print("{} {}".format(max_num,ans)
Statement Let {\rm comb}(n,r) be the number of ways to choose r objects from among n objects, disregarding order. From n non-negative integers a_1, a_2, ..., a_n, select two numbers a_i > a_j so that {\rm comb}(a_i,a_j) is maximized. If there are multiple pairs that maximize the value, any of them is accepted.
[{"input": "5\n 6 9 4 2 11", "output": "11 6\n \n\n\\rm{comb}(a_i,a_j) for each possible selection is as follows:\n\n * \\rm{comb}(4,2)=6\n * \\rm{comb}(6,2)=15\n * \\rm{comb}(6,4)=15\n * \\rm{comb}(9,2)=36\n * \\rm{comb}(9,4)=126\n * \\rm{comb}(9,6)=84\n * \\rm{comb}(11,2)=55\n * \\rm{comb}(11,4)=330\n * \\rm{comb}(11,6)=462\n * \\rm{comb}(11,9)=55\n\nThus, we should print 11 and 6.\n\n* * *"}, {"input": "2\n 100 0", "output": "100 0"}]
Print a_i and a_j that you selected, with a space in between. * * *
s835036552
Runtime Error
p03380
Input is given from Standard Input in the following format: n a_1 a_2 ... a_n
import bisect n = int(input()) A = sorted(list(map(int,input().splitfrom math import factorial import bisect import sys n = int(input()) A = sorted(list(map(int,input().split()))) max1 = A[-1] half = A[-1]//2 point = bisect.bisect_left(A, half) if A[point] == A[-1]: print(A[-1],A[-2]) sys.exit() a1 = factorial(max1) / factorial(A[point]) / factorial(max1 - A[point]) a2 = factorial(max1) / factorial(A[point+1]) / factorial(max1 - A[point+1]) if a1>=a2: print(max1,A[point]) else: print(max1,A[point+1])
Statement Let {\rm comb}(n,r) be the number of ways to choose r objects from among n objects, disregarding order. From n non-negative integers a_1, a_2, ..., a_n, select two numbers a_i > a_j so that {\rm comb}(a_i,a_j) is maximized. If there are multiple pairs that maximize the value, any of them is accepted.
[{"input": "5\n 6 9 4 2 11", "output": "11 6\n \n\n\\rm{comb}(a_i,a_j) for each possible selection is as follows:\n\n * \\rm{comb}(4,2)=6\n * \\rm{comb}(6,2)=15\n * \\rm{comb}(6,4)=15\n * \\rm{comb}(9,2)=36\n * \\rm{comb}(9,4)=126\n * \\rm{comb}(9,6)=84\n * \\rm{comb}(11,2)=55\n * \\rm{comb}(11,4)=330\n * \\rm{comb}(11,6)=462\n * \\rm{comb}(11,9)=55\n\nThus, we should print 11 and 6.\n\n* * *"}, {"input": "2\n 100 0", "output": "100 0"}]
Print a_i and a_j that you selected, with a space in between. * * *
s970411025
Runtime Error
p03380
Input is given from Standard Input in the following format: n a_1 a_2 ... a_n
# ABC094D - Binomial Coefficients (ARC095D) from bisect import bisect_left as bs def main(): # pascal's triangle := mid area (nCn/2) is the biggest -> bisect N = int(input()) A = sorted(map(int, input().split())) if N == 2: print(A[1], A[0]) return n, idx = A[-1], bs(A[:-1], A[-1] // 2) cand = [abs(A[i] - n / 2), A[i] for i in (idx - 1, idx, idx + 1)] r = min(cand)[1] print(n, r) if __name__ == "__main__": main()
Statement Let {\rm comb}(n,r) be the number of ways to choose r objects from among n objects, disregarding order. From n non-negative integers a_1, a_2, ..., a_n, select two numbers a_i > a_j so that {\rm comb}(a_i,a_j) is maximized. If there are multiple pairs that maximize the value, any of them is accepted.
[{"input": "5\n 6 9 4 2 11", "output": "11 6\n \n\n\\rm{comb}(a_i,a_j) for each possible selection is as follows:\n\n * \\rm{comb}(4,2)=6\n * \\rm{comb}(6,2)=15\n * \\rm{comb}(6,4)=15\n * \\rm{comb}(9,2)=36\n * \\rm{comb}(9,4)=126\n * \\rm{comb}(9,6)=84\n * \\rm{comb}(11,2)=55\n * \\rm{comb}(11,4)=330\n * \\rm{comb}(11,6)=462\n * \\rm{comb}(11,9)=55\n\nThus, we should print 11 and 6.\n\n* * *"}, {"input": "2\n 100 0", "output": "100 0"}]
Print a_i and a_j that you selected, with a space in between. * * *
s656625996
Runtime Error
p03380
Input is given from Standard Input in the following format: n a_1 a_2 ... a_n
def fact(i): a = 1 for i in range(2,i+1): a *= i return a def comb(i,j): if j != 0 and j != i return int(fact(i)/(fact(j)*fact(i-j))) else: return 1 n = int(input()) l = list(map(int,input().split())) l.sort() a = [] b = [] d = [] for i in range(1,n): c = l[i] if l[0] >= int((c+1)/2): a.append(comb(c,l[0])) b.append(c) d.append(l[0]) else: j = 0 while l[j] < int((c+1)/2): j += 1 else: if l[j] == int((c+1)/2): a.append(comb(c,int((c+1)/2))) b.append(c) d.append(int((c+1)/2)) else: if l[j] - int((c+1)/2) < int((c+1)/2) -l[j-1]: a.append(comb(c,l[j])) b.append(c) d.append(l[j]) else: a.append(comb(c,l[j-1])) b.append(c) d.append(l[j-1]) I = a.index(max(a)) print("{} {}".format(b[I],d[I]))
Statement Let {\rm comb}(n,r) be the number of ways to choose r objects from among n objects, disregarding order. From n non-negative integers a_1, a_2, ..., a_n, select two numbers a_i > a_j so that {\rm comb}(a_i,a_j) is maximized. If there are multiple pairs that maximize the value, any of them is accepted.
[{"input": "5\n 6 9 4 2 11", "output": "11 6\n \n\n\\rm{comb}(a_i,a_j) for each possible selection is as follows:\n\n * \\rm{comb}(4,2)=6\n * \\rm{comb}(6,2)=15\n * \\rm{comb}(6,4)=15\n * \\rm{comb}(9,2)=36\n * \\rm{comb}(9,4)=126\n * \\rm{comb}(9,6)=84\n * \\rm{comb}(11,2)=55\n * \\rm{comb}(11,4)=330\n * \\rm{comb}(11,6)=462\n * \\rm{comb}(11,9)=55\n\nThus, we should print 11 and 6.\n\n* * *"}, {"input": "2\n 100 0", "output": "100 0"}]
Print a_i and a_j that you selected, with a space in between. * * *
s318333171
Runtime Error
p03380
Input is given from Standard Input in the following format: n a_1 a_2 ... a_n
n = int(input()) a = list(map(int,input().split())) ans1 = max(a) diff = min(ans1//2, ans1//2 + 1) ans2 = ans1 for x in a: if x == ans1: continue d = min(abs(ans1//2 - x), abs(ans1//2 + 1 - x)) if d <= diff: diff = d ans2 = x print('{} {}'.format(ans1, ans2)
Statement Let {\rm comb}(n,r) be the number of ways to choose r objects from among n objects, disregarding order. From n non-negative integers a_1, a_2, ..., a_n, select two numbers a_i > a_j so that {\rm comb}(a_i,a_j) is maximized. If there are multiple pairs that maximize the value, any of them is accepted.
[{"input": "5\n 6 9 4 2 11", "output": "11 6\n \n\n\\rm{comb}(a_i,a_j) for each possible selection is as follows:\n\n * \\rm{comb}(4,2)=6\n * \\rm{comb}(6,2)=15\n * \\rm{comb}(6,4)=15\n * \\rm{comb}(9,2)=36\n * \\rm{comb}(9,4)=126\n * \\rm{comb}(9,6)=84\n * \\rm{comb}(11,2)=55\n * \\rm{comb}(11,4)=330\n * \\rm{comb}(11,6)=462\n * \\rm{comb}(11,9)=55\n\nThus, we should print 11 and 6.\n\n* * *"}, {"input": "2\n 100 0", "output": "100 0"}]
Print a_i and a_j that you selected, with a space in between. * * *
s671414606
Runtime Error
p03380
Input is given from Standard Input in the following format: n a_1 a_2 ... a_n
import math n int(input()) a = input().split(' ') a = [int(aa) for aa in a] n = max(a) a.remove(n) res = [] for k in a: res.append(math.factorial(n) / (math.factorial(k) * math.factorial(n-k))) mm = max(res) print(n, [a[i] for i in range(len(res)) if res[i] == mm][0])
Statement Let {\rm comb}(n,r) be the number of ways to choose r objects from among n objects, disregarding order. From n non-negative integers a_1, a_2, ..., a_n, select two numbers a_i > a_j so that {\rm comb}(a_i,a_j) is maximized. If there are multiple pairs that maximize the value, any of them is accepted.
[{"input": "5\n 6 9 4 2 11", "output": "11 6\n \n\n\\rm{comb}(a_i,a_j) for each possible selection is as follows:\n\n * \\rm{comb}(4,2)=6\n * \\rm{comb}(6,2)=15\n * \\rm{comb}(6,4)=15\n * \\rm{comb}(9,2)=36\n * \\rm{comb}(9,4)=126\n * \\rm{comb}(9,6)=84\n * \\rm{comb}(11,2)=55\n * \\rm{comb}(11,4)=330\n * \\rm{comb}(11,6)=462\n * \\rm{comb}(11,9)=55\n\nThus, we should print 11 and 6.\n\n* * *"}, {"input": "2\n 100 0", "output": "100 0"}]
Print a_i and a_j that you selected, with a space in between. * * *
s192625484
Accepted
p03380
Input is given from Standard Input in the following format: n a_1 a_2 ... a_n
N = int(input()) aList = list(map(int, input().split())) n = max(aList) rc = n // 2 r = min(aList) for a in aList: if a != n and abs(r - rc) > abs(a - rc): r = a print("{} {}".format(n, r))
Statement Let {\rm comb}(n,r) be the number of ways to choose r objects from among n objects, disregarding order. From n non-negative integers a_1, a_2, ..., a_n, select two numbers a_i > a_j so that {\rm comb}(a_i,a_j) is maximized. If there are multiple pairs that maximize the value, any of them is accepted.
[{"input": "5\n 6 9 4 2 11", "output": "11 6\n \n\n\\rm{comb}(a_i,a_j) for each possible selection is as follows:\n\n * \\rm{comb}(4,2)=6\n * \\rm{comb}(6,2)=15\n * \\rm{comb}(6,4)=15\n * \\rm{comb}(9,2)=36\n * \\rm{comb}(9,4)=126\n * \\rm{comb}(9,6)=84\n * \\rm{comb}(11,2)=55\n * \\rm{comb}(11,4)=330\n * \\rm{comb}(11,6)=462\n * \\rm{comb}(11,9)=55\n\nThus, we should print 11 and 6.\n\n* * *"}, {"input": "2\n 100 0", "output": "100 0"}]
Print a_i and a_j that you selected, with a space in between. * * *
s846700260
Wrong Answer
p03380
Input is given from Standard Input in the following format: n a_1 a_2 ... a_n
n = int(input()) ns = list(map(int, input().split())) a = max(ns) b = a / 2 c = min(abs(j - b) for j in ns) d = [i for i in ns if abs(i - b) == c][0] print(a, d)
Statement Let {\rm comb}(n,r) be the number of ways to choose r objects from among n objects, disregarding order. From n non-negative integers a_1, a_2, ..., a_n, select two numbers a_i > a_j so that {\rm comb}(a_i,a_j) is maximized. If there are multiple pairs that maximize the value, any of them is accepted.
[{"input": "5\n 6 9 4 2 11", "output": "11 6\n \n\n\\rm{comb}(a_i,a_j) for each possible selection is as follows:\n\n * \\rm{comb}(4,2)=6\n * \\rm{comb}(6,2)=15\n * \\rm{comb}(6,4)=15\n * \\rm{comb}(9,2)=36\n * \\rm{comb}(9,4)=126\n * \\rm{comb}(9,6)=84\n * \\rm{comb}(11,2)=55\n * \\rm{comb}(11,4)=330\n * \\rm{comb}(11,6)=462\n * \\rm{comb}(11,9)=55\n\nThus, we should print 11 and 6.\n\n* * *"}, {"input": "2\n 100 0", "output": "100 0"}]
Print a_i and a_j that you selected, with a space in between. * * *
s449980090
Wrong Answer
p03380
Input is given from Standard Input in the following format: n a_1 a_2 ... a_n
# -*- coding: utf-8 -*- # input N = int(input()) A = list(map(int, input().split())) # solve # def comb(n, r): # if n < 0 or r < 0 or n < r: # return 0 # elif n == 0 or r == 0: # return 1 # return comb(n-1, r-1) + comb(n-1, r) # def comb(n, r): # if n == 0 or r == 0: return 1 # return comb(n, r-1) * (n-r+1) / r # A = sorted(A)[::-1] # max_num = 0 # pair = [] # for i in range(len(A)-1): # for j in range(i, len(A), 1): # if (i == j): # continue # if (max_num < comb(A[i], A[j])): # max_num = comb(A[i], A[j]) # pair = [] # pair.append(A[i]) # pair.append(A[j]) # print(pair[0], pair[1]) print(0, 0)
Statement Let {\rm comb}(n,r) be the number of ways to choose r objects from among n objects, disregarding order. From n non-negative integers a_1, a_2, ..., a_n, select two numbers a_i > a_j so that {\rm comb}(a_i,a_j) is maximized. If there are multiple pairs that maximize the value, any of them is accepted.
[{"input": "5\n 6 9 4 2 11", "output": "11 6\n \n\n\\rm{comb}(a_i,a_j) for each possible selection is as follows:\n\n * \\rm{comb}(4,2)=6\n * \\rm{comb}(6,2)=15\n * \\rm{comb}(6,4)=15\n * \\rm{comb}(9,2)=36\n * \\rm{comb}(9,4)=126\n * \\rm{comb}(9,6)=84\n * \\rm{comb}(11,2)=55\n * \\rm{comb}(11,4)=330\n * \\rm{comb}(11,6)=462\n * \\rm{comb}(11,9)=55\n\nThus, we should print 11 and 6.\n\n* * *"}, {"input": "2\n 100 0", "output": "100 0"}]
Print a_i and a_j that you selected, with a space in between. * * *
s316623808
Runtime Error
p03380
Input is given from Standard Input in the following format: n a_1 a_2 ... a_n
pりんt(あ
Statement Let {\rm comb}(n,r) be the number of ways to choose r objects from among n objects, disregarding order. From n non-negative integers a_1, a_2, ..., a_n, select two numbers a_i > a_j so that {\rm comb}(a_i,a_j) is maximized. If there are multiple pairs that maximize the value, any of them is accepted.
[{"input": "5\n 6 9 4 2 11", "output": "11 6\n \n\n\\rm{comb}(a_i,a_j) for each possible selection is as follows:\n\n * \\rm{comb}(4,2)=6\n * \\rm{comb}(6,2)=15\n * \\rm{comb}(6,4)=15\n * \\rm{comb}(9,2)=36\n * \\rm{comb}(9,4)=126\n * \\rm{comb}(9,6)=84\n * \\rm{comb}(11,2)=55\n * \\rm{comb}(11,4)=330\n * \\rm{comb}(11,6)=462\n * \\rm{comb}(11,9)=55\n\nThus, we should print 11 and 6.\n\n* * *"}, {"input": "2\n 100 0", "output": "100 0"}]
Print a_i and a_j that you selected, with a space in between. * * *
s676970545
Runtime Error
p03380
Input is given from Standard Input in the following format: n a_1 a_2 ... a_n
h, w = map(int, input().split()) sl = [] for _ in range(h): row = list(input()) sl.append(row) dp = [[10000] * h for _ in range(w)] dp[0][0] = 0 for wi in range(w): for hi in range(h): if wi + 1 < w: if sl[wi][hi] == "." and sl[wi + 1][hi] == "#": dp[wi + 1][hi] = min(dp[wi + 1][hi], dp[wi][hi] + 1) else: dp[wi + 1][hi] = min(dp[wi + 1][hi], dp[wi][hi]) if hi + 1 < h: if sl[wi][hi] == "." and sl[wi][hi + 1] == "#": dp[wi][hi + 1] = min(dp[wi][hi + 1], dp[wi][hi] + 1) else: dp[wi][hi + 1] = min(dp[wi][hi + 1], dp[wi][hi]) ans = dp[w - 1][h - 1] if sl[0][0] == "#": ans += 1 print(ans)
Statement Let {\rm comb}(n,r) be the number of ways to choose r objects from among n objects, disregarding order. From n non-negative integers a_1, a_2, ..., a_n, select two numbers a_i > a_j so that {\rm comb}(a_i,a_j) is maximized. If there are multiple pairs that maximize the value, any of them is accepted.
[{"input": "5\n 6 9 4 2 11", "output": "11 6\n \n\n\\rm{comb}(a_i,a_j) for each possible selection is as follows:\n\n * \\rm{comb}(4,2)=6\n * \\rm{comb}(6,2)=15\n * \\rm{comb}(6,4)=15\n * \\rm{comb}(9,2)=36\n * \\rm{comb}(9,4)=126\n * \\rm{comb}(9,6)=84\n * \\rm{comb}(11,2)=55\n * \\rm{comb}(11,4)=330\n * \\rm{comb}(11,6)=462\n * \\rm{comb}(11,9)=55\n\nThus, we should print 11 and 6.\n\n* * *"}, {"input": "2\n 100 0", "output": "100 0"}]
Print a_i and a_j that you selected, with a space in between. * * *
s844026256
Accepted
p03380
Input is given from Standard Input in the following format: n a_1 a_2 ... a_n
############################################################################### from sys import stdout from bisect import bisect_left as binl from copy import copy, deepcopy from collections import defaultdict mod = 1 def intin(): input_tuple = input().split() if len(input_tuple) <= 1: return int(input_tuple[0]) return tuple(map(int, input_tuple)) def intina(): return [int(i) for i in input().split()] def intinl(count): return [intin() for _ in range(count)] def modadd(x, y): global mod return (x + y) % mod def modmlt(x, y): global mod return (x * y) % mod def lcm(x, y): while y != 0: z = x % y x = y y = z return x def combination(x, y): assert x >= y if y > x // 2: y = x - y ret = 1 for i in range(0, y): j = x - i i = i + 1 ret = ret * j ret = ret // i return ret def get_divisors(x): retlist = [] for i in range(1, int(x**0.5) + 3): if x % i == 0: retlist.append(i) retlist.append(x // i) return retlist def get_factors(x): retlist = [] for i in range(2, int(x**0.5) + 3): while x % i == 0: retlist.append(i) x = x // i retlist.append(x) return retlist def make_linklist(xylist): linklist = {} for a, b in xylist: linklist.setdefault(a, []) linklist.setdefault(b, []) linklist[a].append(b) linklist[b].append(a) return linklist def calc_longest_distance(linklist, v=1): distance_list = {} distance_count = 0 distance = 0 vlist_previous = [] vlist = [v] nodecount = len(linklist) while distance_count < nodecount: vlist_next = [] for v in vlist: distance_list[v] = distance distance_count += 1 vlist_next.extend(linklist[v]) distance += 1 vlist_to_del = vlist_previous vlist_previous = vlist vlist = list(set(vlist_next) - set(vlist_to_del)) max_distance = -1 max_v = None for v, distance in distance_list.items(): if distance > max_distance: max_distance = distance max_v = v return (max_distance, max_v) def calc_tree_diameter(linklist, v=1): _, u = calc_longest_distance(linklist, v) distance, _ = calc_longest_distance(linklist, u) return distance class UnionFind: def __init__(self, n): self.parent = [i for i in range(n)] def root(self, i): if self.parent[i] == i: return i self.parent[i] = self.root(self.parent[i]) return self.parent[i] def unite(self, i, j): rooti = self.root(i) rootj = self.root(j) if rooti == rootj: return if rooti < rootj: self.parent[rootj] = rooti else: self.parent[rooti] = rootj def same(self, i, j): return self.root(i) == self.root(j) ############################################################################### def main(): n = intin() alist = intina() alist.sort() m = alist[-1] ind = binl(alist, m // 2) ind1 = ind - 1 if ind > 0 else None ind2 = ind mmlist = [m // 2] if m & 1: mmlist.append(m // 2 + 1) c1 = float("inf") if ind1 is not None and ind1 != len(alist) - 1: for mm in mmlist: c1 = min(c1, abs(alist[ind1] - mm)) c2 = float("inf") if ind2 != len(alist) - 1: for mm in mmlist: c2 = min(c2, abs(alist[ind2] - mm)) if c1 < c2: print("%d %d" % (m, alist[ind1])) else: print("%d %d" % (m, alist[ind2])) if __name__ == "__main__": main()
Statement Let {\rm comb}(n,r) be the number of ways to choose r objects from among n objects, disregarding order. From n non-negative integers a_1, a_2, ..., a_n, select two numbers a_i > a_j so that {\rm comb}(a_i,a_j) is maximized. If there are multiple pairs that maximize the value, any of them is accepted.
[{"input": "5\n 6 9 4 2 11", "output": "11 6\n \n\n\\rm{comb}(a_i,a_j) for each possible selection is as follows:\n\n * \\rm{comb}(4,2)=6\n * \\rm{comb}(6,2)=15\n * \\rm{comb}(6,4)=15\n * \\rm{comb}(9,2)=36\n * \\rm{comb}(9,4)=126\n * \\rm{comb}(9,6)=84\n * \\rm{comb}(11,2)=55\n * \\rm{comb}(11,4)=330\n * \\rm{comb}(11,6)=462\n * \\rm{comb}(11,9)=55\n\nThus, we should print 11 and 6.\n\n* * *"}, {"input": "2\n 100 0", "output": "100 0"}]
Print a_i and a_j that you selected, with a space in between. * * *
s955212009
Accepted
p03380
Input is given from Standard Input in the following format: n a_1 a_2 ... a_n
n = int(input()) ls = sorted(map(int, input().split())) ds = [abs(x - ls[-1] / 2) for x in ls[:-1]] print(ls[-1], ls[ds.index(min(ds))])
Statement Let {\rm comb}(n,r) be the number of ways to choose r objects from among n objects, disregarding order. From n non-negative integers a_1, a_2, ..., a_n, select two numbers a_i > a_j so that {\rm comb}(a_i,a_j) is maximized. If there are multiple pairs that maximize the value, any of them is accepted.
[{"input": "5\n 6 9 4 2 11", "output": "11 6\n \n\n\\rm{comb}(a_i,a_j) for each possible selection is as follows:\n\n * \\rm{comb}(4,2)=6\n * \\rm{comb}(6,2)=15\n * \\rm{comb}(6,4)=15\n * \\rm{comb}(9,2)=36\n * \\rm{comb}(9,4)=126\n * \\rm{comb}(9,6)=84\n * \\rm{comb}(11,2)=55\n * \\rm{comb}(11,4)=330\n * \\rm{comb}(11,6)=462\n * \\rm{comb}(11,9)=55\n\nThus, we should print 11 and 6.\n\n* * *"}, {"input": "2\n 100 0", "output": "100 0"}]
Print a_i and a_j that you selected, with a space in between. * * *
s925252193
Accepted
p03380
Input is given from Standard Input in the following format: n a_1 a_2 ... a_n
n = int(input()) a = list(map(int, input().split())) kar = max(a) a.remove(kar) mid = kar // 2 tyu = 10**10 if kar % 2 == 0: for i in range(n - 1): if tyu > abs(mid - a[i]): tyu = abs(mid - a[i]) ans = a[i] elif kar % 2 == 1: for i in range(n - 1): if tyu > min(abs(mid - a[i]), abs(mid + 1 - a[i])): tyu = min(abs(mid - a[i]), abs(mid + 1 - a[i])) ans = a[i] print(str(kar) + " " + str(ans))
Statement Let {\rm comb}(n,r) be the number of ways to choose r objects from among n objects, disregarding order. From n non-negative integers a_1, a_2, ..., a_n, select two numbers a_i > a_j so that {\rm comb}(a_i,a_j) is maximized. If there are multiple pairs that maximize the value, any of them is accepted.
[{"input": "5\n 6 9 4 2 11", "output": "11 6\n \n\n\\rm{comb}(a_i,a_j) for each possible selection is as follows:\n\n * \\rm{comb}(4,2)=6\n * \\rm{comb}(6,2)=15\n * \\rm{comb}(6,4)=15\n * \\rm{comb}(9,2)=36\n * \\rm{comb}(9,4)=126\n * \\rm{comb}(9,6)=84\n * \\rm{comb}(11,2)=55\n * \\rm{comb}(11,4)=330\n * \\rm{comb}(11,6)=462\n * \\rm{comb}(11,9)=55\n\nThus, we should print 11 and 6.\n\n* * *"}, {"input": "2\n 100 0", "output": "100 0"}]
Print the number of ways to select cards such that the average of the written integers is exactly A. * * *
s348772659
Accepted
p04015
The input is given from Standard Input in the following format: N A x_1 x_2 ... x_N
n, a = map(int, input().split()) x = list(map(int, input().split())) x_m = [] x_0 = [] x_p = [] for i in range(n): tmp = x[i] - a if tmp < 0: x_m.append(tmp * -1) elif tmp == 0: x_0.append(tmp) else: x_p.append(tmp) len_m = len(x_m) len_0 = len(x_0) len_p = len(x_p) dp_m = [[0] * 1300 for i in range(len_m + 1)] dp_p = [[0] * 1300 for i in range(len_p + 1)] dp_m[0][0] = 1 dp_p[0][0] = 1 for i in range(1, len_m + 1): for j in range(1300): dp_m[i][j] = dp_m[i - 1][j] if j >= x_m[i - 1]: dp_m[i][j] += dp_m[i - 1][j - x_m[i - 1]] for i in range(1, len_p + 1): for j in range(1300): dp_p[i][j] = dp_p[i - 1][j] if j >= x_p[i - 1]: dp_p[i][j] += dp_p[i - 1][j - x_p[i - 1]] ans = 0 for i in range(0, 1300): ans += dp_m[-1][i] * dp_p[-1][i] ans = ans * 2**len_0 - 1 print(ans)
Statement Tak has N cards. On the i-th (1 \leq i \leq N) card is written an integer x_i. He is selecting one or more cards from these N cards, so that the average of the integers written on the selected cards is exactly A. In how many ways can he make his selection?
[{"input": "4 8\n 7 9 8 9", "output": "5\n \n\n * The following are the 5 ways to select cards such that the average is 8:\n * Select the 3-rd card.\n * Select the 1-st and 2-nd cards.\n * Select the 1-st and 4-th cards.\n * Select the 1-st, 2-nd and 3-rd cards.\n * Select the 1-st, 3-rd and 4-th cards.\n\n* * *"}, {"input": "3 8\n 6 6 9", "output": "0\n \n\n* * *"}, {"input": "8 5\n 3 6 2 8 7 6 5 9", "output": "19\n \n\n* * *"}, {"input": "33 3\n 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3", "output": "8589934591\n \n\n * The answer may not fit into a 32-bit integer."}]
Print the number of ways to select cards such that the average of the written integers is exactly A. * * *
s236474779
Runtime Error
p04015
The input is given from Standard Input in the following format: N A x_1 x_2 ... x_N
import math n = int(input()) s = int(input()) def solve(n, s): if n == s: return n + 1 for b in range(2, math.floor(n**0.5) + 1): tmp = n res = 0 while tmp >= b: res += tmp % b tmp //= b res += tmp if res == s: return b for p in range(int(n**0.5), 0, -1): r = s - p if r < 0: continue if (n - r) % p == 0: b = (n - r) // p if r < b and b * b > n: return b return -1 print(solve(n, s))
Statement Tak has N cards. On the i-th (1 \leq i \leq N) card is written an integer x_i. He is selecting one or more cards from these N cards, so that the average of the integers written on the selected cards is exactly A. In how many ways can he make his selection?
[{"input": "4 8\n 7 9 8 9", "output": "5\n \n\n * The following are the 5 ways to select cards such that the average is 8:\n * Select the 3-rd card.\n * Select the 1-st and 2-nd cards.\n * Select the 1-st and 4-th cards.\n * Select the 1-st, 2-nd and 3-rd cards.\n * Select the 1-st, 3-rd and 4-th cards.\n\n* * *"}, {"input": "3 8\n 6 6 9", "output": "0\n \n\n* * *"}, {"input": "8 5\n 3 6 2 8 7 6 5 9", "output": "19\n \n\n* * *"}, {"input": "33 3\n 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3", "output": "8589934591\n \n\n * The answer may not fit into a 32-bit integer."}]
Print the number of ways to select cards such that the average of the written integers is exactly A. * * *
s480453533
Wrong Answer
p04015
The input is given from Standard Input in the following format: N A x_1 x_2 ... x_N
n, a = [int(_) for _ in input().split()] y = [int(_) - a for _ in input().split()] dp = [[0 for sum in range(2 * n * a + 51)] for right in range(n)] dp[0][0 + n * a] = 1 dp[0][y[0] + n * a] = 1 for right in range(n - 1): for sum in range(-n * a, n * a + 1): dp[right + 1][sum + n * a] += dp[right][sum + n * a] dp[right + 1][sum + y[right + 1] + n * a] += dp[right][sum + n * a] print(dp[-1][n * a] - 1)
Statement Tak has N cards. On the i-th (1 \leq i \leq N) card is written an integer x_i. He is selecting one or more cards from these N cards, so that the average of the integers written on the selected cards is exactly A. In how many ways can he make his selection?
[{"input": "4 8\n 7 9 8 9", "output": "5\n \n\n * The following are the 5 ways to select cards such that the average is 8:\n * Select the 3-rd card.\n * Select the 1-st and 2-nd cards.\n * Select the 1-st and 4-th cards.\n * Select the 1-st, 2-nd and 3-rd cards.\n * Select the 1-st, 3-rd and 4-th cards.\n\n* * *"}, {"input": "3 8\n 6 6 9", "output": "0\n \n\n* * *"}, {"input": "8 5\n 3 6 2 8 7 6 5 9", "output": "19\n \n\n* * *"}, {"input": "33 3\n 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3", "output": "8589934591\n \n\n * The answer may not fit into a 32-bit integer."}]
Print the number of ways to select cards such that the average of the written integers is exactly A. * * *
s206690921
Runtime Error
p04015
The input is given from Standard Input in the following format: N A x_1 x_2 ... x_N
N,A=map(int,input().split()) a=list(map(int, input().split())) def hiku(kazu): return kazu-A b=[] for i in range(N): b.append(hiku(a[i])) X=max(a) def hai(s,t): if s==0 and t==NX: return 1 elif s>=1 and (t-b[s]<0 or t-b[s]>2NX): return hai(s-1,t) elif s>=1 and (0<=t-b[s]<=2NX): return hai(s-1,t)+hai(s-1,t-b[s]) else: return 0 print(hai(N,NX)-1)
Statement Tak has N cards. On the i-th (1 \leq i \leq N) card is written an integer x_i. He is selecting one or more cards from these N cards, so that the average of the integers written on the selected cards is exactly A. In how many ways can he make his selection?
[{"input": "4 8\n 7 9 8 9", "output": "5\n \n\n * The following are the 5 ways to select cards such that the average is 8:\n * Select the 3-rd card.\n * Select the 1-st and 2-nd cards.\n * Select the 1-st and 4-th cards.\n * Select the 1-st, 2-nd and 3-rd cards.\n * Select the 1-st, 3-rd and 4-th cards.\n\n* * *"}, {"input": "3 8\n 6 6 9", "output": "0\n \n\n* * *"}, {"input": "8 5\n 3 6 2 8 7 6 5 9", "output": "19\n \n\n* * *"}, {"input": "33 3\n 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3", "output": "8589934591\n \n\n * The answer may not fit into a 32-bit integer."}]
Print the number of ways to select cards such that the average of the written integers is exactly A. * * *
s095841875
Wrong Answer
p04015
The input is given from Standard Input in the following format: N A x_1 x_2 ... x_N
w = str(input()) w2 = set(w) flag = 0 for i in w2: cnt = 0 cnt = w.count(i) if cnt % 2 == 1: print("No") flag = 1 break if flag == 0: print("Yes")
Statement Tak has N cards. On the i-th (1 \leq i \leq N) card is written an integer x_i. He is selecting one or more cards from these N cards, so that the average of the integers written on the selected cards is exactly A. In how many ways can he make his selection?
[{"input": "4 8\n 7 9 8 9", "output": "5\n \n\n * The following are the 5 ways to select cards such that the average is 8:\n * Select the 3-rd card.\n * Select the 1-st and 2-nd cards.\n * Select the 1-st and 4-th cards.\n * Select the 1-st, 2-nd and 3-rd cards.\n * Select the 1-st, 3-rd and 4-th cards.\n\n* * *"}, {"input": "3 8\n 6 6 9", "output": "0\n \n\n* * *"}, {"input": "8 5\n 3 6 2 8 7 6 5 9", "output": "19\n \n\n* * *"}, {"input": "33 3\n 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3", "output": "8589934591\n \n\n * The answer may not fit into a 32-bit integer."}]
Print the number of ways to select cards such that the average of the written integers is exactly A. * * *
s516427249
Runtime Error
p04015
The input is given from Standard Input in the following format: N A x_1 x_2 ... x_N
n,a=map(int, input().split()) x=list(map(int, input().split())) x=[i-a for i in x] d={0:1} for i in x: for j,k in list(d.items()): d[i+.j]=d.get(i+j,0)+k print(d[0]-1) #sample code
Statement Tak has N cards. On the i-th (1 \leq i \leq N) card is written an integer x_i. He is selecting one or more cards from these N cards, so that the average of the integers written on the selected cards is exactly A. In how many ways can he make his selection?
[{"input": "4 8\n 7 9 8 9", "output": "5\n \n\n * The following are the 5 ways to select cards such that the average is 8:\n * Select the 3-rd card.\n * Select the 1-st and 2-nd cards.\n * Select the 1-st and 4-th cards.\n * Select the 1-st, 2-nd and 3-rd cards.\n * Select the 1-st, 3-rd and 4-th cards.\n\n* * *"}, {"input": "3 8\n 6 6 9", "output": "0\n \n\n* * *"}, {"input": "8 5\n 3 6 2 8 7 6 5 9", "output": "19\n \n\n* * *"}, {"input": "33 3\n 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3", "output": "8589934591\n \n\n * The answer may not fit into a 32-bit integer."}]
Print the number of ways to select cards such that the average of the written integers is exactly A. * * *
s464696676
Accepted
p04015
The input is given from Standard Input in the following format: N A x_1 x_2 ... x_N
# -*- coding: utf-8 -*- import sys import math import os import itertools import _collections import string from functools import lru_cache import heapq class cin: def int(): return int(sys.stdin.readline().rstrip()) def string(): return sys.stdin.readline().rstrip() def mapInt(): return [int(x) for x in cin.string().split()] def stringList(n): return [input() for i in range(n)] def intListList(n): return [cin.mapInt() for i in range(n)] def intColsList(n): return [int(input()) for i in range(n)] class Math: def gcd(a, b): if b == 0: return a return Math.gcd(b, a % b) def lcm(a, b): return (a * b) // Math.gcd(a, b) def roundUp(a, b): return -(-a // b) def toUpperMultiple(a, x): return Math.roundUp(a, x) * x def toLowerMultiple(a, x): return (a // x) * x def nearPow2(n): if n <= 0: return 0 if n & (n - 1) == 0: return n ret = 1 while n > 0: ret <<= 1 n >>= 1 return ret def isPrime(n): if n < 2: return False if n == 2: return True if n % 2 == 0: return False d = int(n**0.5) + 1 for i in range(3, d + 1, 2): if n % i == 0: return False return True MOD = int(1e09) + 7 def main(): N, A = cin.mapInt() X = cin.mapInt() dp = [[[0 for k in range(3000)] for j in range(51)] for i in range(51)] dp[0][0][0] = 1 ans = 0 for i in range(N): for j in range(i + 1): for k in range(2500): dp[i + 1][j][k] += dp[i][j][k] dp[i + 1][j + 1][k + X[i]] += dp[i][j][k] for j in range(1, N + 1): ans += dp[N][j][j * A] print(ans) return if __name__ == "__main__": main()
Statement Tak has N cards. On the i-th (1 \leq i \leq N) card is written an integer x_i. He is selecting one or more cards from these N cards, so that the average of the integers written on the selected cards is exactly A. In how many ways can he make his selection?
[{"input": "4 8\n 7 9 8 9", "output": "5\n \n\n * The following are the 5 ways to select cards such that the average is 8:\n * Select the 3-rd card.\n * Select the 1-st and 2-nd cards.\n * Select the 1-st and 4-th cards.\n * Select the 1-st, 2-nd and 3-rd cards.\n * Select the 1-st, 3-rd and 4-th cards.\n\n* * *"}, {"input": "3 8\n 6 6 9", "output": "0\n \n\n* * *"}, {"input": "8 5\n 3 6 2 8 7 6 5 9", "output": "19\n \n\n* * *"}, {"input": "33 3\n 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3", "output": "8589934591\n \n\n * The answer may not fit into a 32-bit integer."}]
When the minimum required number of recorders is x, print the value of x. * * *
s961841017
Accepted
p03504
Input is given from Standard Input in the following format: N C s_1 t_1 c_1 : s_N t_N c_N
from operator import attrgetter class Data: def __init__(self, s, t, c): self.s = s self.t = t self.c = c N, C = map(int, input().split()) data_list = [] for _ in range(N): s, t, c = map(int, input().split()) data_list.append(Data(s, t, c)) ch_map = {} for data in data_list: if data.c in ch_map: ch_map[data.c].append(data) else: ch_map[data.c] = [data] data_list = [] m = {} for key, val in ch_map.items(): ch_list = sorted(val, key=attrgetter("s")) # m = {} ch_m = {} end = 0 for ch in ch_list: if end <= ch.s: for i in range(ch.s - 1, ch.t): if i in m: if i not in ch_m: m[i] += 1 else: m[i] = 1 ch_m[i] = 1 # m[i] = 1 end = ch.t elif end > ch.t: for i in range((end + 1, ch.t)): if i in m: if i not in ch_m: m[i] += 1 else: m[i] = 1 ch_m[i] = 1 # m[i] = 1 end = ch.t # ch_map[key] = m max = 0 for key, val in m.items(): if max < val: max = val # print(ch_map) """ for i in range(100001): cnt = 0 for key, val in ch_map.items(): if i in val: cnt += 1 if cnt > max: max = cnt cnt = 0 """ print(max)
Statement Joisino is planning to record N TV programs with recorders. The TV can receive C channels numbered 1 through C. The i-th program that she wants to record will be broadcast from time s_i to time t_i (including time s_i but not t_i) on Channel c_i. Here, there will never be more than one program that are broadcast on the same channel at the same time. When the recorder is recording a channel from time S to time T (including time S but not T), it cannot record other channels from time S-0.5 to time T (including time S-0.5 but not T). Find the minimum number of recorders required to record the channels so that all the N programs are completely recorded.
[{"input": "3 2\n 1 7 2\n 7 8 1\n 8 12 1", "output": "2\n \n\nTwo recorders can record all the programs, for example, as follows:\n\n * With the first recorder, record Channel 2 from time 1 to time 7. The first program will be recorded. Note that this recorder will be unable to record other channels from time 0.5 to time 7.\n * With the second recorder, record Channel 1 from time 7 to time 12. The second and third programs will be recorded. Note that this recorder will be unable to record other channels from time 6.5 to time 12.\n\n* * *"}, {"input": "3 4\n 1 3 2\n 3 4 4\n 1 4 3", "output": "3\n \n\nThere may be a channel where there is no program to record.\n\n* * *"}, {"input": "9 4\n 56 60 4\n 33 37 2\n 89 90 3\n 32 43 1\n 67 68 3\n 49 51 3\n 31 32 3\n 70 71 1\n 11 12 3", "output": "2"}]
When the minimum required number of recorders is x, print the value of x. * * *
s802025570
Accepted
p03504
Input is given from Standard Input in the following format: N C s_1 t_1 c_1 : s_N t_N c_N
from sys import stdout printn = lambda x: stdout.write(x) inn = lambda: int(input()) inl = lambda: list(map(int, input().split())) inm = lambda: map(int, input().split()) DBG = True # and False BIG = 999999999 R = 10**9 + 7 def ddprint(x): if DBG: print(x) n, c = inm() a = [] for i in range(n): s, t, c = inm() a.append((t, s, c)) a.sort() h = {} # h[(t,c)] = s for z in a: t, s, c = z if (s, c) in h: s0 = h[(s, c)] del h[(s, c)] h[(t, c)] = s0 else: h[(t, c)] = s a = [] for z in h: t, c = z s = h[z] a.append((t, s, c)) a.sort() # ddprint(a) n = len(a) nu = 0 ut = [-1] * n uc = [-1] * n for i in range(n): t, s, c = a[i] # ddprint("lp t {} s {} c {} i {}".format(t,s,c,i)) mx = -1 for j in range(nu): if ut[j] <= s - 1 and ut[j] > mx: mx = ut[j] mxj = j if False: ddprint("t {} s {} c {} j {}".format(t, s, c, j)) ddprint(ut) ddprint(uc) if mx == -1: mxj = nu nu += 1 ut[mxj] = t uc[mxj] = c # ddprint(mxj) print(nu)
Statement Joisino is planning to record N TV programs with recorders. The TV can receive C channels numbered 1 through C. The i-th program that she wants to record will be broadcast from time s_i to time t_i (including time s_i but not t_i) on Channel c_i. Here, there will never be more than one program that are broadcast on the same channel at the same time. When the recorder is recording a channel from time S to time T (including time S but not T), it cannot record other channels from time S-0.5 to time T (including time S-0.5 but not T). Find the minimum number of recorders required to record the channels so that all the N programs are completely recorded.
[{"input": "3 2\n 1 7 2\n 7 8 1\n 8 12 1", "output": "2\n \n\nTwo recorders can record all the programs, for example, as follows:\n\n * With the first recorder, record Channel 2 from time 1 to time 7. The first program will be recorded. Note that this recorder will be unable to record other channels from time 0.5 to time 7.\n * With the second recorder, record Channel 1 from time 7 to time 12. The second and third programs will be recorded. Note that this recorder will be unable to record other channels from time 6.5 to time 12.\n\n* * *"}, {"input": "3 4\n 1 3 2\n 3 4 4\n 1 4 3", "output": "3\n \n\nThere may be a channel where there is no program to record.\n\n* * *"}, {"input": "9 4\n 56 60 4\n 33 37 2\n 89 90 3\n 32 43 1\n 67 68 3\n 49 51 3\n 31 32 3\n 70 71 1\n 11 12 3", "output": "2"}]
When the minimum required number of recorders is x, print the value of x. * * *
s019655601
Accepted
p03504
Input is given from Standard Input in the following format: N C s_1 t_1 c_1 : s_N t_N c_N
n, _ = map(int, input().split()) a = sorted(tuple(map(int, input().split())) for _ in range(n)) r = [(0, 0)] for s, t, c in a: u, i = min((u + 0.5 * (c != d), i) for i, (u, d) in enumerate(r)) if s < u: r.append((t, c)) else: r[i] = (t, c) print(len(r))
Statement Joisino is planning to record N TV programs with recorders. The TV can receive C channels numbered 1 through C. The i-th program that she wants to record will be broadcast from time s_i to time t_i (including time s_i but not t_i) on Channel c_i. Here, there will never be more than one program that are broadcast on the same channel at the same time. When the recorder is recording a channel from time S to time T (including time S but not T), it cannot record other channels from time S-0.5 to time T (including time S-0.5 but not T). Find the minimum number of recorders required to record the channels so that all the N programs are completely recorded.
[{"input": "3 2\n 1 7 2\n 7 8 1\n 8 12 1", "output": "2\n \n\nTwo recorders can record all the programs, for example, as follows:\n\n * With the first recorder, record Channel 2 from time 1 to time 7. The first program will be recorded. Note that this recorder will be unable to record other channels from time 0.5 to time 7.\n * With the second recorder, record Channel 1 from time 7 to time 12. The second and third programs will be recorded. Note that this recorder will be unable to record other channels from time 6.5 to time 12.\n\n* * *"}, {"input": "3 4\n 1 3 2\n 3 4 4\n 1 4 3", "output": "3\n \n\nThere may be a channel where there is no program to record.\n\n* * *"}, {"input": "9 4\n 56 60 4\n 33 37 2\n 89 90 3\n 32 43 1\n 67 68 3\n 49 51 3\n 31 32 3\n 70 71 1\n 11 12 3", "output": "2"}]
When the minimum required number of recorders is x, print the value of x. * * *
s541012739
Accepted
p03504
Input is given from Standard Input in the following format: N C s_1 t_1 c_1 : s_N t_N c_N
n, c = map(int, input().split()) nca = sorted([tuple(map(int, input().split())) for _ in range(n)]) cnf = [True] * n line = 0 while any(cnf): lst = () for i in range(n): if cnf[i] == True: temp = nca[i] if (lst == ()) or (temp[2] == lst[2]) or (lst[1] < temp[0]): lst = temp cnf[i] = False line += 1 print(line)
Statement Joisino is planning to record N TV programs with recorders. The TV can receive C channels numbered 1 through C. The i-th program that she wants to record will be broadcast from time s_i to time t_i (including time s_i but not t_i) on Channel c_i. Here, there will never be more than one program that are broadcast on the same channel at the same time. When the recorder is recording a channel from time S to time T (including time S but not T), it cannot record other channels from time S-0.5 to time T (including time S-0.5 but not T). Find the minimum number of recorders required to record the channels so that all the N programs are completely recorded.
[{"input": "3 2\n 1 7 2\n 7 8 1\n 8 12 1", "output": "2\n \n\nTwo recorders can record all the programs, for example, as follows:\n\n * With the first recorder, record Channel 2 from time 1 to time 7. The first program will be recorded. Note that this recorder will be unable to record other channels from time 0.5 to time 7.\n * With the second recorder, record Channel 1 from time 7 to time 12. The second and third programs will be recorded. Note that this recorder will be unable to record other channels from time 6.5 to time 12.\n\n* * *"}, {"input": "3 4\n 1 3 2\n 3 4 4\n 1 4 3", "output": "3\n \n\nThere may be a channel where there is no program to record.\n\n* * *"}, {"input": "9 4\n 56 60 4\n 33 37 2\n 89 90 3\n 32 43 1\n 67 68 3\n 49 51 3\n 31 32 3\n 70 71 1\n 11 12 3", "output": "2"}]
When the minimum required number of recorders is x, print the value of x. * * *
s158853037
Accepted
p03504
Input is given from Standard Input in the following format: N C s_1 t_1 c_1 : s_N t_N c_N
# coding: utf-8 # Your code here! N, C = [int(i) for i in input().split()] stc = [list(map(int, input().split())) for i in range(N)] # N行分の入力を二重配列にする sort_stc = sorted(stc) # print(sort_stc) counter = 0 rokuga_joutai = [] for bangumi in range(N): flag = -1 for rokugaki in range(counter): if ( rokuga_joutai[rokugaki][2] == sort_stc[bangumi][2] and rokuga_joutai[rokugaki][1] - 0.1 < sort_stc[bangumi][0] ) or rokuga_joutai[rokugaki][1] + 0.5 < sort_stc[bangumi][0]: flag = rokugaki if flag != -1: # print(flag) rokuga_joutai[flag][0] = sort_stc[bangumi][0] rokuga_joutai[flag][1] = sort_stc[bangumi][1] rokuga_joutai[flag][2] = sort_stc[bangumi][2] else: rokuga_joutai.append( [sort_stc[bangumi][0], sort_stc[bangumi][1], sort_stc[bangumi][2]] ) counter += 1 # print(rokuga_joutai) print(counter)
Statement Joisino is planning to record N TV programs with recorders. The TV can receive C channels numbered 1 through C. The i-th program that she wants to record will be broadcast from time s_i to time t_i (including time s_i but not t_i) on Channel c_i. Here, there will never be more than one program that are broadcast on the same channel at the same time. When the recorder is recording a channel from time S to time T (including time S but not T), it cannot record other channels from time S-0.5 to time T (including time S-0.5 but not T). Find the minimum number of recorders required to record the channels so that all the N programs are completely recorded.
[{"input": "3 2\n 1 7 2\n 7 8 1\n 8 12 1", "output": "2\n \n\nTwo recorders can record all the programs, for example, as follows:\n\n * With the first recorder, record Channel 2 from time 1 to time 7. The first program will be recorded. Note that this recorder will be unable to record other channels from time 0.5 to time 7.\n * With the second recorder, record Channel 1 from time 7 to time 12. The second and third programs will be recorded. Note that this recorder will be unable to record other channels from time 6.5 to time 12.\n\n* * *"}, {"input": "3 4\n 1 3 2\n 3 4 4\n 1 4 3", "output": "3\n \n\nThere may be a channel where there is no program to record.\n\n* * *"}, {"input": "9 4\n 56 60 4\n 33 37 2\n 89 90 3\n 32 43 1\n 67 68 3\n 49 51 3\n 31 32 3\n 70 71 1\n 11 12 3", "output": "2"}]
When the minimum required number of recorders is x, print the value of x. * * *
s945108118
Wrong Answer
p03504
Input is given from Standard Input in the following format: N C s_1 t_1 c_1 : s_N t_N c_N
N, C = list(map(int, input().split())) A = [list(map(int, input().split())) for _ in range(N)] T = 0 for i in A: T = max(i[1], T) timelist = [0 for _ in range((T) * 2)] for item in A: starttime = item[0] endtime = item[1] for time in range(starttime * 2 - 2, endtime * 2 - 1, 2): timelist[time] += 1 timelist[time + 1] += 1 print(max(timelist))
Statement Joisino is planning to record N TV programs with recorders. The TV can receive C channels numbered 1 through C. The i-th program that she wants to record will be broadcast from time s_i to time t_i (including time s_i but not t_i) on Channel c_i. Here, there will never be more than one program that are broadcast on the same channel at the same time. When the recorder is recording a channel from time S to time T (including time S but not T), it cannot record other channels from time S-0.5 to time T (including time S-0.5 but not T). Find the minimum number of recorders required to record the channels so that all the N programs are completely recorded.
[{"input": "3 2\n 1 7 2\n 7 8 1\n 8 12 1", "output": "2\n \n\nTwo recorders can record all the programs, for example, as follows:\n\n * With the first recorder, record Channel 2 from time 1 to time 7. The first program will be recorded. Note that this recorder will be unable to record other channels from time 0.5 to time 7.\n * With the second recorder, record Channel 1 from time 7 to time 12. The second and third programs will be recorded. Note that this recorder will be unable to record other channels from time 6.5 to time 12.\n\n* * *"}, {"input": "3 4\n 1 3 2\n 3 4 4\n 1 4 3", "output": "3\n \n\nThere may be a channel where there is no program to record.\n\n* * *"}, {"input": "9 4\n 56 60 4\n 33 37 2\n 89 90 3\n 32 43 1\n 67 68 3\n 49 51 3\n 31 32 3\n 70 71 1\n 11 12 3", "output": "2"}]
When the minimum required number of recorders is x, print the value of x. * * *
s813987298
Runtime Error
p03504
Input is given from Standard Input in the following format: N C s_1 t_1 c_1 : s_N t_N c_N
n,c = map(int,input().split()) stc = [[int(i) for i in input().split()] for j in range(n)] ans = 0 stc.sort(key=lambda x:(x[2],x[1],x[0])) time = 10**5+1 c_imos = [[0 for i in range(time)] for j in range(c)] for i in range(n): c_imos[stc[i][2]-1][stc[i][0]-1] += 1 c_imos[stc[i][2]-1][stc[i][1]] -= 1 #print(c_imos) nd_v = [[0 for i in range(time)] for j in range(c)] for i in range(c): for j in range(time): if j == 0: if c_imos[i][j] == 1: nd_v[i][j] = 1 else:q nd_v[i][j] = max(0,min(1,nd_v[i][j-1] + c_imos[i][j])) #print(nd_v) ans = 1 for i in range(time-1): tmp = 0 for j in range(c): tmp += nd_v[j][i] ans = max(tmp,ans) print(ans) exit() c_num = stc[0][2] t_num = stc[0][1] idx = 0 print(stc) for i in range(1,n): print(t_num,i) if stc[idx+i][2] == c_num: if stc[idx+i][0] == t_num: stc[idx+i-1][1] = stc[idx+i][1] t_num = stc[idx+i][1] del stc[idx+i] idx -= 1 else: print(t_num,t_num,t_num) c_num = stc[idx+i][2] t_num = stc[idx+i][1] stc.sort(key=lambda x:x[1]) print(stc) exit() tmp = stc[0][1] ans = 1 ans_tmp = 1 for i in range(1,len(stc)): for j in range(i+1,len(stc)): if tmp >= stc[j][0]: ans_tmp += 1 else: tmp = stc[j][0] ans = max(ans_tmp,ans)
Statement Joisino is planning to record N TV programs with recorders. The TV can receive C channels numbered 1 through C. The i-th program that she wants to record will be broadcast from time s_i to time t_i (including time s_i but not t_i) on Channel c_i. Here, there will never be more than one program that are broadcast on the same channel at the same time. When the recorder is recording a channel from time S to time T (including time S but not T), it cannot record other channels from time S-0.5 to time T (including time S-0.5 but not T). Find the minimum number of recorders required to record the channels so that all the N programs are completely recorded.
[{"input": "3 2\n 1 7 2\n 7 8 1\n 8 12 1", "output": "2\n \n\nTwo recorders can record all the programs, for example, as follows:\n\n * With the first recorder, record Channel 2 from time 1 to time 7. The first program will be recorded. Note that this recorder will be unable to record other channels from time 0.5 to time 7.\n * With the second recorder, record Channel 1 from time 7 to time 12. The second and third programs will be recorded. Note that this recorder will be unable to record other channels from time 6.5 to time 12.\n\n* * *"}, {"input": "3 4\n 1 3 2\n 3 4 4\n 1 4 3", "output": "3\n \n\nThere may be a channel where there is no program to record.\n\n* * *"}, {"input": "9 4\n 56 60 4\n 33 37 2\n 89 90 3\n 32 43 1\n 67 68 3\n 49 51 3\n 31 32 3\n 70 71 1\n 11 12 3", "output": "2"}]
When the minimum required number of recorders is x, print the value of x. * * *
s206220862
Runtime Error
p03504
Input is given from Standard Input in the following format: N C s_1 t_1 c_1 : s_N t_N c_N
def popcount(n): res=0 while n > 0: res += n%2; n /= 2 return res n=0 def init_seg(_n): n=1 while(n < _n) n *= 2 data=[0]*n datb=[0]*n def add(a,b,x,k,l,r): if a <=l and r <= b: data[k] += x else: datb[k] += (min(b,r) - max(a,l))*x add(a,b,x,2*k+1,l,(l+r)/2) add(a,b,x,2*k+2,(l+r)/2,r) def sum(a,b,k,l,r): if b <=l or r <=a: return 0 elif a <= l and r <= b: return data[k] * (r - l) + datb[k] else: res=(min(b,r) - max(a,l)) * data[k] res+=sum(a,b,2*k+1,l,(l+r)/2) res+=sum(a,b,2*k+2,(l+r)/2,r) return res init_seg(1e5) for i in range(n): add(i,i+1,0,0,0,n) N,C=map(int,input().split()) for i in range(N): s,t,c=map(int,input().split()) add(s,t,2**(c-1),0,0,n) res=0 for i in range(1:1e5): prev=sum(i-1,i,0,0,n) curr=sum(i,i+1,0,0,n) if prev == curr: res = max(res, popcount(curr)) else: res = max(res, popcount(curr | prev)) print(res)
Statement Joisino is planning to record N TV programs with recorders. The TV can receive C channels numbered 1 through C. The i-th program that she wants to record will be broadcast from time s_i to time t_i (including time s_i but not t_i) on Channel c_i. Here, there will never be more than one program that are broadcast on the same channel at the same time. When the recorder is recording a channel from time S to time T (including time S but not T), it cannot record other channels from time S-0.5 to time T (including time S-0.5 but not T). Find the minimum number of recorders required to record the channels so that all the N programs are completely recorded.
[{"input": "3 2\n 1 7 2\n 7 8 1\n 8 12 1", "output": "2\n \n\nTwo recorders can record all the programs, for example, as follows:\n\n * With the first recorder, record Channel 2 from time 1 to time 7. The first program will be recorded. Note that this recorder will be unable to record other channels from time 0.5 to time 7.\n * With the second recorder, record Channel 1 from time 7 to time 12. The second and third programs will be recorded. Note that this recorder will be unable to record other channels from time 6.5 to time 12.\n\n* * *"}, {"input": "3 4\n 1 3 2\n 3 4 4\n 1 4 3", "output": "3\n \n\nThere may be a channel where there is no program to record.\n\n* * *"}, {"input": "9 4\n 56 60 4\n 33 37 2\n 89 90 3\n 32 43 1\n 67 68 3\n 49 51 3\n 31 32 3\n 70 71 1\n 11 12 3", "output": "2"}]
When the minimum required number of recorders is x, print the value of x. * * *
s737998249
Runtime Error
p03504
Input is given from Standard Input in the following format: N C s_1 t_1 c_1 : s_N t_N c_N
import numpy as np N, C = map(int,input().split()) T1 = [[] for _ in range(C)] for _ in range(N): s, t, c = map(int,input().split()) T1[c-1].append([s,t]) for i in range(C): T1[i].sort() T2 = [[] for _ in range(C)] for i in range(C): for s, t in T1[i]: if len(T2[i]) != 0 and T2[i][-1][1] == s: T2[i][-1][1] = t else: T2[i].append([s,t]) L = np.zeros(10 ** 5 + 1, int) for i in range(C): for time in T2[i]: L[time[0]-1] += 1a L[time[1]+1] -= 1 ans = L.cumsum().max() print(ans)
Statement Joisino is planning to record N TV programs with recorders. The TV can receive C channels numbered 1 through C. The i-th program that she wants to record will be broadcast from time s_i to time t_i (including time s_i but not t_i) on Channel c_i. Here, there will never be more than one program that are broadcast on the same channel at the same time. When the recorder is recording a channel from time S to time T (including time S but not T), it cannot record other channels from time S-0.5 to time T (including time S-0.5 but not T). Find the minimum number of recorders required to record the channels so that all the N programs are completely recorded.
[{"input": "3 2\n 1 7 2\n 7 8 1\n 8 12 1", "output": "2\n \n\nTwo recorders can record all the programs, for example, as follows:\n\n * With the first recorder, record Channel 2 from time 1 to time 7. The first program will be recorded. Note that this recorder will be unable to record other channels from time 0.5 to time 7.\n * With the second recorder, record Channel 1 from time 7 to time 12. The second and third programs will be recorded. Note that this recorder will be unable to record other channels from time 6.5 to time 12.\n\n* * *"}, {"input": "3 4\n 1 3 2\n 3 4 4\n 1 4 3", "output": "3\n \n\nThere may be a channel where there is no program to record.\n\n* * *"}, {"input": "9 4\n 56 60 4\n 33 37 2\n 89 90 3\n 32 43 1\n 67 68 3\n 49 51 3\n 31 32 3\n 70 71 1\n 11 12 3", "output": "2"}]
When the minimum required number of recorders is x, print the value of x. * * *
s866239343
Runtime Error
p03504
Input is given from Standard Input in the following format: N C s_1 t_1 c_1 : s_N t_N c_N
N, C = tuple(map(int, input().split())) events = [] tmax = 0 for i in range(N): s, t, c = map(int, input().split()) start = (s-0.5, 1) end = (t, 0) events.append(start) events.append(end) if tmax < t: tmax = t events.sort() idx = 0 cnt = 0 res = 0 events.append((0,-1)) for t in range(tmax + 1): while events[idx][0] <= t: event = events[idx] if event[1] == 1: cnt += 1 if res < cnt: res = cnt elif event[1] == 0: cnt -= 1 else: break idx += 1 print(res)
Statement Joisino is planning to record N TV programs with recorders. The TV can receive C channels numbered 1 through C. The i-th program that she wants to record will be broadcast from time s_i to time t_i (including time s_i but not t_i) on Channel c_i. Here, there will never be more than one program that are broadcast on the same channel at the same time. When the recorder is recording a channel from time S to time T (including time S but not T), it cannot record other channels from time S-0.5 to time T (including time S-0.5 but not T). Find the minimum number of recorders required to record the channels so that all the N programs are completely recorded.
[{"input": "3 2\n 1 7 2\n 7 8 1\n 8 12 1", "output": "2\n \n\nTwo recorders can record all the programs, for example, as follows:\n\n * With the first recorder, record Channel 2 from time 1 to time 7. The first program will be recorded. Note that this recorder will be unable to record other channels from time 0.5 to time 7.\n * With the second recorder, record Channel 1 from time 7 to time 12. The second and third programs will be recorded. Note that this recorder will be unable to record other channels from time 6.5 to time 12.\n\n* * *"}, {"input": "3 4\n 1 3 2\n 3 4 4\n 1 4 3", "output": "3\n \n\nThere may be a channel where there is no program to record.\n\n* * *"}, {"input": "9 4\n 56 60 4\n 33 37 2\n 89 90 3\n 32 43 1\n 67 68 3\n 49 51 3\n 31 32 3\n 70 71 1\n 11 12 3", "output": "2"}]
When the minimum required number of recorders is x, print the value of x. * * *
s618807423
Runtime Error
p03504
Input is given from Standard Input in the following format: N C s_1 t_1 c_1 : s_N t_N c_N
N,C=map(int,input().split()) chan = '' max1 = 0 for x in range(C): chan = chan + '0' reserv = {} for i in range(N): tmp = input().split() s,t,c=int(tmp[0]),int(tmp[1]),int(tmp[2]) for j in range(s,t+1): if j in reserv: work = list(reserv[j]) max1 = max(max1,1 + reserv[j].count('1')) else: max1 = max(max1,1) work = list(chan) work[(c-1)] = '1' reserv[j] = "".join(work) print(max1)
Statement Joisino is planning to record N TV programs with recorders. The TV can receive C channels numbered 1 through C. The i-th program that she wants to record will be broadcast from time s_i to time t_i (including time s_i but not t_i) on Channel c_i. Here, there will never be more than one program that are broadcast on the same channel at the same time. When the recorder is recording a channel from time S to time T (including time S but not T), it cannot record other channels from time S-0.5 to time T (including time S-0.5 but not T). Find the minimum number of recorders required to record the channels so that all the N programs are completely recorded.
[{"input": "3 2\n 1 7 2\n 7 8 1\n 8 12 1", "output": "2\n \n\nTwo recorders can record all the programs, for example, as follows:\n\n * With the first recorder, record Channel 2 from time 1 to time 7. The first program will be recorded. Note that this recorder will be unable to record other channels from time 0.5 to time 7.\n * With the second recorder, record Channel 1 from time 7 to time 12. The second and third programs will be recorded. Note that this recorder will be unable to record other channels from time 6.5 to time 12.\n\n* * *"}, {"input": "3 4\n 1 3 2\n 3 4 4\n 1 4 3", "output": "3\n \n\nThere may be a channel where there is no program to record.\n\n* * *"}, {"input": "9 4\n 56 60 4\n 33 37 2\n 89 90 3\n 32 43 1\n 67 68 3\n 49 51 3\n 31 32 3\n 70 71 1\n 11 12 3", "output": "2"}]
When the minimum required number of recorders is x, print the value of x. * * *
s601368882
Accepted
p03504
Input is given from Standard Input in the following format: N C s_1 t_1 c_1 : s_N t_N c_N
n, c = map(int, input().split()) chan = [[] for _ in range(c)] for _ in range(n): s, t, sc = map(int, input().split()) sc -= 1 chan[sc].append((s, t)) for i in range(c): chan[i].sort() # print(chan) for i in range(c): lis = [] if len(chan[i]) == 1: lis.append(chan[i][0][0]) lis.append(chan[i][0][1]) elif len(chan[i]) >= 2: lis.append(chan[i][0][0]) for j in range(len(chan[i]) - 1): if chan[i][j][1] != chan[i][j + 1][0]: lis.append(chan[i][j][1]) lis.append(chan[i][j + 1][0]) lis.append(chan[i][j + 1][1]) chan[i] = lis # print(chan) accum = [0] * (10**5 + 2) for i in range(c): for j in range(0, len(chan[i]) - 1, 2): accum[chan[i][j]] += 1 accum[chan[i][j + 1] + 1] -= 1 for i in range(10**5 + 1): accum[i + 1] += accum[i] # print(accum) print(max(accum))
Statement Joisino is planning to record N TV programs with recorders. The TV can receive C channels numbered 1 through C. The i-th program that she wants to record will be broadcast from time s_i to time t_i (including time s_i but not t_i) on Channel c_i. Here, there will never be more than one program that are broadcast on the same channel at the same time. When the recorder is recording a channel from time S to time T (including time S but not T), it cannot record other channels from time S-0.5 to time T (including time S-0.5 but not T). Find the minimum number of recorders required to record the channels so that all the N programs are completely recorded.
[{"input": "3 2\n 1 7 2\n 7 8 1\n 8 12 1", "output": "2\n \n\nTwo recorders can record all the programs, for example, as follows:\n\n * With the first recorder, record Channel 2 from time 1 to time 7. The first program will be recorded. Note that this recorder will be unable to record other channels from time 0.5 to time 7.\n * With the second recorder, record Channel 1 from time 7 to time 12. The second and third programs will be recorded. Note that this recorder will be unable to record other channels from time 6.5 to time 12.\n\n* * *"}, {"input": "3 4\n 1 3 2\n 3 4 4\n 1 4 3", "output": "3\n \n\nThere may be a channel where there is no program to record.\n\n* * *"}, {"input": "9 4\n 56 60 4\n 33 37 2\n 89 90 3\n 32 43 1\n 67 68 3\n 49 51 3\n 31 32 3\n 70 71 1\n 11 12 3", "output": "2"}]
When the minimum required number of recorders is x, print the value of x. * * *
s801524256
Accepted
p03504
Input is given from Standard Input in the following format: N C s_1 t_1 c_1 : s_N t_N c_N
# -*- coding: utf-8 -*- import sys from itertools import accumulate 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, M = MAP() C = [[] for i in range(M)] for i in range(N): l, r, c = MAP() c -= 1 C[c].append((l, r)) # 同チャンネルで連続する区間をまとめる LR = [] for i in range(M): if C[i]: C[i].sort() LR.append(C[i][0]) for j in range(1, len(C[i])): l1, r1 = C[i][j - 1] l2, r2 = C[i][j] if r1 == l2: LR.pop() LR.append((l1, r2)) # 3連続以上を考慮して更新 C[i][j] = (l1, r2) else: LR.append((l2, r2)) # いもす法 MAX = 10**5 + 7 imos = [0] * MAX for l, r in LR: imos[l - 1] += 1 imos[r] -= 1 imos = list(accumulate(imos)) print(max(imos))
Statement Joisino is planning to record N TV programs with recorders. The TV can receive C channels numbered 1 through C. The i-th program that she wants to record will be broadcast from time s_i to time t_i (including time s_i but not t_i) on Channel c_i. Here, there will never be more than one program that are broadcast on the same channel at the same time. When the recorder is recording a channel from time S to time T (including time S but not T), it cannot record other channels from time S-0.5 to time T (including time S-0.5 but not T). Find the minimum number of recorders required to record the channels so that all the N programs are completely recorded.
[{"input": "3 2\n 1 7 2\n 7 8 1\n 8 12 1", "output": "2\n \n\nTwo recorders can record all the programs, for example, as follows:\n\n * With the first recorder, record Channel 2 from time 1 to time 7. The first program will be recorded. Note that this recorder will be unable to record other channels from time 0.5 to time 7.\n * With the second recorder, record Channel 1 from time 7 to time 12. The second and third programs will be recorded. Note that this recorder will be unable to record other channels from time 6.5 to time 12.\n\n* * *"}, {"input": "3 4\n 1 3 2\n 3 4 4\n 1 4 3", "output": "3\n \n\nThere may be a channel where there is no program to record.\n\n* * *"}, {"input": "9 4\n 56 60 4\n 33 37 2\n 89 90 3\n 32 43 1\n 67 68 3\n 49 51 3\n 31 32 3\n 70 71 1\n 11 12 3", "output": "2"}]
When the minimum required number of recorders is x, print the value of x. * * *
s676927512
Accepted
p03504
Input is given from Standard Input in the following format: N C s_1 t_1 c_1 : s_N t_N c_N
import sys, queue, math, copy, itertools, bisect, collections, heapq sys.setrecursionlimit(10**7) INF = 10**18 MOD = 10**9 + 7 LI = lambda: [int(x) for x in sys.stdin.readline().split()] NI = lambda: int(sys.stdin.readline()) N, C = LI() p = [[(0, 0)] for _ in range(C + 1)] for _ in range(N): s, t, c = LI() p[c].append((s, t)) im = [0 for _ in range(10**5 + 1)] for x in p: x.sort() for i in range(1, len(x)): s, t = x[i] if x[i - 1][1] < s: s -= 1 im[s] += 1 im[t] -= 1 ans = 0 tm = 0 for t in im: tm += t ans = max(ans, tm) print(ans)
Statement Joisino is planning to record N TV programs with recorders. The TV can receive C channels numbered 1 through C. The i-th program that she wants to record will be broadcast from time s_i to time t_i (including time s_i but not t_i) on Channel c_i. Here, there will never be more than one program that are broadcast on the same channel at the same time. When the recorder is recording a channel from time S to time T (including time S but not T), it cannot record other channels from time S-0.5 to time T (including time S-0.5 but not T). Find the minimum number of recorders required to record the channels so that all the N programs are completely recorded.
[{"input": "3 2\n 1 7 2\n 7 8 1\n 8 12 1", "output": "2\n \n\nTwo recorders can record all the programs, for example, as follows:\n\n * With the first recorder, record Channel 2 from time 1 to time 7. The first program will be recorded. Note that this recorder will be unable to record other channels from time 0.5 to time 7.\n * With the second recorder, record Channel 1 from time 7 to time 12. The second and third programs will be recorded. Note that this recorder will be unable to record other channels from time 6.5 to time 12.\n\n* * *"}, {"input": "3 4\n 1 3 2\n 3 4 4\n 1 4 3", "output": "3\n \n\nThere may be a channel where there is no program to record.\n\n* * *"}, {"input": "9 4\n 56 60 4\n 33 37 2\n 89 90 3\n 32 43 1\n 67 68 3\n 49 51 3\n 31 32 3\n 70 71 1\n 11 12 3", "output": "2"}]
When the minimum required number of recorders is x, print the value of x. * * *
s337711727
Accepted
p03504
Input is given from Standard Input in the following format: N C s_1 t_1 c_1 : s_N t_N c_N
import sys import math from collections import defaultdict sys.setrecursionlimit(10**7) def input(): return sys.stdin.readline()[:-1] mod = 10**9 + 7 def I(): return int(input()) def II(): return map(int, input().split()) def III(): return list(map(int, input().split())) def Line(N, num): if N <= 0: return [[] for _ in range(num)] elif num == 1: return [I() for _ in range(N)] else: read_all = [tuple(II()) for _ in range(N)] return map(list, zip(*read_all)) ################# # heapq import heapq 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) class Heapq: def __init__(self, arr, desc=False): if desc: for i in range(len(arr)): arr[i] = Reverse(arr[i]) self.desc = desc self.hq = arr heapq.heapify(self.hq) def pop(self): if self.desc: return heapq.heappop(self.hq).val else: return heapq.heappop(self.hq) def push(self, a): if self.desc: heapq.heappush(self.hq, Reverse(a)) else: heapq.heappush(self.hq, a) def top(self): if self.desc: return self.hq[0].val else: return self.hq[0] from operator import itemgetter def index_sort(A): A_sort = sorted(enumerate(A), key=itemgetter(1)) index = [a[0] for a in A_sort] sorted_A = [a[1] for a in A_sort] return index, sorted_A N, C = II() s, t, c = Line(N, 3) # 同じチャンネルで,空き時間なしで番組が続くときはまとめて録画する new_s = [] new_t = [] tl = [[] for _ in range(C)] for i in range(N): tl[c[i] - 1].append((s[i], t[i])) for j in range(C): if not tl[j]: continue tl[j].sort(key=itemgetter(0)) sj = [] tj = [] start, last = tl[j][0][0], tl[j][0][1] for i in range(1, len(tl[j])): if tl[j][i][0] != last: sj.append(start) tj.append(last) start = tl[j][i][0] last = tl[j][i][1] else: last = tl[j][i][1] sj.append(start) tj.append(last) new_s.extend(sj) new_t.extend(tj) index, _ = index_sort(new_s) s = [new_s[i] for i in index] t = [new_t[i] for i in index] h = Heapq([10**6]) ans = 0 for i in range(len(s)): if h.top() < s[i]: h.pop() h.push(t[i]) else: h.push(t[i]) ans += 1 print(ans)
Statement Joisino is planning to record N TV programs with recorders. The TV can receive C channels numbered 1 through C. The i-th program that she wants to record will be broadcast from time s_i to time t_i (including time s_i but not t_i) on Channel c_i. Here, there will never be more than one program that are broadcast on the same channel at the same time. When the recorder is recording a channel from time S to time T (including time S but not T), it cannot record other channels from time S-0.5 to time T (including time S-0.5 but not T). Find the minimum number of recorders required to record the channels so that all the N programs are completely recorded.
[{"input": "3 2\n 1 7 2\n 7 8 1\n 8 12 1", "output": "2\n \n\nTwo recorders can record all the programs, for example, as follows:\n\n * With the first recorder, record Channel 2 from time 1 to time 7. The first program will be recorded. Note that this recorder will be unable to record other channels from time 0.5 to time 7.\n * With the second recorder, record Channel 1 from time 7 to time 12. The second and third programs will be recorded. Note that this recorder will be unable to record other channels from time 6.5 to time 12.\n\n* * *"}, {"input": "3 4\n 1 3 2\n 3 4 4\n 1 4 3", "output": "3\n \n\nThere may be a channel where there is no program to record.\n\n* * *"}, {"input": "9 4\n 56 60 4\n 33 37 2\n 89 90 3\n 32 43 1\n 67 68 3\n 49 51 3\n 31 32 3\n 70 71 1\n 11 12 3", "output": "2"}]
When the minimum required number of recorders is x, print the value of x. * * *
s973594749
Accepted
p03504
Input is given from Standard Input in the following format: N C s_1 t_1 c_1 : s_N t_N c_N
import sys from io import StringIO import unittest from itertools import accumulate def resolve(): end = 100000 input = sys.stdin.readline N, C = map(int, input().rstrip().split()) S = [list(map(int, input().rstrip().split())) for _ in range(N)] l = [[0 for _ in range(C)] for __ in range(2 * end)] for i in range(N): l[S[i][0] * 2 - 1][S[i][2] - 1] += 1 if S[i][1] != end: l[S[i][1] * 2 + 1][S[i][2] - 1] -= 1 """ ans=0 npl=np.array(l) for i in range(C): snpl=npl[:,i] buf=list(snpl) asum = list(accumulate(buf)) M=max(asum) ans=max(ans,M) """ asum = [0 for __ in range(2 * end)] for i in range(2 * end): # 列(C)で和を取る for j in range(C): asum[i] += l[i][j] asum2 = list(accumulate(asum)) ans = max(asum2) ans = min(ans, C) print(int(ans)) class TestClass(unittest.TestCase): def assertIO(self, input, output): stdout, stdin = sys.stdout, sys.stdin sys.stdout, sys.stdin = StringIO(), StringIO(input) resolve() sys.stdout.seek(0) out = sys.stdout.read()[:-1] sys.stdout, sys.stdin = stdout, stdin self.assertEqual(out, output) def test_入力例_1(self): input = """3 2 1 7 2 7 8 1 8 12 1""" output = """2""" self.assertIO(input, output) def test_入力例_2(self): input = """3 4 1 3 2 3 4 4 1 4 3""" output = """3""" self.assertIO(input, output) def test_入力例_3(self): input = """9 4 56 60 4 33 37 2 89 90 3 32 43 1 67 68 3 49 51 3 31 32 3 70 71 1 11 12 3""" output = """2""" self.assertIO(input, output) if __name__ == "__main__": # unittest.main() resolve()
Statement Joisino is planning to record N TV programs with recorders. The TV can receive C channels numbered 1 through C. The i-th program that she wants to record will be broadcast from time s_i to time t_i (including time s_i but not t_i) on Channel c_i. Here, there will never be more than one program that are broadcast on the same channel at the same time. When the recorder is recording a channel from time S to time T (including time S but not T), it cannot record other channels from time S-0.5 to time T (including time S-0.5 but not T). Find the minimum number of recorders required to record the channels so that all the N programs are completely recorded.
[{"input": "3 2\n 1 7 2\n 7 8 1\n 8 12 1", "output": "2\n \n\nTwo recorders can record all the programs, for example, as follows:\n\n * With the first recorder, record Channel 2 from time 1 to time 7. The first program will be recorded. Note that this recorder will be unable to record other channels from time 0.5 to time 7.\n * With the second recorder, record Channel 1 from time 7 to time 12. The second and third programs will be recorded. Note that this recorder will be unable to record other channels from time 6.5 to time 12.\n\n* * *"}, {"input": "3 4\n 1 3 2\n 3 4 4\n 1 4 3", "output": "3\n \n\nThere may be a channel where there is no program to record.\n\n* * *"}, {"input": "9 4\n 56 60 4\n 33 37 2\n 89 90 3\n 32 43 1\n 67 68 3\n 49 51 3\n 31 32 3\n 70 71 1\n 11 12 3", "output": "2"}]
When the minimum required number of recorders is x, print the value of x. * * *
s094884997
Accepted
p03504
Input is given from Standard Input in the following format: N C s_1 t_1 c_1 : s_N t_N c_N
n, c = map(int, input().split()) l = [list() for _ in range(c + 1)] for _ in range(n): s, t, ch = map(int, input().split()) l[ch].append((s, t)) al = list() for x in l: x.sort() for i in range(c + 1): if l[i] == []: continue t = list() for j in range(len(l[i]) - 1): if l[i][j][1] == l[i][j + 1][0]: l[i][j + 1] = (l[i][j][0], l[i][j + 1][1]) else: t.append(l[i][j]) t.append(l[i][-1]) al += t tl = [0] * (10**5 + 10) for s, t in al: tl[s] += 1 tl[t + 1] -= 1 for i in range(10**5 + 9): tl[i + 1] += tl[i] print(max(tl))
Statement Joisino is planning to record N TV programs with recorders. The TV can receive C channels numbered 1 through C. The i-th program that she wants to record will be broadcast from time s_i to time t_i (including time s_i but not t_i) on Channel c_i. Here, there will never be more than one program that are broadcast on the same channel at the same time. When the recorder is recording a channel from time S to time T (including time S but not T), it cannot record other channels from time S-0.5 to time T (including time S-0.5 but not T). Find the minimum number of recorders required to record the channels so that all the N programs are completely recorded.
[{"input": "3 2\n 1 7 2\n 7 8 1\n 8 12 1", "output": "2\n \n\nTwo recorders can record all the programs, for example, as follows:\n\n * With the first recorder, record Channel 2 from time 1 to time 7. The first program will be recorded. Note that this recorder will be unable to record other channels from time 0.5 to time 7.\n * With the second recorder, record Channel 1 from time 7 to time 12. The second and third programs will be recorded. Note that this recorder will be unable to record other channels from time 6.5 to time 12.\n\n* * *"}, {"input": "3 4\n 1 3 2\n 3 4 4\n 1 4 3", "output": "3\n \n\nThere may be a channel where there is no program to record.\n\n* * *"}, {"input": "9 4\n 56 60 4\n 33 37 2\n 89 90 3\n 32 43 1\n 67 68 3\n 49 51 3\n 31 32 3\n 70 71 1\n 11 12 3", "output": "2"}]
When the minimum required number of recorders is x, print the value of x. * * *
s438304497
Wrong Answer
p03504
Input is given from Standard Input in the following format: N C s_1 t_1 c_1 : s_N t_N c_N
n, c = map(int, input().split()) s = [0] * n t = [0] * n for i in range(n): s[i], t[i], c = map(int, input().split()) s.sort() t.sort() j = -1 m = 0 k = 0 for x in s: k += 1 while t[j + 1] + 1 <= x: j += 1 k -= 1 m = max(m, k) print(m)
Statement Joisino is planning to record N TV programs with recorders. The TV can receive C channels numbered 1 through C. The i-th program that she wants to record will be broadcast from time s_i to time t_i (including time s_i but not t_i) on Channel c_i. Here, there will never be more than one program that are broadcast on the same channel at the same time. When the recorder is recording a channel from time S to time T (including time S but not T), it cannot record other channels from time S-0.5 to time T (including time S-0.5 but not T). Find the minimum number of recorders required to record the channels so that all the N programs are completely recorded.
[{"input": "3 2\n 1 7 2\n 7 8 1\n 8 12 1", "output": "2\n \n\nTwo recorders can record all the programs, for example, as follows:\n\n * With the first recorder, record Channel 2 from time 1 to time 7. The first program will be recorded. Note that this recorder will be unable to record other channels from time 0.5 to time 7.\n * With the second recorder, record Channel 1 from time 7 to time 12. The second and third programs will be recorded. Note that this recorder will be unable to record other channels from time 6.5 to time 12.\n\n* * *"}, {"input": "3 4\n 1 3 2\n 3 4 4\n 1 4 3", "output": "3\n \n\nThere may be a channel where there is no program to record.\n\n* * *"}, {"input": "9 4\n 56 60 4\n 33 37 2\n 89 90 3\n 32 43 1\n 67 68 3\n 49 51 3\n 31 32 3\n 70 71 1\n 11 12 3", "output": "2"}]
When the minimum required number of recorders is x, print the value of x. * * *
s180001957
Wrong Answer
p03504
Input is given from Standard Input in the following format: N C s_1 t_1 c_1 : s_N t_N c_N
A, B = list(map(int, input().split())) l = [0] * 100001 for i in range(A): X, Y, Z = list(map(int, input().split())) for j in range(X - 1, Y): l[j] += 1 print(max(l))
Statement Joisino is planning to record N TV programs with recorders. The TV can receive C channels numbered 1 through C. The i-th program that she wants to record will be broadcast from time s_i to time t_i (including time s_i but not t_i) on Channel c_i. Here, there will never be more than one program that are broadcast on the same channel at the same time. When the recorder is recording a channel from time S to time T (including time S but not T), it cannot record other channels from time S-0.5 to time T (including time S-0.5 but not T). Find the minimum number of recorders required to record the channels so that all the N programs are completely recorded.
[{"input": "3 2\n 1 7 2\n 7 8 1\n 8 12 1", "output": "2\n \n\nTwo recorders can record all the programs, for example, as follows:\n\n * With the first recorder, record Channel 2 from time 1 to time 7. The first program will be recorded. Note that this recorder will be unable to record other channels from time 0.5 to time 7.\n * With the second recorder, record Channel 1 from time 7 to time 12. The second and third programs will be recorded. Note that this recorder will be unable to record other channels from time 6.5 to time 12.\n\n* * *"}, {"input": "3 4\n 1 3 2\n 3 4 4\n 1 4 3", "output": "3\n \n\nThere may be a channel where there is no program to record.\n\n* * *"}, {"input": "9 4\n 56 60 4\n 33 37 2\n 89 90 3\n 32 43 1\n 67 68 3\n 49 51 3\n 31 32 3\n 70 71 1\n 11 12 3", "output": "2"}]
When the minimum required number of recorders is x, print the value of x. * * *
s300092845
Wrong Answer
p03504
Input is given from Standard Input in the following format: N C s_1 t_1 c_1 : s_N t_N c_N
n, c = map(int, input().split()) s = [set() for _ in range(c)] t = [0] * (200007) for i in range(n): a, b, c = map(int, input().split()) if a in s[c - 1]: a += 1 s[c - 1].add(b) a *= 2 b *= 2 t[a - 1] += 1 t[b + 1] -= 1 for i in range(1, 200007): t[i] += t[i - 1] print(max(t))
Statement Joisino is planning to record N TV programs with recorders. The TV can receive C channels numbered 1 through C. The i-th program that she wants to record will be broadcast from time s_i to time t_i (including time s_i but not t_i) on Channel c_i. Here, there will never be more than one program that are broadcast on the same channel at the same time. When the recorder is recording a channel from time S to time T (including time S but not T), it cannot record other channels from time S-0.5 to time T (including time S-0.5 but not T). Find the minimum number of recorders required to record the channels so that all the N programs are completely recorded.
[{"input": "3 2\n 1 7 2\n 7 8 1\n 8 12 1", "output": "2\n \n\nTwo recorders can record all the programs, for example, as follows:\n\n * With the first recorder, record Channel 2 from time 1 to time 7. The first program will be recorded. Note that this recorder will be unable to record other channels from time 0.5 to time 7.\n * With the second recorder, record Channel 1 from time 7 to time 12. The second and third programs will be recorded. Note that this recorder will be unable to record other channels from time 6.5 to time 12.\n\n* * *"}, {"input": "3 4\n 1 3 2\n 3 4 4\n 1 4 3", "output": "3\n \n\nThere may be a channel where there is no program to record.\n\n* * *"}, {"input": "9 4\n 56 60 4\n 33 37 2\n 89 90 3\n 32 43 1\n 67 68 3\n 49 51 3\n 31 32 3\n 70 71 1\n 11 12 3", "output": "2"}]
When the minimum required number of recorders is x, print the value of x. * * *
s272919246
Accepted
p03504
Input is given from Standard Input in the following format: N C s_1 t_1 c_1 : s_N t_N c_N
import heapq N, C, *STC = [int(_) for _ in open(0).read().split()] STC = [(s, t, c) for s, t, c in zip(STC[::3], STC[1::3], STC[2::3])] STC.sort() # もしcを映しているテレビがあるならこれにしてしまうのが最適 # cを映しているテレビがないならすでに終わっているテレビのどれかを選ぶ # どのテレビもすでに映しているなら新しいテレビを追加する class SegmentTree: def __init__(self, array, f, ti): """ Parameters ---------- array : list to construct segment tree from f : func binary operation of the monoid ti : identity element of the monoid """ self.f = f self.ti = ti self.n = n = 2 ** (len(array).bit_length()) self.dat = dat = [ti] * n + array + [ti] * (n - len(array)) for i in range(n - 1, 0, -1): # build dat[i] = f(dat[i << 1], dat[i << 1 | 1]) def update(self, p, v): # set value at position p (0-indexed) f, n, dat = self.f, self.n, self.dat p += n dat[p] = v while p > 1: p >>= 1 dat[p] = f(dat[p << 1], dat[p << 1 | 1]) def operate_right(self, p, v): # apply operator from the right side f, n, dat = self.f, self.n, self.dat p += n dat[p] = f(dat[p], v) while p > 1: p >>= 1 dat[p] = f(dat[p << 1], dat[p << 1 | 1]) def operate_left(self, p, v): # apply operator from the left side f, n, dat = self.f, self.n, self.dat p += n dat[p] = f(v, dat[p]) while p > 1: p >>= 1 dat[p] = f(dat[p << 1], dat[p << 1 | 1]) def query(self, l, r): # result on interval [l, r) (0-indexed) f, ti, n, dat = self.f, self.ti, self.n, self.dat vl = vr = ti l += n r += n while l < r: if l & 1: vl = f(vl, dat[l]) l += 1 if r & 1: r -= 1 vr = f(dat[r], vr) l >>= 1 r >>= 1 return f(vl, vr) ti = (10**10, -(10**10)) st = SegmentTree([(10**10, i) for i in range(C + 1)], min, ti) ans = 0 for s, t, c in STC: if st.query(c, c + 1)[0] == 10**10: t2, c2 = st.query(1, C + 1) if t2 < s: st.update(c2, (10**10, c2)) else: ans += 1 st.update(c, (t, c)) print(ans)
Statement Joisino is planning to record N TV programs with recorders. The TV can receive C channels numbered 1 through C. The i-th program that she wants to record will be broadcast from time s_i to time t_i (including time s_i but not t_i) on Channel c_i. Here, there will never be more than one program that are broadcast on the same channel at the same time. When the recorder is recording a channel from time S to time T (including time S but not T), it cannot record other channels from time S-0.5 to time T (including time S-0.5 but not T). Find the minimum number of recorders required to record the channels so that all the N programs are completely recorded.
[{"input": "3 2\n 1 7 2\n 7 8 1\n 8 12 1", "output": "2\n \n\nTwo recorders can record all the programs, for example, as follows:\n\n * With the first recorder, record Channel 2 from time 1 to time 7. The first program will be recorded. Note that this recorder will be unable to record other channels from time 0.5 to time 7.\n * With the second recorder, record Channel 1 from time 7 to time 12. The second and third programs will be recorded. Note that this recorder will be unable to record other channels from time 6.5 to time 12.\n\n* * *"}, {"input": "3 4\n 1 3 2\n 3 4 4\n 1 4 3", "output": "3\n \n\nThere may be a channel where there is no program to record.\n\n* * *"}, {"input": "9 4\n 56 60 4\n 33 37 2\n 89 90 3\n 32 43 1\n 67 68 3\n 49 51 3\n 31 32 3\n 70 71 1\n 11 12 3", "output": "2"}]
When the minimum required number of recorders is x, print the value of x. * * *
s590514773
Wrong Answer
p03504
Input is given from Standard Input in the following format: N C s_1 t_1 c_1 : s_N t_N c_N
n, c = map(int, input().split(" ")) time = list() for i in range(0, n): s, t, c = map(int, input().split(" ")) time.append((s, t, c)) time_sorted = sorted(time, key=lambda x: (x[2], x[1])) time_joined = list() prev = None for current in time_sorted: if prev is None: prev = current elif prev[2] == current[2] and prev[1] == current[0]: prev = (prev[0], current[1], current[2]) else: time_joined.append(prev) prev = current # time_joined.append(prev) print(time_joined) time_list = list() for s, t, c in time_joined: time_list.append((s - 0.5, "s")) time_list.append((t, "t")) time_list_sorted = sorted(time_list, key=lambda x: x[0]) current = 0 ans = 0 for t, s in time_list_sorted: if s == "s": current += 1 ans = max(ans, current) else: current -= 1 print(ans)
Statement Joisino is planning to record N TV programs with recorders. The TV can receive C channels numbered 1 through C. The i-th program that she wants to record will be broadcast from time s_i to time t_i (including time s_i but not t_i) on Channel c_i. Here, there will never be more than one program that are broadcast on the same channel at the same time. When the recorder is recording a channel from time S to time T (including time S but not T), it cannot record other channels from time S-0.5 to time T (including time S-0.5 but not T). Find the minimum number of recorders required to record the channels so that all the N programs are completely recorded.
[{"input": "3 2\n 1 7 2\n 7 8 1\n 8 12 1", "output": "2\n \n\nTwo recorders can record all the programs, for example, as follows:\n\n * With the first recorder, record Channel 2 from time 1 to time 7. The first program will be recorded. Note that this recorder will be unable to record other channels from time 0.5 to time 7.\n * With the second recorder, record Channel 1 from time 7 to time 12. The second and third programs will be recorded. Note that this recorder will be unable to record other channels from time 6.5 to time 12.\n\n* * *"}, {"input": "3 4\n 1 3 2\n 3 4 4\n 1 4 3", "output": "3\n \n\nThere may be a channel where there is no program to record.\n\n* * *"}, {"input": "9 4\n 56 60 4\n 33 37 2\n 89 90 3\n 32 43 1\n 67 68 3\n 49 51 3\n 31 32 3\n 70 71 1\n 11 12 3", "output": "2"}]
When the minimum required number of recorders is x, print the value of x. * * *
s511951622
Accepted
p03504
Input is given from Standard Input in the following format: N C s_1 t_1 c_1 : s_N t_N c_N
def examA(): C1 = SI() C2 = SI() ans = "YES" if C1[0] != C2[2] or C1[1] != C2[1] or C1[2] != C2[0]: ans = "NO" print(ans) return def examB(): A, B, C, X, Y = LI() loop = max(X, Y) ans = inf for i in range(loop + 1): cost = i * 2 * C if X > i: cost += A * (X - i) if Y > i: cost += B * (Y - i) ans = min(ans, cost) print(ans) return def examC(): def gcd(x, y): if y == 0: return x while y != 0: x, y = y, x % y return x N, x = LI() X = LI() if N == 1: print(abs(X[0] - x)) return for i in range(N): X[i] = abs(X[i] - x) now = gcd(X[0], X[1]) for i in range(2, N): now = gcd(now, X[i]) ans = now print(ans) return def examD(): N = I() C = [LI() for _ in range(N - 1)] ans = [inf] * N for i in range(N): cur = 0 for j in range(i, N - 1): c, s, f = C[j] next = 0 if cur <= s: cur = s + c else: cur = (1 + (cur - 1) // f) * f + c ans[i] = cur for v in ans: print(v) return def examE(): class segment_: def __init__(self, A, n, segfunc, ide_ele=0): #####単位元######要設定0or1orinf self.ide_ele = ide_ele #################### self.num = 1 << (n - 1).bit_length() self.seg = [self.ide_ele] * 2 * self.num self.segfunc = segfunc # set_val for i in range(n): self.seg[i + self.num] = A[i] # built for i in range(self.num - 1, 0, -1): self.seg[i] = self.segfunc(self.seg[2 * i], self.seg[2 * i + 1]) def update(self, k, r): k += self.num self.seg[k] = r while k: k >>= 1 self.seg[k] = self.segfunc(self.seg[k * 2], self.seg[k * 2 + 1]) # 値xに1加算 def add(self, k, x=1): k += self.num self.seg[k] += x while k: k >>= 1 self.seg[k] = self.segfunc(self.seg[k * 2], self.seg[k * 2 + 1]) def query(self, p, q): # qは含まない if q < p: return self.ide_ele p += self.num q += self.num res = self.ide_ele while p < q: if p & 1 == 1: res = self.segfunc(res, self.seg[p]) p += 1 if q & 1 == 1: q -= 1 res = self.segfunc(res, self.seg[q]) p >>= 1 q >>= 1 return res N, C = LI() S = defaultdict(list) T = 0 for _ in range(N): s, t, c = LI() c -= 1 T = max(t, T) S[c].append([s, t]) Seg = segment_([0] * (T + 1), (T + 1), lambda a, b: a + b) for i in range(C): if not S[i]: continue S[i].sort() # print(S[i]) Seg.add(S[i][0][0]) Seg.add(S[i][0][1] + 1, -1) for j in range(1, len(S[i])): s, t = S[i][j] if S[i][j - 1][1] == s: Seg.add(s + 1) Seg.add(t + 1, -1) else: Seg.add(s) Seg.add(t + 1, -1) ans = 0 for j in range(T): cur = Seg.query(0, j + 1) ans = max(ans, cur) print(ans) return def examF(): class combination: # 素数のmod取るときのみ 速い def __init__(self, n, mod): self.n = n self.mod = mod self.fac = [1] * (n + 1) self.inv = [1] * (n + 1) for j in range(1, n + 1): self.fac[j] = self.fac[j - 1] * j % mod self.inv[n] = pow(self.fac[n], mod - 2, mod) for j in range(n - 1, -1, -1): self.inv[j] = self.inv[j + 1] * (j + 1) % mod def comb(self, n, r): if r > n or n < 0 or r < 0: return 0 return self.fac[n] * self.inv[n - r] * self.inv[r] % self.mod N, M, K = LI() B = N * M C = combination(B, mod) ans = 0 for i in range(N): for j in range(M): if i > 0 and j > 0: ans += (i + j) * (N - i) * (M - j) * C.comb(B - 2, K - 2) * 2 else: ans += (i + j) * (N - i) * (M - j) * C.comb(B - 2, K - 2) ans %= mod # print(ans) print(ans) return from decimal import Decimal as dec import sys, bisect, itertools, heapq, math, random from copy import deepcopy from heapq import heappop, heappush, heapify from collections import Counter, defaultdict, deque read = sys.stdin.buffer.read readline = sys.stdin.buffer.readline readlines = sys.stdin.buffer.readlines def I(): return int(input()) def LI(): return list(map(int, sys.stdin.readline().split())) def DI(): return dec(input()) def LDI(): return list(map(dec, sys.stdin.readline().split())) def LSI(): return list(map(str, sys.stdin.readline().split())) def LS(): return sys.stdin.readline().split() def SI(): return sys.stdin.readline().strip() global mod, mod2, inf, alphabet, _ep mod = 10**9 + 7 mod2 = 998244353 inf = 10**18 _ep = 10 ** (-12) alphabet = [chr(ord("a") + i) for i in range(26)] sys.setrecursionlimit(10**7) if __name__ == "__main__": examE() """ 142 12 9 1445 0 1 asd dfg hj o o aidn """
Statement Joisino is planning to record N TV programs with recorders. The TV can receive C channels numbered 1 through C. The i-th program that she wants to record will be broadcast from time s_i to time t_i (including time s_i but not t_i) on Channel c_i. Here, there will never be more than one program that are broadcast on the same channel at the same time. When the recorder is recording a channel from time S to time T (including time S but not T), it cannot record other channels from time S-0.5 to time T (including time S-0.5 but not T). Find the minimum number of recorders required to record the channels so that all the N programs are completely recorded.
[{"input": "3 2\n 1 7 2\n 7 8 1\n 8 12 1", "output": "2\n \n\nTwo recorders can record all the programs, for example, as follows:\n\n * With the first recorder, record Channel 2 from time 1 to time 7. The first program will be recorded. Note that this recorder will be unable to record other channels from time 0.5 to time 7.\n * With the second recorder, record Channel 1 from time 7 to time 12. The second and third programs will be recorded. Note that this recorder will be unable to record other channels from time 6.5 to time 12.\n\n* * *"}, {"input": "3 4\n 1 3 2\n 3 4 4\n 1 4 3", "output": "3\n \n\nThere may be a channel where there is no program to record.\n\n* * *"}, {"input": "9 4\n 56 60 4\n 33 37 2\n 89 90 3\n 32 43 1\n 67 68 3\n 49 51 3\n 31 32 3\n 70 71 1\n 11 12 3", "output": "2"}]
When the minimum required number of recorders is x, print the value of x. * * *
s322158778
Accepted
p03504
Input is given from Standard Input in the following format: N C s_1 t_1 c_1 : s_N t_N c_N
def submit(): n, c = map(int, input().split()) table_max = 10**5 table = [0 for _ in range(table_max + 1)] programs = [] for _ in range(n): s, t, c = map(int, input().split()) programs.append((s, t, c)) programs.sort(key=lambda x: (x[2], x[0])) program_merge = [programs[0]] last = programs[0] for p in programs[1:]: if last[2] == p[2] and last[1] == p[0]: program_merge.pop() program_merge.append((last[0], p[1], p[2])) else: program_merge.append(p) last = program_merge[-1] for s, t, _ in program_merge: table[s - 1] += 1 table[t] -= 1 curr_max = 0 for i in range(1, table_max + 1): table[i] += table[i - 1] if table[i] > curr_max: curr_max = table[i] print(curr_max) submit()
Statement Joisino is planning to record N TV programs with recorders. The TV can receive C channels numbered 1 through C. The i-th program that she wants to record will be broadcast from time s_i to time t_i (including time s_i but not t_i) on Channel c_i. Here, there will never be more than one program that are broadcast on the same channel at the same time. When the recorder is recording a channel from time S to time T (including time S but not T), it cannot record other channels from time S-0.5 to time T (including time S-0.5 but not T). Find the minimum number of recorders required to record the channels so that all the N programs are completely recorded.
[{"input": "3 2\n 1 7 2\n 7 8 1\n 8 12 1", "output": "2\n \n\nTwo recorders can record all the programs, for example, as follows:\n\n * With the first recorder, record Channel 2 from time 1 to time 7. The first program will be recorded. Note that this recorder will be unable to record other channels from time 0.5 to time 7.\n * With the second recorder, record Channel 1 from time 7 to time 12. The second and third programs will be recorded. Note that this recorder will be unable to record other channels from time 6.5 to time 12.\n\n* * *"}, {"input": "3 4\n 1 3 2\n 3 4 4\n 1 4 3", "output": "3\n \n\nThere may be a channel where there is no program to record.\n\n* * *"}, {"input": "9 4\n 56 60 4\n 33 37 2\n 89 90 3\n 32 43 1\n 67 68 3\n 49 51 3\n 31 32 3\n 70 71 1\n 11 12 3", "output": "2"}]
When the minimum required number of recorders is x, print the value of x. * * *
s293989482
Wrong Answer
p03504
Input is given from Standard Input in the following format: N C s_1 t_1 c_1 : s_N t_N c_N
import copy n, C = map(int, input().split()) stc = [list(map(int, input().split())) for _ in range(n)] li = [[] for _ in range(C)] li2 = [] for s, t, c in stc: li[c - 1].append((s, t)) # print(li) """ for i in range(C): if li[i]: li[i].sort() flag = False count = 0 for j in range(len(li[i])-1): if li[i][j][1] == li[i][j+1][0]: if flag: pass else: flag = True count = j else: if flag: flag = False li2.append((li[i][count][0]-0.5, li[i][j][1])) else: li2.append((li[i][j][0]-0.5, li[i][j][1])) if flag: flag = False li2.append((li[i][count][0]-0.5, li[i][-1][1])) else: li2.append((li[i][-1][0]-0.5, li[i][-1][1])) """ for i in range(C): if li[i]: li[i].sort() flag = False count = 0 count2 = 0 tmp = 0 li_tmp = [] while li[i]: # print(li[i]) for j in range(len(li[i]) - 1): if li[i][tmp][1] == li[i][j + 1][0]: if flag: tmp = j + 1 else: flag = True count = j tmp = j + 1 else: if flag: li_tmp.append((li[i][j + 1][0], li[i][j + 1][1])) else: li2.append((li[i][j][0] - 0.5, li[i][j][1])) if flag: flag = False li2.append((li[i][count][0] - 0.5, li[i][tmp][1])) else: li2.append((li[i][-1][0] - 0.5, li[i][-1][1])) li[i] = copy.copy(li_tmp) li_tmp = [] # print(li2) li2.sort(key=lambda x: x[1]) ans = 0 li3 = [] while li2: count = 0 ans += 1 for i in range(len(li2)): if li2[i][0] > count: count = li2[i][1] else: li3.append(li2[i]) li2 = copy.copy(li3) li3 = [] print(ans)
Statement Joisino is planning to record N TV programs with recorders. The TV can receive C channels numbered 1 through C. The i-th program that she wants to record will be broadcast from time s_i to time t_i (including time s_i but not t_i) on Channel c_i. Here, there will never be more than one program that are broadcast on the same channel at the same time. When the recorder is recording a channel from time S to time T (including time S but not T), it cannot record other channels from time S-0.5 to time T (including time S-0.5 but not T). Find the minimum number of recorders required to record the channels so that all the N programs are completely recorded.
[{"input": "3 2\n 1 7 2\n 7 8 1\n 8 12 1", "output": "2\n \n\nTwo recorders can record all the programs, for example, as follows:\n\n * With the first recorder, record Channel 2 from time 1 to time 7. The first program will be recorded. Note that this recorder will be unable to record other channels from time 0.5 to time 7.\n * With the second recorder, record Channel 1 from time 7 to time 12. The second and third programs will be recorded. Note that this recorder will be unable to record other channels from time 6.5 to time 12.\n\n* * *"}, {"input": "3 4\n 1 3 2\n 3 4 4\n 1 4 3", "output": "3\n \n\nThere may be a channel where there is no program to record.\n\n* * *"}, {"input": "9 4\n 56 60 4\n 33 37 2\n 89 90 3\n 32 43 1\n 67 68 3\n 49 51 3\n 31 32 3\n 70 71 1\n 11 12 3", "output": "2"}]
When the minimum required number of recorders is x, print the value of x. * * *
s005303357
Accepted
p03504
Input is given from Standard Input in the following format: N C s_1 t_1 c_1 : s_N t_N c_N
n, m = map(int, input().split()) arr = [list(map(int, input().split())) for _ in range(n)] arr.append([10**10, 10**10, 100]) arr = sorted(arr, key=lambda x: x[0]) arr = sorted(arr, key=lambda x: x[2]) job = [[] for _ in range(m + 1)] c = arr[0][2] ts = arr[0][0] tt = arr[0][1] for i in range(1, n + 1): if c != arr[i][2]: job[c].append([ts, tt]) ts = arr[i][0] tt = arr[i][1] c = arr[i][2] else: if tt == arr[i][0]: tt = arr[i][1] else: job[c].append([ts, tt]) ts = arr[i][0] tt = arr[i][1] cnt = [0] * (10**5 + 2) for tj in job: for ts, tt in tj: cnt[ts] += 1 cnt[tt + 1] -= 1 for i in range(1, 10**5 + 2): cnt[i] = cnt[i] + cnt[i - 1] print(max(cnt))
Statement Joisino is planning to record N TV programs with recorders. The TV can receive C channels numbered 1 through C. The i-th program that she wants to record will be broadcast from time s_i to time t_i (including time s_i but not t_i) on Channel c_i. Here, there will never be more than one program that are broadcast on the same channel at the same time. When the recorder is recording a channel from time S to time T (including time S but not T), it cannot record other channels from time S-0.5 to time T (including time S-0.5 but not T). Find the minimum number of recorders required to record the channels so that all the N programs are completely recorded.
[{"input": "3 2\n 1 7 2\n 7 8 1\n 8 12 1", "output": "2\n \n\nTwo recorders can record all the programs, for example, as follows:\n\n * With the first recorder, record Channel 2 from time 1 to time 7. The first program will be recorded. Note that this recorder will be unable to record other channels from time 0.5 to time 7.\n * With the second recorder, record Channel 1 from time 7 to time 12. The second and third programs will be recorded. Note that this recorder will be unable to record other channels from time 6.5 to time 12.\n\n* * *"}, {"input": "3 4\n 1 3 2\n 3 4 4\n 1 4 3", "output": "3\n \n\nThere may be a channel where there is no program to record.\n\n* * *"}, {"input": "9 4\n 56 60 4\n 33 37 2\n 89 90 3\n 32 43 1\n 67 68 3\n 49 51 3\n 31 32 3\n 70 71 1\n 11 12 3", "output": "2"}]
Print the sum of the scores, modulo 10^9 + 7. * * *
s125587100
Runtime Error
p03154
Input is given from Standard Input in the following format: H W K
mod = int(1e9) + 7 # <-- input modulo maxf = 10000100 # <-- input factional limitation def make_fact(n, k): tmp = n perm = [i for i in range(k)] L = [0 for _ in range(k)] for i in range(k): L[i] = tmp % (i + 1) tmp //= i + 1 LL = [0 for _ in range(k)] for i in range(k): LL[i] = perm[L[-i - 1]] for j in range(L[-i - 1] + 1, k): perm[j - 1] = perm[j] return LL def doubling(n, m, modulo=mod): y = 1 base = n tmp = m while tmp != 0: if tmp % 2 == 1: y *= base if modulo > 0: y %= modulo base *= base if modulo > 0: base %= modulo tmp //= 2 return y def inved(a, modulo=mod): x, y, u, v, k, l = 1, 0, 0, 1, a, modulo while l != 0: x, y, u, v = u, v, x - u * (k // l), y - v * (k // l) k, l = l, k % l return x % modulo fact = [1 for _ in range(maxf + 1)] invf = [1 for _ in range(maxf + 1)] for i in range(maxf): fact[i + 1] = (fact[i] * (i + 1)) % mod invf[-1] = inved(fact[-1]) for i in range(maxf, 0, -1): invf[i - 1] = (invf[i] * i) % mod def comb(n, k): return fact[n] * invf[n - k] * invf[k] % mod H, W, K = map(int, input().split()) S = ( ( ((K + 1) * (K + 2) * (2 * K + 3)) // 6 - H * (K + 1) * (K + 2) // 2 + H - 1 + K * (W + 1) ) * comb(H + W - 2, H - 1) % mod ) if H >= 2: S += (W + 1) * ((K + 1) * (K + 2) // 2 - 1) * comb(H + W - 2, H - 2) if W >= 2: S += (K * (K + 1) // 2 - K * (H - 1)) * comb(H + W - 2, H) print(S * invf[H + W - K] * fact[H] * fact[W] % mod)
Statement There is a rectangular sheet of paper with height H+1 and width W+1. We introduce an xy-coordinate system so that the four corners of the sheet are (0, 0), (W + 1, 0), (0, H + 1) and (W + 1, H + 1). This sheet can be cut along the lines x = 1,2,...,W and the lines y = 1,2,...,H. Consider a sequence of operations of length K where we choose K of these H + W lines and cut the sheet along those lines one by one in some order. Let the score of a cut be the number of pieces of paper that exist just after the cut. The score of a sequence of operations is the sum of the scores of all of the K cuts. Find the sum of the scores of all possible sequences of operations of length K. Since this value can be extremely large, print the number modulo 10^9 + 7.
[{"input": "2 1 2", "output": "34\n \n\nLet x_1, y_1 and y_2 denote the cuts along the lines x = 1, y = 1 and y = 2,\nrespectively. The six possible sequences of operations and the score of each\nof them are as follows:\n\n * y_1, y_2: 2 + 3 = 5\n * y_2, y_1: 2 + 3 = 5\n * y_1, x_1: 2 + 4 = 6\n * y_2, x_1: 2 + 4 = 6\n * x_1, y_1: 2 + 4 = 6\n * x_1, y_2: 2 + 4 = 6\n\nThe sum of these is 34.\n\n* * *"}, {"input": "30 40 50", "output": "616365902\n \n\nBe sure to print the sum modulo 10^9 + 7."}]
Print the sum of the scores, modulo 10^9 + 7. * * *
s085563335
Runtime Error
p03154
Input is given from Standard Input in the following format: H W K
N = list(map(int, input().split())) list0_9 = [0 for i in range(10)] for i in N: list0_9[i] += 1 if list0_9[1] == list0_9[2] == list0_9[7] == list0_9[9] == 1: print("YES") else: print("NO")
Statement There is a rectangular sheet of paper with height H+1 and width W+1. We introduce an xy-coordinate system so that the four corners of the sheet are (0, 0), (W + 1, 0), (0, H + 1) and (W + 1, H + 1). This sheet can be cut along the lines x = 1,2,...,W and the lines y = 1,2,...,H. Consider a sequence of operations of length K where we choose K of these H + W lines and cut the sheet along those lines one by one in some order. Let the score of a cut be the number of pieces of paper that exist just after the cut. The score of a sequence of operations is the sum of the scores of all of the K cuts. Find the sum of the scores of all possible sequences of operations of length K. Since this value can be extremely large, print the number modulo 10^9 + 7.
[{"input": "2 1 2", "output": "34\n \n\nLet x_1, y_1 and y_2 denote the cuts along the lines x = 1, y = 1 and y = 2,\nrespectively. The six possible sequences of operations and the score of each\nof them are as follows:\n\n * y_1, y_2: 2 + 3 = 5\n * y_2, y_1: 2 + 3 = 5\n * y_1, x_1: 2 + 4 = 6\n * y_2, x_1: 2 + 4 = 6\n * x_1, y_1: 2 + 4 = 6\n * x_1, y_2: 2 + 4 = 6\n\nThe sum of these is 34.\n\n* * *"}, {"input": "30 40 50", "output": "616365902\n \n\nBe sure to print the sum modulo 10^9 + 7."}]
Print the sum of the scores, modulo 10^9 + 7. * * *
s989307955
Runtime Error
p03154
Input is given from Standard Input in the following format: H W K
import sys from collections import defaultdict def calc5(all_nodes,H,W,K): for _ in range(K): next_nodes = defaultdict(int) for k,v in all_nodes.items(): if k[0]+1 <= H+1: k0 = k[0]+1 s = ((k0)*k[1]+k[2] ) next_nodes[(k0,k[1],s) ] += v * (H+1-k[0]) if k[1]+1 <= W+1: k1 = k[1]+1 s = ((k1)*k[0]+k[2] ) next_nodes[(k[0],k1,s) ] += v* (W+1-k[1]) all_nodes = next_nodes print( sum([ k[2]*v for k,v in all_nodes.items()])%(10**9+7) ) def main5(H,W,K): all_nodes = {} all_nodes[(1,1,0)] = 1 calc5(all_nodes,H,W,K) if __name__ == '__main__': # H,W,K = sys.argv[1:] tmp = input() H,W,K = tmp.split() main5(int(H),int(W),int(K))
Statement There is a rectangular sheet of paper with height H+1 and width W+1. We introduce an xy-coordinate system so that the four corners of the sheet are (0, 0), (W + 1, 0), (0, H + 1) and (W + 1, H + 1). This sheet can be cut along the lines x = 1,2,...,W and the lines y = 1,2,...,H. Consider a sequence of operations of length K where we choose K of these H + W lines and cut the sheet along those lines one by one in some order. Let the score of a cut be the number of pieces of paper that exist just after the cut. The score of a sequence of operations is the sum of the scores of all of the K cuts. Find the sum of the scores of all possible sequences of operations of length K. Since this value can be extremely large, print the number modulo 10^9 + 7.
[{"input": "2 1 2", "output": "34\n \n\nLet x_1, y_1 and y_2 denote the cuts along the lines x = 1, y = 1 and y = 2,\nrespectively. The six possible sequences of operations and the score of each\nof them are as follows:\n\n * y_1, y_2: 2 + 3 = 5\n * y_2, y_1: 2 + 3 = 5\n * y_1, x_1: 2 + 4 = 6\n * y_2, x_1: 2 + 4 = 6\n * x_1, y_1: 2 + 4 = 6\n * x_1, y_2: 2 + 4 = 6\n\nThe sum of these is 34.\n\n* * *"}, {"input": "30 40 50", "output": "616365902\n \n\nBe sure to print the sum modulo 10^9 + 7."}]
Print the sum of the scores, modulo 10^9 + 7. * * *
s776818045
Runtime Error
p03154
Input is given from Standard Input in the following format: H W K
import sys from itertools import permutations # import numpy as np def calc(H,W,K): s = 0 all_ele = [0] * H + [1] * W for perm in permutations(all_ele,K): s += each_calc(perm) print(s) return s def each_calc(perm): s = 0 nx = 1 ny = 1 for e in perm: if e==0: s += ny nx += 1 else: s += nx ny += 1 return s if __name__ == '__main__': H,W,K = sys.args[1:]
Statement There is a rectangular sheet of paper with height H+1 and width W+1. We introduce an xy-coordinate system so that the four corners of the sheet are (0, 0), (W + 1, 0), (0, H + 1) and (W + 1, H + 1). This sheet can be cut along the lines x = 1,2,...,W and the lines y = 1,2,...,H. Consider a sequence of operations of length K where we choose K of these H + W lines and cut the sheet along those lines one by one in some order. Let the score of a cut be the number of pieces of paper that exist just after the cut. The score of a sequence of operations is the sum of the scores of all of the K cuts. Find the sum of the scores of all possible sequences of operations of length K. Since this value can be extremely large, print the number modulo 10^9 + 7.
[{"input": "2 1 2", "output": "34\n \n\nLet x_1, y_1 and y_2 denote the cuts along the lines x = 1, y = 1 and y = 2,\nrespectively. The six possible sequences of operations and the score of each\nof them are as follows:\n\n * y_1, y_2: 2 + 3 = 5\n * y_2, y_1: 2 + 3 = 5\n * y_1, x_1: 2 + 4 = 6\n * y_2, x_1: 2 + 4 = 6\n * x_1, y_1: 2 + 4 = 6\n * x_1, y_2: 2 + 4 = 6\n\nThe sum of these is 34.\n\n* * *"}, {"input": "30 40 50", "output": "616365902\n \n\nBe sure to print the sum modulo 10^9 + 7."}]
Print the sum of the scores, modulo 10^9 + 7. * * *
s808277965
Wrong Answer
p03154
Input is given from Standard Input in the following format: H W K
import sys from collections import defaultdict def calc5(all_nodes, H, W, K): while K != 0: next_nodes = dict() for k, v in all_nodes.items(): if k[0] + 1 <= H + 1: k0 = k[0] + 1 s = (k[0] + 1) * k[1] + k[2] if (k0, k[1], s) in next_nodes: next_nodes[(k0, k[1], s)] += v * (H + 1 - k[0]) else: next_nodes[(k0, k[1], s)] = v * (H + 1 - k[0]) if k[1] + 1 <= W + 1: k1 = k[1] + 1 s = (k[1] + 1) * k[0] + k[2] if (k[0], k1, s) in next_nodes: next_nodes[(k[0], k1, s)] += v * (W + 1 - k[1]) else: next_nodes[(k[0], k1, s)] = v * (W + 1 - k[1]) all_nodes = next_nodes K -= 1 print(sum([k[2] * v for k, v in all_nodes.items()])) # a = ( sum([ k[2]*v for k,v in all_nodes.items()]) ) def main5(H, W, K): all_nodes = {} all_nodes[(1, 1, 0)] = 1 calc5(all_nodes, H, W, K) if __name__ == "__main__": # H,W,K = sys.argv[1:] tmp = input() H, W, K = tmp.split() main5(int(H), int(W), int(K))
Statement There is a rectangular sheet of paper with height H+1 and width W+1. We introduce an xy-coordinate system so that the four corners of the sheet are (0, 0), (W + 1, 0), (0, H + 1) and (W + 1, H + 1). This sheet can be cut along the lines x = 1,2,...,W and the lines y = 1,2,...,H. Consider a sequence of operations of length K where we choose K of these H + W lines and cut the sheet along those lines one by one in some order. Let the score of a cut be the number of pieces of paper that exist just after the cut. The score of a sequence of operations is the sum of the scores of all of the K cuts. Find the sum of the scores of all possible sequences of operations of length K. Since this value can be extremely large, print the number modulo 10^9 + 7.
[{"input": "2 1 2", "output": "34\n \n\nLet x_1, y_1 and y_2 denote the cuts along the lines x = 1, y = 1 and y = 2,\nrespectively. The six possible sequences of operations and the score of each\nof them are as follows:\n\n * y_1, y_2: 2 + 3 = 5\n * y_2, y_1: 2 + 3 = 5\n * y_1, x_1: 2 + 4 = 6\n * y_2, x_1: 2 + 4 = 6\n * x_1, y_1: 2 + 4 = 6\n * x_1, y_2: 2 + 4 = 6\n\nThe sum of these is 34.\n\n* * *"}, {"input": "30 40 50", "output": "616365902\n \n\nBe sure to print the sum modulo 10^9 + 7."}]
Print the sum of the scores, modulo 10^9 + 7. * * *
s454929542
Accepted
p03154
Input is given from Standard Input in the following format: H W K
h, w, k = map(int, input().split()) p, n = 10**9 + 7, h + w x = ( k + k * (k + 1) // 2 + k * (k - 1) * (k + 1) // 3 * h * w * pow(n * (n - 1), p - 2, p) ) for i in range(n, n - k, -1): x = x * i % p print(x)
Statement There is a rectangular sheet of paper with height H+1 and width W+1. We introduce an xy-coordinate system so that the four corners of the sheet are (0, 0), (W + 1, 0), (0, H + 1) and (W + 1, H + 1). This sheet can be cut along the lines x = 1,2,...,W and the lines y = 1,2,...,H. Consider a sequence of operations of length K where we choose K of these H + W lines and cut the sheet along those lines one by one in some order. Let the score of a cut be the number of pieces of paper that exist just after the cut. The score of a sequence of operations is the sum of the scores of all of the K cuts. Find the sum of the scores of all possible sequences of operations of length K. Since this value can be extremely large, print the number modulo 10^9 + 7.
[{"input": "2 1 2", "output": "34\n \n\nLet x_1, y_1 and y_2 denote the cuts along the lines x = 1, y = 1 and y = 2,\nrespectively. The six possible sequences of operations and the score of each\nof them are as follows:\n\n * y_1, y_2: 2 + 3 = 5\n * y_2, y_1: 2 + 3 = 5\n * y_1, x_1: 2 + 4 = 6\n * y_2, x_1: 2 + 4 = 6\n * x_1, y_1: 2 + 4 = 6\n * x_1, y_2: 2 + 4 = 6\n\nThe sum of these is 34.\n\n* * *"}, {"input": "30 40 50", "output": "616365902\n \n\nBe sure to print the sum modulo 10^9 + 7."}]
Print the maximum total values of the items in a line.
s606776013
Accepted
p02315
N W v1 w1 v2 w2 : vN wN The first line consists of the integers N and W. In the following lines, the value and weight of the i-th item are given.
import sys def s(): W=int(input().split()[1]) C=[0]*-~W for e in sys.stdin: v,w=map(int,e.split()) for i in range(W,w-1,-1): t=v+C[i-w] if t>C[i]:C[i]=t print(C[W]) s()
0-1 Knapsack Problem You have N items that you want to put them into a knapsack. Item i has value vi and weight wi. You want to find a subset of items to put such that: * The total value of the items is as large as possible. * The items have combined weight at most W, that is capacity of the knapsack. Find the maximum total value of items in the knapsack.
[{"input": "4 5\n 4 2\n 5 2\n 2 1\n 8 3", "output": "13"}, {"input": "2 20\n 5 9\n 4 10", "output": "9"}]
Print the maximum total values of the items in a line.
s383944975
Wrong Answer
p02315
N W v1 w1 v2 w2 : vN wN The first line consists of the integers N and W. In the following lines, the value and weight of the i-th item are given.
def main(): print(13) main()
0-1 Knapsack Problem You have N items that you want to put them into a knapsack. Item i has value vi and weight wi. You want to find a subset of items to put such that: * The total value of the items is as large as possible. * The items have combined weight at most W, that is capacity of the knapsack. Find the maximum total value of items in the knapsack.
[{"input": "4 5\n 4 2\n 5 2\n 2 1\n 8 3", "output": "13"}, {"input": "2 20\n 5 9\n 4 10", "output": "9"}]
Print the maximum total values of the items in a line.
s990805685
Accepted
p02315
N W v1 w1 v2 w2 : vN wN The first line consists of the integers N and W. In the following lines, the value and weight of the i-th item are given.
from typing import Callable class DynamicProgramming(object): table: list obj_coef: list sbj_coef: list def __init__(self, item_n: int, border: int): self.item_n = item_n self.border = border def __str__(self): return "\n".join(list(map(lambda l: " ".join(list(map(str, l))), self.table))) def __repr__(self): return ( "DynamicProgramming object:\n" + "item_n: " + str(self.item_n) + ", border: " + str(self.border) + "\n" + "table:\n" + self.__str__() ) def solve( self, obj_coef: list, sbj_coef: list, expr: Callable[[int, int], int], initializer=0, ) -> list: self.table = [ [initializer for _ in range(self.item_n + 1)] for _ in range(self.border + 1) ] if len(obj_coef) == self.item_n: # to 1-base obj_coef = [None] + obj_coef self.obj_coef = obj_coef if len(sbj_coef) == self.item_n: sbj_coef = [None] + sbj_coef self.sbj_coef = sbj_coef for weight_lim in range(1, self.border + 1): for item_idx in range(1, self.item_n + 1): self.table[weight_lim][item_idx] = expr(weight_lim, item_idx) return self.table def knapsack_expr(self, weight_lim: int, item_idx: int) -> int: res = self.table[weight_lim][item_idx - 1] if weight_lim - self.sbj_coef[item_idx] >= 0: res = max( res, self.table[weight_lim - self.sbj_coef[item_idx]][item_idx - 1] + self.obj_coef[item_idx], ) return res if __name__ == "__main__": N, W = map(int, input().split()) v, w = [], [] for i in range(N): buff = [int(j) for j in input().split()] v.append(buff[0]) w.append(buff[1]) dp = DynamicProgramming(N, W) print(dp.solve(v, w, dp.knapsack_expr)[W][N])
0-1 Knapsack Problem You have N items that you want to put them into a knapsack. Item i has value vi and weight wi. You want to find a subset of items to put such that: * The total value of the items is as large as possible. * The items have combined weight at most W, that is capacity of the knapsack. Find the maximum total value of items in the knapsack.
[{"input": "4 5\n 4 2\n 5 2\n 2 1\n 8 3", "output": "13"}, {"input": "2 20\n 5 9\n 4 10", "output": "9"}]
Print the maximum total values of the items in a line.
s568194843
Accepted
p02315
N W v1 w1 v2 w2 : vN wN The first line consists of the integers N and W. In the following lines, the value and weight of the i-th item are given.
if __name__ == "__main__": N,W = map(int,input().split(" ")) dp = [[0] * (W+1) for _ in range(N+1)] w_lis = [0] * N v_lis = [0] * N for i in range(N): v,w = map(int,input().split(" ")) w_lis[i] = w v_lis[i] = v for i in range(1,N+1): for w in range(0,W+1): if w >= w_lis[i-1]: dp[i][w] = max([dp[i-1][w - w_lis[i-1]] + v_lis[i-1],dp[i-1][w]]) else: dp[i][w] = dp[i-1][w] print(dp[N][W])
0-1 Knapsack Problem You have N items that you want to put them into a knapsack. Item i has value vi and weight wi. You want to find a subset of items to put such that: * The total value of the items is as large as possible. * The items have combined weight at most W, that is capacity of the knapsack. Find the maximum total value of items in the knapsack.
[{"input": "4 5\n 4 2\n 5 2\n 2 1\n 8 3", "output": "13"}, {"input": "2 20\n 5 9\n 4 10", "output": "9"}]
Print the maximum total values of the items in a line.
s597628251
Accepted
p02315
N W v1 w1 v2 w2 : vN wN The first line consists of the integers N and W. In the following lines, the value and weight of the i-th item are given.
N,W=map(int,input().split()) C=[0]*-~W for _ in[0]*N: v,w=map(int,input().split()) for i in range(W,w-1,-1): t=v+C[i-w] if t>C[i]:C[i]=t print(C[W])
0-1 Knapsack Problem You have N items that you want to put them into a knapsack. Item i has value vi and weight wi. You want to find a subset of items to put such that: * The total value of the items is as large as possible. * The items have combined weight at most W, that is capacity of the knapsack. Find the maximum total value of items in the knapsack.
[{"input": "4 5\n 4 2\n 5 2\n 2 1\n 8 3", "output": "13"}, {"input": "2 20\n 5 9\n 4 10", "output": "9"}]
Print N integers. The i-th of them should represent the number of the cities connected to the i-th city by both roads and railways. * * *
s423804468
Runtime Error
p03857
The input is given from Standard Input in the following format: N K L p_1 q_1 : p_K q_K r_1 s_1 : r_L s_L
#include "bits/stdc++.h" #define rep(i,n) for(int i=0;i<n;i++) using namespace std; typedef long long ll; const int MAX_N = 200001; int par[MAX_N]; int rnk[MAX_N]; void init(int n) { rep(i,n) { par[i] = i; rnk[i] = 0; } } int find(int x) { if (par[x] == x) { return x; } else { return par[x] = find(par[x]); } } void unite(int x, int y) { x = find(x); y = find(y); if (x == y) return; if (rnk[x] < rnk[y]) { par[x] = y; } else { par[y] = x; if (rnk[x] == rnk[y]) rnk[x]++; } } bool same(int x, int y) { return find(x) == find(y); } void solve() { int N, K, L, p, q; cin >> N >> K >> L; init(N); rep(i,K) { cin >> p >> q; unite(p - 1, q - 1); } int roads[N]; rep(i,N) roads[i] = find(i); init(N); rep(i,L) { cin >> p >> q; unite(p - 1, q - 1); } map<pair<int, int>, int> d; rep(i,N) d[make_pair(roads[i], find(i))]++; rep(i,N) cout << d[make_pair(roads[i], find(i))] << " "; cout << endl; return; } int main() { solve(); }
Statement There are N cities. There are also K roads and L railways, extending between the cities. The i-th road bidirectionally connects the p_i-th and q_i-th cities, and the i-th railway bidirectionally connects the r_i-th and s_i-th cities. No two roads connect the same pair of cities. Similarly, no two railways connect the same pair of cities. We will say city A and B are _connected by roads_ if city B is reachable from city A by traversing some number of roads. Here, any city is considered to be connected to itself by roads. We will also define _connectivity by railways_ similarly. For each city, find the number of the cities connected to that city by both roads and railways.
[{"input": "4 3 1\n 1 2\n 2 3\n 3 4\n 2 3", "output": "1 2 2 1\n \n\nAll the four cities are connected to each other by roads.\n\nBy railways, only the second and third cities are connected. Thus, the answers\nfor the cities are 1, 2, 2 and 1, respectively.\n\n* * *"}, {"input": "4 2 2\n 1 2\n 2 3\n 1 4\n 2 3", "output": "1 2 2 1\n \n\n* * *"}, {"input": "7 4 4\n 1 2\n 2 3\n 2 5\n 6 7\n 3 5\n 4 5\n 3 4\n 6 7", "output": "1 1 2 1 2 2 2"}]
Print N integers. The i-th of them should represent the number of the cities connected to the i-th city by both roads and railways. * * *
s967387062
Runtime Error
p03857
The input is given from Standard Input in the following format: N K L p_1 q_1 : p_K q_K r_1 s_1 : r_L s_L
N,K,L=map(int,input().split()) len = [[[] for s in range(N)] for t in range (2)] i=1 j=1 while i <= K: a,b=map(int,input().split()) len[0][a-1].append(b-1) len[0][b-1].append(a-1) i+=1 while j <= L: a,b=map(int,input().split()) len[1][a-1].append(b-1) len[1][b-1].append(a-1) j+=1 def add(z,n): for num1 in len[z][n]: for num2 in len[z][num1]: if num2 != n and num2 not in len[z][n]: len[z][n].append(num2) add(z,num2) n=0 while n < N: add(0,n) add(1,n) n+=1 n=0 answer=[1]*N while n < N: for point in len[0][n]: if point in len[1][n]: answer[n]+=1 n+=1 n=0 while n<N-1: print(answer[n],end=' ') n+=1 print(answer[N-1])
Statement There are N cities. There are also K roads and L railways, extending between the cities. The i-th road bidirectionally connects the p_i-th and q_i-th cities, and the i-th railway bidirectionally connects the r_i-th and s_i-th cities. No two roads connect the same pair of cities. Similarly, no two railways connect the same pair of cities. We will say city A and B are _connected by roads_ if city B is reachable from city A by traversing some number of roads. Here, any city is considered to be connected to itself by roads. We will also define _connectivity by railways_ similarly. For each city, find the number of the cities connected to that city by both roads and railways.
[{"input": "4 3 1\n 1 2\n 2 3\n 3 4\n 2 3", "output": "1 2 2 1\n \n\nAll the four cities are connected to each other by roads.\n\nBy railways, only the second and third cities are connected. Thus, the answers\nfor the cities are 1, 2, 2 and 1, respectively.\n\n* * *"}, {"input": "4 2 2\n 1 2\n 2 3\n 1 4\n 2 3", "output": "1 2 2 1\n \n\n* * *"}, {"input": "7 4 4\n 1 2\n 2 3\n 2 5\n 6 7\n 3 5\n 4 5\n 3 4\n 6 7", "output": "1 1 2 1 2 2 2"}]
Print N integers. The i-th of them should represent the number of the cities connected to the i-th city by both roads and railways. * * *
s402173539
Runtime Error
p03857
The input is given from Standard Input in the following format: N K L p_1 q_1 : p_K q_K r_1 s_1 : r_L s_L
N,K,L=map(int,input().split()) len = [[[] for s in range(N)] for t in range (2)] i=1 j=1 while i <= K: a,b=map(int,input().split()) len[0][a-1].append(b-1) len[0][b-1].append(a-1) i+=1 while j <= L: a,b=map(int,input().split()) len[1][a-1].append(b-1) len[1][b-1].append(a-1) j+=1 def add(z,n): for num1 in len[z][n]: for num2 in len[z][num1]: if num2 != n and num2 not in len[z][n]: len[z][n].append(num2) add(z,num2) n=0 while n < N: add(0,n) add(1,n) n+=1 n=0 answer=[1]*N while n < N: for point in len[0][n]: if point in len[1][n]: answer[n]+=1 n+=1 n=0 while n<N-1: print(answer[n],end=' ') n+=1 print(answer[N-1])
Statement There are N cities. There are also K roads and L railways, extending between the cities. The i-th road bidirectionally connects the p_i-th and q_i-th cities, and the i-th railway bidirectionally connects the r_i-th and s_i-th cities. No two roads connect the same pair of cities. Similarly, no two railways connect the same pair of cities. We will say city A and B are _connected by roads_ if city B is reachable from city A by traversing some number of roads. Here, any city is considered to be connected to itself by roads. We will also define _connectivity by railways_ similarly. For each city, find the number of the cities connected to that city by both roads and railways.
[{"input": "4 3 1\n 1 2\n 2 3\n 3 4\n 2 3", "output": "1 2 2 1\n \n\nAll the four cities are connected to each other by roads.\n\nBy railways, only the second and third cities are connected. Thus, the answers\nfor the cities are 1, 2, 2 and 1, respectively.\n\n* * *"}, {"input": "4 2 2\n 1 2\n 2 3\n 1 4\n 2 3", "output": "1 2 2 1\n \n\n* * *"}, {"input": "7 4 4\n 1 2\n 2 3\n 2 5\n 6 7\n 3 5\n 4 5\n 3 4\n 6 7", "output": "1 1 2 1 2 2 2"}]
Print N integers. The i-th of them should represent the number of the cities connected to the i-th city by both roads and railways. * * *
s970206077
Wrong Answer
p03857
The input is given from Standard Input in the following format: N K L p_1 q_1 : p_K q_K r_1 s_1 : r_L s_L
def f(m, r): connmap = [[] for _ in range(m + 1)] for _ in range(r): a, b = map(int, input().split()) connmap[a].append(b) connmap[b].append(a) group = [0] * (m + 1) num = 0 for i in range(1, m + 1): if group[i] > 0: continue if len(connmap[i]) == 0: continue num += 1 group[i] = num for j in connmap[i]: group[j] = num bfs = connmap[i] while len(bfs) > 0: tmp = [] for j in bfs: for k in connmap[j]: if group[k] > 0: continue group[k] = num tmp.append(k) bfs = tmp return group n, k, l = map(int, input().split()) road = f(n, k) rail = f(n, l) count = {} for i in range(1, n + 1): key = "{0} {1}".format(road[i], rail[i]) if key in count: count[key] += 1 else: count[key] = 1 for i in range(1, n + 1): key = "{0} {1}".format(road[i], rail[i]) print(count[key], end=" " if i < n else "") print()
Statement There are N cities. There are also K roads and L railways, extending between the cities. The i-th road bidirectionally connects the p_i-th and q_i-th cities, and the i-th railway bidirectionally connects the r_i-th and s_i-th cities. No two roads connect the same pair of cities. Similarly, no two railways connect the same pair of cities. We will say city A and B are _connected by roads_ if city B is reachable from city A by traversing some number of roads. Here, any city is considered to be connected to itself by roads. We will also define _connectivity by railways_ similarly. For each city, find the number of the cities connected to that city by both roads and railways.
[{"input": "4 3 1\n 1 2\n 2 3\n 3 4\n 2 3", "output": "1 2 2 1\n \n\nAll the four cities are connected to each other by roads.\n\nBy railways, only the second and third cities are connected. Thus, the answers\nfor the cities are 1, 2, 2 and 1, respectively.\n\n* * *"}, {"input": "4 2 2\n 1 2\n 2 3\n 1 4\n 2 3", "output": "1 2 2 1\n \n\n* * *"}, {"input": "7 4 4\n 1 2\n 2 3\n 2 5\n 6 7\n 3 5\n 4 5\n 3 4\n 6 7", "output": "1 1 2 1 2 2 2"}]
Print N integers. The i-th of them should represent the number of the cities connected to the i-th city by both roads and railways. * * *
s636359881
Wrong Answer
p03857
The input is given from Standard Input in the following format: N K L p_1 q_1 : p_K q_K r_1 s_1 : r_L s_L
from collections import defaultdict as dd import queue N, K, L = map(int, input().split()) PQ = [tuple(map(int, input().split())) for _ in range(K)] RS = [tuple(map(int, input().split())) for _ in range(L)] road = [[] for _ in range(N)] railroad = [[] for _ in range(N)] for p, q in PQ: road[p - 1].append(q - 1) road[q - 1].append(p - 1) for r, s in RS: railroad[r - 1].append(s - 1) railroad[s - 1].append(r - 1) uf_road = [0] * N uf_railroad = [0] * N idx_road = 1 idx_railroad = 1 # 連結判定 for i in range(N): if uf_road[i] == 0: q = queue.Queue() q.put(i) while not q.empty(): now_node = q.get() print(now_node) uf_road[now_node] = idx_road for target in road[now_node]: road[target].remove(now_node) q.put(target) road[now_node] = [] idx_road += 1 if uf_railroad[i] == 0: q = queue.Queue() q.put(i) while not q.empty(): now_node = q.get() uf_railroad[now_node] = idx_railroad for target in railroad[now_node]: railroad[target].remove(now_node) q.put(target) railroad[now_node] = [] idx_railroad += 1 dic = dd(int) # print(uf_road) # print(uf_railroad) for i, j in zip(uf_road, uf_railroad): dic[(i, j)] += 1 res = [dic[(i, j)] for i, j in zip(uf_road, uf_railroad)] print(*res)
Statement There are N cities. There are also K roads and L railways, extending between the cities. The i-th road bidirectionally connects the p_i-th and q_i-th cities, and the i-th railway bidirectionally connects the r_i-th and s_i-th cities. No two roads connect the same pair of cities. Similarly, no two railways connect the same pair of cities. We will say city A and B are _connected by roads_ if city B is reachable from city A by traversing some number of roads. Here, any city is considered to be connected to itself by roads. We will also define _connectivity by railways_ similarly. For each city, find the number of the cities connected to that city by both roads and railways.
[{"input": "4 3 1\n 1 2\n 2 3\n 3 4\n 2 3", "output": "1 2 2 1\n \n\nAll the four cities are connected to each other by roads.\n\nBy railways, only the second and third cities are connected. Thus, the answers\nfor the cities are 1, 2, 2 and 1, respectively.\n\n* * *"}, {"input": "4 2 2\n 1 2\n 2 3\n 1 4\n 2 3", "output": "1 2 2 1\n \n\n* * *"}, {"input": "7 4 4\n 1 2\n 2 3\n 2 5\n 6 7\n 3 5\n 4 5\n 3 4\n 6 7", "output": "1 1 2 1 2 2 2"}]
Print the minimum possible length of s. * * *
s524292604
Wrong Answer
p02745
Input is given from Standard Input in the following format: a b c
# -*- coding: utf-8 -*- # input = sys.stdin.readline def inpl(): return list(map(int, input().split())) A = input() B = input() C = input() ab = [] bc = [] ca = [] res = len(A) + len(B) + len(C) for i in range(len(A) + len(B) - 1): X = A[ min(max(0, len(B) - i - 1), len(A)) : min( len(A) + len(B) - 2, len(A) + len(B) - i - 1 ) ] Y = B[max(0, i - len(A) + 1) : i + 1] for x, y in zip(X, Y): if (x == "?") or (y == "?") or (x == y): continue else: break else: ab.append(i) res = min(res, len(A) + len(B) + len(C) - len(X)) for i in range(len(B) + len(C) - 1): X = B[ min(max(0, len(C) - i - 1), len(B)) : min( len(B) + len(C) - 2, len(B) + len(C) - i - 1 ) ] Y = C[max(0, i - len(B) + 1) : i + 1] for x, y in zip(X, Y): if x == "?" or y == "?" or x == y: continue else: break else: bc.append(i) res = min(res, len(A) + len(B) + len(C) - len(X)) for i in range(len(C) + len(A) - 1): X = C[ min(max(0, len(A) - i - 1), len(C)) : min( len(C) + len(A) - 2, len(C) + len(A) - i - 1 ) ] Y = A[max(0, i - len(C) + 1) : i + 1] for x, y in zip(X, Y): if x == "?" or y == "?" or x == y: continue else: break else: ca.append(i) res = min(res, len(A) + len(B) + len(C) - len(X)) ab = set(ab) bc = set(bc) ca = set(ca) for x in ab: for y in bc: z = x + y - len(B) + 1 if z < 0 or (len(C) + len(A) - 1 <= z) or (z in ca): # print(len(B) + max(0, len(A)-x-1, y-len(B)+1) + max(0, x-len(B)+1, len(C)-y-1)) res = min( res, len(B) + max(0, len(A) - x - 1, y - len(B) + 1) + max(0, x - len(B) + 1, len(C) - y - 1), ) for x in bc: for y in ca: z = x + y - len(C) + 1 if z < 0 or (len(A) + len(B) - 1 <= z) or (z in ab): # print(len(B) + max(0, len(A)-x-1, y-len(B)+1) + max(0, x-len(B)+1, len(C)-y-1)) res = min( res, len(C) + max(0, len(B) - x - 1, y - len(C) + 1) + max(0, x - len(C) + 1, len(A) - y - 1), ) for x in ca: for y in ab: z = x + y - len(A) + 1 if z < 0 or (len(B) + len(C) - 1 <= z) or (z in bc): # print(len(B) + max(0, len(A)-x-1, y-len(B)+1) + max(0, x-len(B)+1, len(C)-y-1)) res = min( res, len(A) + max(0, len(C) - x - 1, y - len(A) + 1) + max(0, x - len(A) + 1, len(B) - y - 1), ) print(res)
Statement Snuke has a string s. From this string, Anuke, Bnuke, and Cnuke obtained strings a, b, and c, respectively, as follows: * Choose a non-empty (contiguous) substring of s (possibly s itself). Then, replace some characters (possibly all or none) in it with `?`s. For example, if s is `mississippi`, we can choose the substring `ssissip` and replace its 1-st and 3-rd characters with `?` to obtain `?s?ssip`. You are given the strings a, b, and c. Find the minimum possible length of s.
[{"input": "a?c\n der\n cod", "output": "7\n \n\nFor example, s could be `atcoder`.\n\n* * *"}, {"input": "atcoder\n atcoder\n ???????", "output": "7\n \n\na, b, and c may not be distinct."}]
Print the minimum possible length of s. * * *
s858427853
Runtime Error
p02745
Input is given from Standard Input in the following format: a b c
def inner(a, b, la, lb): for i in range(lb - la + 1): for j in range(la): if a[j] == "?" or a[j] == b[i + j]: continue elif b[i + j] == "?": continue else: break else: return True return False def head(a, b, la): for i in range(la, -1, -1): for j in range(i): if a[j] == "?" or a[j] == b[-(i - j)]: continue elif b[-(i - j)] == "?": continue else: break else: return b + a[i:] def tail(a, b, la): for i in range(la, -1, -1): for j in range(i): if a[-(i - j)] == "?" or a[-(i - j)] == b[j]: continue elif b[j] == "?": continue else: break else: return a + b[i:] break a = input() la = len(a) b = input() lb = len(b) c = input() lc = len(c) arr = [[a, la], [b, lb], [c, lc]] arr = sorted(arr, key=lambda x: x[1]) a, la = arr[0] b, lb = arr[1] c, lc = arr[2] tmp1 = head(a, c, la) tmp2 = tail(a, c, la) ans1 = min(len(head(b, tmp1, lb)), len(tail(b, tmp1, lb))) if inner(b, tmp1, lb, len(tmp1)): ans1 = min(ans1, len(tmp1)) ans2 = min(len(head(b, tmp2, lb)), len(tail(b, tmp2, lb))) if inner(b, tmp2, lb, len(tmp2)): ans2 = min(ans2, len(tmp2)) ans3 = 10**18 if inner(a, c, la, lc): ans3 = min(len(head(b, c, lb)), len(tail(b, c, lb))) if inner(b, c, lb, lc): ans3 = min(ans3, lc) ansac = min(ans1, ans2, ans3) tmp1 = head(b, c, lb) tmp2 = tail(b, c, lb) ans1 = min(len(head(a, tmp1, la)), len(tail(a, tmp1, la))) if inner(a, tmp1, la, len(tmp1)): ans1 = min(ans1, len(tmp1)) ans2 = min(len(head(a, tmp2, la)), len(tail(a, tmp2, la))) if inner(a, tmp2, la, len(tmp2)): ans2 = min(ans2, len(tmp2)) ans3 = 10**18 if inner(b, c, lb, lc): ans3 = min(len(head(a, c, la)), len(tail(a, c, la))) if inner(a, c, la, lc): ans3 = min(ans3, lc) ansbc = min(ans1, ans2, ans3) tmp1 = head(a, b, la) lt1 = len(tmp1) tmp2 = tail(a, b, la) lt2 = len(tmp2) if lt1 >= lc: ans1 = min(len(head(c, tmp1, lc)), len(tail(c, tmp1, lc))) if inner(c, tmp1, lc, lt1): ans1 = min(ans1, lt1) else: ans1 = min(len(head(tmp1, c, lt1)), len(tail(tmp1, c, lt1))) if inner(tmp1, c, lt1, c): ans1 = min(ans1, c) if lt2 >= lc: ans2 = min(len(head(c, tmp2, lc)), len(tail(c, tmp2, lc))) if inner(c, tmp2, lc, lt2): ans2 = min(ans2, lt2) else: ans2 = min(len(head(tmp2, c, lt2)), len(tail(tmp2, c, lt2))) if inner(tmp2, c, lt2, lc): ans2 = min(ans2, lc) ans3 = 10**18 if inner(a, b, la, lb): ans3 = min(len(head(b, c, lb)), len(tail(b, c, lb))) if inner(b, c, lb, lc): ans3 = min(ans3, lc) ansab = min(ans1, ans2, ans3) ans = min(ansac, ansbc, ansab) print(ans)
Statement Snuke has a string s. From this string, Anuke, Bnuke, and Cnuke obtained strings a, b, and c, respectively, as follows: * Choose a non-empty (contiguous) substring of s (possibly s itself). Then, replace some characters (possibly all or none) in it with `?`s. For example, if s is `mississippi`, we can choose the substring `ssissip` and replace its 1-st and 3-rd characters with `?` to obtain `?s?ssip`. You are given the strings a, b, and c. Find the minimum possible length of s.
[{"input": "a?c\n der\n cod", "output": "7\n \n\nFor example, s could be `atcoder`.\n\n* * *"}, {"input": "atcoder\n atcoder\n ???????", "output": "7\n \n\na, b, and c may not be distinct."}]
Print the minimum possible length of s. * * *
s804583610
Wrong Answer
p02745
Input is given from Standard Input in the following format: a b c
l = ["", "", ""] d = [["", "", ""], ["", "", ""], ["", "", ""]] l[0] = str(input()) l[1] = str(input()) l[2] = str(input()) for i in range(3): for j in range(3): if i != j: p = min(len(l[i]), len(l[j])) s = 0 for k in reversed(range(p)): t = 0 for x in range(k + 1): if l[i][x - k - 1] != l[j][x]: if (l[i][x - k - 1] != "?") & (l[j][x] != "?"): t = 1 break if t == 0: s = k + 1 break d[i][j] = s r = len(l[0]) + len(l[1]) + len(l[2]) u = (d[0][1] + d[1][2] + d[2][0]) - min(min(d[0][1], d[1][2]), d[2][0]) v = (d[1][0] + d[2][1] + d[0][2]) - min(min(d[1][0], d[2][1]), d[0][2]) print(r - min(u, v))
Statement Snuke has a string s. From this string, Anuke, Bnuke, and Cnuke obtained strings a, b, and c, respectively, as follows: * Choose a non-empty (contiguous) substring of s (possibly s itself). Then, replace some characters (possibly all or none) in it with `?`s. For example, if s is `mississippi`, we can choose the substring `ssissip` and replace its 1-st and 3-rd characters with `?` to obtain `?s?ssip`. You are given the strings a, b, and c. Find the minimum possible length of s.
[{"input": "a?c\n der\n cod", "output": "7\n \n\nFor example, s could be `atcoder`.\n\n* * *"}, {"input": "atcoder\n atcoder\n ???????", "output": "7\n \n\na, b, and c may not be distinct."}]
Print the minimum possible length of s. * * *
s435298803
Wrong Answer
p02745
Input is given from Standard Input in the following format: a b c
import sys sys.setrecursionlimit(1000000) def js(s1, s2): for i in range(0, len(s1)): flag = True for j in range(0, min(len(s1) - i, len(s2))): c1 = s1[i + j] c2 = s2[j] if c1 != "?" and c2 != "?" and c1 != c2: flag = False break if flag: if len(s1) > len(s2) + i: l1 = list(s1) for j in range(len(s2)): if s1[i + j] == "?": l1[i + j] = s2[j] return "".join(l1) else: l2 = list(s2) for j in range(i, len(s1)): if s2[j - i] == "?": l2[j - i] = s1[j] return s1[:i] + "".join(l2) return s1 + s2 def main(): a = input() b = input() c = input() ac = js(a, c) ab = js(a, b) ba = js(b, a) bc = js(b, c) ca = js(c, a) cb = js(c, b) abc = js(ab, c) acb = js(ac, b) bac = js(ba, c) bca = js(bc, a) cab = js(ca, b) cba = js(cb, a) # for s in (abc, acb, bac, bca, cab, cba): # print(s) print(min(len(s) for s in (abc, acb, bac, bca, cab, cba))) main()
Statement Snuke has a string s. From this string, Anuke, Bnuke, and Cnuke obtained strings a, b, and c, respectively, as follows: * Choose a non-empty (contiguous) substring of s (possibly s itself). Then, replace some characters (possibly all or none) in it with `?`s. For example, if s is `mississippi`, we can choose the substring `ssissip` and replace its 1-st and 3-rd characters with `?` to obtain `?s?ssip`. You are given the strings a, b, and c. Find the minimum possible length of s.
[{"input": "a?c\n der\n cod", "output": "7\n \n\nFor example, s could be `atcoder`.\n\n* * *"}, {"input": "atcoder\n atcoder\n ???????", "output": "7\n \n\na, b, and c may not be distinct."}]
Print the minimum possible length of s. * * *
s364375341
Wrong Answer
p02745
Input is given from Standard Input in the following format: a b c
a = list((input())) b = list((input())) c = list((input())) def f(s, t): # print(s,t) for i, j in zip(s, t): if i == j or i == "?" or j == "?": pass else: return False else: return True def calc(a, c): l = 0 r = len(a) * 2 + 1 while r - l > 1: m = (l + r) // 2 if f(a[-m:], c[:m]): l = m else: r = m # print(l,m,r) return l ans = len(a) + len(b) + len(c) max_ = 0 for case in [((b, a), (a, c)), ((a, b), (a, c))]: s = 0 for i, j in case: s += (calc(i, j)) // 2 max_ = max(max_, s) print(ans - max_)
Statement Snuke has a string s. From this string, Anuke, Bnuke, and Cnuke obtained strings a, b, and c, respectively, as follows: * Choose a non-empty (contiguous) substring of s (possibly s itself). Then, replace some characters (possibly all or none) in it with `?`s. For example, if s is `mississippi`, we can choose the substring `ssissip` and replace its 1-st and 3-rd characters with `?` to obtain `?s?ssip`. You are given the strings a, b, and c. Find the minimum possible length of s.
[{"input": "a?c\n der\n cod", "output": "7\n \n\nFor example, s could be `atcoder`.\n\n* * *"}, {"input": "atcoder\n atcoder\n ???????", "output": "7\n \n\na, b, and c may not be distinct."}]
Print the minimum possible length of s. * * *
s324064103
Runtime Error
p02745
Input is given from Standard Input in the following format: a b c
from functools import reduce n = int(input()) alphabet = "abcdefghij" cur = [[] for _ in range(10)] nxt = [[] for _ in range(10)] cur[0] = ["a"] for _ in range(1, n): for i in range(10): for x in cur[i]: nxt[i].extend([x + alphabet[j] for j in range(i + 1)]) nxt[i + 1].append(x + alphabet[i + 1]) cur = nxt.copy() nxt = [[] for _ in range(10)] ans = reduce(lambda a, b: a + b, cur) ans.sort() print(*ans, sep="\n")
Statement Snuke has a string s. From this string, Anuke, Bnuke, and Cnuke obtained strings a, b, and c, respectively, as follows: * Choose a non-empty (contiguous) substring of s (possibly s itself). Then, replace some characters (possibly all or none) in it with `?`s. For example, if s is `mississippi`, we can choose the substring `ssissip` and replace its 1-st and 3-rd characters with `?` to obtain `?s?ssip`. You are given the strings a, b, and c. Find the minimum possible length of s.
[{"input": "a?c\n der\n cod", "output": "7\n \n\nFor example, s could be `atcoder`.\n\n* * *"}, {"input": "atcoder\n atcoder\n ???????", "output": "7\n \n\na, b, and c may not be distinct."}]
Print the minimum possible length of s. * * *
s480907372
Wrong Answer
p02745
Input is given from Standard Input in the following format: a b c
# coding: utf-8 # Your code here! # coding: utf-8 import sys sys.setrecursionlimit(10000000) # const # my functions here! def pin(type=int): return map(type, input().rstrip().split()) """ def resolve(): a,b,c=pin() from math import sqrt cond =(c-a-b)>sqrt(a*b)*2 print(["No","Yes"][cond]) """ def resolve(): t = [input() for i in range(3)] ans = sum(map(lambda x: len(x), t)) # デフォ値 from itertools import permutations as p for perm in p(range(3)): x, y, z = t[perm[0]], t[perm[1]], t[perm[2]] X, Y, Z = len(x), len(y), len(z) kasa = [0, 0] # xy for ixy in range(min(X, Y), -1, -1): # ixyはxのケツとyの頭での文字の重なり(?をふくむ # 重なりの最大を求めたいのでrev # print("ya") # ixy個の文字比較 flag = 0 for pxy in range(ixy): # print(x,y,ixy) # print(y[pxy],x[X-ixy+pxy],(y[pxy]==x[X-ixy+pxy])) if y[pxy] != "?" and x[X - ixy + pxy] != "?": if y[pxy] != x[X - ixy + pxy]: flag = 1 break if flag == 1: continue if flag == 0: # print("end") kasa[0] = ixy break flag = 0 # yz for iyz in range(min(Z, Y), -1, -1): # ixyはxのケツとyの頭での文字の重なり(?をふくむ # 重なりの最大を求めたいのでrev # ixy個の文字比較 flag2 = 0 for pyz in range(iyz): if z[pyz] != "?" and y[Y - iyz + pyz] != "?": if z[pyz] != y[Y - iyz + pyz]: flag2 = 1 break if flag == 1: continue if flag2 == 0: kasa[1] = iyz break flag2 = 0 # print(kasa) ans = min(ans, X + Y + Z - sum(kasa)) print(ans) """ #printデバッグ消した? #前の問題の結果見てないのに次の問題に行くの? """ """ お前カッコ閉じるの忘れてるだろ """ import sys from io import StringIO import unittest class TestClass(unittest.TestCase): def assertIO(self, input, output): stdout, stdin = sys.stdout, sys.stdin sys.stdout, sys.stdin = StringIO(), StringIO(input) resolve() sys.stdout.seek(0) out = sys.stdout.read()[:-1] sys.stdout, sys.stdin = stdout, stdin self.assertEqual(out, output) def test_入力例_1(self): input = """a?c der cod""" output = """7""" self.assertIO(input, output) def test_入力例_2(self): input = """atcoder atcoder ???????""" output = """7""" self.assertIO(input, output) if __name__ == "__main__": resolve()
Statement Snuke has a string s. From this string, Anuke, Bnuke, and Cnuke obtained strings a, b, and c, respectively, as follows: * Choose a non-empty (contiguous) substring of s (possibly s itself). Then, replace some characters (possibly all or none) in it with `?`s. For example, if s is `mississippi`, we can choose the substring `ssissip` and replace its 1-st and 3-rd characters with `?` to obtain `?s?ssip`. You are given the strings a, b, and c. Find the minimum possible length of s.
[{"input": "a?c\n der\n cod", "output": "7\n \n\nFor example, s could be `atcoder`.\n\n* * *"}, {"input": "atcoder\n atcoder\n ???????", "output": "7\n \n\na, b, and c may not be distinct."}]
Print the minimum possible length of s. * * *
s977603320
Wrong Answer
p02745
Input is given from Standard Input in the following format: a b c
# -*- coding: utf-8 -*- """ Created on Sat Mar 14 23:05:24 2020 @author: Kanaru Sato """ def rdndnt(a, b): la = len(a) lb = len(b) l = min(la, lb) n = 0 for i in range(l): if a[la - 1 - i] != "?" and b[i] != "?": if a[la - 1 - i : la] == b[0 : i + 1]: n = i + 1 else: break else: n = i + 1 return n s = input() t = input() u = input() st = rdndnt(s, t) ts = rdndnt(t, s) tu = rdndnt(t, u) ut = rdndnt(u, t) us = rdndnt(u, s) su = rdndnt(s, u) stu = st + tu sut = su + ut tsu = ts + su tus = tu + us uts = ut + ts ust = us + st M = max(stu, sut, tsu, tus, uts, ust) ans = len(s) + len(t) + len(u) - M print(ans)
Statement Snuke has a string s. From this string, Anuke, Bnuke, and Cnuke obtained strings a, b, and c, respectively, as follows: * Choose a non-empty (contiguous) substring of s (possibly s itself). Then, replace some characters (possibly all or none) in it with `?`s. For example, if s is `mississippi`, we can choose the substring `ssissip` and replace its 1-st and 3-rd characters with `?` to obtain `?s?ssip`. You are given the strings a, b, and c. Find the minimum possible length of s.
[{"input": "a?c\n der\n cod", "output": "7\n \n\nFor example, s could be `atcoder`.\n\n* * *"}, {"input": "atcoder\n atcoder\n ???????", "output": "7\n \n\na, b, and c may not be distinct."}]
Print the minimum possible length of s. * * *
s963062041
Wrong Answer
p02745
Input is given from Standard Input in the following format: a b c
string = list(input("Enter a string: ")) lists = [] count = 0 for x in string: if x not in lists: lists.append(x) count += 1 print(count)
Statement Snuke has a string s. From this string, Anuke, Bnuke, and Cnuke obtained strings a, b, and c, respectively, as follows: * Choose a non-empty (contiguous) substring of s (possibly s itself). Then, replace some characters (possibly all or none) in it with `?`s. For example, if s is `mississippi`, we can choose the substring `ssissip` and replace its 1-st and 3-rd characters with `?` to obtain `?s?ssip`. You are given the strings a, b, and c. Find the minimum possible length of s.
[{"input": "a?c\n der\n cod", "output": "7\n \n\nFor example, s could be `atcoder`.\n\n* * *"}, {"input": "atcoder\n atcoder\n ???????", "output": "7\n \n\na, b, and c may not be distinct."}]
Print the minimum possible length of s. * * *
s033616257
Runtime Error
p02745
Input is given from Standard Input in the following format: a b c
a, b, c = input() a = a + b + c s = set() for char in a: s.add(char) print(len(s))
Statement Snuke has a string s. From this string, Anuke, Bnuke, and Cnuke obtained strings a, b, and c, respectively, as follows: * Choose a non-empty (contiguous) substring of s (possibly s itself). Then, replace some characters (possibly all or none) in it with `?`s. For example, if s is `mississippi`, we can choose the substring `ssissip` and replace its 1-st and 3-rd characters with `?` to obtain `?s?ssip`. You are given the strings a, b, and c. Find the minimum possible length of s.
[{"input": "a?c\n der\n cod", "output": "7\n \n\nFor example, s could be `atcoder`.\n\n* * *"}, {"input": "atcoder\n atcoder\n ???????", "output": "7\n \n\na, b, and c may not be distinct."}]
Print the minimum possible length of s. * * *
s485572333
Runtime Error
p02745
Input is given from Standard Input in the following format: a b c
import sys input = lambda: sys.stdin.readline().rstrip() n = int(input()) A = [chr(97 + int(i)) for i in range(n)] Ans = ["a"] if n >= 2: for _ in range(n - 1): Ans2 = [] for a in Ans: s = set() for aa in a: s.add(aa) ss = len(s) for i in range(ss + 1): Ans2.append(a + A[i]) Ans = Ans2 Ans.sort() for ans in Ans: print(ans)
Statement Snuke has a string s. From this string, Anuke, Bnuke, and Cnuke obtained strings a, b, and c, respectively, as follows: * Choose a non-empty (contiguous) substring of s (possibly s itself). Then, replace some characters (possibly all or none) in it with `?`s. For example, if s is `mississippi`, we can choose the substring `ssissip` and replace its 1-st and 3-rd characters with `?` to obtain `?s?ssip`. You are given the strings a, b, and c. Find the minimum possible length of s.
[{"input": "a?c\n der\n cod", "output": "7\n \n\nFor example, s could be `atcoder`.\n\n* * *"}, {"input": "atcoder\n atcoder\n ???????", "output": "7\n \n\na, b, and c may not be distinct."}]
Print the minimum possible length of s. * * *
s458163749
Accepted
p02745
Input is given from Standard Input in the following format: a b c
# 解説の写経 def solve_panasonic2020_e(): def unmatched(c1: str, c2: str) -> bool: """c1,c2がマッチしない""" return not (c1 == "?" or c2 == "?" or c1 == c2) A = input() B = input() C = input() MX = max(map(len, [A, B, C])) # 相対位置ごとの文字列マッチングの可否を調べる # ab/ac/bc[index差]:=その相対位置でマッチしないときTrue # [-MX,MX] # + : 左文字より右文字が右にある, a->b # - : 右文字より左文字が右にある, b->a ab = [False] * (MX * 4 + 1) ac = [False] * (MX * 4 + 1) bc = [False] * (MX * 4 + 1) for i, a in enumerate(A): for j, b in enumerate(B): ab[i - j] |= unmatched(a, b) for i, a in enumerate(A): for j, c in enumerate(C): ac[i - j] |= unmatched(a, c) for i, b in enumerate(B): for j, c in enumerate(C): bc[i - j] |= unmatched(b, c) # Aに対するB,Cの相対位置MX**2で全探索 ans = sum(map(len, [A, B, C])) for i in range(-MX * 2, MX * 2 + 1): # ACBのようにAB間にMX分空くこともあって、幅2MX if ab[i]: continue for j in range( -MX * 2, MX * 2 + 1 ): # ABCのようにAC間にMX分空くこともあって、幅2MX if ac[j]: continue if bc[j - i]: continue # 添え字で混乱するが # ab[i-j]で # 添え字i-jは(bの開始)-(aの開始)を意味したことから # (i-j>0でa->bの配置から) # 今回i,jは(aの開始)を基準にした(b,cの開始位置)で # bcの添え字は(cの開始)-(bの開始)なのでj-i # [L,R) L = min(0, i, j) R = max(len(A), i + len(B), j + len(C)) ans = min(ans, R - L) print(ans) return if __name__ == "__main__": solve_panasonic2020_e() # N**3は通らない # N**2の方針=2本の文字列の捜査
Statement Snuke has a string s. From this string, Anuke, Bnuke, and Cnuke obtained strings a, b, and c, respectively, as follows: * Choose a non-empty (contiguous) substring of s (possibly s itself). Then, replace some characters (possibly all or none) in it with `?`s. For example, if s is `mississippi`, we can choose the substring `ssissip` and replace its 1-st and 3-rd characters with `?` to obtain `?s?ssip`. You are given the strings a, b, and c. Find the minimum possible length of s.
[{"input": "a?c\n der\n cod", "output": "7\n \n\nFor example, s could be `atcoder`.\n\n* * *"}, {"input": "atcoder\n atcoder\n ???????", "output": "7\n \n\na, b, and c may not be distinct."}]
Print the minimum possible length of s. * * *
s147617586
Wrong Answer
p02745
Input is given from Standard Input in the following format: a b c
def constructable(str1, str2): if str1 == "?" or str2 == "?": return True elif str1 == str2: return True else: return False def condition(num): N = num if N < max(len(a), len(b), len(c)): return False flag = 0 S = ["?" for i in range(0, N)] for i in range(0, len(a)): S[i] = a[i] for i in range(0, len(c)): if not constructable(S[-i - 1], c[-i - 1]): flag = 1 break else: if S[-i - 1] == "?": S[-i - 1] = c[-i - 1] if flag == 0: for i in range(0, N - len(b) + 1): start = i for j in range(0, len(b)): if not constructable(b[j], S[start + j]): break else: return True flag = 0 S = ["?" for i in range(0, N)] for i in range(0, len(a)): S[i] = a[i] for i in range(0, len(b)): if not constructable(S[-i - 1], b[-i - 1]): flag = 1 break else: if S[-i - 1] == "?": S[-i - 1] = b[-i - 1] if flag == 0: for i in range(0, N - len(c) + 1): start = i for j in range(0, len(c)): if not constructable(c[j], S[start + j]): break else: return True flag = 0 S = ["?" for i in range(0, N)] for i in range(0, len(b)): S[i] = b[i] for i in range(0, len(c)): if not constructable(S[-i - 1], c[-i - 1]): flag = 1 break else: if S[-i - 1] == "?": S[-i - 1] = c[-i - 1] if flag == 0: for i in range(0, N - len(a) + 1): start = i for j in range(0, len(a)): if not constructable(a[j], S[start + j]): break else: return True flag = 0 S = ["?" for i in range(0, N)] for i in range(0, len(b)): S[i] = b[i] for i in range(0, len(a)): if not constructable(S[-i - 1], a[-i - 1]): flag = 1 break else: if S[-i - 1] == "?": S[-i - 1] = a[-i - 1] if flag == 0: for i in range(0, N - len(c) + 1): start = i for j in range(0, len(c)): if not constructable(c[j], S[start + j]): break else: return True flag = 0 S = ["?" for i in range(0, N)] for i in range(0, len(c)): S[i] = c[i] for i in range(0, len(a)): if not constructable(S[-i - 1], a[-i - 1]): flag = 1 break else: if S[-i - 1] == "?": S[-i - 1] = a[-i - 1] if flag == 0: for i in range(0, N - len(b) + 1): start = i for j in range(0, len(b)): if not constructable(b[j], S[start + j]): break else: return True flag = 0 S = ["?" for i in range(0, N)] for i in range(0, len(c)): S[i] = c[i] for i in range(0, len(b)): if not constructable(S[-i - 1], b[-i - 1]): flag = 1 break else: if S[-i - 1] == "?": S[-i - 1] = b[-i - 1] if flag == 0: for i in range(0, N - len(a) + 1): start = i for j in range(0, len(a)): if not constructable(a[j], S[start + j]): break else: return True return False a = input() b = input() c = input() s = 1 e = 6000 while e - s > 1: test = (e + s) // 2 if condition(test): e = test else: s = test if condition(s): print(s) else: print(e)
Statement Snuke has a string s. From this string, Anuke, Bnuke, and Cnuke obtained strings a, b, and c, respectively, as follows: * Choose a non-empty (contiguous) substring of s (possibly s itself). Then, replace some characters (possibly all or none) in it with `?`s. For example, if s is `mississippi`, we can choose the substring `ssissip` and replace its 1-st and 3-rd characters with `?` to obtain `?s?ssip`. You are given the strings a, b, and c. Find the minimum possible length of s.
[{"input": "a?c\n der\n cod", "output": "7\n \n\nFor example, s could be `atcoder`.\n\n* * *"}, {"input": "atcoder\n atcoder\n ???????", "output": "7\n \n\na, b, and c may not be distinct."}]
Print the minimum possible length of s. * * *
s041615675
Wrong Answer
p02745
Input is given from Standard Input in the following format: a b c
# パナソニック2020E import sys input = sys.stdin.readline sys.setrecursionlimit(max(1000, 10**9)) a, b, c = [input() for _ in range(3)] la, lb, lc = len(a), len(b), len(c) def ok(c1, c2): return True if c1 == c2 or c1 == "?" or c2 == "?" else False def sub(s, t, gap): # tを固定したとき、 # sの開始位置座標としてありえるもののset S = set(list(range(-len(s) - gap, -len(s) + 1)) + list(range(len(t), len(t) + gap))) i1 = min(len(s), len(t)) i2 = max(len(s), len(t)) i3 = len(s) + len(t) for i in range(1, i1): if all((ok(s[-i + ii], t[ii])) for ii in range(i)): S.add(i - len(s)) for i in range(i1, i2): if len(s) < len(t) and all((ok(s[ii], t[ii + i - i1]) for ii in range(i1))): S.add(i - len(s)) elif len(t) <= len(s) and all(ok(s[i1 - i + ii], t[ii]) for ii in range(i1)): S.add(i - len(s)) for i in range(i2, i3): if all((ok(s[ii], t[i - i3 + ii]) for ii in range(i3 - i))): S.add(i - len(s)) return S ab = sub(a, b, lc) bc = sub(c, b, la) ac = sub(a, c, lb) ans = 10**9 import itertools for ii, jj in itertools.product(ab, bc): if ii - jj in ac: val = max(lb, ii + la, jj + lc) - min(0, ii, jj) ans = min(ans, val) print(ans)
Statement Snuke has a string s. From this string, Anuke, Bnuke, and Cnuke obtained strings a, b, and c, respectively, as follows: * Choose a non-empty (contiguous) substring of s (possibly s itself). Then, replace some characters (possibly all or none) in it with `?`s. For example, if s is `mississippi`, we can choose the substring `ssissip` and replace its 1-st and 3-rd characters with `?` to obtain `?s?ssip`. You are given the strings a, b, and c. Find the minimum possible length of s.
[{"input": "a?c\n der\n cod", "output": "7\n \n\nFor example, s could be `atcoder`.\n\n* * *"}, {"input": "atcoder\n atcoder\n ???????", "output": "7\n \n\na, b, and c may not be distinct."}]
Print the minimum possible length of s. * * *
s030139920
Wrong Answer
p02745
Input is given from Standard Input in the following format: a b c
def comp(a, b): r = "" for x, y in zip(a, b): if x == y: r += x elif y == "?": r += x elif x == "?": r += y else: return False return r def merge1(a, b): la, lb = map(len, [a, b]) for i in range(la - lb + 1): m = comp(a[i:], b) if m: yield i, (a[:i] + m + a[i + lb :], la) def merge2(a, b): la, lb = map(len, [a, b]) for i in range(1, lb): m = comp(b, a[-lb + i :]) if m: yield la - lb + i, (a[: -lb + i] + m + b[-i:], la + i) yield la, (a + b, la + lb) def merge3(a, b): la, lb = map(len, [a, b]) for i in range(1, lb): m = comp(b[i:], a) if m: yield -i, (b[:i] + m + a[len(b) - i :], la + i) yield -lb, (b + a, la + lb) def min_merge(a, b, c): a, b, c = sorted([a, b, c], key=len, reverse=True) la, lb, lc = map(len, [a, b, c]) abc = float("inf") a_b = dict(merge1(a, b)) a_b2 = dict(merge2(a, b)) a_b3 = dict(merge3(a, b)) a_c = dict(merge1(a, c)) a_c2 = dict(merge2(a, c)) a_c3 = dict(merge3(a, c)) b_c = dict(merge1(b, c)) b_c2 = dict(merge2(b, c)) b_c3 = dict(merge3(b, c)) for i, (d, ld) in a_b.items(): for j, (e, le) in a_c.items(): if j + lc <= i or i + lb <= j: return la if j - i in b_c and comp(d[j:], c): return la if j - i in b_c2 and comp(d[j : j + lb], c): return la if j - i in b_c3 and comp(d[i:], c[i - j :]): return la for i, (d, ld) in a_b2.items(): if abc <= ld: break for j, (e, le) in a_c.items() | a_c2.items(): if j + lc <= i: abc = min(abc, ld) break if j - i in b_c and comp(d[j:la], c): abc = min(abc, ld) break if j - i in b_c3 and comp(d[i:la], c[i - j :]): abc = min(abc, ld) break if abc <= ld: break for j, (e, le) in b_c.items(): if la <= i + j: abc = min(abc, ld) break if abc <= ld: break for j, (e, le) in a_c3.items(): if j + lc <= i: abc = min(abc, ld - j) break if j - i in b_c3 and comp(d[i:], c[i - j :]): abc = min(abc, ld - j) break for j, (e, le) in b_c2.items(): if la <= i + j: abc = min(abc, i + le) break if i + j in a_c2 and comp(d[i + j : la], c): abc = min(abc, i + le) break for i, (d, ld) in a_b3.items(): if abc <= ld: break for j, (e, le) in a_c.items() | a_c3.items(): if i + lb <= j: abc = min(abc, ld) break if j - i in b_c and comp(d[j - i + lc - 1 : -1 : -1], c[::-1]): abc = min(abc, ld) break if j - i in b_c2 and comp(d[lb - 1 : -i - 1 : -1], c[i - j + lb - 1 :: -1]): abc = min(abc, ld) break if abc <= ld: break for j, (e, le) in b_c.items(): if i + j + lc <= 0: abc = min(abc, ld) break if abc <= ld: break for j, (e, le) in a_c3.items(): if i + lb <= j: abc = min(abc, le - i) break if j - i in b_c2 and comp(d[j - i : lb], c): abc = min(abc, le - i) break for j, (e, le) in b_c3.items(): if i + j + lc <= 0: abc = min(abc, ld - j) break if i + j in a_c3 and comp(d[-i:], c[-i - j :]): abc = min(abc, ld - j) break for i in range(1, lc): if abc < la + lb + i: break for j, (e, le) in a_c2.items(): if j - la - i in b_c3: return la + lb + i for j, (e, le) in b_c2.items(): if j - la - i in a_c3: return la + lb + i return abc a = input() b = input() c = input() print(min_merge(a, b, c))
Statement Snuke has a string s. From this string, Anuke, Bnuke, and Cnuke obtained strings a, b, and c, respectively, as follows: * Choose a non-empty (contiguous) substring of s (possibly s itself). Then, replace some characters (possibly all or none) in it with `?`s. For example, if s is `mississippi`, we can choose the substring `ssissip` and replace its 1-st and 3-rd characters with `?` to obtain `?s?ssip`. You are given the strings a, b, and c. Find the minimum possible length of s.
[{"input": "a?c\n der\n cod", "output": "7\n \n\nFor example, s could be `atcoder`.\n\n* * *"}, {"input": "atcoder\n atcoder\n ???????", "output": "7\n \n\na, b, and c may not be distinct."}]
Print the minimum possible length of s. * * *
s177515409
Accepted
p02745
Input is given from Standard Input in the following format: a b c
a = input().strip() b = input().strip() c = input().strip() kk = 2000 K = kk * 2 na, nb, nc = len(a), len(b), len(c) def ll(s, t): X = [0] * 100000 ns, nt = len(s), len(t) for i in range(ns): for j in range(nt): if s[i] != t[j] and s[i] != "?" and t[j] != "?": X[i - j + 2 * K] = 1 return X ab = ll(a, b) bc = ll(b, c) ac = ll(a, c) r = na + nb + nc for i in range(-K, K + 1): for j in range(-K, K + 1): if (not ab[i + 2 * K]) and (not ac[j + 2 * K]) and (not bc[j - i + 2 * K]): st = min(i, j, 0) en = max(i + nb, j + nc, na) r = min(en - st, r) print(r)
Statement Snuke has a string s. From this string, Anuke, Bnuke, and Cnuke obtained strings a, b, and c, respectively, as follows: * Choose a non-empty (contiguous) substring of s (possibly s itself). Then, replace some characters (possibly all or none) in it with `?`s. For example, if s is `mississippi`, we can choose the substring `ssissip` and replace its 1-st and 3-rd characters with `?` to obtain `?s?ssip`. You are given the strings a, b, and c. Find the minimum possible length of s.
[{"input": "a?c\n der\n cod", "output": "7\n \n\nFor example, s could be `atcoder`.\n\n* * *"}, {"input": "atcoder\n atcoder\n ???????", "output": "7\n \n\na, b, and c may not be distinct."}]
Print the minimum possible length of s. * * *
s242234642
Runtime Error
p02745
Input is given from Standard Input in the following format: a b c
a = list(input()) b = list(input()) c = list(input()) n0 = len(a) n1 = len(b) n2 = len(c) al = [] def mae(a, b): n0 = len(a) n1 = len(b) al = [] now = [] count = 0 for i in range(n1): if a[0] == b[i] or a[0] == "?" or b[i] == "?": now2 = now count2 = 0 for j in range(min(n1 - i, n0)): if a[j] != b[j + i] and a[j] != "?" and b[j + i] != "?": break else: count2 += 1 now2.append(a[j]) count = max(count, count2) al.append([now2, count2]) now.append(b[i]) return al, count def ushiro(a, b): n0 = len(a) n1 = len(b) al = [] now = [] count = 0 for i in range(n1 - 1, -1, -1): if a[n0 - 1] == b[i] or a[n0 - 1] == "?" or b[i] == "?": now2 = now count2 = 0 for j in range(min(i, n0)): if ( a[n0 - 1 - j] != b[i - j] and a[n0 - 1 - j] != "?" and b[i - j] != "?" ): break else: count2 += 1 now2.append(a[j]) count = max(count, count2) al.append([now2, count2]) now.append(b[i]) return al, count ansl = [] c1, k = mae(a, b) c2, p = ushiro(a, b) for i in c1: c3, k1 = mae(c, i[0]) ansl.append(k1 + i[1]) for i in c2: c3, k1 = ushiro(c, i[0]) ansl.append(k1 + i[1]) c1, k = mae(b, a) c2, p = ushiro(b, a) for i in c1: c3, k1 = mae(c, i[0]) ansl.append(k1 + i[1]) for i in c2: c3, k1 = ushiro(c, i[0]) ansl.append(k1 + i[1]) c1, k = mae(a, c) c2, p = ushiro(a, c) for i in c1: c3, k1 = mae(b, i[0]) ansl.append(k1 + i[1]) for i in c2: c3, k1 = ushiro(b, i[0]) ansl.append(k1 + i[1]) c1, k = mae(c, a) c2, p = ushiro(c, a) for i in c1: c3, k1 = mae(b, i[0]) ansl.append(k1 + i[1]) for i in c2: c3, k1 = ushiro(b, i[0]) ansl.append(k1 + i[1]) c1, k = mae(c, b) c2, p = ushiro(c, b) for i in c1: c3, k1 = mae(a, i[0]) ansl.append(k1 + i[1]) for i in c2: c3, k1 = ushiro(a, i[0]) ansl.append(k1 + i[1]) c1, k = mae(b, c) c2, p = ushiro(b, c) for i in c1: c3, k1 = mae(a, i[0]) ansl.append(k1 + i[1]) for i in c2: c3, k1 = ushiro(a, i[0]) ansl.append(k1 + i[1]) print(n0 + n1 + n2 - max(ansl))
Statement Snuke has a string s. From this string, Anuke, Bnuke, and Cnuke obtained strings a, b, and c, respectively, as follows: * Choose a non-empty (contiguous) substring of s (possibly s itself). Then, replace some characters (possibly all or none) in it with `?`s. For example, if s is `mississippi`, we can choose the substring `ssissip` and replace its 1-st and 3-rd characters with `?` to obtain `?s?ssip`. You are given the strings a, b, and c. Find the minimum possible length of s.
[{"input": "a?c\n der\n cod", "output": "7\n \n\nFor example, s could be `atcoder`.\n\n* * *"}, {"input": "atcoder\n atcoder\n ???????", "output": "7\n \n\na, b, and c may not be distinct."}]
For each question, print 1 if the text includes P_i, or print 0 otherwise.
s076140925
Accepted
p02250
In the first line, a text T is given. In the second line, an integer Q denoting the number of queries is given. In the following Q lines, the patterns P_i are given respectively.
from collections import Counter from math import floor, ceil, log from heapq import heapreplace, heappush import time class TreeIndex: class Node: __slots__ = ("level", "keys", "values", "keylen", "_cache", "_cacheq") def __init__(self, level): self.level = level self.values = [] self.keys = {} self.keylen = 2**self.level self._init_cache() def add(self, text, value): def _add(node, t): if len(t) == 0: node.values.append(value) return node pre = t[: node.keylen] post = t[node.keylen :] if pre not in node.keys: node.keys[pre] = self.__class__(node.level + 1) return _add(node.keys[pre], post) node = self._get_cache(text) if node is not None: _add(node, "") else: self._set_cache(text, _add(self, text)) def index(self, text): def _index(node, t): if len(t) == 0: return node pre = t[: node.keylen] post = t[node.keylen :] if pre in node.keys: return _index(node.keys[pre], post) else: return None node = self._get_cache(text) if node is not None: return node.values else: node = _index(self, text) if node is not None: self._set_cache(text, node) return node.values return [] def __contains__(self, text): if len(text) > self.keylen: pre = text[: self.keylen] post = text[self.keylen :] return pre in self.keys and post in self.keys[pre] else: return any(key.startswith(text) for key in self.keys) def _init_cache(self): self._cache = {} self._cacheq = [] def _set_cache(self, text, node): if text not in self._cache: if len(self._cacheq) > 65535: _, txt = heapreplace(self._cacheq, (time.clock(), text)) del self._cache[txt] else: heappush(self._cacheq, (time.clock(), text)) self._cache[text] = node def _get_cache(self, text): if text in self._cache: return self._cache[text] else: return None def __str__(self): return ( "(" + ",".join(["{}->{}".format(k, v) for k, v in self.keys.items()]) + ")" ) def __init__(self, text): self._keylen(text) self._create_index(text) def _keylen(self, text): chars = Counter(list(text)) ent = 0.0 total = len(text) base = len(chars) + 1 for c, cnt in chars.items(): p = cnt / total ent -= p * log(p, base) self.keylen = max(2 ** ceil(10 * (1 - ent)) - 1, 3) # print(ent, self.keylen) def _create_index(self, text): tree = self.Node(0) length = len(text) for i in range(length): tree.add(text[i : i + self.keylen], i) self.tree = tree self.text = text # print('key length = {}'.format(self.keylen)) # print(self.tree) def match(self, search_text): def _match_partial(lo, hi): # print('match partial', lo, hi, search_text[lo:hi]) split = self.keylen if search_text[lo + split : hi] in self.tree: for i in self.tree.index(search_text[lo : lo + split]): if ( self.text[i + split : i + hi - lo] == search_text[lo + split : hi] ): yield i def _match(lo, hi): length = hi - lo if length == self.keylen: # print('match index', lo, hi) return (i for i in self.tree.index(search_text[lo:hi])) if length < self.keylen * 2: return _match_partial(lo, hi) mid = lo + length // 2 pre = _match(lo, mid) post = _match(mid, hi) return _merge(pre, post, mid - lo) def _merge(idx1, idx2, shift): i2 = next(idx2) for i1 in idx1: while i1 + shift > i2: i2 = next(idx2) if i1 + shift == i2: # print('match!', i1, self.text[i1:i1+length], search_text) yield i1 length = len(search_text) if length < self.keylen: return search_text in self.tree # align by key length k = floor(log(length / self.keylen, 2)) b = self.keylen * 2**k if length - self.keylen < b < length and k > 0: b = self.keylen * 2 ** (k - 1) try: if b + self.keylen < length: match = _merge(_match(0, b), _match(b, length), b) else: match = _match(0, length) next(match) return True except StopIteration: return False def run(): s1 = input() n = int(input()) index = TreeIndex(s1) for _ in range(n): s2 = input() if index.match(s2): print(1) else: print(0) if __name__ == "__main__": run()
String Search Determine whether a text T includes a pattern P. Your program should answer for given queries consisting of P_i.
[{"input": "aabaaa\n 4\n aa\n ba\n bb\n xyz", "output": "1\n 1\n 0\n 0"}]
For each question, print 1 if the text includes P_i, or print 0 otherwise.
s079221469
Wrong Answer
p02250
In the first line, a text T is given. In the second line, an integer Q denoting the number of queries is given. In the following Q lines, the patterns P_i are given respectively.
T = input() n = int(input()) for i in range(n): P = input() if T in P: print(1) else: print(0)
String Search Determine whether a text T includes a pattern P. Your program should answer for given queries consisting of P_i.
[{"input": "aabaaa\n 4\n aa\n ba\n bb\n xyz", "output": "1\n 1\n 0\n 0"}]
For each question, print 1 if the text includes P_i, or print 0 otherwise.
s195358614
Wrong Answer
p02250
In the first line, a text T is given. In the second line, an integer Q denoting the number of queries is given. In the following Q lines, the patterns P_i are given respectively.
# coding: utf-8 original_string = list(map(ord, list(input()))) check_string_count = int(input()) checkers = [list(map(ord, list(input()))) for i in range(check_string_count)] for checker in checkers: found = False sum_of_checker = sum(checker) if len(checker) > len(original_string): print(0) continue for index in range(0, len(original_string)): if (len(original_string) - len(checker)) < index: break if original_string[index] == checker[0]: found = True sum_of_origin = sum(original_string[index : index + len(checker)]) if sum_of_origin != sum_of_checker: found = False if found: print(1) break if not found: print(0)
String Search Determine whether a text T includes a pattern P. Your program should answer for given queries consisting of P_i.
[{"input": "aabaaa\n 4\n aa\n ba\n bb\n xyz", "output": "1\n 1\n 0\n 0"}]
Print the maximum number of pairs that can be created. * * *
s316268437
Accepted
p03912
The input is given from Standard Input in the following format: N M X_1 X_2 ... X_N
import sys input = sys.stdin.buffer.readline def getN(): return int(input()) def getNM(): return map(int, input().split()) def getlist(): return list(map(int, input().split())) import math import heapq from collections import defaultdict, Counter, deque MOD = 10**9 + 7 INF = 10**15 def main(): n, m = getlist() nums = getlist() cnt = Counter(nums) mod = [0 for i in range(m)] same = [0 for i in range(m)] for k, v in cnt.items(): mod[k % m] += v same[k % m] += v // 2 ans = mod[0] // 2 for i in range(1, int((m + 2) // 2)): if i == m / 2: ans += mod[i] // 2 else: other = m - i ans += min(mod[i], mod[other]) if mod[i] > mod[other]: ans += min(same[i], (mod[i] - mod[other]) // 2) if mod[i] < mod[other]: ans += min(same[other], -(mod[i] - mod[other]) // 2) print(ans) # print(same, mod) if __name__ == "__main__": main() """ 9999 3 2916 """
Statement Takahashi is playing with N cards. The i-th card has an integer X_i on it. Takahashi is trying to create as many pairs of cards as possible satisfying one of the following conditions: * The integers on the two cards are the same. * The sum of the integers on the two cards is a multiple of M. Find the maximum number of pairs that can be created. Note that a card cannot be used in more than one pair.
[{"input": "7 5\n 3 1 4 1 5 9 2", "output": "3\n \n\nThree pairs (3,2), (1,4) and (1,9) can be created.\n\nIt is possible to create pairs (3,2) and (1,1), but the number of pairs is not\nmaximized with this.\n\n* * *"}, {"input": "15 10\n 1 5 6 10 11 11 11 20 21 25 25 26 99 99 99", "output": "6"}]
Print the maximum number of pairs that can be created. * * *
s542079943
Accepted
p03912
The input is given from Standard Input in the following format: N M X_1 X_2 ... X_N
from collections import defaultdict printn = lambda x: print(x, end="") inn = lambda: int(input()) inl = lambda: list(map(int, input().split())) inm = lambda: map(int, input().split()) ins = lambda: input().strip() DBG = True # and False BIG = 10**18 R = 10**9 + 7 def ddprint(x): if DBG: print(x) n, m = inm() x = inl() h = defaultdict(int) for y in x: h[y] += 1 od = [0] * m ev = [0] * m for y in h: od[y % m] += h[y] % 2 ev[y % m] += h[y] - h[y] % 2 ans = (ev[0] + od[0]) // 2 if m % 2 == 0: ans += (ev[m // 2] + od[m // 2]) // 2 for i in range(1, m // 2 + m % 2): a = od[i] b = ev[i] c = od[m - i] d = ev[m - i] if a > c + d: ans += c + d + b // 2 elif c > a + b: ans += a + b + d // 2 else: ans += (a + b + c + d) // 2 print(ans)
Statement Takahashi is playing with N cards. The i-th card has an integer X_i on it. Takahashi is trying to create as many pairs of cards as possible satisfying one of the following conditions: * The integers on the two cards are the same. * The sum of the integers on the two cards is a multiple of M. Find the maximum number of pairs that can be created. Note that a card cannot be used in more than one pair.
[{"input": "7 5\n 3 1 4 1 5 9 2", "output": "3\n \n\nThree pairs (3,2), (1,4) and (1,9) can be created.\n\nIt is possible to create pairs (3,2) and (1,1), but the number of pairs is not\nmaximized with this.\n\n* * *"}, {"input": "15 10\n 1 5 6 10 11 11 11 20 21 25 25 26 99 99 99", "output": "6"}]
Print the maximum number of pairs that can be created. * * *
s275427332
Accepted
p03912
The input is given from Standard Input in the following format: N M X_1 X_2 ... X_N
from collections import Counter N, M = map(int, input().split()) X = list(map(int, input().split())) Xremainder = [x % M for x in X] Xcount = Counter(X) Xremaindercount = Counter(Xremainder) # print(Xcount) # print(Xremaindercount) # 余りが0のものは2個ずつとって1組に answer = Xremaindercount[0] // 2 Xremaindercount[0] -= (Xremaindercount[0] // 2) * 2 # print(answer) if M % 2 == 0: # Mが偶数のとき、余りがM//2のものは余り0のものと同様に扱える limit = int(M // 2) answer += Xremaindercount[M // 2] // 2 Xremaindercount[M // 2] -= (Xremaindercount[M // 2] // 2) * 2 else: limit = int(M // 2 + 1) for i in range(1, limit): # 余りがiとM-iのものを組み合わせるとMの倍数の組ができる s = Xremaindercount[i] t = Xremaindercount[M - i] answer += min(s, t) Xremaindercount[i] -= min(s, t) Xremaindercount[M - i] -= min(s, t) # print(Xremaindercount) # print(answer) for i in Xcount: # 余りで組み合わせた後,同じ数同士のものが残り得るかを判定し、残っていたら組み合わせる if Xremaindercount[i % M] >= 2 and Xcount[i] >= 2: answer += min(Xremaindercount[i % M], Xcount[i]) // 2 Xremaindercount[i % M] -= (min(Xremaindercount[i % M], Xcount[i]) // 2) * 2 print(answer)
Statement Takahashi is playing with N cards. The i-th card has an integer X_i on it. Takahashi is trying to create as many pairs of cards as possible satisfying one of the following conditions: * The integers on the two cards are the same. * The sum of the integers on the two cards is a multiple of M. Find the maximum number of pairs that can be created. Note that a card cannot be used in more than one pair.
[{"input": "7 5\n 3 1 4 1 5 9 2", "output": "3\n \n\nThree pairs (3,2), (1,4) and (1,9) can be created.\n\nIt is possible to create pairs (3,2) and (1,1), but the number of pairs is not\nmaximized with this.\n\n* * *"}, {"input": "15 10\n 1 5 6 10 11 11 11 20 21 25 25 26 99 99 99", "output": "6"}]
Print the maximum number of pairs that can be created. * * *
s061386522
Wrong Answer
p03912
The input is given from Standard Input in the following format: N M X_1 X_2 ... X_N
import collections n, m = map(int, input().split()) arr = list(map(int, input().split())) cnt = collections.Counter(arr) cnt1 = collections.defaultdict(int) cnt2 = collections.defaultdict(int) for key in cnt.keys(): tmp = key % m val = cnt[key] if val % 2 == 0: cnt2[tmp] += val else: cnt1[tmp] += 1 cnt2[tmp] += val - 1 ans = 0 for i in range(m): l = i r = (m - i) % m if l > r: break elif l == r: ans += (cnt1[l] + cnt2[l]) // 2 else: ans += min(cnt1[l], cnt1[r]) if cnt1[l] == cnt1[r]: ans += min(cnt2[l], cnt2[r]) if cnt2[l] == cnt2[r]: continue elif cnt2[l] < cnt2[r]: ans += (cnt2[r] - cnt2[l]) // 2 else: ans += (cnt2[l] - cnt2[r]) // 2 elif cnt1[l] < cnt1[r]: ans += min(cnt2[l], cnt1[r]) if cnt2[l] <= cnt1[r]: ans += cnt2[r] // 2 else: cnt2[l] -= cnt1[r] ans += min(cnt2[l], cnt2[r]) if cnt2[l] == cnt2[r]: continue elif cnt2[l] < cnt2[r]: ans += (cnt2[r] - cnt2[l]) // 2 else: ans += (cnt2[l] - cnt2[r]) // 2 else: ans += min(cnt1[l], cnt2[r]) if cnt2[r] <= cnt1[l]: ans += cnt2[l] // 2 else: cnt2[r] -= cnt1[l] ans += min(cnt2[l], cnt2[r]) if cnt2[l] == cnt2[r]: continue elif cnt2[l] < cnt2[r]: ans += (cnt2[r] - cnt2[l]) // 2 else: ans += (cnt2[l] - cnt2[r]) // 2 print(ans)
Statement Takahashi is playing with N cards. The i-th card has an integer X_i on it. Takahashi is trying to create as many pairs of cards as possible satisfying one of the following conditions: * The integers on the two cards are the same. * The sum of the integers on the two cards is a multiple of M. Find the maximum number of pairs that can be created. Note that a card cannot be used in more than one pair.
[{"input": "7 5\n 3 1 4 1 5 9 2", "output": "3\n \n\nThree pairs (3,2), (1,4) and (1,9) can be created.\n\nIt is possible to create pairs (3,2) and (1,1), but the number of pairs is not\nmaximized with this.\n\n* * *"}, {"input": "15 10\n 1 5 6 10 11 11 11 20 21 25 25 26 99 99 99", "output": "6"}]
Print the maximum number of pairs that can be created. * * *
s235210512
Wrong Answer
p03912
The input is given from Standard Input in the following format: N M X_1 X_2 ... X_N
from collections import Counter as c n, m = map(int, input().split()) a = list(map(int, input().split())) b = c(a) d = [0] * m e = [0] * m for i in b.keys(): t = b[i] d[i % m] += t e[i % m] += t // 2 z = 0 for i in range(1, m // 2): x, y = d[i], d[-i] if x > y: z += d[-i] + min(e[i], (d[i] - d[-i]) // 2) else: z += d[i] + min(e[-i], (d[-i] - d[i]) // 2) if m % 2 == 0: z += d[m // 2] // 2 z += d[0] // 2 print(z)
Statement Takahashi is playing with N cards. The i-th card has an integer X_i on it. Takahashi is trying to create as many pairs of cards as possible satisfying one of the following conditions: * The integers on the two cards are the same. * The sum of the integers on the two cards is a multiple of M. Find the maximum number of pairs that can be created. Note that a card cannot be used in more than one pair.
[{"input": "7 5\n 3 1 4 1 5 9 2", "output": "3\n \n\nThree pairs (3,2), (1,4) and (1,9) can be created.\n\nIt is possible to create pairs (3,2) and (1,1), but the number of pairs is not\nmaximized with this.\n\n* * *"}, {"input": "15 10\n 1 5 6 10 11 11 11 20 21 25 25 26 99 99 99", "output": "6"}]
Print the maximum number of pairs that can be created. * * *
s452516789
Accepted
p03912
The input is given from Standard Input in the following format: N M X_1 X_2 ... X_N
MIS = lambda: map(int, input().split()) def match(L, R): # print(L, R) L.sort() R.sort() match = 0 lself = rself = 0 lrem = rrem = 0 while L: if len(L) >= 2 and L[-1] == L[-2]: lself += 1 match += 1 L.pop() L.pop() else: lrem += 1 L.pop() while R: if len(R) >= 2 and R[-1] == R[-2]: rself += 1 match += 1 R.pop() R.pop() else: rrem += 1 R.pop() while lrem and rrem: lrem -= 1 rrem -= 1 match += 1 while lrem >= 2 and rself: lrem -= 2 rself -= 1 match += 1 while rrem >= 2 and lself: rrem -= 2 lself -= 1 match += 1 return match n, m = MIS() card = [[] for i in range(m)] for x in MIS(): card[x % m].append(x // m) tot = len(card[0]) // 2 for i in range(1, (m + 1) // 2): tot += match(card[i], card[m - i]) if m % 2 == 0: tot += len(card[m // 2]) // 2 print(tot)
Statement Takahashi is playing with N cards. The i-th card has an integer X_i on it. Takahashi is trying to create as many pairs of cards as possible satisfying one of the following conditions: * The integers on the two cards are the same. * The sum of the integers on the two cards is a multiple of M. Find the maximum number of pairs that can be created. Note that a card cannot be used in more than one pair.
[{"input": "7 5\n 3 1 4 1 5 9 2", "output": "3\n \n\nThree pairs (3,2), (1,4) and (1,9) can be created.\n\nIt is possible to create pairs (3,2) and (1,1), but the number of pairs is not\nmaximized with this.\n\n* * *"}, {"input": "15 10\n 1 5 6 10 11 11 11 20 21 25 25 26 99 99 99", "output": "6"}]