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 length of the period in which he can start studying, as an integer.
* * * | s130064851 | Accepted | p02663 | Input is given from Standard Input in the following format:
H_1 M_1 H_2 M_2 K | h1, m1, h2, m2, x = map(int, input().split())
# a=list(map(int,input().split()))
a = h2 - h1
b = 60 - m1 + m2
a -= 1
t = a * 60 + b - x
print(t)
| Statement
In this problem, we use the 24-hour clock.
Takahashi gets up exactly at the time H_1 : M_1 and goes to bed exactly at the
time H_2 : M_2. (See Sample Inputs below for clarity.) He has decided to study
for K consecutive minutes while he is up. What is the length of the period in
which he can start studying? | [{"input": "10 0 15 0 30", "output": "270\n \n\nTakahashi gets up at exactly ten in the morning and goes to bed at exactly\nthree in the afternoon. It takes 30 minutes to do the study, so he can start\nit in the period between ten o'clock and half-past two. The length of this\nperiod is 270 minutes, so we should print 270.\n\n* * *"}, {"input": "10 0 12 0 120", "output": "0\n \n\nTakahashi gets up at exactly ten in the morning and goes to bed at exactly\nnoon. It takes 120 minutes to do the study, so he has to start it at exactly\nten o'clock. Thus, we should print 0."}] |
Print the length of the period in which he can start studying, as an integer.
* * * | s133904456 | Wrong Answer | p02663 | Input is given from Standard Input in the following format:
H_1 M_1 H_2 M_2 K | H1, H2, M1, M2, K = map(int, input().split())
print(((60 * (H2 - H1)) + (M2 - M1) - K))
| Statement
In this problem, we use the 24-hour clock.
Takahashi gets up exactly at the time H_1 : M_1 and goes to bed exactly at the
time H_2 : M_2. (See Sample Inputs below for clarity.) He has decided to study
for K consecutive minutes while he is up. What is the length of the period in
which he can start studying? | [{"input": "10 0 15 0 30", "output": "270\n \n\nTakahashi gets up at exactly ten in the morning and goes to bed at exactly\nthree in the afternoon. It takes 30 minutes to do the study, so he can start\nit in the period between ten o'clock and half-past two. The length of this\nperiod is 270 minutes, so we should print 270.\n\n* * *"}, {"input": "10 0 12 0 120", "output": "0\n \n\nTakahashi gets up at exactly ten in the morning and goes to bed at exactly\nnoon. It takes 120 minutes to do the study, so he has to start it at exactly\nten o'clock. Thus, we should print 0."}] |
Print the length of the period in which he can start studying, as an integer.
* * * | s952869936 | Runtime Error | p02663 | Input is given from Standard Input in the following format:
H_1 M_1 H_2 M_2 K | a, b, c, d = map(int, input().split())
e = (c - a) * 60
print(e - d)
| Statement
In this problem, we use the 24-hour clock.
Takahashi gets up exactly at the time H_1 : M_1 and goes to bed exactly at the
time H_2 : M_2. (See Sample Inputs below for clarity.) He has decided to study
for K consecutive minutes while he is up. What is the length of the period in
which he can start studying? | [{"input": "10 0 15 0 30", "output": "270\n \n\nTakahashi gets up at exactly ten in the morning and goes to bed at exactly\nthree in the afternoon. It takes 30 minutes to do the study, so he can start\nit in the period between ten o'clock and half-past two. The length of this\nperiod is 270 minutes, so we should print 270.\n\n* * *"}, {"input": "10 0 12 0 120", "output": "0\n \n\nTakahashi gets up at exactly ten in the morning and goes to bed at exactly\nnoon. It takes 120 minutes to do the study, so he has to start it at exactly\nten o'clock. Thus, we should print 0."}] |
Print the length of the period in which he can start studying, as an integer.
* * * | s729122969 | Accepted | p02663 | Input is given from Standard Input in the following format:
H_1 M_1 H_2 M_2 K | start_hour, start_min, end_hour, end_min, study_min = list(map(int, input().split()))
day_time = (end_hour * 60 + end_min) - (start_hour * 60 + start_min)
able_time = day_time - study_min
print(able_time)
| Statement
In this problem, we use the 24-hour clock.
Takahashi gets up exactly at the time H_1 : M_1 and goes to bed exactly at the
time H_2 : M_2. (See Sample Inputs below for clarity.) He has decided to study
for K consecutive minutes while he is up. What is the length of the period in
which he can start studying? | [{"input": "10 0 15 0 30", "output": "270\n \n\nTakahashi gets up at exactly ten in the morning and goes to bed at exactly\nthree in the afternoon. It takes 30 minutes to do the study, so he can start\nit in the period between ten o'clock and half-past two. The length of this\nperiod is 270 minutes, so we should print 270.\n\n* * *"}, {"input": "10 0 12 0 120", "output": "0\n \n\nTakahashi gets up at exactly ten in the morning and goes to bed at exactly\nnoon. It takes 120 minutes to do the study, so he has to start it at exactly\nten o'clock. Thus, we should print 0."}] |
Print the length of the period in which he can start studying, as an integer.
* * * | s143323509 | Accepted | p02663 | Input is given from Standard Input in the following format:
H_1 M_1 H_2 M_2 K | import sys
input = lambda: sys.stdin.readline().rstrip()
sys.setrecursionlimit(10**7)
INF = 10**20
def I():
return int(input())
def F():
return float(input())
def S():
return input()
def LI():
return [int(x) for x in input().split()]
def LI_():
return [int(x) - 1 for x in input().split()]
def LF():
return [float(x) for x in input().split()]
def LS():
return input().split()
def resolve():
H1, M1, H2, M2, K = LI()
print((60 * H2 + M2) - (60 * H1 + M1) - K)
if __name__ == "__main__":
resolve()
| Statement
In this problem, we use the 24-hour clock.
Takahashi gets up exactly at the time H_1 : M_1 and goes to bed exactly at the
time H_2 : M_2. (See Sample Inputs below for clarity.) He has decided to study
for K consecutive minutes while he is up. What is the length of the period in
which he can start studying? | [{"input": "10 0 15 0 30", "output": "270\n \n\nTakahashi gets up at exactly ten in the morning and goes to bed at exactly\nthree in the afternoon. It takes 30 minutes to do the study, so he can start\nit in the period between ten o'clock and half-past two. The length of this\nperiod is 270 minutes, so we should print 270.\n\n* * *"}, {"input": "10 0 12 0 120", "output": "0\n \n\nTakahashi gets up at exactly ten in the morning and goes to bed at exactly\nnoon. It takes 120 minutes to do the study, so he has to start it at exactly\nten o'clock. Thus, we should print 0."}] |
Print the length of the period in which he can start studying, as an integer.
* * * | s691032890 | Runtime Error | p02663 | Input is given from Standard Input in the following format:
H_1 M_1 H_2 M_2 K | if __name__ == "__main__":
N = int(input().strip())
A = list(map(int, input().strip().split(" ")))
if A[0] != 1 and len(A) == 1:
print(-1)
tree = [0] * (sum([2**i for i in range(N + 1)]))
for i, a in enumerate(A[::-1]):
depth = len(A) - 1 - i
depth_hierarchy_start_index = (
sum([2**i for i in range(depth)]) if depth != 0 else 0
)
depth_hierarchy_end_index = (
sum([2**i for i in range(depth + 1)]) if depth != 0 else 1
)
# keisho
if depth != N:
for i in range(depth_hierarchy_start_index, depth_hierarchy_end_index):
if tree[2 * i + 1] != 0 or tree[2 * i + 2] != 0:
tree[i] = 2
# 1 ume
count = 0
part = 2
while True:
try:
for i in range(
0,
2**depth,
int(2**depth / part) if int(2**depth / part) != 0 else 1,
):
if tree[depth_hierarchy_start_index + i] == 0:
tree[depth_hierarchy_start_index + i] = 1
count += 1
if count == a:
break
part *= 2
if count == a:
break
except:
print(-1)
print(sum([1 if i != 0 else 0 for i in tree]))
| Statement
In this problem, we use the 24-hour clock.
Takahashi gets up exactly at the time H_1 : M_1 and goes to bed exactly at the
time H_2 : M_2. (See Sample Inputs below for clarity.) He has decided to study
for K consecutive minutes while he is up. What is the length of the period in
which he can start studying? | [{"input": "10 0 15 0 30", "output": "270\n \n\nTakahashi gets up at exactly ten in the morning and goes to bed at exactly\nthree in the afternoon. It takes 30 minutes to do the study, so he can start\nit in the period between ten o'clock and half-past two. The length of this\nperiod is 270 minutes, so we should print 270.\n\n* * *"}, {"input": "10 0 12 0 120", "output": "0\n \n\nTakahashi gets up at exactly ten in the morning and goes to bed at exactly\nnoon. It takes 120 minutes to do the study, so he has to start it at exactly\nten o'clock. Thus, we should print 0."}] |
Print the length of the period in which he can start studying, as an integer.
* * * | s205319733 | Accepted | p02663 | Input is given from Standard Input in the following format:
H_1 M_1 H_2 M_2 K | a, b, c, d, e = [int(x) for x in input().split()]
ans1 = a * 60 + b
ans2 = c * 60 + d
print(ans2 - ans1 - e)
| Statement
In this problem, we use the 24-hour clock.
Takahashi gets up exactly at the time H_1 : M_1 and goes to bed exactly at the
time H_2 : M_2. (See Sample Inputs below for clarity.) He has decided to study
for K consecutive minutes while he is up. What is the length of the period in
which he can start studying? | [{"input": "10 0 15 0 30", "output": "270\n \n\nTakahashi gets up at exactly ten in the morning and goes to bed at exactly\nthree in the afternoon. It takes 30 minutes to do the study, so he can start\nit in the period between ten o'clock and half-past two. The length of this\nperiod is 270 minutes, so we should print 270.\n\n* * *"}, {"input": "10 0 12 0 120", "output": "0\n \n\nTakahashi gets up at exactly ten in the morning and goes to bed at exactly\nnoon. It takes 120 minutes to do the study, so he has to start it at exactly\nten o'clock. Thus, we should print 0."}] |
Print the length of the period in which he can start studying, as an integer.
* * * | s476936503 | Runtime Error | p02663 | Input is given from Standard Input in the following format:
H_1 M_1 H_2 M_2 K | N = int(input())
A = list(map(int, input().split()))
V = [0] * (N + 1)
flug = 0
Lsum = sum(A)
V[0] = 1
for i in range(N):
V[i + 1] = V[i] * 2 - A[i + 1]
if V[i + 1] <= 0 and i != N - 1:
flug = 1
if V[i + 1] < 0 and i == N - 1:
flug = 1
Lsum = Lsum - A[i + 1]
if V[i + 1] > Lsum:
V[i + 1] = Lsum
ans = sum(V) + sum(A)
if A[0] != 0:
ans = -1
if flug == 1:
ans = -1
if N == 0:
ans = -1
print(ans)
| Statement
In this problem, we use the 24-hour clock.
Takahashi gets up exactly at the time H_1 : M_1 and goes to bed exactly at the
time H_2 : M_2. (See Sample Inputs below for clarity.) He has decided to study
for K consecutive minutes while he is up. What is the length of the period in
which he can start studying? | [{"input": "10 0 15 0 30", "output": "270\n \n\nTakahashi gets up at exactly ten in the morning and goes to bed at exactly\nthree in the afternoon. It takes 30 minutes to do the study, so he can start\nit in the period between ten o'clock and half-past two. The length of this\nperiod is 270 minutes, so we should print 270.\n\n* * *"}, {"input": "10 0 12 0 120", "output": "0\n \n\nTakahashi gets up at exactly ten in the morning and goes to bed at exactly\nnoon. It takes 120 minutes to do the study, so he has to start it at exactly\nten o'clock. Thus, we should print 0."}] |
Print the length of the period in which he can start studying, as an integer.
* * * | s910712178 | Wrong Answer | p02663 | Input is given from Standard Input in the following format:
H_1 M_1 H_2 M_2 K | H1, H2, H3, H4, K = map(int, input().split())
up = H1 * 60 + H2
down = H3 * 60 - H4
print(down - up - K)
| Statement
In this problem, we use the 24-hour clock.
Takahashi gets up exactly at the time H_1 : M_1 and goes to bed exactly at the
time H_2 : M_2. (See Sample Inputs below for clarity.) He has decided to study
for K consecutive minutes while he is up. What is the length of the period in
which he can start studying? | [{"input": "10 0 15 0 30", "output": "270\n \n\nTakahashi gets up at exactly ten in the morning and goes to bed at exactly\nthree in the afternoon. It takes 30 minutes to do the study, so he can start\nit in the period between ten o'clock and half-past two. The length of this\nperiod is 270 minutes, so we should print 270.\n\n* * *"}, {"input": "10 0 12 0 120", "output": "0\n \n\nTakahashi gets up at exactly ten in the morning and goes to bed at exactly\nnoon. It takes 120 minutes to do the study, so he has to start it at exactly\nten o'clock. Thus, we should print 0."}] |
Print the length of the period in which he can start studying, as an integer.
* * * | s881107538 | Accepted | p02663 | Input is given from Standard Input in the following format:
H_1 M_1 H_2 M_2 K | H1, M1, H2, M2, K = list(map(int, input().split(" ")))
print(abs(K - ((H2 - H1) * 60 + M2 - M1)))
| Statement
In this problem, we use the 24-hour clock.
Takahashi gets up exactly at the time H_1 : M_1 and goes to bed exactly at the
time H_2 : M_2. (See Sample Inputs below for clarity.) He has decided to study
for K consecutive minutes while he is up. What is the length of the period in
which he can start studying? | [{"input": "10 0 15 0 30", "output": "270\n \n\nTakahashi gets up at exactly ten in the morning and goes to bed at exactly\nthree in the afternoon. It takes 30 minutes to do the study, so he can start\nit in the period between ten o'clock and half-past two. The length of this\nperiod is 270 minutes, so we should print 270.\n\n* * *"}, {"input": "10 0 12 0 120", "output": "0\n \n\nTakahashi gets up at exactly ten in the morning and goes to bed at exactly\nnoon. It takes 120 minutes to do the study, so he has to start it at exactly\nten o'clock. Thus, we should print 0."}] |
Print the length of the period in which he can start studying, as an integer.
* * * | s270541083 | Wrong Answer | p02663 | Input is given from Standard Input in the following format:
H_1 M_1 H_2 M_2 K | print(-1)
| Statement
In this problem, we use the 24-hour clock.
Takahashi gets up exactly at the time H_1 : M_1 and goes to bed exactly at the
time H_2 : M_2. (See Sample Inputs below for clarity.) He has decided to study
for K consecutive minutes while he is up. What is the length of the period in
which he can start studying? | [{"input": "10 0 15 0 30", "output": "270\n \n\nTakahashi gets up at exactly ten in the morning and goes to bed at exactly\nthree in the afternoon. It takes 30 minutes to do the study, so he can start\nit in the period between ten o'clock and half-past two. The length of this\nperiod is 270 minutes, so we should print 270.\n\n* * *"}, {"input": "10 0 12 0 120", "output": "0\n \n\nTakahashi gets up at exactly ten in the morning and goes to bed at exactly\nnoon. It takes 120 minutes to do the study, so he has to start it at exactly\nten o'clock. Thus, we should print 0."}] |
Print the length of the period in which he can start studying, as an integer.
* * * | s818434586 | Accepted | p02663 | Input is given from Standard Input in the following format:
H_1 M_1 H_2 M_2 K | n = 0
H1, M1, H2, M2, K = map(int, input().rstrip().split(" "))
n = (H2 - H1) * 60 + (M2 - M1)
print(n - K)
| Statement
In this problem, we use the 24-hour clock.
Takahashi gets up exactly at the time H_1 : M_1 and goes to bed exactly at the
time H_2 : M_2. (See Sample Inputs below for clarity.) He has decided to study
for K consecutive minutes while he is up. What is the length of the period in
which he can start studying? | [{"input": "10 0 15 0 30", "output": "270\n \n\nTakahashi gets up at exactly ten in the morning and goes to bed at exactly\nthree in the afternoon. It takes 30 minutes to do the study, so he can start\nit in the period between ten o'clock and half-past two. The length of this\nperiod is 270 minutes, so we should print 270.\n\n* * *"}, {"input": "10 0 12 0 120", "output": "0\n \n\nTakahashi gets up at exactly ten in the morning and goes to bed at exactly\nnoon. It takes 120 minutes to do the study, so he has to start it at exactly\nten o'clock. Thus, we should print 0."}] |
Print the length of the period in which he can start studying, as an integer.
* * * | s862545855 | Accepted | p02663 | Input is given from Standard Input in the following format:
H_1 M_1 H_2 M_2 K | h1,m1,h2,m2,k=map(int,input().split())
minites=(h2-h1)*60+(m2-m1)-k
print(minites) | Statement
In this problem, we use the 24-hour clock.
Takahashi gets up exactly at the time H_1 : M_1 and goes to bed exactly at the
time H_2 : M_2. (See Sample Inputs below for clarity.) He has decided to study
for K consecutive minutes while he is up. What is the length of the period in
which he can start studying? | [{"input": "10 0 15 0 30", "output": "270\n \n\nTakahashi gets up at exactly ten in the morning and goes to bed at exactly\nthree in the afternoon. It takes 30 minutes to do the study, so he can start\nit in the period between ten o'clock and half-past two. The length of this\nperiod is 270 minutes, so we should print 270.\n\n* * *"}, {"input": "10 0 12 0 120", "output": "0\n \n\nTakahashi gets up at exactly ten in the morning and goes to bed at exactly\nnoon. It takes 120 minutes to do the study, so he has to start it at exactly\nten o'clock. Thus, we should print 0."}] |
Print the length of the period in which he can start studying, as an integer.
* * * | s039349309 | Accepted | p02663 | Input is given from Standard Input in the following format:
H_1 M_1 H_2 M_2 K | H, M, h, m, k = map(int, input().split())
s = H * 60 + M
t = h * 60 + m
print(t - s - k)
| Statement
In this problem, we use the 24-hour clock.
Takahashi gets up exactly at the time H_1 : M_1 and goes to bed exactly at the
time H_2 : M_2. (See Sample Inputs below for clarity.) He has decided to study
for K consecutive minutes while he is up. What is the length of the period in
which he can start studying? | [{"input": "10 0 15 0 30", "output": "270\n \n\nTakahashi gets up at exactly ten in the morning and goes to bed at exactly\nthree in the afternoon. It takes 30 minutes to do the study, so he can start\nit in the period between ten o'clock and half-past two. The length of this\nperiod is 270 minutes, so we should print 270.\n\n* * *"}, {"input": "10 0 12 0 120", "output": "0\n \n\nTakahashi gets up at exactly ten in the morning and goes to bed at exactly\nnoon. It takes 120 minutes to do the study, so he has to start it at exactly\nten o'clock. Thus, we should print 0."}] |
Print the length of the period in which he can start studying, as an integer.
* * * | s062911289 | Wrong Answer | p02663 | Input is given from Standard Input in the following format:
H_1 M_1 H_2 M_2 K | t = input()
result = ""
for i in range(len(t) - 1):
if t[i] == "?":
try:
if result[i - 1] == "P":
result += "D"
else:
result += "P"
except:
if t[i + 1] == "P":
result += "D"
else:
result += "P"
else:
result += t[i]
print(result + "D")
| Statement
In this problem, we use the 24-hour clock.
Takahashi gets up exactly at the time H_1 : M_1 and goes to bed exactly at the
time H_2 : M_2. (See Sample Inputs below for clarity.) He has decided to study
for K consecutive minutes while he is up. What is the length of the period in
which he can start studying? | [{"input": "10 0 15 0 30", "output": "270\n \n\nTakahashi gets up at exactly ten in the morning and goes to bed at exactly\nthree in the afternoon. It takes 30 minutes to do the study, so he can start\nit in the period between ten o'clock and half-past two. The length of this\nperiod is 270 minutes, so we should print 270.\n\n* * *"}, {"input": "10 0 12 0 120", "output": "0\n \n\nTakahashi gets up at exactly ten in the morning and goes to bed at exactly\nnoon. It takes 120 minutes to do the study, so he has to start it at exactly\nten o'clock. Thus, we should print 0."}] |
Print the length of the period in which he can start studying, as an integer.
* * * | s890870658 | Wrong Answer | p02663 | Input is given from Standard Input in the following format:
H_1 M_1 H_2 M_2 K | h, m, a, b, k = map(int, input().split())
m_to_hour = m / 60
b_to_hour = b / 60
h_hour = h + m_to_hour
a_hour = a + b_to_hour
re = a_hour - h_hour
to_min = (re) * 60
print(int(to_min - k))
| Statement
In this problem, we use the 24-hour clock.
Takahashi gets up exactly at the time H_1 : M_1 and goes to bed exactly at the
time H_2 : M_2. (See Sample Inputs below for clarity.) He has decided to study
for K consecutive minutes while he is up. What is the length of the period in
which he can start studying? | [{"input": "10 0 15 0 30", "output": "270\n \n\nTakahashi gets up at exactly ten in the morning and goes to bed at exactly\nthree in the afternoon. It takes 30 minutes to do the study, so he can start\nit in the period between ten o'clock and half-past two. The length of this\nperiod is 270 minutes, so we should print 270.\n\n* * *"}, {"input": "10 0 12 0 120", "output": "0\n \n\nTakahashi gets up at exactly ten in the morning and goes to bed at exactly\nnoon. It takes 120 minutes to do the study, so he has to start it at exactly\nten o'clock. Thus, we should print 0."}] |
Print the length of the period in which he can start studying, as an integer.
* * * | s027075457 | Runtime Error | p02663 | Input is given from Standard Input in the following format:
H_1 M_1 H_2 M_2 K | a, b, c, d, e, f = map(int, input().split())
kis = a * 60 + b
nel = c * 60 + d
print(nel - f - kis)
| Statement
In this problem, we use the 24-hour clock.
Takahashi gets up exactly at the time H_1 : M_1 and goes to bed exactly at the
time H_2 : M_2. (See Sample Inputs below for clarity.) He has decided to study
for K consecutive minutes while he is up. What is the length of the period in
which he can start studying? | [{"input": "10 0 15 0 30", "output": "270\n \n\nTakahashi gets up at exactly ten in the morning and goes to bed at exactly\nthree in the afternoon. It takes 30 minutes to do the study, so he can start\nit in the period between ten o'clock and half-past two. The length of this\nperiod is 270 minutes, so we should print 270.\n\n* * *"}, {"input": "10 0 12 0 120", "output": "0\n \n\nTakahashi gets up at exactly ten in the morning and goes to bed at exactly\nnoon. It takes 120 minutes to do the study, so he has to start it at exactly\nten o'clock. Thus, we should print 0."}] |
Print the length of the period in which he can start studying, as an integer.
* * * | s249431800 | Accepted | p02663 | Input is given from Standard Input in the following format:
H_1 M_1 H_2 M_2 K | a = input().split(" ")
a[0] = int(a[0])
a[1] = int(a[1])
a[2] = int(a[2])
a[3] = int(a[3])
a[4] = int(a[4])
b = (a[0] * 60) + a[1]
c = (a[2] * 60) + a[3]
print((c - b) - a[4])
| Statement
In this problem, we use the 24-hour clock.
Takahashi gets up exactly at the time H_1 : M_1 and goes to bed exactly at the
time H_2 : M_2. (See Sample Inputs below for clarity.) He has decided to study
for K consecutive minutes while he is up. What is the length of the period in
which he can start studying? | [{"input": "10 0 15 0 30", "output": "270\n \n\nTakahashi gets up at exactly ten in the morning and goes to bed at exactly\nthree in the afternoon. It takes 30 minutes to do the study, so he can start\nit in the period between ten o'clock and half-past two. The length of this\nperiod is 270 minutes, so we should print 270.\n\n* * *"}, {"input": "10 0 12 0 120", "output": "0\n \n\nTakahashi gets up at exactly ten in the morning and goes to bed at exactly\nnoon. It takes 120 minutes to do the study, so he has to start it at exactly\nten o'clock. Thus, we should print 0."}] |
Print the length of the period in which he can start studying, as an integer.
* * * | s695378386 | Accepted | p02663 | Input is given from Standard Input in the following format:
H_1 M_1 H_2 M_2 K | gh, gm, sh, sm, k = map(int, input().split())
print(sh * 60 + sm - (gh * 60 + gm) - k)
| Statement
In this problem, we use the 24-hour clock.
Takahashi gets up exactly at the time H_1 : M_1 and goes to bed exactly at the
time H_2 : M_2. (See Sample Inputs below for clarity.) He has decided to study
for K consecutive minutes while he is up. What is the length of the period in
which he can start studying? | [{"input": "10 0 15 0 30", "output": "270\n \n\nTakahashi gets up at exactly ten in the morning and goes to bed at exactly\nthree in the afternoon. It takes 30 minutes to do the study, so he can start\nit in the period between ten o'clock and half-past two. The length of this\nperiod is 270 minutes, so we should print 270.\n\n* * *"}, {"input": "10 0 12 0 120", "output": "0\n \n\nTakahashi gets up at exactly ten in the morning and goes to bed at exactly\nnoon. It takes 120 minutes to do the study, so he has to start it at exactly\nten o'clock. Thus, we should print 0."}] |
Print the length of the period in which he can start studying, as an integer.
* * * | s550009142 | Accepted | p02663 | Input is given from Standard Input in the following format:
H_1 M_1 H_2 M_2 K | H1,M1,H2,M2,K = map(int,input().split())
t = (H2*60 + M2) - (H1*60 + M1) - K
print(t) | Statement
In this problem, we use the 24-hour clock.
Takahashi gets up exactly at the time H_1 : M_1 and goes to bed exactly at the
time H_2 : M_2. (See Sample Inputs below for clarity.) He has decided to study
for K consecutive minutes while he is up. What is the length of the period in
which he can start studying? | [{"input": "10 0 15 0 30", "output": "270\n \n\nTakahashi gets up at exactly ten in the morning and goes to bed at exactly\nthree in the afternoon. It takes 30 minutes to do the study, so he can start\nit in the period between ten o'clock and half-past two. The length of this\nperiod is 270 minutes, so we should print 270.\n\n* * *"}, {"input": "10 0 12 0 120", "output": "0\n \n\nTakahashi gets up at exactly ten in the morning and goes to bed at exactly\nnoon. It takes 120 minutes to do the study, so he has to start it at exactly\nten o'clock. Thus, we should print 0."}] |
Print the length of the period in which he can start studying, as an integer.
* * * | s613838321 | Accepted | p02663 | Input is given from Standard Input in the following format:
H_1 M_1 H_2 M_2 K | def find(H1, M1, H2, M2, K):
left = H1 * 60 + M1
right = H2 * 60 + M2
remain = right - left - K
return max(remain, 0)
H1, M1, H2, M2, K = list(map(int, input().strip().split()))
print(find(H1, M1, H2, M2, K))
| Statement
In this problem, we use the 24-hour clock.
Takahashi gets up exactly at the time H_1 : M_1 and goes to bed exactly at the
time H_2 : M_2. (See Sample Inputs below for clarity.) He has decided to study
for K consecutive minutes while he is up. What is the length of the period in
which he can start studying? | [{"input": "10 0 15 0 30", "output": "270\n \n\nTakahashi gets up at exactly ten in the morning and goes to bed at exactly\nthree in the afternoon. It takes 30 minutes to do the study, so he can start\nit in the period between ten o'clock and half-past two. The length of this\nperiod is 270 minutes, so we should print 270.\n\n* * *"}, {"input": "10 0 12 0 120", "output": "0\n \n\nTakahashi gets up at exactly ten in the morning and goes to bed at exactly\nnoon. It takes 120 minutes to do the study, so he has to start it at exactly\nten o'clock. Thus, we should print 0."}] |
Print the length of the period in which he can start studying, as an integer.
* * * | s346430295 | Accepted | p02663 | Input is given from Standard Input in the following format:
H_1 M_1 H_2 M_2 K | a, b, c, d, e = [int(i) for i in input().split()]
time = (c * 60 + d) - (a * 60 + b) # 活動時間(分)
# print(time)
print(time - e)
| Statement
In this problem, we use the 24-hour clock.
Takahashi gets up exactly at the time H_1 : M_1 and goes to bed exactly at the
time H_2 : M_2. (See Sample Inputs below for clarity.) He has decided to study
for K consecutive minutes while he is up. What is the length of the period in
which he can start studying? | [{"input": "10 0 15 0 30", "output": "270\n \n\nTakahashi gets up at exactly ten in the morning and goes to bed at exactly\nthree in the afternoon. It takes 30 minutes to do the study, so he can start\nit in the period between ten o'clock and half-past two. The length of this\nperiod is 270 minutes, so we should print 270.\n\n* * *"}, {"input": "10 0 12 0 120", "output": "0\n \n\nTakahashi gets up at exactly ten in the morning and goes to bed at exactly\nnoon. It takes 120 minutes to do the study, so he has to start it at exactly\nten o'clock. Thus, we should print 0."}] |
Print the length of the period in which he can start studying, as an integer.
* * * | s682508158 | Wrong Answer | p02663 | Input is given from Standard Input in the following format:
H_1 M_1 H_2 M_2 K | h1, m1, h2, m2, k = map(int, input().split())
h1 += m1 / 60
h2 += m2 / 60
val = h2 - h1
val *= 60
val -= k
print(max(0, int(val)))
| Statement
In this problem, we use the 24-hour clock.
Takahashi gets up exactly at the time H_1 : M_1 and goes to bed exactly at the
time H_2 : M_2. (See Sample Inputs below for clarity.) He has decided to study
for K consecutive minutes while he is up. What is the length of the period in
which he can start studying? | [{"input": "10 0 15 0 30", "output": "270\n \n\nTakahashi gets up at exactly ten in the morning and goes to bed at exactly\nthree in the afternoon. It takes 30 minutes to do the study, so he can start\nit in the period between ten o'clock and half-past two. The length of this\nperiod is 270 minutes, so we should print 270.\n\n* * *"}, {"input": "10 0 12 0 120", "output": "0\n \n\nTakahashi gets up at exactly ten in the morning and goes to bed at exactly\nnoon. It takes 120 minutes to do the study, so he has to start it at exactly\nten o'clock. Thus, we should print 0."}] |
Print the length of the period in which he can start studying, as an integer.
* * * | s947387195 | Runtime Error | p02663 | Input is given from Standard Input in the following format:
H_1 M_1 H_2 M_2 K | N = int(input())
A = list(map(int, input().split()))
last = A[-1]
count = last
root = 1
for i in range(N):
if root <= A[i]:
print(-1)
break
if i + 1 == N and root - A[i] > A[i + 1]:
root = last + A[i]
elif root - A[i] > (last + A[i + 1]):
root = (last + A[i + 1]) + A[i]
count += root
root = (root - A[i]) * 2
else:
if count == 0 or root < last:
count = -1
print(count)
| Statement
In this problem, we use the 24-hour clock.
Takahashi gets up exactly at the time H_1 : M_1 and goes to bed exactly at the
time H_2 : M_2. (See Sample Inputs below for clarity.) He has decided to study
for K consecutive minutes while he is up. What is the length of the period in
which he can start studying? | [{"input": "10 0 15 0 30", "output": "270\n \n\nTakahashi gets up at exactly ten in the morning and goes to bed at exactly\nthree in the afternoon. It takes 30 minutes to do the study, so he can start\nit in the period between ten o'clock and half-past two. The length of this\nperiod is 270 minutes, so we should print 270.\n\n* * *"}, {"input": "10 0 12 0 120", "output": "0\n \n\nTakahashi gets up at exactly ten in the morning and goes to bed at exactly\nnoon. It takes 120 minutes to do the study, so he has to start it at exactly\nten o'clock. Thus, we should print 0."}] |
Print the length of the period in which he can start studying, as an integer.
* * * | s966819190 | Runtime Error | p02663 | Input is given from Standard Input in the following format:
H_1 M_1 H_2 M_2 K | def step(n, lis):
return [l + n for l in lis]
def func(lis):
if len(lis) == 0:
return -1
maxval = max(lis)
lis.pop(lis.index(maxval))
if maxval == 2:
lis.append(1)
if maxval > 2:
lis.append(maxval - 1)
lis.append(maxval - 2)
lis.sort()
lis = lis[:maxA]
return maxval
N = int(input())
A = list(map(int, input().split()))
maxA = max(A)
lis = [0]
count = 0
ans = 0
flag = False
for i in range(N + 1):
count += 1
if flag:
break
if A[i] == 0:
continue
lis = step(count, lis)
count = 0
a = A[i]
# print(i,lis)
for j in range(a):
res = func(lis)
# print(i, res, lis)
if res == -1:
flag = True
break
else:
ans += res
if flag:
print(-1)
else:
print(ans)
| Statement
In this problem, we use the 24-hour clock.
Takahashi gets up exactly at the time H_1 : M_1 and goes to bed exactly at the
time H_2 : M_2. (See Sample Inputs below for clarity.) He has decided to study
for K consecutive minutes while he is up. What is the length of the period in
which he can start studying? | [{"input": "10 0 15 0 30", "output": "270\n \n\nTakahashi gets up at exactly ten in the morning and goes to bed at exactly\nthree in the afternoon. It takes 30 minutes to do the study, so he can start\nit in the period between ten o'clock and half-past two. The length of this\nperiod is 270 minutes, so we should print 270.\n\n* * *"}, {"input": "10 0 12 0 120", "output": "0\n \n\nTakahashi gets up at exactly ten in the morning and goes to bed at exactly\nnoon. It takes 120 minutes to do the study, so he has to start it at exactly\nten o'clock. Thus, we should print 0."}] |
Print the length of the period in which he can start studying, as an integer.
* * * | s066294159 | Runtime Error | p02663 | Input is given from Standard Input in the following format:
H_1 M_1 H_2 M_2 K | h1 = input(">>")
m1 = input(">>")
h2 = input(">>")
m2 = input(">>")
k = input(">>")
print("60*(h2-h1)+(m2-m1)-k")
| Statement
In this problem, we use the 24-hour clock.
Takahashi gets up exactly at the time H_1 : M_1 and goes to bed exactly at the
time H_2 : M_2. (See Sample Inputs below for clarity.) He has decided to study
for K consecutive minutes while he is up. What is the length of the period in
which he can start studying? | [{"input": "10 0 15 0 30", "output": "270\n \n\nTakahashi gets up at exactly ten in the morning and goes to bed at exactly\nthree in the afternoon. It takes 30 minutes to do the study, so he can start\nit in the period between ten o'clock and half-past two. The length of this\nperiod is 270 minutes, so we should print 270.\n\n* * *"}, {"input": "10 0 12 0 120", "output": "0\n \n\nTakahashi gets up at exactly ten in the morning and goes to bed at exactly\nnoon. It takes 120 minutes to do the study, so he has to start it at exactly\nten o'clock. Thus, we should print 0."}] |
Print the length of the period in which he can start studying, as an integer.
* * * | s514889515 | Runtime Error | p02663 | Input is given from Standard Input in the following format:
H_1 M_1 H_2 M_2 K | h1 = input()
m1 = input()
h2 = input()
m2 = input()
k = input()
| Statement
In this problem, we use the 24-hour clock.
Takahashi gets up exactly at the time H_1 : M_1 and goes to bed exactly at the
time H_2 : M_2. (See Sample Inputs below for clarity.) He has decided to study
for K consecutive minutes while he is up. What is the length of the period in
which he can start studying? | [{"input": "10 0 15 0 30", "output": "270\n \n\nTakahashi gets up at exactly ten in the morning and goes to bed at exactly\nthree in the afternoon. It takes 30 minutes to do the study, so he can start\nit in the period between ten o'clock and half-past two. The length of this\nperiod is 270 minutes, so we should print 270.\n\n* * *"}, {"input": "10 0 12 0 120", "output": "0\n \n\nTakahashi gets up at exactly ten in the morning and goes to bed at exactly\nnoon. It takes 120 minutes to do the study, so he has to start it at exactly\nten o'clock. Thus, we should print 0."}] |
Print the length of the period in which he can start studying, as an integer.
* * * | s354799924 | Runtime Error | p02663 | Input is given from Standard Input in the following format:
H_1 M_1 H_2 M_2 K | wake_up_hour = int(input())
| Statement
In this problem, we use the 24-hour clock.
Takahashi gets up exactly at the time H_1 : M_1 and goes to bed exactly at the
time H_2 : M_2. (See Sample Inputs below for clarity.) He has decided to study
for K consecutive minutes while he is up. What is the length of the period in
which he can start studying? | [{"input": "10 0 15 0 30", "output": "270\n \n\nTakahashi gets up at exactly ten in the morning and goes to bed at exactly\nthree in the afternoon. It takes 30 minutes to do the study, so he can start\nit in the period between ten o'clock and half-past two. The length of this\nperiod is 270 minutes, so we should print 270.\n\n* * *"}, {"input": "10 0 12 0 120", "output": "0\n \n\nTakahashi gets up at exactly ten in the morning and goes to bed at exactly\nnoon. It takes 120 minutes to do the study, so he has to start it at exactly\nten o'clock. Thus, we should print 0."}] |
Print the length of the period in which he can start studying, as an integer.
* * * | s818743574 | Wrong Answer | p02663 | Input is given from Standard Input in the following format:
H_1 M_1 H_2 M_2 K | # coding: utf-8
number = 12 - 10
print(number * 60 + (0 - 0))
| Statement
In this problem, we use the 24-hour clock.
Takahashi gets up exactly at the time H_1 : M_1 and goes to bed exactly at the
time H_2 : M_2. (See Sample Inputs below for clarity.) He has decided to study
for K consecutive minutes while he is up. What is the length of the period in
which he can start studying? | [{"input": "10 0 15 0 30", "output": "270\n \n\nTakahashi gets up at exactly ten in the morning and goes to bed at exactly\nthree in the afternoon. It takes 30 minutes to do the study, so he can start\nit in the period between ten o'clock and half-past two. The length of this\nperiod is 270 minutes, so we should print 270.\n\n* * *"}, {"input": "10 0 12 0 120", "output": "0\n \n\nTakahashi gets up at exactly ten in the morning and goes to bed at exactly\nnoon. It takes 120 minutes to do the study, so he has to start it at exactly\nten o'clock. Thus, we should print 0."}] |
Print the length of the period in which he can start studying, as an integer.
* * * | s948497734 | Wrong Answer | p02663 | Input is given from Standard Input in the following format:
H_1 M_1 H_2 M_2 K | h_1 , m_1, h_2, m_2 , k = map(int, input().split())
# study_time = ((h_2*60 + m_2) - (h_1*60 + m_1))
if h_2 < h_1:
h_2 += 24
study_time = ((h_2*60 + m_2) - (h_1*60 + m_1))
print(k*((study_time//k) - 1)) | Statement
In this problem, we use the 24-hour clock.
Takahashi gets up exactly at the time H_1 : M_1 and goes to bed exactly at the
time H_2 : M_2. (See Sample Inputs below for clarity.) He has decided to study
for K consecutive minutes while he is up. What is the length of the period in
which he can start studying? | [{"input": "10 0 15 0 30", "output": "270\n \n\nTakahashi gets up at exactly ten in the morning and goes to bed at exactly\nthree in the afternoon. It takes 30 minutes to do the study, so he can start\nit in the period between ten o'clock and half-past two. The length of this\nperiod is 270 minutes, so we should print 270.\n\n* * *"}, {"input": "10 0 12 0 120", "output": "0\n \n\nTakahashi gets up at exactly ten in the morning and goes to bed at exactly\nnoon. It takes 120 minutes to do the study, so he has to start it at exactly\nten o'clock. Thus, we should print 0."}] |
Print the length of the period in which he can start studying, as an integer.
* * * | s558054711 | Accepted | p02663 | Input is given from Standard Input in the following format:
H_1 M_1 H_2 M_2 K | h, m, h2, m2, k = map(int, input().split())
mp = 0
while True:
m += 1
mp += 1
if m == 60:
h += 1
m = 0
if h == h2 and m == m2:
break
print(mp - k)
| Statement
In this problem, we use the 24-hour clock.
Takahashi gets up exactly at the time H_1 : M_1 and goes to bed exactly at the
time H_2 : M_2. (See Sample Inputs below for clarity.) He has decided to study
for K consecutive minutes while he is up. What is the length of the period in
which he can start studying? | [{"input": "10 0 15 0 30", "output": "270\n \n\nTakahashi gets up at exactly ten in the morning and goes to bed at exactly\nthree in the afternoon. It takes 30 minutes to do the study, so he can start\nit in the period between ten o'clock and half-past two. The length of this\nperiod is 270 minutes, so we should print 270.\n\n* * *"}, {"input": "10 0 12 0 120", "output": "0\n \n\nTakahashi gets up at exactly ten in the morning and goes to bed at exactly\nnoon. It takes 120 minutes to do the study, so he has to start it at exactly\nten o'clock. Thus, we should print 0."}] |
Print the length of the period in which he can start studying, as an integer.
* * * | s660341968 | Accepted | p02663 | Input is given from Standard Input in the following format:
H_1 M_1 H_2 M_2 K | h1, M1, h2, M2, K = map(int, input().split(" "))
wakeup = h1 * 60 + M1
sleep = h2 * 60 + M2
limit = sleep - K
study_t = limit - wakeup
print(study_t)
| Statement
In this problem, we use the 24-hour clock.
Takahashi gets up exactly at the time H_1 : M_1 and goes to bed exactly at the
time H_2 : M_2. (See Sample Inputs below for clarity.) He has decided to study
for K consecutive minutes while he is up. What is the length of the period in
which he can start studying? | [{"input": "10 0 15 0 30", "output": "270\n \n\nTakahashi gets up at exactly ten in the morning and goes to bed at exactly\nthree in the afternoon. It takes 30 minutes to do the study, so he can start\nit in the period between ten o'clock and half-past two. The length of this\nperiod is 270 minutes, so we should print 270.\n\n* * *"}, {"input": "10 0 12 0 120", "output": "0\n \n\nTakahashi gets up at exactly ten in the morning and goes to bed at exactly\nnoon. It takes 120 minutes to do the study, so he has to start it at exactly\nten o'clock. Thus, we should print 0."}] |
Print the length of the period in which he can start studying, as an integer.
* * * | s634749209 | Runtime Error | p02663 | Input is given from Standard Input in the following format:
H_1 M_1 H_2 M_2 K | h1 = input()
m1 = input()
h2 = input()
m2 = input()
k = input()
i1 = h1 * 60 + m1
i2 = h2 * 60 + m2
okiterumin = i2 - i1
ans = okiterumin - k
print(ans)
| Statement
In this problem, we use the 24-hour clock.
Takahashi gets up exactly at the time H_1 : M_1 and goes to bed exactly at the
time H_2 : M_2. (See Sample Inputs below for clarity.) He has decided to study
for K consecutive minutes while he is up. What is the length of the period in
which he can start studying? | [{"input": "10 0 15 0 30", "output": "270\n \n\nTakahashi gets up at exactly ten in the morning and goes to bed at exactly\nthree in the afternoon. It takes 30 minutes to do the study, so he can start\nit in the period between ten o'clock and half-past two. The length of this\nperiod is 270 minutes, so we should print 270.\n\n* * *"}, {"input": "10 0 12 0 120", "output": "0\n \n\nTakahashi gets up at exactly ten in the morning and goes to bed at exactly\nnoon. It takes 120 minutes to do the study, so he has to start it at exactly\nten o'clock. Thus, we should print 0."}] |
Print the length of the period in which he can start studying, as an integer.
* * * | s919482062 | Accepted | p02663 | Input is given from Standard Input in the following format:
H_1 M_1 H_2 M_2 K | hw, mw, hs, ms, k = map(int, input().split())
waking = (hs * 60 + ms) - (hw * 60 + mw) - k
print(max(0, waking))
| Statement
In this problem, we use the 24-hour clock.
Takahashi gets up exactly at the time H_1 : M_1 and goes to bed exactly at the
time H_2 : M_2. (See Sample Inputs below for clarity.) He has decided to study
for K consecutive minutes while he is up. What is the length of the period in
which he can start studying? | [{"input": "10 0 15 0 30", "output": "270\n \n\nTakahashi gets up at exactly ten in the morning and goes to bed at exactly\nthree in the afternoon. It takes 30 minutes to do the study, so he can start\nit in the period between ten o'clock and half-past two. The length of this\nperiod is 270 minutes, so we should print 270.\n\n* * *"}, {"input": "10 0 12 0 120", "output": "0\n \n\nTakahashi gets up at exactly ten in the morning and goes to bed at exactly\nnoon. It takes 120 minutes to do the study, so he has to start it at exactly\nten o'clock. Thus, we should print 0."}] |
Print the length of the period in which he can start studying, as an integer.
* * * | s045201556 | Wrong Answer | p02663 | Input is given from Standard Input in the following format:
H_1 M_1 H_2 M_2 K | k = list(map(int, input().split()))
time = (k[2] - k[0]) * 60 + (k[3] - k[1])
print(((time // k[4]) - 1) * k[4])
| Statement
In this problem, we use the 24-hour clock.
Takahashi gets up exactly at the time H_1 : M_1 and goes to bed exactly at the
time H_2 : M_2. (See Sample Inputs below for clarity.) He has decided to study
for K consecutive minutes while he is up. What is the length of the period in
which he can start studying? | [{"input": "10 0 15 0 30", "output": "270\n \n\nTakahashi gets up at exactly ten in the morning and goes to bed at exactly\nthree in the afternoon. It takes 30 minutes to do the study, so he can start\nit in the period between ten o'clock and half-past two. The length of this\nperiod is 270 minutes, so we should print 270.\n\n* * *"}, {"input": "10 0 12 0 120", "output": "0\n \n\nTakahashi gets up at exactly ten in the morning and goes to bed at exactly\nnoon. It takes 120 minutes to do the study, so he has to start it at exactly\nten o'clock. Thus, we should print 0."}] |
Print the length of the period in which he can start studying, as an integer.
* * * | s184767099 | Wrong Answer | p02663 | Input is given from Standard Input in the following format:
H_1 M_1 H_2 M_2 K | h, m, a, b, k = map(int, input().split())
h1 = 12 - h
a1 = a - 12
sub = (h1 + a1) * 60
print(sub - k)
| Statement
In this problem, we use the 24-hour clock.
Takahashi gets up exactly at the time H_1 : M_1 and goes to bed exactly at the
time H_2 : M_2. (See Sample Inputs below for clarity.) He has decided to study
for K consecutive minutes while he is up. What is the length of the period in
which he can start studying? | [{"input": "10 0 15 0 30", "output": "270\n \n\nTakahashi gets up at exactly ten in the morning and goes to bed at exactly\nthree in the afternoon. It takes 30 minutes to do the study, so he can start\nit in the period between ten o'clock and half-past two. The length of this\nperiod is 270 minutes, so we should print 270.\n\n* * *"}, {"input": "10 0 12 0 120", "output": "0\n \n\nTakahashi gets up at exactly ten in the morning and goes to bed at exactly\nnoon. It takes 120 minutes to do the study, so he has to start it at exactly\nten o'clock. Thus, we should print 0."}] |
Print the length of the period in which he can start studying, as an integer.
* * * | s442741227 | Accepted | p02663 | Input is given from Standard Input in the following format:
H_1 M_1 H_2 M_2 K | H1, M1, H2, M2, K = map(int, input().rstrip().split())
minutes = M2 - M1
hours = 0
if minutes < 0:
minutes += 60
hours -= 1
hours += H2 - H1
minutes += hours * 60
answer = minutes - K
if answer < 0:
answer = 0
print(answer)
| Statement
In this problem, we use the 24-hour clock.
Takahashi gets up exactly at the time H_1 : M_1 and goes to bed exactly at the
time H_2 : M_2. (See Sample Inputs below for clarity.) He has decided to study
for K consecutive minutes while he is up. What is the length of the period in
which he can start studying? | [{"input": "10 0 15 0 30", "output": "270\n \n\nTakahashi gets up at exactly ten in the morning and goes to bed at exactly\nthree in the afternoon. It takes 30 minutes to do the study, so he can start\nit in the period between ten o'clock and half-past two. The length of this\nperiod is 270 minutes, so we should print 270.\n\n* * *"}, {"input": "10 0 12 0 120", "output": "0\n \n\nTakahashi gets up at exactly ten in the morning and goes to bed at exactly\nnoon. It takes 120 minutes to do the study, so he has to start it at exactly\nten o'clock. Thus, we should print 0."}] |
Print the length of the period in which he can start studying, as an integer.
* * * | s261507377 | Wrong Answer | p02663 | Input is given from Standard Input in the following format:
H_1 M_1 H_2 M_2 K | """
H1時M1分起床
H2時M2分就寝
K分勉強
"""
H1, M1, H2, M2, K = [int(i) for i in input().split()]
awake_time = H1 *60 + M1
sleep_time = H2 *60 + M1
start_limit_time = sleep_time - K
can_study_time = start_limit_time - awake_time
print(can_study_time) | Statement
In this problem, we use the 24-hour clock.
Takahashi gets up exactly at the time H_1 : M_1 and goes to bed exactly at the
time H_2 : M_2. (See Sample Inputs below for clarity.) He has decided to study
for K consecutive minutes while he is up. What is the length of the period in
which he can start studying? | [{"input": "10 0 15 0 30", "output": "270\n \n\nTakahashi gets up at exactly ten in the morning and goes to bed at exactly\nthree in the afternoon. It takes 30 minutes to do the study, so he can start\nit in the period between ten o'clock and half-past two. The length of this\nperiod is 270 minutes, so we should print 270.\n\n* * *"}, {"input": "10 0 12 0 120", "output": "0\n \n\nTakahashi gets up at exactly ten in the morning and goes to bed at exactly\nnoon. It takes 120 minutes to do the study, so he has to start it at exactly\nten o'clock. Thus, we should print 0."}] |
Print the minimum prime number greater than or equal to X.
* * * | s135712775 | Runtime Error | p02819 | Input is given from Standard Input in the following format:
X | a = [int(i) for i in input().split()]
for I in range(a[2]):
if a[0] and a[1] == 0:
print(0, 0)
break
elif a[0] + a[1] < a[2]:
print(0, 0)
break
elif a[0] >= 1:
a[0] = a[0] - 1
if I == a[2]:
print(a[0], a[1])
elif a[0] < 1 and a[1] >= 1:
a[1] = a[1] - 1
if I == a[2]:
print(a[0], a[1])
| Statement
Find the minimum prime number greater than or equal to X. | [{"input": "20", "output": "23\n \n\nThe minimum prime number greater than or equal to 20 is 23.\n\n* * *"}, {"input": "2", "output": "2\n \n\nX itself can be a prime number.\n\n* * *"}, {"input": "99992", "output": "100003"}] |
Print the minimum prime number greater than or equal to X.
* * * | s730341229 | Accepted | p02819 | Input is given from Standard Input in the following format:
X | a = [True] * 110000
n = 110000
for i in range(2, int(n**0.5) + 1):
if a[i]:
for i in range(i * i, n, i):
a[i] = False
s = int(input())
ans = None
start = s
while not a[start]:
start += 1
print(start)
| Statement
Find the minimum prime number greater than or equal to X. | [{"input": "20", "output": "23\n \n\nThe minimum prime number greater than or equal to 20 is 23.\n\n* * *"}, {"input": "2", "output": "2\n \n\nX itself can be a prime number.\n\n* * *"}, {"input": "99992", "output": "100003"}] |
Print the minimum prime number greater than or equal to X.
* * * | s827886871 | Runtime Error | p02819 | Input is given from Standard Input in the following format:
X | X = int(input())
t = X // 2 + X
a = set(range(2, t))
l = map(lambda c: range(2 * c, t, c), a)
result = a.difference(*l)
result = list(sorted(result))
matchingVals = filter(lambda x: x > X, result)
res = list(matchingVals)
print(res[0])
| Statement
Find the minimum prime number greater than or equal to X. | [{"input": "20", "output": "23\n \n\nThe minimum prime number greater than or equal to 20 is 23.\n\n* * *"}, {"input": "2", "output": "2\n \n\nX itself can be a prime number.\n\n* * *"}, {"input": "99992", "output": "100003"}] |
Print the minimum prime number greater than or equal to X.
* * * | s617447448 | Accepted | p02819 | Input is given from Standard Input in the following format:
X | import sys
sys.setrecursionlimit(10**6)
int1 = lambda x: int(x) - 1
p2D = lambda x: print(*x, sep="\n")
def II():
return int(sys.stdin.readline())
def MI():
return map(int, sys.stdin.readline().split())
def LI():
return list(map(int, sys.stdin.readline().split()))
def LLI(rows_number):
return [LI() for _ in range(rows_number)]
def main():
prime = [0, 1] * 500000
prime[2] = 1
for x in range(3, 500000):
if prime[x]:
for y in range(x**2, 1000000, x):
prime[y] = 0
x = II()
for y in range(x, 1000000):
if prime[y]:
print(y)
break
main()
| Statement
Find the minimum prime number greater than or equal to X. | [{"input": "20", "output": "23\n \n\nThe minimum prime number greater than or equal to 20 is 23.\n\n* * *"}, {"input": "2", "output": "2\n \n\nX itself can be a prime number.\n\n* * *"}, {"input": "99992", "output": "100003"}] |
Print the minimum prime number greater than or equal to X.
* * * | s118784723 | Wrong Answer | p02819 | Input is given from Standard Input in the following format:
X | dp = [0 for i in range(1000000)]
N = int(input())
for i in range(2, N):
if i**2 > N:
break
if dp[i] != 0:
continue
for j in range(i, N, i):
dp[j] = 1
while dp[N] != 0:
N += 1
print(N)
| Statement
Find the minimum prime number greater than or equal to X. | [{"input": "20", "output": "23\n \n\nThe minimum prime number greater than or equal to 20 is 23.\n\n* * *"}, {"input": "2", "output": "2\n \n\nX itself can be a prime number.\n\n* * *"}, {"input": "99992", "output": "100003"}] |
Print the minimum prime number greater than or equal to X.
* * * | s010466478 | Accepted | p02819 | Input is given from Standard Input in the following format:
X | x = int(input())
Primes = [2]
cand = 2
max_prime = 2
while max_prime < x:
cand = cand + 1
for prime in Primes:
if cand % prime == 0:
break
else:
max_prime = cand
Primes.append(cand)
print(max_prime)
| Statement
Find the minimum prime number greater than or equal to X. | [{"input": "20", "output": "23\n \n\nThe minimum prime number greater than or equal to 20 is 23.\n\n* * *"}, {"input": "2", "output": "2\n \n\nX itself can be a prime number.\n\n* * *"}, {"input": "99992", "output": "100003"}] |
Print the minimum prime number greater than or equal to X.
* * * | s511681570 | Accepted | p02819 | Input is given from Standard Input in the following format:
X | import numpy as np
a = np.array(
[
2,
3,
5,
7,
11,
13,
17,
19,
23,
29,
31,
37,
41,
43,
47,
53,
59,
61,
67,
71,
73,
79,
83,
89,
97,
101,
103,
107,
109,
113,
127,
131,
137,
139,
149,
151,
157,
163,
167,
173,
179,
181,
191,
193,
197,
199,
211,
223,
227,
229,
233,
239,
241,
251,
257,
263,
269,
271,
277,
281,
283,
293,
307,
311,
313,
317,
331,
337,
347,
349,
353,
359,
367,
]
)
candidate = int(input())
while True:
if ((candidate / a[a < candidate]) % 1 == 0).any():
candidate += 1
else:
break
print(candidate)
| Statement
Find the minimum prime number greater than or equal to X. | [{"input": "20", "output": "23\n \n\nThe minimum prime number greater than or equal to 20 is 23.\n\n* * *"}, {"input": "2", "output": "2\n \n\nX itself can be a prime number.\n\n* * *"}, {"input": "99992", "output": "100003"}] |
Print the minimum prime number greater than or equal to X.
* * * | s482593000 | Accepted | p02819 | Input is given from Standard Input in the following format:
X | n = int(input())
a = 0
b = 0
while a == 0:
x = n + b
b += 1
y = 0
for i in range(x - 2):
if x % (2 + i) == 0:
y += 1
if y == 0:
a += 1
print(x)
| Statement
Find the minimum prime number greater than or equal to X. | [{"input": "20", "output": "23\n \n\nThe minimum prime number greater than or equal to 20 is 23.\n\n* * *"}, {"input": "2", "output": "2\n \n\nX itself can be a prime number.\n\n* * *"}, {"input": "99992", "output": "100003"}] |
For each data set, the output should contain one line with resulting set
elements sorted in ascending order separated by blanks. If the result contains
no set elements then the line should contain the text NULL. | s196722294 | Wrong Answer | p00598 | Input consists of several pairs of lines difining sets and one pair of lines
defining an expression. Each pair of lines for set definition includes the
following.
_Line 1_ : Set name (A, B, C, D, E), number of elements in a set.
_Line 2_ : Set elements separated by blanks.
Pair of lines for expression definition:
_Line 1_ : R 0
_Line 2_ : Expression consisting of set names, operators and parenthesis (no
blanks).
Number of sets can vary from 1 to 5. Set names can be specified in any order.
Each set consists of 1-100 elements. Pair of lines for expression definition
signals the end of data set. Input file includes several data sets. The number
of datasets is less than 20. | import sys
def rpn(str):
r = []
stack = []
for i in range(0, len(str)):
c = str[i]
if c in "idsu":
while len(stack) > 0:
if stack[-1] in "idsuc":
a = stack.pop()
r.extend(a)
else:
break
stack.extend(c)
elif c == "c":
stack.extend(c)
elif c == "(":
stack.extend(c)
elif c == ")":
while len(stack) > 0:
a = stack.pop()
if a == "(":
break
r.extend(a)
else:
r.extend(c)
while len(stack) > 0:
a = stack.pop()
r.extend(a)
return r
def intersect(a, b):
r = []
for e in a:
if e in b:
r.extend([e])
return r
def union(a, b):
r = list(set(a + b))
return r
def diff(a, b):
r = []
for e in a:
if e not in b:
r.extend([e])
return r
def universal(sets):
r = []
for v in sets.values():
r.extend(v)
r = list(set(r))
return r
def calc(rpn, sets):
stack = []
U = universal(sets)
for c in rpn:
if c in "iuds":
op2 = stack.pop()
op1 = stack.pop()
if c == "i":
x = intersect(op1, op2)
stack.append(x)
elif c == "u":
x = union(op1, op2)
stack.append(x)
elif c == "d":
x = diff(op1, op2)
stack.append(x)
elif c == "s":
x = diff(op1, op2)
y = diff(op2, op1)
z = union(x, y)
stack.append(z)
elif c == "c":
op1 = stack.pop()
x = diff(U, op1)
stack.append(x)
else:
stack.append(sets[c])
return stack.pop()
lno = 0
sets = {}
name = ""
for line in sys.stdin:
lno += 1
if lno % 2 == 1:
name = line.strip().split()[0]
elif name != "R":
elem = list(map(int, line.strip().split()))
sets[name] = elem
else:
e = rpn(line.strip())
result = calc(e, sets)
result.sort()
for n in result:
print(n, end=" ")
print()
| D: Operations with Finite Sets
Let _A, B, C, D, E_ be sets of integers and let _U_ is a universal set that
includes all sets under consideration. All elements in any set are different
(no repetitions).
u - **union** of two sets, _AuB_ = {_x ∈ U_ : _x ∈ A_ or _x ∈ B_} is the set
of all elements which belong to _A_ or _B_.
i - **intersection** of two sets, _AiB_ = {_x ∈ U_ : _x ∈ A_ and _x ∈ B_} is
the set of all elements which belong to both _A_ and _B_.
d - **difference** of two sets, _AdB_ = {_x ∈ U_ : _x ∈ A_, _x ∉ B_} is the
set of those elements of _A_ which do not belong to _B_.
s - **symmetric difference** of two sets, _AsB_ = (_AdB_)_u_(_BdA_) consists
of those elements which belong to _A_ or _B_ but not to both.
c - **complement** of a set, _cA_ = {_x ∈ U_ : _x ∉ A_}, is set of elements
which belong to _U_ but do not belong to _A_. Unary operator _c_ has higest
precedence.
The universal set _U_ is defined as a union of all sets specified in data.
Your task is to determine the result of an expression, which includes sets,
set operations and parenthesis (any number of parenthesis and any correct
enclosure of parenthesis may take place). | [{"input": "A 3\n 1 3 -1\n B 4\n 3 1 5 7\n D 1\n 5\n R 0\n cAiBdD\n C 3\n 1 2 3\n A 4\n 2 10 8 3\n B 3\n 2 4 8\n R 0\n (As(AiB))uC", "output": "1 2 3 10"}] |
Print the minimum number of times Operation 1 that Snuke has to perform.
* * * | s056504062 | Wrong Answer | p04021 | The input is given from Standard Input in the following format:
N
A_1
:
A_N | N, *A = map(int, open(0))
print(len(set(A[1::2] + sorted(A)[::2])))
| Statement
Snuke got an integer sequence of length N from his mother, as a birthday
present. The i-th (1 ≦ i ≦ N) element of the sequence is a_i. The elements are
pairwise distinct. He is sorting this sequence in increasing order. With
supernatural power, he can perform the following two operations on the
sequence in any order:
* Operation 1: choose 2 consecutive elements, then reverse the order of those elements.
* Operation 2: choose 3 consecutive elements, then reverse the order of those elements.
Snuke likes Operation 2, but not Operation 1. Find the minimum number of
Operation 1 that he has to perform in order to sort the sequence in increasing
order. | [{"input": "4\n 2\n 4\n 3\n 1", "output": "1\n \n\nThe given sequence can be sorted as follows:\n\n * First, reverse the order of the last three elements. The sequence is now: 2,1,3,4.\n * Then, reverse the order of the first two elements. The sequence is now: 1,2,3,4.\n\nIn this sequence of operations, Operation 1 is performed once. It is not\npossible to sort the sequence with less number of Operation 1, thus the answer\nis 1.\n\n* * *"}, {"input": "5\n 10\n 8\n 5\n 3\n 2", "output": "0"}] |
Print the minimum number of times Operation 1 that Snuke has to perform.
* * * | s143844452 | Runtime Error | p04021 | The input is given from Standard Input in the following format:
N
A_1
:
A_N | n=int(input())
a=[int(input() for i in range(n)]
b=a[::2]
c=a[1::2]
b.sort()
c.sort()
a=[c[i] if i&1 else b[i] for i in range(n)]
cnt=0
for i in range(n-1):
if a[i]>a[i+1]:
cnt+=1
a[i],a[i+1]=a[i+1],a[i]
print(cnt) | Statement
Snuke got an integer sequence of length N from his mother, as a birthday
present. The i-th (1 ≦ i ≦ N) element of the sequence is a_i. The elements are
pairwise distinct. He is sorting this sequence in increasing order. With
supernatural power, he can perform the following two operations on the
sequence in any order:
* Operation 1: choose 2 consecutive elements, then reverse the order of those elements.
* Operation 2: choose 3 consecutive elements, then reverse the order of those elements.
Snuke likes Operation 2, but not Operation 1. Find the minimum number of
Operation 1 that he has to perform in order to sort the sequence in increasing
order. | [{"input": "4\n 2\n 4\n 3\n 1", "output": "1\n \n\nThe given sequence can be sorted as follows:\n\n * First, reverse the order of the last three elements. The sequence is now: 2,1,3,4.\n * Then, reverse the order of the first two elements. The sequence is now: 1,2,3,4.\n\nIn this sequence of operations, Operation 1 is performed once. It is not\npossible to sort the sequence with less number of Operation 1, thus the answer\nis 1.\n\n* * *"}, {"input": "5\n 10\n 8\n 5\n 3\n 2", "output": "0"}] |
Print the minimum number of times Operation 1 that Snuke has to perform.
* * * | s157512540 | Runtime Error | p04021 | The input is given from Standard Input in the following format:
N
A_1
:
A_N | from collections import Counter
n=int(input())
a=[int(input()) for i in range(n)]
b=Counter(a[::2])
a.sort()
c=Counter(a[::2])
ans=0
for i in b:
if i in c:
ans+=abs(b[i])-c[i])
else:
ans+=b[i]
print(ans) | Statement
Snuke got an integer sequence of length N from his mother, as a birthday
present. The i-th (1 ≦ i ≦ N) element of the sequence is a_i. The elements are
pairwise distinct. He is sorting this sequence in increasing order. With
supernatural power, he can perform the following two operations on the
sequence in any order:
* Operation 1: choose 2 consecutive elements, then reverse the order of those elements.
* Operation 2: choose 3 consecutive elements, then reverse the order of those elements.
Snuke likes Operation 2, but not Operation 1. Find the minimum number of
Operation 1 that he has to perform in order to sort the sequence in increasing
order. | [{"input": "4\n 2\n 4\n 3\n 1", "output": "1\n \n\nThe given sequence can be sorted as follows:\n\n * First, reverse the order of the last three elements. The sequence is now: 2,1,3,4.\n * Then, reverse the order of the first two elements. The sequence is now: 1,2,3,4.\n\nIn this sequence of operations, Operation 1 is performed once. It is not\npossible to sort the sequence with less number of Operation 1, thus the answer\nis 1.\n\n* * *"}, {"input": "5\n 10\n 8\n 5\n 3\n 2", "output": "0"}] |
Print the minimum number of times Operation 1 that Snuke has to perform.
* * * | s663071750 | Wrong Answer | p04021 | The input is given from Standard Input in the following format:
N
A_1
:
A_N | print(1)
| Statement
Snuke got an integer sequence of length N from his mother, as a birthday
present. The i-th (1 ≦ i ≦ N) element of the sequence is a_i. The elements are
pairwise distinct. He is sorting this sequence in increasing order. With
supernatural power, he can perform the following two operations on the
sequence in any order:
* Operation 1: choose 2 consecutive elements, then reverse the order of those elements.
* Operation 2: choose 3 consecutive elements, then reverse the order of those elements.
Snuke likes Operation 2, but not Operation 1. Find the minimum number of
Operation 1 that he has to perform in order to sort the sequence in increasing
order. | [{"input": "4\n 2\n 4\n 3\n 1", "output": "1\n \n\nThe given sequence can be sorted as follows:\n\n * First, reverse the order of the last three elements. The sequence is now: 2,1,3,4.\n * Then, reverse the order of the first two elements. The sequence is now: 1,2,3,4.\n\nIn this sequence of operations, Operation 1 is performed once. It is not\npossible to sort the sequence with less number of Operation 1, thus the answer\nis 1.\n\n* * *"}, {"input": "5\n 10\n 8\n 5\n 3\n 2", "output": "0"}] |
Print the minimum number of times Operation 1 that Snuke has to perform.
* * * | s631227713 | Wrong Answer | p04021 | The input is given from Standard Input in the following format:
N
A_1
:
A_N | print(len([i for i in [i for i in range(int(input()))][::2] if i % 2 != 1]))
| Statement
Snuke got an integer sequence of length N from his mother, as a birthday
present. The i-th (1 ≦ i ≦ N) element of the sequence is a_i. The elements are
pairwise distinct. He is sorting this sequence in increasing order. With
supernatural power, he can perform the following two operations on the
sequence in any order:
* Operation 1: choose 2 consecutive elements, then reverse the order of those elements.
* Operation 2: choose 3 consecutive elements, then reverse the order of those elements.
Snuke likes Operation 2, but not Operation 1. Find the minimum number of
Operation 1 that he has to perform in order to sort the sequence in increasing
order. | [{"input": "4\n 2\n 4\n 3\n 1", "output": "1\n \n\nThe given sequence can be sorted as follows:\n\n * First, reverse the order of the last three elements. The sequence is now: 2,1,3,4.\n * Then, reverse the order of the first two elements. The sequence is now: 1,2,3,4.\n\nIn this sequence of operations, Operation 1 is performed once. It is not\npossible to sort the sequence with less number of Operation 1, thus the answer\nis 1.\n\n* * *"}, {"input": "5\n 10\n 8\n 5\n 3\n 2", "output": "0"}] |
Print the minimum number of times Operation 1 that Snuke has to perform.
* * * | s198392129 | Wrong Answer | p04021 | The input is given from Standard Input in the following format:
N
A_1
:
A_N | print(sum([1 for j in [int(input()) for i in range(int(input()))][::2] if j % 2 != 1]))
| Statement
Snuke got an integer sequence of length N from his mother, as a birthday
present. The i-th (1 ≦ i ≦ N) element of the sequence is a_i. The elements are
pairwise distinct. He is sorting this sequence in increasing order. With
supernatural power, he can perform the following two operations on the
sequence in any order:
* Operation 1: choose 2 consecutive elements, then reverse the order of those elements.
* Operation 2: choose 3 consecutive elements, then reverse the order of those elements.
Snuke likes Operation 2, but not Operation 1. Find the minimum number of
Operation 1 that he has to perform in order to sort the sequence in increasing
order. | [{"input": "4\n 2\n 4\n 3\n 1", "output": "1\n \n\nThe given sequence can be sorted as follows:\n\n * First, reverse the order of the last three elements. The sequence is now: 2,1,3,4.\n * Then, reverse the order of the first two elements. The sequence is now: 1,2,3,4.\n\nIn this sequence of operations, Operation 1 is performed once. It is not\npossible to sort the sequence with less number of Operation 1, thus the answer\nis 1.\n\n* * *"}, {"input": "5\n 10\n 8\n 5\n 3\n 2", "output": "0"}] |
Print the minimum number of times Operation 1 that Snuke has to perform.
* * * | s976449973 | Wrong Answer | p04021 | The input is given from Standard Input in the following format:
N
A_1
:
A_N | print(len([i for i in [i for i in range(int(input()))][::2] if i % 2 != 0]))
| Statement
Snuke got an integer sequence of length N from his mother, as a birthday
present. The i-th (1 ≦ i ≦ N) element of the sequence is a_i. The elements are
pairwise distinct. He is sorting this sequence in increasing order. With
supernatural power, he can perform the following two operations on the
sequence in any order:
* Operation 1: choose 2 consecutive elements, then reverse the order of those elements.
* Operation 2: choose 3 consecutive elements, then reverse the order of those elements.
Snuke likes Operation 2, but not Operation 1. Find the minimum number of
Operation 1 that he has to perform in order to sort the sequence in increasing
order. | [{"input": "4\n 2\n 4\n 3\n 1", "output": "1\n \n\nThe given sequence can be sorted as follows:\n\n * First, reverse the order of the last three elements. The sequence is now: 2,1,3,4.\n * Then, reverse the order of the first two elements. The sequence is now: 1,2,3,4.\n\nIn this sequence of operations, Operation 1 is performed once. It is not\npossible to sort the sequence with less number of Operation 1, thus the answer\nis 1.\n\n* * *"}, {"input": "5\n 10\n 8\n 5\n 3\n 2", "output": "0"}] |
Print the minimum number of times Operation 1 that Snuke has to perform.
* * * | s605848774 | Accepted | p04021 | The input is given from Standard Input in the following format:
N
A_1
:
A_N | n = int(input())
a = sorted([[int(input()), i] for i in range(n)])
print(sum([(a[i][1] - i) % 2 for i in range(n)]) // 2)
| Statement
Snuke got an integer sequence of length N from his mother, as a birthday
present. The i-th (1 ≦ i ≦ N) element of the sequence is a_i. The elements are
pairwise distinct. He is sorting this sequence in increasing order. With
supernatural power, he can perform the following two operations on the
sequence in any order:
* Operation 1: choose 2 consecutive elements, then reverse the order of those elements.
* Operation 2: choose 3 consecutive elements, then reverse the order of those elements.
Snuke likes Operation 2, but not Operation 1. Find the minimum number of
Operation 1 that he has to perform in order to sort the sequence in increasing
order. | [{"input": "4\n 2\n 4\n 3\n 1", "output": "1\n \n\nThe given sequence can be sorted as follows:\n\n * First, reverse the order of the last three elements. The sequence is now: 2,1,3,4.\n * Then, reverse the order of the first two elements. The sequence is now: 1,2,3,4.\n\nIn this sequence of operations, Operation 1 is performed once. It is not\npossible to sort the sequence with less number of Operation 1, thus the answer\nis 1.\n\n* * *"}, {"input": "5\n 10\n 8\n 5\n 3\n 2", "output": "0"}] |
Print the minimum number of times Operation 1 that Snuke has to perform.
* * * | s420275578 | Wrong Answer | p04021 | The input is given from Standard Input in the following format:
N
A_1
:
A_N | a = sorted([[int(input()), i] for i in range(int(input()))])
print(sum([(a[i][1] - i) % 2 for i in range(len(a))]))
| Statement
Snuke got an integer sequence of length N from his mother, as a birthday
present. The i-th (1 ≦ i ≦ N) element of the sequence is a_i. The elements are
pairwise distinct. He is sorting this sequence in increasing order. With
supernatural power, he can perform the following two operations on the
sequence in any order:
* Operation 1: choose 2 consecutive elements, then reverse the order of those elements.
* Operation 2: choose 3 consecutive elements, then reverse the order of those elements.
Snuke likes Operation 2, but not Operation 1. Find the minimum number of
Operation 1 that he has to perform in order to sort the sequence in increasing
order. | [{"input": "4\n 2\n 4\n 3\n 1", "output": "1\n \n\nThe given sequence can be sorted as follows:\n\n * First, reverse the order of the last three elements. The sequence is now: 2,1,3,4.\n * Then, reverse the order of the first two elements. The sequence is now: 1,2,3,4.\n\nIn this sequence of operations, Operation 1 is performed once. It is not\npossible to sort the sequence with less number of Operation 1, thus the answer\nis 1.\n\n* * *"}, {"input": "5\n 10\n 8\n 5\n 3\n 2", "output": "0"}] |
Print the minimum number of times Operation 1 that Snuke has to perform.
* * * | s385166418 | Wrong Answer | p04021 | The input is given from Standard Input in the following format:
N
A_1
:
A_N | import sys
input = lambda: sys.stdin.readline().rstrip()
sys.setrecursionlimit(max(1000, 10**9))
write = lambda x: sys.stdout.write(x + "\n")
n = int(input())
a = [None] * n
for i in range(n):
a[i] = int(input())
from bisect import bisect_left
def press(l):
# xs[inds[i]]==l[i]となる
xs = sorted(set(l))
inds = [None] * len(l)
for i, item in enumerate(l):
inds[i] = bisect_left(xs, item)
return xs, inds
xs, inds = press(a)
odd = [num for i, num in enumerate(inds) if i % 2]
even = [num for i, num in enumerate(inds) if i % 2 == 0]
odd.sort()
even.sort()
aa = [None] * n
for i in range(n // 2 + n % 2):
aa[2 * i] = even[i]
for i in range(n // 2):
aa[2 * i + 1] = odd[i]
def init(bit, values):
for i, v in enumerate(values):
update(bit, i, v)
# a1 ~ aiまでの和 O(logn)
def query(bit, i):
res = 0
while i > 0:
res += bit[i]
i -= i & (-i)
return res
# ai += x(logN)
def update(bit, i, x):
while i <= len(bit) - 1:
bit[i] += x
i += i & (-i)
return
# 1-indexedなので注意
bit = [0] * (n + 1)
ans = 0
for i, ind in enumerate(aa):
ans += i - query(bit, ind + 1)
update(bit, ind + 1, 1)
print(ans)
| Statement
Snuke got an integer sequence of length N from his mother, as a birthday
present. The i-th (1 ≦ i ≦ N) element of the sequence is a_i. The elements are
pairwise distinct. He is sorting this sequence in increasing order. With
supernatural power, he can perform the following two operations on the
sequence in any order:
* Operation 1: choose 2 consecutive elements, then reverse the order of those elements.
* Operation 2: choose 3 consecutive elements, then reverse the order of those elements.
Snuke likes Operation 2, but not Operation 1. Find the minimum number of
Operation 1 that he has to perform in order to sort the sequence in increasing
order. | [{"input": "4\n 2\n 4\n 3\n 1", "output": "1\n \n\nThe given sequence can be sorted as follows:\n\n * First, reverse the order of the last three elements. The sequence is now: 2,1,3,4.\n * Then, reverse the order of the first two elements. The sequence is now: 1,2,3,4.\n\nIn this sequence of operations, Operation 1 is performed once. It is not\npossible to sort the sequence with less number of Operation 1, thus the answer\nis 1.\n\n* * *"}, {"input": "5\n 10\n 8\n 5\n 3\n 2", "output": "0"}] |
Print the minimum number of times Operation 1 that Snuke has to perform.
* * * | s975687508 | Accepted | p04021 | The input is given from Standard Input in the following format:
N
A_1
:
A_N | print(
sum(a[1] % 2 for a in sorted((int(input()), i) for i in range(int(input())))[::2])
)
| Statement
Snuke got an integer sequence of length N from his mother, as a birthday
present. The i-th (1 ≦ i ≦ N) element of the sequence is a_i. The elements are
pairwise distinct. He is sorting this sequence in increasing order. With
supernatural power, he can perform the following two operations on the
sequence in any order:
* Operation 1: choose 2 consecutive elements, then reverse the order of those elements.
* Operation 2: choose 3 consecutive elements, then reverse the order of those elements.
Snuke likes Operation 2, but not Operation 1. Find the minimum number of
Operation 1 that he has to perform in order to sort the sequence in increasing
order. | [{"input": "4\n 2\n 4\n 3\n 1", "output": "1\n \n\nThe given sequence can be sorted as follows:\n\n * First, reverse the order of the last three elements. The sequence is now: 2,1,3,4.\n * Then, reverse the order of the first two elements. The sequence is now: 1,2,3,4.\n\nIn this sequence of operations, Operation 1 is performed once. It is not\npossible to sort the sequence with less number of Operation 1, thus the answer\nis 1.\n\n* * *"}, {"input": "5\n 10\n 8\n 5\n 3\n 2", "output": "0"}] |
Print the minimum number of times Operation 1 that Snuke has to perform.
* * * | s115084494 | Wrong Answer | p04021 | The input is given from Standard Input in the following format:
N
A_1
:
A_N | import itertools
N = int(input())
A = list(enumerate([int(input()) for _ in range(N)]))
B = [
iv[0] + 1
for iv in sorted(
enumerate([i for i, v in sorted(A, key=lambda xs: xs[1])]), key=lambda xs: xs[1]
)
]
C = list(
itertools.chain.from_iterable(
itertools.zip_longest(sorted(B[::2]), sorted(B[1::2]))
)
)
if C[-1] == None:
C = C[:-1]
class SegmentTree:
"""
Parameters
----------
array : list
to construct segment tree from
f : func
binary operation of the monoid
e :
identity element of the monoid
size : int
limit for array size
"""
def __init__(self, array, f, e, size):
self.f = f
self.e = e
self.size = size
self.n = n = len(array)
self.dat = [e] * n + array + [e] * (2 * size - 2 * n)
self.build()
def build(self):
dat, n, f = self.dat, self.n, self.f
for i in range(n - 1, 0, -1):
dat[i] = f(dat[i << 1], dat[i << 1 | 1])
def modify(self, p, v):
"""
set value at position p (0-indexed)
"""
f, n, dat = self.f, self.n, self.dat
p += n
dat[p] = v
while p > 1:
dat[p >> 1] = f(dat[p], dat[p ^ 1])
p >>= 1
def query(self, l, r):
"""
result on interval [l, r) (0-indexed)
"""
f, e, n, dat = self.f, self.e, self.n, self.dat
res = e
l += n
r += n
while l < r:
if l & 1:
res = f(res, dat[l])
l += 1
if r & 1:
r -= 1
res = f(res, dat[r])
l >>= 1
r >>= 1
return res
e = 0
size = N + 1
ST = SegmentTree([0] * N, f=lambda x, y: x + y, e=e, size=size)
ans = N * (N + 1) // 2
for c in C:
ST.modify(c, ST.query(c, c + 1) + 1)
ans -= ST.query(1, c + 1)
print(ans)
| Statement
Snuke got an integer sequence of length N from his mother, as a birthday
present. The i-th (1 ≦ i ≦ N) element of the sequence is a_i. The elements are
pairwise distinct. He is sorting this sequence in increasing order. With
supernatural power, he can perform the following two operations on the
sequence in any order:
* Operation 1: choose 2 consecutive elements, then reverse the order of those elements.
* Operation 2: choose 3 consecutive elements, then reverse the order of those elements.
Snuke likes Operation 2, but not Operation 1. Find the minimum number of
Operation 1 that he has to perform in order to sort the sequence in increasing
order. | [{"input": "4\n 2\n 4\n 3\n 1", "output": "1\n \n\nThe given sequence can be sorted as follows:\n\n * First, reverse the order of the last three elements. The sequence is now: 2,1,3,4.\n * Then, reverse the order of the first two elements. The sequence is now: 1,2,3,4.\n\nIn this sequence of operations, Operation 1 is performed once. It is not\npossible to sort the sequence with less number of Operation 1, thus the answer\nis 1.\n\n* * *"}, {"input": "5\n 10\n 8\n 5\n 3\n 2", "output": "0"}] |
Print the minimum number of times Operation 1 that Snuke has to perform.
* * * | s263122125 | Accepted | p04021 | The input is given from Standard Input in the following format:
N
A_1
:
A_N | N = int(input())
xs = list(map(int, (input() for _ in range(N))))
ss = sorted(xs)
odd1 = set((x for i, x in enumerate(xs) if i % 2 == 1))
even2 = set((s for i, s in enumerate(ss) if i % 2 == 0))
print(len(odd1 & even2))
| Statement
Snuke got an integer sequence of length N from his mother, as a birthday
present. The i-th (1 ≦ i ≦ N) element of the sequence is a_i. The elements are
pairwise distinct. He is sorting this sequence in increasing order. With
supernatural power, he can perform the following two operations on the
sequence in any order:
* Operation 1: choose 2 consecutive elements, then reverse the order of those elements.
* Operation 2: choose 3 consecutive elements, then reverse the order of those elements.
Snuke likes Operation 2, but not Operation 1. Find the minimum number of
Operation 1 that he has to perform in order to sort the sequence in increasing
order. | [{"input": "4\n 2\n 4\n 3\n 1", "output": "1\n \n\nThe given sequence can be sorted as follows:\n\n * First, reverse the order of the last three elements. The sequence is now: 2,1,3,4.\n * Then, reverse the order of the first two elements. The sequence is now: 1,2,3,4.\n\nIn this sequence of operations, Operation 1 is performed once. It is not\npossible to sort the sequence with less number of Operation 1, thus the answer\nis 1.\n\n* * *"}, {"input": "5\n 10\n 8\n 5\n 3\n 2", "output": "0"}] |
Print the minimum number of times Operation 1 that Snuke has to perform.
* * * | s847499261 | Wrong Answer | p04021 | The input is given from Standard Input in the following format:
N
A_1
:
A_N | def solve(A):
A0 = [A[i] for i in range(0, len(A), 2)]
A1 = [A[i] for i in range(1, len(A), 2)]
A0.sort()
A1.sort()
result = 0
i0, i1 = 0, 0
a0 = A0[0]
a1 = A1[0]
for pos in range(len(A)):
if pos % 2 == 0:
if a0 < a1:
i0 += 1
if i0 == len(A0):
break
a0 = A0[i0]
else:
result += 1
a1 = a0
i1 += 1
if i1 == len(A1):
break
a0 = A1[i1]
else:
if a1 < a0:
i1 += 1
if i1 == len(A1):
break
a1 = A1[i1]
else:
result += 1
a0 = a1
i0 += 1
if i0 == len(A0):
break
a1 = A0[i0]
return result
N = int(input())
A = [int(input()) for i in range(N)]
print(solve(A))
| Statement
Snuke got an integer sequence of length N from his mother, as a birthday
present. The i-th (1 ≦ i ≦ N) element of the sequence is a_i. The elements are
pairwise distinct. He is sorting this sequence in increasing order. With
supernatural power, he can perform the following two operations on the
sequence in any order:
* Operation 1: choose 2 consecutive elements, then reverse the order of those elements.
* Operation 2: choose 3 consecutive elements, then reverse the order of those elements.
Snuke likes Operation 2, but not Operation 1. Find the minimum number of
Operation 1 that he has to perform in order to sort the sequence in increasing
order. | [{"input": "4\n 2\n 4\n 3\n 1", "output": "1\n \n\nThe given sequence can be sorted as follows:\n\n * First, reverse the order of the last three elements. The sequence is now: 2,1,3,4.\n * Then, reverse the order of the first two elements. The sequence is now: 1,2,3,4.\n\nIn this sequence of operations, Operation 1 is performed once. It is not\npossible to sort the sequence with less number of Operation 1, thus the answer\nis 1.\n\n* * *"}, {"input": "5\n 10\n 8\n 5\n 3\n 2", "output": "0"}] |
Print the minimum possible total cost incurred.
* * * | s227075126 | Runtime Error | p03160 | Input is given from Standard Input in the following format:
N
h_1 h_2 \ldots h_N | # _*_ coding:utf-8 _*_
# Atcoder_EducationDP_ContestX-1_other2
# TODO https://atcoder.jp/contests/dp/tasks/dp_a
# 参考文献 https://qiita.com/drken/items/dc53c683d6de8aeacf5a#%E8%A7%A3%E6%B3%95
# C++ バージョンを上から書き下す
# TODO メモ化再帰
# https://qiita.com/drken/items/dc53c683d6de8aeacf5a#%E5%88%A5%E8%A7%A3-2-%E3%83%A1%E3%83%A2%E5%8C%96%E5%86%8D%E5%B8%B0
import sys
# 初期化
# 足場の数となる要素数は足場の値の最大値であるMAX
blockMAXElement = 100010
blockElementRange = range(0, blockMAXElement, +1)
# DPテーブルの中身は今回は最小値を求めるため最大値を利用
dp = [sys.maxsize] * blockMAXElement
# コスト
# 参考文献のC++では配列は宣言時に初期化されるがpythonはそれがないのでまずはあえて0で初期化
h = [0] * blockMAXElement
# 入力データ諸々
N = int(input().strip())
inputh = list(map(int, input().strip().split(" ")))
# h配列を入力データから取り出した物に置き換える
for i in range(0, len(inputh), +1):
h[i] = inputh[i]
# 初期の条件 0歩の時だけはコストがないので、0にセット
dp[0] = 0
def rec(position):
# まずは最大値にセット(上でもやっているのだが)
answer = sys.maxsize
if position == 0:
answer = 0
# もしメモを見てデフォルトでセットされた最大値以下であれば更新済みなのでその値をそのまま返す
elif dp[position] < sys.maxsize:
answer = dp[position]
else:
# 貰うDPを想定して組む
# 一つ手前の足場から来た場合
nowCost = rec(position - 1) + abs(h[position] - h[position - 1])
if nowCost < answer:
answer = nowCost
# 二つ手前から来た場合→position = 1では-1を参照するので不具合
if 2 <= position:
nowCost = rec(position - 2) + abs(h[position] - h[position - 2])
if nowCost < answer:
answer = nowCost
# この位置についての最小値はdp配列にメモする
dp[position] = answer
return answer
answer = rec(N - 1)
print("{}".format(answer))
| Statement
There are N stones, numbered 1, 2, \ldots, N. For each i (1 \leq i \leq N),
the height of Stone i is h_i.
There is a frog who is initially on Stone 1. He will repeat the following
action some number of times to reach Stone N:
* If the frog is currently on Stone i, jump to Stone i + 1 or Stone i + 2. Here, a cost of |h_i - h_j| is incurred, where j is the stone to land on.
Find the minimum possible total cost incurred before the frog reaches Stone N. | [{"input": "4\n 10 30 40 20", "output": "30\n \n\nIf we follow the path 1 \u2192 2 \u2192 4, the total cost incurred would be |10 - 30| +\n|30 - 20| = 30.\n\n* * *"}, {"input": "2\n 10 10", "output": "0\n \n\nIf we follow the path 1 \u2192 2, the total cost incurred would be |10 - 10| = 0.\n\n* * *"}, {"input": "6\n 30 10 60 10 60 50", "output": "40\n \n\nIf we follow the path 1 \u2192 3 \u2192 5 \u2192 6, the total cost incurred would be |30 -\n60| + |60 - 60| + |60 - 50| = 40."}] |
Print the minimum possible total cost incurred.
* * * | s725328833 | Accepted | p03160 | Input is given from Standard Input in the following format:
N
h_1 h_2 \ldots h_N | # -*- coding: utf-8 -*-
#############
# Libraries #
#############
import sys
input = sys.stdin.readline
import math
# from math import gcd
import bisect
import heapq
from collections import defaultdict
from collections import deque
from collections import Counter
from functools import lru_cache
#############
# Constants #
#############
MOD = 10**9 + 7
INF = float("inf")
AZ = "abcdefghijklmnopqrstuvwxyz"
#############
# Functions #
#############
######INPUT######
def I():
return int(input().strip())
def S():
return input().strip()
def IL():
return list(map(int, input().split()))
def SL():
return list(map(str, input().split()))
def ILs(n):
return list(int(input()) for _ in range(n))
def SLs(n):
return list(input().strip() for _ in range(n))
def ILL(n):
return [list(map(int, input().split())) for _ in range(n)]
def SLL(n):
return [list(map(str, input().split())) for _ in range(n)]
######OUTPUT######
def P(arg):
print(arg)
return
def Y():
print("Yes")
return
def N():
print("No")
return
def E():
exit()
def PE(arg):
print(arg)
exit()
def YE():
print("Yes")
exit()
def NE():
print("No")
exit()
#####Shorten#####
def DD(arg):
return defaultdict(arg)
#####Inverse#####
def inv(n):
return pow(n, MOD - 2, MOD)
######Combination######
kaijo_memo = []
def kaijo(n):
if len(kaijo_memo) > n:
return kaijo_memo[n]
if len(kaijo_memo) == 0:
kaijo_memo.append(1)
while len(kaijo_memo) <= n:
kaijo_memo.append(kaijo_memo[-1] * len(kaijo_memo) % MOD)
return kaijo_memo[n]
gyaku_kaijo_memo = []
def gyaku_kaijo(n):
if len(gyaku_kaijo_memo) > n:
return gyaku_kaijo_memo[n]
if len(gyaku_kaijo_memo) == 0:
gyaku_kaijo_memo.append(1)
while len(gyaku_kaijo_memo) <= n:
gyaku_kaijo_memo.append(
gyaku_kaijo_memo[-1] * pow(len(gyaku_kaijo_memo), MOD - 2, MOD) % MOD
)
return gyaku_kaijo_memo[n]
def nCr(n, r):
if n == r:
return 1
if n < r or r < 0:
return 0
ret = 1
ret = ret * kaijo(n) % MOD
ret = ret * gyaku_kaijo(r) % MOD
ret = ret * gyaku_kaijo(n - r) % MOD
return ret
######Factorization######
def factorization(n):
arr = []
temp = n
for i in range(2, int(-(-(n**0.5) // 1)) + 1):
if temp % i == 0:
cnt = 0
while temp % i == 0:
cnt += 1
temp //= i
arr.append([i, cnt])
if temp != 1:
arr.append([temp, 1])
if arr == []:
arr.append([n, 1])
return arr
#####MakeDivisors######
def make_divisors(n):
divisors = []
for i in range(1, int(n**0.5) + 1):
if n % i == 0:
divisors.append(i)
if i != n // i:
divisors.append(n // i)
return divisors
#####MakePrimes######
def make_primes(N):
max = int(math.sqrt(N))
seachList = [i for i in range(2, N + 1)]
primeNum = []
while seachList[0] <= max:
primeNum.append(seachList[0])
tmp = seachList[0]
seachList = [i for i in seachList if i % tmp != 0]
primeNum.extend(seachList)
return primeNum
#####GCD#####
def gcd(a, b):
while b:
a, b = b, a % b
return a
#####LCM#####
def lcm(a, b):
return a * b // gcd(a, b)
#####BitCount#####
def count_bit(n):
count = 0
while n:
n &= n - 1
count += 1
return count
#####ChangeBase#####
def base_10_to_n(X, n):
if X // n:
return base_10_to_n(X // n, n) + [X % n]
return [X % n]
def base_n_to_10(X, n):
return sum(int(str(X)[-i - 1]) * n**i for i in range(len(str(X))))
def base_10_to_n_without_0(X, n):
X -= 1
if X // n:
return base_10_to_n_without_0(X // n, n) + [X % n]
return [X % n]
#####IntLog#####
def int_log(n, a):
count = 0
while n >= a:
n //= a
count += 1
return count
#############
# Main Code #
#############
N = I()
A = IL() + [INF] * 5
dp = [INF for i in range(N + 5)]
dp[0] = 0
for i in range(N):
dp[i + 1] = min(dp[i + 1], dp[i] + abs(A[i] - A[i + 1]))
dp[i + 2] = min(dp[i + 2], dp[i] + abs(A[i] - A[i + 2]))
print(dp[N - 1])
| Statement
There are N stones, numbered 1, 2, \ldots, N. For each i (1 \leq i \leq N),
the height of Stone i is h_i.
There is a frog who is initially on Stone 1. He will repeat the following
action some number of times to reach Stone N:
* If the frog is currently on Stone i, jump to Stone i + 1 or Stone i + 2. Here, a cost of |h_i - h_j| is incurred, where j is the stone to land on.
Find the minimum possible total cost incurred before the frog reaches Stone N. | [{"input": "4\n 10 30 40 20", "output": "30\n \n\nIf we follow the path 1 \u2192 2 \u2192 4, the total cost incurred would be |10 - 30| +\n|30 - 20| = 30.\n\n* * *"}, {"input": "2\n 10 10", "output": "0\n \n\nIf we follow the path 1 \u2192 2, the total cost incurred would be |10 - 10| = 0.\n\n* * *"}, {"input": "6\n 30 10 60 10 60 50", "output": "40\n \n\nIf we follow the path 1 \u2192 3 \u2192 5 \u2192 6, the total cost incurred would be |30 -\n60| + |60 - 60| + |60 - 50| = 40."}] |
Print the minimum possible total cost incurred.
* * * | s331130150 | Accepted | p03160 | Input is given from Standard Input in the following format:
N
h_1 h_2 \ldots h_N | # 入力を受け取る
list_num = int(input())
places = list(map(int, input().split()))
# すべてをINFで初期化
dp_table = [99999999] * (list_num + 1)
# 初期条件の作成
dp_table[0] = 0
dp_table[1] = abs(places[1] - places[0])
for i in range(2, list_num):
dp_table_pre_1 = dp_table[i - 1] + abs(places[i] - places[i - 1])
dp_table_pre_2 = dp_table[i - 2] + abs(places[i] - places[i - 2])
dp_table[i] = min(dp_table_pre_1, dp_table_pre_2)
print(dp_table[list_num - 1])
| Statement
There are N stones, numbered 1, 2, \ldots, N. For each i (1 \leq i \leq N),
the height of Stone i is h_i.
There is a frog who is initially on Stone 1. He will repeat the following
action some number of times to reach Stone N:
* If the frog is currently on Stone i, jump to Stone i + 1 or Stone i + 2. Here, a cost of |h_i - h_j| is incurred, where j is the stone to land on.
Find the minimum possible total cost incurred before the frog reaches Stone N. | [{"input": "4\n 10 30 40 20", "output": "30\n \n\nIf we follow the path 1 \u2192 2 \u2192 4, the total cost incurred would be |10 - 30| +\n|30 - 20| = 30.\n\n* * *"}, {"input": "2\n 10 10", "output": "0\n \n\nIf we follow the path 1 \u2192 2, the total cost incurred would be |10 - 10| = 0.\n\n* * *"}, {"input": "6\n 30 10 60 10 60 50", "output": "40\n \n\nIf we follow the path 1 \u2192 3 \u2192 5 \u2192 6, the total cost incurred would be |30 -\n60| + |60 - 60| + |60 - 50| = 40."}] |
Print the minimum possible total cost incurred.
* * * | s951698393 | Wrong Answer | p03160 | Input is given from Standard Input in the following format:
N
h_1 h_2 \ldots h_N | # coding: utf-8
import re
import math
import itertools
from copy import deepcopy
import fractions
import random
from functools import lru_cache
from heapq import heappop, heappush
import time
import sys
readline = sys.stdin.readline
sys.setrecursionlimit(2000)
# import numpy as np
alphabet = "abcdefghijklmnopqrstuvwxyz"
mod = int(10**9 + 7)
inf = int(10**20)
def yn(b):
if b:
print("yes")
else:
print("no")
def Yn(b):
if b:
print("Yes")
else:
print("No")
def YN(b):
if b:
print("YES")
else:
print("NO")
class union_find:
def __init__(self, n):
self.n = n
self.P = [a for a in range(N)]
self.rank = [0] * n
def find(self, x):
if x != self.P[x]:
self.P[x] = self.find(self.P[x])
return self.P[x]
def same(self, x, y):
return self.find(x) == self.find(y)
def link(self, x, y):
if self.rank[x] < self.rank[y]:
self.P[x] = y
elif self.rank[y] < self.rank[x]:
self.P[y] = x
else:
self.P[x] = y
self.rank[y] += 1
def unite(self, x, y):
self.link(self.find(x), self.find(y))
def size(self):
S = set()
for a in range(self.n):
S.add(self.find(a))
return len(S)
def bin_(num, size):
A = [0] * size
for a in range(size):
if (num >> (size - a - 1)) & 1 == 1:
A[a] = 1
else:
A[a] = 0
return A
def fac_list(n, mod_=0):
A = [1] * (n + 1)
for a in range(2, len(A)):
A[a] = A[a - 1] * a
if mod > 0:
A[a] %= mod_
return A
def comb(n, r, mod, fac):
if n - r < 0:
return 0
return (fac[n] * pow(fac[n - r], mod - 2, mod) * pow(fac[r], mod - 2, mod)) % mod
def next_comb(num, size):
x = num & (-num)
y = num + x
z = num & (~y)
z //= x
z = z >> 1
num = y | z
if num >= (1 << size):
return False
else:
return num
def get_primes(n, type="int"):
A = [True] * (n + 1)
A[0] = False
A[1] = False
for a in range(2, n + 1):
if A[a]:
for b in range(a * 2, n + 1, a):
A[b] = False
if type == "bool":
return A
B = []
for a in range(n + 1):
if A[a]:
B.append(a)
return B
def is_prime(num):
if num <= 2:
return False
i = 2
while i * i <= num:
if num % i == 0:
return False
i += 1
return True
def join(A, c=" "):
n = len(A)
A = list(map(str, A))
s = ""
for a in range(n):
s += A[a]
if a < n - 1:
s += c
return s
# main
n = int(input())
H = list(map(int, input().split()))
dp = [inf] * n
for a in range(n):
if a == 0:
dp[a] = 0
elif a == 1:
dp[a] = abs(H[a] - H[a - 1])
else:
dp[a] = min(dp[a - 2] + abs(H[a] - H[a - 2]), dp[a - 2] + abs(H[a] - H[a - 1]))
print(dp[a])
print(dp[n - 1])
| Statement
There are N stones, numbered 1, 2, \ldots, N. For each i (1 \leq i \leq N),
the height of Stone i is h_i.
There is a frog who is initially on Stone 1. He will repeat the following
action some number of times to reach Stone N:
* If the frog is currently on Stone i, jump to Stone i + 1 or Stone i + 2. Here, a cost of |h_i - h_j| is incurred, where j is the stone to land on.
Find the minimum possible total cost incurred before the frog reaches Stone N. | [{"input": "4\n 10 30 40 20", "output": "30\n \n\nIf we follow the path 1 \u2192 2 \u2192 4, the total cost incurred would be |10 - 30| +\n|30 - 20| = 30.\n\n* * *"}, {"input": "2\n 10 10", "output": "0\n \n\nIf we follow the path 1 \u2192 2, the total cost incurred would be |10 - 10| = 0.\n\n* * *"}, {"input": "6\n 30 10 60 10 60 50", "output": "40\n \n\nIf we follow the path 1 \u2192 3 \u2192 5 \u2192 6, the total cost incurred would be |30 -\n60| + |60 - 60| + |60 - 50| = 40."}] |
Print the minimum possible total cost incurred.
* * * | s437699607 | Wrong Answer | p03160 | Input is given from Standard Input in the following format:
N
h_1 h_2 \ldots h_N | import math
route_list = [
[0, 50, 80, 0, 0],
[0, 0, 20, 15, 0],
[0, 0, 0, 10, 15],
[0, 0, 0, 0, 30],
[0, 0, 0, 0, 0],
] # 初期のノード間の距離のリスト
node_num = int(input())
nodes = input().split()
route_list = []
for _ in range(node_num):
route_list.append([-1 for _ in range(node_num)])
for i in range(node_num - 1):
if i + 2 < node_num:
route_list[i][i + 1] = abs(int(nodes[i + 1]) - int(nodes[i]))
route_list[i][i + 2] = abs(int(nodes[i + 2]) - int(nodes[i]))
else:
route_list[i][i + 1] = abs(int(nodes[i + 1]) - int(nodes[i]))
print(route_list)
unsearched_nodes = list(range(node_num)) # 未探索ノード
distance = [99999999999] * node_num # ノードごとの距離のリスト
previous_nodes = [
-1
] * node_num # 最短経路でそのノードのひとつ前に到達するノードのリスト
distance[0] = 0 # 初期のノードの距離は0とする
# @GDaigo さんのコメントより関数の追加 2017/03/18
def get_target_min_index(min_index, distance, unsearched_nodes):
start = 0
while True:
index = distance.index(min_index, start)
found = index in unsearched_nodes
if found:
return index
else:
start = index + 1
while len(unsearched_nodes) != 0: # 未探索ノードがなくなるまで繰り返す
# まず未探索ノードのうちdistanceが最小のものを選択する
posible_min_distance = 99999999999 # 最小のdistanceを見つけるための一時的なdistance。初期値は inf に設定。
for node_index in unsearched_nodes: # 未探索のノードのループ
if posible_min_distance > distance[node_index]:
posible_min_distance = distance[node_index] # より小さい値が見つかれば更新
target_min_index = get_target_min_index(
posible_min_distance, distance, unsearched_nodes
) # 未探索ノードのうちで最小のindex番号を取得
unsearched_nodes.remove(target_min_index) # ここで探索するので未探索リストから除去
target_edge = route_list[
target_min_index
] # ターゲットになるノードからのびるエッジのリスト
for index, route_dis in enumerate(target_edge):
if route_dis != -1:
if distance[index] > (distance[target_min_index] + route_dis):
distance[index] = (
distance[target_min_index] + route_dis
) # 過去に設定されたdistanceよりも小さい場合はdistanceを更新
previous_nodes[index] = (
target_min_index # ひとつ前に到達するノードのリストも更新
)
# 以下で結果の表示
"""
print("-----経路-----")
previous_node = node_num - 1
while previous_node != -1:
if previous_node !=0:
print(str(previous_node + 1) + " <- ", end='')
else:
print(str(previous_node + 1))
previous_node = previous_nodes[previous_node]
print("-----距離-----")
"""
print(distance[node_num - 1])
| Statement
There are N stones, numbered 1, 2, \ldots, N. For each i (1 \leq i \leq N),
the height of Stone i is h_i.
There is a frog who is initially on Stone 1. He will repeat the following
action some number of times to reach Stone N:
* If the frog is currently on Stone i, jump to Stone i + 1 or Stone i + 2. Here, a cost of |h_i - h_j| is incurred, where j is the stone to land on.
Find the minimum possible total cost incurred before the frog reaches Stone N. | [{"input": "4\n 10 30 40 20", "output": "30\n \n\nIf we follow the path 1 \u2192 2 \u2192 4, the total cost incurred would be |10 - 30| +\n|30 - 20| = 30.\n\n* * *"}, {"input": "2\n 10 10", "output": "0\n \n\nIf we follow the path 1 \u2192 2, the total cost incurred would be |10 - 10| = 0.\n\n* * *"}, {"input": "6\n 30 10 60 10 60 50", "output": "40\n \n\nIf we follow the path 1 \u2192 3 \u2192 5 \u2192 6, the total cost incurred would be |30 -\n60| + |60 - 60| + |60 - 50| = 40."}] |
Print the minimum possible total cost incurred.
* * * | s947720970 | Accepted | p03160 | Input is given from Standard Input in the following format:
N
h_1 h_2 \ldots h_N | nums = int(input())
ary = list(map(int, input().split()))
dp = [0 for i in range(nums)]
for i in range(1, nums):
dp[i] = float("inf")
jump_min = 0
for i in range(1, nums):
for x in range(1, 3):
jump = i - x
if i - x < 0:
continue
jump = dp[i - x] + abs(ary[i - x] - ary[i])
if jump < dp[i]:
dp[i] = jump
print(dp[nums - 1])
| Statement
There are N stones, numbered 1, 2, \ldots, N. For each i (1 \leq i \leq N),
the height of Stone i is h_i.
There is a frog who is initially on Stone 1. He will repeat the following
action some number of times to reach Stone N:
* If the frog is currently on Stone i, jump to Stone i + 1 or Stone i + 2. Here, a cost of |h_i - h_j| is incurred, where j is the stone to land on.
Find the minimum possible total cost incurred before the frog reaches Stone N. | [{"input": "4\n 10 30 40 20", "output": "30\n \n\nIf we follow the path 1 \u2192 2 \u2192 4, the total cost incurred would be |10 - 30| +\n|30 - 20| = 30.\n\n* * *"}, {"input": "2\n 10 10", "output": "0\n \n\nIf we follow the path 1 \u2192 2, the total cost incurred would be |10 - 10| = 0.\n\n* * *"}, {"input": "6\n 30 10 60 10 60 50", "output": "40\n \n\nIf we follow the path 1 \u2192 3 \u2192 5 \u2192 6, the total cost incurred would be |30 -\n60| + |60 - 60| + |60 - 50| = 40."}] |
Print the minimum possible total cost incurred.
* * * | s664551610 | Wrong Answer | p03160 | Input is given from Standard Input in the following format:
N
h_1 h_2 \ldots h_N | n = int(input())
arr = list(map(int, input().split()))
print(arr)
| Statement
There are N stones, numbered 1, 2, \ldots, N. For each i (1 \leq i \leq N),
the height of Stone i is h_i.
There is a frog who is initially on Stone 1. He will repeat the following
action some number of times to reach Stone N:
* If the frog is currently on Stone i, jump to Stone i + 1 or Stone i + 2. Here, a cost of |h_i - h_j| is incurred, where j is the stone to land on.
Find the minimum possible total cost incurred before the frog reaches Stone N. | [{"input": "4\n 10 30 40 20", "output": "30\n \n\nIf we follow the path 1 \u2192 2 \u2192 4, the total cost incurred would be |10 - 30| +\n|30 - 20| = 30.\n\n* * *"}, {"input": "2\n 10 10", "output": "0\n \n\nIf we follow the path 1 \u2192 2, the total cost incurred would be |10 - 10| = 0.\n\n* * *"}, {"input": "6\n 30 10 60 10 60 50", "output": "40\n \n\nIf we follow the path 1 \u2192 3 \u2192 5 \u2192 6, the total cost incurred would be |30 -\n60| + |60 - 60| + |60 - 50| = 40."}] |
Print the minimum possible total cost incurred.
* * * | s241356197 | Runtime Error | p03160 | Input is given from Standard Input in the following format:
N
h_1 h_2 \ldots h_N | def min_cost_frog_jump(stone_values, i, n):
# Base Case
if i + 1 == n:
t[i + 1] = 0
return t[i + 1]
if i + 2 == n:
t[i + 2] = abs(stone_values[i + 1] - stone_values[i])
return t[i + 2]
if t[i] != -1:
return t[i]
jump_to_one = abs(stone_values[i + 1] - stone_values[i]) + min_cost_frog_jump(
stone_values, i + 1, n
)
jumpy_to_two = abs(stone_values[i + 2] - stone_values[i]) + min_cost_frog_jump(
stone_values, i + 2, n
)
t[i] = min(jump_to_one, jumpy_to_two)
return t[i]
num_of_stones = int(input())
stone_values = [int(it) for it in input().split(" ")]
t = [-1] * (num_of_stones + 1)
print(min_cost_frog_jump(stone_values=stone_values, i=0, n=num_of_stones))
| Statement
There are N stones, numbered 1, 2, \ldots, N. For each i (1 \leq i \leq N),
the height of Stone i is h_i.
There is a frog who is initially on Stone 1. He will repeat the following
action some number of times to reach Stone N:
* If the frog is currently on Stone i, jump to Stone i + 1 or Stone i + 2. Here, a cost of |h_i - h_j| is incurred, where j is the stone to land on.
Find the minimum possible total cost incurred before the frog reaches Stone N. | [{"input": "4\n 10 30 40 20", "output": "30\n \n\nIf we follow the path 1 \u2192 2 \u2192 4, the total cost incurred would be |10 - 30| +\n|30 - 20| = 30.\n\n* * *"}, {"input": "2\n 10 10", "output": "0\n \n\nIf we follow the path 1 \u2192 2, the total cost incurred would be |10 - 10| = 0.\n\n* * *"}, {"input": "6\n 30 10 60 10 60 50", "output": "40\n \n\nIf we follow the path 1 \u2192 3 \u2192 5 \u2192 6, the total cost incurred would be |30 -\n60| + |60 - 60| + |60 - 50| = 40."}] |
Print the minimum possible total cost incurred.
* * * | s497626923 | Runtime Error | p03160 | Input is given from Standard Input in the following format:
N
h_1 h_2 \ldots h_N | import sys
inp = sys.stdin.readline
read = lambda: list(map(int, inp().strip().split()))
def a():
n = int(inp())
arr = read()
dic = {0: 0, 1: abs(arr[0] - arr[1])}
def func(arr, n):
if n in dic:
return dic[n]
min_path = min(
abs(arr[n] - arr[n - 1]) + func(arr, n - 1),
abs(arr[n] - arr[n - 2]) + func(arr, n - 2),
)
dic[n] = min_path
return min_path
print(func(arr, n - 1))
# print(dic)
if __name__ == "__main__":
a()
| Statement
There are N stones, numbered 1, 2, \ldots, N. For each i (1 \leq i \leq N),
the height of Stone i is h_i.
There is a frog who is initially on Stone 1. He will repeat the following
action some number of times to reach Stone N:
* If the frog is currently on Stone i, jump to Stone i + 1 or Stone i + 2. Here, a cost of |h_i - h_j| is incurred, where j is the stone to land on.
Find the minimum possible total cost incurred before the frog reaches Stone N. | [{"input": "4\n 10 30 40 20", "output": "30\n \n\nIf we follow the path 1 \u2192 2 \u2192 4, the total cost incurred would be |10 - 30| +\n|30 - 20| = 30.\n\n* * *"}, {"input": "2\n 10 10", "output": "0\n \n\nIf we follow the path 1 \u2192 2, the total cost incurred would be |10 - 10| = 0.\n\n* * *"}, {"input": "6\n 30 10 60 10 60 50", "output": "40\n \n\nIf we follow the path 1 \u2192 3 \u2192 5 \u2192 6, the total cost incurred would be |30 -\n60| + |60 - 60| + |60 - 50| = 40."}] |
Print the minimum possible total cost incurred.
* * * | s398307508 | Runtime Error | p03160 | Input is given from Standard Input in the following format:
N
h_1 h_2 \ldots h_N | A = [-1] * (10**9)
print(A)
| Statement
There are N stones, numbered 1, 2, \ldots, N. For each i (1 \leq i \leq N),
the height of Stone i is h_i.
There is a frog who is initially on Stone 1. He will repeat the following
action some number of times to reach Stone N:
* If the frog is currently on Stone i, jump to Stone i + 1 or Stone i + 2. Here, a cost of |h_i - h_j| is incurred, where j is the stone to land on.
Find the minimum possible total cost incurred before the frog reaches Stone N. | [{"input": "4\n 10 30 40 20", "output": "30\n \n\nIf we follow the path 1 \u2192 2 \u2192 4, the total cost incurred would be |10 - 30| +\n|30 - 20| = 30.\n\n* * *"}, {"input": "2\n 10 10", "output": "0\n \n\nIf we follow the path 1 \u2192 2, the total cost incurred would be |10 - 10| = 0.\n\n* * *"}, {"input": "6\n 30 10 60 10 60 50", "output": "40\n \n\nIf we follow the path 1 \u2192 3 \u2192 5 \u2192 6, the total cost incurred would be |30 -\n60| + |60 - 60| + |60 - 50| = 40."}] |
Print the minimum possible total cost incurred.
* * * | s040610609 | Accepted | p03160 | Input is given from Standard Input in the following format:
N
h_1 h_2 \ldots h_N | import math, sys, bisect, heapq
from collections import defaultdict, Counter, deque
from itertools import groupby, accumulate
# sys.setrecursionlimit(200000000)
input = iter(sys.stdin.buffer.read().decode().splitlines()).__next__
ilele = lambda: map(int, input().split())
alele = lambda: list(map(int, input().split()))
def list2d(a, b, c):
return [[c] * b for i in range(a)]
# def list3d(a, b, c, d): return [[[d] * c for j in range(b)] for i in range(a)]
MOD = 1000000000 + 7
def Y(c):
print(["NO", "YES"][c])
def y(c):
print(["no", "yes"][c])
def Yy(c):
print(["No", "Yes"][c])
def fun(A, N):
dp = [0] * N
for pos in range(N):
if pos == 0:
dp[pos] = 0
elif pos == 1:
dp[pos] = abs(A[pos - 1] - A[pos])
else:
dp[pos] = min(
abs(A[pos] - A[pos - 1]) + dp[pos - 1],
abs(A[pos] - A[pos - 2]) + dp[pos - 2],
)
return dp[-1]
N = int(input())
A = alele()
print(fun(A, N))
| Statement
There are N stones, numbered 1, 2, \ldots, N. For each i (1 \leq i \leq N),
the height of Stone i is h_i.
There is a frog who is initially on Stone 1. He will repeat the following
action some number of times to reach Stone N:
* If the frog is currently on Stone i, jump to Stone i + 1 or Stone i + 2. Here, a cost of |h_i - h_j| is incurred, where j is the stone to land on.
Find the minimum possible total cost incurred before the frog reaches Stone N. | [{"input": "4\n 10 30 40 20", "output": "30\n \n\nIf we follow the path 1 \u2192 2 \u2192 4, the total cost incurred would be |10 - 30| +\n|30 - 20| = 30.\n\n* * *"}, {"input": "2\n 10 10", "output": "0\n \n\nIf we follow the path 1 \u2192 2, the total cost incurred would be |10 - 10| = 0.\n\n* * *"}, {"input": "6\n 30 10 60 10 60 50", "output": "40\n \n\nIf we follow the path 1 \u2192 3 \u2192 5 \u2192 6, the total cost incurred would be |30 -\n60| + |60 - 60| + |60 - 50| = 40."}] |
Print the minimum possible total cost incurred.
* * * | s529359653 | Wrong Answer | p03160 | Input is given from Standard Input in the following format:
N
h_1 h_2 \ldots h_N | """ ===============================
-- @uthor : Kaleab Asfaw
-- Handle : kaleabasfaw2010
-- Bio : None
==============================="""
# Fast IO
import sys
import os
from io import BytesIO, IOBase
BUFSIZE = 8192
class FastIO(IOBase):
newlines = 0
def __init__(self, file):
self._fd = file.fileno()
self.buffer = BytesIO()
self.writable = "x" in file.mode or "r" not in file.mode
self.write = self.buffer.write if self.writable else None
def read(self):
while True:
b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
if not b:
break
ptr = self.buffer.tell()
self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
self.newlines = 0
return self.buffer.read()
def readline(self):
while self.newlines == 0:
b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
self.newlines = b.count(b"\n") + (not b)
ptr = self.buffer.tell()
self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
self.newlines -= 1
return self.buffer.readline()
def flush(self):
if self.writable:
os.write(self._fd, self.buffer.getvalue())
self.buffer.truncate(0), self.buffer.seek(0)
class IOWrapper(IOBase):
def __init__(self, file):
self.buffer = FastIO(file)
self.flush = self.buffer.flush
self.writable = self.buffer.writable
self.write = lambda s: self.buffer.write(s.encode("ascii"))
self.read = lambda: self.buffer.read().decode("ascii")
self.readline = lambda: self.buffer.readline().decode("ascii")
sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout)
input = lambda: sys.stdin.readline().rstrip("\r\n")
# Others
# from math import floor, ceil, gcd
# from decimal import Decimal as d
mod = 10**9 + 7
def lcm(x, y):
return (x * y) / (gcd(x, y))
def fact(x, mod=mod):
ans = 1
for i in range(1, x + 1):
ans = (ans * i) % mod
return ans
def arr2D(n, m, default=0):
lst = []
for i in range(n):
temp = [default] * m
lst.append(temp)
return lst
def sortDictV(x):
return {k: v for k, v in sorted(x.items(), key=lambda item: item[1])}
def solve(n, lst):
dp = [float("inf")] * n
dp[1] = abs(lst[1] - lst[0])
for i in range(2, n):
dp[i] = min(
dp[i - 1] + abs(lst[i] - lst[i - 1]), dp[i - 2] + abs(lst[i] - lst[i - 2])
)
return dp[n - 1]
n = int(input())
lst = list(map(int, input().split()))
print(solve(n, lst))
| Statement
There are N stones, numbered 1, 2, \ldots, N. For each i (1 \leq i \leq N),
the height of Stone i is h_i.
There is a frog who is initially on Stone 1. He will repeat the following
action some number of times to reach Stone N:
* If the frog is currently on Stone i, jump to Stone i + 1 or Stone i + 2. Here, a cost of |h_i - h_j| is incurred, where j is the stone to land on.
Find the minimum possible total cost incurred before the frog reaches Stone N. | [{"input": "4\n 10 30 40 20", "output": "30\n \n\nIf we follow the path 1 \u2192 2 \u2192 4, the total cost incurred would be |10 - 30| +\n|30 - 20| = 30.\n\n* * *"}, {"input": "2\n 10 10", "output": "0\n \n\nIf we follow the path 1 \u2192 2, the total cost incurred would be |10 - 10| = 0.\n\n* * *"}, {"input": "6\n 30 10 60 10 60 50", "output": "40\n \n\nIf we follow the path 1 \u2192 3 \u2192 5 \u2192 6, the total cost incurred would be |30 -\n60| + |60 - 60| + |60 - 50| = 40."}] |
Print the minimum possible total cost incurred.
* * * | s600286479 | Runtime Error | p03160 | Input is given from Standard Input in the following format:
N
h_1 h_2 \ldots h_N | #include<bits/stdc++.h>
using namespace std;
int dp[10000001];
int arr[10000001];
int n;
int solve(int ind)
{
if(ind==n-1)
{
return 0;
}
if(dp[ind]!=-1)
{
return dp[ind];
}
int ans=solve(ind+1)+abs(arr[ind+1]-arr[ind]);
if(ind+2<n)
{
ans=min(ans,solve(ind+2)+abs(arr[ind+2]-arr[ind]));
}
return dp[ind]=ans;
}
int main() {
#ifndef ONLINE_JUDGE
freopen("input.txt","r",stdin);
freopen("output.txt","w",stdout);
#endif
memset(dp,-1,sizeof(dp));
cin>>n;
for(int i=0;i<n;i++)
{
cin>>arr[i];
}
cout<<solve(0)<<"\n";
return 0;
} | Statement
There are N stones, numbered 1, 2, \ldots, N. For each i (1 \leq i \leq N),
the height of Stone i is h_i.
There is a frog who is initially on Stone 1. He will repeat the following
action some number of times to reach Stone N:
* If the frog is currently on Stone i, jump to Stone i + 1 or Stone i + 2. Here, a cost of |h_i - h_j| is incurred, where j is the stone to land on.
Find the minimum possible total cost incurred before the frog reaches Stone N. | [{"input": "4\n 10 30 40 20", "output": "30\n \n\nIf we follow the path 1 \u2192 2 \u2192 4, the total cost incurred would be |10 - 30| +\n|30 - 20| = 30.\n\n* * *"}, {"input": "2\n 10 10", "output": "0\n \n\nIf we follow the path 1 \u2192 2, the total cost incurred would be |10 - 10| = 0.\n\n* * *"}, {"input": "6\n 30 10 60 10 60 50", "output": "40\n \n\nIf we follow the path 1 \u2192 3 \u2192 5 \u2192 6, the total cost incurred would be |30 -\n60| + |60 - 60| + |60 - 50| = 40."}] |
Print the minimum possible total cost incurred.
* * * | s485904077 | Runtime Error | p03160 | Input is given from Standard Input in the following format:
N
h_1 h_2 \ldots h_N | N, K = map(int, input().split())
h_list = list(map(int, input().split()))
dp_list = [0]
for n in range(1, N):
tmp_h = h_list[n]
if n < K:
lst = [abs(tmp_h - h_list[i]) + dp_list[i] for i in range(n)]
else:
lst = [abs(tmp_h - h_list[n-k]) + dp_list[n-k] for k in range(1, K + 1)]
dp_list.append(min(lst))
print(dp_list[-1]) | Statement
There are N stones, numbered 1, 2, \ldots, N. For each i (1 \leq i \leq N),
the height of Stone i is h_i.
There is a frog who is initially on Stone 1. He will repeat the following
action some number of times to reach Stone N:
* If the frog is currently on Stone i, jump to Stone i + 1 or Stone i + 2. Here, a cost of |h_i - h_j| is incurred, where j is the stone to land on.
Find the minimum possible total cost incurred before the frog reaches Stone N. | [{"input": "4\n 10 30 40 20", "output": "30\n \n\nIf we follow the path 1 \u2192 2 \u2192 4, the total cost incurred would be |10 - 30| +\n|30 - 20| = 30.\n\n* * *"}, {"input": "2\n 10 10", "output": "0\n \n\nIf we follow the path 1 \u2192 2, the total cost incurred would be |10 - 10| = 0.\n\n* * *"}, {"input": "6\n 30 10 60 10 60 50", "output": "40\n \n\nIf we follow the path 1 \u2192 3 \u2192 5 \u2192 6, the total cost incurred would be |30 -\n60| + |60 - 60| + |60 - 50| = 40."}] |
Print the minimum possible total cost incurred.
* * * | s181425953 | Runtime Error | p03160 | Input is given from Standard Input in the following format:
N
h_1 h_2 \ldots h_N | import sys
sys.setrecursionlimit(10**6)
def dp(n,cache,height):
if n<0:
return float('inf')
elif n==0:
return 0
elif n==1:
return abs(height[1]-height[0])
elif n in cache :
return cache[n]
else:
cache[n]= min(dp(n-1,cahche,height)+abs(height[n]-height[n-1]),dp(n-2,cahche,height)+abs(height[n]-height[n-2]))
return cache[n] | Statement
There are N stones, numbered 1, 2, \ldots, N. For each i (1 \leq i \leq N),
the height of Stone i is h_i.
There is a frog who is initially on Stone 1. He will repeat the following
action some number of times to reach Stone N:
* If the frog is currently on Stone i, jump to Stone i + 1 or Stone i + 2. Here, a cost of |h_i - h_j| is incurred, where j is the stone to land on.
Find the minimum possible total cost incurred before the frog reaches Stone N. | [{"input": "4\n 10 30 40 20", "output": "30\n \n\nIf we follow the path 1 \u2192 2 \u2192 4, the total cost incurred would be |10 - 30| +\n|30 - 20| = 30.\n\n* * *"}, {"input": "2\n 10 10", "output": "0\n \n\nIf we follow the path 1 \u2192 2, the total cost incurred would be |10 - 10| = 0.\n\n* * *"}, {"input": "6\n 30 10 60 10 60 50", "output": "40\n \n\nIf we follow the path 1 \u2192 3 \u2192 5 \u2192 6, the total cost incurred would be |30 -\n60| + |60 - 60| + |60 - 50| = 40."}] |
Print the minimum possible total cost incurred.
* * * | s257345235 | Runtime Error | p03160 | Input is given from Standard Input in the following format:
N
h_1 h_2 \ldots h_N | #dp educational contest a frog1
n=int(input())
h=list(map(int,input().split()))
dp=[0]*n
for i in range(1,n):
if i==1:
dp[i]=abs(h[i]-h[i-1]) #0番目と1番目の差
else:
dp[i]=min(dp[i-1]+abs(h[i]-h[i-1]),dp[i-2]+abs(h[i]-h[i-2]))
ans=dp[n-1]
print(ans)
| Statement
There are N stones, numbered 1, 2, \ldots, N. For each i (1 \leq i \leq N),
the height of Stone i is h_i.
There is a frog who is initially on Stone 1. He will repeat the following
action some number of times to reach Stone N:
* If the frog is currently on Stone i, jump to Stone i + 1 or Stone i + 2. Here, a cost of |h_i - h_j| is incurred, where j is the stone to land on.
Find the minimum possible total cost incurred before the frog reaches Stone N. | [{"input": "4\n 10 30 40 20", "output": "30\n \n\nIf we follow the path 1 \u2192 2 \u2192 4, the total cost incurred would be |10 - 30| +\n|30 - 20| = 30.\n\n* * *"}, {"input": "2\n 10 10", "output": "0\n \n\nIf we follow the path 1 \u2192 2, the total cost incurred would be |10 - 10| = 0.\n\n* * *"}, {"input": "6\n 30 10 60 10 60 50", "output": "40\n \n\nIf we follow the path 1 \u2192 3 \u2192 5 \u2192 6, the total cost incurred would be |30 -\n60| + |60 - 60| + |60 - 50| = 40."}] |
Print the minimum possible total cost incurred.
* * * | s508135266 | Runtime Error | p03160 | Input is given from Standard Input in the following format:
N
h_1 h_2 \ldots h_N | (n, W) = map(int, input().split())
pre = [0] * (W + 1)
cur = [0] * (W + 1)
# a = [[0] * (W+1) for i in range(n)]
for i in range(0, n):
(w, v) = map(int, input().split())
for j in range(w, W + 1):
cur[j] = max(pre[j], pre[j - w] + v)
pre = list(cur)
print(cur[W])
| Statement
There are N stones, numbered 1, 2, \ldots, N. For each i (1 \leq i \leq N),
the height of Stone i is h_i.
There is a frog who is initially on Stone 1. He will repeat the following
action some number of times to reach Stone N:
* If the frog is currently on Stone i, jump to Stone i + 1 or Stone i + 2. Here, a cost of |h_i - h_j| is incurred, where j is the stone to land on.
Find the minimum possible total cost incurred before the frog reaches Stone N. | [{"input": "4\n 10 30 40 20", "output": "30\n \n\nIf we follow the path 1 \u2192 2 \u2192 4, the total cost incurred would be |10 - 30| +\n|30 - 20| = 30.\n\n* * *"}, {"input": "2\n 10 10", "output": "0\n \n\nIf we follow the path 1 \u2192 2, the total cost incurred would be |10 - 10| = 0.\n\n* * *"}, {"input": "6\n 30 10 60 10 60 50", "output": "40\n \n\nIf we follow the path 1 \u2192 3 \u2192 5 \u2192 6, the total cost incurred would be |30 -\n60| + |60 - 60| + |60 - 50| = 40."}] |
Print the minimum possible total cost incurred.
* * * | s760031430 | Runtime Error | p03160 | Input is given from Standard Input in the following format:
N
h_1 h_2 \ldots h_N | def findmin(arr,n):
dp = [0]*n
dp[1] = abs(arr[0]-arr[1])
for i in range(2,n):
dp[i] = min(dp[i-1]+abs(arr[i-1]-arr[i]), dp[i-2]+abs(arr[i-2]-arr[i]))
return dp[-1]
n = int(input())
arr = list(map(int,input().split())
print(findmin(arr,n)) | Statement
There are N stones, numbered 1, 2, \ldots, N. For each i (1 \leq i \leq N),
the height of Stone i is h_i.
There is a frog who is initially on Stone 1. He will repeat the following
action some number of times to reach Stone N:
* If the frog is currently on Stone i, jump to Stone i + 1 or Stone i + 2. Here, a cost of |h_i - h_j| is incurred, where j is the stone to land on.
Find the minimum possible total cost incurred before the frog reaches Stone N. | [{"input": "4\n 10 30 40 20", "output": "30\n \n\nIf we follow the path 1 \u2192 2 \u2192 4, the total cost incurred would be |10 - 30| +\n|30 - 20| = 30.\n\n* * *"}, {"input": "2\n 10 10", "output": "0\n \n\nIf we follow the path 1 \u2192 2, the total cost incurred would be |10 - 10| = 0.\n\n* * *"}, {"input": "6\n 30 10 60 10 60 50", "output": "40\n \n\nIf we follow the path 1 \u2192 3 \u2192 5 \u2192 6, the total cost incurred would be |30 -\n60| + |60 - 60| + |60 - 50| = 40."}] |
Print the minimum possible total cost incurred.
* * * | s795207036 | Runtime Error | p03160 | Input is given from Standard Input in the following format:
N
h_1 h_2 \ldots h_N | n = int(input())
h = [int(i) for i in input().split()]
dp = [0,abs(h[0]-h[1])]
for i in range(2,n):
dp.append(min(dp[-1]+abs(h[i]-h[i-1]),dp[-2]+abs(h[i]-h[i-2])))
print(dp[-1]) | Statement
There are N stones, numbered 1, 2, \ldots, N. For each i (1 \leq i \leq N),
the height of Stone i is h_i.
There is a frog who is initially on Stone 1. He will repeat the following
action some number of times to reach Stone N:
* If the frog is currently on Stone i, jump to Stone i + 1 or Stone i + 2. Here, a cost of |h_i - h_j| is incurred, where j is the stone to land on.
Find the minimum possible total cost incurred before the frog reaches Stone N. | [{"input": "4\n 10 30 40 20", "output": "30\n \n\nIf we follow the path 1 \u2192 2 \u2192 4, the total cost incurred would be |10 - 30| +\n|30 - 20| = 30.\n\n* * *"}, {"input": "2\n 10 10", "output": "0\n \n\nIf we follow the path 1 \u2192 2, the total cost incurred would be |10 - 10| = 0.\n\n* * *"}, {"input": "6\n 30 10 60 10 60 50", "output": "40\n \n\nIf we follow the path 1 \u2192 3 \u2192 5 \u2192 6, the total cost incurred would be |30 -\n60| + |60 - 60| + |60 - 50| = 40."}] |
Print the minimum possible total cost incurred.
* * * | s232189410 | Runtime Error | p03160 | Input is given from Standard Input in the following format:
N
h_1 h_2 \ldots h_N | n=int(input())
h=[10**6]+list(map(int,input().split()))
c=[0]*(n+1)
for i in range(2,n+1):
a=c[i-1]+abs(h[i]-h[i-1])
b=c[i-2]+abs(h[i]-h[i-2])
c[i]=min(a,b)
print(c[n] | Statement
There are N stones, numbered 1, 2, \ldots, N. For each i (1 \leq i \leq N),
the height of Stone i is h_i.
There is a frog who is initially on Stone 1. He will repeat the following
action some number of times to reach Stone N:
* If the frog is currently on Stone i, jump to Stone i + 1 or Stone i + 2. Here, a cost of |h_i - h_j| is incurred, where j is the stone to land on.
Find the minimum possible total cost incurred before the frog reaches Stone N. | [{"input": "4\n 10 30 40 20", "output": "30\n \n\nIf we follow the path 1 \u2192 2 \u2192 4, the total cost incurred would be |10 - 30| +\n|30 - 20| = 30.\n\n* * *"}, {"input": "2\n 10 10", "output": "0\n \n\nIf we follow the path 1 \u2192 2, the total cost incurred would be |10 - 10| = 0.\n\n* * *"}, {"input": "6\n 30 10 60 10 60 50", "output": "40\n \n\nIf we follow the path 1 \u2192 3 \u2192 5 \u2192 6, the total cost incurred would be |30 -\n60| + |60 - 60| + |60 - 50| = 40."}] |
Print the minimum possible total cost incurred.
* * * | s564151170 | Runtime Error | p03160 | Input is given from Standard Input in the following format:
N
h_1 h_2 \ldots h_N | N=int(input())
his=input().split()
DP=[]
DP.append(0)
DP.append(his[0]-his[1])
for i in range(2,len(his)):
DP.append(max(DP[i-1]-his[i],DP[i-2])
print(DP[-1])
| Statement
There are N stones, numbered 1, 2, \ldots, N. For each i (1 \leq i \leq N),
the height of Stone i is h_i.
There is a frog who is initially on Stone 1. He will repeat the following
action some number of times to reach Stone N:
* If the frog is currently on Stone i, jump to Stone i + 1 or Stone i + 2. Here, a cost of |h_i - h_j| is incurred, where j is the stone to land on.
Find the minimum possible total cost incurred before the frog reaches Stone N. | [{"input": "4\n 10 30 40 20", "output": "30\n \n\nIf we follow the path 1 \u2192 2 \u2192 4, the total cost incurred would be |10 - 30| +\n|30 - 20| = 30.\n\n* * *"}, {"input": "2\n 10 10", "output": "0\n \n\nIf we follow the path 1 \u2192 2, the total cost incurred would be |10 - 10| = 0.\n\n* * *"}, {"input": "6\n 30 10 60 10 60 50", "output": "40\n \n\nIf we follow the path 1 \u2192 3 \u2192 5 \u2192 6, the total cost incurred would be |30 -\n60| + |60 - 60| + |60 - 50| = 40."}] |
Print the minimum possible total cost incurred.
* * * | s548817608 | Runtime Error | p03160 | Input is given from Standard Input in the following format:
N
h_1 h_2 \ldots h_N | import sys
n = int(input())
a = list(map(int,input().split())
dp = [sys.maxsize]*n
dp[0] = 0
for i in range(n):
for j in (i+1,i+2):
if j < n:
dp[j] = min(dp[j], dp[i]+abs(dp[i]-dp[j]))
print(dp[n-1],end="") | Statement
There are N stones, numbered 1, 2, \ldots, N. For each i (1 \leq i \leq N),
the height of Stone i is h_i.
There is a frog who is initially on Stone 1. He will repeat the following
action some number of times to reach Stone N:
* If the frog is currently on Stone i, jump to Stone i + 1 or Stone i + 2. Here, a cost of |h_i - h_j| is incurred, where j is the stone to land on.
Find the minimum possible total cost incurred before the frog reaches Stone N. | [{"input": "4\n 10 30 40 20", "output": "30\n \n\nIf we follow the path 1 \u2192 2 \u2192 4, the total cost incurred would be |10 - 30| +\n|30 - 20| = 30.\n\n* * *"}, {"input": "2\n 10 10", "output": "0\n \n\nIf we follow the path 1 \u2192 2, the total cost incurred would be |10 - 10| = 0.\n\n* * *"}, {"input": "6\n 30 10 60 10 60 50", "output": "40\n \n\nIf we follow the path 1 \u2192 3 \u2192 5 \u2192 6, the total cost incurred would be |30 -\n60| + |60 - 60| + |60 - 50| = 40."}] |
Print the minimum possible total cost incurred.
* * * | s129112682 | Runtime Error | p03160 | Input is given from Standard Input in the following format:
N
h_1 h_2 \ldots h_N | return True
| Statement
There are N stones, numbered 1, 2, \ldots, N. For each i (1 \leq i \leq N),
the height of Stone i is h_i.
There is a frog who is initially on Stone 1. He will repeat the following
action some number of times to reach Stone N:
* If the frog is currently on Stone i, jump to Stone i + 1 or Stone i + 2. Here, a cost of |h_i - h_j| is incurred, where j is the stone to land on.
Find the minimum possible total cost incurred before the frog reaches Stone N. | [{"input": "4\n 10 30 40 20", "output": "30\n \n\nIf we follow the path 1 \u2192 2 \u2192 4, the total cost incurred would be |10 - 30| +\n|30 - 20| = 30.\n\n* * *"}, {"input": "2\n 10 10", "output": "0\n \n\nIf we follow the path 1 \u2192 2, the total cost incurred would be |10 - 10| = 0.\n\n* * *"}, {"input": "6\n 30 10 60 10 60 50", "output": "40\n \n\nIf we follow the path 1 \u2192 3 \u2192 5 \u2192 6, the total cost incurred would be |30 -\n60| + |60 - 60| + |60 - 50| = 40."}] |
Print the minimum possible total cost incurred.
* * * | s611521352 | Runtime Error | p03160 | Input is given from Standard Input in the following format:
N
h_1 h_2 \ldots h_N | N = int(input())
h = [int(x) for x in input().split()]
dp = [0]*N
for i in range(1,N):
if i==1:
dp[i] = abs(h[1]-h[0])
elif i>1:
dp[i] = min(abs(h[i]-h[i-1])+dp[i-1],abs(h[i]-h[i-2])+dp[i-2])
print(dp[N-1]) | Statement
There are N stones, numbered 1, 2, \ldots, N. For each i (1 \leq i \leq N),
the height of Stone i is h_i.
There is a frog who is initially on Stone 1. He will repeat the following
action some number of times to reach Stone N:
* If the frog is currently on Stone i, jump to Stone i + 1 or Stone i + 2. Here, a cost of |h_i - h_j| is incurred, where j is the stone to land on.
Find the minimum possible total cost incurred before the frog reaches Stone N. | [{"input": "4\n 10 30 40 20", "output": "30\n \n\nIf we follow the path 1 \u2192 2 \u2192 4, the total cost incurred would be |10 - 30| +\n|30 - 20| = 30.\n\n* * *"}, {"input": "2\n 10 10", "output": "0\n \n\nIf we follow the path 1 \u2192 2, the total cost incurred would be |10 - 10| = 0.\n\n* * *"}, {"input": "6\n 30 10 60 10 60 50", "output": "40\n \n\nIf we follow the path 1 \u2192 3 \u2192 5 \u2192 6, the total cost incurred would be |30 -\n60| + |60 - 60| + |60 - 50| = 40."}] |
Print the minimum possible total cost incurred.
* * * | s149585879 | Runtime Error | p03160 | Input is given from Standard Input in the following format:
N
h_1 h_2 \ldots h_N | n=int(input())
ashiba=list(map(int,input()))
cost=[0]*n
for item in range(1:n):
print(item) | Statement
There are N stones, numbered 1, 2, \ldots, N. For each i (1 \leq i \leq N),
the height of Stone i is h_i.
There is a frog who is initially on Stone 1. He will repeat the following
action some number of times to reach Stone N:
* If the frog is currently on Stone i, jump to Stone i + 1 or Stone i + 2. Here, a cost of |h_i - h_j| is incurred, where j is the stone to land on.
Find the minimum possible total cost incurred before the frog reaches Stone N. | [{"input": "4\n 10 30 40 20", "output": "30\n \n\nIf we follow the path 1 \u2192 2 \u2192 4, the total cost incurred would be |10 - 30| +\n|30 - 20| = 30.\n\n* * *"}, {"input": "2\n 10 10", "output": "0\n \n\nIf we follow the path 1 \u2192 2, the total cost incurred would be |10 - 10| = 0.\n\n* * *"}, {"input": "6\n 30 10 60 10 60 50", "output": "40\n \n\nIf we follow the path 1 \u2192 3 \u2192 5 \u2192 6, the total cost incurred would be |30 -\n60| + |60 - 60| + |60 - 50| = 40."}] |
Print the minimum possible total cost incurred.
* * * | s862728742 | Wrong Answer | p03160 | Input is given from Standard Input in the following format:
N
h_1 h_2 \ldots h_N | def frog():
return 1
| Statement
There are N stones, numbered 1, 2, \ldots, N. For each i (1 \leq i \leq N),
the height of Stone i is h_i.
There is a frog who is initially on Stone 1. He will repeat the following
action some number of times to reach Stone N:
* If the frog is currently on Stone i, jump to Stone i + 1 or Stone i + 2. Here, a cost of |h_i - h_j| is incurred, where j is the stone to land on.
Find the minimum possible total cost incurred before the frog reaches Stone N. | [{"input": "4\n 10 30 40 20", "output": "30\n \n\nIf we follow the path 1 \u2192 2 \u2192 4, the total cost incurred would be |10 - 30| +\n|30 - 20| = 30.\n\n* * *"}, {"input": "2\n 10 10", "output": "0\n \n\nIf we follow the path 1 \u2192 2, the total cost incurred would be |10 - 10| = 0.\n\n* * *"}, {"input": "6\n 30 10 60 10 60 50", "output": "40\n \n\nIf we follow the path 1 \u2192 3 \u2192 5 \u2192 6, the total cost incurred would be |30 -\n60| + |60 - 60| + |60 - 50| = 40."}] |
Print the minimum possible total cost incurred.
* * * | s539259261 | Runtime Error | p03160 | Input is given from Standard Input in the following format:
N
h_1 h_2 \ldots h_N | N = int(input())
A = list(map(int,input().split()))
dp = [0] * (N+10)
dp[2] = abs(A[1] - A[0])
for i in range(2,N):
Ai2 = abs(A[i] - A[i-2])
dp[i+1] = min(dp[i]+,dp[i-1]+Ai2)
print(dp[N]) | Statement
There are N stones, numbered 1, 2, \ldots, N. For each i (1 \leq i \leq N),
the height of Stone i is h_i.
There is a frog who is initially on Stone 1. He will repeat the following
action some number of times to reach Stone N:
* If the frog is currently on Stone i, jump to Stone i + 1 or Stone i + 2. Here, a cost of |h_i - h_j| is incurred, where j is the stone to land on.
Find the minimum possible total cost incurred before the frog reaches Stone N. | [{"input": "4\n 10 30 40 20", "output": "30\n \n\nIf we follow the path 1 \u2192 2 \u2192 4, the total cost incurred would be |10 - 30| +\n|30 - 20| = 30.\n\n* * *"}, {"input": "2\n 10 10", "output": "0\n \n\nIf we follow the path 1 \u2192 2, the total cost incurred would be |10 - 10| = 0.\n\n* * *"}, {"input": "6\n 30 10 60 10 60 50", "output": "40\n \n\nIf we follow the path 1 \u2192 3 \u2192 5 \u2192 6, the total cost incurred would be |30 -\n60| + |60 - 60| + |60 - 50| = 40."}] |
Print the minimum possible total cost incurred.
* * * | s129455314 | Wrong Answer | p03160 | Input is given from Standard Input in the following format:
N
h_1 h_2 \ldots h_N | print(1)
| Statement
There are N stones, numbered 1, 2, \ldots, N. For each i (1 \leq i \leq N),
the height of Stone i is h_i.
There is a frog who is initially on Stone 1. He will repeat the following
action some number of times to reach Stone N:
* If the frog is currently on Stone i, jump to Stone i + 1 or Stone i + 2. Here, a cost of |h_i - h_j| is incurred, where j is the stone to land on.
Find the minimum possible total cost incurred before the frog reaches Stone N. | [{"input": "4\n 10 30 40 20", "output": "30\n \n\nIf we follow the path 1 \u2192 2 \u2192 4, the total cost incurred would be |10 - 30| +\n|30 - 20| = 30.\n\n* * *"}, {"input": "2\n 10 10", "output": "0\n \n\nIf we follow the path 1 \u2192 2, the total cost incurred would be |10 - 10| = 0.\n\n* * *"}, {"input": "6\n 30 10 60 10 60 50", "output": "40\n \n\nIf we follow the path 1 \u2192 3 \u2192 5 \u2192 6, the total cost incurred would be |30 -\n60| + |60 - 60| + |60 - 50| = 40."}] |
Print the minimum possible total cost incurred.
* * * | s610754749 | Runtime Error | p03160 | Input is given from Standard Input in the following format:
N
h_1 h_2 \ldots h_N | import numpy as np
n = int(input())
h = list(map(int, input().split()))
ans = [np.inf for i in range(n)]
ans[0] = 0
def dp(ans, h, k):
if n == k + 1:
return
if n != k + 2:
ans[k + 2] = min(ans[k + 2], ans[k] + abs(h[k + 2] - h[k]))
ans[k + 1] = min(ans[k + 1], ans[k] + abs(h[k + 1] - h[k]))
dp(ans, h , k + 1)
dp(ans, h, 0)
print(ans[-1]) | Statement
There are N stones, numbered 1, 2, \ldots, N. For each i (1 \leq i \leq N),
the height of Stone i is h_i.
There is a frog who is initially on Stone 1. He will repeat the following
action some number of times to reach Stone N:
* If the frog is currently on Stone i, jump to Stone i + 1 or Stone i + 2. Here, a cost of |h_i - h_j| is incurred, where j is the stone to land on.
Find the minimum possible total cost incurred before the frog reaches Stone N. | [{"input": "4\n 10 30 40 20", "output": "30\n \n\nIf we follow the path 1 \u2192 2 \u2192 4, the total cost incurred would be |10 - 30| +\n|30 - 20| = 30.\n\n* * *"}, {"input": "2\n 10 10", "output": "0\n \n\nIf we follow the path 1 \u2192 2, the total cost incurred would be |10 - 10| = 0.\n\n* * *"}, {"input": "6\n 30 10 60 10 60 50", "output": "40\n \n\nIf we follow the path 1 \u2192 3 \u2192 5 \u2192 6, the total cost incurred would be |30 -\n60| + |60 - 60| + |60 - 50| = 40."}] |
Print the minimum possible total cost incurred.
* * * | s580160279 | Runtime Error | p03160 | Input is given from Standard Input in the following format:
N
h_1 h_2 \ldots h_N | import os
n = int(input())
ashiba = list(map(int, input().split()))
DP = [10**5 for i in range(n)]
DP[0] = 0
if n == 2:
print(abs(ashiba[1]-ashoba[0]))
os.exit()
for i in range(n-1):
plus_one = abs(ashiba[i+1] - ashiba[i])
DP[i+1] = min(DP[i+1], DP[i]+plus_one)
if i == n-2:break
plus_two = abs(ashiba[i+2] - ashiba[i])
DP[i+2] = min(DP[i+2], DP[i+1]+plus_one, DP[i]+plus_two)
print(DP[n-1]) | Statement
There are N stones, numbered 1, 2, \ldots, N. For each i (1 \leq i \leq N),
the height of Stone i is h_i.
There is a frog who is initially on Stone 1. He will repeat the following
action some number of times to reach Stone N:
* If the frog is currently on Stone i, jump to Stone i + 1 or Stone i + 2. Here, a cost of |h_i - h_j| is incurred, where j is the stone to land on.
Find the minimum possible total cost incurred before the frog reaches Stone N. | [{"input": "4\n 10 30 40 20", "output": "30\n \n\nIf we follow the path 1 \u2192 2 \u2192 4, the total cost incurred would be |10 - 30| +\n|30 - 20| = 30.\n\n* * *"}, {"input": "2\n 10 10", "output": "0\n \n\nIf we follow the path 1 \u2192 2, the total cost incurred would be |10 - 10| = 0.\n\n* * *"}, {"input": "6\n 30 10 60 10 60 50", "output": "40\n \n\nIf we follow the path 1 \u2192 3 \u2192 5 \u2192 6, the total cost incurred would be |30 -\n60| + |60 - 60| + |60 - 50| = 40."}] |
Print the minimum possible total cost incurred.
* * * | s504119190 | Runtime Error | p03160 | Input is given from Standard Input in the following format:
N
h_1 h_2 \ldots h_N | import sys
sys.setrecursionlimit(10**8)
n = int(input())
h = list(map(int,input().split()))
dp = [float("inf")] * n #dpテーブル
#dp[i]メモ化テーブル
def rec(i):#再帰による全探索
if dp[i] != float("inf"):
return dp[i]
if i == 0:
return 0
elif i == 1:
return abs(h[0]-h[1])
else:
return dp[i] = min(rec(i-1)+abs(h[i]-h[i-1]),rec(i-2)+abs(h[i]-h[i-2]))
print(rec(n-1))
| Statement
There are N stones, numbered 1, 2, \ldots, N. For each i (1 \leq i \leq N),
the height of Stone i is h_i.
There is a frog who is initially on Stone 1. He will repeat the following
action some number of times to reach Stone N:
* If the frog is currently on Stone i, jump to Stone i + 1 or Stone i + 2. Here, a cost of |h_i - h_j| is incurred, where j is the stone to land on.
Find the minimum possible total cost incurred before the frog reaches Stone N. | [{"input": "4\n 10 30 40 20", "output": "30\n \n\nIf we follow the path 1 \u2192 2 \u2192 4, the total cost incurred would be |10 - 30| +\n|30 - 20| = 30.\n\n* * *"}, {"input": "2\n 10 10", "output": "0\n \n\nIf we follow the path 1 \u2192 2, the total cost incurred would be |10 - 10| = 0.\n\n* * *"}, {"input": "6\n 30 10 60 10 60 50", "output": "40\n \n\nIf we follow the path 1 \u2192 3 \u2192 5 \u2192 6, the total cost incurred would be |30 -\n60| + |60 - 60| + |60 - 50| = 40."}] |
Print the minimum possible total cost incurred.
* * * | s541073564 | Runtime Error | p03160 | Input is given from Standard Input in the following format:
N
h_1 h_2 \ldots h_N | def solve(N, W, weight_values):
dp = [0 for _ in range(W + 1)]
for i in range(N):
wi, vi = weight_values[i]
for w in range(W, wi - 1, -1): # loop from W down to wi
temp = dp[w - wi] + vi
if temp > dp[w]:
dp[w] = temp
print(dp[W])
def iln(): return list(map(int, input().split()))
N, W = iln()
w_v = []
for i in range(N):
w_v.append(iln())
solve(N, W, w_v) | Statement
There are N stones, numbered 1, 2, \ldots, N. For each i (1 \leq i \leq N),
the height of Stone i is h_i.
There is a frog who is initially on Stone 1. He will repeat the following
action some number of times to reach Stone N:
* If the frog is currently on Stone i, jump to Stone i + 1 or Stone i + 2. Here, a cost of |h_i - h_j| is incurred, where j is the stone to land on.
Find the minimum possible total cost incurred before the frog reaches Stone N. | [{"input": "4\n 10 30 40 20", "output": "30\n \n\nIf we follow the path 1 \u2192 2 \u2192 4, the total cost incurred would be |10 - 30| +\n|30 - 20| = 30.\n\n* * *"}, {"input": "2\n 10 10", "output": "0\n \n\nIf we follow the path 1 \u2192 2, the total cost incurred would be |10 - 10| = 0.\n\n* * *"}, {"input": "6\n 30 10 60 10 60 50", "output": "40\n \n\nIf we follow the path 1 \u2192 3 \u2192 5 \u2192 6, the total cost incurred would be |30 -\n60| + |60 - 60| + |60 - 50| = 40."}] |
Print the minimum possible total cost incurred.
* * * | s330655244 | Runtime Error | p03160 | Input is given from Standard Input in the following format:
N
h_1 h_2 \ldots h_N | def A(w, v, n,V):
mem=[0 for i in range(V+1)]
if n == 0 or V == 0:
return 0
for i in range(n):
for j in range(V,w[i]-1,-1):
m=v[i]+ mem[j - w[i]]
if m>mem[j]:
mem[j]=m
return mem[V]
n,V=input().split()
n,V=int(n),int(V)
w=[0]*n
v=[0]*n
for i in range(n):
x,y=input().split()
w[i],v[i]=int(x),int(y)
print(A(w,v,n,V)) | Statement
There are N stones, numbered 1, 2, \ldots, N. For each i (1 \leq i \leq N),
the height of Stone i is h_i.
There is a frog who is initially on Stone 1. He will repeat the following
action some number of times to reach Stone N:
* If the frog is currently on Stone i, jump to Stone i + 1 or Stone i + 2. Here, a cost of |h_i - h_j| is incurred, where j is the stone to land on.
Find the minimum possible total cost incurred before the frog reaches Stone N. | [{"input": "4\n 10 30 40 20", "output": "30\n \n\nIf we follow the path 1 \u2192 2 \u2192 4, the total cost incurred would be |10 - 30| +\n|30 - 20| = 30.\n\n* * *"}, {"input": "2\n 10 10", "output": "0\n \n\nIf we follow the path 1 \u2192 2, the total cost incurred would be |10 - 10| = 0.\n\n* * *"}, {"input": "6\n 30 10 60 10 60 50", "output": "40\n \n\nIf we follow the path 1 \u2192 3 \u2192 5 \u2192 6, the total cost incurred would be |30 -\n60| + |60 - 60| + |60 - 50| = 40."}] |
Print the minimum possible total cost incurred.
* * * | s685309858 | Runtime Error | p03160 | Input is given from Standard Input in the following format:
N
h_1 h_2 \ldots h_N | N = int(input())
arr = [int(num) for num in input().split()]
print(get_cost(arr, N-1))
def get_cost(arr, n):
if n == 1:
return abs(arr[1] - arr[0])
elif n == 0:
return 0
else:
return min(
abs(arr[n] - arr[n-1]) + get_cost(arr, n-1),
abs(arr[n] - arr[n-2] + get_cost(arr, n-2)
) | Statement
There are N stones, numbered 1, 2, \ldots, N. For each i (1 \leq i \leq N),
the height of Stone i is h_i.
There is a frog who is initially on Stone 1. He will repeat the following
action some number of times to reach Stone N:
* If the frog is currently on Stone i, jump to Stone i + 1 or Stone i + 2. Here, a cost of |h_i - h_j| is incurred, where j is the stone to land on.
Find the minimum possible total cost incurred before the frog reaches Stone N. | [{"input": "4\n 10 30 40 20", "output": "30\n \n\nIf we follow the path 1 \u2192 2 \u2192 4, the total cost incurred would be |10 - 30| +\n|30 - 20| = 30.\n\n* * *"}, {"input": "2\n 10 10", "output": "0\n \n\nIf we follow the path 1 \u2192 2, the total cost incurred would be |10 - 10| = 0.\n\n* * *"}, {"input": "6\n 30 10 60 10 60 50", "output": "40\n \n\nIf we follow the path 1 \u2192 3 \u2192 5 \u2192 6, the total cost incurred would be |30 -\n60| + |60 - 60| + |60 - 50| = 40."}] |
Print the minimum possible total cost incurred.
* * * | s787355332 | Runtime Error | p03160 | Input is given from Standard Input in the following format:
N
h_1 h_2 \ldots h_N | def cal_min_cost(cnt):
return min([
abs(hight_list[i] - hight_list[i-diff]) + cost_list[i-diff])
for diff in range(1,3)
])
hight_list = []
cost_list = [0,0]
N = int(input())
hight_list = list(map(int, input().split()))
hight_list.insert(0,self.hight_list[0])
for i in range(2, N+1):
cost_list.append(cal_min_cost(i))
print(cost_list[-1])
| Statement
There are N stones, numbered 1, 2, \ldots, N. For each i (1 \leq i \leq N),
the height of Stone i is h_i.
There is a frog who is initially on Stone 1. He will repeat the following
action some number of times to reach Stone N:
* If the frog is currently on Stone i, jump to Stone i + 1 or Stone i + 2. Here, a cost of |h_i - h_j| is incurred, where j is the stone to land on.
Find the minimum possible total cost incurred before the frog reaches Stone N. | [{"input": "4\n 10 30 40 20", "output": "30\n \n\nIf we follow the path 1 \u2192 2 \u2192 4, the total cost incurred would be |10 - 30| +\n|30 - 20| = 30.\n\n* * *"}, {"input": "2\n 10 10", "output": "0\n \n\nIf we follow the path 1 \u2192 2, the total cost incurred would be |10 - 10| = 0.\n\n* * *"}, {"input": "6\n 30 10 60 10 60 50", "output": "40\n \n\nIf we follow the path 1 \u2192 3 \u2192 5 \u2192 6, the total cost incurred would be |30 -\n60| + |60 - 60| + |60 - 50| = 40."}] |
Print the minimum possible total cost incurred.
* * * | s355295368 | Accepted | p03160 | Input is given from Standard Input in the following format:
N
h_1 h_2 \ldots h_N | times = int(input())
line = input()
list1 = []
if times <= 1:
print("%s" % 0)
else:
for i in line.split():
if i:
list1.append(int(i))
mem = [0] * times
mem[-2] = abs(list1[-1] - list1[-2])
for i in range(len(list1) - 3, -1, -1):
step1 = abs(list1[i] - list1[i + 1]) + mem[i + 1]
step2 = abs(list1[i] - list1[i + 2]) + mem[i + 2]
mem[i] = min(step1, step2)
print("%s" % mem[0])
| Statement
There are N stones, numbered 1, 2, \ldots, N. For each i (1 \leq i \leq N),
the height of Stone i is h_i.
There is a frog who is initially on Stone 1. He will repeat the following
action some number of times to reach Stone N:
* If the frog is currently on Stone i, jump to Stone i + 1 or Stone i + 2. Here, a cost of |h_i - h_j| is incurred, where j is the stone to land on.
Find the minimum possible total cost incurred before the frog reaches Stone N. | [{"input": "4\n 10 30 40 20", "output": "30\n \n\nIf we follow the path 1 \u2192 2 \u2192 4, the total cost incurred would be |10 - 30| +\n|30 - 20| = 30.\n\n* * *"}, {"input": "2\n 10 10", "output": "0\n \n\nIf we follow the path 1 \u2192 2, the total cost incurred would be |10 - 10| = 0.\n\n* * *"}, {"input": "6\n 30 10 60 10 60 50", "output": "40\n \n\nIf we follow the path 1 \u2192 3 \u2192 5 \u2192 6, the total cost incurred would be |30 -\n60| + |60 - 60| + |60 - 50| = 40."}] |
Print the minimum possible total cost incurred.
* * * | s656143379 | Runtime Error | p03160 | Input is given from Standard Input in the following format:
N
h_1 h_2 \ldots h_N | N = int(input())
*h, = map(int, input().split())
dp = [float("inf") for _ in range(N)]
dp[0] = 0
for i in range(N - 1):
dp[i + 1] = min(dp[i + 1], dp[i] + abs(h[i + 1] - h[i]))
if i < N - 2:
dp[i + 2] = min(dp[i + 2], dp[i] + abs(h[i + 2] - h[i]))
print(dp[N - 1])
B – Frog 2 | Statement
There are N stones, numbered 1, 2, \ldots, N. For each i (1 \leq i \leq N),
the height of Stone i is h_i.
There is a frog who is initially on Stone 1. He will repeat the following
action some number of times to reach Stone N:
* If the frog is currently on Stone i, jump to Stone i + 1 or Stone i + 2. Here, a cost of |h_i - h_j| is incurred, where j is the stone to land on.
Find the minimum possible total cost incurred before the frog reaches Stone N. | [{"input": "4\n 10 30 40 20", "output": "30\n \n\nIf we follow the path 1 \u2192 2 \u2192 4, the total cost incurred would be |10 - 30| +\n|30 - 20| = 30.\n\n* * *"}, {"input": "2\n 10 10", "output": "0\n \n\nIf we follow the path 1 \u2192 2, the total cost incurred would be |10 - 10| = 0.\n\n* * *"}, {"input": "6\n 30 10 60 10 60 50", "output": "40\n \n\nIf we follow the path 1 \u2192 3 \u2192 5 \u2192 6, the total cost incurred would be |30 -\n60| + |60 - 60| + |60 - 50| = 40."}] |
Print the minimum possible total cost incurred.
* * * | s367209625 | Runtime Error | p03160 | Input is given from Standard Input in the following format:
N
h_1 h_2 \ldots h_N | N, W = list(map(int, input().split(" ")))
for i in range(0, N):
for w in range(1, W+1):
weight, vvalue = list(map(int, input().split(" ")))
if w >= weight:
dp[i + 1][w] = max([dp[i][w - weight] + value, dp[i][w]])
else:
dp[i + 1][w] = dp[i][w]
print(dp[N][W])
| Statement
There are N stones, numbered 1, 2, \ldots, N. For each i (1 \leq i \leq N),
the height of Stone i is h_i.
There is a frog who is initially on Stone 1. He will repeat the following
action some number of times to reach Stone N:
* If the frog is currently on Stone i, jump to Stone i + 1 or Stone i + 2. Here, a cost of |h_i - h_j| is incurred, where j is the stone to land on.
Find the minimum possible total cost incurred before the frog reaches Stone N. | [{"input": "4\n 10 30 40 20", "output": "30\n \n\nIf we follow the path 1 \u2192 2 \u2192 4, the total cost incurred would be |10 - 30| +\n|30 - 20| = 30.\n\n* * *"}, {"input": "2\n 10 10", "output": "0\n \n\nIf we follow the path 1 \u2192 2, the total cost incurred would be |10 - 10| = 0.\n\n* * *"}, {"input": "6\n 30 10 60 10 60 50", "output": "40\n \n\nIf we follow the path 1 \u2192 3 \u2192 5 \u2192 6, the total cost incurred would be |30 -\n60| + |60 - 60| + |60 - 50| = 40."}] |
Print the minimum possible total cost incurred.
* * * | s096267694 | Accepted | p03160 | Input is given from Standard Input in the following format:
N
h_1 h_2 \ldots h_N | #!/usr/bin/env python3
from collections import defaultdict
from heapq import heappush, heappop
import sys
sys.setrecursionlimit(10**6)
input = sys.stdin.buffer.readline
INF = 10**9 + 1 # sys.maxsize # float("inf")
def debug(*x):
print(*x)
def solve1(N, heights):
heights += [INF]
costs = [INF] * (N + 1)
costs[0] = 0
for i in range(N - 1):
costs[i + 1] = min(costs[i + 1], costs[i] + abs(heights[i + 1] - heights[i]))
costs[i + 2] = min(costs[i + 2], costs[i] + abs(heights[i + 2] - heights[i]))
return costs[N - 1]
def solve2(N, heights):
costs = [0] * N
costs[0] = 0
costs[1] = abs(heights[1] - heights[0])
for i in range(2, N):
costs[i] = min(
costs[i - 2] + abs(heights[i] - heights[i - 2]),
costs[i - 1] + abs(heights[i] - heights[i - 1]),
)
return costs[-1]
def solve(N, heights):
costs = [None] * N
costs[0] = 0
costs[1] = abs(heights[1] - heights[0])
def get_cost(i):
if costs[i] != None:
return costs[i]
c = min(
get_cost(i - 2) + abs(heights[i] - heights[i - 2]),
get_cost(i - 1) + abs(heights[i] - heights[i - 1]),
)
costs[i] = c
return c
return get_cost(N - 1)
def main():
N = int(input())
heights = list(map(int, input().split()))
print(solve(N, heights))
def _test():
"""
>>> solve(4, [10, 30, 40, 20])
30
>>> solve(2, [10, 10])
0
>>> solve(6, [30, 10, 60, 10, 60, 50])
40
"""
import doctest
doctest.testmod()
def as_input(s):
"use in test, use given string as input file"
import io
global read, input
f = io.StringIO(s.strip())
input = f.readline
read = f.read
USE_NUMBA = False
if (USE_NUMBA and sys.argv[-1] == "ONLINE_JUDGE") or sys.argv[-1] == "-c":
print("compiling")
from numba.pycc import CC
cc = CC("my_module")
cc.export("solve", solve.__doc__.strip().split()[0])(solve)
cc.compile()
exit()
else:
input = sys.stdin.buffer.readline
read = sys.stdin.buffer.read
if (USE_NUMBA and sys.argv[-1] != "-p") or sys.argv[-1] == "--numba":
# -p: pure python mode
# if not -p, import compiled module
from my_module import solve # pylint: disable=all
elif sys.argv[-1] == "-t":
_test()
sys.exit()
elif sys.argv[-1] != "-p" and len(sys.argv) == 2:
# input given as file
input_as_file = open(sys.argv[1])
input = input_as_file.buffer.readline
read = input_as_file.buffer.read
main()
| Statement
There are N stones, numbered 1, 2, \ldots, N. For each i (1 \leq i \leq N),
the height of Stone i is h_i.
There is a frog who is initially on Stone 1. He will repeat the following
action some number of times to reach Stone N:
* If the frog is currently on Stone i, jump to Stone i + 1 or Stone i + 2. Here, a cost of |h_i - h_j| is incurred, where j is the stone to land on.
Find the minimum possible total cost incurred before the frog reaches Stone N. | [{"input": "4\n 10 30 40 20", "output": "30\n \n\nIf we follow the path 1 \u2192 2 \u2192 4, the total cost incurred would be |10 - 30| +\n|30 - 20| = 30.\n\n* * *"}, {"input": "2\n 10 10", "output": "0\n \n\nIf we follow the path 1 \u2192 2, the total cost incurred would be |10 - 10| = 0.\n\n* * *"}, {"input": "6\n 30 10 60 10 60 50", "output": "40\n \n\nIf we follow the path 1 \u2192 3 \u2192 5 \u2192 6, the total cost incurred would be |30 -\n60| + |60 - 60| + |60 - 50| = 40."}] |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.