output_description
stringlengths
15
956
submission_id
stringlengths
10
10
status
stringclasses
3 values
problem_id
stringlengths
6
6
input_description
stringlengths
9
2.55k
attempt
stringlengths
1
13.7k
problem_description
stringlengths
7
5.24k
samples
stringlengths
2
2.72k
Print the K-th smallest integer in the array after the N operations. * * *
s229333959
Runtime Error
p03721
Input is given from Standard Input in the following format: N K a_1 b_1 : a_N b_N
n,k=map(int,input().split()) ab=[[int(i) for i in input().split()]for j in range(n)] dic={} for a,b in ab: if a in dic: dic[a]+=j else: dic[a]=j dic=sorted(dic.items() , key=lambda x:x[0]) check=0 for i,j in dic: check+=j if check>=k print(i) break
Statement There is an empty array. The following N operations will be performed to insert integers into the array. In the i-th operation (1≤i≤N), b_i copies of an integer a_i are inserted into the array. Find the K-th smallest integer in the array after the N operations. For example, the 4-th smallest integer in the array \\{1,2,2,3,3,3\\} is 3.
[{"input": "3 4\n 1 1\n 2 2\n 3 3", "output": "3\n \n\nThe resulting array is the same as the one in the problem statement.\n\n* * *"}, {"input": "10 500000\n 1 100000\n 1 100000\n 1 100000\n 1 100000\n 1 100000\n 100000 100000\n 100000 100000\n 100000 100000\n 100000 100000\n 100000 100000", "output": "1"}]
Print the K-th smallest integer in the array after the N operations. * * *
s436572148
Runtime Error
p03721
Input is given from Standard Input in the following format: N K a_1 b_1 : a_N b_N
N, K = [int(x) for x in input().split()] Array = list() A = list() count = 0 ans = 0 for i in range(N): A.append[int(x) for x in input().split()] A.sort(key=itemgetter(0), reverse=True) for i in range(N): count += A[1, i] if count >= K: ans = A[0, i] break print(ans)
Statement There is an empty array. The following N operations will be performed to insert integers into the array. In the i-th operation (1≤i≤N), b_i copies of an integer a_i are inserted into the array. Find the K-th smallest integer in the array after the N operations. For example, the 4-th smallest integer in the array \\{1,2,2,3,3,3\\} is 3.
[{"input": "3 4\n 1 1\n 2 2\n 3 3", "output": "3\n \n\nThe resulting array is the same as the one in the problem statement.\n\n* * *"}, {"input": "10 500000\n 1 100000\n 1 100000\n 1 100000\n 1 100000\n 1 100000\n 100000 100000\n 100000 100000\n 100000 100000\n 100000 100000\n 100000 100000", "output": "1"}]
Print the K-th smallest integer in the array after the N operations. * * *
s919290003
Runtime Error
p03721
Input is given from Standard Input in the following format: N K a_1 b_1 : a_N b_N
mport numpy as np N,K = list(map(int,input().split())) a = [] array = np.array([]) for i in range(N): a = list(map(int,input().split())) array = np.concatenate((array,a[0]*np.ones(a[1]))) print (array) array = np.sort(array) print (int(array[K-1]))
Statement There is an empty array. The following N operations will be performed to insert integers into the array. In the i-th operation (1≤i≤N), b_i copies of an integer a_i are inserted into the array. Find the K-th smallest integer in the array after the N operations. For example, the 4-th smallest integer in the array \\{1,2,2,3,3,3\\} is 3.
[{"input": "3 4\n 1 1\n 2 2\n 3 3", "output": "3\n \n\nThe resulting array is the same as the one in the problem statement.\n\n* * *"}, {"input": "10 500000\n 1 100000\n 1 100000\n 1 100000\n 1 100000\n 1 100000\n 100000 100000\n 100000 100000\n 100000 100000\n 100000 100000\n 100000 100000", "output": "1"}]
Print the K-th smallest integer in the array after the N operations. * * *
s165182612
Wrong Answer
p03721
Input is given from Standard Input in the following format: N K a_1 b_1 : a_N b_N
table = input().split() N, K = int(table[0]), int(table[1]) preA, preB = [], [] l = 1 while l <= N: a = input().split() a = list(map(int, a)) if sum(preB) < K: preA += [a[0]] preB += [a[1]] l += 1 print(preA[-1])
Statement There is an empty array. The following N operations will be performed to insert integers into the array. In the i-th operation (1≤i≤N), b_i copies of an integer a_i are inserted into the array. Find the K-th smallest integer in the array after the N operations. For example, the 4-th smallest integer in the array \\{1,2,2,3,3,3\\} is 3.
[{"input": "3 4\n 1 1\n 2 2\n 3 3", "output": "3\n \n\nThe resulting array is the same as the one in the problem statement.\n\n* * *"}, {"input": "10 500000\n 1 100000\n 1 100000\n 1 100000\n 1 100000\n 1 100000\n 100000 100000\n 100000 100000\n 100000 100000\n 100000 100000\n 100000 100000", "output": "1"}]
Print the K-th smallest integer in the array after the N operations. * * *
s340112514
Runtime Error
p03721
Input is given from Standard Input in the following format: N K a_1 b_1 : a_N b_N
[ [ print( ab[ [ index for index in [ SumI if NK[1] <= sum([ab[1][I] for I in range(SumI)]) else -1 for SumI in range(NK[0]) ] if index != -1 ][0] ][0] ) for ab in [ sorted( [list(map(int, (input().split()))) for i in range(NK[0])], key=lambda x: x[0], ) ] ] for NK in [list(map(int, (input().split())))] ]
Statement There is an empty array. The following N operations will be performed to insert integers into the array. In the i-th operation (1≤i≤N), b_i copies of an integer a_i are inserted into the array. Find the K-th smallest integer in the array after the N operations. For example, the 4-th smallest integer in the array \\{1,2,2,3,3,3\\} is 3.
[{"input": "3 4\n 1 1\n 2 2\n 3 3", "output": "3\n \n\nThe resulting array is the same as the one in the problem statement.\n\n* * *"}, {"input": "10 500000\n 1 100000\n 1 100000\n 1 100000\n 1 100000\n 1 100000\n 100000 100000\n 100000 100000\n 100000 100000\n 100000 100000\n 100000 100000", "output": "1"}]
Print the number of trailing zeros in the decimal notation of f(N). * * *
s337499511
Wrong Answer
p02833
Input is given from Standard Input in the following format: N
import math N = int(input()) a1 = N // 10 a2 = N // 100 a3 = N // 1000 a4 = N // 10000 a5 = N // 100000 a6 = N // 1000000 a7 = N // 10000000 a8 = N // 100000000 a9 = N // 1000000000 a10 = N // 10000000000 a11 = N // 100000000000 a12 = N // 1000000000000 a13 = N // 10000000000000 a14 = N // 100000000000000 a15 = N // 1000000000000000 a16 = N // 10000000000000000 a17 = N // 100000000000000000 a18 = N // 1000000000000000000 a19 = N // 10000000000000000000 b1 = (N // 50) - a2 b2 = (N // 250) - a3 - a2 b3 = (N // 1250) - a4 - a3 - a2 b4 = (N // (5**4) * 10) - a5 - a4 - a3 - a2 b5 = math.ceil(N // (5**5) * 10) - a6 - a5 - a4 - a3 - a2 b6 = math.ceil(N // (5**6) * 10) - a7 - a6 - a5 - a4 - a3 - a2 b7 = math.ceil(N // (5**7) * 10) - a8 - a7 - a6 - a5 - a4 - a3 - a2 b8 = math.ceil(N // (5**8) * 10) - a9 - a8 - a7 - a6 - a5 - a4 - a3 - a2 b9 = math.ceil(N // (5**9) * 10) - a10 - a9 - a8 - a7 - a6 - a5 - a4 - a3 - a2 b10 = math.ceil(N // (5**10) * 10) - a11 - a10 - a9 - a8 - a7 - a6 - a5 - a4 - a3 - a2 b11 = ( math.ceil(N // (5**11) * 10) - a12 - a11 - a10 - a9 - a8 - a7 - a6 - a5 - a4 - a3 - a2 ) b12 = ( math.ceil(N // (5**12) * 10) - a13 - a12 - a11 - a10 - a9 - a8 - a7 - a6 - a5 - a4 - a3 - a2 ) b13 = ( math.ceil(N // (5**13) * 10) - a14 - a13 - a12 - a11 - a10 - a9 - a8 - a7 - a6 - a5 - a4 - a3 - a2 ) b14 = ( math.ceil(N // (5**14) * 10) - a15 - a14 - a13 - a12 - a11 - a10 - a9 - a8 - a7 - a6 - a5 - a4 - a3 - a2 ) b15 = ( math.ceil(N // (5**15) * 10) - a16 - a15 - a14 - a13 - a12 - a11 - a10 - a9 - a8 - a7 - a6 - a5 - a4 - a3 - a2 ) b16 = ( math.ceil(N // (5**16) * 10) - a17 - a16 - a15 - a14 - a13 - a12 - a11 - a10 - a9 - a8 - a7 - a6 - a5 - a4 - a3 - a2 ) b17 = ( math.ceil(N // (5**17) * 10) - a18 - a17 - a16 - a15 - a14 - a13 - a12 - a11 - a10 - a9 - a8 - a7 - a6 - a5 - a4 - a3 - a2 ) b18 = ( math.ceil(N // (5**18) * 10) - a19 - a18 - a17 - a16 - a15 - a14 - a13 - a12 - a11 - a10 - a9 - a8 - a7 - a6 - a5 - a4 - a3 - a2 ) ans = ( a1 * 1 + a2 * 1 + a3 * 1 + a4 * 1 + a5 * 1 + a6 * 1 + a7 * 1 + a8 * 1 + a9 * 1 + a10 * 1 + a11 * 1 + a12 * 1 + a13 * 1 + a14 * 1 + a15 * 1 + a16 * 1 + a17 * 1 + a18 * 1 + a19 * 1 ) ans = ( ans + b1 * 1 + b2 * 1 + b3 * 1 + b4 * 1 + b5 * 1 + b6 * 1 + b7 * 1 + b8 * 1 + b9 * 1 + b10 * 1 + b11 * 1 + b12 * 1 + b13 * 1 + b14 * 1 + b15 * 1 + b16 * 1 + b17 * 1 + b18 * 1 ) if N % 2 == 1: print(0) else: print(ans)
Statement For an integer n not less than 0, let us define f(n) as follows: * f(n) = 1 (if n < 2) * f(n) = n f(n-2) (if n \geq 2) Given is an integer N. Find the number of trailing zeros in the decimal notation of f(N).
[{"input": "12", "output": "1\n \n\nf(12) = 12 \u00d7 10 \u00d7 8 \u00d7 6 \u00d7 4 \u00d7 2 = 46080, which has one trailing zero.\n\n* * *"}, {"input": "5", "output": "0\n \n\nf(5) = 5 \u00d7 3 \u00d7 1 = 15, which has no trailing zeros.\n\n* * *"}, {"input": "1000000000000000000", "output": "124999999999999995"}]
Print the number of trailing zeros in the decimal notation of f(N). * * *
s525557546
Wrong Answer
p02833
Input is given from Standard Input in the following format: N
N = int(input()) ########################################### ########################################### def factorization(n): # 素因数分解 arr = [] temp = n for i in range(2, int(-(-(n**0.5) // 1)) + 1): if temp % i == 0: cnt = 0 while temp % i == 0: cnt += 1 temp //= i arr.append([i, cnt]) if temp != 1: arr.append([temp, 1]) if arr == []: arr.append([n, 1]) return arr ########################################### ########################################### count = N // 2 # 切り捨て除算 # 素因数分解して2と5の少ない方選べばよい。 # 素因数分解して2と5の少ない方選べばよい。 # 素因数分解して2と5の少ない方選べばよい。 # 素因数分解して2と5の少ない方選べばよい。 # 素因数分解して2と5の少ない方選べばよい。 # 素因数分解して2と5の少ない方選べばよい。 # 素因数分解して2と5の少ない方選べばよい。 # 素因数分解して2と5の少ない方選べばよい。 # 素因数分解して2と5の少ない方選べばよい。 # 素因数分解して2と5の少ない方選べばよい。 # 素因数分解して2と5の少ない方選べばよい。 # 素因数分解して2と5の少ない方選べばよい。 AN5 = 0 AN2 = 0 for i in range(count): cal = N - i * 2 AN1 = factorization(cal) try: if AN1[0][0] == 2: AN2 = AN2 + AN1[0][1] except: kari = 1 try: if AN1[0][0] == 5: AN5 = AN5 + AN1[0][1] except: kari = 1 try: if AN1[1][0] == 2: AN2 = AN2 + AN1[1][1] except: kari = 1 try: if AN1[1][0] == 5: AN5 = AN5 + AN1[1][1] except: kari = 1 try: if AN1[2][0] == 2: AN2 = AN2 + AN1[2][1] except: kari = 1 try: if AN1[2][0] == 5: AN5 = AN5 + AN1[2][1] except: kari = 1 if AN2 < AN5: print(AN5) else: print(AN2)
Statement For an integer n not less than 0, let us define f(n) as follows: * f(n) = 1 (if n < 2) * f(n) = n f(n-2) (if n \geq 2) Given is an integer N. Find the number of trailing zeros in the decimal notation of f(N).
[{"input": "12", "output": "1\n \n\nf(12) = 12 \u00d7 10 \u00d7 8 \u00d7 6 \u00d7 4 \u00d7 2 = 46080, which has one trailing zero.\n\n* * *"}, {"input": "5", "output": "0\n \n\nf(5) = 5 \u00d7 3 \u00d7 1 = 15, which has no trailing zeros.\n\n* * *"}, {"input": "1000000000000000000", "output": "124999999999999995"}]
Print the number of trailing zeros in the decimal notation of f(N). * * *
s714752436
Accepted
p02833
Input is given from Standard Input in the following format: N
# coding: utf-8 # Your code here! import sys n = int(input()) if n % 2 == 1: print(0) sys.exit() if n < 2: print(0) sys.exit() l = list() # 2 * 5 l.append(10) # 2 * 5 * 5 l.append(50) # 2 * 5 * 5 * 5 l.append(250) # 2 * 5 * 5 * 5 * 5 l.append(1250) # 2 * 5 * 5 * 5 * 5 * 5 l.append(6250) # 2 * 5 * 5 * 5 * 5 * 5 * 5 l.append(31250) # 2 * 5 * 5 * 5 * 5 * 5 * 5 * 5 l.append(156250) # 2 * 5 * 5 * 5 * 5 * 5 * 5 * 5 * 5 l.append(781250) # 2 * 5 * 5 * 5 * 5 * 5 * 5 * 5 * 5 * 5 l.append(3906250) # 2 * 5 * 5 * 5 * 5 * 5 * 5 * 5 * 5 * 5 * 5 l.append(19531250) # 2 * 5 * 5 * 5 * 5 * 5 * 5 * 5 * 5 * 5 * 5 * 5 l.append(97656250) # 2 * 5 * 5 * 5 * 5 * 5 * 5 * 5 * 5 * 5 * 5 * 5 * 5 l.append(488281250) # 2 * 5 * 5 * 5 * 5 * 5 * 5 * 5 * 5 * 5 * 5 * 5 * 5 * 5 l.append(2441406250) # 2 * 5 * 5 * 5 * 5 * 5 * 5 * 5 * 5 * 5 * 5 * 5 * 5 * 5 * 5 l.append(12207031250) # 2 * 5 * 5 * 5 * 5 * 5 * 5 * 5 * 5 * 5 * 5 * 5 * 5 * 5 * 5 * 5 l.append(61035156250) # 2 * 5 * 5 * 5 * 5 * 5 * 5 * 5 * 5 * 5 * 5 * 5 * 5 * 5 * 5 * 5 * 5 l.append(305175781250) # 2 * 5 * 5 * 5 * 5 * 5 * 5 * 5 * 5 * 5 * 5 * 5 * 5 * 5 * 5 * 5 * 5 * 5 l.append(1525878906250) # 2 * 5 * 5 * 5 * 5 * 5 * 5 * 5 * 5 * 5 * 5 * 5 * 5 * 5 * 5 * 5 * 5 * 5 * 5 l.append(7629394531250) # 2 * 5 * 5 * 5 * 5 * 5 * 5 * 5 * 5 * 5 * 5 * 5 * 5 * 5 * 5 * 5 * 5 * 5 * 5 * 5 l.append(38146972656250) # 2 * 5 * 5 * 5 * 5 * 5 * 5 * 5 * 5 * 5 * 5 * 5 * 5 * 5 * 5 * 5 * 5 * 5 * 5 * 5 * 5 l.append(190734863281250) # 2 * 5 * 5 * 5 * 5 * 5 * 5 * 5 * 5 * 5 * 5 * 5 * 5 * 5 * 5 * 5 * 5 * 5 * 5 * 5 * 5 * 5 l.append(953674316406250) # 2 * 5 * 5 * 5 * 5 * 5 * 5 * 5 * 5 * 5 * 5 * 5 * 5 * 5 * 5 * 5 * 5 * 5 * 5 * 5 * 5 * 5 * 5 l.append(4768371582031250) # 2 * 5 * 5 * 5 * 5 * 5 * 5 * 5 * 5 * 5 * 5 * 5 * 5 * 5 * 5 * 5 * 5 * 5 * 5 * 5 * 5 * 5 * 5 * 5 l.append(23841857910156200) # 2 * 5 * 5 * 5 * 5 * 5 * 5 * 5 * 5 * 5 * 5 * 5 * 5 * 5 * 5 * 5 * 5 * 5 * 5 * 5 * 5 * 5 * 5 * 5 * 5 l.append(119209289550781000) # 2 * 5 * 5 * 5 * 5 * 5 * 5 * 5 * 5 * 5 * 5 * 5 * 5 * 5 * 5 * 5 * 5 * 5 * 5 * 5 * 5 * 5 * 5 * 5 * 5 * 5 l.append(596046447753906000) result = 0 for a in l: result += n // a print(result)
Statement For an integer n not less than 0, let us define f(n) as follows: * f(n) = 1 (if n < 2) * f(n) = n f(n-2) (if n \geq 2) Given is an integer N. Find the number of trailing zeros in the decimal notation of f(N).
[{"input": "12", "output": "1\n \n\nf(12) = 12 \u00d7 10 \u00d7 8 \u00d7 6 \u00d7 4 \u00d7 2 = 46080, which has one trailing zero.\n\n* * *"}, {"input": "5", "output": "0\n \n\nf(5) = 5 \u00d7 3 \u00d7 1 = 15, which has no trailing zeros.\n\n* * *"}, {"input": "1000000000000000000", "output": "124999999999999995"}]
Print the number of trailing zeros in the decimal notation of f(N). * * *
s172965471
Wrong Answer
p02833
Input is given from Standard Input in the following format: N
N = int(input()) if N % 10 == 0: print(int(N / 10)) elif N % 10 == 1: print("0") elif N % 10 == 2: print(int((N - 2) / 10)) elif N % 10 == 3: print("0") elif N % 10 == 4: print(int((N - 4) / 10)) elif N % 10 == 5: print("0") elif N % 10 == 6: print(int((N - 6) / 10)) elif N % 10 == 7: print("0") elif N % 10 == 8: print(int((N - 8) / 10)) else: print("0")
Statement For an integer n not less than 0, let us define f(n) as follows: * f(n) = 1 (if n < 2) * f(n) = n f(n-2) (if n \geq 2) Given is an integer N. Find the number of trailing zeros in the decimal notation of f(N).
[{"input": "12", "output": "1\n \n\nf(12) = 12 \u00d7 10 \u00d7 8 \u00d7 6 \u00d7 4 \u00d7 2 = 46080, which has one trailing zero.\n\n* * *"}, {"input": "5", "output": "0\n \n\nf(5) = 5 \u00d7 3 \u00d7 1 = 15, which has no trailing zeros.\n\n* * *"}, {"input": "1000000000000000000", "output": "124999999999999995"}]
Print the number of trailing zeros in the decimal notation of f(N). * * *
s083604677
Wrong Answer
p02833
Input is given from Standard Input in the following format: N
n = float(input()) a = 0 if n % 2 == 1: print(0) else: a = n // 596046447753906250 a += n // 119209289550781250 a += n // 23841857910156250 a += n // 4768371582031250 a += n // 953674316406250 a += n // 190734863281250 a += n // 38146972656250 a += n // 7629394531250 a += n // 1525878906250 a += n // 305175781250 a += n // 305175781250 a += n // 12207031250 a += n // 2441406250 a += n // 488281250 a += n // 97656250 a += n // 19531250 a += n // 3906250 a += n // 781250 a += n // 156250 a += n // 31250 a += n // 6250 a += n // 1250 a += n // 250 a += n // 50 a += n // 10 print(a)
Statement For an integer n not less than 0, let us define f(n) as follows: * f(n) = 1 (if n < 2) * f(n) = n f(n-2) (if n \geq 2) Given is an integer N. Find the number of trailing zeros in the decimal notation of f(N).
[{"input": "12", "output": "1\n \n\nf(12) = 12 \u00d7 10 \u00d7 8 \u00d7 6 \u00d7 4 \u00d7 2 = 46080, which has one trailing zero.\n\n* * *"}, {"input": "5", "output": "0\n \n\nf(5) = 5 \u00d7 3 \u00d7 1 = 15, which has no trailing zeros.\n\n* * *"}, {"input": "1000000000000000000", "output": "124999999999999995"}]
Print the number of trailing zeros in the decimal notation of f(N). * * *
s635546703
Accepted
p02833
Input is given from Standard Input in the following format: N
L = [ 10, 50, 250, 1250, 6250, 31250, 156250, 781250, 3906250, 19531250, 97656250, 488281250, 2441406250, 12207031250, 61035156250, 305175781250, 1525878906250, 7629394531250, 38146972656250, 190734863281250, 953674316406250, 4768371582031250, 23841857910156250, 119209289550781250, 596046447753906250, ] N = int(input()) A = 0 if N % 2 == 0: for i in L: A += N // i print(A)
Statement For an integer n not less than 0, let us define f(n) as follows: * f(n) = 1 (if n < 2) * f(n) = n f(n-2) (if n \geq 2) Given is an integer N. Find the number of trailing zeros in the decimal notation of f(N).
[{"input": "12", "output": "1\n \n\nf(12) = 12 \u00d7 10 \u00d7 8 \u00d7 6 \u00d7 4 \u00d7 2 = 46080, which has one trailing zero.\n\n* * *"}, {"input": "5", "output": "0\n \n\nf(5) = 5 \u00d7 3 \u00d7 1 = 15, which has no trailing zeros.\n\n* * *"}, {"input": "1000000000000000000", "output": "124999999999999995"}]
Print the number of trailing zeros in the decimal notation of f(N). * * *
s260667259
Wrong Answer
p02833
Input is given from Standard Input in the following format: N
N = int(input()) two = 2 two_cnt = 0 while two <= N: two_cnt += (N // two) // 2 two *= 2 five = 5 five_cnt = 0 while five <= N: five_cnt += (N // five) // 2 five *= 5 print(min(two_cnt, five_cnt))
Statement For an integer n not less than 0, let us define f(n) as follows: * f(n) = 1 (if n < 2) * f(n) = n f(n-2) (if n \geq 2) Given is an integer N. Find the number of trailing zeros in the decimal notation of f(N).
[{"input": "12", "output": "1\n \n\nf(12) = 12 \u00d7 10 \u00d7 8 \u00d7 6 \u00d7 4 \u00d7 2 = 46080, which has one trailing zero.\n\n* * *"}, {"input": "5", "output": "0\n \n\nf(5) = 5 \u00d7 3 \u00d7 1 = 15, which has no trailing zeros.\n\n* * *"}, {"input": "1000000000000000000", "output": "124999999999999995"}]
If X is less than A, print 0; if X is not less than A, print 10. * * *
s144695910
Wrong Answer
p02999
Input is given from Standard Input in the following format: X A
x, a = map(int, input().split()) print("0") if x < a else print("10") cons = 10**7 def primes(n): is_prime = [True] * (n + 1) is_prime[0] = False is_prime[1] = False for i in range(2, int(n**0.5) + 1): if not is_prime[i]: continue for j in range(i * 2, n + 1, i): is_prime[j] = False return [i for i in range(n + 1) if is_prime[i]] print(primes(cons))
Statement X and A are integers between 0 and 9 (inclusive). If X is less than A, print 0; if X is not less than A, print 10.
[{"input": "3 5", "output": "0\n \n\n3 is less than 5, so we should print 0.\n\n* * *"}, {"input": "7 5", "output": "10\n \n\n7 is not less than 5, so we should print 10.\n\n* * *"}, {"input": "6 6", "output": "10\n \n\n6 is not less than 6, so we should print 10."}]
If X is less than A, print 0; if X is not less than A, print 10. * * *
s127146231
Runtime Error
p02999
Input is given from Standard Input in the following format: X A
a, b, c, d, e, f = [], [], [], [], [], [] INF = 10**9 for i in range(int(input())): s, t, u = map(str, input().split()) if u == "R": a.append(int(s)) e.append(int(t)) elif u == "L": c.append(int(s)) e.append(int(t)) elif u == "U": d.append(int(t)) b.append(int(s)) else: f.append(int(t)) b.append(int(s)) l = 10**8 + 1 r = 0 a1, a2 = max(a + [-INF]), min(a + [INF]) b1, b2 = max(b + [-INF]), min(b + [INF]) c1, c2 = max(c + [-INF]), min(c + [INF]) d1, d2 = max(d + [-INF]), min(d + [INF]) e1, e2 = max(e + [-INF]), min(e + [INF]) f1, f2 = max(f + [-INF]), min(f + [INF]) p, q = 10, 1 while l - r > 10**-8: x2 = (l * 2 + r) / 3 x1 = (l + r * 2) / 3 s1, s2 = max(a1 + x2, b1, c1 - x2), min(a2 + x2, b2, c2 - x2) t1, t2 = max(d1 + x2, e1, f1 - x2), min(d2 + x2, e2, f2 - x2) u1, u2 = max(a1 + x1, b1, c1 - x1), min(a2 + x1, b2, c2 - x1) v1, v2 = max(d1 + x1, e1, f1 - x1), min(d2 + x1, e2, f2 - x1) p, q = (s1 - s2) * (t1 - t2), (u1 - u2) * (v1 - v2) if (s1 - s2) * (t1 - t2) <= (u1 - u2) * (v1 - v2): r = x1 else: l = x2 print(p)
Statement X and A are integers between 0 and 9 (inclusive). If X is less than A, print 0; if X is not less than A, print 10.
[{"input": "3 5", "output": "0\n \n\n3 is less than 5, so we should print 0.\n\n* * *"}, {"input": "7 5", "output": "10\n \n\n7 is not less than 5, so we should print 10.\n\n* * *"}, {"input": "6 6", "output": "10\n \n\n6 is not less than 6, so we should print 10."}]
If X is less than A, print 0; if X is not less than A, print 10. * * *
s676623471
Wrong Answer
p02999
Input is given from Standard Input in the following format: X A
x, a = [int(i) for i in input().split()] # n=int(input()) print(10 if a < x else 0)
Statement X and A are integers between 0 and 9 (inclusive). If X is less than A, print 0; if X is not less than A, print 10.
[{"input": "3 5", "output": "0\n \n\n3 is less than 5, so we should print 0.\n\n* * *"}, {"input": "7 5", "output": "10\n \n\n7 is not less than 5, so we should print 10.\n\n* * *"}, {"input": "6 6", "output": "10\n \n\n6 is not less than 6, so we should print 10."}]
If X is less than A, print 0; if X is not less than A, print 10. * * *
s769588243
Accepted
p02999
Input is given from Standard Input in the following format: X A
N, M = map(int, input().split()) print(("0", "10")[N >= M])
Statement X and A are integers between 0 and 9 (inclusive). If X is less than A, print 0; if X is not less than A, print 10.
[{"input": "3 5", "output": "0\n \n\n3 is less than 5, so we should print 0.\n\n* * *"}, {"input": "7 5", "output": "10\n \n\n7 is not less than 5, so we should print 10.\n\n* * *"}, {"input": "6 6", "output": "10\n \n\n6 is not less than 6, so we should print 10."}]
If X is less than A, print 0; if X is not less than A, print 10. * * *
s900525408
Wrong Answer
p02999
Input is given from Standard Input in the following format: X A
print(10)
Statement X and A are integers between 0 and 9 (inclusive). If X is less than A, print 0; if X is not less than A, print 10.
[{"input": "3 5", "output": "0\n \n\n3 is less than 5, so we should print 0.\n\n* * *"}, {"input": "7 5", "output": "10\n \n\n7 is not less than 5, so we should print 10.\n\n* * *"}, {"input": "6 6", "output": "10\n \n\n6 is not less than 6, so we should print 10."}]
If X is less than A, print 0; if X is not less than A, print 10. * * *
s534751764
Runtime Error
p02999
Input is given from Standard Input in the following format: X A
# B - Bounding(ABC130) A = list(map(int, input().split())) L = list(map(int, input().split())) D = 0 C = 1 for i in L: D += i if D <= A[1]: C += 1 else: print(C) break else: print(A[0])
Statement X and A are integers between 0 and 9 (inclusive). If X is less than A, print 0; if X is not less than A, print 10.
[{"input": "3 5", "output": "0\n \n\n3 is less than 5, so we should print 0.\n\n* * *"}, {"input": "7 5", "output": "10\n \n\n7 is not less than 5, so we should print 10.\n\n* * *"}, {"input": "6 6", "output": "10\n \n\n6 is not less than 6, so we should print 10."}]
If X is less than A, print 0; if X is not less than A, print 10. * * *
s845406975
Runtime Error
p02999
Input is given from Standard Input in the following format: X A
w, h, x, y = input().split() w, h, x, y = int(w), int(h), int(x), int(y) if (x == 0) or (y == 0) or (x == w / 2) or (y == h / 2) or (x == w) or (y == h): if (x == w / 2) and (y == h / 2): print(w * h / 2, 1) else: print(w * h / 2, 0) else: if (x < w / 2) and (y < h / 2): p = (h - y) / (w - x) x_pos = (p * x - y) / p print((w - x_pos) * h / 2, 0) elif (x > w / 2) and (y < h / 2): p = (h - y) / -x x_pos = (p * x - y) / p print(x_pos * h / 2, 0) elif (x < w / 2) and (y > h / 2): p = -y / (w - x) x_pos = (h - y + p * x) / p print((w - x_pos) * h / 2, 0) elif (x > w / 2) and (y > h / 2): p = y / x x_pos = (h - y + p * x) / p print(x_pos * h / 2, 0)
Statement X and A are integers between 0 and 9 (inclusive). If X is less than A, print 0; if X is not less than A, print 10.
[{"input": "3 5", "output": "0\n \n\n3 is less than 5, so we should print 0.\n\n* * *"}, {"input": "7 5", "output": "10\n \n\n7 is not less than 5, so we should print 10.\n\n* * *"}, {"input": "6 6", "output": "10\n \n\n6 is not less than 6, so we should print 10."}]
If X is less than A, print 0; if X is not less than A, print 10. * * *
s841503098
Accepted
p02999
Input is given from Standard Input in the following format: X A
X, A = [int(x) for x in input().split()] print("10"[X < A :])
Statement X and A are integers between 0 and 9 (inclusive). If X is less than A, print 0; if X is not less than A, print 10.
[{"input": "3 5", "output": "0\n \n\n3 is less than 5, so we should print 0.\n\n* * *"}, {"input": "7 5", "output": "10\n \n\n7 is not less than 5, so we should print 10.\n\n* * *"}, {"input": "6 6", "output": "10\n \n\n6 is not less than 6, so we should print 10."}]
If X is less than A, print 0; if X is not less than A, print 10. * * *
s690141607
Accepted
p02999
Input is given from Standard Input in the following format: X A
s = input() print(0 if s[0] < s[2] else 10)
Statement X and A are integers between 0 and 9 (inclusive). If X is less than A, print 0; if X is not less than A, print 10.
[{"input": "3 5", "output": "0\n \n\n3 is less than 5, so we should print 0.\n\n* * *"}, {"input": "7 5", "output": "10\n \n\n7 is not less than 5, so we should print 10.\n\n* * *"}, {"input": "6 6", "output": "10\n \n\n6 is not less than 6, so we should print 10."}]
If X is less than A, print 0; if X is not less than A, print 10. * * *
s490537853
Runtime Error
p02999
Input is given from Standard Input in the following format: X A
print(10 * (input() >= input()))
Statement X and A are integers between 0 and 9 (inclusive). If X is less than A, print 0; if X is not less than A, print 10.
[{"input": "3 5", "output": "0\n \n\n3 is less than 5, so we should print 0.\n\n* * *"}, {"input": "7 5", "output": "10\n \n\n7 is not less than 5, so we should print 10.\n\n* * *"}, {"input": "6 6", "output": "10\n \n\n6 is not less than 6, so we should print 10."}]
If X is less than A, print 0; if X is not less than A, print 10. * * *
s478303490
Accepted
p02999
Input is given from Standard Input in the following format: X A
X, N = map(int, input().split()) print(0 if X < N else 10)
Statement X and A are integers between 0 and 9 (inclusive). If X is less than A, print 0; if X is not less than A, print 10.
[{"input": "3 5", "output": "0\n \n\n3 is less than 5, so we should print 0.\n\n* * *"}, {"input": "7 5", "output": "10\n \n\n7 is not less than 5, so we should print 10.\n\n* * *"}, {"input": "6 6", "output": "10\n \n\n6 is not less than 6, so we should print 10."}]
If X is less than A, print 0; if X is not less than A, print 10. * * *
s803144093
Runtime Error
p02999
Input is given from Standard Input in the following format: X A
a, b = map(input().split()) print(0 if a < b else 10)
Statement X and A are integers between 0 and 9 (inclusive). If X is less than A, print 0; if X is not less than A, print 10.
[{"input": "3 5", "output": "0\n \n\n3 is less than 5, so we should print 0.\n\n* * *"}, {"input": "7 5", "output": "10\n \n\n7 is not less than 5, so we should print 10.\n\n* * *"}, {"input": "6 6", "output": "10\n \n\n6 is not less than 6, so we should print 10."}]
Print the minimum amount of money required to prepare X A-pizzas and Y B-pizzas. * * *
s974325074
Runtime Error
p03371
Input is given from Standard Input in the following format: A B C X Y
a, b, c, x, y = map(int, input().split()) print(min(a*x+b*y, 2*c*x + b*max(0,y-x), 2*c*y + a*max(0, x-y))
Statement "Pizza At", a fast food chain, offers three kinds of pizza: "A-pizza", "B-pizza" and "AB-pizza". A-pizza and B-pizza are completely different pizzas, and AB-pizza is one half of A-pizza and one half of B-pizza combined together. The prices of one A-pizza, B-pizza and AB-pizza are A yen, B yen and C yen (yen is the currency of Japan), respectively. Nakahashi needs to prepare X A-pizzas and Y B-pizzas for a party tonight. He can only obtain these pizzas by directly buying A-pizzas and B-pizzas, or buying two AB-pizzas and then rearrange them into one A-pizza and one B-pizza. At least how much money does he need for this? It is fine to have more pizzas than necessary by rearranging pizzas.
[{"input": "1500 2000 1600 3 2", "output": "7900\n \n\nIt is optimal to buy four AB-pizzas and rearrange them into two A-pizzas and\ntwo B-pizzas, then buy additional one A-pizza.\n\n* * *"}, {"input": "1500 2000 1900 3 2", "output": "8500\n \n\nIt is optimal to directly buy three A-pizzas and two B-pizzas.\n\n* * *"}, {"input": "1500 2000 500 90000 100000", "output": "100000000\n \n\nIt is optimal to buy 200000 AB-pizzas and rearrange them into 100000 A-pizzas\nand 100000 B-pizzas. We will have 10000 more A-pizzas than necessary, but that\nis fine."}]
Print the minimum amount of money required to prepare X A-pizzas and Y B-pizzas. * * *
s965034465
Runtime Error
p03371
Input is given from Standard Input in the following format: A B C X Y
A,B,C,X,Y=map(int,input().split()) if A<=2*C amd B<=2*C: print(A*X+B*Y) else: if X>=Y: print(min(A*(X-Y)+2*C*Y),2*C*X) else: print(B*(Y-X)+2*C*X,2*C*Y)
Statement "Pizza At", a fast food chain, offers three kinds of pizza: "A-pizza", "B-pizza" and "AB-pizza". A-pizza and B-pizza are completely different pizzas, and AB-pizza is one half of A-pizza and one half of B-pizza combined together. The prices of one A-pizza, B-pizza and AB-pizza are A yen, B yen and C yen (yen is the currency of Japan), respectively. Nakahashi needs to prepare X A-pizzas and Y B-pizzas for a party tonight. He can only obtain these pizzas by directly buying A-pizzas and B-pizzas, or buying two AB-pizzas and then rearrange them into one A-pizza and one B-pizza. At least how much money does he need for this? It is fine to have more pizzas than necessary by rearranging pizzas.
[{"input": "1500 2000 1600 3 2", "output": "7900\n \n\nIt is optimal to buy four AB-pizzas and rearrange them into two A-pizzas and\ntwo B-pizzas, then buy additional one A-pizza.\n\n* * *"}, {"input": "1500 2000 1900 3 2", "output": "8500\n \n\nIt is optimal to directly buy three A-pizzas and two B-pizzas.\n\n* * *"}, {"input": "1500 2000 500 90000 100000", "output": "100000000\n \n\nIt is optimal to buy 200000 AB-pizzas and rearrange them into 100000 A-pizzas\nand 100000 B-pizzas. We will have 10000 more A-pizzas than necessary, but that\nis fine."}]
Print the minimum amount of money required to prepare X A-pizzas and Y B-pizzas. * * *
s063431997
Accepted
p03371
Input is given from Standard Input in the following format: A B C X Y
price_A, price_B, price_AB, num_A, num_B = map(int, input().split()) AandB = price_A * num_A + price_B * num_B if num_A >= num_B: minAB = price_AB * num_B * 2 + price_A * (num_A - num_B) else: minAB = price_AB * num_A * 2 + price_B * (num_B - num_A) maxAB = price_AB * max(num_A, num_B) * 2 print(min(AandB, minAB, maxAB))
Statement "Pizza At", a fast food chain, offers three kinds of pizza: "A-pizza", "B-pizza" and "AB-pizza". A-pizza and B-pizza are completely different pizzas, and AB-pizza is one half of A-pizza and one half of B-pizza combined together. The prices of one A-pizza, B-pizza and AB-pizza are A yen, B yen and C yen (yen is the currency of Japan), respectively. Nakahashi needs to prepare X A-pizzas and Y B-pizzas for a party tonight. He can only obtain these pizzas by directly buying A-pizzas and B-pizzas, or buying two AB-pizzas and then rearrange them into one A-pizza and one B-pizza. At least how much money does he need for this? It is fine to have more pizzas than necessary by rearranging pizzas.
[{"input": "1500 2000 1600 3 2", "output": "7900\n \n\nIt is optimal to buy four AB-pizzas and rearrange them into two A-pizzas and\ntwo B-pizzas, then buy additional one A-pizza.\n\n* * *"}, {"input": "1500 2000 1900 3 2", "output": "8500\n \n\nIt is optimal to directly buy three A-pizzas and two B-pizzas.\n\n* * *"}, {"input": "1500 2000 500 90000 100000", "output": "100000000\n \n\nIt is optimal to buy 200000 AB-pizzas and rearrange them into 100000 A-pizzas\nand 100000 B-pizzas. We will have 10000 more A-pizzas than necessary, but that\nis fine."}]
Print the minimum amount of money required to prepare X A-pizzas and Y B-pizzas. * * *
s022859067
Runtime Error
p03371
Input is given from Standard Input in the following format: A B C X Y
a,b,c,x,y=list(map(int,input().split())) if (a*x)+(b*y) < 2*c: print((a*x)+(b*y)) elif (c*min(x,y))+(max(x,y)-min(x,y)*a) < max(x,y)*c: print((c*min(x,y))+(max(x,y)-min(x,y)*a)) elif (c*min(x,y))+(max(x,y)-min(x,y)*b) < max(x,y)*c: print((c*min(x,y))+(max(x,y)-min(x,y)*b)) else: print(max(x,y)*c
Statement "Pizza At", a fast food chain, offers three kinds of pizza: "A-pizza", "B-pizza" and "AB-pizza". A-pizza and B-pizza are completely different pizzas, and AB-pizza is one half of A-pizza and one half of B-pizza combined together. The prices of one A-pizza, B-pizza and AB-pizza are A yen, B yen and C yen (yen is the currency of Japan), respectively. Nakahashi needs to prepare X A-pizzas and Y B-pizzas for a party tonight. He can only obtain these pizzas by directly buying A-pizzas and B-pizzas, or buying two AB-pizzas and then rearrange them into one A-pizza and one B-pizza. At least how much money does he need for this? It is fine to have more pizzas than necessary by rearranging pizzas.
[{"input": "1500 2000 1600 3 2", "output": "7900\n \n\nIt is optimal to buy four AB-pizzas and rearrange them into two A-pizzas and\ntwo B-pizzas, then buy additional one A-pizza.\n\n* * *"}, {"input": "1500 2000 1900 3 2", "output": "8500\n \n\nIt is optimal to directly buy three A-pizzas and two B-pizzas.\n\n* * *"}, {"input": "1500 2000 500 90000 100000", "output": "100000000\n \n\nIt is optimal to buy 200000 AB-pizzas and rearrange them into 100000 A-pizzas\nand 100000 B-pizzas. We will have 10000 more A-pizzas than necessary, but that\nis fine."}]
Print the minimum amount of money required to prepare X A-pizzas and Y B-pizzas. * * *
s809576787
Accepted
p03371
Input is given from Standard Input in the following format: A B C X Y
import glob # 問題ごとのディレクトリのトップからの相対パス REL_PATH = "ABC\\95\\C" # テスト用ファイル置き場のトップ TOP_PATH = "C:\\AtCoder" class Common: problem = [] index = 0 def __init__(self, rel_path): self.rel_path = rel_path def initialize(self, path): file = open(path) self.problem = file.readlines() self.index = 0 return def input_data(self): try: IS_TEST self.index += 1 return self.problem[self.index - 1] except NameError: return input() def resolve(self): pass def exec_resolve(self): try: IS_TEST for path in glob.glob(TOP_PATH + "\\" + self.rel_path + "/*.txt"): print("Test: " + path) self.initialize(path) self.resolve() print("\n\n") except NameError: self.resolve() class Solver(Common): def resolve(self): q = [int(i) for i in self.input_data().split()] A = q[0] B = q[1] C = q[2] X = q[3] Y = q[4] if 2 * C > A + B: result = A * X + B * Y else: if X > Y: result = C * Y * 2 if A > C * 2: result += (X - Y) * C * 2 else: result += (X - Y) * A else: result = C * X * 2 if B > C * 2: result += (Y - X) * C * 2 else: result += (Y - X) * B print(str(result)) solver = Solver(REL_PATH) solver.exec_resolve()
Statement "Pizza At", a fast food chain, offers three kinds of pizza: "A-pizza", "B-pizza" and "AB-pizza". A-pizza and B-pizza are completely different pizzas, and AB-pizza is one half of A-pizza and one half of B-pizza combined together. The prices of one A-pizza, B-pizza and AB-pizza are A yen, B yen and C yen (yen is the currency of Japan), respectively. Nakahashi needs to prepare X A-pizzas and Y B-pizzas for a party tonight. He can only obtain these pizzas by directly buying A-pizzas and B-pizzas, or buying two AB-pizzas and then rearrange them into one A-pizza and one B-pizza. At least how much money does he need for this? It is fine to have more pizzas than necessary by rearranging pizzas.
[{"input": "1500 2000 1600 3 2", "output": "7900\n \n\nIt is optimal to buy four AB-pizzas and rearrange them into two A-pizzas and\ntwo B-pizzas, then buy additional one A-pizza.\n\n* * *"}, {"input": "1500 2000 1900 3 2", "output": "8500\n \n\nIt is optimal to directly buy three A-pizzas and two B-pizzas.\n\n* * *"}, {"input": "1500 2000 500 90000 100000", "output": "100000000\n \n\nIt is optimal to buy 200000 AB-pizzas and rearrange them into 100000 A-pizzas\nand 100000 B-pizzas. We will have 10000 more A-pizzas than necessary, but that\nis fine."}]
Print the minimum amount of money required to prepare X A-pizzas and Y B-pizzas. * * *
s603293038
Accepted
p03371
Input is given from Standard Input in the following format: A B C X Y
import math, string, itertools, fractions, heapq, collections, re, array, bisect, sys, random, time, copy, functools sys.setrecursionlimit(10**7) inf = 10**20 eps = 1.0 / 10**10 mod = 10**9 + 7 dd = [(-1, 0), (0, 1), (1, 0), (0, -1)] ddn = [(-1, 0), (-1, 1), (0, 1), (1, 1), (1, 0), (1, -1), (0, -1), (-1, -1)] def LI(): return [int(x) for x in sys.stdin.readline().split()] def LI_(): return [int(x) - 1 for x in sys.stdin.readline().split()] def LF(): return [float(x) for x in sys.stdin.readline().split()] def LS(): return sys.stdin.readline().split() def I(): return int(sys.stdin.readline()) def F(): return float(sys.stdin.readline()) def pf(s): return print(s, flush=True) A, B, C, X, Y = LI() """ A+BよりもCのほうがお得な場合、XまたはYを買い切るまでCを買う その後は、AかBで残っているものとAB*2で安い方を買う """ result = 0 if A + B >= C * 2: # Cを購入する reduce_amount = min(X, Y) X -= reduce_amount Y -= reduce_amount result += C * 2 * reduce_amount if X > 0: result += min(C * 2 * X, A * X) if Y > 0: result += min(C * 2 * Y, B * Y) print(result)
Statement "Pizza At", a fast food chain, offers three kinds of pizza: "A-pizza", "B-pizza" and "AB-pizza". A-pizza and B-pizza are completely different pizzas, and AB-pizza is one half of A-pizza and one half of B-pizza combined together. The prices of one A-pizza, B-pizza and AB-pizza are A yen, B yen and C yen (yen is the currency of Japan), respectively. Nakahashi needs to prepare X A-pizzas and Y B-pizzas for a party tonight. He can only obtain these pizzas by directly buying A-pizzas and B-pizzas, or buying two AB-pizzas and then rearrange them into one A-pizza and one B-pizza. At least how much money does he need for this? It is fine to have more pizzas than necessary by rearranging pizzas.
[{"input": "1500 2000 1600 3 2", "output": "7900\n \n\nIt is optimal to buy four AB-pizzas and rearrange them into two A-pizzas and\ntwo B-pizzas, then buy additional one A-pizza.\n\n* * *"}, {"input": "1500 2000 1900 3 2", "output": "8500\n \n\nIt is optimal to directly buy three A-pizzas and two B-pizzas.\n\n* * *"}, {"input": "1500 2000 500 90000 100000", "output": "100000000\n \n\nIt is optimal to buy 200000 AB-pizzas and rearrange them into 100000 A-pizzas\nand 100000 B-pizzas. We will have 10000 more A-pizzas than necessary, but that\nis fine."}]
Print the minimum amount of money required to prepare X A-pizzas and Y B-pizzas. * * *
s030349799
Accepted
p03371
Input is given from Standard Input in the following format: A B C X Y
money_a, money_b, money_c, num_a, num_b = [int(x) for x in input().strip().split()] sum_money = list() temp = 0 for _ in range(num_a): temp += money_a for _ in range(num_b): temp += money_b sum_money.append(temp) temp = 0 for _ in range(min(num_a, num_b)): temp += money_c * 2 if num_a > num_b: temp += money_a * (num_a - num_b) elif num_a < num_b: temp += money_b * (num_b - num_a) sum_money.append(temp) temp = 0 for _ in range(max(num_a, num_b)): temp += money_c * 2 sum_money.append(temp) print(min(sum_money))
Statement "Pizza At", a fast food chain, offers three kinds of pizza: "A-pizza", "B-pizza" and "AB-pizza". A-pizza and B-pizza are completely different pizzas, and AB-pizza is one half of A-pizza and one half of B-pizza combined together. The prices of one A-pizza, B-pizza and AB-pizza are A yen, B yen and C yen (yen is the currency of Japan), respectively. Nakahashi needs to prepare X A-pizzas and Y B-pizzas for a party tonight. He can only obtain these pizzas by directly buying A-pizzas and B-pizzas, or buying two AB-pizzas and then rearrange them into one A-pizza and one B-pizza. At least how much money does he need for this? It is fine to have more pizzas than necessary by rearranging pizzas.
[{"input": "1500 2000 1600 3 2", "output": "7900\n \n\nIt is optimal to buy four AB-pizzas and rearrange them into two A-pizzas and\ntwo B-pizzas, then buy additional one A-pizza.\n\n* * *"}, {"input": "1500 2000 1900 3 2", "output": "8500\n \n\nIt is optimal to directly buy three A-pizzas and two B-pizzas.\n\n* * *"}, {"input": "1500 2000 500 90000 100000", "output": "100000000\n \n\nIt is optimal to buy 200000 AB-pizzas and rearrange them into 100000 A-pizzas\nand 100000 B-pizzas. We will have 10000 more A-pizzas than necessary, but that\nis fine."}]
Print the minimum amount of money required to prepare X A-pizzas and Y B-pizzas. * * *
s134349944
Accepted
p03371
Input is given from Standard Input in the following format: A B C X Y
s = input().rstrip().split(" ") costa = int(s[0]) costb = int(s[1]) costc = int(s[2]) needa = int(s[3]) needb = int(s[4]) mini = min(needa, needb) maxi = max(needa, needb) lst = [] total = costa * needa + costb * needb totala = costa * needa + costb * needb totalb = costc * maxi * 2 for i in range(mini + 1): temp = costa * (needa - i) + costb * (needb - i) + costc * i * 2 if total > temp: total = temp lst.append(total) lst.append(totala) lst.append(totalb) mintotal = min(lst) print(mintotal)
Statement "Pizza At", a fast food chain, offers three kinds of pizza: "A-pizza", "B-pizza" and "AB-pizza". A-pizza and B-pizza are completely different pizzas, and AB-pizza is one half of A-pizza and one half of B-pizza combined together. The prices of one A-pizza, B-pizza and AB-pizza are A yen, B yen and C yen (yen is the currency of Japan), respectively. Nakahashi needs to prepare X A-pizzas and Y B-pizzas for a party tonight. He can only obtain these pizzas by directly buying A-pizzas and B-pizzas, or buying two AB-pizzas and then rearrange them into one A-pizza and one B-pizza. At least how much money does he need for this? It is fine to have more pizzas than necessary by rearranging pizzas.
[{"input": "1500 2000 1600 3 2", "output": "7900\n \n\nIt is optimal to buy four AB-pizzas and rearrange them into two A-pizzas and\ntwo B-pizzas, then buy additional one A-pizza.\n\n* * *"}, {"input": "1500 2000 1900 3 2", "output": "8500\n \n\nIt is optimal to directly buy three A-pizzas and two B-pizzas.\n\n* * *"}, {"input": "1500 2000 500 90000 100000", "output": "100000000\n \n\nIt is optimal to buy 200000 AB-pizzas and rearrange them into 100000 A-pizzas\nand 100000 B-pizzas. We will have 10000 more A-pizzas than necessary, but that\nis fine."}]
Print the minimum amount of money required to prepare X A-pizzas and Y B-pizzas. * * *
s774588977
Accepted
p03371
Input is given from Standard Input in the following format: A B C X Y
A, B, C, X, Y = map(int, input().split()) cmin = 10**10 for k in range(max(X, Y) + 1): n = max(X - k, 0) m = max(Y - k, 0) cmin = min(cmin, n * A + m * B + 2 * k * C) print(cmin)
Statement "Pizza At", a fast food chain, offers three kinds of pizza: "A-pizza", "B-pizza" and "AB-pizza". A-pizza and B-pizza are completely different pizzas, and AB-pizza is one half of A-pizza and one half of B-pizza combined together. The prices of one A-pizza, B-pizza and AB-pizza are A yen, B yen and C yen (yen is the currency of Japan), respectively. Nakahashi needs to prepare X A-pizzas and Y B-pizzas for a party tonight. He can only obtain these pizzas by directly buying A-pizzas and B-pizzas, or buying two AB-pizzas and then rearrange them into one A-pizza and one B-pizza. At least how much money does he need for this? It is fine to have more pizzas than necessary by rearranging pizzas.
[{"input": "1500 2000 1600 3 2", "output": "7900\n \n\nIt is optimal to buy four AB-pizzas and rearrange them into two A-pizzas and\ntwo B-pizzas, then buy additional one A-pizza.\n\n* * *"}, {"input": "1500 2000 1900 3 2", "output": "8500\n \n\nIt is optimal to directly buy three A-pizzas and two B-pizzas.\n\n* * *"}, {"input": "1500 2000 500 90000 100000", "output": "100000000\n \n\nIt is optimal to buy 200000 AB-pizzas and rearrange them into 100000 A-pizzas\nand 100000 B-pizzas. We will have 10000 more A-pizzas than necessary, but that\nis fine."}]
Print the minimum amount of money required to prepare X A-pizzas and Y B-pizzas. * * *
s233171456
Runtime Error
p03371
Input is given from Standard Input in the following format: A B C X Y
n = int(input()) a = 1 b = 1 mx = 10**10 while a <= b and a * a <= n: if n % a == 0: b = int(n / a) mx = min(mx, max(a, b)) a += 1 print(len(str(mx)))
Statement "Pizza At", a fast food chain, offers three kinds of pizza: "A-pizza", "B-pizza" and "AB-pizza". A-pizza and B-pizza are completely different pizzas, and AB-pizza is one half of A-pizza and one half of B-pizza combined together. The prices of one A-pizza, B-pizza and AB-pizza are A yen, B yen and C yen (yen is the currency of Japan), respectively. Nakahashi needs to prepare X A-pizzas and Y B-pizzas for a party tonight. He can only obtain these pizzas by directly buying A-pizzas and B-pizzas, or buying two AB-pizzas and then rearrange them into one A-pizza and one B-pizza. At least how much money does he need for this? It is fine to have more pizzas than necessary by rearranging pizzas.
[{"input": "1500 2000 1600 3 2", "output": "7900\n \n\nIt is optimal to buy four AB-pizzas and rearrange them into two A-pizzas and\ntwo B-pizzas, then buy additional one A-pizza.\n\n* * *"}, {"input": "1500 2000 1900 3 2", "output": "8500\n \n\nIt is optimal to directly buy three A-pizzas and two B-pizzas.\n\n* * *"}, {"input": "1500 2000 500 90000 100000", "output": "100000000\n \n\nIt is optimal to buy 200000 AB-pizzas and rearrange them into 100000 A-pizzas\nand 100000 B-pizzas. We will have 10000 more A-pizzas than necessary, but that\nis fine."}]
Print the minimum amount of money required to prepare X A-pizzas and Y B-pizzas. * * *
s581692164
Wrong Answer
p03371
Input is given from Standard Input in the following format: A B C X Y
pa, pb, pab, x, y = map(int, input().split()) li = [] if x - y >= 0: li.append(pa * x + pb * y) li.append(pa * (x - y) + pab * 2 * y) li.append(pab * 2 * x) if y - x >= 0: li.append(pa * x + pb * y) li.append(pb * (y - x) + pab * 2 * y) li.append(pab * 2 * y) li.sort() print(li[0])
Statement "Pizza At", a fast food chain, offers three kinds of pizza: "A-pizza", "B-pizza" and "AB-pizza". A-pizza and B-pizza are completely different pizzas, and AB-pizza is one half of A-pizza and one half of B-pizza combined together. The prices of one A-pizza, B-pizza and AB-pizza are A yen, B yen and C yen (yen is the currency of Japan), respectively. Nakahashi needs to prepare X A-pizzas and Y B-pizzas for a party tonight. He can only obtain these pizzas by directly buying A-pizzas and B-pizzas, or buying two AB-pizzas and then rearrange them into one A-pizza and one B-pizza. At least how much money does he need for this? It is fine to have more pizzas than necessary by rearranging pizzas.
[{"input": "1500 2000 1600 3 2", "output": "7900\n \n\nIt is optimal to buy four AB-pizzas and rearrange them into two A-pizzas and\ntwo B-pizzas, then buy additional one A-pizza.\n\n* * *"}, {"input": "1500 2000 1900 3 2", "output": "8500\n \n\nIt is optimal to directly buy three A-pizzas and two B-pizzas.\n\n* * *"}, {"input": "1500 2000 500 90000 100000", "output": "100000000\n \n\nIt is optimal to buy 200000 AB-pizzas and rearrange them into 100000 A-pizzas\nand 100000 B-pizzas. We will have 10000 more A-pizzas than necessary, but that\nis fine."}]
Print the minimum amount of money required to prepare X A-pizzas and Y B-pizzas. * * *
s016370058
Runtime Error
p03371
Input is given from Standard Input in the following format: A B C X Y
a,b,c,x,y = map(int,input().split()) if 2*c-a-b >= 0: print(a*x+b*y) else: s = 0 if x => y: s += 2*c*x x -= y s += min(2*c,a)*x print(s) else: s += 2*c*y y -= x s += min(2*c,b)*y print(s)
Statement "Pizza At", a fast food chain, offers three kinds of pizza: "A-pizza", "B-pizza" and "AB-pizza". A-pizza and B-pizza are completely different pizzas, and AB-pizza is one half of A-pizza and one half of B-pizza combined together. The prices of one A-pizza, B-pizza and AB-pizza are A yen, B yen and C yen (yen is the currency of Japan), respectively. Nakahashi needs to prepare X A-pizzas and Y B-pizzas for a party tonight. He can only obtain these pizzas by directly buying A-pizzas and B-pizzas, or buying two AB-pizzas and then rearrange them into one A-pizza and one B-pizza. At least how much money does he need for this? It is fine to have more pizzas than necessary by rearranging pizzas.
[{"input": "1500 2000 1600 3 2", "output": "7900\n \n\nIt is optimal to buy four AB-pizzas and rearrange them into two A-pizzas and\ntwo B-pizzas, then buy additional one A-pizza.\n\n* * *"}, {"input": "1500 2000 1900 3 2", "output": "8500\n \n\nIt is optimal to directly buy three A-pizzas and two B-pizzas.\n\n* * *"}, {"input": "1500 2000 500 90000 100000", "output": "100000000\n \n\nIt is optimal to buy 200000 AB-pizzas and rearrange them into 100000 A-pizzas\nand 100000 B-pizzas. We will have 10000 more A-pizzas than necessary, but that\nis fine."}]
Print the minimum amount of money required to prepare X A-pizzas and Y B-pizzas. * * *
s497150562
Accepted
p03371
Input is given from Standard Input in the following format: A B C X Y
# -*- coding: utf-8 -*- ############# # Libraries # ############# import sys input = sys.stdin.readline import math # from math import gcd import bisect from collections import defaultdict from collections import deque from functools import lru_cache ############# # Constants # ############# MOD = 10**9 + 7 INF = float("inf") ############# # Functions # ############# ######INPUT###### def I(): return int(input().strip()) def S(): return input().strip() def IL(): return list(map(int, input().split())) def SL(): return list(map(str, input().split())) def ILs(n): return list(int(input()) for _ in range(n)) def SLs(n): return list(input().strip() for _ in range(n)) def ILL(n): return [list(map(int, input().split())) for _ in range(n)] def SLL(n): return [list(map(str, input().split())) for _ in range(n)] ######OUTPUT###### def P(arg): print(arg) return def Y(): print("Yes") return def N(): print("No") return def E(): exit() def PE(arg): print(arg) exit() def YE(): print("Yes") exit() def NE(): print("No") exit() #####Shorten##### def DD(arg): return defaultdict(arg) #####Inverse##### def inv(n): return pow(n, MOD - 2, MOD) ######Combination###### kaijo_memo = [] def kaijo(n): if len(kaijo_memo) > n: return kaijo_memo[n] if len(kaijo_memo) == 0: kaijo_memo.append(1) while len(kaijo_memo) <= n: kaijo_memo.append(kaijo_memo[-1] * len(kaijo_memo) % MOD) return kaijo_memo[n] gyaku_kaijo_memo = [] def gyaku_kaijo(n): if len(gyaku_kaijo_memo) > n: return gyaku_kaijo_memo[n] if len(gyaku_kaijo_memo) == 0: gyaku_kaijo_memo.append(1) while len(gyaku_kaijo_memo) <= n: gyaku_kaijo_memo.append( gyaku_kaijo_memo[-1] * pow(len(gyaku_kaijo_memo), MOD - 2, MOD) % MOD ) return gyaku_kaijo_memo[n] def nCr(n, r): if n == r: return 1 if n < r or r < 0: return 0 ret = 1 ret = ret * kaijo(n) % MOD ret = ret * gyaku_kaijo(r) % MOD ret = ret * gyaku_kaijo(n - r) % MOD return ret ######Factorization###### def factorization(n): arr = [] temp = n for i in range(2, int(-(-(n**0.5) // 1)) + 1): if temp % i == 0: cnt = 0 while temp % i == 0: cnt += 1 temp //= i arr.append([i, cnt]) if temp != 1: arr.append([temp, 1]) if arr == []: arr.append([n, 1]) return arr #####MakeDivisors###### def make_divisors(n): divisors = [] for i in range(1, int(n**0.5) + 1): if n % i == 0: divisors.append(i) if i != n // i: divisors.append(n // i) return divisors #####LCM##### def lcm(a, b): return a * b // gcd(a, b) #####BitCount##### def count_bit(n): count = 0 while n: n &= n - 1 count += 1 return count #####ChangeBase##### def base_10_to_n(X, n): if X // n: return base_10_to_n(X // n, n) + [X % n] return [X % n] def base_n_to_10(X, n): return sum(int(str(X)[-i]) * n**i for i in range(len(str(X)))) #####IntLog##### def int_log(n, a): count = 0 while n >= a: n //= a count += 1 return count ############# # Main Code # ############# A, B, C, X, Y = IL() P( min( A * X + B * Y, C * 2 * max(X, Y), C * X * 2 + B * max(0, Y - X), C * Y * 2 + A * max(0, X - Y), ) )
Statement "Pizza At", a fast food chain, offers three kinds of pizza: "A-pizza", "B-pizza" and "AB-pizza". A-pizza and B-pizza are completely different pizzas, and AB-pizza is one half of A-pizza and one half of B-pizza combined together. The prices of one A-pizza, B-pizza and AB-pizza are A yen, B yen and C yen (yen is the currency of Japan), respectively. Nakahashi needs to prepare X A-pizzas and Y B-pizzas for a party tonight. He can only obtain these pizzas by directly buying A-pizzas and B-pizzas, or buying two AB-pizzas and then rearrange them into one A-pizza and one B-pizza. At least how much money does he need for this? It is fine to have more pizzas than necessary by rearranging pizzas.
[{"input": "1500 2000 1600 3 2", "output": "7900\n \n\nIt is optimal to buy four AB-pizzas and rearrange them into two A-pizzas and\ntwo B-pizzas, then buy additional one A-pizza.\n\n* * *"}, {"input": "1500 2000 1900 3 2", "output": "8500\n \n\nIt is optimal to directly buy three A-pizzas and two B-pizzas.\n\n* * *"}, {"input": "1500 2000 500 90000 100000", "output": "100000000\n \n\nIt is optimal to buy 200000 AB-pizzas and rearrange them into 100000 A-pizzas\nand 100000 B-pizzas. We will have 10000 more A-pizzas than necessary, but that\nis fine."}]
Print the minimum amount of money required to prepare X A-pizzas and Y B-pizzas. * * *
s849387707
Wrong Answer
p03371
Input is given from Standard Input in the following format: A B C X Y
A, B, C, X, Y = map(int, input().split()) cnt_A = X cnt_B = Y cnt_C = 0 ans = [] for _ in range(X + Y): if 2 * C <= A + B: cnt_C += 2 cnt_A -= 1 cnt_B -= 1 ans.append(cnt_A * A + cnt_B * B + cnt_C * C) if ((cnt_A < 0) or (cnt_B < 0)) or ((cnt_C == 2 * X) or (cnt_C == Y * 22)): break ans.sort() print(ans[0])
Statement "Pizza At", a fast food chain, offers three kinds of pizza: "A-pizza", "B-pizza" and "AB-pizza". A-pizza and B-pizza are completely different pizzas, and AB-pizza is one half of A-pizza and one half of B-pizza combined together. The prices of one A-pizza, B-pizza and AB-pizza are A yen, B yen and C yen (yen is the currency of Japan), respectively. Nakahashi needs to prepare X A-pizzas and Y B-pizzas for a party tonight. He can only obtain these pizzas by directly buying A-pizzas and B-pizzas, or buying two AB-pizzas and then rearrange them into one A-pizza and one B-pizza. At least how much money does he need for this? It is fine to have more pizzas than necessary by rearranging pizzas.
[{"input": "1500 2000 1600 3 2", "output": "7900\n \n\nIt is optimal to buy four AB-pizzas and rearrange them into two A-pizzas and\ntwo B-pizzas, then buy additional one A-pizza.\n\n* * *"}, {"input": "1500 2000 1900 3 2", "output": "8500\n \n\nIt is optimal to directly buy three A-pizzas and two B-pizzas.\n\n* * *"}, {"input": "1500 2000 500 90000 100000", "output": "100000000\n \n\nIt is optimal to buy 200000 AB-pizzas and rearrange them into 100000 A-pizzas\nand 100000 B-pizzas. We will have 10000 more A-pizzas than necessary, but that\nis fine."}]
Print the minimum amount of money required to prepare X A-pizzas and Y B-pizzas. * * *
s162278600
Accepted
p03371
Input is given from Standard Input in the following format: A B C X Y
input = input() split = input.split() pliceA = int(split[0]) pliceB = int(split[1]) pliceC = int(split[2]) neededA = int(split[3]) neededB = int(split[4]) maxC = neededA * 2 if neededA > neededB else neededB * 2 minPlice = 10**10 for c in range(0, maxC + 1, 1): leftA = neededA - int(c / 2) if neededA - int(c / 2) > 0 else 0 leftB = neededB - int(c / 2) if neededB - int(c / 2) > 0 else 0 plice = leftA * pliceA + leftB * pliceB + pliceC * c minPlice = plice if plice < minPlice else minPlice print(minPlice)
Statement "Pizza At", a fast food chain, offers three kinds of pizza: "A-pizza", "B-pizza" and "AB-pizza". A-pizza and B-pizza are completely different pizzas, and AB-pizza is one half of A-pizza and one half of B-pizza combined together. The prices of one A-pizza, B-pizza and AB-pizza are A yen, B yen and C yen (yen is the currency of Japan), respectively. Nakahashi needs to prepare X A-pizzas and Y B-pizzas for a party tonight. He can only obtain these pizzas by directly buying A-pizzas and B-pizzas, or buying two AB-pizzas and then rearrange them into one A-pizza and one B-pizza. At least how much money does he need for this? It is fine to have more pizzas than necessary by rearranging pizzas.
[{"input": "1500 2000 1600 3 2", "output": "7900\n \n\nIt is optimal to buy four AB-pizzas and rearrange them into two A-pizzas and\ntwo B-pizzas, then buy additional one A-pizza.\n\n* * *"}, {"input": "1500 2000 1900 3 2", "output": "8500\n \n\nIt is optimal to directly buy three A-pizzas and two B-pizzas.\n\n* * *"}, {"input": "1500 2000 500 90000 100000", "output": "100000000\n \n\nIt is optimal to buy 200000 AB-pizzas and rearrange them into 100000 A-pizzas\nand 100000 B-pizzas. We will have 10000 more A-pizzas than necessary, but that\nis fine."}]
Print the minimum amount of money required to prepare X A-pizzas and Y B-pizzas. * * *
s539846778
Wrong Answer
p03371
Input is given from Standard Input in the following format: A B C X Y
A, B, C, X, Y = list(map(int, input().split())) price_min = float("inf") for ib in range(X + 1): price_min_a = float("inf") for ia in range(Y + 1): ic = max(X - ia, Y - ib) * 2 price = A * ia + B * ib + C * ic # print(ia, ib, ic, price) if price < price_min_a: price_min_a = price elif price > price_min_a: break if price_min_a < price_min: price_min = price_min_a elif price_min_a > price_min: break print(price_min)
Statement "Pizza At", a fast food chain, offers three kinds of pizza: "A-pizza", "B-pizza" and "AB-pizza". A-pizza and B-pizza are completely different pizzas, and AB-pizza is one half of A-pizza and one half of B-pizza combined together. The prices of one A-pizza, B-pizza and AB-pizza are A yen, B yen and C yen (yen is the currency of Japan), respectively. Nakahashi needs to prepare X A-pizzas and Y B-pizzas for a party tonight. He can only obtain these pizzas by directly buying A-pizzas and B-pizzas, or buying two AB-pizzas and then rearrange them into one A-pizza and one B-pizza. At least how much money does he need for this? It is fine to have more pizzas than necessary by rearranging pizzas.
[{"input": "1500 2000 1600 3 2", "output": "7900\n \n\nIt is optimal to buy four AB-pizzas and rearrange them into two A-pizzas and\ntwo B-pizzas, then buy additional one A-pizza.\n\n* * *"}, {"input": "1500 2000 1900 3 2", "output": "8500\n \n\nIt is optimal to directly buy three A-pizzas and two B-pizzas.\n\n* * *"}, {"input": "1500 2000 500 90000 100000", "output": "100000000\n \n\nIt is optimal to buy 200000 AB-pizzas and rearrange them into 100000 A-pizzas\nand 100000 B-pizzas. We will have 10000 more A-pizzas than necessary, but that\nis fine."}]
Print the minimum amount of money required to prepare X A-pizzas and Y B-pizzas. * * *
s509522727
Wrong Answer
p03371
Input is given from Standard Input in the following format: A B C X Y
A, B, C, X, Y = map(int, input().split()) List = [(A * 3) + (B * 2)] AB = 0 AP = 0 BP = 0 ANS = 0 while 1: if AP >= X and BP >= Y: # print(ANS) List.append(ANS) break if AB == 2: AP += 1 BP += 1 AB = 0 else: ANS += C AB += 1 AB = 0 AP = X BP = Y ANS = 0 while 1: if AP == 0: ANS += BP * B List.append(ANS) break elif BP == 0: ANS += AP * A List.append(ANS) break else: if AB == 2: AP -= 1 BP -= 1 AB = 0 else: ANS += C AB += 1 print(min(List))
Statement "Pizza At", a fast food chain, offers three kinds of pizza: "A-pizza", "B-pizza" and "AB-pizza". A-pizza and B-pizza are completely different pizzas, and AB-pizza is one half of A-pizza and one half of B-pizza combined together. The prices of one A-pizza, B-pizza and AB-pizza are A yen, B yen and C yen (yen is the currency of Japan), respectively. Nakahashi needs to prepare X A-pizzas and Y B-pizzas for a party tonight. He can only obtain these pizzas by directly buying A-pizzas and B-pizzas, or buying two AB-pizzas and then rearrange them into one A-pizza and one B-pizza. At least how much money does he need for this? It is fine to have more pizzas than necessary by rearranging pizzas.
[{"input": "1500 2000 1600 3 2", "output": "7900\n \n\nIt is optimal to buy four AB-pizzas and rearrange them into two A-pizzas and\ntwo B-pizzas, then buy additional one A-pizza.\n\n* * *"}, {"input": "1500 2000 1900 3 2", "output": "8500\n \n\nIt is optimal to directly buy three A-pizzas and two B-pizzas.\n\n* * *"}, {"input": "1500 2000 500 90000 100000", "output": "100000000\n \n\nIt is optimal to buy 200000 AB-pizzas and rearrange them into 100000 A-pizzas\nand 100000 B-pizzas. We will have 10000 more A-pizzas than necessary, but that\nis fine."}]
Print the minimum amount of money required to prepare X A-pizzas and Y B-pizzas. * * *
s787746512
Runtime Error
p03371
Input is given from Standard Input in the following format: A B C X Y
a, b, c, x, y = map(int, input().split()) xy = [x, y] if (a + b) // 2 <= c: total_ab = a * x + b * y print(total_ab) else: d = c * min(xy) * 2 if x == y: print(d) elif x > y: print(min((x-y) * a + d, c * max(xy) * 2)) else: print(min((y-x) * b + d, c * max(xy) * 2))
Statement "Pizza At", a fast food chain, offers three kinds of pizza: "A-pizza", "B-pizza" and "AB-pizza". A-pizza and B-pizza are completely different pizzas, and AB-pizza is one half of A-pizza and one half of B-pizza combined together. The prices of one A-pizza, B-pizza and AB-pizza are A yen, B yen and C yen (yen is the currency of Japan), respectively. Nakahashi needs to prepare X A-pizzas and Y B-pizzas for a party tonight. He can only obtain these pizzas by directly buying A-pizzas and B-pizzas, or buying two AB-pizzas and then rearrange them into one A-pizza and one B-pizza. At least how much money does he need for this? It is fine to have more pizzas than necessary by rearranging pizzas.
[{"input": "1500 2000 1600 3 2", "output": "7900\n \n\nIt is optimal to buy four AB-pizzas and rearrange them into two A-pizzas and\ntwo B-pizzas, then buy additional one A-pizza.\n\n* * *"}, {"input": "1500 2000 1900 3 2", "output": "8500\n \n\nIt is optimal to directly buy three A-pizzas and two B-pizzas.\n\n* * *"}, {"input": "1500 2000 500 90000 100000", "output": "100000000\n \n\nIt is optimal to buy 200000 AB-pizzas and rearrange them into 100000 A-pizzas\nand 100000 B-pizzas. We will have 10000 more A-pizzas than necessary, but that\nis fine."}]
Print the minimum amount of money required to prepare X A-pizzas and Y B-pizzas. * * *
s038850704
Runtime Error
p03371
Input is given from Standard Input in the following format: A B C X Y
a, b, c, x, y = map(int,input().split()) if (a+b)//2 <= c and x != 0 and y != 0: print(x*a + y*b) exit() ans = 0 ans += min(x,y) * c * 2 if x >= y: ans += min((x-y)*a, (x-y)*2*c) else: ans += min((y-x)*b, (y-x)*2*c) print(ans)
Statement "Pizza At", a fast food chain, offers three kinds of pizza: "A-pizza", "B-pizza" and "AB-pizza". A-pizza and B-pizza are completely different pizzas, and AB-pizza is one half of A-pizza and one half of B-pizza combined together. The prices of one A-pizza, B-pizza and AB-pizza are A yen, B yen and C yen (yen is the currency of Japan), respectively. Nakahashi needs to prepare X A-pizzas and Y B-pizzas for a party tonight. He can only obtain these pizzas by directly buying A-pizzas and B-pizzas, or buying two AB-pizzas and then rearrange them into one A-pizza and one B-pizza. At least how much money does he need for this? It is fine to have more pizzas than necessary by rearranging pizzas.
[{"input": "1500 2000 1600 3 2", "output": "7900\n \n\nIt is optimal to buy four AB-pizzas and rearrange them into two A-pizzas and\ntwo B-pizzas, then buy additional one A-pizza.\n\n* * *"}, {"input": "1500 2000 1900 3 2", "output": "8500\n \n\nIt is optimal to directly buy three A-pizzas and two B-pizzas.\n\n* * *"}, {"input": "1500 2000 500 90000 100000", "output": "100000000\n \n\nIt is optimal to buy 200000 AB-pizzas and rearrange them into 100000 A-pizzas\nand 100000 B-pizzas. We will have 10000 more A-pizzas than necessary, but that\nis fine."}]
Print the minimum amount of money required to prepare X A-pizzas and Y B-pizzas. * * *
s406880722
Runtime Error
p03371
Input is given from Standard Input in the following format: A B C X Y
Not found
Statement "Pizza At", a fast food chain, offers three kinds of pizza: "A-pizza", "B-pizza" and "AB-pizza". A-pizza and B-pizza are completely different pizzas, and AB-pizza is one half of A-pizza and one half of B-pizza combined together. The prices of one A-pizza, B-pizza and AB-pizza are A yen, B yen and C yen (yen is the currency of Japan), respectively. Nakahashi needs to prepare X A-pizzas and Y B-pizzas for a party tonight. He can only obtain these pizzas by directly buying A-pizzas and B-pizzas, or buying two AB-pizzas and then rearrange them into one A-pizza and one B-pizza. At least how much money does he need for this? It is fine to have more pizzas than necessary by rearranging pizzas.
[{"input": "1500 2000 1600 3 2", "output": "7900\n \n\nIt is optimal to buy four AB-pizzas and rearrange them into two A-pizzas and\ntwo B-pizzas, then buy additional one A-pizza.\n\n* * *"}, {"input": "1500 2000 1900 3 2", "output": "8500\n \n\nIt is optimal to directly buy three A-pizzas and two B-pizzas.\n\n* * *"}, {"input": "1500 2000 500 90000 100000", "output": "100000000\n \n\nIt is optimal to buy 200000 AB-pizzas and rearrange them into 100000 A-pizzas\nand 100000 B-pizzas. We will have 10000 more A-pizzas than necessary, but that\nis fine."}]
Print the minimum amount of money required to prepare X A-pizzas and Y B-pizzas. * * *
s134846587
Runtime Error
p03371
Input is given from Standard Input in the following format: A B C X Y
1500 2000 1600 3 2
Statement "Pizza At", a fast food chain, offers three kinds of pizza: "A-pizza", "B-pizza" and "AB-pizza". A-pizza and B-pizza are completely different pizzas, and AB-pizza is one half of A-pizza and one half of B-pizza combined together. The prices of one A-pizza, B-pizza and AB-pizza are A yen, B yen and C yen (yen is the currency of Japan), respectively. Nakahashi needs to prepare X A-pizzas and Y B-pizzas for a party tonight. He can only obtain these pizzas by directly buying A-pizzas and B-pizzas, or buying two AB-pizzas and then rearrange them into one A-pizza and one B-pizza. At least how much money does he need for this? It is fine to have more pizzas than necessary by rearranging pizzas.
[{"input": "1500 2000 1600 3 2", "output": "7900\n \n\nIt is optimal to buy four AB-pizzas and rearrange them into two A-pizzas and\ntwo B-pizzas, then buy additional one A-pizza.\n\n* * *"}, {"input": "1500 2000 1900 3 2", "output": "8500\n \n\nIt is optimal to directly buy three A-pizzas and two B-pizzas.\n\n* * *"}, {"input": "1500 2000 500 90000 100000", "output": "100000000\n \n\nIt is optimal to buy 200000 AB-pizzas and rearrange them into 100000 A-pizzas\nand 100000 B-pizzas. We will have 10000 more A-pizzas than necessary, but that\nis fine."}]
Print the minimum amount of money required to prepare X A-pizzas and Y B-pizzas. * * *
s287254028
Runtime Error
p03371
Input is given from Standard Input in the following format: A B C X Y
a,b,c,x,y = map(int,input().split()) ans = 0 if x=>y: if 2*c <= a: print(2*c*x) else: if 2*c <= a+b: print(2*c*y + a*(x-y)) else: print(a*x + b*y) else: if 2*c <= b: print(2*c*y) else: if 2*c <= a+b: print(2*c*x + a*(y-x)) else: print(a*x + b*y)
Statement "Pizza At", a fast food chain, offers three kinds of pizza: "A-pizza", "B-pizza" and "AB-pizza". A-pizza and B-pizza are completely different pizzas, and AB-pizza is one half of A-pizza and one half of B-pizza combined together. The prices of one A-pizza, B-pizza and AB-pizza are A yen, B yen and C yen (yen is the currency of Japan), respectively. Nakahashi needs to prepare X A-pizzas and Y B-pizzas for a party tonight. He can only obtain these pizzas by directly buying A-pizzas and B-pizzas, or buying two AB-pizzas and then rearrange them into one A-pizza and one B-pizza. At least how much money does he need for this? It is fine to have more pizzas than necessary by rearranging pizzas.
[{"input": "1500 2000 1600 3 2", "output": "7900\n \n\nIt is optimal to buy four AB-pizzas and rearrange them into two A-pizzas and\ntwo B-pizzas, then buy additional one A-pizza.\n\n* * *"}, {"input": "1500 2000 1900 3 2", "output": "8500\n \n\nIt is optimal to directly buy three A-pizzas and two B-pizzas.\n\n* * *"}, {"input": "1500 2000 500 90000 100000", "output": "100000000\n \n\nIt is optimal to buy 200000 AB-pizzas and rearrange them into 100000 A-pizzas\nand 100000 B-pizzas. We will have 10000 more A-pizzas than necessary, but that\nis fine."}]
Print the minimum amount of money required to prepare X A-pizzas and Y B-pizzas. * * *
s347704590
Accepted
p03371
Input is given from Standard Input in the following format: A B C X Y
a, b, c, x, y = map(int, input().split()) # 購入金額 price_a_b = 0 price_mix = 0 price_c = 0 # Aピザ、BピザをそれぞれX,Y枚購入する price_a_b = a * x + b * y # ABピザを、MIN(X,Y)*2枚購入し、Aピザ、Bピザどちらかの不足分を購入する price_mix = c * min(x, y) * 2 + a * (x - min(x, y)) + b * (y - min(x, y)) # ABピザをMAX(X,Y)枚購入する price_c = c * max(x, y) * 2 print(min(price_a_b, price_mix, price_c))
Statement "Pizza At", a fast food chain, offers three kinds of pizza: "A-pizza", "B-pizza" and "AB-pizza". A-pizza and B-pizza are completely different pizzas, and AB-pizza is one half of A-pizza and one half of B-pizza combined together. The prices of one A-pizza, B-pizza and AB-pizza are A yen, B yen and C yen (yen is the currency of Japan), respectively. Nakahashi needs to prepare X A-pizzas and Y B-pizzas for a party tonight. He can only obtain these pizzas by directly buying A-pizzas and B-pizzas, or buying two AB-pizzas and then rearrange them into one A-pizza and one B-pizza. At least how much money does he need for this? It is fine to have more pizzas than necessary by rearranging pizzas.
[{"input": "1500 2000 1600 3 2", "output": "7900\n \n\nIt is optimal to buy four AB-pizzas and rearrange them into two A-pizzas and\ntwo B-pizzas, then buy additional one A-pizza.\n\n* * *"}, {"input": "1500 2000 1900 3 2", "output": "8500\n \n\nIt is optimal to directly buy three A-pizzas and two B-pizzas.\n\n* * *"}, {"input": "1500 2000 500 90000 100000", "output": "100000000\n \n\nIt is optimal to buy 200000 AB-pizzas and rearrange them into 100000 A-pizzas\nand 100000 B-pizzas. We will have 10000 more A-pizzas than necessary, but that\nis fine."}]
Print the minimum amount of money required to prepare X A-pizzas and Y B-pizzas. * * *
s670279721
Runtime Error
p03371
Input is given from Standard Input in the following format: A B C X Y
#include <bits/stdc++.h> using namespace std; typedef long long ll; #define rep(i, n) for (int i = 0; i < (int)(n); i++) int main() { int a, b, c, x, y; cin >> a >> b >> c >> x >> y; int upp = 2*max(x, y); ll ans = 1000000000; int i=0; while(i <= upp) { ll price = max(x-i/2, 0)*a + max(y-i/2, 0)*b + c*i; ans = min(ans, price); i+=2; } cout << ans << endl; }
Statement "Pizza At", a fast food chain, offers three kinds of pizza: "A-pizza", "B-pizza" and "AB-pizza". A-pizza and B-pizza are completely different pizzas, and AB-pizza is one half of A-pizza and one half of B-pizza combined together. The prices of one A-pizza, B-pizza and AB-pizza are A yen, B yen and C yen (yen is the currency of Japan), respectively. Nakahashi needs to prepare X A-pizzas and Y B-pizzas for a party tonight. He can only obtain these pizzas by directly buying A-pizzas and B-pizzas, or buying two AB-pizzas and then rearrange them into one A-pizza and one B-pizza. At least how much money does he need for this? It is fine to have more pizzas than necessary by rearranging pizzas.
[{"input": "1500 2000 1600 3 2", "output": "7900\n \n\nIt is optimal to buy four AB-pizzas and rearrange them into two A-pizzas and\ntwo B-pizzas, then buy additional one A-pizza.\n\n* * *"}, {"input": "1500 2000 1900 3 2", "output": "8500\n \n\nIt is optimal to directly buy three A-pizzas and two B-pizzas.\n\n* * *"}, {"input": "1500 2000 500 90000 100000", "output": "100000000\n \n\nIt is optimal to buy 200000 AB-pizzas and rearrange them into 100000 A-pizzas\nand 100000 B-pizzas. We will have 10000 more A-pizzas than necessary, but that\nis fine."}]
Print the answer for each testcase. * * *
s269080539
Wrong Answer
p02560
Input is given from Standard Input in the following format: T N_0 M_0 A_0 B_0 N_1 M_1 A_1 B_1 : N_{T - 1} M_{T - 1} A_{T - 1} B_{T - 1}
mod = 10**9 + 7 from operator import mul from functools import reduce def cmb(n, r): r = min(n - r, r) if r == 0: return 1 over = reduce(mul, range(n, n - r, -1)) under = reduce(mul, range(1, r + 1)) return over // under s = int(input()) if s == 1 or s == 2: print(0) exit() pk_num = s // 3 - 1 ans = 1 for i in range(pk_num): pk = (i + 2) * 3 g = s - pk b = i + 2 ans += cmb(g + b - 1, b - 1) ans %= mod print(ans)
Statement In this problem, you should process T testcases. For each testcase, you are given four integers N, M, A, B. Calculate \sum_{i = 0}^{N - 1} floor((A \times i + B) / M).
[{"input": "5\n 4 10 6 3\n 6 5 4 3\n 1 1 0 0\n 31415 92653 58979 32384\n 1000000000 1000000000 999999999 999999999", "output": "3\n 13\n 0\n 314095480\n 499999999500000000"}]
Print the number of the possible pairs of integers u and v, modulo 10^9+7. * * *
s846436020
Runtime Error
p03849
The input is given from Standard Input in the following format: N
n,m,q = input().split(" ") n1=int(n/2) m1=(m/2) for i in range(int(q)): a,b,c,d = input().split(" ") a = int(a) b= int(b) c = int(c) d=int(d) if(a==1 and c==2): if((b<=n1 and d<=m1) or (b>n1 and d>m1)): print("YES") else: print("NO") if(a==2 and c==1): if((b<=m1 and d<=n1) or (b>m1 and d>n1)): print("YES") else: print("NO") if(a==1 and c==1): if((b<=n1 and d<=n1) or (b>n1 and d>n1)): print("YES") else: print("NO") if(a==2 and c==2): if((b<=m1 and d<=m1) or (b>m1 and d>m1)): print("YES") else: print("NO")
Statement You are given a positive integer N. Find the number of the pairs of integers u and v (0≦u,v≦N) such that there exist two non-negative integers a and b satisfying a xor b=u and a+b=v. Here, xor denotes the bitwise exclusive OR. Since it can be extremely large, compute the answer modulo 10^9+7.
[{"input": "3", "output": "5\n \n\nThe five possible pairs of u and v are:\n\n * u=0,v=0 (Let a=0,b=0, then 0 xor 0=0, 0+0=0.)\n\n * u=0,v=2 (Let a=1,b=1, then 1 xor 1=0, 1+1=2.\uff09\n\n * u=1,v=1 (Let a=1,b=0, then 1 xor 0=1, 1+0=1.\uff09\n\n * u=2,v=2 (Let a=2,b=0, then 2 xor 0=2, 2+0=2.\uff09\n\n * u=3,v=3 (Let a=3,b=0, then 3 xor 0=3, 3+0=3.\uff09\n\n* * *"}, {"input": "1422", "output": "52277\n \n\n* * *"}, {"input": "1000000000000000000", "output": "787014179"}]
Print the number of the possible pairs of integers u and v, modulo 10^9+7. * * *
s199813355
Accepted
p03849
The input is given from Standard Input in the following format: N
MOD = 10**9 + 7 N = int(input()) binN = list(map(int, bin(N)[2:])) dp = [[0] * 3 for _ in range(len(binN) + 1)] dp[0][0] = 1 for i, Ni in enumerate(binN): dp[i + 1][0] += dp[i][0] * 1 dp[i + 1][1] += dp[i][0] * Ni dp[i + 1][0] += dp[i][1] * (1 - Ni) dp[i + 1][1] += dp[i][1] * 1 dp[i + 1][2] += dp[i][1] * (1 + Ni) dp[i + 1][2] += dp[i][2] * 3 dp[i + 1][0] %= MOD dp[i + 1][1] %= MOD dp[i + 1][2] %= MOD print(sum(dp[-1]) % MOD)
Statement You are given a positive integer N. Find the number of the pairs of integers u and v (0≦u,v≦N) such that there exist two non-negative integers a and b satisfying a xor b=u and a+b=v. Here, xor denotes the bitwise exclusive OR. Since it can be extremely large, compute the answer modulo 10^9+7.
[{"input": "3", "output": "5\n \n\nThe five possible pairs of u and v are:\n\n * u=0,v=0 (Let a=0,b=0, then 0 xor 0=0, 0+0=0.)\n\n * u=0,v=2 (Let a=1,b=1, then 1 xor 1=0, 1+1=2.\uff09\n\n * u=1,v=1 (Let a=1,b=0, then 1 xor 0=1, 1+0=1.\uff09\n\n * u=2,v=2 (Let a=2,b=0, then 2 xor 0=2, 2+0=2.\uff09\n\n * u=3,v=3 (Let a=3,b=0, then 3 xor 0=3, 3+0=3.\uff09\n\n* * *"}, {"input": "1422", "output": "52277\n \n\n* * *"}, {"input": "1000000000000000000", "output": "787014179"}]
Print the number of the possible pairs of integers u and v, modulo 10^9+7. * * *
s462622825
Wrong Answer
p03849
The input is given from Standard Input in the following format: N
MOD = 1000000007 n = int(input()) m = [0, 1] for i in range(1, (n - 1) // 2 + 2): m.append(m[i]) m.append((m[i] + m[i + 1]) % MOD) if n % 2 == 1: print("pop") m.pop() print(sum(m) % MOD)
Statement You are given a positive integer N. Find the number of the pairs of integers u and v (0≦u,v≦N) such that there exist two non-negative integers a and b satisfying a xor b=u and a+b=v. Here, xor denotes the bitwise exclusive OR. Since it can be extremely large, compute the answer modulo 10^9+7.
[{"input": "3", "output": "5\n \n\nThe five possible pairs of u and v are:\n\n * u=0,v=0 (Let a=0,b=0, then 0 xor 0=0, 0+0=0.)\n\n * u=0,v=2 (Let a=1,b=1, then 1 xor 1=0, 1+1=2.\uff09\n\n * u=1,v=1 (Let a=1,b=0, then 1 xor 0=1, 1+0=1.\uff09\n\n * u=2,v=2 (Let a=2,b=0, then 2 xor 0=2, 2+0=2.\uff09\n\n * u=3,v=3 (Let a=3,b=0, then 3 xor 0=3, 3+0=3.\uff09\n\n* * *"}, {"input": "1422", "output": "52277\n \n\n* * *"}, {"input": "1000000000000000000", "output": "787014179"}]
Print the number of the possible pairs of integers u and v, modulo 10^9+7. * * *
s539626371
Wrong Answer
p03849
The input is given from Standard Input in the following format: N
N = int(input()) ans = 0 for i in range(N): tmp = 1 b = 1 while b <= i: if i & b > 0: tmp <<= 1 b <<= 1 tmp >>= 1 ans = (ans + tmp) % 10000000007 print(ans)
Statement You are given a positive integer N. Find the number of the pairs of integers u and v (0≦u,v≦N) such that there exist two non-negative integers a and b satisfying a xor b=u and a+b=v. Here, xor denotes the bitwise exclusive OR. Since it can be extremely large, compute the answer modulo 10^9+7.
[{"input": "3", "output": "5\n \n\nThe five possible pairs of u and v are:\n\n * u=0,v=0 (Let a=0,b=0, then 0 xor 0=0, 0+0=0.)\n\n * u=0,v=2 (Let a=1,b=1, then 1 xor 1=0, 1+1=2.\uff09\n\n * u=1,v=1 (Let a=1,b=0, then 1 xor 0=1, 1+0=1.\uff09\n\n * u=2,v=2 (Let a=2,b=0, then 2 xor 0=2, 2+0=2.\uff09\n\n * u=3,v=3 (Let a=3,b=0, then 3 xor 0=3, 3+0=3.\uff09\n\n* * *"}, {"input": "1422", "output": "52277\n \n\n* * *"}, {"input": "1000000000000000000", "output": "787014179"}]
Print the answer. * * *
s431407142
Wrong Answer
p03799
The input is given from Standard Input in the following format: N M
S, C = [int(v) for v in input().split(" ")] total = 0 for i in range(S): C -= 2 total += 1 # print(C) # C: 4->1, 8->2 total += int(C / 4) print(total)
Statement Snuke loves puzzles. Today, he is working on a puzzle using `S`\- and `c`-shaped pieces. In this puzzle, you can combine two `c`-shaped pieces into one `S`-shaped piece, as shown in the figure below: ![9b0bd546db9f28b4093d417b8f274124.png](https://atcoder.jp/img/arc069/9b0bd546db9f28b4093d417b8f274124.png) Snuke decided to create as many `Scc` groups as possible by putting together one `S`-shaped piece and two `c`-shaped pieces. Find the maximum number of `Scc` groups that can be created when Snuke has N `S`-shaped pieces and M `c`-shaped pieces.
[{"input": "1 6", "output": "2\n \n\nTwo `Scc` groups can be created as follows:\n\n * Combine two `c`-shaped pieces into one `S`-shaped piece\n * Create two `Scc` groups, each from one `S`-shaped piece and two `c`-shaped pieces\n\n* * *"}, {"input": "12345 678901", "output": "175897"}]
Print the answer. * * *
s196406745
Wrong Answer
p03799
The input is given from Standard Input in the following format: N M
N, M = map(int, (input()).split()) print((M // 2 + N) // 2)
Statement Snuke loves puzzles. Today, he is working on a puzzle using `S`\- and `c`-shaped pieces. In this puzzle, you can combine two `c`-shaped pieces into one `S`-shaped piece, as shown in the figure below: ![9b0bd546db9f28b4093d417b8f274124.png](https://atcoder.jp/img/arc069/9b0bd546db9f28b4093d417b8f274124.png) Snuke decided to create as many `Scc` groups as possible by putting together one `S`-shaped piece and two `c`-shaped pieces. Find the maximum number of `Scc` groups that can be created when Snuke has N `S`-shaped pieces and M `c`-shaped pieces.
[{"input": "1 6", "output": "2\n \n\nTwo `Scc` groups can be created as follows:\n\n * Combine two `c`-shaped pieces into one `S`-shaped piece\n * Create two `Scc` groups, each from one `S`-shaped piece and two `c`-shaped pieces\n\n* * *"}, {"input": "12345 678901", "output": "175897"}]
Print the answer. * * *
s568172860
Accepted
p03799
The input is given from Standard Input in the following format: N M
n, M = map(int, input().split()) l, r, ans = 0, 10**18, -1 while l <= r: m = (l + r) // 2 ns = max(0, m - n) uc = 2 * ns + 2 * m if uc <= M: ans = m l = m + 1 else: r = m - 1 print(ans)
Statement Snuke loves puzzles. Today, he is working on a puzzle using `S`\- and `c`-shaped pieces. In this puzzle, you can combine two `c`-shaped pieces into one `S`-shaped piece, as shown in the figure below: ![9b0bd546db9f28b4093d417b8f274124.png](https://atcoder.jp/img/arc069/9b0bd546db9f28b4093d417b8f274124.png) Snuke decided to create as many `Scc` groups as possible by putting together one `S`-shaped piece and two `c`-shaped pieces. Find the maximum number of `Scc` groups that can be created when Snuke has N `S`-shaped pieces and M `c`-shaped pieces.
[{"input": "1 6", "output": "2\n \n\nTwo `Scc` groups can be created as follows:\n\n * Combine two `c`-shaped pieces into one `S`-shaped piece\n * Create two `Scc` groups, each from one `S`-shaped piece and two `c`-shaped pieces\n\n* * *"}, {"input": "12345 678901", "output": "175897"}]
Print the answer. * * *
s425175057
Accepted
p03799
The input is given from Standard Input in the following format: N M
l = input().split() N = int(l[0]) M = int(l[1]) if N * 2 > M: Max = M // 2 elif N * 2 == M: Max = N else: N2 = N * 2 Max = (N2 + M) // 4 print(Max)
Statement Snuke loves puzzles. Today, he is working on a puzzle using `S`\- and `c`-shaped pieces. In this puzzle, you can combine two `c`-shaped pieces into one `S`-shaped piece, as shown in the figure below: ![9b0bd546db9f28b4093d417b8f274124.png](https://atcoder.jp/img/arc069/9b0bd546db9f28b4093d417b8f274124.png) Snuke decided to create as many `Scc` groups as possible by putting together one `S`-shaped piece and two `c`-shaped pieces. Find the maximum number of `Scc` groups that can be created when Snuke has N `S`-shaped pieces and M `c`-shaped pieces.
[{"input": "1 6", "output": "2\n \n\nTwo `Scc` groups can be created as follows:\n\n * Combine two `c`-shaped pieces into one `S`-shaped piece\n * Create two `Scc` groups, each from one `S`-shaped piece and two `c`-shaped pieces\n\n* * *"}, {"input": "12345 678901", "output": "175897"}]
Print the answer. * * *
s255663126
Wrong Answer
p03799
The input is given from Standard Input in the following format: N M
N, M = map(int, input().split()) res = -1 left = 0 right = M while left < right: mid1 = (2 * left + right) // 3 mid2 = (left + 2 * right) // 3 m1 = mid1 // 2 m2 = mid2 // 2 curr1 = min(m1 + N, M // 2 - m1) curr2 = min(m2 + N, M // 2 - m2) if curr1 < curr2: left = mid1 elif curr1 > curr2: right = mid2 else: res = mid1 break res = left if res == -1 else res print(res)
Statement Snuke loves puzzles. Today, he is working on a puzzle using `S`\- and `c`-shaped pieces. In this puzzle, you can combine two `c`-shaped pieces into one `S`-shaped piece, as shown in the figure below: ![9b0bd546db9f28b4093d417b8f274124.png](https://atcoder.jp/img/arc069/9b0bd546db9f28b4093d417b8f274124.png) Snuke decided to create as many `Scc` groups as possible by putting together one `S`-shaped piece and two `c`-shaped pieces. Find the maximum number of `Scc` groups that can be created when Snuke has N `S`-shaped pieces and M `c`-shaped pieces.
[{"input": "1 6", "output": "2\n \n\nTwo `Scc` groups can be created as follows:\n\n * Combine two `c`-shaped pieces into one `S`-shaped piece\n * Create two `Scc` groups, each from one `S`-shaped piece and two `c`-shaped pieces\n\n* * *"}, {"input": "12345 678901", "output": "175897"}]
Print the answer. * * *
s656391621
Runtime Error
p03799
The input is given from Standard Input in the following format: N M
u, v = map(int, input().split()) print(min(u//2, (2*u+v)//4)
Statement Snuke loves puzzles. Today, he is working on a puzzle using `S`\- and `c`-shaped pieces. In this puzzle, you can combine two `c`-shaped pieces into one `S`-shaped piece, as shown in the figure below: ![9b0bd546db9f28b4093d417b8f274124.png](https://atcoder.jp/img/arc069/9b0bd546db9f28b4093d417b8f274124.png) Snuke decided to create as many `Scc` groups as possible by putting together one `S`-shaped piece and two `c`-shaped pieces. Find the maximum number of `Scc` groups that can be created when Snuke has N `S`-shaped pieces and M `c`-shaped pieces.
[{"input": "1 6", "output": "2\n \n\nTwo `Scc` groups can be created as follows:\n\n * Combine two `c`-shaped pieces into one `S`-shaped piece\n * Create two `Scc` groups, each from one `S`-shaped piece and two `c`-shaped pieces\n\n* * *"}, {"input": "12345 678901", "output": "175897"}]
Print the answer. * * *
s828378128
Runtime Error
p03799
The input is given from Standard Input in the following format: N M
from functools import cmp_to_key n = int(input()) a = list(map(int, input().split())) def group(a): d = {} for i, x in enumerate(a): d.setdefault(x, []).append(i) s = sorted(d.items(), key=cmp_to_key(lambda x, y: x[0] - y[0]), reverse=True) return list(map(lambda x: [x[0], x[1][0], len(x[1])], s)) ans = [0] * n g = group(a) g.append([0, 0, 0]) for c, n in zip(g[:-1], g[1:]): ans[c[1]] += (c[0] - n[0]) * c[2] n[1] = min(c[1], n[1]) n[2] += c[2] [print(a) for a in ans]
Statement Snuke loves puzzles. Today, he is working on a puzzle using `S`\- and `c`-shaped pieces. In this puzzle, you can combine two `c`-shaped pieces into one `S`-shaped piece, as shown in the figure below: ![9b0bd546db9f28b4093d417b8f274124.png](https://atcoder.jp/img/arc069/9b0bd546db9f28b4093d417b8f274124.png) Snuke decided to create as many `Scc` groups as possible by putting together one `S`-shaped piece and two `c`-shaped pieces. Find the maximum number of `Scc` groups that can be created when Snuke has N `S`-shaped pieces and M `c`-shaped pieces.
[{"input": "1 6", "output": "2\n \n\nTwo `Scc` groups can be created as follows:\n\n * Combine two `c`-shaped pieces into one `S`-shaped piece\n * Create two `Scc` groups, each from one `S`-shaped piece and two `c`-shaped pieces\n\n* * *"}, {"input": "12345 678901", "output": "175897"}]
Print the answer. * * *
s418282455
Runtime Error
p03799
The input is given from Standard Input in the following format: N M
n,m=map(int,input().split()) p1=n p2=m//2 if p1>p2: print(p2) else: delta=p2-p1 print(delta//2+p1)
Statement Snuke loves puzzles. Today, he is working on a puzzle using `S`\- and `c`-shaped pieces. In this puzzle, you can combine two `c`-shaped pieces into one `S`-shaped piece, as shown in the figure below: ![9b0bd546db9f28b4093d417b8f274124.png](https://atcoder.jp/img/arc069/9b0bd546db9f28b4093d417b8f274124.png) Snuke decided to create as many `Scc` groups as possible by putting together one `S`-shaped piece and two `c`-shaped pieces. Find the maximum number of `Scc` groups that can be created when Snuke has N `S`-shaped pieces and M `c`-shaped pieces.
[{"input": "1 6", "output": "2\n \n\nTwo `Scc` groups can be created as follows:\n\n * Combine two `c`-shaped pieces into one `S`-shaped piece\n * Create two `Scc` groups, each from one `S`-shaped piece and two `c`-shaped pieces\n\n* * *"}, {"input": "12345 678901", "output": "175897"}]
Print the answer. * * *
s751924029
Accepted
p03799
The input is given from Standard Input in the following format: N M
N, M = map(int, input().split(" ")) s = min(N, M // 2) s += (M - s * 2) // 4 print(s)
Statement Snuke loves puzzles. Today, he is working on a puzzle using `S`\- and `c`-shaped pieces. In this puzzle, you can combine two `c`-shaped pieces into one `S`-shaped piece, as shown in the figure below: ![9b0bd546db9f28b4093d417b8f274124.png](https://atcoder.jp/img/arc069/9b0bd546db9f28b4093d417b8f274124.png) Snuke decided to create as many `Scc` groups as possible by putting together one `S`-shaped piece and two `c`-shaped pieces. Find the maximum number of `Scc` groups that can be created when Snuke has N `S`-shaped pieces and M `c`-shaped pieces.
[{"input": "1 6", "output": "2\n \n\nTwo `Scc` groups can be created as follows:\n\n * Combine two `c`-shaped pieces into one `S`-shaped piece\n * Create two `Scc` groups, each from one `S`-shaped piece and two `c`-shaped pieces\n\n* * *"}, {"input": "12345 678901", "output": "175897"}]
Print the answer. * * *
s739865768
Wrong Answer
p03799
The input is given from Standard Input in the following format: N M
a, b = map(int, input().split()) c = b - 2 * a print(a + c // 4)
Statement Snuke loves puzzles. Today, he is working on a puzzle using `S`\- and `c`-shaped pieces. In this puzzle, you can combine two `c`-shaped pieces into one `S`-shaped piece, as shown in the figure below: ![9b0bd546db9f28b4093d417b8f274124.png](https://atcoder.jp/img/arc069/9b0bd546db9f28b4093d417b8f274124.png) Snuke decided to create as many `Scc` groups as possible by putting together one `S`-shaped piece and two `c`-shaped pieces. Find the maximum number of `Scc` groups that can be created when Snuke has N `S`-shaped pieces and M `c`-shaped pieces.
[{"input": "1 6", "output": "2\n \n\nTwo `Scc` groups can be created as follows:\n\n * Combine two `c`-shaped pieces into one `S`-shaped piece\n * Create two `Scc` groups, each from one `S`-shaped piece and two `c`-shaped pieces\n\n* * *"}, {"input": "12345 678901", "output": "175897"}]
Print the answer. * * *
s812252560
Runtime Error
p03799
The input is given from Standard Input in the following format: N M
N,M = map(int()input().split()) if N <= M//2+1: print(N) else: print(N+(M-N*2)//4)
Statement Snuke loves puzzles. Today, he is working on a puzzle using `S`\- and `c`-shaped pieces. In this puzzle, you can combine two `c`-shaped pieces into one `S`-shaped piece, as shown in the figure below: ![9b0bd546db9f28b4093d417b8f274124.png](https://atcoder.jp/img/arc069/9b0bd546db9f28b4093d417b8f274124.png) Snuke decided to create as many `Scc` groups as possible by putting together one `S`-shaped piece and two `c`-shaped pieces. Find the maximum number of `Scc` groups that can be created when Snuke has N `S`-shaped pieces and M `c`-shaped pieces.
[{"input": "1 6", "output": "2\n \n\nTwo `Scc` groups can be created as follows:\n\n * Combine two `c`-shaped pieces into one `S`-shaped piece\n * Create two `Scc` groups, each from one `S`-shaped piece and two `c`-shaped pieces\n\n* * *"}, {"input": "12345 678901", "output": "175897"}]
Print the answer. * * *
s923221225
Accepted
p03799
The input is given from Standard Input in the following format: N M
n, k = (int(s) for s in input().strip().split(" ")) print((n * 2 + k) // 4 if k / 2 > n else k // 2)
Statement Snuke loves puzzles. Today, he is working on a puzzle using `S`\- and `c`-shaped pieces. In this puzzle, you can combine two `c`-shaped pieces into one `S`-shaped piece, as shown in the figure below: ![9b0bd546db9f28b4093d417b8f274124.png](https://atcoder.jp/img/arc069/9b0bd546db9f28b4093d417b8f274124.png) Snuke decided to create as many `Scc` groups as possible by putting together one `S`-shaped piece and two `c`-shaped pieces. Find the maximum number of `Scc` groups that can be created when Snuke has N `S`-shaped pieces and M `c`-shaped pieces.
[{"input": "1 6", "output": "2\n \n\nTwo `Scc` groups can be created as follows:\n\n * Combine two `c`-shaped pieces into one `S`-shaped piece\n * Create two `Scc` groups, each from one `S`-shaped piece and two `c`-shaped pieces\n\n* * *"}, {"input": "12345 678901", "output": "175897"}]
Print the answer. * * *
s383436807
Runtime Error
p03799
The input is given from Standard Input in the following format: N M
n,m=map(int,input().split()) p1=n p2=m//2 if p1>p2: print(p2) else: delta=p2-p1 print(delta//2+p1)
Statement Snuke loves puzzles. Today, he is working on a puzzle using `S`\- and `c`-shaped pieces. In this puzzle, you can combine two `c`-shaped pieces into one `S`-shaped piece, as shown in the figure below: ![9b0bd546db9f28b4093d417b8f274124.png](https://atcoder.jp/img/arc069/9b0bd546db9f28b4093d417b8f274124.png) Snuke decided to create as many `Scc` groups as possible by putting together one `S`-shaped piece and two `c`-shaped pieces. Find the maximum number of `Scc` groups that can be created when Snuke has N `S`-shaped pieces and M `c`-shaped pieces.
[{"input": "1 6", "output": "2\n \n\nTwo `Scc` groups can be created as follows:\n\n * Combine two `c`-shaped pieces into one `S`-shaped piece\n * Create two `Scc` groups, each from one `S`-shaped piece and two `c`-shaped pieces\n\n* * *"}, {"input": "12345 678901", "output": "175897"}]
Print the answer. * * *
s579547290
Runtime Error
p03799
The input is given from Standard Input in the following format: N M
u, v = map(int, input().split()) print(min(u//2, (2*u+v)//4))
Statement Snuke loves puzzles. Today, he is working on a puzzle using `S`\- and `c`-shaped pieces. In this puzzle, you can combine two `c`-shaped pieces into one `S`-shaped piece, as shown in the figure below: ![9b0bd546db9f28b4093d417b8f274124.png](https://atcoder.jp/img/arc069/9b0bd546db9f28b4093d417b8f274124.png) Snuke decided to create as many `Scc` groups as possible by putting together one `S`-shaped piece and two `c`-shaped pieces. Find the maximum number of `Scc` groups that can be created when Snuke has N `S`-shaped pieces and M `c`-shaped pieces.
[{"input": "1 6", "output": "2\n \n\nTwo `Scc` groups can be created as follows:\n\n * Combine two `c`-shaped pieces into one `S`-shaped piece\n * Create two `Scc` groups, each from one `S`-shaped piece and two `c`-shaped pieces\n\n* * *"}, {"input": "12345 678901", "output": "175897"}]
Print a sequence of operations that maximizes the number of cells containing an even number of coins, in the following format: N y_1 x_1 y_1' x_1' y_2 x_2 y_2' x_2' : y_N x_N y_N' x_N' That is, in the first line, print an integer N between 0 and H \times W (inclusive), representing the number of operations. In the (i+1)-th line (1 \leq i \leq N), print four integers y_i, x_i, y_i' and x_i' (1 \leq y_i, y_i' \leq H and 1 \leq x_i, x_i' \leq W), representing the i-th operation. These four integers represents the operation of moving one of the coins placed in Cell (y_i, x_i) to a vertically or horizontally adjacent cell, (y_i', x_i'). Note that if the specified operation violates the specification in the problem statement or the output format is invalid, it will result in _Wrong Answer_. * * *
s091337023
Wrong Answer
p03263
Input is given from Standard Input in the following format: H W a_{11} a_{12} ... a_{1W} a_{21} a_{22} ... a_{2W} : a_{H1} a_{H2} ... a_{HW}
H, W = map(int, input().split()) L = lines = [input().split(" ") for i in range(H)]
Statement There is a grid of square cells with H horizontal rows and W vertical columns. The cell at the i-th row and the j-th column will be denoted as Cell (i, j). In Cell (i, j), a_{ij} coins are placed. You can perform the following operation any number of times: Operation: Choose a cell that was not chosen before and contains one or more coins, then move one of those coins to a vertically or horizontally adjacent cell. Maximize the number of cells containing an even number of coins.
[{"input": "2 3\n 1 2 3\n 0 1 1", "output": "3\n 2 2 2 3\n 1 1 1 2\n 1 3 1 2\n \n\nEvery cell contains an even number of coins after the following sequence of\noperations:\n\n * Move the coin in Cell (2, 2) to Cell (2, 3).\n * Move the coin in Cell (1, 1) to Cell (1, 2).\n * Move one of the coins in Cell (1, 3) to Cell (1, 2).\n\n* * *"}, {"input": "3 2\n 1 0\n 2 1\n 1 0", "output": "3\n 1 1 1 2\n 1 2 2 2\n 3 1 3 2\n \n\n* * *"}, {"input": "1 5\n 9 9 9 9 9", "output": "2\n 1 1 1 2\n 1 3 1 4"}]
Print a sequence of operations that maximizes the number of cells containing an even number of coins, in the following format: N y_1 x_1 y_1' x_1' y_2 x_2 y_2' x_2' : y_N x_N y_N' x_N' That is, in the first line, print an integer N between 0 and H \times W (inclusive), representing the number of operations. In the (i+1)-th line (1 \leq i \leq N), print four integers y_i, x_i, y_i' and x_i' (1 \leq y_i, y_i' \leq H and 1 \leq x_i, x_i' \leq W), representing the i-th operation. These four integers represents the operation of moving one of the coins placed in Cell (y_i, x_i) to a vertically or horizontally adjacent cell, (y_i', x_i'). Note that if the specified operation violates the specification in the problem statement or the output format is invalid, it will result in _Wrong Answer_. * * *
s770591863
Runtime Error
p03263
Input is given from Standard Input in the following format: H W a_{11} a_{12} ... a_{1W} a_{21} a_{22} ... a_{2W} : a_{H1} a_{H2} ... a_{HW}
import sys sys.setrecursionlimit(4100000) import math import logging logging.basicConfig(level=logging.DEBUG) logger = logging.getLogger(__name__) # from collections import defaultdict # d = defaultdict(list) # from itertools import combinations # comb = combinations(range(N), 2) # 累積和 # from itertools import accumulate # _list = list(accumulate(a_list) # from functools import lru_cache # @lru_cache(maxsize=None) # def setUp(self): # dp.cache_clear() from collections import deque def resolve(): # S = [x for x in sys.stdin.readline().split()][0] # 文字列 一つ # N = [int(x) for x in sys.stdin.readline().split()][0] # int 一つ H, W = [int(x) for x in sys.stdin.readline().split()] # 複数int # h_list = [int(x) for x in sys.stdin.readline().split()] # 複数int # grid = [list(sys.stdin.readline().split()[0]) for _ in range(N)] # 文字列grid # v_list = [int(sys.stdin.readline().split()[0]) for _ in range(N)] grid = [ [int(x) for x in sys.stdin.readline().split()] for _ in range(H) ] # int grid logger.debug("{}".format([])) I_MIN = 0 I_MAX = H - 1 J_MIN = 0 J_MAX = W - 1 delta_i = [0, -1, 0, 1] delta_j = [1, 0, -1, 0] global_track_list = [] global_visited_set = set() for i_outer in range(H): for j_outer in range(W): if ( grid[i_outer][j_outer] % 2 == 1 and (i_outer, j_outer) not in global_visited_set ): queue = deque() queue.append((i_outer, j_outer, [])) bfs_visited_set = set() bfs_visited_set.add((i_outer, j_outer)) to_break = False while queue: i, j, _track_list = queue.popleft() for d in range(4): i_next = i + delta_i[d] j_next = j + delta_j[d] if ( I_MIN <= i_next <= I_MAX and J_MIN <= j_next <= J_MAX and (i_next, j_next) not in bfs_visited_set and (i_next, j_next) not in global_visited_set ): bfs_visited_set.add((i_next, j_next)) track_list = _track_list.copy() track_list.append((i_next, j_next, i, j)) if grid[i_next][j_next] % 2 == 1: # reverse global_track_list += track_list[::-1] for a_next, b_next, a, b in track_list: global_visited_set.add((a_next, b_next)) global_visited_set.add((a, b)) to_break = True break else: queue.append((i_next, j_next, track_list)) if to_break: break print(len(global_track_list)) for t in global_track_list: print(" ".join([str(i + 1) for i in t])) if __name__ == "__main__": resolve() # AtCoder Unit Test で自動生成できる, 最後のunittest.main は消す # python -m unittest template/template.py で実行できる # pypy3 -m unittest template/template.py で実行できる 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 = """2 3 1 2 3 0 1 1""" output = """3 2 2 2 3 1 1 1 2 1 3 1 2""" self.assertIO(input, output) def test_入力例_2(self): input = """3 2 1 0 2 1 1 0""" output = """3 1 1 1 2 1 2 2 2 3 1 3 2""" self.assertIO(input, output) def test_入力例_3(self): input = """1 5 9 9 9 9 9""" output = """2 1 1 1 2 1 3 1 4""" self.assertIO(input, output)
Statement There is a grid of square cells with H horizontal rows and W vertical columns. The cell at the i-th row and the j-th column will be denoted as Cell (i, j). In Cell (i, j), a_{ij} coins are placed. You can perform the following operation any number of times: Operation: Choose a cell that was not chosen before and contains one or more coins, then move one of those coins to a vertically or horizontally adjacent cell. Maximize the number of cells containing an even number of coins.
[{"input": "2 3\n 1 2 3\n 0 1 1", "output": "3\n 2 2 2 3\n 1 1 1 2\n 1 3 1 2\n \n\nEvery cell contains an even number of coins after the following sequence of\noperations:\n\n * Move the coin in Cell (2, 2) to Cell (2, 3).\n * Move the coin in Cell (1, 1) to Cell (1, 2).\n * Move one of the coins in Cell (1, 3) to Cell (1, 2).\n\n* * *"}, {"input": "3 2\n 1 0\n 2 1\n 1 0", "output": "3\n 1 1 1 2\n 1 2 2 2\n 3 1 3 2\n \n\n* * *"}, {"input": "1 5\n 9 9 9 9 9", "output": "2\n 1 1 1 2\n 1 3 1 4"}]
Print a sequence of operations that maximizes the number of cells containing an even number of coins, in the following format: N y_1 x_1 y_1' x_1' y_2 x_2 y_2' x_2' : y_N x_N y_N' x_N' That is, in the first line, print an integer N between 0 and H \times W (inclusive), representing the number of operations. In the (i+1)-th line (1 \leq i \leq N), print four integers y_i, x_i, y_i' and x_i' (1 \leq y_i, y_i' \leq H and 1 \leq x_i, x_i' \leq W), representing the i-th operation. These four integers represents the operation of moving one of the coins placed in Cell (y_i, x_i) to a vertically or horizontally adjacent cell, (y_i', x_i'). Note that if the specified operation violates the specification in the problem statement or the output format is invalid, it will result in _Wrong Answer_. * * *
s474746590
Accepted
p03263
Input is given from Standard Input in the following format: H W a_{11} a_{12} ... a_{1W} a_{21} a_{22} ... a_{2W} : a_{H1} a_{H2} ... a_{HW}
f = lambda: [*map(int, input().split())] r = range h, w = f() g = [f() for _ in r(h)] a = [] for x in r(h): for y in r(w): if g[x][y] % 2 and (x + 1) * (y + 1) < h * w: if (t := y + 1) < w: s = x elif (s := x + 1) < h: t = y g[x][y] -= 1 g[s][t] += 1 a += [(x + 1, y + 1, s + 1, t + 1)] print(len(a)) for l in a: print(*l)
Statement There is a grid of square cells with H horizontal rows and W vertical columns. The cell at the i-th row and the j-th column will be denoted as Cell (i, j). In Cell (i, j), a_{ij} coins are placed. You can perform the following operation any number of times: Operation: Choose a cell that was not chosen before and contains one or more coins, then move one of those coins to a vertically or horizontally adjacent cell. Maximize the number of cells containing an even number of coins.
[{"input": "2 3\n 1 2 3\n 0 1 1", "output": "3\n 2 2 2 3\n 1 1 1 2\n 1 3 1 2\n \n\nEvery cell contains an even number of coins after the following sequence of\noperations:\n\n * Move the coin in Cell (2, 2) to Cell (2, 3).\n * Move the coin in Cell (1, 1) to Cell (1, 2).\n * Move one of the coins in Cell (1, 3) to Cell (1, 2).\n\n* * *"}, {"input": "3 2\n 1 0\n 2 1\n 1 0", "output": "3\n 1 1 1 2\n 1 2 2 2\n 3 1 3 2\n \n\n* * *"}, {"input": "1 5\n 9 9 9 9 9", "output": "2\n 1 1 1 2\n 1 3 1 4"}]
Print a sequence of operations that maximizes the number of cells containing an even number of coins, in the following format: N y_1 x_1 y_1' x_1' y_2 x_2 y_2' x_2' : y_N x_N y_N' x_N' That is, in the first line, print an integer N between 0 and H \times W (inclusive), representing the number of operations. In the (i+1)-th line (1 \leq i \leq N), print four integers y_i, x_i, y_i' and x_i' (1 \leq y_i, y_i' \leq H and 1 \leq x_i, x_i' \leq W), representing the i-th operation. These four integers represents the operation of moving one of the coins placed in Cell (y_i, x_i) to a vertically or horizontally adjacent cell, (y_i', x_i'). Note that if the specified operation violates the specification in the problem statement or the output format is invalid, it will result in _Wrong Answer_. * * *
s144734408
Runtime Error
p03263
Input is given from Standard Input in the following format: H W a_{11} a_{12} ... a_{1W} a_{21} a_{22} ... a_{2W} : a_{H1} a_{H2} ... a_{HW}
H,W = map(int,input().split()) A=[] for i in range(H): A.append(list(map(int,input().split()))) num=0 ans='' for i in range(H): for j in range(W): if i%2==0: n=j else: n=W-1-j if A[i][n]%2==1: A[i][n]-=1 if i!=H-1 and (i%2==0 and n==W-1) or (i%2==1 and n==0): num+=1 A[i+1][n]+=1 ans+='{} {} {} {}'.format(i+1 n+1 i+2 n+1) if (i%2==0 and n!=W-1) or (i%2==1 and n!=0): num+=1 A[i][n+(-1)**(i%2)]+=1 ans+='{} {} {} {}'.format(i+1,n+1,i+1,n+1+(-1)**(i%2)) print(num) print(ans)
Statement There is a grid of square cells with H horizontal rows and W vertical columns. The cell at the i-th row and the j-th column will be denoted as Cell (i, j). In Cell (i, j), a_{ij} coins are placed. You can perform the following operation any number of times: Operation: Choose a cell that was not chosen before and contains one or more coins, then move one of those coins to a vertically or horizontally adjacent cell. Maximize the number of cells containing an even number of coins.
[{"input": "2 3\n 1 2 3\n 0 1 1", "output": "3\n 2 2 2 3\n 1 1 1 2\n 1 3 1 2\n \n\nEvery cell contains an even number of coins after the following sequence of\noperations:\n\n * Move the coin in Cell (2, 2) to Cell (2, 3).\n * Move the coin in Cell (1, 1) to Cell (1, 2).\n * Move one of the coins in Cell (1, 3) to Cell (1, 2).\n\n* * *"}, {"input": "3 2\n 1 0\n 2 1\n 1 0", "output": "3\n 1 1 1 2\n 1 2 2 2\n 3 1 3 2\n \n\n* * *"}, {"input": "1 5\n 9 9 9 9 9", "output": "2\n 1 1 1 2\n 1 3 1 4"}]
Print a sequence of operations that maximizes the number of cells containing an even number of coins, in the following format: N y_1 x_1 y_1' x_1' y_2 x_2 y_2' x_2' : y_N x_N y_N' x_N' That is, in the first line, print an integer N between 0 and H \times W (inclusive), representing the number of operations. In the (i+1)-th line (1 \leq i \leq N), print four integers y_i, x_i, y_i' and x_i' (1 \leq y_i, y_i' \leq H and 1 \leq x_i, x_i' \leq W), representing the i-th operation. These four integers represents the operation of moving one of the coins placed in Cell (y_i, x_i) to a vertically or horizontally adjacent cell, (y_i', x_i'). Note that if the specified operation violates the specification in the problem statement or the output format is invalid, it will result in _Wrong Answer_. * * *
s223308125
Runtime Error
p03263
Input is given from Standard Input in the following format: H W a_{11} a_{12} ... a_{1W} a_{21} a_{22} ... a_{2W} : a_{H1} a_{H2} ... a_{HW}
def move_one_coine(target_i, target_j): while grids[target_j][target_i] < 2: for j in range(H): for i in range(W): if grids[j][i] >= 3: grids[j][i] -= 1 grids[target_j][target_i] += 1 append_steps_to_answer(target_j, target_i, j, i) if j == H - 1 and i == W - 1: return def append_steps_to_answer(j1, i1, j2, i2): prv_i = i1 for i in range(i1 + 1, i2 + 1): ans.append([j1, prv_i, j2, i]) prv_i = i prv_j = j1 for j in range(j1 + 1, j2 + 1): ans.append([prv_j, i1, j2, i2]) prv_j = j H, W = map(int, input().split()) grids = [list(map(int, input().split())) for _ in range(H)] ans = [] for j in range(H): for i in range(W): if grids[j][i] in [0, 1]: move_one_coine(i, j) girds_to_move = None for j in range(H): for i in range(W): if grids[j][i] % 2 == 1: if girds_to_move is None: girds_to_move = [j, i] else: grids[girds_to_move[0]][girds_to_move[1]] += 1 grids[j][i] -= 1 append_steps_to_answer(*girds_to_move, j, i) print(len(ans)) [print(*map(lambda x: x + 1, process)) for process in ans]
Statement There is a grid of square cells with H horizontal rows and W vertical columns. The cell at the i-th row and the j-th column will be denoted as Cell (i, j). In Cell (i, j), a_{ij} coins are placed. You can perform the following operation any number of times: Operation: Choose a cell that was not chosen before and contains one or more coins, then move one of those coins to a vertically or horizontally adjacent cell. Maximize the number of cells containing an even number of coins.
[{"input": "2 3\n 1 2 3\n 0 1 1", "output": "3\n 2 2 2 3\n 1 1 1 2\n 1 3 1 2\n \n\nEvery cell contains an even number of coins after the following sequence of\noperations:\n\n * Move the coin in Cell (2, 2) to Cell (2, 3).\n * Move the coin in Cell (1, 1) to Cell (1, 2).\n * Move one of the coins in Cell (1, 3) to Cell (1, 2).\n\n* * *"}, {"input": "3 2\n 1 0\n 2 1\n 1 0", "output": "3\n 1 1 1 2\n 1 2 2 2\n 3 1 3 2\n \n\n* * *"}, {"input": "1 5\n 9 9 9 9 9", "output": "2\n 1 1 1 2\n 1 3 1 4"}]
Print a sequence of operations that maximizes the number of cells containing an even number of coins, in the following format: N y_1 x_1 y_1' x_1' y_2 x_2 y_2' x_2' : y_N x_N y_N' x_N' That is, in the first line, print an integer N between 0 and H \times W (inclusive), representing the number of operations. In the (i+1)-th line (1 \leq i \leq N), print four integers y_i, x_i, y_i' and x_i' (1 \leq y_i, y_i' \leq H and 1 \leq x_i, x_i' \leq W), representing the i-th operation. These four integers represents the operation of moving one of the coins placed in Cell (y_i, x_i) to a vertically or horizontally adjacent cell, (y_i', x_i'). Note that if the specified operation violates the specification in the problem statement or the output format is invalid, it will result in _Wrong Answer_. * * *
s833377205
Runtime Error
p03263
Input is given from Standard Input in the following format: H W a_{11} a_{12} ... a_{1W} a_{21} a_{22} ... a_{2W} : a_{H1} a_{H2} ... a_{HW}
#!/usr/bin/env python3 from collections import defaultdict from collections import deque from heapq import heappush, heappop import sys import math import bisect import random import itertools sys.setrecursionlimit(10**5) stdin = sys.stdin bisect_left = bisect.bisect_left bisect_right = bisect.bisect_right def LI(): return list(map(int, stdin.readline().split())) def LF(): return list(map(float, stdin.readline().split())) def LI_(): return list(map(lambda x: int(x)-1, stdin.readline().split())) def II(): return int(stdin.readline()) def IF(): return float(stdin.readline()) def LS(): return list(map(list, stdin.readline().split())) def S(): return list(stdin.readline().rstrip()) def IR(n): return [II() for _ in range(n)] def LIR(n): return [LI() for _ in range(n)] def FR(n): return [IF() for _ in range(n)] def LFR(n): return [LI() for _ in range(n)] def LIR_(n): return [LI_() for _ in range(n)] def SR(n): return [S() for _ in range(n)] def LSR(n): return [LS() for _ in range(n)] mod = 1000000007 inf = float('INF') #A def A(): a, b = LI() if (a * b) % 2: print("Yes") else: print("No") return #B def B(): n = II() w = SR(n) d = [] for i in w: d.append("".join(i)) if len(set(d)) != n: print("No") return for i in range(n - 1): if w[i][-1] != w[i + 1][0]: print("No") return print("Yes") return #C def C(): def gcd(a, b): a, b = max(a, b), min(a, b) while b: a, b = b, a % b return a n, x = LI() xn = LI()+[x] xn.sort() ans = xn[1] - xn[0] for i in range(1, n): ans = gcd(ans, xn[i + 1] - xn[i]) print(ans) return #D def D(): h, w = LI() d = [] for y in range(h): a = LI() tmp = [] for x in range(w): if a[x] & 1: tmp.append((y,x)) for t in tmp[::-1 if y & 1 else 1]: d.append(t) ans = [] for i in range(0, len(d) - 1, 2): y, x = d[i] next_y, next_x = d[i + 1] while abs(x - next_x) > 0: ans.append((y + 1, x + 1, y + 1, x + 1 + (1 if x < next_x else - 1)) x += 1 if x < next_x else - 1 while abs(y - next_y) > 0: ans.append((y + 1, x + 1, y + 1 + (1 if y < next_y else - 1), x + 1)) y += 1 if y < next_y else - 1 print(len(ans)) for a in ans: print(*a) return #Solve if __name__ == '__main__': D()
Statement There is a grid of square cells with H horizontal rows and W vertical columns. The cell at the i-th row and the j-th column will be denoted as Cell (i, j). In Cell (i, j), a_{ij} coins are placed. You can perform the following operation any number of times: Operation: Choose a cell that was not chosen before and contains one or more coins, then move one of those coins to a vertically or horizontally adjacent cell. Maximize the number of cells containing an even number of coins.
[{"input": "2 3\n 1 2 3\n 0 1 1", "output": "3\n 2 2 2 3\n 1 1 1 2\n 1 3 1 2\n \n\nEvery cell contains an even number of coins after the following sequence of\noperations:\n\n * Move the coin in Cell (2, 2) to Cell (2, 3).\n * Move the coin in Cell (1, 1) to Cell (1, 2).\n * Move one of the coins in Cell (1, 3) to Cell (1, 2).\n\n* * *"}, {"input": "3 2\n 1 0\n 2 1\n 1 0", "output": "3\n 1 1 1 2\n 1 2 2 2\n 3 1 3 2\n \n\n* * *"}, {"input": "1 5\n 9 9 9 9 9", "output": "2\n 1 1 1 2\n 1 3 1 4"}]
Print a sequence of operations that maximizes the number of cells containing an even number of coins, in the following format: N y_1 x_1 y_1' x_1' y_2 x_2 y_2' x_2' : y_N x_N y_N' x_N' That is, in the first line, print an integer N between 0 and H \times W (inclusive), representing the number of operations. In the (i+1)-th line (1 \leq i \leq N), print four integers y_i, x_i, y_i' and x_i' (1 \leq y_i, y_i' \leq H and 1 \leq x_i, x_i' \leq W), representing the i-th operation. These four integers represents the operation of moving one of the coins placed in Cell (y_i, x_i) to a vertically or horizontally adjacent cell, (y_i', x_i'). Note that if the specified operation violates the specification in the problem statement or the output format is invalid, it will result in _Wrong Answer_. * * *
s655575676
Accepted
p03263
Input is given from Standard Input in the following format: H W a_{11} a_{12} ... a_{1W} a_{21} a_{22} ... a_{2W} : a_{H1} a_{H2} ... a_{HW}
a, b = input().split() S = 0 T = 0 echo = [] for x in range(int(a)): S += 1 l = [int(x) for x in input().split()] for c in range(int(b) - 1): if l[c] % 2 == 1: echo.append( str(str(S) + " " + str(c + 1) + " " + str(S) + " " + str(c + 2)) ) l[c] = l[c] - 1 l[c + 1] = l[c + 1] + 1 # print(sum(l),T) # print(l) if (sum(l) + T) % 2 == 1 and x + 1 < int(a): echo.append(str(str(S) + " " + str(b) + " " + str(S + 1) + " " + str(b))) T = 1 else: T = 0 print(len(echo)) for y in echo: print(y)
Statement There is a grid of square cells with H horizontal rows and W vertical columns. The cell at the i-th row and the j-th column will be denoted as Cell (i, j). In Cell (i, j), a_{ij} coins are placed. You can perform the following operation any number of times: Operation: Choose a cell that was not chosen before and contains one or more coins, then move one of those coins to a vertically or horizontally adjacent cell. Maximize the number of cells containing an even number of coins.
[{"input": "2 3\n 1 2 3\n 0 1 1", "output": "3\n 2 2 2 3\n 1 1 1 2\n 1 3 1 2\n \n\nEvery cell contains an even number of coins after the following sequence of\noperations:\n\n * Move the coin in Cell (2, 2) to Cell (2, 3).\n * Move the coin in Cell (1, 1) to Cell (1, 2).\n * Move one of the coins in Cell (1, 3) to Cell (1, 2).\n\n* * *"}, {"input": "3 2\n 1 0\n 2 1\n 1 0", "output": "3\n 1 1 1 2\n 1 2 2 2\n 3 1 3 2\n \n\n* * *"}, {"input": "1 5\n 9 9 9 9 9", "output": "2\n 1 1 1 2\n 1 3 1 4"}]
Print a sequence of operations that maximizes the number of cells containing an even number of coins, in the following format: N y_1 x_1 y_1' x_1' y_2 x_2 y_2' x_2' : y_N x_N y_N' x_N' That is, in the first line, print an integer N between 0 and H \times W (inclusive), representing the number of operations. In the (i+1)-th line (1 \leq i \leq N), print four integers y_i, x_i, y_i' and x_i' (1 \leq y_i, y_i' \leq H and 1 \leq x_i, x_i' \leq W), representing the i-th operation. These four integers represents the operation of moving one of the coins placed in Cell (y_i, x_i) to a vertically or horizontally adjacent cell, (y_i', x_i'). Note that if the specified operation violates the specification in the problem statement or the output format is invalid, it will result in _Wrong Answer_. * * *
s914508717
Runtime Error
p03263
Input is given from Standard Input in the following format: H W a_{11} a_{12} ... a_{1W} a_{21} a_{22} ... a_{2W} : a_{H1} a_{H2} ... a_{HW}
H,W = map(int,input().split()) Data = [] for _ in range(H): List = list(map(int,input().split())) Data.append(List) Ans = [] for i in range(H-1): for j in range(W): if Data[i][j] % 2 != 0: Data[i][j] -= 1 Data[i+1][j] += 1 Ans.append([i,j,i+1,j]) for j in range(W-1): if Data[H-1][j] % 2 != 0: Data[H-1][j] -= 1 Data[H-1][j+1] += 1 Ans.append([H-1,j,H-1,j+1]) print(len(Ans)) for ans in Ans: print( "{} {} {} {}".fo
Statement There is a grid of square cells with H horizontal rows and W vertical columns. The cell at the i-th row and the j-th column will be denoted as Cell (i, j). In Cell (i, j), a_{ij} coins are placed. You can perform the following operation any number of times: Operation: Choose a cell that was not chosen before and contains one or more coins, then move one of those coins to a vertically or horizontally adjacent cell. Maximize the number of cells containing an even number of coins.
[{"input": "2 3\n 1 2 3\n 0 1 1", "output": "3\n 2 2 2 3\n 1 1 1 2\n 1 3 1 2\n \n\nEvery cell contains an even number of coins after the following sequence of\noperations:\n\n * Move the coin in Cell (2, 2) to Cell (2, 3).\n * Move the coin in Cell (1, 1) to Cell (1, 2).\n * Move one of the coins in Cell (1, 3) to Cell (1, 2).\n\n* * *"}, {"input": "3 2\n 1 0\n 2 1\n 1 0", "output": "3\n 1 1 1 2\n 1 2 2 2\n 3 1 3 2\n \n\n* * *"}, {"input": "1 5\n 9 9 9 9 9", "output": "2\n 1 1 1 2\n 1 3 1 4"}]
Print a sequence of operations that maximizes the number of cells containing an even number of coins, in the following format: N y_1 x_1 y_1' x_1' y_2 x_2 y_2' x_2' : y_N x_N y_N' x_N' That is, in the first line, print an integer N between 0 and H \times W (inclusive), representing the number of operations. In the (i+1)-th line (1 \leq i \leq N), print four integers y_i, x_i, y_i' and x_i' (1 \leq y_i, y_i' \leq H and 1 \leq x_i, x_i' \leq W), representing the i-th operation. These four integers represents the operation of moving one of the coins placed in Cell (y_i, x_i) to a vertically or horizontally adjacent cell, (y_i', x_i'). Note that if the specified operation violates the specification in the problem statement or the output format is invalid, it will result in _Wrong Answer_. * * *
s326820877
Runtime Error
p03263
Input is given from Standard Input in the following format: H W a_{11} a_{12} ... a_{1W} a_{21} a_{22} ... a_{2W} : a_{H1} a_{H2} ... a_{HW}
# #    ⋀_⋀  #   (・ω・) # ./ U ∽ U\ # │* 合 *│ # │* 格 *│ # │* 祈 *│ # │* 願 *│ # │*   *│ #  ̄ # import sys sys.setrecursionlimit(10**6) input=sys.stdin.readline from math import floor,ceil,sqrt,factorial,hypot,log #log2ないyp from heapq import heappop, heappush, heappushpop from collections import Counter,defaultdict,deque from itertools import accumulate,permutations,combinations,product,combinations_with_replacement from bisect import bisect_left,bisect_right from copy import deepcopy inf=float('inf') mod = 10**9+7 def pprint(*A): for a in A: print(*a,sep='\n') def INT_(n): return int(n)-1 def MI(): return map(int,input().split()) def MF(): return map(float, input().split()) def MI_(): return map(INT_,input().split()) def LI(): return list(MI()) def LI_(): return [int(x) - 1 for x in input().split()] def LF(): return list(MF()) def LIN(n:int): return [I() for _ in range(n)] def LLIN(n: int): return [LI() for _ in range(n)] def LLIN_(n: int): return [LI_() for _ in range(n)] def LLI(): return [list(map(int, l.split() )) for l in input()] def I(): return int(input()) def F(): return float(input()) def ST(): return input().replace('\n', '') def main(): H,W=MI() A=LLIN(H) odds=[] ans=[] for i in range(H): if i&1: for j in range(W)[::-1]: if A[i][j]&1: if j==0: dy=1 dx=0 else: dy=0 dx=-1 if i+dy!=H: ans.append((i+1,j+1,i+dy+1,j+dx+1)) A[i+dy][j+dx]+=1 else: for j in range(W)[::-1]: if A[i][j]&1: if j==W-1: dy=1 dx=0 else: dy=0 dx=1 if i+dy!=H: ans.append((i+1,j+1,i+dy+1,j+dx+1)) A[i+dy][j+dx]+=1 print(len(ans)) for a in ans: print(*a) if __name__ == '__main__':   main()
Statement There is a grid of square cells with H horizontal rows and W vertical columns. The cell at the i-th row and the j-th column will be denoted as Cell (i, j). In Cell (i, j), a_{ij} coins are placed. You can perform the following operation any number of times: Operation: Choose a cell that was not chosen before and contains one or more coins, then move one of those coins to a vertically or horizontally adjacent cell. Maximize the number of cells containing an even number of coins.
[{"input": "2 3\n 1 2 3\n 0 1 1", "output": "3\n 2 2 2 3\n 1 1 1 2\n 1 3 1 2\n \n\nEvery cell contains an even number of coins after the following sequence of\noperations:\n\n * Move the coin in Cell (2, 2) to Cell (2, 3).\n * Move the coin in Cell (1, 1) to Cell (1, 2).\n * Move one of the coins in Cell (1, 3) to Cell (1, 2).\n\n* * *"}, {"input": "3 2\n 1 0\n 2 1\n 1 0", "output": "3\n 1 1 1 2\n 1 2 2 2\n 3 1 3 2\n \n\n* * *"}, {"input": "1 5\n 9 9 9 9 9", "output": "2\n 1 1 1 2\n 1 3 1 4"}]
Print a sequence of operations that maximizes the number of cells containing an even number of coins, in the following format: N y_1 x_1 y_1' x_1' y_2 x_2 y_2' x_2' : y_N x_N y_N' x_N' That is, in the first line, print an integer N between 0 and H \times W (inclusive), representing the number of operations. In the (i+1)-th line (1 \leq i \leq N), print four integers y_i, x_i, y_i' and x_i' (1 \leq y_i, y_i' \leq H and 1 \leq x_i, x_i' \leq W), representing the i-th operation. These four integers represents the operation of moving one of the coins placed in Cell (y_i, x_i) to a vertically or horizontally adjacent cell, (y_i', x_i'). Note that if the specified operation violates the specification in the problem statement or the output format is invalid, it will result in _Wrong Answer_. * * *
s268172728
Runtime Error
p03263
Input is given from Standard Input in the following format: H W a_{11} a_{12} ... a_{1W} a_{21} a_{22} ... a_{2W} : a_{H1} a_{H2} ... a_{HW}
#!/usr/bin/env python3 import sys def validToGo(h, w, H, W, visited): return h >= 0 and w >= 0 and h < H and w < W and not visited[h][w] def prettyPrint(M): for i in range(len(M)): r = M[i] message = "" for j in range(len(r)): message += f" {r[j]}" print(message) def solve(H: int, W: int, a: "List[List[int]]"): visited = [[False for w in range(W)] for h in range(H)] odds = set([]) count = 0 for h in range(H): for w in range(W): count += a[h][w] if a[h][w] % 2 == 1: odds.add((h, w)) step = 0 steps = [] while len(odds) > count % 2: # prettyPrint(a) h, w = odds.pop() if a[h][w] % 2 == 0: continue step += 1 # print(f"next: ({h} , {w})") visited[h][w] = True if validToGo(h - 1, w, H, W, visited) and a[h - 1][w] % 2 == 1: a[h - 1][w] += 1 a[h][w] -= 1 steps.append((h, w, h - 1, w)) continue if validToGo(h + 1, w, H, W, visited) and a[h + 1][w] % 2 == 1: a[h + 1][w] += 1 a[h][w] -= 1 steps.append((h, w, h + 1, w)) continue if validToGo(h, w - 1, H, W, visited) and a[h][w - 1] % 2 == 1: a[h][w - 1] += 1 a[h][w] -= 1 steps.append((h, w, h, w - 1)) continue if validToGo(h, w + 1, H, W, visited) and a[h][w + 1] % 2 == 1: a[h][w + 1] += 1 a[h][w] -= 1 steps.append((h, w, h, w + 1)) continue if validToGo(h - 1, w, H, W, visited) and a[h - 1][w] % 2 == 0: a[h - 1][w] += 1 a[h][w] -= 1 odds.add((h - 1, w)) steps.append((h, w, h - 1, w)) continue if validToGo(h + 1, w, H, W, visited) and a[h + 1][w] % 2 == 0: a[h + 1][w] += 1 a[h][w] -= 1 odds.add((h + 1, w)) steps.append((h, w, h + 1, w)) continue if validToGo(h, w - 1, H, W, visited) and a[h][w - 1] % 2 == 0: a[h][w - 1] += 1 a[h][w] -= 1 odds.add((h, w - 1)) steps.append((h, w, h, w - 1)) continue if validToGo(h, w + 1, H, W, visited) and a[h][w + 1] % 2 == 0: a[h][w + 1] += 1 a[h][w] -= 1 odds.add((h, w + 1)) steps.append((h, w, h, w + 1)) continue print(step) for s in steps: print(f"{s[0]} {s[1]} {s[2]} {s[3]}") # prettyPrint(a) return # Generated by 1.1.4 https://github.com/kyuridenamida/atcoder-tools (tips: You use the default template now. You can remove this line by using your custom template) def main(): def iterate_tokens(): for line in sys.stdin: for word in line.split(): yield word tokens = iterate_tokens() H = int(next(tokens)) # type: int W = int(next(tokens)) # type: int a = [ [int(next(tokens)) for _ in range(W)] for _ in range(H) ] # type: "List[List[int]]" solve(H, W, a) if __name__ == "__main__": main()
Statement There is a grid of square cells with H horizontal rows and W vertical columns. The cell at the i-th row and the j-th column will be denoted as Cell (i, j). In Cell (i, j), a_{ij} coins are placed. You can perform the following operation any number of times: Operation: Choose a cell that was not chosen before and contains one or more coins, then move one of those coins to a vertically or horizontally adjacent cell. Maximize the number of cells containing an even number of coins.
[{"input": "2 3\n 1 2 3\n 0 1 1", "output": "3\n 2 2 2 3\n 1 1 1 2\n 1 3 1 2\n \n\nEvery cell contains an even number of coins after the following sequence of\noperations:\n\n * Move the coin in Cell (2, 2) to Cell (2, 3).\n * Move the coin in Cell (1, 1) to Cell (1, 2).\n * Move one of the coins in Cell (1, 3) to Cell (1, 2).\n\n* * *"}, {"input": "3 2\n 1 0\n 2 1\n 1 0", "output": "3\n 1 1 1 2\n 1 2 2 2\n 3 1 3 2\n \n\n* * *"}, {"input": "1 5\n 9 9 9 9 9", "output": "2\n 1 1 1 2\n 1 3 1 4"}]
Print a sequence of operations that maximizes the number of cells containing an even number of coins, in the following format: N y_1 x_1 y_1' x_1' y_2 x_2 y_2' x_2' : y_N x_N y_N' x_N' That is, in the first line, print an integer N between 0 and H \times W (inclusive), representing the number of operations. In the (i+1)-th line (1 \leq i \leq N), print four integers y_i, x_i, y_i' and x_i' (1 \leq y_i, y_i' \leq H and 1 \leq x_i, x_i' \leq W), representing the i-th operation. These four integers represents the operation of moving one of the coins placed in Cell (y_i, x_i) to a vertically or horizontally adjacent cell, (y_i', x_i'). Note that if the specified operation violates the specification in the problem statement or the output format is invalid, it will result in _Wrong Answer_. * * *
s470500737
Runtime Error
p03263
Input is given from Standard Input in the following format: H W a_{11} a_{12} ... a_{1W} a_{21} a_{22} ... a_{2W} : a_{H1} a_{H2} ... a_{HW}
ins = string.split("\n") h, w = map(int, ins[0].split(" ")) matrix = [list(map(int, _i.split(" "))) for _i in ins[1:]] move = [] for _h in range(h): for _w in range(w): if matrix[_h][_w] % 2 == 0: continue matrix[_h][_w] -= 1 if _w < w - 1: matrix[_h][_w + 1] += 1 move.append("{} {} {} {}".format(_h + 1, _w + 1, _h + 1, _w + 2)) elif _h < h - 1: matrix[_h + 1][_w] += 1 move.append("{} {} {} {}".format(_h + 1, _w + 1, _h + 2, _w + 1)) return "{}\n{}".format(len(move), "\n".join(move)) if __name__ == '__main__': line = input() tmp = [line] for _ in range(int(line[0])): tmp.append(input()) print(solve('\n'.join(tmp)))
Statement There is a grid of square cells with H horizontal rows and W vertical columns. The cell at the i-th row and the j-th column will be denoted as Cell (i, j). In Cell (i, j), a_{ij} coins are placed. You can perform the following operation any number of times: Operation: Choose a cell that was not chosen before and contains one or more coins, then move one of those coins to a vertically or horizontally adjacent cell. Maximize the number of cells containing an even number of coins.
[{"input": "2 3\n 1 2 3\n 0 1 1", "output": "3\n 2 2 2 3\n 1 1 1 2\n 1 3 1 2\n \n\nEvery cell contains an even number of coins after the following sequence of\noperations:\n\n * Move the coin in Cell (2, 2) to Cell (2, 3).\n * Move the coin in Cell (1, 1) to Cell (1, 2).\n * Move one of the coins in Cell (1, 3) to Cell (1, 2).\n\n* * *"}, {"input": "3 2\n 1 0\n 2 1\n 1 0", "output": "3\n 1 1 1 2\n 1 2 2 2\n 3 1 3 2\n \n\n* * *"}, {"input": "1 5\n 9 9 9 9 9", "output": "2\n 1 1 1 2\n 1 3 1 4"}]
Print a sequence of operations that maximizes the number of cells containing an even number of coins, in the following format: N y_1 x_1 y_1' x_1' y_2 x_2 y_2' x_2' : y_N x_N y_N' x_N' That is, in the first line, print an integer N between 0 and H \times W (inclusive), representing the number of operations. In the (i+1)-th line (1 \leq i \leq N), print four integers y_i, x_i, y_i' and x_i' (1 \leq y_i, y_i' \leq H and 1 \leq x_i, x_i' \leq W), representing the i-th operation. These four integers represents the operation of moving one of the coins placed in Cell (y_i, x_i) to a vertically or horizontally adjacent cell, (y_i', x_i'). Note that if the specified operation violates the specification in the problem statement or the output format is invalid, it will result in _Wrong Answer_. * * *
s436932423
Runtime Error
p03263
Input is given from Standard Input in the following format: H W a_{11} a_{12} ... a_{1W} a_{21} a_{22} ... a_{2W} : a_{H1} a_{H2} ... a_{HW}
import sys, bisect, math, itertools, string, queue, copy # import numpy as np # import scipy from collections import Counter, defaultdict, deque from itertools import permutations, combinations from heapq import heappop, heappush input = sys.stdin.readline sys.setrecursionlimit(10**8) mod = 10**9 + 7 def inp(): return int(input()) # n=1 def inpm(): return map(int, input().split()) # x=1,y=2 def inpl(): return list(map(int, input().split())) # a=[1,2,3,4,5,...,n] def inpls(): return list(input().split()) # a=['1','2','3',...,'n'] def inplm(n): return list(int(input()) for _ in range(n)) # x=[] 複数行 def inplL(n): return [list(input()) for _ in range(n)] def inplT(n): return [tuple(input()) for _ in range(n)] def inpll(n): return [ list(map(int, input().split())) for _ in range(n) ] # [[1,1,1,1],[2,2,2,2],[3,3,3,3]] def inplls(n): return sorted( [list(map(int, input().split())) for _ in range(n)] ) # [[1,1,1,1],[2,2,2,2],[3,3,3,3]] def graph(): n = inp() g = [[] for _ in range(n)] for i in range(n): a = inp() a -= 1 g[i].append(a) g[a].append(i) return n, g def rotation_find(n, m, g): # 迷路を外側からぐるぐると探索 did = [[False for _ in range(m + 2)] for _ in range(n + 2)] for i in range(n + 2): did[i][0] = True did[i][m + 1] = True for i in range(m + 2): did[0][i] = True did[n + 1][i] = True x = 1 y = 1 key = 1 ans = [] while True: did[x][y] = True key1 = 0 if g[x - 1][y - 1] % 2 != 0: key1 = 1 a, b = x, y if key == 1: x += 1 elif key == 2: y += 1 elif key == 3: x -= 1 elif key == 4: y -= 1 if key == 1 and did[x][y]: x -= 1 y += 1 key = 2 elif key == 2 and did[x][y]: y -= 1 x -= 1 key = 3 elif key == 3 and did[x][y]: x += 1 y -= 1 key = 4 elif key == 4 and did[x][y]: x += 1 y += 1 key = 1 if key1: g[a - 1][b - 1] -= 1 g[x - 1][y - 1] += 1 ans.append((a, b, x, y)) if did[x][y]: break return ans def main(): h, w = inpm() a = inpll(h) ans = rotation_find(h, w, a) print(len(ans)) for i in range(len(ans)): print(*ans[i]) if __name__ == "__main__": main()
Statement There is a grid of square cells with H horizontal rows and W vertical columns. The cell at the i-th row and the j-th column will be denoted as Cell (i, j). In Cell (i, j), a_{ij} coins are placed. You can perform the following operation any number of times: Operation: Choose a cell that was not chosen before and contains one or more coins, then move one of those coins to a vertically or horizontally adjacent cell. Maximize the number of cells containing an even number of coins.
[{"input": "2 3\n 1 2 3\n 0 1 1", "output": "3\n 2 2 2 3\n 1 1 1 2\n 1 3 1 2\n \n\nEvery cell contains an even number of coins after the following sequence of\noperations:\n\n * Move the coin in Cell (2, 2) to Cell (2, 3).\n * Move the coin in Cell (1, 1) to Cell (1, 2).\n * Move one of the coins in Cell (1, 3) to Cell (1, 2).\n\n* * *"}, {"input": "3 2\n 1 0\n 2 1\n 1 0", "output": "3\n 1 1 1 2\n 1 2 2 2\n 3 1 3 2\n \n\n* * *"}, {"input": "1 5\n 9 9 9 9 9", "output": "2\n 1 1 1 2\n 1 3 1 4"}]
Print a sequence of operations that maximizes the number of cells containing an even number of coins, in the following format: N y_1 x_1 y_1' x_1' y_2 x_2 y_2' x_2' : y_N x_N y_N' x_N' That is, in the first line, print an integer N between 0 and H \times W (inclusive), representing the number of operations. In the (i+1)-th line (1 \leq i \leq N), print four integers y_i, x_i, y_i' and x_i' (1 \leq y_i, y_i' \leq H and 1 \leq x_i, x_i' \leq W), representing the i-th operation. These four integers represents the operation of moving one of the coins placed in Cell (y_i, x_i) to a vertically or horizontally adjacent cell, (y_i', x_i'). Note that if the specified operation violates the specification in the problem statement or the output format is invalid, it will result in _Wrong Answer_. * * *
s341554332
Runtime Error
p03263
Input is given from Standard Input in the following format: H W a_{11} a_{12} ... a_{1W} a_{21} a_{22} ... a_{2W} : a_{H1} a_{H2} ... a_{HW}
# -*- coding: utf-8 -*- ############# # Libraries # ############# import sys input = sys.stdin.readline import math # from math import gcd import bisect from collections import defaultdict from collections import deque from functools import lru_cache ############# # Constants # ############# MOD = 10**9 + 7 INF = float("inf") ############# # Functions # ############# ######INPUT###### def I(): return int(input().strip()) def S(): return input().strip() def IL(): return list(map(int, input().split())) def SL(): return list(map(str, input().split())) def ILs(n): return list(int(input()) for _ in range(n)) def SLs(n): return list(input().strip() for _ in range(n)) def ILL(n): return [list(map(int, input().split())) for _ in range(n)] def SLL(n): return [list(map(str, input().split())) for _ in range(n)] ######OUTPUT###### def P(arg): print(arg) return def Y(): print("Yes") return def N(): print("No") return def E(): exit() def PE(arg): print(arg) exit() def YE(): print("Yes") exit() def NE(): print("No") exit() #####Shorten##### def DD(arg): return defaultdict(arg) #####Inverse##### def inv(n): return pow(n, MOD - 2, MOD) ######Combination###### kaijo_memo = [] def kaijo(n): if len(kaijo_memo) > n: return kaijo_memo[n] if len(kaijo_memo) == 0: kaijo_memo.append(1) while len(kaijo_memo) <= n: kaijo_memo.append(kaijo_memo[-1] * len(kaijo_memo) % MOD) return kaijo_memo[n] gyaku_kaijo_memo = [] def gyaku_kaijo(n): if len(gyaku_kaijo_memo) > n: return gyaku_kaijo_memo[n] if len(gyaku_kaijo_memo) == 0: gyaku_kaijo_memo.append(1) while len(gyaku_kaijo_memo) <= n: gyaku_kaijo_memo.append( gyaku_kaijo_memo[-1] * pow(len(gyaku_kaijo_memo), MOD - 2, MOD) % MOD ) return gyaku_kaijo_memo[n] def nCr(n, r): if n == r: return 1 if n < r or r < 0: return 0 ret = 1 ret = ret * kaijo(n) % MOD ret = ret * gyaku_kaijo(r) % MOD ret = ret * gyaku_kaijo(n - r) % MOD return ret ######Factorization###### def factorization(n): arr = [] temp = n for i in range(2, int(-(-(n**0.5) // 1)) + 1): if temp % i == 0: cnt = 0 while temp % i == 0: cnt += 1 temp //= i arr.append([i, cnt]) if temp != 1: arr.append([temp, 1]) if arr == []: arr.append([n, 1]) return arr #####MakeDivisors###### def make_divisors(n): divisors = [] for i in range(1, int(n**0.5) + 1): if n % i == 0: divisors.append(i) if i != n // i: divisors.append(n // i) return divisors #####GCD##### def gcd(a, b): while b: a, b = b, a % b return a #####LCM##### def lcm(a, b): return a * b // gcd(a, b) #####BitCount##### def count_bit(n): count = 0 while n: n &= n - 1 count += 1 return count #####ChangeBase##### def base_10_to_n(X, n): if X // n: return base_10_to_n(X // n, n) + [X % n] return [X % n] def base_n_to_10(X, n): return sum(int(str(X)[-i - 1]) * n**i for i in range(len(str(X)))) #####IntLog##### def int_log(n, a): count = 0 while n >= a: n //= a count += 1 return count ############# # Main Code # ############# H, W = IL() A = ILL(H) x = 0 y = -1 temoti = None if H % 2 == 1: xg = W - 1 else: xg = 0 yg = H - 1 ans = [] while x != xg or y != yg: if x == 0: if y % 2 == 1: y += 1 else: x += 1 elif x == W - 1: if y % 2 == 1: x -= 1 else: y += 1 else: if y % 2 == 1: x -= 1 else: x += 1 if temoti == None: if A[y][x] % 2 == 1: temoti = (y, x) else: if A[y][x] % 2 == 1: ans.append([temoti[0] + 1, temoti[1] + 1, y + 1, x + 1]) temoti = None else: ans.append([temoti[0] + 1, temoti[1] + 1, y + 1, x + 1]) temoti = (y, x) print(len(ans)) for a in ans: print(*a)
Statement There is a grid of square cells with H horizontal rows and W vertical columns. The cell at the i-th row and the j-th column will be denoted as Cell (i, j). In Cell (i, j), a_{ij} coins are placed. You can perform the following operation any number of times: Operation: Choose a cell that was not chosen before and contains one or more coins, then move one of those coins to a vertically or horizontally adjacent cell. Maximize the number of cells containing an even number of coins.
[{"input": "2 3\n 1 2 3\n 0 1 1", "output": "3\n 2 2 2 3\n 1 1 1 2\n 1 3 1 2\n \n\nEvery cell contains an even number of coins after the following sequence of\noperations:\n\n * Move the coin in Cell (2, 2) to Cell (2, 3).\n * Move the coin in Cell (1, 1) to Cell (1, 2).\n * Move one of the coins in Cell (1, 3) to Cell (1, 2).\n\n* * *"}, {"input": "3 2\n 1 0\n 2 1\n 1 0", "output": "3\n 1 1 1 2\n 1 2 2 2\n 3 1 3 2\n \n\n* * *"}, {"input": "1 5\n 9 9 9 9 9", "output": "2\n 1 1 1 2\n 1 3 1 4"}]
Print a sequence of operations that maximizes the number of cells containing an even number of coins, in the following format: N y_1 x_1 y_1' x_1' y_2 x_2 y_2' x_2' : y_N x_N y_N' x_N' That is, in the first line, print an integer N between 0 and H \times W (inclusive), representing the number of operations. In the (i+1)-th line (1 \leq i \leq N), print four integers y_i, x_i, y_i' and x_i' (1 \leq y_i, y_i' \leq H and 1 \leq x_i, x_i' \leq W), representing the i-th operation. These four integers represents the operation of moving one of the coins placed in Cell (y_i, x_i) to a vertically or horizontally adjacent cell, (y_i', x_i'). Note that if the specified operation violates the specification in the problem statement or the output format is invalid, it will result in _Wrong Answer_. * * *
s575839014
Accepted
p03263
Input is given from Standard Input in the following format: H W a_{11} a_{12} ... a_{1W} a_{21} a_{22} ... a_{2W} : a_{H1} a_{H2} ... a_{HW}
#!/usr/bin/env python # coding: utf-8 # import copy def advance(h, w, nx, ny): if 0 == ny % 2: if nx == w - 1: return nx, ny + 1 else: return nx + 1, ny elif 1 == ny % 2: if nx == 0: return nx, ny + 1 else: return nx - 1, ny def main(h, x, mat): nx = 0 ny = 0 retlist = [] while nx < w and ny < h: """終了条件""" next_x, next_y = advance(h, w, nx, ny) if next_x == w or next_y == h: break if 0 == mat[ny][nx] % 2: pass else: mat[ny][nx] -= 1 mat[next_y][next_x] += 1 retlist.append([ny, nx, next_y, next_x]) # print('{} {} {} {}'.format(ny, nx, next_y, next_x)) nx = next_x ny = next_y print(len(retlist)) for i in range(len(retlist)): print( "{} {} {} {}".format( retlist[i][0] + 1, retlist[i][1] + 1, retlist[i][2] + 1, retlist[i][3] + 1, ) ) if __name__ == "__main__": try: h, w = list(map(int, input().strip().split(" "))) mat = [] for i in range(h): mat.append(list(map(int, input().strip().split(" ")))) main(h, w, mat) except EOFError: pass
Statement There is a grid of square cells with H horizontal rows and W vertical columns. The cell at the i-th row and the j-th column will be denoted as Cell (i, j). In Cell (i, j), a_{ij} coins are placed. You can perform the following operation any number of times: Operation: Choose a cell that was not chosen before and contains one or more coins, then move one of those coins to a vertically or horizontally adjacent cell. Maximize the number of cells containing an even number of coins.
[{"input": "2 3\n 1 2 3\n 0 1 1", "output": "3\n 2 2 2 3\n 1 1 1 2\n 1 3 1 2\n \n\nEvery cell contains an even number of coins after the following sequence of\noperations:\n\n * Move the coin in Cell (2, 2) to Cell (2, 3).\n * Move the coin in Cell (1, 1) to Cell (1, 2).\n * Move one of the coins in Cell (1, 3) to Cell (1, 2).\n\n* * *"}, {"input": "3 2\n 1 0\n 2 1\n 1 0", "output": "3\n 1 1 1 2\n 1 2 2 2\n 3 1 3 2\n \n\n* * *"}, {"input": "1 5\n 9 9 9 9 9", "output": "2\n 1 1 1 2\n 1 3 1 4"}]
Print a sequence of operations that maximizes the number of cells containing an even number of coins, in the following format: N y_1 x_1 y_1' x_1' y_2 x_2 y_2' x_2' : y_N x_N y_N' x_N' That is, in the first line, print an integer N between 0 and H \times W (inclusive), representing the number of operations. In the (i+1)-th line (1 \leq i \leq N), print four integers y_i, x_i, y_i' and x_i' (1 \leq y_i, y_i' \leq H and 1 \leq x_i, x_i' \leq W), representing the i-th operation. These four integers represents the operation of moving one of the coins placed in Cell (y_i, x_i) to a vertically or horizontally adjacent cell, (y_i', x_i'). Note that if the specified operation violates the specification in the problem statement or the output format is invalid, it will result in _Wrong Answer_. * * *
s752184772
Accepted
p03263
Input is given from Standard Input in the following format: H W a_{11} a_{12} ... a_{1W} a_{21} a_{22} ... a_{2W} : a_{H1} a_{H2} ... a_{HW}
h, w = map(int, input().split()) a_list = [] for i in range(h): a_list.append(list(map(int, input().split()))) ans_list = [] one_load = [] for a in range(h): if a % 2 == 0: for b in range(w): one_load.append([a, b]) else: for b in range(w - 1, -1, -1): one_load.append([a, b]) keiro = [] for i in range(len(one_load) - 1): if a_list[one_load[i][0]][one_load[i][1]] % 2 == 1: a_list[one_load[i + 1][0]][one_load[i + 1][1]] += 1 keiro.append( [ one_load[i][0] + 1, one_load[i][1] + 1, one_load[i + 1][0] + 1, one_load[i + 1][1] + 1, ] ) print(len(keiro)) for k in keiro: print(*k)
Statement There is a grid of square cells with H horizontal rows and W vertical columns. The cell at the i-th row and the j-th column will be denoted as Cell (i, j). In Cell (i, j), a_{ij} coins are placed. You can perform the following operation any number of times: Operation: Choose a cell that was not chosen before and contains one or more coins, then move one of those coins to a vertically or horizontally adjacent cell. Maximize the number of cells containing an even number of coins.
[{"input": "2 3\n 1 2 3\n 0 1 1", "output": "3\n 2 2 2 3\n 1 1 1 2\n 1 3 1 2\n \n\nEvery cell contains an even number of coins after the following sequence of\noperations:\n\n * Move the coin in Cell (2, 2) to Cell (2, 3).\n * Move the coin in Cell (1, 1) to Cell (1, 2).\n * Move one of the coins in Cell (1, 3) to Cell (1, 2).\n\n* * *"}, {"input": "3 2\n 1 0\n 2 1\n 1 0", "output": "3\n 1 1 1 2\n 1 2 2 2\n 3 1 3 2\n \n\n* * *"}, {"input": "1 5\n 9 9 9 9 9", "output": "2\n 1 1 1 2\n 1 3 1 4"}]
Print a sequence of operations that maximizes the number of cells containing an even number of coins, in the following format: N y_1 x_1 y_1' x_1' y_2 x_2 y_2' x_2' : y_N x_N y_N' x_N' That is, in the first line, print an integer N between 0 and H \times W (inclusive), representing the number of operations. In the (i+1)-th line (1 \leq i \leq N), print four integers y_i, x_i, y_i' and x_i' (1 \leq y_i, y_i' \leq H and 1 \leq x_i, x_i' \leq W), representing the i-th operation. These four integers represents the operation of moving one of the coins placed in Cell (y_i, x_i) to a vertically or horizontally adjacent cell, (y_i', x_i'). Note that if the specified operation violates the specification in the problem statement or the output format is invalid, it will result in _Wrong Answer_. * * *
s442151082
Wrong Answer
p03263
Input is given from Standard Input in the following format: H W a_{11} a_{12} ... a_{1W} a_{21} a_{22} ... a_{2W} : a_{H1} a_{H2} ... a_{HW}
H, W = map(int, input().split()) As = [] odds = [] for i in range(H): # As.append(list(map(int,input().split()))) ls = list(map(int, input().split())) for j, l in enumerate(ls): if l % 2 == 1: odds.append([i, j]) """ 解法 奇数のペアを見つけ出し、ペアが重なるようにルートを敷いてやると良い? """ def make_route(odd1, odd2): h1, w1 = odd1 h2, w2 = odd2 hmax, hmin = max(h1, h2), min(h1, h2) wmax, wmin = max(w1, w2), min(w1, w2) dh = hmax - hmin dw = wmax - wmin move_list = [] h1, w1 = hmin, wmin for _ in range(dh): move_list.append((h1, w1, h1 + 1, w1)) h1 += 1 for _ in range(dw): move_list.append((h1, w1, h1, w1 + 1)) w1 += 1 return move_list n = len(odds) cnt = 0 mvs = [] for i in range(0, n - 1, 2): odd1 = odds[i] odd2 = odds[i + 1] routes = make_route(odd1, odd2) for h1, w1, h2, w2 in routes: mvs.append([h1, w1, h2, w2]) cnt += 1 print(cnt) for h1, w1, h2, w2 in mvs: print(h1 + 1, w1 + 1, h2 + 1, w2 + 1)
Statement There is a grid of square cells with H horizontal rows and W vertical columns. The cell at the i-th row and the j-th column will be denoted as Cell (i, j). In Cell (i, j), a_{ij} coins are placed. You can perform the following operation any number of times: Operation: Choose a cell that was not chosen before and contains one or more coins, then move one of those coins to a vertically or horizontally adjacent cell. Maximize the number of cells containing an even number of coins.
[{"input": "2 3\n 1 2 3\n 0 1 1", "output": "3\n 2 2 2 3\n 1 1 1 2\n 1 3 1 2\n \n\nEvery cell contains an even number of coins after the following sequence of\noperations:\n\n * Move the coin in Cell (2, 2) to Cell (2, 3).\n * Move the coin in Cell (1, 1) to Cell (1, 2).\n * Move one of the coins in Cell (1, 3) to Cell (1, 2).\n\n* * *"}, {"input": "3 2\n 1 0\n 2 1\n 1 0", "output": "3\n 1 1 1 2\n 1 2 2 2\n 3 1 3 2\n \n\n* * *"}, {"input": "1 5\n 9 9 9 9 9", "output": "2\n 1 1 1 2\n 1 3 1 4"}]
Print a sequence of operations that maximizes the number of cells containing an even number of coins, in the following format: N y_1 x_1 y_1' x_1' y_2 x_2 y_2' x_2' : y_N x_N y_N' x_N' That is, in the first line, print an integer N between 0 and H \times W (inclusive), representing the number of operations. In the (i+1)-th line (1 \leq i \leq N), print four integers y_i, x_i, y_i' and x_i' (1 \leq y_i, y_i' \leq H and 1 \leq x_i, x_i' \leq W), representing the i-th operation. These four integers represents the operation of moving one of the coins placed in Cell (y_i, x_i) to a vertically or horizontally adjacent cell, (y_i', x_i'). Note that if the specified operation violates the specification in the problem statement or the output format is invalid, it will result in _Wrong Answer_. * * *
s574466986
Wrong Answer
p03263
Input is given from Standard Input in the following format: H W a_{11} a_{12} ... a_{1W} a_{21} a_{22} ... a_{2W} : a_{H1} a_{H2} ... a_{HW}
DEBUG = 0 H, W = map(int, input().split()) coins = [] odds = [] for y in range(H): line = list(map(int, input().split())) coins.append(line) tmp = [x for x in range(W) if line[x] % 2 == 1] odds.append(tmp) if DEBUG: print(odds) hands = [] prev = None # import pdb; pdb.set_trace() for y, o in enumerate(odds): if y % 2 == 0: if prev is not None: for x in range(prev, 0, -1): hands.append((x, y - 1, x - 1, y - 1)) hands.append((0, y - 1, 0, y)) for x in range(o[0]): hands.append((x, y, x + 1, y)) del o[0] n = len(o) for i in range(n // 2): for x in range(o[2 * i], o[2 * i + 1]): hands.append((x, y, x + 1, y)) if n % 2 == 1: prev = o[-1] else: prev = None else: o = o[::-1] if prev is not None: for x in range(prev, W - 1): hands.append((x, y - 1, x + 1, y - 1)) hands.append((W - 1, y - 1, W - 1, y)) for x in range(W - 1, o[0] + 1, -1): hands.append((x, y, x - 1, y)) del o[0] n = len(o) for i in range(n // 2): for x in range(o[2 * i], o[2 * i + 1], -1): hands.append((x, y, x - 1, y)) if n % 2 == 1: prev = o[-1] else: prev = None print(len(hands)) for h in hands: x, y, x_, y_ = [_ + 1 for _ in map(int, h)] print(y, x, y_, x_)
Statement There is a grid of square cells with H horizontal rows and W vertical columns. The cell at the i-th row and the j-th column will be denoted as Cell (i, j). In Cell (i, j), a_{ij} coins are placed. You can perform the following operation any number of times: Operation: Choose a cell that was not chosen before and contains one or more coins, then move one of those coins to a vertically or horizontally adjacent cell. Maximize the number of cells containing an even number of coins.
[{"input": "2 3\n 1 2 3\n 0 1 1", "output": "3\n 2 2 2 3\n 1 1 1 2\n 1 3 1 2\n \n\nEvery cell contains an even number of coins after the following sequence of\noperations:\n\n * Move the coin in Cell (2, 2) to Cell (2, 3).\n * Move the coin in Cell (1, 1) to Cell (1, 2).\n * Move one of the coins in Cell (1, 3) to Cell (1, 2).\n\n* * *"}, {"input": "3 2\n 1 0\n 2 1\n 1 0", "output": "3\n 1 1 1 2\n 1 2 2 2\n 3 1 3 2\n \n\n* * *"}, {"input": "1 5\n 9 9 9 9 9", "output": "2\n 1 1 1 2\n 1 3 1 4"}]
Print a sequence of operations that maximizes the number of cells containing an even number of coins, in the following format: N y_1 x_1 y_1' x_1' y_2 x_2 y_2' x_2' : y_N x_N y_N' x_N' That is, in the first line, print an integer N between 0 and H \times W (inclusive), representing the number of operations. In the (i+1)-th line (1 \leq i \leq N), print four integers y_i, x_i, y_i' and x_i' (1 \leq y_i, y_i' \leq H and 1 \leq x_i, x_i' \leq W), representing the i-th operation. These four integers represents the operation of moving one of the coins placed in Cell (y_i, x_i) to a vertically or horizontally adjacent cell, (y_i', x_i'). Note that if the specified operation violates the specification in the problem statement or the output format is invalid, it will result in _Wrong Answer_. * * *
s006190830
Accepted
p03263
Input is given from Standard Input in the following format: H W a_{11} a_{12} ... a_{1W} a_{21} a_{22} ... a_{2W} : a_{H1} a_{H2} ... a_{HW}
h, w = map(int, input().split(" ")) def judge(t): if int(t) % 2 == 1: return "d" else: return int(t) field = [["n" for i in range(w + 1)]] for i in range(1, h + 1): field.append(list(map(judge, input().split(" ")))) field[i] = ["n"] + field[i] d_num = 0 for i in range(1, h + 1): for j in range(1, w + 1): if field[i][j] == "d": d_num += 1 ans_a = [] ans_a2 = [] pri = False for i in range(1, h + 1): if i % 2 == 1: dir_j = [i + 1 for i in range(w)] else: dir_j = [w - i for i in range(w)] for j in dir_j: if field[i][j] == "d" and d_num >= 2: if pri: pri = False ans_a.append([i, j]) for k in range(len(ans_a) - 1): ans_a2.append(ans_a[k] + ans_a[k + 1]) ans_a = [] else: pri = True if pri: ans_a.append([i, j]) print(len(ans_a2)) for i in ans_a2: print(" ".join(list(map(str, i))))
Statement There is a grid of square cells with H horizontal rows and W vertical columns. The cell at the i-th row and the j-th column will be denoted as Cell (i, j). In Cell (i, j), a_{ij} coins are placed. You can perform the following operation any number of times: Operation: Choose a cell that was not chosen before and contains one or more coins, then move one of those coins to a vertically or horizontally adjacent cell. Maximize the number of cells containing an even number of coins.
[{"input": "2 3\n 1 2 3\n 0 1 1", "output": "3\n 2 2 2 3\n 1 1 1 2\n 1 3 1 2\n \n\nEvery cell contains an even number of coins after the following sequence of\noperations:\n\n * Move the coin in Cell (2, 2) to Cell (2, 3).\n * Move the coin in Cell (1, 1) to Cell (1, 2).\n * Move one of the coins in Cell (1, 3) to Cell (1, 2).\n\n* * *"}, {"input": "3 2\n 1 0\n 2 1\n 1 0", "output": "3\n 1 1 1 2\n 1 2 2 2\n 3 1 3 2\n \n\n* * *"}, {"input": "1 5\n 9 9 9 9 9", "output": "2\n 1 1 1 2\n 1 3 1 4"}]
Print a sequence of operations that maximizes the number of cells containing an even number of coins, in the following format: N y_1 x_1 y_1' x_1' y_2 x_2 y_2' x_2' : y_N x_N y_N' x_N' That is, in the first line, print an integer N between 0 and H \times W (inclusive), representing the number of operations. In the (i+1)-th line (1 \leq i \leq N), print four integers y_i, x_i, y_i' and x_i' (1 \leq y_i, y_i' \leq H and 1 \leq x_i, x_i' \leq W), representing the i-th operation. These four integers represents the operation of moving one of the coins placed in Cell (y_i, x_i) to a vertically or horizontally adjacent cell, (y_i', x_i'). Note that if the specified operation violates the specification in the problem statement or the output format is invalid, it will result in _Wrong Answer_. * * *
s143363314
Wrong Answer
p03263
Input is given from Standard Input in the following format: H W a_{11} a_{12} ... a_{1W} a_{21} a_{22} ... a_{2W} : a_{H1} a_{H2} ... a_{HW}
h, w = map(int, input().split()) a = [list(map(int, input().split())) for _ in range(h)] ww = 2 * w m = 0 def pos(i): y = i // ww y *= 2 ri = i % ww if ri < w: x = ri else: x = ww - ri - 1 y += 1 return y, x for i in range(h * w - 1): y, x = pos(i) print("pos", i, y, x) if a[y][x] % 2 != m: yy, xx = pos(i + 1) print(y + 1, x + 1, yy + 1, xx + 1) m = 1 else: m = 0
Statement There is a grid of square cells with H horizontal rows and W vertical columns. The cell at the i-th row and the j-th column will be denoted as Cell (i, j). In Cell (i, j), a_{ij} coins are placed. You can perform the following operation any number of times: Operation: Choose a cell that was not chosen before and contains one or more coins, then move one of those coins to a vertically or horizontally adjacent cell. Maximize the number of cells containing an even number of coins.
[{"input": "2 3\n 1 2 3\n 0 1 1", "output": "3\n 2 2 2 3\n 1 1 1 2\n 1 3 1 2\n \n\nEvery cell contains an even number of coins after the following sequence of\noperations:\n\n * Move the coin in Cell (2, 2) to Cell (2, 3).\n * Move the coin in Cell (1, 1) to Cell (1, 2).\n * Move one of the coins in Cell (1, 3) to Cell (1, 2).\n\n* * *"}, {"input": "3 2\n 1 0\n 2 1\n 1 0", "output": "3\n 1 1 1 2\n 1 2 2 2\n 3 1 3 2\n \n\n* * *"}, {"input": "1 5\n 9 9 9 9 9", "output": "2\n 1 1 1 2\n 1 3 1 4"}]
Print a sequence of operations that maximizes the number of cells containing an even number of coins, in the following format: N y_1 x_1 y_1' x_1' y_2 x_2 y_2' x_2' : y_N x_N y_N' x_N' That is, in the first line, print an integer N between 0 and H \times W (inclusive), representing the number of operations. In the (i+1)-th line (1 \leq i \leq N), print four integers y_i, x_i, y_i' and x_i' (1 \leq y_i, y_i' \leq H and 1 \leq x_i, x_i' \leq W), representing the i-th operation. These four integers represents the operation of moving one of the coins placed in Cell (y_i, x_i) to a vertically or horizontally adjacent cell, (y_i', x_i'). Note that if the specified operation violates the specification in the problem statement or the output format is invalid, it will result in _Wrong Answer_. * * *
s827158100
Accepted
p03263
Input is given from Standard Input in the following format: H W a_{11} a_{12} ... a_{1W} a_{21} a_{22} ... a_{2W} : a_{H1} a_{H2} ... a_{HW}
def line_mainte(A, h): output = [] for i in range(len(A) - 1): if A[i] % 2 != 0: A[i] -= 1 A[i + 1] += 1 output.append((h, i + 1, h, i + 2)) return (len(output), output) def row_mainte(A, w): output = [] for i in range(len(A) - 1): if A[i] % 2 != 0: A[i] -= 1 A[i + 1] += 1 output.append((i + 1, w, i + 2, w)) return (len(output), output) H, W = map(int, input().split()) a = [list(map(int, input().split())) for _ in range(H)] count, procedure = 0, [] for i in range(H): tmp = line_mainte(a[i], i + 1) count += tmp[0] procedure += tmp[1] row_W = [a[i][W - 1] for i in range(H)] tmp = row_mainte(row_W, W) count += tmp[0] procedure += tmp[1] print(count) for i in range(len(procedure)): for j in range(4): if j != 3: print(procedure[i][j], end=" ") else: print(procedure[i][j])
Statement There is a grid of square cells with H horizontal rows and W vertical columns. The cell at the i-th row and the j-th column will be denoted as Cell (i, j). In Cell (i, j), a_{ij} coins are placed. You can perform the following operation any number of times: Operation: Choose a cell that was not chosen before and contains one or more coins, then move one of those coins to a vertically or horizontally adjacent cell. Maximize the number of cells containing an even number of coins.
[{"input": "2 3\n 1 2 3\n 0 1 1", "output": "3\n 2 2 2 3\n 1 1 1 2\n 1 3 1 2\n \n\nEvery cell contains an even number of coins after the following sequence of\noperations:\n\n * Move the coin in Cell (2, 2) to Cell (2, 3).\n * Move the coin in Cell (1, 1) to Cell (1, 2).\n * Move one of the coins in Cell (1, 3) to Cell (1, 2).\n\n* * *"}, {"input": "3 2\n 1 0\n 2 1\n 1 0", "output": "3\n 1 1 1 2\n 1 2 2 2\n 3 1 3 2\n \n\n* * *"}, {"input": "1 5\n 9 9 9 9 9", "output": "2\n 1 1 1 2\n 1 3 1 4"}]
Print a sequence of operations that maximizes the number of cells containing an even number of coins, in the following format: N y_1 x_1 y_1' x_1' y_2 x_2 y_2' x_2' : y_N x_N y_N' x_N' That is, in the first line, print an integer N between 0 and H \times W (inclusive), representing the number of operations. In the (i+1)-th line (1 \leq i \leq N), print four integers y_i, x_i, y_i' and x_i' (1 \leq y_i, y_i' \leq H and 1 \leq x_i, x_i' \leq W), representing the i-th operation. These four integers represents the operation of moving one of the coins placed in Cell (y_i, x_i) to a vertically or horizontally adjacent cell, (y_i', x_i'). Note that if the specified operation violates the specification in the problem statement or the output format is invalid, it will result in _Wrong Answer_. * * *
s308724132
Accepted
p03263
Input is given from Standard Input in the following format: H W a_{11} a_{12} ... a_{1W} a_{21} a_{22} ... a_{2W} : a_{H1} a_{H2} ... a_{HW}
def movement(inpair1, inpair2): outlist = [(inpair1)] if inpair1[1] < inpair2[1]: for i in range(inpair1[1] + 1, inpair2[1] + 1): outlist.append((inpair1[0], i)) t = i elif inpair1[1] > inpair2[1]: for i in range(inpair1[1] - 1, inpair2[1] - 1, -1): outlist.append((inpair1[0], i)) t = i else: t = inpair1[1] for j in range(inpair1[0] + 1, inpair2[0] + 1): outlist.append((j, t)) outlist = [ (outlist[i][0], outlist[i][1], outlist[i + 1][0], outlist[i + 1][1]) for i in range(len(outlist) - 1) ] return outlist h, w = [int(v) for v in input().split()] odd_list = [] odd_list_2 = [] odd_list_3 = [] for i in range(h): line = [int(v) % 2 for v in input().split()] if line.count(1) >= 1: temp_list = [] for j in range(w): if line[j] % 2 == 1: temp_list.append((i, j)) odd_list_2.append(temp_list) odd_list.append([[i, 0], [i, w - 1]]) for i in range(len(odd_list)): if i % 2 == 1: odd_list[i] = list(reversed(odd_list[i])) odd_list_2[i] = list(reversed(odd_list_2[i])) odd_list_3 += odd_list_2[i] odd_list_3.append((h, w)) total_move_list = [] for i in range(len(odd_list)): total_move_list += movement(odd_list[i][0], odd_list[i][1]) if i != len(odd_list) - 1: total_move_list += movement(odd_list[i][1], odd_list[i + 1][0]) rec = -1 z = 0 x, y = odd_list_3[0] anslist = [] for i in total_move_list: if i[0] == x and i[1] == y: rec *= -1 z += 1 x, y = odd_list_3[z] if rec == 1: anslist.append(i) print(len(anslist)) for i in anslist: print(i[0] + 1, i[1] + 1, i[2] + 1, i[3] + 1)
Statement There is a grid of square cells with H horizontal rows and W vertical columns. The cell at the i-th row and the j-th column will be denoted as Cell (i, j). In Cell (i, j), a_{ij} coins are placed. You can perform the following operation any number of times: Operation: Choose a cell that was not chosen before and contains one or more coins, then move one of those coins to a vertically or horizontally adjacent cell. Maximize the number of cells containing an even number of coins.
[{"input": "2 3\n 1 2 3\n 0 1 1", "output": "3\n 2 2 2 3\n 1 1 1 2\n 1 3 1 2\n \n\nEvery cell contains an even number of coins after the following sequence of\noperations:\n\n * Move the coin in Cell (2, 2) to Cell (2, 3).\n * Move the coin in Cell (1, 1) to Cell (1, 2).\n * Move one of the coins in Cell (1, 3) to Cell (1, 2).\n\n* * *"}, {"input": "3 2\n 1 0\n 2 1\n 1 0", "output": "3\n 1 1 1 2\n 1 2 2 2\n 3 1 3 2\n \n\n* * *"}, {"input": "1 5\n 9 9 9 9 9", "output": "2\n 1 1 1 2\n 1 3 1 4"}]
Print a sequence of operations that maximizes the number of cells containing an even number of coins, in the following format: N y_1 x_1 y_1' x_1' y_2 x_2 y_2' x_2' : y_N x_N y_N' x_N' That is, in the first line, print an integer N between 0 and H \times W (inclusive), representing the number of operations. In the (i+1)-th line (1 \leq i \leq N), print four integers y_i, x_i, y_i' and x_i' (1 \leq y_i, y_i' \leq H and 1 \leq x_i, x_i' \leq W), representing the i-th operation. These four integers represents the operation of moving one of the coins placed in Cell (y_i, x_i) to a vertically or horizontally adjacent cell, (y_i', x_i'). Note that if the specified operation violates the specification in the problem statement or the output format is invalid, it will result in _Wrong Answer_. * * *
s759601269
Wrong Answer
p03263
Input is given from Standard Input in the following format: H W a_{11} a_{12} ... a_{1W} a_{21} a_{22} ... a_{2W} : a_{H1} a_{H2} ... a_{HW}
h, w = map(int, input().split()) lists = [0 for _ in range(h)] for _ in range(h): s = list(map(int, input().split())) lists[_] = s subanswer = 0 anslist = [0] * w uselist = [] if h >= 2: for _ in range(w): s = [lists[j][_] % 2 for j in range(h)] for i in range(h - 1): if s[i] == 0 and s[i + 1] == 0: s[i] = 0 s[i + 1] = 0 elif s[i] == 0 and s[i + 1] == 1: s[i] = 0 s[i + 1] = 1 elif s[i] == 1 and s[i + 1] == 0: s[i] = 0 s[i + 1] = 1 uselist.append([i + 1, _ + 1, i + 2, _ + 1]) subanswer += 1 elif s[i] == 1 and s[i + 1] == 1: s[i] = 0 s[i + 1] = 0 uselist.append([i + 1, _ + 1, i + 2, _ + 1]) subanswer += 1 anslist[_] = s[h - 1] else: anslist = [lists[0][_] % 2 for _ in range(w)] for i in range(w - 1): if anslist[i] == 0 and anslist[i + 1] == 0: anslist[i] = 0 anslist[i + 1] = 0 elif anslist[i] == 0 and anslist[i + 1] == 1: anslist[i] = 0 anslist[i + 1] = 1 elif anslist[i] == 1 and anslist[i + 1] == 0: anslist[i] = 0 anslist[i + 1] = 1 uselist.append([w, i + 1, w, i + 2]) subanswer += 1 elif anslist[i] == 1 and anslist[i + 1] == 1: anslist[i] = 0 anslist[i + 1] = 0 uselist.append([w, i + 1, w, i + 2]) subanswer += 1 print(subanswer) for some in uselist: print(*some)
Statement There is a grid of square cells with H horizontal rows and W vertical columns. The cell at the i-th row and the j-th column will be denoted as Cell (i, j). In Cell (i, j), a_{ij} coins are placed. You can perform the following operation any number of times: Operation: Choose a cell that was not chosen before and contains one or more coins, then move one of those coins to a vertically or horizontally adjacent cell. Maximize the number of cells containing an even number of coins.
[{"input": "2 3\n 1 2 3\n 0 1 1", "output": "3\n 2 2 2 3\n 1 1 1 2\n 1 3 1 2\n \n\nEvery cell contains an even number of coins after the following sequence of\noperations:\n\n * Move the coin in Cell (2, 2) to Cell (2, 3).\n * Move the coin in Cell (1, 1) to Cell (1, 2).\n * Move one of the coins in Cell (1, 3) to Cell (1, 2).\n\n* * *"}, {"input": "3 2\n 1 0\n 2 1\n 1 0", "output": "3\n 1 1 1 2\n 1 2 2 2\n 3 1 3 2\n \n\n* * *"}, {"input": "1 5\n 9 9 9 9 9", "output": "2\n 1 1 1 2\n 1 3 1 4"}]
Print the number of seconds after which the hand of every clock point directly upward again. * * *
s476359798
Runtime Error
p03633
Input is given from Standard Input in the following format: N T_1 : T_N
import math n = int(input()) a = [] for i in range(n): a.append(int(input())) if n == 1: print(a[0]) else: lcm = (a[0] * a[1]) // math.gcd(a[0], a[1]) for i in range(2, n): lcm = (lcm * a[i]) // math.gcd(lcm, a[i]) print(lcm)
Statement We have N clocks. The hand of the i-th clock (1≤i≤N) rotates through 360° in exactly T_i seconds. Initially, the hand of every clock stands still, pointing directly upward. Now, Dolphin starts all the clocks simultaneously. In how many seconds will the hand of every clock point directly upward again?
[{"input": "2\n 2\n 3", "output": "6\n \n\nWe have two clocks. The time when the hand of each clock points upward is as\nfollows:\n\n * Clock 1: 2, 4, 6, ... seconds after the beginning\n * Clock 2: 3, 6, 9, ... seconds after the beginning\n\nTherefore, it takes 6 seconds until the hands of both clocks point directly\nupward.\n\n* * *"}, {"input": "5\n 2\n 5\n 10\n 1000000000000000000\n 1000000000000000000", "output": "1000000000000000000"}]
Print the number of seconds after which the hand of every clock point directly upward again. * * *
s541724453
Runtime Error
p03633
Input is given from Standard Input in the following format: N T_1 : T_N
def delete_head_zeros(n): n = str(n) l = len(n) if "." in n: l = n.find(".") head_zeros = 0 for i in range(l - 1): if n[i] == "0": head_zeros += 1 else: break return n[head_zeros:] # compare a, b # a, b: int or string def bigint_compare(a, b): a = delete_head_zeros(a) b = delete_head_zeros(b) if len(a) > len(b): return 1 elif len(a) < len(b): return -1 else: if a > b: return 1 elif a < b: return -1 else: return 0 # calculate a + b # a, b: int or string def bigint_plus(a, b): a = str(a) b = str(b) d = max([len(a), len(b)]) a = "0" * (d - len(a)) + a b = "0" * (d - len(b)) + b ans = "" carry = 0 for i in range(d): s = int(a[-i - 1]) + int(b[-i - 1]) + carry carry = s // 10 ans = str(s % 10) + ans else: if carry: ans = str(carry) + ans return ans # calculate a - b # a, b: int or string def bigint_minus(a, b): a = str(a) b = str(b) M = [] m = [] sign = "" if len(a) > len(b) or (len(a) == len(b) and a >= b): [M, m] = [a, b] else: [M, m] = [b, a] sign = "-" m = "0" * (len(M) - len(m)) + m ans = "" borrow = 0 for i in range(len(M)): s = int(M[-i - 1]) - int(m[-i - 1]) - borrow if s < 0: borrow = 1 s += 10 else: borrow = 0 ans = str(s) + ans return sign + delete_head_zeros(ans) # calculate a * b # a, b: int or string def bigint_multiply(a, b): a = str(a) b = str(b) md = [] carry = 0 for j in range(len(b)): mj = "" for i in range(len(a)): m = int(a[-i - 1]) * int(b[-j - 1]) + carry carry = m // 10 mj = str(m % 10) + mj else: if carry: mj = str(carry) + mj md.append(mj) ans = 0 for k in range(len(md)): ans = bigint_plus(md[k] + "0" * k, ans) return ans # calculate a / b to d digits after decimal point # a, b, d: int or string def bigint_divide(a, b, d=0): a = str(a) b = str(b) d = int(d) if d < 0: d = 0 ans = "" r = "" for i in range(len(a) + d): q = 0 if i < len(a): r += a[i] elif i == len(a): ans += "." r += "0" else: r += "0" if bigint_compare(r, b) == -1: ans += str(q) else: while bigint_compare(r, b) >= 0: r = bigint_minus(r, b) q += 1 ans += str(q) return delete_head_zeros(ans) def gcd(a, b): if bigint_compare(a, b) >= 0: M = a m = b else: M = b m = a if m == "0": return M else: q = bigint_divide(M, m) r = bigint_minus(M, bigint_multiply(m, q)) return gcd(m, r) def lcm(a, b): return bigint_divide(bigint_multiply(a, b), gcd(a, b)) def main(): N = int(input()) T = [input() for i in range(N)] ans = 1 for i in range(len(T)): ans = lcm(T[i], ans) print(ans) main()
Statement We have N clocks. The hand of the i-th clock (1≤i≤N) rotates through 360° in exactly T_i seconds. Initially, the hand of every clock stands still, pointing directly upward. Now, Dolphin starts all the clocks simultaneously. In how many seconds will the hand of every clock point directly upward again?
[{"input": "2\n 2\n 3", "output": "6\n \n\nWe have two clocks. The time when the hand of each clock points upward is as\nfollows:\n\n * Clock 1: 2, 4, 6, ... seconds after the beginning\n * Clock 2: 3, 6, 9, ... seconds after the beginning\n\nTherefore, it takes 6 seconds until the hands of both clocks point directly\nupward.\n\n* * *"}, {"input": "5\n 2\n 5\n 10\n 1000000000000000000\n 1000000000000000000", "output": "1000000000000000000"}]
Print the number of seconds after which the hand of every clock point directly upward again. * * *
s811518603
Wrong Answer
p03633
Input is given from Standard Input in the following format: N T_1 : T_N
N, T1 = int(input()), int(input()) for n in range(1, N): T2 = int(input()) t, T = sorted((T1, T2)) while t != 0: T, t = t, T % t T1 *= T2 / T # TはT1とT2の最大公約数 print(int(T1))
Statement We have N clocks. The hand of the i-th clock (1≤i≤N) rotates through 360° in exactly T_i seconds. Initially, the hand of every clock stands still, pointing directly upward. Now, Dolphin starts all the clocks simultaneously. In how many seconds will the hand of every clock point directly upward again?
[{"input": "2\n 2\n 3", "output": "6\n \n\nWe have two clocks. The time when the hand of each clock points upward is as\nfollows:\n\n * Clock 1: 2, 4, 6, ... seconds after the beginning\n * Clock 2: 3, 6, 9, ... seconds after the beginning\n\nTherefore, it takes 6 seconds until the hands of both clocks point directly\nupward.\n\n* * *"}, {"input": "5\n 2\n 5\n 10\n 1000000000000000000\n 1000000000000000000", "output": "1000000000000000000"}]
Print the number of seconds after which the hand of every clock point directly upward again. * * *
s715299153
Wrong Answer
p03633
Input is given from Standard Input in the following format: N T_1 : T_N
import math n = int(input().rstrip()) seconds = [int(input().rstrip()) for _ in range(n)] seconds = set(seconds) def getPrimeList(num): prime_l = {} if num < 1: return prime_l pos_max = math.floor(math.sqrt(num)) for i in range(2, pos_max + 1): if num % i == 0: count = 0 while num % i == 0: count += 1 num = int(num / i) prime_l[i] = count if num > pos_max: prime_l[num] = 1 return prime_l prime_all = {} for num in seconds: prime = getPrimeList(num) for p in prime.keys(): if (prime_all.get(p) and prime_all[p] < prime[p]) or (prime_all.get(p) != True): prime_all[p] = prime[p] lcm = 1 for p in prime_all.keys(): lcm *= pow(p, prime_all[p]) print(lcm)
Statement We have N clocks. The hand of the i-th clock (1≤i≤N) rotates through 360° in exactly T_i seconds. Initially, the hand of every clock stands still, pointing directly upward. Now, Dolphin starts all the clocks simultaneously. In how many seconds will the hand of every clock point directly upward again?
[{"input": "2\n 2\n 3", "output": "6\n \n\nWe have two clocks. The time when the hand of each clock points upward is as\nfollows:\n\n * Clock 1: 2, 4, 6, ... seconds after the beginning\n * Clock 2: 3, 6, 9, ... seconds after the beginning\n\nTherefore, it takes 6 seconds until the hands of both clocks point directly\nupward.\n\n* * *"}, {"input": "5\n 2\n 5\n 10\n 1000000000000000000\n 1000000000000000000", "output": "1000000000000000000"}]
Print the number of seconds after which the hand of every clock point directly upward again. * * *
s904382241
Wrong Answer
p03633
Input is given from Standard Input in the following format: N T_1 : T_N
N = int(input()) T = [int(input()) for i in range(N)] T.sort(reverse=True) ans = T[0] def nibu(ans, t): if ans % t == 0: return ans Min = 1 big = min((10**18 + ans - 1) // ans, t) Max = big check = (1, 2) now = big * check[0] // check[1] while True: if now * ans % t == 0: if Min + 1 == now: return ans * now Max = min(now, Max) check = (check[0] * 2 - 1, check[1] * 2) elif now * ans % t != 0: if Max - 1 == now: return ans * Max Min = max(now, Min) check = (check[0] * 2 + 1, check[1] * 2) now = big * check[0] // check[1] for i in range(1, N): t = T[i] ans = nibu(ans, t) print(ans)
Statement We have N clocks. The hand of the i-th clock (1≤i≤N) rotates through 360° in exactly T_i seconds. Initially, the hand of every clock stands still, pointing directly upward. Now, Dolphin starts all the clocks simultaneously. In how many seconds will the hand of every clock point directly upward again?
[{"input": "2\n 2\n 3", "output": "6\n \n\nWe have two clocks. The time when the hand of each clock points upward is as\nfollows:\n\n * Clock 1: 2, 4, 6, ... seconds after the beginning\n * Clock 2: 3, 6, 9, ... seconds after the beginning\n\nTherefore, it takes 6 seconds until the hands of both clocks point directly\nupward.\n\n* * *"}, {"input": "5\n 2\n 5\n 10\n 1000000000000000000\n 1000000000000000000", "output": "1000000000000000000"}]
Print the number of seconds after which the hand of every clock point directly upward again. * * *
s808921776
Accepted
p03633
Input is given from Standard Input in the following format: N T_1 : T_N
import sys import math sys.setrecursionlimit(10**8) ini = lambda: int(sys.stdin.readline()) inm = lambda: map(int, sys.stdin.readline().split()) inl = lambda: list(inm()) ins = lambda: sys.stdin.readline().rstrip() debug = lambda *a, **kw: print("\033[33m", *a, "\033[0m", **dict(file=sys.stderr, **kw)) n = ini() T = [ini() for _ in range(n)] def solve(): a = T[0] for t in T[1:]: g = math.gcd(a, t) a = g * (a // g) * (t // g) return a print(solve())
Statement We have N clocks. The hand of the i-th clock (1≤i≤N) rotates through 360° in exactly T_i seconds. Initially, the hand of every clock stands still, pointing directly upward. Now, Dolphin starts all the clocks simultaneously. In how many seconds will the hand of every clock point directly upward again?
[{"input": "2\n 2\n 3", "output": "6\n \n\nWe have two clocks. The time when the hand of each clock points upward is as\nfollows:\n\n * Clock 1: 2, 4, 6, ... seconds after the beginning\n * Clock 2: 3, 6, 9, ... seconds after the beginning\n\nTherefore, it takes 6 seconds until the hands of both clocks point directly\nupward.\n\n* * *"}, {"input": "5\n 2\n 5\n 10\n 1000000000000000000\n 1000000000000000000", "output": "1000000000000000000"}]
Print the number of seconds after which the hand of every clock point directly upward again. * * *
s612639117
Wrong Answer
p03633
Input is given from Standard Input in the following format: N T_1 : T_N
5 2 5 10 1000000000000000000 1000000000000000000
Statement We have N clocks. The hand of the i-th clock (1≤i≤N) rotates through 360° in exactly T_i seconds. Initially, the hand of every clock stands still, pointing directly upward. Now, Dolphin starts all the clocks simultaneously. In how many seconds will the hand of every clock point directly upward again?
[{"input": "2\n 2\n 3", "output": "6\n \n\nWe have two clocks. The time when the hand of each clock points upward is as\nfollows:\n\n * Clock 1: 2, 4, 6, ... seconds after the beginning\n * Clock 2: 3, 6, 9, ... seconds after the beginning\n\nTherefore, it takes 6 seconds until the hands of both clocks point directly\nupward.\n\n* * *"}, {"input": "5\n 2\n 5\n 10\n 1000000000000000000\n 1000000000000000000", "output": "1000000000000000000"}]
Print the number of seconds after which the hand of every clock point directly upward again. * * *
s141501840
Runtime Error
p03633
Input is given from Standard Input in the following format: N T_1 : T_N
n = int(input()) t = [int(input()) for _ in range(n)] def gcd(x,y): if x % y == 0: return y return gcd(y, x % y) for i in range(n): for j in range(i+1, n): if t[i] == 1: break t[i] //= gcd(t[i], t[j]) ans = 1 [ans *= x for x in t] print(ans)
Statement We have N clocks. The hand of the i-th clock (1≤i≤N) rotates through 360° in exactly T_i seconds. Initially, the hand of every clock stands still, pointing directly upward. Now, Dolphin starts all the clocks simultaneously. In how many seconds will the hand of every clock point directly upward again?
[{"input": "2\n 2\n 3", "output": "6\n \n\nWe have two clocks. The time when the hand of each clock points upward is as\nfollows:\n\n * Clock 1: 2, 4, 6, ... seconds after the beginning\n * Clock 2: 3, 6, 9, ... seconds after the beginning\n\nTherefore, it takes 6 seconds until the hands of both clocks point directly\nupward.\n\n* * *"}, {"input": "5\n 2\n 5\n 10\n 1000000000000000000\n 1000000000000000000", "output": "1000000000000000000"}]
Print the number of seconds after which the hand of every clock point directly upward again. * * *
s183476579
Runtime Error
p03633
Input is given from Standard Input in the following format: N T_1 : T_N
import math def lcm(x, y): return int(x * y) // int(math.gcd(x, y))) n = int(input()) t = [i for i in range(n)] for i in range(n): t[i] = int(input()) ans = 1 for i in range(0, n): ans = lcm(ans, t[i]) print(int(ans))
Statement We have N clocks. The hand of the i-th clock (1≤i≤N) rotates through 360° in exactly T_i seconds. Initially, the hand of every clock stands still, pointing directly upward. Now, Dolphin starts all the clocks simultaneously. In how many seconds will the hand of every clock point directly upward again?
[{"input": "2\n 2\n 3", "output": "6\n \n\nWe have two clocks. The time when the hand of each clock points upward is as\nfollows:\n\n * Clock 1: 2, 4, 6, ... seconds after the beginning\n * Clock 2: 3, 6, 9, ... seconds after the beginning\n\nTherefore, it takes 6 seconds until the hands of both clocks point directly\nupward.\n\n* * *"}, {"input": "5\n 2\n 5\n 10\n 1000000000000000000\n 1000000000000000000", "output": "1000000000000000000"}]
Print the number of days for which the forecast was correct. * * *
s507276043
Runtime Error
p02921
Input is given from Standard Input in the following format: S T
S = int(input()) s = S - 1 if s % 2 == 0: ans = (1 + s) * (s / 2) else: ans = (1 + s) * int(s / 2) + (int(s / 2) + 1) print(int(ans))
Statement You will be given a string S of length 3 representing the weather forecast for three days in the past. The i-th character (1 \leq i \leq 3) of S represents the forecast for the i-th day. `S`, `C`, and `R` stand for sunny, cloudy, and rainy, respectively. You will also be given a string T of length 3 representing the actual weather on those three days. The i-th character (1 \leq i \leq 3) of S represents the actual weather on the i-th day. `S`, `C`, and `R` stand for sunny, cloudy, and rainy, respectively. Print the number of days for which the forecast was correct.
[{"input": "CSS\n CSR", "output": "2\n \n\n * For the first day, it was forecast to be cloudy, and it was indeed cloudy.\n * For the second day, it was forecast to be sunny, and it was indeed sunny.\n * For the third day, it was forecast to be sunny, but it was rainy.\n\nThus, the forecast was correct for two days in this case.\n\n* * *"}, {"input": "SSR\n SSR", "output": "3\n \n\n* * *"}, {"input": "RRR\n SSS", "output": "0"}]
Print the number of days for which the forecast was correct. * * *
s279388613
Accepted
p02921
Input is given from Standard Input in the following format: S T
print(3 - sum(i != j for i, j in zip(*open(0))))
Statement You will be given a string S of length 3 representing the weather forecast for three days in the past. The i-th character (1 \leq i \leq 3) of S represents the forecast for the i-th day. `S`, `C`, and `R` stand for sunny, cloudy, and rainy, respectively. You will also be given a string T of length 3 representing the actual weather on those three days. The i-th character (1 \leq i \leq 3) of S represents the actual weather on the i-th day. `S`, `C`, and `R` stand for sunny, cloudy, and rainy, respectively. Print the number of days for which the forecast was correct.
[{"input": "CSS\n CSR", "output": "2\n \n\n * For the first day, it was forecast to be cloudy, and it was indeed cloudy.\n * For the second day, it was forecast to be sunny, and it was indeed sunny.\n * For the third day, it was forecast to be sunny, but it was rainy.\n\nThus, the forecast was correct for two days in this case.\n\n* * *"}, {"input": "SSR\n SSR", "output": "3\n \n\n* * *"}, {"input": "RRR\n SSS", "output": "0"}]