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 minimum time required for all of the people to reach City 6, in
minutes.
* * * | s572417887 | Wrong Answer | p03077 | Input is given from Standard Input in the following format:
N
A
B
C
D
E | n, a, b, c, d, e = open(0)
print(-(-int(n) // int(min(a, b, c, d, e))) + 4)
| Statement
In 2028 and after a continuous growth, AtCoder Inc. finally built an empire
with six cities (City 1, 2, 3, 4, 5, 6)!
There are five means of transport in this empire:
* Train: travels from City 1 to 2 in one minute. A train can occupy at most A people.
* Bus: travels from City 2 to 3 in one minute. A bus can occupy at most B people.
* Taxi: travels from City 3 to 4 in one minute. A taxi can occupy at most C people.
* Airplane: travels from City 4 to 5 in one minute. An airplane can occupy at most D people.
* Ship: travels from City 5 to 6 in one minute. A ship can occupy at most E people.
For each of them, one vehicle leaves the city at each integer time (time 0, 1,
2, ...).
There is a group of N people at City 1, and they all want to go to City 6.
At least how long does it take for all of them to reach there? You can ignore
the time needed to transfer. | [{"input": "5\n 3\n 2\n 4\n 3\n 5", "output": "7\n \n\nOne possible way to travel is as follows. First, there are N = 5 people at\nCity 1, as shown in the following image:\n\n![ ](https://img.atcoder.jp/ghi/9c306138eddc8a2e08acfa5da19bdfe8.png)\n\nIn the first minute, three people travels from City 1 to City 2 by train. Note\nthat a train can only occupy at most three people.\n\n![ ](https://img.atcoder.jp/ghi/bd30b5ab37fc06951c9f5256bb974e4f.png)\n\nIn the second minute, the remaining two people travels from City 1 to City 2\nby train, and two of the three people who were already at City 2 travels to\nCity 3 by bus. Note that a bus can only occupy at most two people.\n\n![ ](https://img.atcoder.jp/ghi/50f2e49a770a30193fc53588ec8475b3.png)\n\nIn the third minute, two people travels from City 2 to City 3 by train, and\nanother two people travels from City 3 to City 4 by taxi.\n\n![ ](https://img.atcoder.jp/ghi/d6d80dc50abe58190905c8c5ea6ba345.png)\n\nFrom then on, if they continue traveling without stopping until they reach\nCity 6, all of them can reach there in seven minutes. \nThere is no way for them to reach City 6 in 6 minutes or less.\n\n* * *"}, {"input": "10\n 123\n 123\n 123\n 123\n 123", "output": "5\n \n\nAll kinds of vehicles can occupy N = 10 people at a time. Thus, if they\ncontinue traveling without stopping until they reach City 6, all of them can\nreach there in five minutes.\n\n* * *"}, {"input": "10000000007\n 2\n 3\n 5\n 7\n 11", "output": "5000000008\n \n\nNote that the input or output may not fit into a 32-bit integer type."}] |
Print the minimum time required for all of the people to reach City 6, in
minutes.
* * * | s708760038 | Wrong Answer | p03077 | Input is given from Standard Input in the following format:
N
A
B
C
D
E | n, *city = [int(input()) for _ in range(6)]
print(5 + n // min(city))
| Statement
In 2028 and after a continuous growth, AtCoder Inc. finally built an empire
with six cities (City 1, 2, 3, 4, 5, 6)!
There are five means of transport in this empire:
* Train: travels from City 1 to 2 in one minute. A train can occupy at most A people.
* Bus: travels from City 2 to 3 in one minute. A bus can occupy at most B people.
* Taxi: travels from City 3 to 4 in one minute. A taxi can occupy at most C people.
* Airplane: travels from City 4 to 5 in one minute. An airplane can occupy at most D people.
* Ship: travels from City 5 to 6 in one minute. A ship can occupy at most E people.
For each of them, one vehicle leaves the city at each integer time (time 0, 1,
2, ...).
There is a group of N people at City 1, and they all want to go to City 6.
At least how long does it take for all of them to reach there? You can ignore
the time needed to transfer. | [{"input": "5\n 3\n 2\n 4\n 3\n 5", "output": "7\n \n\nOne possible way to travel is as follows. First, there are N = 5 people at\nCity 1, as shown in the following image:\n\n![ ](https://img.atcoder.jp/ghi/9c306138eddc8a2e08acfa5da19bdfe8.png)\n\nIn the first minute, three people travels from City 1 to City 2 by train. Note\nthat a train can only occupy at most three people.\n\n![ ](https://img.atcoder.jp/ghi/bd30b5ab37fc06951c9f5256bb974e4f.png)\n\nIn the second minute, the remaining two people travels from City 1 to City 2\nby train, and two of the three people who were already at City 2 travels to\nCity 3 by bus. Note that a bus can only occupy at most two people.\n\n![ ](https://img.atcoder.jp/ghi/50f2e49a770a30193fc53588ec8475b3.png)\n\nIn the third minute, two people travels from City 2 to City 3 by train, and\nanother two people travels from City 3 to City 4 by taxi.\n\n![ ](https://img.atcoder.jp/ghi/d6d80dc50abe58190905c8c5ea6ba345.png)\n\nFrom then on, if they continue traveling without stopping until they reach\nCity 6, all of them can reach there in seven minutes. \nThere is no way for them to reach City 6 in 6 minutes or less.\n\n* * *"}, {"input": "10\n 123\n 123\n 123\n 123\n 123", "output": "5\n \n\nAll kinds of vehicles can occupy N = 10 people at a time. Thus, if they\ncontinue traveling without stopping until they reach City 6, all of them can\nreach there in five minutes.\n\n* * *"}, {"input": "10000000007\n 2\n 3\n 5\n 7\n 11", "output": "5000000008\n \n\nNote that the input or output may not fit into a 32-bit integer type."}] |
Print the minimum time required for all of the people to reach City 6, in
minutes.
* * * | s787497468 | Wrong Answer | p03077 | Input is given from Standard Input in the following format:
N
A
B
C
D
E | N = int(input())
ABCDE = [int(input()) for i in range(5)]
mi = min(ABCDE)
for i in range(len(ABCDE)):
if mi == ABCDE[i]:
index = i
break
moved = [0 for i in range(index + 1)]
moved[0] = N
time = 0
while moved[-1] < N:
for i in range(index - 1, -1, -1):
if moved[i] < ABCDE[i]:
moved[i + 1] += moved[i]
moved[i] = 0
else:
moved[i + 1] += ABCDE[i]
moved[i] -= ABCDE[i]
time += 1
ans = N // mi + 5
print(ans)
| Statement
In 2028 and after a continuous growth, AtCoder Inc. finally built an empire
with six cities (City 1, 2, 3, 4, 5, 6)!
There are five means of transport in this empire:
* Train: travels from City 1 to 2 in one minute. A train can occupy at most A people.
* Bus: travels from City 2 to 3 in one minute. A bus can occupy at most B people.
* Taxi: travels from City 3 to 4 in one minute. A taxi can occupy at most C people.
* Airplane: travels from City 4 to 5 in one minute. An airplane can occupy at most D people.
* Ship: travels from City 5 to 6 in one minute. A ship can occupy at most E people.
For each of them, one vehicle leaves the city at each integer time (time 0, 1,
2, ...).
There is a group of N people at City 1, and they all want to go to City 6.
At least how long does it take for all of them to reach there? You can ignore
the time needed to transfer. | [{"input": "5\n 3\n 2\n 4\n 3\n 5", "output": "7\n \n\nOne possible way to travel is as follows. First, there are N = 5 people at\nCity 1, as shown in the following image:\n\n![ ](https://img.atcoder.jp/ghi/9c306138eddc8a2e08acfa5da19bdfe8.png)\n\nIn the first minute, three people travels from City 1 to City 2 by train. Note\nthat a train can only occupy at most three people.\n\n![ ](https://img.atcoder.jp/ghi/bd30b5ab37fc06951c9f5256bb974e4f.png)\n\nIn the second minute, the remaining two people travels from City 1 to City 2\nby train, and two of the three people who were already at City 2 travels to\nCity 3 by bus. Note that a bus can only occupy at most two people.\n\n![ ](https://img.atcoder.jp/ghi/50f2e49a770a30193fc53588ec8475b3.png)\n\nIn the third minute, two people travels from City 2 to City 3 by train, and\nanother two people travels from City 3 to City 4 by taxi.\n\n![ ](https://img.atcoder.jp/ghi/d6d80dc50abe58190905c8c5ea6ba345.png)\n\nFrom then on, if they continue traveling without stopping until they reach\nCity 6, all of them can reach there in seven minutes. \nThere is no way for them to reach City 6 in 6 minutes or less.\n\n* * *"}, {"input": "10\n 123\n 123\n 123\n 123\n 123", "output": "5\n \n\nAll kinds of vehicles can occupy N = 10 people at a time. Thus, if they\ncontinue traveling without stopping until they reach City 6, all of them can\nreach there in five minutes.\n\n* * *"}, {"input": "10000000007\n 2\n 3\n 5\n 7\n 11", "output": "5000000008\n \n\nNote that the input or output may not fit into a 32-bit integer type."}] |
Print the minimum time required for all of the people to reach City 6, in
minutes.
* * * | s935485497 | Accepted | p03077 | Input is given from Standard Input in the following format:
N
A
B
C
D
E | import math
def my_solve2():
"""
最短時間はもっとも移動可能人数が少ない区間に依存する
"""
num = int(input())
transpotations = []
for _ in range(5):
transpotations.append(int(input()))
# print(transpotations, min(transpotations))
# 最も移動可能人数が少ない区間の抽出
bottleneck = min(transpotations)
# 移動時間.切り上げの必要あり
time = math.ceil(num / bottleneck)
time += 4
return time
def my_solve():
"""
未完成
現在の人の分布と1分後の人の分布を分けて考えるために2つの人分布リストが必要
この方法では制限時間内に計算を終了することができない
"""
num = int(input())
# print("num: {}".format(num))
traffic_a = int(input())
traffic_b = int(input())
traffic_c = int(input())
traffic_d = int(input())
traffic_e = int(input())
city_people_num = [num, 0, 0, 0, 0, 0]
time = 0
# TODO: 現在の人の分布と1分後の人の分布を分けて考えるために2つのリストが必要
while city_people_num[5] < num:
# print(city_people_num)
# 1->2
if city_people_num[0] >= traffic_a:
city_people_num[0] -= traffic_a
city_people_num[1] += traffic_a
else:
city_people_num[1] += city_people_num[0]
city_people_num[0] = 0
# print(city_people_num)
time += 1
# 2->3
if city_people_num[1] >= traffic_b:
city_people_num[1] -= traffic_b
city_people_num[2] += traffic_b
else:
city_people_num[2] += city_people_num[1]
city_people_num[1] = 0
# print(city_people_num)
time += 1
# 3->4
if city_people_num[2] >= traffic_c:
city_people_num[2] -= traffic_c
city_people_num[3] += traffic_c
else:
city_people_num[3] += city_people_num[2]
city_people_num[2] = 0
time += 1
# 4->5
if city_people_num[3] >= traffic_d:
city_people_num[3] -= traffic_d
city_people_num[4] += traffic_d
else:
city_people_num[4] += city_people_num[3]
city_people_num[3] = 0
time += 1
# 5->6
if city_people_num[4] >= traffic_e:
city_people_num[4] -= traffic_e
city_people_num[5] += traffic_e
else:
city_people_num[5] += city_people_num[4]
city_people_num[4] = 0
time += 1
# print("time {}".format(time))
# print(city_people_num)
return time
print(my_solve2())
| Statement
In 2028 and after a continuous growth, AtCoder Inc. finally built an empire
with six cities (City 1, 2, 3, 4, 5, 6)!
There are five means of transport in this empire:
* Train: travels from City 1 to 2 in one minute. A train can occupy at most A people.
* Bus: travels from City 2 to 3 in one minute. A bus can occupy at most B people.
* Taxi: travels from City 3 to 4 in one minute. A taxi can occupy at most C people.
* Airplane: travels from City 4 to 5 in one minute. An airplane can occupy at most D people.
* Ship: travels from City 5 to 6 in one minute. A ship can occupy at most E people.
For each of them, one vehicle leaves the city at each integer time (time 0, 1,
2, ...).
There is a group of N people at City 1, and they all want to go to City 6.
At least how long does it take for all of them to reach there? You can ignore
the time needed to transfer. | [{"input": "5\n 3\n 2\n 4\n 3\n 5", "output": "7\n \n\nOne possible way to travel is as follows. First, there are N = 5 people at\nCity 1, as shown in the following image:\n\n![ ](https://img.atcoder.jp/ghi/9c306138eddc8a2e08acfa5da19bdfe8.png)\n\nIn the first minute, three people travels from City 1 to City 2 by train. Note\nthat a train can only occupy at most three people.\n\n![ ](https://img.atcoder.jp/ghi/bd30b5ab37fc06951c9f5256bb974e4f.png)\n\nIn the second minute, the remaining two people travels from City 1 to City 2\nby train, and two of the three people who were already at City 2 travels to\nCity 3 by bus. Note that a bus can only occupy at most two people.\n\n![ ](https://img.atcoder.jp/ghi/50f2e49a770a30193fc53588ec8475b3.png)\n\nIn the third minute, two people travels from City 2 to City 3 by train, and\nanother two people travels from City 3 to City 4 by taxi.\n\n![ ](https://img.atcoder.jp/ghi/d6d80dc50abe58190905c8c5ea6ba345.png)\n\nFrom then on, if they continue traveling without stopping until they reach\nCity 6, all of them can reach there in seven minutes. \nThere is no way for them to reach City 6 in 6 minutes or less.\n\n* * *"}, {"input": "10\n 123\n 123\n 123\n 123\n 123", "output": "5\n \n\nAll kinds of vehicles can occupy N = 10 people at a time. Thus, if they\ncontinue traveling without stopping until they reach City 6, all of them can\nreach there in five minutes.\n\n* * *"}, {"input": "10000000007\n 2\n 3\n 5\n 7\n 11", "output": "5000000008\n \n\nNote that the input or output may not fit into a 32-bit integer type."}] |
Print the minimum time required for all of the people to reach City 6, in
minutes.
* * * | s196498220 | Runtime Error | p03077 | Input is given from Standard Input in the following format:
N
A
B
C
D
E | N = int(input())
A = [0, 0, 0, 0, 0]
A[0] = int(input())
A[1] = int(input())
A[2] = int(input())
A[3] = int(input())
A[4] = int(input())
class person:
def __init__(self):
# 現在の居場所
self.now = 1
# 最後の都市まできたかどうか
self.end = False
# 乗り物に乗っているかどうか
self.ride = False
def ridee(self, Info):
if self.end == False and self.ride == False:
if self.now == 1 and Info.train_now < Info.train_max:
self.ride = True
Info.train_now = Info.train_now + 1
elif self.now == 2 and Info.buss_now < Info.buss_max:
self.ride = True
Info.buss_now = Info.buss_now + 1
Info.train_now = Info.train_now - 1
elif self.now == 3 and Info.taxi_now < Info.taxi_max:
self.ride = True
Info.taxi_now = Info.taxi_now + 1
Info.buss_now = Info.buss_now - 1
elif self.now == 4 and Info.airplane_now < Info.airplane_max:
self.ride = True
Info.airplane_now = Info.airplane_now + 1
Info.taxi_now = Info.taxi_now - 1
elif self.now == 5 and Info.ship_now < Info.ship_max:
self.ride = True
Info.ship_now = Info.ship_now + 1
Info.airplane_now = Info.airplane_now - 1
class info:
def __init__(self, N):
self.train_max = A[0]
self.buss_max = A[1]
self.taxi_max = A[2]
self.airplane_max = A[3]
self.ship_max = A[4]
self.train_now = 0
self.buss_now = 0
self.taxi_now = 0
self.airplane_now = 0
self.ship_now = 0
self.people = []
self.people = [person()] * N
def ride(self, N):
for i in range(N):
self.people[i].ridee(self)
def end_check(self):
if self.people[N - 1].end == True:
return 1
return 0
def update(self):
for i in range(N):
if self.people[i].ride == True:
self.people[i].now = self.people[i].now + 1
self.people[i].ride = False
if self.people[i].now == 6:
self.ship_now = self.ship_now - 1
self.people[i].end = True
# infoインスタンスを生成する
INFO = info(N)
time = 0
while True:
INFO.ride(N)
INFO.update()
time = time + 1
if INFO.end_check() == 1:
break
print(time)
| Statement
In 2028 and after a continuous growth, AtCoder Inc. finally built an empire
with six cities (City 1, 2, 3, 4, 5, 6)!
There are five means of transport in this empire:
* Train: travels from City 1 to 2 in one minute. A train can occupy at most A people.
* Bus: travels from City 2 to 3 in one minute. A bus can occupy at most B people.
* Taxi: travels from City 3 to 4 in one minute. A taxi can occupy at most C people.
* Airplane: travels from City 4 to 5 in one minute. An airplane can occupy at most D people.
* Ship: travels from City 5 to 6 in one minute. A ship can occupy at most E people.
For each of them, one vehicle leaves the city at each integer time (time 0, 1,
2, ...).
There is a group of N people at City 1, and they all want to go to City 6.
At least how long does it take for all of them to reach there? You can ignore
the time needed to transfer. | [{"input": "5\n 3\n 2\n 4\n 3\n 5", "output": "7\n \n\nOne possible way to travel is as follows. First, there are N = 5 people at\nCity 1, as shown in the following image:\n\n![ ](https://img.atcoder.jp/ghi/9c306138eddc8a2e08acfa5da19bdfe8.png)\n\nIn the first minute, three people travels from City 1 to City 2 by train. Note\nthat a train can only occupy at most three people.\n\n![ ](https://img.atcoder.jp/ghi/bd30b5ab37fc06951c9f5256bb974e4f.png)\n\nIn the second minute, the remaining two people travels from City 1 to City 2\nby train, and two of the three people who were already at City 2 travels to\nCity 3 by bus. Note that a bus can only occupy at most two people.\n\n![ ](https://img.atcoder.jp/ghi/50f2e49a770a30193fc53588ec8475b3.png)\n\nIn the third minute, two people travels from City 2 to City 3 by train, and\nanother two people travels from City 3 to City 4 by taxi.\n\n![ ](https://img.atcoder.jp/ghi/d6d80dc50abe58190905c8c5ea6ba345.png)\n\nFrom then on, if they continue traveling without stopping until they reach\nCity 6, all of them can reach there in seven minutes. \nThere is no way for them to reach City 6 in 6 minutes or less.\n\n* * *"}, {"input": "10\n 123\n 123\n 123\n 123\n 123", "output": "5\n \n\nAll kinds of vehicles can occupy N = 10 people at a time. Thus, if they\ncontinue traveling without stopping until they reach City 6, all of them can\nreach there in five minutes.\n\n* * *"}, {"input": "10000000007\n 2\n 3\n 5\n 7\n 11", "output": "5000000008\n \n\nNote that the input or output may not fit into a 32-bit integer type."}] |
Print the minimum time required for all of the people to reach City 6, in
minutes.
* * * | s534257894 | Runtime Error | p03077 | Input is given from Standard Input in the following format:
N
A
B
C
D
E | inf = input().split()
X = int(inf[0])
Y = int(inf[1])
Z = int(inf[2])
K = int(inf[3])
A = [int(i) for i in input().split()]
B = [int(i) for i in input().split()]
C = [int(i) for i in input().split()]
ab = []
for a in A:
for b in B:
ab += [a + b]
ab.sort(reverse=True)
C.sort(reverse=True)
state = [ab[0] + i for i in C]
count = 0
while count < K:
x = max(state)
print(x)
count += 1
i = state.index(x)
j = ab.index(x - C[i])
if j < X * Y - 1:
state[i] = ab[j + 1] + C[i]
else:
state[i] = -1
| Statement
In 2028 and after a continuous growth, AtCoder Inc. finally built an empire
with six cities (City 1, 2, 3, 4, 5, 6)!
There are five means of transport in this empire:
* Train: travels from City 1 to 2 in one minute. A train can occupy at most A people.
* Bus: travels from City 2 to 3 in one minute. A bus can occupy at most B people.
* Taxi: travels from City 3 to 4 in one minute. A taxi can occupy at most C people.
* Airplane: travels from City 4 to 5 in one minute. An airplane can occupy at most D people.
* Ship: travels from City 5 to 6 in one minute. A ship can occupy at most E people.
For each of them, one vehicle leaves the city at each integer time (time 0, 1,
2, ...).
There is a group of N people at City 1, and they all want to go to City 6.
At least how long does it take for all of them to reach there? You can ignore
the time needed to transfer. | [{"input": "5\n 3\n 2\n 4\n 3\n 5", "output": "7\n \n\nOne possible way to travel is as follows. First, there are N = 5 people at\nCity 1, as shown in the following image:\n\n![ ](https://img.atcoder.jp/ghi/9c306138eddc8a2e08acfa5da19bdfe8.png)\n\nIn the first minute, three people travels from City 1 to City 2 by train. Note\nthat a train can only occupy at most three people.\n\n![ ](https://img.atcoder.jp/ghi/bd30b5ab37fc06951c9f5256bb974e4f.png)\n\nIn the second minute, the remaining two people travels from City 1 to City 2\nby train, and two of the three people who were already at City 2 travels to\nCity 3 by bus. Note that a bus can only occupy at most two people.\n\n![ ](https://img.atcoder.jp/ghi/50f2e49a770a30193fc53588ec8475b3.png)\n\nIn the third minute, two people travels from City 2 to City 3 by train, and\nanother two people travels from City 3 to City 4 by taxi.\n\n![ ](https://img.atcoder.jp/ghi/d6d80dc50abe58190905c8c5ea6ba345.png)\n\nFrom then on, if they continue traveling without stopping until they reach\nCity 6, all of them can reach there in seven minutes. \nThere is no way for them to reach City 6 in 6 minutes or less.\n\n* * *"}, {"input": "10\n 123\n 123\n 123\n 123\n 123", "output": "5\n \n\nAll kinds of vehicles can occupy N = 10 people at a time. Thus, if they\ncontinue traveling without stopping until they reach City 6, all of them can\nreach there in five minutes.\n\n* * *"}, {"input": "10000000007\n 2\n 3\n 5\n 7\n 11", "output": "5000000008\n \n\nNote that the input or output may not fit into a 32-bit integer type."}] |
Print the minimum time required for all of the people to reach City 6, in
minutes.
* * * | s065496223 | Wrong Answer | p03077 | Input is given from Standard Input in the following format:
N
A
B
C
D
E | N = int(input())
former_capacity = 0
ans = 0
areas = [0] * 6
areas[0] = N
capacity_list = []
for i in range(5):
capacity_list.append(int(input()))
for i, capacity in enumerate(capacity_list):
n = areas[i]
if former_capacity == 0:
diff = int(n / capacity) + 1
elif capacity < former_capacity:
diff = int(n / capacity) - int(n / former_capacity) + 1
else:
diff = 1
ans += diff
former_cap = 0
trans = 0
for idx, orig_cap in enumerate(capacity_list):
area = areas[idx]
if former_cap != 0:
cap = min(orig_cap, former_cap)
area = min(capacity_list[idx - 1] * (diff - 1), trans)
else:
cap = orig_cap
trans = min(cap * diff, area)
former_cap = orig_cap
areas[idx] -= trans
areas[idx + 1] += trans
former_capacity = capacity
print(ans)
| Statement
In 2028 and after a continuous growth, AtCoder Inc. finally built an empire
with six cities (City 1, 2, 3, 4, 5, 6)!
There are five means of transport in this empire:
* Train: travels from City 1 to 2 in one minute. A train can occupy at most A people.
* Bus: travels from City 2 to 3 in one minute. A bus can occupy at most B people.
* Taxi: travels from City 3 to 4 in one minute. A taxi can occupy at most C people.
* Airplane: travels from City 4 to 5 in one minute. An airplane can occupy at most D people.
* Ship: travels from City 5 to 6 in one minute. A ship can occupy at most E people.
For each of them, one vehicle leaves the city at each integer time (time 0, 1,
2, ...).
There is a group of N people at City 1, and they all want to go to City 6.
At least how long does it take for all of them to reach there? You can ignore
the time needed to transfer. | [{"input": "5\n 3\n 2\n 4\n 3\n 5", "output": "7\n \n\nOne possible way to travel is as follows. First, there are N = 5 people at\nCity 1, as shown in the following image:\n\n![ ](https://img.atcoder.jp/ghi/9c306138eddc8a2e08acfa5da19bdfe8.png)\n\nIn the first minute, three people travels from City 1 to City 2 by train. Note\nthat a train can only occupy at most three people.\n\n![ ](https://img.atcoder.jp/ghi/bd30b5ab37fc06951c9f5256bb974e4f.png)\n\nIn the second minute, the remaining two people travels from City 1 to City 2\nby train, and two of the three people who were already at City 2 travels to\nCity 3 by bus. Note that a bus can only occupy at most two people.\n\n![ ](https://img.atcoder.jp/ghi/50f2e49a770a30193fc53588ec8475b3.png)\n\nIn the third minute, two people travels from City 2 to City 3 by train, and\nanother two people travels from City 3 to City 4 by taxi.\n\n![ ](https://img.atcoder.jp/ghi/d6d80dc50abe58190905c8c5ea6ba345.png)\n\nFrom then on, if they continue traveling without stopping until they reach\nCity 6, all of them can reach there in seven minutes. \nThere is no way for them to reach City 6 in 6 minutes or less.\n\n* * *"}, {"input": "10\n 123\n 123\n 123\n 123\n 123", "output": "5\n \n\nAll kinds of vehicles can occupy N = 10 people at a time. Thus, if they\ncontinue traveling without stopping until they reach City 6, all of them can\nreach there in five minutes.\n\n* * *"}, {"input": "10000000007\n 2\n 3\n 5\n 7\n 11", "output": "5000000008\n \n\nNote that the input or output may not fit into a 32-bit integer type."}] |
Print the minimum time required for all of the people to reach City 6, in
minutes.
* * * | s045259293 | Runtime Error | p03077 | Input is given from Standard Input in the following format:
N
A
B
C
D
E | import heapq
X, Y, Z, K = map(int, input().split())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
C = list(map(int, input().split()))
asort, bsort, csort = (
sorted(A, reverse=True),
sorted(B, reverse=True),
sorted(C, reverse=True),
)
already = set((0, 0, 0))
print(asort[0] + bsort[0] + csort[0])
x, y, z = 0, 0, 0
check = []
for k in range(K - 1):
if (x + 1, y, z) not in already and x + 1 < X:
already.add((x + 1, y, z))
heapq.heappush(check, (-(asort[x + 1] + bsort[y] + csort[z]), x + 1, y, z))
if (x, y + 1, z) not in already and y + 1 < Y:
already.add((x, y + 1, z))
heapq.heappush(check, (-(asort[x] + bsort[y + 1] + csort[z]), x, y + 1, z))
if (x, y, z + 1) not in already and z + 1 < Z:
already.add((x, y, z + 1))
heapq.heappush(check, (-(asort[x] + bsort[y] + csort[z + 1]), x, y, z + 1))
maxsum = heapq.heappop(check)
print(-maxsum[0])
x, y, z = maxsum[1], maxsum[2], maxsum[3]
| Statement
In 2028 and after a continuous growth, AtCoder Inc. finally built an empire
with six cities (City 1, 2, 3, 4, 5, 6)!
There are five means of transport in this empire:
* Train: travels from City 1 to 2 in one minute. A train can occupy at most A people.
* Bus: travels from City 2 to 3 in one minute. A bus can occupy at most B people.
* Taxi: travels from City 3 to 4 in one minute. A taxi can occupy at most C people.
* Airplane: travels from City 4 to 5 in one minute. An airplane can occupy at most D people.
* Ship: travels from City 5 to 6 in one minute. A ship can occupy at most E people.
For each of them, one vehicle leaves the city at each integer time (time 0, 1,
2, ...).
There is a group of N people at City 1, and they all want to go to City 6.
At least how long does it take for all of them to reach there? You can ignore
the time needed to transfer. | [{"input": "5\n 3\n 2\n 4\n 3\n 5", "output": "7\n \n\nOne possible way to travel is as follows. First, there are N = 5 people at\nCity 1, as shown in the following image:\n\n![ ](https://img.atcoder.jp/ghi/9c306138eddc8a2e08acfa5da19bdfe8.png)\n\nIn the first minute, three people travels from City 1 to City 2 by train. Note\nthat a train can only occupy at most three people.\n\n![ ](https://img.atcoder.jp/ghi/bd30b5ab37fc06951c9f5256bb974e4f.png)\n\nIn the second minute, the remaining two people travels from City 1 to City 2\nby train, and two of the three people who were already at City 2 travels to\nCity 3 by bus. Note that a bus can only occupy at most two people.\n\n![ ](https://img.atcoder.jp/ghi/50f2e49a770a30193fc53588ec8475b3.png)\n\nIn the third minute, two people travels from City 2 to City 3 by train, and\nanother two people travels from City 3 to City 4 by taxi.\n\n![ ](https://img.atcoder.jp/ghi/d6d80dc50abe58190905c8c5ea6ba345.png)\n\nFrom then on, if they continue traveling without stopping until they reach\nCity 6, all of them can reach there in seven minutes. \nThere is no way for them to reach City 6 in 6 minutes or less.\n\n* * *"}, {"input": "10\n 123\n 123\n 123\n 123\n 123", "output": "5\n \n\nAll kinds of vehicles can occupy N = 10 people at a time. Thus, if they\ncontinue traveling without stopping until they reach City 6, all of them can\nreach there in five minutes.\n\n* * *"}, {"input": "10000000007\n 2\n 3\n 5\n 7\n 11", "output": "5000000008\n \n\nNote that the input or output may not fit into a 32-bit integer type."}] |
Print the minimum time required for all of the people to reach City 6, in
minutes.
* * * | s251914097 | Accepted | p03077 | Input is given from Standard Input in the following format:
N
A
B
C
D
E | h = int(input())
l = min([int(input()) for i in range(5)])
print(4 - (-h // l))
| Statement
In 2028 and after a continuous growth, AtCoder Inc. finally built an empire
with six cities (City 1, 2, 3, 4, 5, 6)!
There are five means of transport in this empire:
* Train: travels from City 1 to 2 in one minute. A train can occupy at most A people.
* Bus: travels from City 2 to 3 in one minute. A bus can occupy at most B people.
* Taxi: travels from City 3 to 4 in one minute. A taxi can occupy at most C people.
* Airplane: travels from City 4 to 5 in one minute. An airplane can occupy at most D people.
* Ship: travels from City 5 to 6 in one minute. A ship can occupy at most E people.
For each of them, one vehicle leaves the city at each integer time (time 0, 1,
2, ...).
There is a group of N people at City 1, and they all want to go to City 6.
At least how long does it take for all of them to reach there? You can ignore
the time needed to transfer. | [{"input": "5\n 3\n 2\n 4\n 3\n 5", "output": "7\n \n\nOne possible way to travel is as follows. First, there are N = 5 people at\nCity 1, as shown in the following image:\n\n![ ](https://img.atcoder.jp/ghi/9c306138eddc8a2e08acfa5da19bdfe8.png)\n\nIn the first minute, three people travels from City 1 to City 2 by train. Note\nthat a train can only occupy at most three people.\n\n![ ](https://img.atcoder.jp/ghi/bd30b5ab37fc06951c9f5256bb974e4f.png)\n\nIn the second minute, the remaining two people travels from City 1 to City 2\nby train, and two of the three people who were already at City 2 travels to\nCity 3 by bus. Note that a bus can only occupy at most two people.\n\n![ ](https://img.atcoder.jp/ghi/50f2e49a770a30193fc53588ec8475b3.png)\n\nIn the third minute, two people travels from City 2 to City 3 by train, and\nanother two people travels from City 3 to City 4 by taxi.\n\n![ ](https://img.atcoder.jp/ghi/d6d80dc50abe58190905c8c5ea6ba345.png)\n\nFrom then on, if they continue traveling without stopping until they reach\nCity 6, all of them can reach there in seven minutes. \nThere is no way for them to reach City 6 in 6 minutes or less.\n\n* * *"}, {"input": "10\n 123\n 123\n 123\n 123\n 123", "output": "5\n \n\nAll kinds of vehicles can occupy N = 10 people at a time. Thus, if they\ncontinue traveling without stopping until they reach City 6, all of them can\nreach there in five minutes.\n\n* * *"}, {"input": "10000000007\n 2\n 3\n 5\n 7\n 11", "output": "5000000008\n \n\nNote that the input or output may not fit into a 32-bit integer type."}] |
Print the minimum time required for all of the people to reach City 6, in
minutes.
* * * | s106192826 | Wrong Answer | p03077 | Input is given from Standard Input in the following format:
N
A
B
C
D
E | print(5 + int(input()) // min([int(input()) for _ in range(5)]))
| Statement
In 2028 and after a continuous growth, AtCoder Inc. finally built an empire
with six cities (City 1, 2, 3, 4, 5, 6)!
There are five means of transport in this empire:
* Train: travels from City 1 to 2 in one minute. A train can occupy at most A people.
* Bus: travels from City 2 to 3 in one minute. A bus can occupy at most B people.
* Taxi: travels from City 3 to 4 in one minute. A taxi can occupy at most C people.
* Airplane: travels from City 4 to 5 in one minute. An airplane can occupy at most D people.
* Ship: travels from City 5 to 6 in one minute. A ship can occupy at most E people.
For each of them, one vehicle leaves the city at each integer time (time 0, 1,
2, ...).
There is a group of N people at City 1, and they all want to go to City 6.
At least how long does it take for all of them to reach there? You can ignore
the time needed to transfer. | [{"input": "5\n 3\n 2\n 4\n 3\n 5", "output": "7\n \n\nOne possible way to travel is as follows. First, there are N = 5 people at\nCity 1, as shown in the following image:\n\n![ ](https://img.atcoder.jp/ghi/9c306138eddc8a2e08acfa5da19bdfe8.png)\n\nIn the first minute, three people travels from City 1 to City 2 by train. Note\nthat a train can only occupy at most three people.\n\n![ ](https://img.atcoder.jp/ghi/bd30b5ab37fc06951c9f5256bb974e4f.png)\n\nIn the second minute, the remaining two people travels from City 1 to City 2\nby train, and two of the three people who were already at City 2 travels to\nCity 3 by bus. Note that a bus can only occupy at most two people.\n\n![ ](https://img.atcoder.jp/ghi/50f2e49a770a30193fc53588ec8475b3.png)\n\nIn the third minute, two people travels from City 2 to City 3 by train, and\nanother two people travels from City 3 to City 4 by taxi.\n\n![ ](https://img.atcoder.jp/ghi/d6d80dc50abe58190905c8c5ea6ba345.png)\n\nFrom then on, if they continue traveling without stopping until they reach\nCity 6, all of them can reach there in seven minutes. \nThere is no way for them to reach City 6 in 6 minutes or less.\n\n* * *"}, {"input": "10\n 123\n 123\n 123\n 123\n 123", "output": "5\n \n\nAll kinds of vehicles can occupy N = 10 people at a time. Thus, if they\ncontinue traveling without stopping until they reach City 6, all of them can\nreach there in five minutes.\n\n* * *"}, {"input": "10000000007\n 2\n 3\n 5\n 7\n 11", "output": "5000000008\n \n\nNote that the input or output may not fit into a 32-bit integer type."}] |
Print the minimum time required for all of the people to reach City 6, in
minutes.
* * * | s868639450 | Wrong Answer | p03077 | Input is given from Standard Input in the following format:
N
A
B
C
D
E | n = int(input())
mins = [(int(input()), idx) for idx in range(5)]
ans = n // min(mins)[0]
print(ans + 5)
| Statement
In 2028 and after a continuous growth, AtCoder Inc. finally built an empire
with six cities (City 1, 2, 3, 4, 5, 6)!
There are five means of transport in this empire:
* Train: travels from City 1 to 2 in one minute. A train can occupy at most A people.
* Bus: travels from City 2 to 3 in one minute. A bus can occupy at most B people.
* Taxi: travels from City 3 to 4 in one minute. A taxi can occupy at most C people.
* Airplane: travels from City 4 to 5 in one minute. An airplane can occupy at most D people.
* Ship: travels from City 5 to 6 in one minute. A ship can occupy at most E people.
For each of them, one vehicle leaves the city at each integer time (time 0, 1,
2, ...).
There is a group of N people at City 1, and they all want to go to City 6.
At least how long does it take for all of them to reach there? You can ignore
the time needed to transfer. | [{"input": "5\n 3\n 2\n 4\n 3\n 5", "output": "7\n \n\nOne possible way to travel is as follows. First, there are N = 5 people at\nCity 1, as shown in the following image:\n\n![ ](https://img.atcoder.jp/ghi/9c306138eddc8a2e08acfa5da19bdfe8.png)\n\nIn the first minute, three people travels from City 1 to City 2 by train. Note\nthat a train can only occupy at most three people.\n\n![ ](https://img.atcoder.jp/ghi/bd30b5ab37fc06951c9f5256bb974e4f.png)\n\nIn the second minute, the remaining two people travels from City 1 to City 2\nby train, and two of the three people who were already at City 2 travels to\nCity 3 by bus. Note that a bus can only occupy at most two people.\n\n![ ](https://img.atcoder.jp/ghi/50f2e49a770a30193fc53588ec8475b3.png)\n\nIn the third minute, two people travels from City 2 to City 3 by train, and\nanother two people travels from City 3 to City 4 by taxi.\n\n![ ](https://img.atcoder.jp/ghi/d6d80dc50abe58190905c8c5ea6ba345.png)\n\nFrom then on, if they continue traveling without stopping until they reach\nCity 6, all of them can reach there in seven minutes. \nThere is no way for them to reach City 6 in 6 minutes or less.\n\n* * *"}, {"input": "10\n 123\n 123\n 123\n 123\n 123", "output": "5\n \n\nAll kinds of vehicles can occupy N = 10 people at a time. Thus, if they\ncontinue traveling without stopping until they reach City 6, all of them can\nreach there in five minutes.\n\n* * *"}, {"input": "10000000007\n 2\n 3\n 5\n 7\n 11", "output": "5000000008\n \n\nNote that the input or output may not fit into a 32-bit integer type."}] |
Print the minimum time required for all of the people to reach City 6, in
minutes.
* * * | s219706960 | Wrong Answer | p03077 | Input is given from Standard Input in the following format:
N
A
B
C
D
E | print(int(input()) // min([int(input()) for _ in range(5)]) + 5)
| Statement
In 2028 and after a continuous growth, AtCoder Inc. finally built an empire
with six cities (City 1, 2, 3, 4, 5, 6)!
There are five means of transport in this empire:
* Train: travels from City 1 to 2 in one minute. A train can occupy at most A people.
* Bus: travels from City 2 to 3 in one minute. A bus can occupy at most B people.
* Taxi: travels from City 3 to 4 in one minute. A taxi can occupy at most C people.
* Airplane: travels from City 4 to 5 in one minute. An airplane can occupy at most D people.
* Ship: travels from City 5 to 6 in one minute. A ship can occupy at most E people.
For each of them, one vehicle leaves the city at each integer time (time 0, 1,
2, ...).
There is a group of N people at City 1, and they all want to go to City 6.
At least how long does it take for all of them to reach there? You can ignore
the time needed to transfer. | [{"input": "5\n 3\n 2\n 4\n 3\n 5", "output": "7\n \n\nOne possible way to travel is as follows. First, there are N = 5 people at\nCity 1, as shown in the following image:\n\n![ ](https://img.atcoder.jp/ghi/9c306138eddc8a2e08acfa5da19bdfe8.png)\n\nIn the first minute, three people travels from City 1 to City 2 by train. Note\nthat a train can only occupy at most three people.\n\n![ ](https://img.atcoder.jp/ghi/bd30b5ab37fc06951c9f5256bb974e4f.png)\n\nIn the second minute, the remaining two people travels from City 1 to City 2\nby train, and two of the three people who were already at City 2 travels to\nCity 3 by bus. Note that a bus can only occupy at most two people.\n\n![ ](https://img.atcoder.jp/ghi/50f2e49a770a30193fc53588ec8475b3.png)\n\nIn the third minute, two people travels from City 2 to City 3 by train, and\nanother two people travels from City 3 to City 4 by taxi.\n\n![ ](https://img.atcoder.jp/ghi/d6d80dc50abe58190905c8c5ea6ba345.png)\n\nFrom then on, if they continue traveling without stopping until they reach\nCity 6, all of them can reach there in seven minutes. \nThere is no way for them to reach City 6 in 6 minutes or less.\n\n* * *"}, {"input": "10\n 123\n 123\n 123\n 123\n 123", "output": "5\n \n\nAll kinds of vehicles can occupy N = 10 people at a time. Thus, if they\ncontinue traveling without stopping until they reach City 6, all of them can\nreach there in five minutes.\n\n* * *"}, {"input": "10000000007\n 2\n 3\n 5\n 7\n 11", "output": "5000000008\n \n\nNote that the input or output may not fit into a 32-bit integer type."}] |
Print the minimum time required for all of the people to reach City 6, in
minutes.
* * * | s013759411 | Wrong Answer | p03077 | Input is given from Standard Input in the following format:
N
A
B
C
D
E | A = [int(input()) for _ in [0] * 5]
B = [-(-a // 10) * 10 - a for a in A]
print(sum(B) + sum(A) - max(B))
| Statement
In 2028 and after a continuous growth, AtCoder Inc. finally built an empire
with six cities (City 1, 2, 3, 4, 5, 6)!
There are five means of transport in this empire:
* Train: travels from City 1 to 2 in one minute. A train can occupy at most A people.
* Bus: travels from City 2 to 3 in one minute. A bus can occupy at most B people.
* Taxi: travels from City 3 to 4 in one minute. A taxi can occupy at most C people.
* Airplane: travels from City 4 to 5 in one minute. An airplane can occupy at most D people.
* Ship: travels from City 5 to 6 in one minute. A ship can occupy at most E people.
For each of them, one vehicle leaves the city at each integer time (time 0, 1,
2, ...).
There is a group of N people at City 1, and they all want to go to City 6.
At least how long does it take for all of them to reach there? You can ignore
the time needed to transfer. | [{"input": "5\n 3\n 2\n 4\n 3\n 5", "output": "7\n \n\nOne possible way to travel is as follows. First, there are N = 5 people at\nCity 1, as shown in the following image:\n\n![ ](https://img.atcoder.jp/ghi/9c306138eddc8a2e08acfa5da19bdfe8.png)\n\nIn the first minute, three people travels from City 1 to City 2 by train. Note\nthat a train can only occupy at most three people.\n\n![ ](https://img.atcoder.jp/ghi/bd30b5ab37fc06951c9f5256bb974e4f.png)\n\nIn the second minute, the remaining two people travels from City 1 to City 2\nby train, and two of the three people who were already at City 2 travels to\nCity 3 by bus. Note that a bus can only occupy at most two people.\n\n![ ](https://img.atcoder.jp/ghi/50f2e49a770a30193fc53588ec8475b3.png)\n\nIn the third minute, two people travels from City 2 to City 3 by train, and\nanother two people travels from City 3 to City 4 by taxi.\n\n![ ](https://img.atcoder.jp/ghi/d6d80dc50abe58190905c8c5ea6ba345.png)\n\nFrom then on, if they continue traveling without stopping until they reach\nCity 6, all of them can reach there in seven minutes. \nThere is no way for them to reach City 6 in 6 minutes or less.\n\n* * *"}, {"input": "10\n 123\n 123\n 123\n 123\n 123", "output": "5\n \n\nAll kinds of vehicles can occupy N = 10 people at a time. Thus, if they\ncontinue traveling without stopping until they reach City 6, all of them can\nreach there in five minutes.\n\n* * *"}, {"input": "10000000007\n 2\n 3\n 5\n 7\n 11", "output": "5000000008\n \n\nNote that the input or output may not fit into a 32-bit integer type."}] |
Print the minimum time required for all of the people to reach City 6, in
minutes.
* * * | s212045418 | Wrong Answer | p03077 | Input is given from Standard Input in the following format:
N
A
B
C
D
E | L = [int(input()) for i in range(6)]
m = L[0]
c = 0
for i in range(1, 6):
c += -(-m // L[i])
m = min(m, L[i])
print(c)
| Statement
In 2028 and after a continuous growth, AtCoder Inc. finally built an empire
with six cities (City 1, 2, 3, 4, 5, 6)!
There are five means of transport in this empire:
* Train: travels from City 1 to 2 in one minute. A train can occupy at most A people.
* Bus: travels from City 2 to 3 in one minute. A bus can occupy at most B people.
* Taxi: travels from City 3 to 4 in one minute. A taxi can occupy at most C people.
* Airplane: travels from City 4 to 5 in one minute. An airplane can occupy at most D people.
* Ship: travels from City 5 to 6 in one minute. A ship can occupy at most E people.
For each of them, one vehicle leaves the city at each integer time (time 0, 1,
2, ...).
There is a group of N people at City 1, and they all want to go to City 6.
At least how long does it take for all of them to reach there? You can ignore
the time needed to transfer. | [{"input": "5\n 3\n 2\n 4\n 3\n 5", "output": "7\n \n\nOne possible way to travel is as follows. First, there are N = 5 people at\nCity 1, as shown in the following image:\n\n![ ](https://img.atcoder.jp/ghi/9c306138eddc8a2e08acfa5da19bdfe8.png)\n\nIn the first minute, three people travels from City 1 to City 2 by train. Note\nthat a train can only occupy at most three people.\n\n![ ](https://img.atcoder.jp/ghi/bd30b5ab37fc06951c9f5256bb974e4f.png)\n\nIn the second minute, the remaining two people travels from City 1 to City 2\nby train, and two of the three people who were already at City 2 travels to\nCity 3 by bus. Note that a bus can only occupy at most two people.\n\n![ ](https://img.atcoder.jp/ghi/50f2e49a770a30193fc53588ec8475b3.png)\n\nIn the third minute, two people travels from City 2 to City 3 by train, and\nanother two people travels from City 3 to City 4 by taxi.\n\n![ ](https://img.atcoder.jp/ghi/d6d80dc50abe58190905c8c5ea6ba345.png)\n\nFrom then on, if they continue traveling without stopping until they reach\nCity 6, all of them can reach there in seven minutes. \nThere is no way for them to reach City 6 in 6 minutes or less.\n\n* * *"}, {"input": "10\n 123\n 123\n 123\n 123\n 123", "output": "5\n \n\nAll kinds of vehicles can occupy N = 10 people at a time. Thus, if they\ncontinue traveling without stopping until they reach City 6, all of them can\nreach there in five minutes.\n\n* * *"}, {"input": "10000000007\n 2\n 3\n 5\n 7\n 11", "output": "5000000008\n \n\nNote that the input or output may not fit into a 32-bit integer type."}] |
Print the minimum time required for all of the people to reach City 6, in
minutes.
* * * | s240503713 | Accepted | p03077 | Input is given from Standard Input in the following format:
N
A
B
C
D
E | def int_raw():
return int(input())
def ss_raw():
return input().split()
def ints_raw():
return list(map(int, ss_raw()))
N = int_raw()
poss = []
for i in range(5):
p = int_raw()
poss.append(p)
def main():
minp = min(poss)
return ((N + minp - 1) // minp) + 4
print(main())
| Statement
In 2028 and after a continuous growth, AtCoder Inc. finally built an empire
with six cities (City 1, 2, 3, 4, 5, 6)!
There are five means of transport in this empire:
* Train: travels from City 1 to 2 in one minute. A train can occupy at most A people.
* Bus: travels from City 2 to 3 in one minute. A bus can occupy at most B people.
* Taxi: travels from City 3 to 4 in one minute. A taxi can occupy at most C people.
* Airplane: travels from City 4 to 5 in one minute. An airplane can occupy at most D people.
* Ship: travels from City 5 to 6 in one minute. A ship can occupy at most E people.
For each of them, one vehicle leaves the city at each integer time (time 0, 1,
2, ...).
There is a group of N people at City 1, and they all want to go to City 6.
At least how long does it take for all of them to reach there? You can ignore
the time needed to transfer. | [{"input": "5\n 3\n 2\n 4\n 3\n 5", "output": "7\n \n\nOne possible way to travel is as follows. First, there are N = 5 people at\nCity 1, as shown in the following image:\n\n![ ](https://img.atcoder.jp/ghi/9c306138eddc8a2e08acfa5da19bdfe8.png)\n\nIn the first minute, three people travels from City 1 to City 2 by train. Note\nthat a train can only occupy at most three people.\n\n![ ](https://img.atcoder.jp/ghi/bd30b5ab37fc06951c9f5256bb974e4f.png)\n\nIn the second minute, the remaining two people travels from City 1 to City 2\nby train, and two of the three people who were already at City 2 travels to\nCity 3 by bus. Note that a bus can only occupy at most two people.\n\n![ ](https://img.atcoder.jp/ghi/50f2e49a770a30193fc53588ec8475b3.png)\n\nIn the third minute, two people travels from City 2 to City 3 by train, and\nanother two people travels from City 3 to City 4 by taxi.\n\n![ ](https://img.atcoder.jp/ghi/d6d80dc50abe58190905c8c5ea6ba345.png)\n\nFrom then on, if they continue traveling without stopping until they reach\nCity 6, all of them can reach there in seven minutes. \nThere is no way for them to reach City 6 in 6 minutes or less.\n\n* * *"}, {"input": "10\n 123\n 123\n 123\n 123\n 123", "output": "5\n \n\nAll kinds of vehicles can occupy N = 10 people at a time. Thus, if they\ncontinue traveling without stopping until they reach City 6, all of them can\nreach there in five minutes.\n\n* * *"}, {"input": "10000000007\n 2\n 3\n 5\n 7\n 11", "output": "5000000008\n \n\nNote that the input or output may not fit into a 32-bit integer type."}] |
Print the minimum time required for all of the people to reach City 6, in
minutes.
* * * | s669164210 | Wrong Answer | p03077 | Input is given from Standard Input in the following format:
N
A
B
C
D
E | a = [int(input()) for _ in range(6)]
print(
max(
a[0] + (a[1] - 1) // a[1],
a[0] + (a[2] - 1) // a[2],
a[0] + (a[3] - 1) // a[3],
a[0] + (a[4] - 1) // a[4],
a[0] + (a[5] - 1) // a[5],
)
+ 4
)
| Statement
In 2028 and after a continuous growth, AtCoder Inc. finally built an empire
with six cities (City 1, 2, 3, 4, 5, 6)!
There are five means of transport in this empire:
* Train: travels from City 1 to 2 in one minute. A train can occupy at most A people.
* Bus: travels from City 2 to 3 in one minute. A bus can occupy at most B people.
* Taxi: travels from City 3 to 4 in one minute. A taxi can occupy at most C people.
* Airplane: travels from City 4 to 5 in one minute. An airplane can occupy at most D people.
* Ship: travels from City 5 to 6 in one minute. A ship can occupy at most E people.
For each of them, one vehicle leaves the city at each integer time (time 0, 1,
2, ...).
There is a group of N people at City 1, and they all want to go to City 6.
At least how long does it take for all of them to reach there? You can ignore
the time needed to transfer. | [{"input": "5\n 3\n 2\n 4\n 3\n 5", "output": "7\n \n\nOne possible way to travel is as follows. First, there are N = 5 people at\nCity 1, as shown in the following image:\n\n![ ](https://img.atcoder.jp/ghi/9c306138eddc8a2e08acfa5da19bdfe8.png)\n\nIn the first minute, three people travels from City 1 to City 2 by train. Note\nthat a train can only occupy at most three people.\n\n![ ](https://img.atcoder.jp/ghi/bd30b5ab37fc06951c9f5256bb974e4f.png)\n\nIn the second minute, the remaining two people travels from City 1 to City 2\nby train, and two of the three people who were already at City 2 travels to\nCity 3 by bus. Note that a bus can only occupy at most two people.\n\n![ ](https://img.atcoder.jp/ghi/50f2e49a770a30193fc53588ec8475b3.png)\n\nIn the third minute, two people travels from City 2 to City 3 by train, and\nanother two people travels from City 3 to City 4 by taxi.\n\n![ ](https://img.atcoder.jp/ghi/d6d80dc50abe58190905c8c5ea6ba345.png)\n\nFrom then on, if they continue traveling without stopping until they reach\nCity 6, all of them can reach there in seven minutes. \nThere is no way for them to reach City 6 in 6 minutes or less.\n\n* * *"}, {"input": "10\n 123\n 123\n 123\n 123\n 123", "output": "5\n \n\nAll kinds of vehicles can occupy N = 10 people at a time. Thus, if they\ncontinue traveling without stopping until they reach City 6, all of them can\nreach there in five minutes.\n\n* * *"}, {"input": "10000000007\n 2\n 3\n 5\n 7\n 11", "output": "5000000008\n \n\nNote that the input or output may not fit into a 32-bit integer type."}] |
Print the minimum time required for all of the people to reach City 6, in
minutes.
* * * | s387300207 | Wrong Answer | p03077 | Input is given from Standard Input in the following format:
N
A
B
C
D
E | read = input
n = int(read())
a = [read() for i in range(5)]
a = list(map(int, a))
a = min(a)
if n % a == 0:
n = n / a
else:
n = n // a + 1
print(n + 5 - 1)
| Statement
In 2028 and after a continuous growth, AtCoder Inc. finally built an empire
with six cities (City 1, 2, 3, 4, 5, 6)!
There are five means of transport in this empire:
* Train: travels from City 1 to 2 in one minute. A train can occupy at most A people.
* Bus: travels from City 2 to 3 in one minute. A bus can occupy at most B people.
* Taxi: travels from City 3 to 4 in one minute. A taxi can occupy at most C people.
* Airplane: travels from City 4 to 5 in one minute. An airplane can occupy at most D people.
* Ship: travels from City 5 to 6 in one minute. A ship can occupy at most E people.
For each of them, one vehicle leaves the city at each integer time (time 0, 1,
2, ...).
There is a group of N people at City 1, and they all want to go to City 6.
At least how long does it take for all of them to reach there? You can ignore
the time needed to transfer. | [{"input": "5\n 3\n 2\n 4\n 3\n 5", "output": "7\n \n\nOne possible way to travel is as follows. First, there are N = 5 people at\nCity 1, as shown in the following image:\n\n![ ](https://img.atcoder.jp/ghi/9c306138eddc8a2e08acfa5da19bdfe8.png)\n\nIn the first minute, three people travels from City 1 to City 2 by train. Note\nthat a train can only occupy at most three people.\n\n![ ](https://img.atcoder.jp/ghi/bd30b5ab37fc06951c9f5256bb974e4f.png)\n\nIn the second minute, the remaining two people travels from City 1 to City 2\nby train, and two of the three people who were already at City 2 travels to\nCity 3 by bus. Note that a bus can only occupy at most two people.\n\n![ ](https://img.atcoder.jp/ghi/50f2e49a770a30193fc53588ec8475b3.png)\n\nIn the third minute, two people travels from City 2 to City 3 by train, and\nanother two people travels from City 3 to City 4 by taxi.\n\n![ ](https://img.atcoder.jp/ghi/d6d80dc50abe58190905c8c5ea6ba345.png)\n\nFrom then on, if they continue traveling without stopping until they reach\nCity 6, all of them can reach there in seven minutes. \nThere is no way for them to reach City 6 in 6 minutes or less.\n\n* * *"}, {"input": "10\n 123\n 123\n 123\n 123\n 123", "output": "5\n \n\nAll kinds of vehicles can occupy N = 10 people at a time. Thus, if they\ncontinue traveling without stopping until they reach City 6, all of them can\nreach there in five minutes.\n\n* * *"}, {"input": "10000000007\n 2\n 3\n 5\n 7\n 11", "output": "5000000008\n \n\nNote that the input or output may not fit into a 32-bit integer type."}] |
Print the minimum time required for all of the people to reach City 6, in
minutes.
* * * | s255133675 | Accepted | p03077 | Input is given from Standard Input in the following format:
N
A
B
C
D
E | print(-(-int(input()) // min([int(input()) for i in range(5)])) + 4)
| Statement
In 2028 and after a continuous growth, AtCoder Inc. finally built an empire
with six cities (City 1, 2, 3, 4, 5, 6)!
There are five means of transport in this empire:
* Train: travels from City 1 to 2 in one minute. A train can occupy at most A people.
* Bus: travels from City 2 to 3 in one minute. A bus can occupy at most B people.
* Taxi: travels from City 3 to 4 in one minute. A taxi can occupy at most C people.
* Airplane: travels from City 4 to 5 in one minute. An airplane can occupy at most D people.
* Ship: travels from City 5 to 6 in one minute. A ship can occupy at most E people.
For each of them, one vehicle leaves the city at each integer time (time 0, 1,
2, ...).
There is a group of N people at City 1, and they all want to go to City 6.
At least how long does it take for all of them to reach there? You can ignore
the time needed to transfer. | [{"input": "5\n 3\n 2\n 4\n 3\n 5", "output": "7\n \n\nOne possible way to travel is as follows. First, there are N = 5 people at\nCity 1, as shown in the following image:\n\n![ ](https://img.atcoder.jp/ghi/9c306138eddc8a2e08acfa5da19bdfe8.png)\n\nIn the first minute, three people travels from City 1 to City 2 by train. Note\nthat a train can only occupy at most three people.\n\n![ ](https://img.atcoder.jp/ghi/bd30b5ab37fc06951c9f5256bb974e4f.png)\n\nIn the second minute, the remaining two people travels from City 1 to City 2\nby train, and two of the three people who were already at City 2 travels to\nCity 3 by bus. Note that a bus can only occupy at most two people.\n\n![ ](https://img.atcoder.jp/ghi/50f2e49a770a30193fc53588ec8475b3.png)\n\nIn the third minute, two people travels from City 2 to City 3 by train, and\nanother two people travels from City 3 to City 4 by taxi.\n\n![ ](https://img.atcoder.jp/ghi/d6d80dc50abe58190905c8c5ea6ba345.png)\n\nFrom then on, if they continue traveling without stopping until they reach\nCity 6, all of them can reach there in seven minutes. \nThere is no way for them to reach City 6 in 6 minutes or less.\n\n* * *"}, {"input": "10\n 123\n 123\n 123\n 123\n 123", "output": "5\n \n\nAll kinds of vehicles can occupy N = 10 people at a time. Thus, if they\ncontinue traveling without stopping until they reach City 6, all of them can\nreach there in five minutes.\n\n* * *"}, {"input": "10000000007\n 2\n 3\n 5\n 7\n 11", "output": "5000000008\n \n\nNote that the input or output may not fit into a 32-bit integer type."}] |
Print the minimum time required for all of the people to reach City 6, in
minutes.
* * * | s265892178 | Accepted | p03077 | Input is given from Standard Input in the following format:
N
A
B
C
D
E | def getInt():
return int(input())
def getIntList():
return [int(x) for x in input().split()]
def zeros(n):
return [0] * n
# def zeros(n): return np.zeros(n, dtype=np.longlong)
def zeros2(n, m):
return [zeros(m) for i in range(n)] # obsoleted zeros((n, m))で代替
INF = 10**18
class Debug:
def __init__(self):
self.debug = True
def off(self):
self.debug = False
def dmp(self, x, cmt=""):
if self.debug:
if cmt != "":
w = cmt + ": " + str(x)
else:
w = str(x)
print(w)
return x
def prob():
d = Debug()
d.off()
N = int(input())
xport = zeros(5)
for i in range(5):
xport[i] = int(input())
d.dmp((xport), "xport")
minCapa = INF
for i in range(5):
minCapa = min(minCapa, xport[i])
d.dmp((minCapa), "minCapa")
minutes = 4
minutes += (N + minCapa - 1) // minCapa
d.dmp((minutes), "minutes")
return minutes
ans = prob()
print(ans)
| Statement
In 2028 and after a continuous growth, AtCoder Inc. finally built an empire
with six cities (City 1, 2, 3, 4, 5, 6)!
There are five means of transport in this empire:
* Train: travels from City 1 to 2 in one minute. A train can occupy at most A people.
* Bus: travels from City 2 to 3 in one minute. A bus can occupy at most B people.
* Taxi: travels from City 3 to 4 in one minute. A taxi can occupy at most C people.
* Airplane: travels from City 4 to 5 in one minute. An airplane can occupy at most D people.
* Ship: travels from City 5 to 6 in one minute. A ship can occupy at most E people.
For each of them, one vehicle leaves the city at each integer time (time 0, 1,
2, ...).
There is a group of N people at City 1, and they all want to go to City 6.
At least how long does it take for all of them to reach there? You can ignore
the time needed to transfer. | [{"input": "5\n 3\n 2\n 4\n 3\n 5", "output": "7\n \n\nOne possible way to travel is as follows. First, there are N = 5 people at\nCity 1, as shown in the following image:\n\n![ ](https://img.atcoder.jp/ghi/9c306138eddc8a2e08acfa5da19bdfe8.png)\n\nIn the first minute, three people travels from City 1 to City 2 by train. Note\nthat a train can only occupy at most three people.\n\n![ ](https://img.atcoder.jp/ghi/bd30b5ab37fc06951c9f5256bb974e4f.png)\n\nIn the second minute, the remaining two people travels from City 1 to City 2\nby train, and two of the three people who were already at City 2 travels to\nCity 3 by bus. Note that a bus can only occupy at most two people.\n\n![ ](https://img.atcoder.jp/ghi/50f2e49a770a30193fc53588ec8475b3.png)\n\nIn the third minute, two people travels from City 2 to City 3 by train, and\nanother two people travels from City 3 to City 4 by taxi.\n\n![ ](https://img.atcoder.jp/ghi/d6d80dc50abe58190905c8c5ea6ba345.png)\n\nFrom then on, if they continue traveling without stopping until they reach\nCity 6, all of them can reach there in seven minutes. \nThere is no way for them to reach City 6 in 6 minutes or less.\n\n* * *"}, {"input": "10\n 123\n 123\n 123\n 123\n 123", "output": "5\n \n\nAll kinds of vehicles can occupy N = 10 people at a time. Thus, if they\ncontinue traveling without stopping until they reach City 6, all of them can\nreach there in five minutes.\n\n* * *"}, {"input": "10000000007\n 2\n 3\n 5\n 7\n 11", "output": "5000000008\n \n\nNote that the input or output may not fit into a 32-bit integer type."}] |
Print the minimum time required for all of the people to reach City 6, in
minutes.
* * * | s123102966 | Accepted | p03077 | Input is given from Standard Input in the following format:
N
A
B
C
D
E | N = int(input())
a = int(input())
b = int(input())
c = int(input())
d = int(input())
e = int(input())
if min(a, b, c, d, e) == a:
if N % a == 0:
print(N // a + 4)
else:
print(N // a + 5)
elif min(b, c, d, e) == b:
if N % b == 0:
print(N // b + 4)
else:
print(N // b + 5)
elif min(c, d, e) == c:
if N % c == 0:
print(N // c + 4)
else:
print(N // c + 5)
elif min(d, e) == d:
if N % d == 0:
print(N // d + 4)
else:
print(N // d + 5)
else:
if N % e == 0:
print(N // e + 4)
else:
print(N // e + 5)
| Statement
In 2028 and after a continuous growth, AtCoder Inc. finally built an empire
with six cities (City 1, 2, 3, 4, 5, 6)!
There are five means of transport in this empire:
* Train: travels from City 1 to 2 in one minute. A train can occupy at most A people.
* Bus: travels from City 2 to 3 in one minute. A bus can occupy at most B people.
* Taxi: travels from City 3 to 4 in one minute. A taxi can occupy at most C people.
* Airplane: travels from City 4 to 5 in one minute. An airplane can occupy at most D people.
* Ship: travels from City 5 to 6 in one minute. A ship can occupy at most E people.
For each of them, one vehicle leaves the city at each integer time (time 0, 1,
2, ...).
There is a group of N people at City 1, and they all want to go to City 6.
At least how long does it take for all of them to reach there? You can ignore
the time needed to transfer. | [{"input": "5\n 3\n 2\n 4\n 3\n 5", "output": "7\n \n\nOne possible way to travel is as follows. First, there are N = 5 people at\nCity 1, as shown in the following image:\n\n![ ](https://img.atcoder.jp/ghi/9c306138eddc8a2e08acfa5da19bdfe8.png)\n\nIn the first minute, three people travels from City 1 to City 2 by train. Note\nthat a train can only occupy at most three people.\n\n![ ](https://img.atcoder.jp/ghi/bd30b5ab37fc06951c9f5256bb974e4f.png)\n\nIn the second minute, the remaining two people travels from City 1 to City 2\nby train, and two of the three people who were already at City 2 travels to\nCity 3 by bus. Note that a bus can only occupy at most two people.\n\n![ ](https://img.atcoder.jp/ghi/50f2e49a770a30193fc53588ec8475b3.png)\n\nIn the third minute, two people travels from City 2 to City 3 by train, and\nanother two people travels from City 3 to City 4 by taxi.\n\n![ ](https://img.atcoder.jp/ghi/d6d80dc50abe58190905c8c5ea6ba345.png)\n\nFrom then on, if they continue traveling without stopping until they reach\nCity 6, all of them can reach there in seven minutes. \nThere is no way for them to reach City 6 in 6 minutes or less.\n\n* * *"}, {"input": "10\n 123\n 123\n 123\n 123\n 123", "output": "5\n \n\nAll kinds of vehicles can occupy N = 10 people at a time. Thus, if they\ncontinue traveling without stopping until they reach City 6, all of them can\nreach there in five minutes.\n\n* * *"}, {"input": "10000000007\n 2\n 3\n 5\n 7\n 11", "output": "5000000008\n \n\nNote that the input or output may not fit into a 32-bit integer type."}] |
Print the minimum time required for all of the people to reach City 6, in
minutes.
* * * | s082889279 | Wrong Answer | p03077 | Input is given from Standard Input in the following format:
N
A
B
C
D
E | l = [int(input()) for _ in range(6)]
N = l[0]
l = l[1:]
c = [0] * 5
for i in range(len(l)):
if N > l[i]:
c[i] = N - l[i]
N = l[i]
res = 0
for i in range(len(c)):
if c[i] > 0 and i == 0:
res += int(c[i] / l[i]) + 1
elif c[i] > 0:
if int(c[i] / l[i]) + 1 >= i:
nokori = c[i] - int(c[i] / l[i]) * l[i]
res += int((c[i] + nokori) / l[i])
print(5 + res)
| Statement
In 2028 and after a continuous growth, AtCoder Inc. finally built an empire
with six cities (City 1, 2, 3, 4, 5, 6)!
There are five means of transport in this empire:
* Train: travels from City 1 to 2 in one minute. A train can occupy at most A people.
* Bus: travels from City 2 to 3 in one minute. A bus can occupy at most B people.
* Taxi: travels from City 3 to 4 in one minute. A taxi can occupy at most C people.
* Airplane: travels from City 4 to 5 in one minute. An airplane can occupy at most D people.
* Ship: travels from City 5 to 6 in one minute. A ship can occupy at most E people.
For each of them, one vehicle leaves the city at each integer time (time 0, 1,
2, ...).
There is a group of N people at City 1, and they all want to go to City 6.
At least how long does it take for all of them to reach there? You can ignore
the time needed to transfer. | [{"input": "5\n 3\n 2\n 4\n 3\n 5", "output": "7\n \n\nOne possible way to travel is as follows. First, there are N = 5 people at\nCity 1, as shown in the following image:\n\n![ ](https://img.atcoder.jp/ghi/9c306138eddc8a2e08acfa5da19bdfe8.png)\n\nIn the first minute, three people travels from City 1 to City 2 by train. Note\nthat a train can only occupy at most three people.\n\n![ ](https://img.atcoder.jp/ghi/bd30b5ab37fc06951c9f5256bb974e4f.png)\n\nIn the second minute, the remaining two people travels from City 1 to City 2\nby train, and two of the three people who were already at City 2 travels to\nCity 3 by bus. Note that a bus can only occupy at most two people.\n\n![ ](https://img.atcoder.jp/ghi/50f2e49a770a30193fc53588ec8475b3.png)\n\nIn the third minute, two people travels from City 2 to City 3 by train, and\nanother two people travels from City 3 to City 4 by taxi.\n\n![ ](https://img.atcoder.jp/ghi/d6d80dc50abe58190905c8c5ea6ba345.png)\n\nFrom then on, if they continue traveling without stopping until they reach\nCity 6, all of them can reach there in seven minutes. \nThere is no way for them to reach City 6 in 6 minutes or less.\n\n* * *"}, {"input": "10\n 123\n 123\n 123\n 123\n 123", "output": "5\n \n\nAll kinds of vehicles can occupy N = 10 people at a time. Thus, if they\ncontinue traveling without stopping until they reach City 6, all of them can\nreach there in five minutes.\n\n* * *"}, {"input": "10000000007\n 2\n 3\n 5\n 7\n 11", "output": "5000000008\n \n\nNote that the input or output may not fit into a 32-bit integer type."}] |
Print the minimum time required for all of the people to reach City 6, in
minutes.
* * * | s840184463 | Wrong Answer | p03077 | Input is given from Standard Input in the following format:
N
A
B
C
D
E | N = input()
A = input()
B = input()
C = input()
D = input()
E = input()
N = int(N)
A = int(A)
B = int(B)
C = int(C)
D = int(D)
E = int(E)
a = N // A
b = N // B
c = N // C
d = N // D
e = N // E
f = max(a, b, c, d, e)
if a == b == c == d == e:
print(f + 4)
else:
print(f + 5)
| Statement
In 2028 and after a continuous growth, AtCoder Inc. finally built an empire
with six cities (City 1, 2, 3, 4, 5, 6)!
There are five means of transport in this empire:
* Train: travels from City 1 to 2 in one minute. A train can occupy at most A people.
* Bus: travels from City 2 to 3 in one minute. A bus can occupy at most B people.
* Taxi: travels from City 3 to 4 in one minute. A taxi can occupy at most C people.
* Airplane: travels from City 4 to 5 in one minute. An airplane can occupy at most D people.
* Ship: travels from City 5 to 6 in one minute. A ship can occupy at most E people.
For each of them, one vehicle leaves the city at each integer time (time 0, 1,
2, ...).
There is a group of N people at City 1, and they all want to go to City 6.
At least how long does it take for all of them to reach there? You can ignore
the time needed to transfer. | [{"input": "5\n 3\n 2\n 4\n 3\n 5", "output": "7\n \n\nOne possible way to travel is as follows. First, there are N = 5 people at\nCity 1, as shown in the following image:\n\n![ ](https://img.atcoder.jp/ghi/9c306138eddc8a2e08acfa5da19bdfe8.png)\n\nIn the first minute, three people travels from City 1 to City 2 by train. Note\nthat a train can only occupy at most three people.\n\n![ ](https://img.atcoder.jp/ghi/bd30b5ab37fc06951c9f5256bb974e4f.png)\n\nIn the second minute, the remaining two people travels from City 1 to City 2\nby train, and two of the three people who were already at City 2 travels to\nCity 3 by bus. Note that a bus can only occupy at most two people.\n\n![ ](https://img.atcoder.jp/ghi/50f2e49a770a30193fc53588ec8475b3.png)\n\nIn the third minute, two people travels from City 2 to City 3 by train, and\nanother two people travels from City 3 to City 4 by taxi.\n\n![ ](https://img.atcoder.jp/ghi/d6d80dc50abe58190905c8c5ea6ba345.png)\n\nFrom then on, if they continue traveling without stopping until they reach\nCity 6, all of them can reach there in seven minutes. \nThere is no way for them to reach City 6 in 6 minutes or less.\n\n* * *"}, {"input": "10\n 123\n 123\n 123\n 123\n 123", "output": "5\n \n\nAll kinds of vehicles can occupy N = 10 people at a time. Thus, if they\ncontinue traveling without stopping until they reach City 6, all of them can\nreach there in five minutes.\n\n* * *"}, {"input": "10000000007\n 2\n 3\n 5\n 7\n 11", "output": "5000000008\n \n\nNote that the input or output may not fit into a 32-bit integer type."}] |
Print the minimum time required for all of the people to reach City 6, in
minutes.
* * * | s785034569 | Wrong Answer | p03077 | Input is given from Standard Input in the following format:
N
A
B
C
D
E | population = int(input())
a2b = int(input())
b2c = int(input())
c2d = int(input())
d2e = int(input())
e2f = int(input())
city = [population, 0, 0, 0, 0, 0]
vehicle = [a2b, b2c, c2d, d2e, e2f]
print(round(population / min(vehicle)) + 4)
| Statement
In 2028 and after a continuous growth, AtCoder Inc. finally built an empire
with six cities (City 1, 2, 3, 4, 5, 6)!
There are five means of transport in this empire:
* Train: travels from City 1 to 2 in one minute. A train can occupy at most A people.
* Bus: travels from City 2 to 3 in one minute. A bus can occupy at most B people.
* Taxi: travels from City 3 to 4 in one minute. A taxi can occupy at most C people.
* Airplane: travels from City 4 to 5 in one minute. An airplane can occupy at most D people.
* Ship: travels from City 5 to 6 in one minute. A ship can occupy at most E people.
For each of them, one vehicle leaves the city at each integer time (time 0, 1,
2, ...).
There is a group of N people at City 1, and they all want to go to City 6.
At least how long does it take for all of them to reach there? You can ignore
the time needed to transfer. | [{"input": "5\n 3\n 2\n 4\n 3\n 5", "output": "7\n \n\nOne possible way to travel is as follows. First, there are N = 5 people at\nCity 1, as shown in the following image:\n\n![ ](https://img.atcoder.jp/ghi/9c306138eddc8a2e08acfa5da19bdfe8.png)\n\nIn the first minute, three people travels from City 1 to City 2 by train. Note\nthat a train can only occupy at most three people.\n\n![ ](https://img.atcoder.jp/ghi/bd30b5ab37fc06951c9f5256bb974e4f.png)\n\nIn the second minute, the remaining two people travels from City 1 to City 2\nby train, and two of the three people who were already at City 2 travels to\nCity 3 by bus. Note that a bus can only occupy at most two people.\n\n![ ](https://img.atcoder.jp/ghi/50f2e49a770a30193fc53588ec8475b3.png)\n\nIn the third minute, two people travels from City 2 to City 3 by train, and\nanother two people travels from City 3 to City 4 by taxi.\n\n![ ](https://img.atcoder.jp/ghi/d6d80dc50abe58190905c8c5ea6ba345.png)\n\nFrom then on, if they continue traveling without stopping until they reach\nCity 6, all of them can reach there in seven minutes. \nThere is no way for them to reach City 6 in 6 minutes or less.\n\n* * *"}, {"input": "10\n 123\n 123\n 123\n 123\n 123", "output": "5\n \n\nAll kinds of vehicles can occupy N = 10 people at a time. Thus, if they\ncontinue traveling without stopping until they reach City 6, all of them can\nreach there in five minutes.\n\n* * *"}, {"input": "10000000007\n 2\n 3\n 5\n 7\n 11", "output": "5000000008\n \n\nNote that the input or output may not fit into a 32-bit integer type."}] |
Print the expected value for a search operation on the optimal binary search
tree in a line. The output must not contain an error greater than $10^{−4}$. | s197119915 | Wrong Answer | p02236 | $n$
$p_1$ $p_2$ ... $p_n$
$q_0$ $q_1$ $q_2$ ... $q_n$
In the first line, an integer $n$ which represents the number of keys is
given.
In the second line, $p_i (1 \le i \le n)$ are given in real numbers with four
decimal places.
In the third line, $q_i (0 \le i \le n)$ are given in real numbers with four
decimal places. | n = int(input())
p = [float(i) for i in input().split()]
q = [float(i) for i in input().split()]
pq = [q[-1]] * (2 * n + 1)
dp = {}
for i in range(n):
pq[2 * i] = q[i]
pq[2 * i + 1] = p[i]
pq = [0.0] + pq
for j in range(len(pq)):
for i in range(len(pq) - j):
if j == 0:
dp[(i, i + j)] = 0.0
elif j == 1:
dp[(i, i + j)] = pq[i + j]
else:
tmp = 1001
for k in range(j):
c = dp[(i, i + k)] + dp[(i + k + 1, i + j)] + sum(pq[i + 1 : i + j + 1])
if c < tmp:
if j == len(pq) - 1 and i + k % 2 == 1:
continue
tmp = c
dp[(i, i + j)] = tmp
print(dp[(0, 2 * n + 1)])
| Optimal Binary Search Tree
Optimal Binary Search Tree is a binary search tree constructed from $n$ keys
and $n+1$ dummy keys so as to minimize the expected value of cost for a search
operation.
We are given a sequence $K = {k_1, k_2, ..., k_n}$ of $n$ distinct keys in
sorted order $(k_1 < k_2 < ... < k_n)$, and we wish to construct a binary
search tree. For each key $k_i$, we have a probability $p_i$ that a search
will be for $k_i$. Some searches may be for values not in $K$, and so we also
have $n+1$ dummy keys $d_0, d_1, d_2, ..., d_n$ representing values not in
$K$. The dummy keys $d_i (0 \le i \le n)$ are defined as follows:
* if $i=0$, then $d_i$ represents all values less than $k_1$
* if $i=n$, then $d_i$ represents all values greater than $k_n$
* if $1 \le i \le n-1$, then $d_i$ represents all values between $k_i$ and $k_{i+1}$
For each dummy key $d_i$, we have a probability $q_i$ that a search will
correspond to $d_i$. For $p_i (1 \le i \le n)$ and $q_i (0 \le i \le n)$, we
have \\[ \sum_{i=1}^n p_i + \sum_{i=0}^n q_i = 1 \\] Then the expected cost of
a search in a binary search tree $T$ is \\[ E_T = \sum_{i=1}^n (depth_T(k_i) +
1) \cdot p_i + \sum_{i=0}^n (depth_T(d_i) + 1) \cdot q_i \\] where
$depth_T(v)$ is the depth of node $v$ in $T$. For a given set of
probabilities, our goal is to construct a binary search tree whose expected
search cost is smallest. We call such a tree an **optimal binary search
tree**.
Each key $k_i$ is an internal node and each dummy key $d_i$ is a leaf. For
example, the following figure shows the optimal binary search tree obtained
from Sample Input 1.
![](https://judgeapi.u-aizu.ac.jp/resources/images/ALDS1_10_D_tree1) | [{"input": "5\n 0.1500 0.1000 0.0500 0.1000 0.2000\n 0.0500 0.1000 0.0500 0.0500 0.0500 0.1000", "output": "2.75000000"}, {"input": "7\n 0.0400 0.0600 0.0800 0.0200 0.1000 0.1200 0.1400\n 0.0600 0.0600 0.0600 0.0600 0.0500 0.0500 0.0500 0.0500", "output": "3.12000000"}] |
For each way to make requests, find the minimum number of roads needed to meet
all the requests, and print the sum of those (N-1)^K numbers, modulo (10^9+7).
* * * | s994483322 | Wrong Answer | p02666 | Input is given from Standard Input in the following format:
N
P_1 P_2 \cdots P_N | import sys
input = lambda: sys.stdin.readline().rstrip()
sys.setrecursionlimit(max(1000, 10**9))
write = lambda x: sys.stdout.write(x + "\n")
class UnionFindTree:
def __init__(self, n):
self.n = n
self.parent = list(range(n))
self.size = [1] * n
def root(self, i):
inter = set()
while self.parent[i] != i:
inter.add(i)
i = self.parent[i]
r = i
for i in inter:
self.parent[i] = r
return r
def connect(self, i, j):
if i == j:
return
ri = self.root(i)
rj = self.root(j)
if ri == rj:
return
if self.size[ri] < self.size[rj]:
self.parent[ri] = rj
self.size[rj] += self.size[ri]
else:
self.parent[rj] = ri
self.size[ri] += self.size[rj]
n = int(input())
uf = UnionFindTree(n)
ps = list(map(int, input().split()))
k = 0
for i, p in enumerate(ps):
if p < 0:
k += 1
continue
uf.connect(i, p - 1)
for i in range(n):
uf.root(i)
from collections import Counter, defaultdict
M = 10**9 + 7
ncount = Counter(uf.parent)
mcount = defaultdict(int)
for i, g in enumerate(uf.parent):
if ps[i] == -1:
mcount[g] += 1
ans = sum(v - 1 for v in ncount.values())
ans *= pow(n - 1, k, M)
for kk in ncount.keys():
ncount[kk] -= mcount[kk]
for kk, mm in mcount.items():
if mm == 0:
continue
nn = ncount[kk]
ans += (n - mm - nn) * pow(n - 1, k - 1, M) * mm
ans %= M
nums = [nn + mcount[k] for k, nn in ncount.items() if mcount[k]]
l = len(nums)
dp = [[0] * l for _ in range(l)]
# dp[i][j] : i番目まで使うときの周期j+1の個数
if nums:
dp[0][0] = nums[0]
for i in range(1, l):
dp[i][0] = dp[i - 1][0] + nums[i]
for i in range(1, l):
for j in range(1, l):
dp[i][j] += dp[i - 1][j - 1] * nums[i] * j + dp[i - 1][j]
dp[i][j] %= M
for j in range(1, l):
ans -= dp[-1][j] * pow(n - 1, l - j - 1, M)
print(ans)
| Statement
There are N towns numbered 1, 2, \cdots, N.
Some roads are planned to be built so that each of them connects two distinct
towns bidirectionally. Currently, there are no roads connecting towns.
In the planning of construction, each town chooses one town different from
itself and requests the following: roads are built so that the chosen town is
reachable from itself using one or more roads.
These requests from the towns are represented by an array P_1, P_2, \cdots,
P_N. If P_i = -1, it means that Town i has not chosen the request; if 1 \leq
P_i \leq N, it means that Town i has chosen Town P_i.
Let K be the number of towns i such that P_i = -1. There are (N-1)^K ways in
which the towns can make the requests. For each way to make requests, find the
minimum number of roads needed to meet all the requests, and print the sum of
those (N-1)^K numbers, modulo (10^9+7). | [{"input": "4\n 2 1 -1 3", "output": "8\n \n\nThere are three ways to make requests, as follows:\n\n * Choose P_1 = 2, P_2 = 1, P_3 = 1, P_4 = 3. In this case, at least three roads - for example, (1,2),(1,3),(3,4) \\- are needed to meet the requests.\n * Choose P_1 = 2, P_2 = 1, P_3 = 2, P_4 = 3. In this case, at least three roads - for example, (1,2),(1,3),(3,4) \\- are needed to meet the requests.\n * Choose P_1 = 2, P_2 = 1, P_3 = 4, P_4 = 3. In this case, at least two roads - for example, (1,2),(3,4) \\- are needed to meet the requests.\n\nNote that it is not mandatory to connect Town i and Town P_i directly.\n\nThe sum of the above numbers is 8.\n\n* * *"}, {"input": "2\n 2 1", "output": "1\n \n\nThere may be just one fixed way to make requests.\n\n* * *"}, {"input": "10\n 2 6 9 -1 6 9 -1 -1 -1 -1", "output": "527841"}] |
For each way to make requests, find the minimum number of roads needed to meet
all the requests, and print the sum of those (N-1)^K numbers, modulo (10^9+7).
* * * | s361408420 | Wrong Answer | p02666 | Input is given from Standard Input in the following format:
N
P_1 P_2 \cdots P_N | N = int(input())
A = list(map(int, input().split()))
MOD = 10**9 + 7
yet = []
belongto = [-1] * N
group = []
groupsize = []
for i in range(N):
if A[i] > 0:
nex = A[i] - 1
if belongto[nex] < 0 and belongto[i] < 0:
belongto[nex] = len(group)
belongto[i] = len(group)
group.append([i + 1, A[i]])
elif belongto[nex] >= 0 and belongto[i] < 0:
belongto[i] = belongto[nex]
group[belongto[A[i] - 1]].append(i + 1)
elif belongto[nex] < 0 and belongto[i] >= 0:
belongto[nex] = belongto[i]
group[belongto[i]].append(A[i])
elif belongto[nex] == belongto[i]:
continue
elif belongto[nex] >= 0 and belongto[i] >= 0:
ori_group = belongto[nex]
for j in group[belongto[nex]]:
belongto[j - 1] = belongto[i]
group[belongto[i]] += group[ori_group]
group[ori_group] = []
elif A[i] < 0:
yet.append(i + 1)
if belongto[i] == -1:
belongto[i] = len(group)
group.append([i + 1])
for i in range(len(group)):
groupsize.append(len(group[i]))
if len(yet) > 0:
comb = [[0] * len(yet) for _ in range(len(yet))]
comb[0][0] = groupsize[belongto[yet[0] - 1]] - 1
for i in range(len(yet) - 1):
comb[i + 1][0] = comb[i][0] + groupsize[belongto[yet[i + 1] - 1]] - 1
comb[i + 1][1] = (
(comb[i][0] + i + 1) * groupsize[belongto[yet[i + 1] - 1]]
) % MOD
for j in range(1, i + 1):
comb[i + 1][j] = comb[i][j] + comb[i + 1][j]
comb[i + 1][j + 1] = (
comb[i][j] * groupsize[belongto[yet[i + 1] - 1]] * (j + 1)
) % MOD
groupnum = 0
for agroup in group:
if len(agroup) > 0:
groupnum += 1
del group
del belongto
del A
total = (N - (groupnum - len(yet))) % MOD
if len(yet) == 0:
print(total)
else:
for i in range(len(yet)):
total = (total * (N - 1)) % MOD
total = total - comb[len(yet) - 1][i]
print(total)
| Statement
There are N towns numbered 1, 2, \cdots, N.
Some roads are planned to be built so that each of them connects two distinct
towns bidirectionally. Currently, there are no roads connecting towns.
In the planning of construction, each town chooses one town different from
itself and requests the following: roads are built so that the chosen town is
reachable from itself using one or more roads.
These requests from the towns are represented by an array P_1, P_2, \cdots,
P_N. If P_i = -1, it means that Town i has not chosen the request; if 1 \leq
P_i \leq N, it means that Town i has chosen Town P_i.
Let K be the number of towns i such that P_i = -1. There are (N-1)^K ways in
which the towns can make the requests. For each way to make requests, find the
minimum number of roads needed to meet all the requests, and print the sum of
those (N-1)^K numbers, modulo (10^9+7). | [{"input": "4\n 2 1 -1 3", "output": "8\n \n\nThere are three ways to make requests, as follows:\n\n * Choose P_1 = 2, P_2 = 1, P_3 = 1, P_4 = 3. In this case, at least three roads - for example, (1,2),(1,3),(3,4) \\- are needed to meet the requests.\n * Choose P_1 = 2, P_2 = 1, P_3 = 2, P_4 = 3. In this case, at least three roads - for example, (1,2),(1,3),(3,4) \\- are needed to meet the requests.\n * Choose P_1 = 2, P_2 = 1, P_3 = 4, P_4 = 3. In this case, at least two roads - for example, (1,2),(3,4) \\- are needed to meet the requests.\n\nNote that it is not mandatory to connect Town i and Town P_i directly.\n\nThe sum of the above numbers is 8.\n\n* * *"}, {"input": "2\n 2 1", "output": "1\n \n\nThere may be just one fixed way to make requests.\n\n* * *"}, {"input": "10\n 2 6 9 -1 6 9 -1 -1 -1 -1", "output": "527841"}] |
For each way to make requests, find the minimum number of roads needed to meet
all the requests, and print the sum of those (N-1)^K numbers, modulo (10^9+7).
* * * | s854113896 | Wrong Answer | p02666 | Input is given from Standard Input in the following format:
N
P_1 P_2 \cdots P_N | N = int(input())
P_list = list(map(int, input().split()))
class UnionFind:
def __init__(self, n):
self.groups = [g for g in range(n)]
def get_root(self, node):
parent = self.groups[node]
if parent == node:
return parent
else:
root = parent
parent = self.groups[parent]
while root != parent:
root = parent
parent = self.groups[parent]
while node != root:
tmp = self.groups[node]
self.groups[node] = root
node = tmp
return root
def set_root(self, node, root):
parent = self.groups[node]
while parent != root:
self.groups[node] = root
node = parent
parent = self.groups[node]
def combine(self, i1, i2):
self.set_root(i2, self.get_root(i1))
def in_same_group(self, i1, i2):
return self.get_root(i1) == self.get_root(i2)
def to_counts(self):
table = [None] * len(self.groups)
for i in range(len(self.groups)):
g = self.get_root(i)
if table[g] != None:
table[g] += 1
else:
table[g] = 1
for i in range(len(self.groups)):
table[i] = table[self.get_root(i)]
return table
def to_list_list(self):
table = [[] for _ in range(len(self.groups))]
for i in range(len(self.groups)):
g = self.get_root(i)
if table[g] != None:
table[g].append(i)
else:
table[g] = [i]
for i in range(len(self.groups)):
table[i] = table[self.get_root(i)]
return table
def to_dic(self):
table = {}
for i in range(len(self.groups)):
g = self.get_root(i)
if g in table:
table[g].append(i)
else:
table[g] = [i]
return table
def to_list(self):
table = self.to_dic()
return [table[g] for g in table]
uf = UnionFind(N)
not_decided = set()
for i, p in enumerate(P_list):
if p >= 1:
p -= 1
uf.combine(i, p)
else:
not_decided.add(i)
total_bridges = 0
groups = uf.to_list()
not_decided_counts = []
for group in groups:
count = 0
for i in group:
if i in not_decided:
count += 1
not_decided_counts.append(count)
total_bridges += len(group) - 1
# print(groups)
# print(not_decided_counts)
# print(total_bridges)
M = 10**9 + 7
not_decided_count = len(not_decided)
total = ((total_bridges + not_decided_count) * pow(N - 1, not_decided_count, M)) % M
for i in range(len(groups)):
g1 = groups[i]
c1 = not_decided_counts[i]
if c1 > 0:
l1 = len(g1)
total = (total - (l1 - 1) * pow(N - 1, not_decided_count - c1, M)) % M
for j in range(i + 1, len(groups)):
g2 = groups[j]
c2 = not_decided_counts[j]
if c2 > 0:
l2 = len(g2)
# print(not_decided_count, c1, c2)
total = (
total - (l1 * l2) * pow(N - 1, not_decided_count - c1 - c2, M)
) % M
print(total)
| Statement
There are N towns numbered 1, 2, \cdots, N.
Some roads are planned to be built so that each of them connects two distinct
towns bidirectionally. Currently, there are no roads connecting towns.
In the planning of construction, each town chooses one town different from
itself and requests the following: roads are built so that the chosen town is
reachable from itself using one or more roads.
These requests from the towns are represented by an array P_1, P_2, \cdots,
P_N. If P_i = -1, it means that Town i has not chosen the request; if 1 \leq
P_i \leq N, it means that Town i has chosen Town P_i.
Let K be the number of towns i such that P_i = -1. There are (N-1)^K ways in
which the towns can make the requests. For each way to make requests, find the
minimum number of roads needed to meet all the requests, and print the sum of
those (N-1)^K numbers, modulo (10^9+7). | [{"input": "4\n 2 1 -1 3", "output": "8\n \n\nThere are three ways to make requests, as follows:\n\n * Choose P_1 = 2, P_2 = 1, P_3 = 1, P_4 = 3. In this case, at least three roads - for example, (1,2),(1,3),(3,4) \\- are needed to meet the requests.\n * Choose P_1 = 2, P_2 = 1, P_3 = 2, P_4 = 3. In this case, at least three roads - for example, (1,2),(1,3),(3,4) \\- are needed to meet the requests.\n * Choose P_1 = 2, P_2 = 1, P_3 = 4, P_4 = 3. In this case, at least two roads - for example, (1,2),(3,4) \\- are needed to meet the requests.\n\nNote that it is not mandatory to connect Town i and Town P_i directly.\n\nThe sum of the above numbers is 8.\n\n* * *"}, {"input": "2\n 2 1", "output": "1\n \n\nThere may be just one fixed way to make requests.\n\n* * *"}, {"input": "10\n 2 6 9 -1 6 9 -1 -1 -1 -1", "output": "527841"}] |
For each way to make requests, find the minimum number of roads needed to meet
all the requests, and print the sum of those (N-1)^K numbers, modulo (10^9+7).
* * * | s389517821 | Wrong Answer | p02666 | Input is given from Standard Input in the following format:
N
P_1 P_2 \cdots P_N | def dfs(i):
stack = [i]
used[i] = True
cnt = 1
is_white = False
while stack:
v = stack.pop()
if p[v] == -1:
is_white = True
for nxt_v in graph[v]:
if used[nxt_v]:
continue
stack.append(nxt_v)
used[nxt_v] = True
cnt += 1
return cnt, is_white
n = int(input())
p = list(map(int, input().split()))
MOD = 10**9 + 7
graph = [set() for i in range(n)]
for a in range(n):
if p[a] == -1:
continue
b = p[a] - 1
graph[a].add(b)
graph[b].add(a)
used = [False] * n
white = []
black = []
for i in range(n):
if not used[i]:
cnt, is_white = dfs(i)
if is_white:
white.append(cnt)
else:
black.append(cnt)
# S[i][j] := i個(区別する)をkグループ(区別しない)に分ける場合の数
box = len(white)
ball = len(white)
ru_white = [0] * (len(white) + 1)
for i in range(len(white)):
ru_white[i + 1] = ru_white[i] + white[i]
S = [[0] * (box + 1) for i in range(ball + 1)]
S[0][0] = 1
for i in range(ball):
for j in range(box):
S[i + 1][j + 1] = S[i][j] + S[i][j + 1] * ru_white[j + 1]
S[i + 1][j + 1] %= MOD
# わかりません
print(sum(S[-1]))
| Statement
There are N towns numbered 1, 2, \cdots, N.
Some roads are planned to be built so that each of them connects two distinct
towns bidirectionally. Currently, there are no roads connecting towns.
In the planning of construction, each town chooses one town different from
itself and requests the following: roads are built so that the chosen town is
reachable from itself using one or more roads.
These requests from the towns are represented by an array P_1, P_2, \cdots,
P_N. If P_i = -1, it means that Town i has not chosen the request; if 1 \leq
P_i \leq N, it means that Town i has chosen Town P_i.
Let K be the number of towns i such that P_i = -1. There are (N-1)^K ways in
which the towns can make the requests. For each way to make requests, find the
minimum number of roads needed to meet all the requests, and print the sum of
those (N-1)^K numbers, modulo (10^9+7). | [{"input": "4\n 2 1 -1 3", "output": "8\n \n\nThere are three ways to make requests, as follows:\n\n * Choose P_1 = 2, P_2 = 1, P_3 = 1, P_4 = 3. In this case, at least three roads - for example, (1,2),(1,3),(3,4) \\- are needed to meet the requests.\n * Choose P_1 = 2, P_2 = 1, P_3 = 2, P_4 = 3. In this case, at least three roads - for example, (1,2),(1,3),(3,4) \\- are needed to meet the requests.\n * Choose P_1 = 2, P_2 = 1, P_3 = 4, P_4 = 3. In this case, at least two roads - for example, (1,2),(3,4) \\- are needed to meet the requests.\n\nNote that it is not mandatory to connect Town i and Town P_i directly.\n\nThe sum of the above numbers is 8.\n\n* * *"}, {"input": "2\n 2 1", "output": "1\n \n\nThere may be just one fixed way to make requests.\n\n* * *"}, {"input": "10\n 2 6 9 -1 6 9 -1 -1 -1 -1", "output": "527841"}] |
For each way to make requests, find the minimum number of roads needed to meet
all the requests, and print the sum of those (N-1)^K numbers, modulo (10^9+7).
* * * | s446085387 | Wrong Answer | p02666 | Input is given from Standard Input in the following format:
N
P_1 P_2 \cdots P_N | def main():
N = int(input())
P = list(map(int, input().split()))
mod = pow(10, 9) + 7
a = set()
for i in range(N):
if P[i] != -1:
if i < P[i] - 1:
a.add((i, P[i] - 1))
else:
a.add((P[i] - 1, i))
l = len(a) % mod
if -1 not in P:
return l
parent = [i for i in range(N)]
def find(parent, i):
if i != parent[i]:
parent[i] = find(parent, parent[i])
return parent[i]
def union(parent, i, j):
pi, pj = find(parent, i), find(parent, j)
if pi != pj:
parent[pi] = pj
for i in range(N):
if P[i] != -1:
union(parent, i, P[i] - 1)
for i in range(N):
find(parent, i)
ans = 0
for i in range(N):
if P[i] == -1:
for j in range(N):
if j != i:
if parent[i] != parent[j]:
ans += l + 1
else:
ans += l
ans %= mod
return ans
if __name__ == "__main__":
print(main())
| Statement
There are N towns numbered 1, 2, \cdots, N.
Some roads are planned to be built so that each of them connects two distinct
towns bidirectionally. Currently, there are no roads connecting towns.
In the planning of construction, each town chooses one town different from
itself and requests the following: roads are built so that the chosen town is
reachable from itself using one or more roads.
These requests from the towns are represented by an array P_1, P_2, \cdots,
P_N. If P_i = -1, it means that Town i has not chosen the request; if 1 \leq
P_i \leq N, it means that Town i has chosen Town P_i.
Let K be the number of towns i such that P_i = -1. There are (N-1)^K ways in
which the towns can make the requests. For each way to make requests, find the
minimum number of roads needed to meet all the requests, and print the sum of
those (N-1)^K numbers, modulo (10^9+7). | [{"input": "4\n 2 1 -1 3", "output": "8\n \n\nThere are three ways to make requests, as follows:\n\n * Choose P_1 = 2, P_2 = 1, P_3 = 1, P_4 = 3. In this case, at least three roads - for example, (1,2),(1,3),(3,4) \\- are needed to meet the requests.\n * Choose P_1 = 2, P_2 = 1, P_3 = 2, P_4 = 3. In this case, at least three roads - for example, (1,2),(1,3),(3,4) \\- are needed to meet the requests.\n * Choose P_1 = 2, P_2 = 1, P_3 = 4, P_4 = 3. In this case, at least two roads - for example, (1,2),(3,4) \\- are needed to meet the requests.\n\nNote that it is not mandatory to connect Town i and Town P_i directly.\n\nThe sum of the above numbers is 8.\n\n* * *"}, {"input": "2\n 2 1", "output": "1\n \n\nThere may be just one fixed way to make requests.\n\n* * *"}, {"input": "10\n 2 6 9 -1 6 9 -1 -1 -1 -1", "output": "527841"}] |
For each way to make requests, find the minimum number of roads needed to meet
all the requests, and print the sum of those (N-1)^K numbers, modulo (10^9+7).
* * * | s315932548 | Runtime Error | p02666 | Input is given from Standard Input in the following format:
N
P_1 P_2 \cdots P_N | import sys
import numpy as np
def Ii():
return int(sys.stdin.buffer.readline())
def Mi():
return map(int, sys.stdin.buffer.readline().split())
def Li():
return list(map(int, sys.stdin.buffer.readline().split()))
n = Ii()
a = Li()
b = [0] * (n + 1)
bm = [0] * (n + 1)
b[0] = 1
bm[-1] = a[-1]
for i in range(1, n + 1):
bm[-1 - i] = bm[-i] + a[-i - 1]
b[i] = (b[i - 1] - a[i - 1]) * 2
b = np.array(b)
bm = np.array(bm)
c = np.amin([[b], [bm]], axis=0)
if np.any(c == 0):
print(-1)
else:
print(np.sum(c))
| Statement
There are N towns numbered 1, 2, \cdots, N.
Some roads are planned to be built so that each of them connects two distinct
towns bidirectionally. Currently, there are no roads connecting towns.
In the planning of construction, each town chooses one town different from
itself and requests the following: roads are built so that the chosen town is
reachable from itself using one or more roads.
These requests from the towns are represented by an array P_1, P_2, \cdots,
P_N. If P_i = -1, it means that Town i has not chosen the request; if 1 \leq
P_i \leq N, it means that Town i has chosen Town P_i.
Let K be the number of towns i such that P_i = -1. There are (N-1)^K ways in
which the towns can make the requests. For each way to make requests, find the
minimum number of roads needed to meet all the requests, and print the sum of
those (N-1)^K numbers, modulo (10^9+7). | [{"input": "4\n 2 1 -1 3", "output": "8\n \n\nThere are three ways to make requests, as follows:\n\n * Choose P_1 = 2, P_2 = 1, P_3 = 1, P_4 = 3. In this case, at least three roads - for example, (1,2),(1,3),(3,4) \\- are needed to meet the requests.\n * Choose P_1 = 2, P_2 = 1, P_3 = 2, P_4 = 3. In this case, at least three roads - for example, (1,2),(1,3),(3,4) \\- are needed to meet the requests.\n * Choose P_1 = 2, P_2 = 1, P_3 = 4, P_4 = 3. In this case, at least two roads - for example, (1,2),(3,4) \\- are needed to meet the requests.\n\nNote that it is not mandatory to connect Town i and Town P_i directly.\n\nThe sum of the above numbers is 8.\n\n* * *"}, {"input": "2\n 2 1", "output": "1\n \n\nThere may be just one fixed way to make requests.\n\n* * *"}, {"input": "10\n 2 6 9 -1 6 9 -1 -1 -1 -1", "output": "527841"}] |
For each way to make requests, find the minimum number of roads needed to meet
all the requests, and print the sum of those (N-1)^K numbers, modulo (10^9+7).
* * * | s969348767 | Wrong Answer | p02666 | Input is given from Standard Input in the following format:
N
P_1 P_2 \cdots P_N | import unittest
class UnionFind:
def __init__(self, size: int):
# 負の値はルート (集合の代表) で集合の個数
# 正の値は次の要素を表す
self.size = size
self.parent = [-1] * size
def find(self, x: int) -> int:
"""
xを含む集合の代表を求める
"""
if self.parent[x] < 0:
return x
# 集合の代表にリンクを繋ぎ変える
same_group_items = []
while self.parent[x] >= 0:
same_group_items.append(x)
x = self.parent[x]
for child in same_group_items:
self.parent[child] = x
return x
def unite(self, x: int, y: int):
"""
xを含む集合とyを含む集合を併合する
"""
root_x = self.find(x)
root_y = self.find(y)
if root_x != root_y:
if self.parent[root_x] >= self.parent[root_y]:
self.parent[root_x] += self.parent[root_y]
self.parent[root_y] = root_x
else:
self.parent[root_y] += self.parent[root_x]
self.parent[root_x] = root_y
def same(self, x: int, y: int) -> bool:
return self.find(x) == self.find(y)
def count_group(self) -> int:
"""
集合の数を数える。
"""
count = 0
for i in range(self.size):
if self.parent[i] < 0:
count += 1
return count
def get_size(self, x):
return -1 * self.parent[self.find(x)]
def solve(n, ps):
mod = 10**9 + 7
undefs = []
uf = UnionFind(n)
base_cost = 0
for i in range(n):
if ps[i] == -1:
undefs.append(i)
else:
p = ps[i] - 1
if not uf.same(p, i):
base_cost += 1
uf.unite(p, i)
n_undef = len(undefs)
n_undef_pattern_p = pow(n - 1, n_undef - 2, mod)
n_undef_pattern = n_undef_pattern_p * (n - 1) * (n - 1) % mod
base_cost = base_cost * n_undef_pattern
cost = 0
for i, p in enumerate(undefs):
m = uf.get_size(p) - 1
cost += (n - 1 - m) * n_undef_pattern_p * (n - 1)
cost -= i * n_undef_pattern_p * (n - 2)
cost %= mod
# print(base_cost, cost, n_undef, n_undef_pattern)
return (base_cost + cost) % mod
def main():
n = int(input())
ps = list(map(int, input().split()))
result = solve(n, ps)
print(result)
class Test(unittest.TestCase):
def test_solve_1(self):
n = 4
p = [2, 1, -1, 3]
actual = solve(n, p)
expected = 8
self.assertEqual(actual, expected)
def test_solve_2(self):
n = 2
p = [2, 1]
actual = solve(n, p)
expected = 1
self.assertEqual(actual, expected)
def test_solve_3(self):
n = 10
p = [2, 6, 9, -1, 6, 9, -1, -1, -1, -1]
actual = solve(n, p)
expected = 527841
self.assertEqual(actual, expected)
def test_solve_4(self):
n = 2
p = [2, -1]
actual = solve(n, p)
expected = 1
self.assertEqual(actual, expected)
def test_solve_5(self):
n = 2
p = [-1, -1]
actual = solve(n, p)
expected = 1
self.assertEqual(actual, expected)
def test_solve_6(self):
n = 3
p = [-1, -1, -1]
actual = solve(n, p)
expected = 16
self.assertEqual(actual, expected)
def test_solve_7(self):
n = 4
p = [-1, -1, -1, -1]
actual = solve(n, p)
expected = 240
self.assertEqual(actual, expected)
def test_solve_8(self):
n = 4
p = [2, -1, -1, -1]
actual = solve(n, p)
expected = 80
self.assertEqual(actual, expected)
if __name__ == "__main__":
main()
| Statement
There are N towns numbered 1, 2, \cdots, N.
Some roads are planned to be built so that each of them connects two distinct
towns bidirectionally. Currently, there are no roads connecting towns.
In the planning of construction, each town chooses one town different from
itself and requests the following: roads are built so that the chosen town is
reachable from itself using one or more roads.
These requests from the towns are represented by an array P_1, P_2, \cdots,
P_N. If P_i = -1, it means that Town i has not chosen the request; if 1 \leq
P_i \leq N, it means that Town i has chosen Town P_i.
Let K be the number of towns i such that P_i = -1. There are (N-1)^K ways in
which the towns can make the requests. For each way to make requests, find the
minimum number of roads needed to meet all the requests, and print the sum of
those (N-1)^K numbers, modulo (10^9+7). | [{"input": "4\n 2 1 -1 3", "output": "8\n \n\nThere are three ways to make requests, as follows:\n\n * Choose P_1 = 2, P_2 = 1, P_3 = 1, P_4 = 3. In this case, at least three roads - for example, (1,2),(1,3),(3,4) \\- are needed to meet the requests.\n * Choose P_1 = 2, P_2 = 1, P_3 = 2, P_4 = 3. In this case, at least three roads - for example, (1,2),(1,3),(3,4) \\- are needed to meet the requests.\n * Choose P_1 = 2, P_2 = 1, P_3 = 4, P_4 = 3. In this case, at least two roads - for example, (1,2),(3,4) \\- are needed to meet the requests.\n\nNote that it is not mandatory to connect Town i and Town P_i directly.\n\nThe sum of the above numbers is 8.\n\n* * *"}, {"input": "2\n 2 1", "output": "1\n \n\nThere may be just one fixed way to make requests.\n\n* * *"}, {"input": "10\n 2 6 9 -1 6 9 -1 -1 -1 -1", "output": "527841"}] |
For each way to make requests, find the minimum number of roads needed to meet
all the requests, and print the sum of those (N-1)^K numbers, modulo (10^9+7).
* * * | s663180289 | Wrong Answer | p02666 | Input is given from Standard Input in the following format:
N
P_1 P_2 \cdots P_N | N = int(input())
cityList = list(map(int, input().split()))
result = 0
for index, toCity in enumerate(cityList):
if toCity == -1:
continue
if toCity > cityList[toCity - 1]:
continue
result += 1
print(result)
| Statement
There are N towns numbered 1, 2, \cdots, N.
Some roads are planned to be built so that each of them connects two distinct
towns bidirectionally. Currently, there are no roads connecting towns.
In the planning of construction, each town chooses one town different from
itself and requests the following: roads are built so that the chosen town is
reachable from itself using one or more roads.
These requests from the towns are represented by an array P_1, P_2, \cdots,
P_N. If P_i = -1, it means that Town i has not chosen the request; if 1 \leq
P_i \leq N, it means that Town i has chosen Town P_i.
Let K be the number of towns i such that P_i = -1. There are (N-1)^K ways in
which the towns can make the requests. For each way to make requests, find the
minimum number of roads needed to meet all the requests, and print the sum of
those (N-1)^K numbers, modulo (10^9+7). | [{"input": "4\n 2 1 -1 3", "output": "8\n \n\nThere are three ways to make requests, as follows:\n\n * Choose P_1 = 2, P_2 = 1, P_3 = 1, P_4 = 3. In this case, at least three roads - for example, (1,2),(1,3),(3,4) \\- are needed to meet the requests.\n * Choose P_1 = 2, P_2 = 1, P_3 = 2, P_4 = 3. In this case, at least three roads - for example, (1,2),(1,3),(3,4) \\- are needed to meet the requests.\n * Choose P_1 = 2, P_2 = 1, P_3 = 4, P_4 = 3. In this case, at least two roads - for example, (1,2),(3,4) \\- are needed to meet the requests.\n\nNote that it is not mandatory to connect Town i and Town P_i directly.\n\nThe sum of the above numbers is 8.\n\n* * *"}, {"input": "2\n 2 1", "output": "1\n \n\nThere may be just one fixed way to make requests.\n\n* * *"}, {"input": "10\n 2 6 9 -1 6 9 -1 -1 -1 -1", "output": "527841"}] |
For each way to make requests, find the minimum number of roads needed to meet
all the requests, and print the sum of those (N-1)^K numbers, modulo (10^9+7).
* * * | s585317144 | Wrong Answer | p02666 | Input is given from Standard Input in the following format:
N
P_1 P_2 \cdots P_N | N = int(input())
P = list(map(int, input().split()))
NUM = 10**9 + 7
for i in range(len(P)):
P[i] -= 1
# 基本的な道の数
# 既知→未知の道の数
base = N
cnt = 0
k_unk_num = 0
for i, value in enumerate(P):
if value >= 0:
if P[value] == i:
cnt += 1
elif P[value] == -2:
k_unk_num += 1
base -= cnt // 2
# 未知の道の数
unknown_num = 0
for i in P:
if i < 0:
unknown_num += 1
# print(base, unknown_num, k_unk_num)
ans = 0
ans = (ans + base * (N - 1) ** unknown_num) % NUM
# print(ans)
ans = int(ans - k_unk_num * (N - 1) ** (unknown_num - 1) + NUM) % NUM
# print(ans)
if unknown_num > 1:
ans = (
ans
- (unknown_num * (unknown_num - 1) // 2) * (N - 1) ** (unknown_num - 2)
+ NUM
) % NUM
print(ans)
| Statement
There are N towns numbered 1, 2, \cdots, N.
Some roads are planned to be built so that each of them connects two distinct
towns bidirectionally. Currently, there are no roads connecting towns.
In the planning of construction, each town chooses one town different from
itself and requests the following: roads are built so that the chosen town is
reachable from itself using one or more roads.
These requests from the towns are represented by an array P_1, P_2, \cdots,
P_N. If P_i = -1, it means that Town i has not chosen the request; if 1 \leq
P_i \leq N, it means that Town i has chosen Town P_i.
Let K be the number of towns i such that P_i = -1. There are (N-1)^K ways in
which the towns can make the requests. For each way to make requests, find the
minimum number of roads needed to meet all the requests, and print the sum of
those (N-1)^K numbers, modulo (10^9+7). | [{"input": "4\n 2 1 -1 3", "output": "8\n \n\nThere are three ways to make requests, as follows:\n\n * Choose P_1 = 2, P_2 = 1, P_3 = 1, P_4 = 3. In this case, at least three roads - for example, (1,2),(1,3),(3,4) \\- are needed to meet the requests.\n * Choose P_1 = 2, P_2 = 1, P_3 = 2, P_4 = 3. In this case, at least three roads - for example, (1,2),(1,3),(3,4) \\- are needed to meet the requests.\n * Choose P_1 = 2, P_2 = 1, P_3 = 4, P_4 = 3. In this case, at least two roads - for example, (1,2),(3,4) \\- are needed to meet the requests.\n\nNote that it is not mandatory to connect Town i and Town P_i directly.\n\nThe sum of the above numbers is 8.\n\n* * *"}, {"input": "2\n 2 1", "output": "1\n \n\nThere may be just one fixed way to make requests.\n\n* * *"}, {"input": "10\n 2 6 9 -1 6 9 -1 -1 -1 -1", "output": "527841"}] |
For each way to make requests, find the minimum number of roads needed to meet
all the requests, and print the sum of those (N-1)^K numbers, modulo (10^9+7).
* * * | s660910515 | Wrong Answer | p02666 | Input is given from Standard Input in the following format:
N
P_1 P_2 \cdots P_N | mod = 10**9 + 7
def modInv(x, m=mod):
return pow(x, m - 2, m) % m
def modDiv(x, y, m=mod):
return x * modInv(y, m) % m
def modnCr(n, r, m=mod):
if n == 0:
return 0
if r > n - r:
r = n - r
denom = 1
numer = 1
for i in range(r):
denom = (n - i) * denom % m
numer = (i + 1) * numer % m
return modInv(numer, m) * denom % m
n = int(input().strip())
L = list(map(int, input().strip().split()))
to = [set() for _ in range(n)]
default = 0
k = 0
for i, v in enumerate(L):
if v == -1:
k += 1
continue
if v - 1 not in to[i]:
default += 1
to[i].add(v - 1)
to[v - 1].add(i)
already = 0
for i in range(n):
if L[i] == -1:
already += len(to[i])
ans = (default + k) * pow(n - 1, k, mod) % mod
if k:
ans -= pow((already + modnCr(k, 2)) * (n - 1) % mod, k - 1, mod)
print(ans % mod)
| Statement
There are N towns numbered 1, 2, \cdots, N.
Some roads are planned to be built so that each of them connects two distinct
towns bidirectionally. Currently, there are no roads connecting towns.
In the planning of construction, each town chooses one town different from
itself and requests the following: roads are built so that the chosen town is
reachable from itself using one or more roads.
These requests from the towns are represented by an array P_1, P_2, \cdots,
P_N. If P_i = -1, it means that Town i has not chosen the request; if 1 \leq
P_i \leq N, it means that Town i has chosen Town P_i.
Let K be the number of towns i such that P_i = -1. There are (N-1)^K ways in
which the towns can make the requests. For each way to make requests, find the
minimum number of roads needed to meet all the requests, and print the sum of
those (N-1)^K numbers, modulo (10^9+7). | [{"input": "4\n 2 1 -1 3", "output": "8\n \n\nThere are three ways to make requests, as follows:\n\n * Choose P_1 = 2, P_2 = 1, P_3 = 1, P_4 = 3. In this case, at least three roads - for example, (1,2),(1,3),(3,4) \\- are needed to meet the requests.\n * Choose P_1 = 2, P_2 = 1, P_3 = 2, P_4 = 3. In this case, at least three roads - for example, (1,2),(1,3),(3,4) \\- are needed to meet the requests.\n * Choose P_1 = 2, P_2 = 1, P_3 = 4, P_4 = 3. In this case, at least two roads - for example, (1,2),(3,4) \\- are needed to meet the requests.\n\nNote that it is not mandatory to connect Town i and Town P_i directly.\n\nThe sum of the above numbers is 8.\n\n* * *"}, {"input": "2\n 2 1", "output": "1\n \n\nThere may be just one fixed way to make requests.\n\n* * *"}, {"input": "10\n 2 6 9 -1 6 9 -1 -1 -1 -1", "output": "527841"}] |
Output Q lines.
On line i, for the i-th query, output an integer indicating the sequence of
the string S_{k_i} among the N strings in lexicographical order.
* * * | s359401108 | Wrong Answer | p03974 | Inputs are provided from standard inputs in the following form.
N
S_1
:
S_N
Q
k_1 p_{1,1}p_{1,2}...p_{1,26}
:
k_Q p_{Q,1}p_{Q,2}...p_{Q,26} | import math
def conv26to10(S, k):
num10 = 0
j = 0
for i in reversed(range(len(S))):
# print(i)
key = k.find(S[i])
num10 = key * math.pow(26, j) + num10
# print(num10)
j = j + 1
return num10
if __name__ == "__main__":
N = int(input())
S = [str(input()) for i in range(N)]
Q = int(input())
K = [[str(i) for i in input().split()] for i in range(Q)]
numlist = [0] * N
for query in range(Q):
for i in range(N):
numlist[i] = conv26to10(S[i], K[query][1])
target = sorted(numlist)[int(K[query][0]) - 1]
print(numlist.index(target) + 1)
| Statement
There are N strings of lowercase alphabet only. The i-th string is S_i. Every
string is unique.
Provide answers for the Q queries below. The i-th query has the following
format:
Query: An integer k_i and a string p_{i,1}p_{i,2}...p_{i,26} that results from
permuting {`a`,`b`,...,`z`} are given. Output the sequence of the string
S_{k_i} among the N strings in lexicographical order when the literal sequence
is p_{i,1}<p_{i,2}<...<p_{i,26}. | [{"input": "5\n aa\n abbaa\n abbba\n aaab\n aaaaaba\n 5\n 1 abcdefghijklmnopqrstuvwxyz\n 2 bacdefghijklmnopqrstuvwxyz\n 3 abcdefghijklmnopqrstuvwxyz\n 4 bacdefghijklmnopqrstuvwxyz\n 5 abcdefghijklmnopqrstuvwxyz", "output": "1\n 2\n 5\n 4\n 2\n \n\nWhen the literal sequence is `a` < `b`, sorting the input strings in\nlexicographical order yields `aa`, `aaaaaba`, `aaab`, `abbaa`, `abbba`. The\nanswers to queries 1, 3, and 5 are thus 1, 5, and 2, respectively.\n\nWhen the literal sequence is `b` < `a`, sorting the input strings in\nlexicographical order yields `abbba`, `abbaa`, `aa`, `aaab`, `aaaaaba`. The\nanswers to queries 2 and 4 are thus 2 and 4, respectively.\n\n* * *"}, {"input": "8\n abrakatabra\n abadaba\n abracadabra\n atcoder\n grand\n contest\n ababa\n a\n 6\n 3 abcdefghijklmnopqrstuvwxyz\n 6 qwertyuiopasdfghjklzxcvbnm\n 8 poiuytrewqlkjhgfdsamnbvcxz\n 2 qazwsxedcrfvtgbyhnujmikolp\n 1 plokmijnuhbygvtfcrdxeszwaq\n 4 mnbvcxzasdfghjklpoiuytrewq", "output": "4\n 8\n 2\n 3\n 4\n 7"}] |
Output Q lines.
On line i, for the i-th query, output an integer indicating the sequence of
the string S_{k_i} among the N strings in lexicographical order.
* * * | s448854847 | Runtime Error | p03974 | Inputs are provided from standard inputs in the following form.
N
S_1
:
S_N
Q
k_1 p_{1,1}p_{1,2}...p_{1,26}
:
k_Q p_{Q,1}p_{Q,2}...p_{Q,26} | import array
R = range
L = input
T = [0] * 28
N = int(L())
S = []
U = N * 26**2 * array.array("i", [0])
V = N * [0]
Q = int(L())
for I in R(N):
S += [[ord(C) - 95 for C in L()]]
P = 0
for C in S[I]:
if T[P + C] == 0:
T[P + C] = len(T)
T += [0] * 28
T[P] += 1
P = T[P + C]
T[P] += 1
T[P + 1] = 1
while N:
N -= 1
P = 0
for C in S[N]:
for A in R(26):
X = T[P + A + 2]
if (A != C - 2) * X:
U[676 * N + 26 * A + C - 2] += T[X]
V[N] += T[P + 1]
P = T[P + C]
while Q:
K, P = L().split()
K = int(K) - 1
P = [ord(C) - 97 for C in P]
X = 1 + V[K]
for A in R(26):
for B in R(A + 1, 26):
X += U[676 * K + 26 * P[A] + P[B]]
print(X)
Q -= 1
| Statement
There are N strings of lowercase alphabet only. The i-th string is S_i. Every
string is unique.
Provide answers for the Q queries below. The i-th query has the following
format:
Query: An integer k_i and a string p_{i,1}p_{i,2}...p_{i,26} that results from
permuting {`a`,`b`,...,`z`} are given. Output the sequence of the string
S_{k_i} among the N strings in lexicographical order when the literal sequence
is p_{i,1}<p_{i,2}<...<p_{i,26}. | [{"input": "5\n aa\n abbaa\n abbba\n aaab\n aaaaaba\n 5\n 1 abcdefghijklmnopqrstuvwxyz\n 2 bacdefghijklmnopqrstuvwxyz\n 3 abcdefghijklmnopqrstuvwxyz\n 4 bacdefghijklmnopqrstuvwxyz\n 5 abcdefghijklmnopqrstuvwxyz", "output": "1\n 2\n 5\n 4\n 2\n \n\nWhen the literal sequence is `a` < `b`, sorting the input strings in\nlexicographical order yields `aa`, `aaaaaba`, `aaab`, `abbaa`, `abbba`. The\nanswers to queries 1, 3, and 5 are thus 1, 5, and 2, respectively.\n\nWhen the literal sequence is `b` < `a`, sorting the input strings in\nlexicographical order yields `abbba`, `abbaa`, `aa`, `aaab`, `aaaaaba`. The\nanswers to queries 2 and 4 are thus 2 and 4, respectively.\n\n* * *"}, {"input": "8\n abrakatabra\n abadaba\n abracadabra\n atcoder\n grand\n contest\n ababa\n a\n 6\n 3 abcdefghijklmnopqrstuvwxyz\n 6 qwertyuiopasdfghjklzxcvbnm\n 8 poiuytrewqlkjhgfdsamnbvcxz\n 2 qazwsxedcrfvtgbyhnujmikolp\n 1 plokmijnuhbygvtfcrdxeszwaq\n 4 mnbvcxzasdfghjklpoiuytrewq", "output": "4\n 8\n 2\n 3\n 4\n 7"}] |
Output Q lines.
On line i, for the i-th query, output an integer indicating the sequence of
the string S_{k_i} among the N strings in lexicographical order.
* * * | s978772386 | Wrong Answer | p03974 | Inputs are provided from standard inputs in the following form.
N
S_1
:
S_N
Q
k_1 p_{1,1}p_{1,2}...p_{1,26}
:
k_Q p_{Q,1}p_{Q,2}...p_{Q,26} | N = int(input())
S = []
for i in range(N):
S.append(input())
Q = int(input())
kp = []
orderd = "abcdefghijklmnopqrstuvwxyz"
for i in range(Q):
l = input()
kp.append([int(l.split()[0]), l.split()[1]])
SS = sorted(S)
for i, s in enumerate(kp):
if s[1] == orderd:
print(SS.index(S[s[0] - 1]) + 1)
else:
print(i + 1)
| Statement
There are N strings of lowercase alphabet only. The i-th string is S_i. Every
string is unique.
Provide answers for the Q queries below. The i-th query has the following
format:
Query: An integer k_i and a string p_{i,1}p_{i,2}...p_{i,26} that results from
permuting {`a`,`b`,...,`z`} are given. Output the sequence of the string
S_{k_i} among the N strings in lexicographical order when the literal sequence
is p_{i,1}<p_{i,2}<...<p_{i,26}. | [{"input": "5\n aa\n abbaa\n abbba\n aaab\n aaaaaba\n 5\n 1 abcdefghijklmnopqrstuvwxyz\n 2 bacdefghijklmnopqrstuvwxyz\n 3 abcdefghijklmnopqrstuvwxyz\n 4 bacdefghijklmnopqrstuvwxyz\n 5 abcdefghijklmnopqrstuvwxyz", "output": "1\n 2\n 5\n 4\n 2\n \n\nWhen the literal sequence is `a` < `b`, sorting the input strings in\nlexicographical order yields `aa`, `aaaaaba`, `aaab`, `abbaa`, `abbba`. The\nanswers to queries 1, 3, and 5 are thus 1, 5, and 2, respectively.\n\nWhen the literal sequence is `b` < `a`, sorting the input strings in\nlexicographical order yields `abbba`, `abbaa`, `aa`, `aaab`, `aaaaaba`. The\nanswers to queries 2 and 4 are thus 2 and 4, respectively.\n\n* * *"}, {"input": "8\n abrakatabra\n abadaba\n abracadabra\n atcoder\n grand\n contest\n ababa\n a\n 6\n 3 abcdefghijklmnopqrstuvwxyz\n 6 qwertyuiopasdfghjklzxcvbnm\n 8 poiuytrewqlkjhgfdsamnbvcxz\n 2 qazwsxedcrfvtgbyhnujmikolp\n 1 plokmijnuhbygvtfcrdxeszwaq\n 4 mnbvcxzasdfghjklpoiuytrewq", "output": "4\n 8\n 2\n 3\n 4\n 7"}] |
Output Q lines.
On line i, for the i-th query, output an integer indicating the sequence of
the string S_{k_i} among the N strings in lexicographical order.
* * * | s577403388 | Wrong Answer | p03974 | Inputs are provided from standard inputs in the following form.
N
S_1
:
S_N
Q
k_1 p_{1,1}p_{1,2}...p_{1,26}
:
k_Q p_{Q,1}p_{Q,2}...p_{Q,26} | N = int(input())
S = [input() for _ in range(N)]
Q = int(input())
S.sort()
k, p = zip(*map(lambda x: (int(x[0]), x[1]), [input().split() for _ in range(Q)]))
for q in range(Q):
print(q)
| Statement
There are N strings of lowercase alphabet only. The i-th string is S_i. Every
string is unique.
Provide answers for the Q queries below. The i-th query has the following
format:
Query: An integer k_i and a string p_{i,1}p_{i,2}...p_{i,26} that results from
permuting {`a`,`b`,...,`z`} are given. Output the sequence of the string
S_{k_i} among the N strings in lexicographical order when the literal sequence
is p_{i,1}<p_{i,2}<...<p_{i,26}. | [{"input": "5\n aa\n abbaa\n abbba\n aaab\n aaaaaba\n 5\n 1 abcdefghijklmnopqrstuvwxyz\n 2 bacdefghijklmnopqrstuvwxyz\n 3 abcdefghijklmnopqrstuvwxyz\n 4 bacdefghijklmnopqrstuvwxyz\n 5 abcdefghijklmnopqrstuvwxyz", "output": "1\n 2\n 5\n 4\n 2\n \n\nWhen the literal sequence is `a` < `b`, sorting the input strings in\nlexicographical order yields `aa`, `aaaaaba`, `aaab`, `abbaa`, `abbba`. The\nanswers to queries 1, 3, and 5 are thus 1, 5, and 2, respectively.\n\nWhen the literal sequence is `b` < `a`, sorting the input strings in\nlexicographical order yields `abbba`, `abbaa`, `aa`, `aaab`, `aaaaaba`. The\nanswers to queries 2 and 4 are thus 2 and 4, respectively.\n\n* * *"}, {"input": "8\n abrakatabra\n abadaba\n abracadabra\n atcoder\n grand\n contest\n ababa\n a\n 6\n 3 abcdefghijklmnopqrstuvwxyz\n 6 qwertyuiopasdfghjklzxcvbnm\n 8 poiuytrewqlkjhgfdsamnbvcxz\n 2 qazwsxedcrfvtgbyhnujmikolp\n 1 plokmijnuhbygvtfcrdxeszwaq\n 4 mnbvcxzasdfghjklpoiuytrewq", "output": "4\n 8\n 2\n 3\n 4\n 7"}] |
Print the number of good observatories.
* * * | s313396732 | Wrong Answer | p02689 | Input is given from Standard Input in the following format:
N M
H_1 H_2 ... H_N
A_1 B_1
A_2 B_2
:
A_M B_M | N, M = input().split()
view = [int(i) for i in input().split()]
result = set()
remove = set()
for _ in range(int(M)):
A, B = [int(i) for i in input().split()]
if view[A - 1] > view[B - 1]:
if A not in remove:
result.add(A)
try:
remove.add(B)
result.remove(B)
except KeyError:
pass
elif view[A - 1] < view[B - 1]:
if B not in remove:
result.add(B)
try:
remove.add(A)
result.remove(A)
except KeyError:
pass
else:
if A not in remove:
result.add(A)
if B not in remove:
result.add(B)
print(len(result))
| Statement
There are N observatories in AtCoder Hill, called Obs. 1, Obs. 2, ..., Obs. N.
The elevation of Obs. i is H_i. There are also M roads, each connecting two
different observatories. Road j connects Obs. A_j and Obs. B_j.
Obs. i is said to be good when its elevation is higher than those of all
observatories that can be reached from Obs. i using just one road. Note that
Obs. i is also good when no observatory can be reached from Obs. i using just
one road.
How many good observatories are there? | [{"input": "4 3\n 1 2 3 4\n 1 3\n 2 3\n 2 4", "output": "2\n \n\n * From Obs. 1, you can reach Obs. 3 using just one road. The elevation of Obs. 1 is not higher than that of Obs. 3, so Obs. 1 is not good.\n\n * From Obs. 2, you can reach Obs. 3 and 4 using just one road. The elevation of Obs. 2 is not higher than that of Obs. 3, so Obs. 2 is not good.\n\n * From Obs. 3, you can reach Obs. 1 and 2 using just one road. The elevation of Obs. 3 is higher than those of Obs. 1 and 2, so Obs. 3 is good.\n\n * From Obs. 4, you can reach Obs. 2 using just one road. The elevation of Obs. 4 is higher than that of Obs. 2, so Obs. 4 is good.\n\nThus, the good observatories are Obs. 3 and 4, so there are two good\nobservatories.\n\n* * *"}, {"input": "6 5\n 8 6 9 1 2 1\n 1 3\n 4 2\n 4 3\n 4 6\n 4 6", "output": "3"}] |
Print the number of good observatories.
* * * | s744016817 | Accepted | p02689 | Input is given from Standard Input in the following format:
N M
H_1 H_2 ... H_N
A_1 B_1
A_2 B_2
:
A_M B_M | N, M = list(map(int, input().split()))
H_keys = [i + 1 for i in range(N)]
H_values = list(map(int, input().split()))
AB_list = [list(map(int, input().split())) for i in range(M)]
H = dict(zip(H_keys, H_values))
# H_sort = sorted(H.items(), key=lambda x:x[1])
# print(H_sort)
# temp=0
ans_list = []
for i in AB_list:
if H[i[0]] < H[i[1]]:
ans_list.append(i[0])
elif H[i[1]] < H[i[0]]:
ans_list.append(i[1])
else:
ans_list.append(i[0])
ans_list.append(i[1])
# temp+=1
# print(temp)
# print(H)
print(N - len(set(ans_list)))
| Statement
There are N observatories in AtCoder Hill, called Obs. 1, Obs. 2, ..., Obs. N.
The elevation of Obs. i is H_i. There are also M roads, each connecting two
different observatories. Road j connects Obs. A_j and Obs. B_j.
Obs. i is said to be good when its elevation is higher than those of all
observatories that can be reached from Obs. i using just one road. Note that
Obs. i is also good when no observatory can be reached from Obs. i using just
one road.
How many good observatories are there? | [{"input": "4 3\n 1 2 3 4\n 1 3\n 2 3\n 2 4", "output": "2\n \n\n * From Obs. 1, you can reach Obs. 3 using just one road. The elevation of Obs. 1 is not higher than that of Obs. 3, so Obs. 1 is not good.\n\n * From Obs. 2, you can reach Obs. 3 and 4 using just one road. The elevation of Obs. 2 is not higher than that of Obs. 3, so Obs. 2 is not good.\n\n * From Obs. 3, you can reach Obs. 1 and 2 using just one road. The elevation of Obs. 3 is higher than those of Obs. 1 and 2, so Obs. 3 is good.\n\n * From Obs. 4, you can reach Obs. 2 using just one road. The elevation of Obs. 4 is higher than that of Obs. 2, so Obs. 4 is good.\n\nThus, the good observatories are Obs. 3 and 4, so there are two good\nobservatories.\n\n* * *"}, {"input": "6 5\n 8 6 9 1 2 1\n 1 3\n 4 2\n 4 3\n 4 6\n 4 6", "output": "3"}] |
Print the number of good observatories.
* * * | s639581090 | Wrong Answer | p02689 | Input is given from Standard Input in the following format:
N M
H_1 H_2 ... H_N
A_1 B_1
A_2 B_2
:
A_M B_M | a, b = map(int, input().split())
c = list(map(int, input().split()))
f = []
g = []
for i in range(b):
d, e = map(int, input().split())
f.append(d)
if e not in f:
g.append(e)
h = set(g)
print(len(h))
| Statement
There are N observatories in AtCoder Hill, called Obs. 1, Obs. 2, ..., Obs. N.
The elevation of Obs. i is H_i. There are also M roads, each connecting two
different observatories. Road j connects Obs. A_j and Obs. B_j.
Obs. i is said to be good when its elevation is higher than those of all
observatories that can be reached from Obs. i using just one road. Note that
Obs. i is also good when no observatory can be reached from Obs. i using just
one road.
How many good observatories are there? | [{"input": "4 3\n 1 2 3 4\n 1 3\n 2 3\n 2 4", "output": "2\n \n\n * From Obs. 1, you can reach Obs. 3 using just one road. The elevation of Obs. 1 is not higher than that of Obs. 3, so Obs. 1 is not good.\n\n * From Obs. 2, you can reach Obs. 3 and 4 using just one road. The elevation of Obs. 2 is not higher than that of Obs. 3, so Obs. 2 is not good.\n\n * From Obs. 3, you can reach Obs. 1 and 2 using just one road. The elevation of Obs. 3 is higher than those of Obs. 1 and 2, so Obs. 3 is good.\n\n * From Obs. 4, you can reach Obs. 2 using just one road. The elevation of Obs. 4 is higher than that of Obs. 2, so Obs. 4 is good.\n\nThus, the good observatories are Obs. 3 and 4, so there are two good\nobservatories.\n\n* * *"}, {"input": "6 5\n 8 6 9 1 2 1\n 1 3\n 4 2\n 4 3\n 4 6\n 4 6", "output": "3"}] |
Print the number of good observatories.
* * * | s426424850 | Runtime Error | p02689 | Input is given from Standard Input in the following format:
N M
H_1 H_2 ... H_N
A_1 B_1
A_2 B_2
:
A_M B_M | n, m = map(int, input().split())
h = list(map(int, input().split()))
l = [tuple(map(int, input().split())) for i in range(m)]
x = ["B"] * n
for t in l:
if h[t[0] - 1] <= h[t[1] - 1]:
x[t[1] - 1] = "G"
x[t[0] - 1] = "B"
elif h[t[0] - 1] >= h[t[1] - 1]:
x[t[1] - 1] = "B"
x[t[0] - 1] = "G"
print(x)
print(x.count("G"))
| Statement
There are N observatories in AtCoder Hill, called Obs. 1, Obs. 2, ..., Obs. N.
The elevation of Obs. i is H_i. There are also M roads, each connecting two
different observatories. Road j connects Obs. A_j and Obs. B_j.
Obs. i is said to be good when its elevation is higher than those of all
observatories that can be reached from Obs. i using just one road. Note that
Obs. i is also good when no observatory can be reached from Obs. i using just
one road.
How many good observatories are there? | [{"input": "4 3\n 1 2 3 4\n 1 3\n 2 3\n 2 4", "output": "2\n \n\n * From Obs. 1, you can reach Obs. 3 using just one road. The elevation of Obs. 1 is not higher than that of Obs. 3, so Obs. 1 is not good.\n\n * From Obs. 2, you can reach Obs. 3 and 4 using just one road. The elevation of Obs. 2 is not higher than that of Obs. 3, so Obs. 2 is not good.\n\n * From Obs. 3, you can reach Obs. 1 and 2 using just one road. The elevation of Obs. 3 is higher than those of Obs. 1 and 2, so Obs. 3 is good.\n\n * From Obs. 4, you can reach Obs. 2 using just one road. The elevation of Obs. 4 is higher than that of Obs. 2, so Obs. 4 is good.\n\nThus, the good observatories are Obs. 3 and 4, so there are two good\nobservatories.\n\n* * *"}, {"input": "6 5\n 8 6 9 1 2 1\n 1 3\n 4 2\n 4 3\n 4 6\n 4 6", "output": "3"}] |
Print the number of good observatories.
* * * | s971896400 | Wrong Answer | p02689 | Input is given from Standard Input in the following format:
N M
H_1 H_2 ... H_N
A_1 B_1
A_2 B_2
:
A_M B_M | n, m = input().split()
height = list(input().split())
list = []
for i in range(1, int(n) + 1):
list.append(i)
for i in range(int(m)):
a, b = input().split()
a = int(a)
b = int(b)
if int(height[a - 1]) < int(height[b - 1]):
if int(a) in list:
list.remove(a)
elif int(height[a - 1]) > int(height[b - 1]):
if int(b) in list:
list.remove(b)
elif int(height[a - 1]) == int(height[b - 1]):
if int(b) in list:
list.remove(b)
elif int(a) in list:
list.remove(a)
print(len(list))
| Statement
There are N observatories in AtCoder Hill, called Obs. 1, Obs. 2, ..., Obs. N.
The elevation of Obs. i is H_i. There are also M roads, each connecting two
different observatories. Road j connects Obs. A_j and Obs. B_j.
Obs. i is said to be good when its elevation is higher than those of all
observatories that can be reached from Obs. i using just one road. Note that
Obs. i is also good when no observatory can be reached from Obs. i using just
one road.
How many good observatories are there? | [{"input": "4 3\n 1 2 3 4\n 1 3\n 2 3\n 2 4", "output": "2\n \n\n * From Obs. 1, you can reach Obs. 3 using just one road. The elevation of Obs. 1 is not higher than that of Obs. 3, so Obs. 1 is not good.\n\n * From Obs. 2, you can reach Obs. 3 and 4 using just one road. The elevation of Obs. 2 is not higher than that of Obs. 3, so Obs. 2 is not good.\n\n * From Obs. 3, you can reach Obs. 1 and 2 using just one road. The elevation of Obs. 3 is higher than those of Obs. 1 and 2, so Obs. 3 is good.\n\n * From Obs. 4, you can reach Obs. 2 using just one road. The elevation of Obs. 4 is higher than that of Obs. 2, so Obs. 4 is good.\n\nThus, the good observatories are Obs. 3 and 4, so there are two good\nobservatories.\n\n* * *"}, {"input": "6 5\n 8 6 9 1 2 1\n 1 3\n 4 2\n 4 3\n 4 6\n 4 6", "output": "3"}] |
Print the number of good observatories.
* * * | s710804569 | Runtime Error | p02689 | Input is given from Standard Input in the following format:
N M
H_1 H_2 ... H_N
A_1 B_1
A_2 B_2
:
A_M B_M | n, m = (int(x) for x in input().split())
h = [0] * n
ans = [0] * n
i = 0
y = input().split()
while i < n:
h[i] = int(y[i])
ans[i] = i + 1
i += 1
j = 1
while (j <= m) or len(ans) >= 2:
a, b = (int(x) for x in input().split())
if a in ans:
if h[a - 1] <= h[b - 1]:
ans.remove(a)
if b in ans:
if h[a - 1] >= h[b - 1]:
ans.remove(b)
j += 1
print(len(ans))
| Statement
There are N observatories in AtCoder Hill, called Obs. 1, Obs. 2, ..., Obs. N.
The elevation of Obs. i is H_i. There are also M roads, each connecting two
different observatories. Road j connects Obs. A_j and Obs. B_j.
Obs. i is said to be good when its elevation is higher than those of all
observatories that can be reached from Obs. i using just one road. Note that
Obs. i is also good when no observatory can be reached from Obs. i using just
one road.
How many good observatories are there? | [{"input": "4 3\n 1 2 3 4\n 1 3\n 2 3\n 2 4", "output": "2\n \n\n * From Obs. 1, you can reach Obs. 3 using just one road. The elevation of Obs. 1 is not higher than that of Obs. 3, so Obs. 1 is not good.\n\n * From Obs. 2, you can reach Obs. 3 and 4 using just one road. The elevation of Obs. 2 is not higher than that of Obs. 3, so Obs. 2 is not good.\n\n * From Obs. 3, you can reach Obs. 1 and 2 using just one road. The elevation of Obs. 3 is higher than those of Obs. 1 and 2, so Obs. 3 is good.\n\n * From Obs. 4, you can reach Obs. 2 using just one road. The elevation of Obs. 4 is higher than that of Obs. 2, so Obs. 4 is good.\n\nThus, the good observatories are Obs. 3 and 4, so there are two good\nobservatories.\n\n* * *"}, {"input": "6 5\n 8 6 9 1 2 1\n 1 3\n 4 2\n 4 3\n 4 6\n 4 6", "output": "3"}] |
Print the number of good observatories.
* * * | s843273484 | Accepted | p02689 | Input is given from Standard Input in the following format:
N M
H_1 H_2 ... H_N
A_1 B_1
A_2 B_2
:
A_M B_M | num_of_observatory, num_of_road = map(int, input().split())
elevations = list(map(int, input().split()))
road_unions = []
for _ in range(num_of_road):
road_unions.append(list(map(int, input().split())))
# つながっている展望台のリスト
to_observatorys = [[] for i in range(num_of_observatory)]
for road_union in road_unions:
to_observatorys[road_union[0] - 1].append(elevations[road_union[1] - 1])
to_observatorys[road_union[1] - 1].append(elevations[road_union[0] - 1])
num_of_good = 0
for i in range(num_of_observatory):
# つながっている展望台がない または つながっている展望台よりも高い場合
if len(to_observatorys[i]) == 0 or elevations[i] > max(to_observatorys[i]):
num_of_good = num_of_good + 1
print(num_of_good)
| Statement
There are N observatories in AtCoder Hill, called Obs. 1, Obs. 2, ..., Obs. N.
The elevation of Obs. i is H_i. There are also M roads, each connecting two
different observatories. Road j connects Obs. A_j and Obs. B_j.
Obs. i is said to be good when its elevation is higher than those of all
observatories that can be reached from Obs. i using just one road. Note that
Obs. i is also good when no observatory can be reached from Obs. i using just
one road.
How many good observatories are there? | [{"input": "4 3\n 1 2 3 4\n 1 3\n 2 3\n 2 4", "output": "2\n \n\n * From Obs. 1, you can reach Obs. 3 using just one road. The elevation of Obs. 1 is not higher than that of Obs. 3, so Obs. 1 is not good.\n\n * From Obs. 2, you can reach Obs. 3 and 4 using just one road. The elevation of Obs. 2 is not higher than that of Obs. 3, so Obs. 2 is not good.\n\n * From Obs. 3, you can reach Obs. 1 and 2 using just one road. The elevation of Obs. 3 is higher than those of Obs. 1 and 2, so Obs. 3 is good.\n\n * From Obs. 4, you can reach Obs. 2 using just one road. The elevation of Obs. 4 is higher than that of Obs. 2, so Obs. 4 is good.\n\nThus, the good observatories are Obs. 3 and 4, so there are two good\nobservatories.\n\n* * *"}, {"input": "6 5\n 8 6 9 1 2 1\n 1 3\n 4 2\n 4 3\n 4 6\n 4 6", "output": "3"}] |
Print the number of good observatories.
* * * | s508551069 | Accepted | p02689 | Input is given from Standard Input in the following format:
N M
H_1 H_2 ... H_N
A_1 B_1
A_2 B_2
:
A_M B_M | nm = input("")
n = int(nm.split(" ")[0])
m = int(nm.split(" ")[1])
hs = input("").split(" ")
abmap = {}
for i in range(m):
ab = input("")
a = int(ab.split(" ")[0])
b = int(ab.split(" ")[1])
if a in abmap.keys():
abmap[a].append(b)
else:
abmap[a] = [b]
if b in abmap.keys():
abmap[b].append(a)
else:
abmap[b] = [a]
ytb_cnt = 0
for a, b in abmap.items():
ah = int(hs[a - 1])
ytb = 1
for bn in b:
bh = int(hs[bn - 1])
# print("{}[{}]->{}[{}]".format(a,ah,b,bh))
if ah <= bh:
ytb = 0
if ytb == 1:
ytb_cnt += 1
for h in range(len(hs)):
if not (h + 1) in abmap.keys():
# print("{} is no root".format(h+1))
ytb_cnt += 1
print(ytb_cnt)
| Statement
There are N observatories in AtCoder Hill, called Obs. 1, Obs. 2, ..., Obs. N.
The elevation of Obs. i is H_i. There are also M roads, each connecting two
different observatories. Road j connects Obs. A_j and Obs. B_j.
Obs. i is said to be good when its elevation is higher than those of all
observatories that can be reached from Obs. i using just one road. Note that
Obs. i is also good when no observatory can be reached from Obs. i using just
one road.
How many good observatories are there? | [{"input": "4 3\n 1 2 3 4\n 1 3\n 2 3\n 2 4", "output": "2\n \n\n * From Obs. 1, you can reach Obs. 3 using just one road. The elevation of Obs. 1 is not higher than that of Obs. 3, so Obs. 1 is not good.\n\n * From Obs. 2, you can reach Obs. 3 and 4 using just one road. The elevation of Obs. 2 is not higher than that of Obs. 3, so Obs. 2 is not good.\n\n * From Obs. 3, you can reach Obs. 1 and 2 using just one road. The elevation of Obs. 3 is higher than those of Obs. 1 and 2, so Obs. 3 is good.\n\n * From Obs. 4, you can reach Obs. 2 using just one road. The elevation of Obs. 4 is higher than that of Obs. 2, so Obs. 4 is good.\n\nThus, the good observatories are Obs. 3 and 4, so there are two good\nobservatories.\n\n* * *"}, {"input": "6 5\n 8 6 9 1 2 1\n 1 3\n 4 2\n 4 3\n 4 6\n 4 6", "output": "3"}] |
Print the number of good observatories.
* * * | s508615331 | Wrong Answer | p02689 | Input is given from Standard Input in the following format:
N M
H_1 H_2 ... H_N
A_1 B_1
A_2 B_2
:
A_M B_M | line = input().split(" ")
num = int(line[0])
road = int(line[1])
high = input().split(" ")
lowgroup = []
for i in range(road):
a = input().split(" ")
if int(high[int(a[0]) - 1]) < int(high[int(a[1]) - 1]):
lowgroup.append(a[0])
else:
lowgroup.append(a[1])
print(num - len(set(lowgroup)))
| Statement
There are N observatories in AtCoder Hill, called Obs. 1, Obs. 2, ..., Obs. N.
The elevation of Obs. i is H_i. There are also M roads, each connecting two
different observatories. Road j connects Obs. A_j and Obs. B_j.
Obs. i is said to be good when its elevation is higher than those of all
observatories that can be reached from Obs. i using just one road. Note that
Obs. i is also good when no observatory can be reached from Obs. i using just
one road.
How many good observatories are there? | [{"input": "4 3\n 1 2 3 4\n 1 3\n 2 3\n 2 4", "output": "2\n \n\n * From Obs. 1, you can reach Obs. 3 using just one road. The elevation of Obs. 1 is not higher than that of Obs. 3, so Obs. 1 is not good.\n\n * From Obs. 2, you can reach Obs. 3 and 4 using just one road. The elevation of Obs. 2 is not higher than that of Obs. 3, so Obs. 2 is not good.\n\n * From Obs. 3, you can reach Obs. 1 and 2 using just one road. The elevation of Obs. 3 is higher than those of Obs. 1 and 2, so Obs. 3 is good.\n\n * From Obs. 4, you can reach Obs. 2 using just one road. The elevation of Obs. 4 is higher than that of Obs. 2, so Obs. 4 is good.\n\nThus, the good observatories are Obs. 3 and 4, so there are two good\nobservatories.\n\n* * *"}, {"input": "6 5\n 8 6 9 1 2 1\n 1 3\n 4 2\n 4 3\n 4 6\n 4 6", "output": "3"}] |
Print the number of good observatories.
* * * | s285001597 | Runtime Error | p02689 | Input is given from Standard Input in the following format:
N M
H_1 H_2 ... H_N
A_1 B_1
A_2 B_2
:
A_M B_M | n, m = [int(_) for _ in input().split()]
H = [int(_) for _ in input().split()]
Hlist = [(set() for a in range(n))]
count = 0
for a in range(m):
a, b = [int(_) for _ in input().split()]
Hlist[a - 1].add(b - 1)
Hlist[b - 1].add(a - 1)
for i, j in enumerate(Hlist):
flag = 1
for a in j:
if H[a] >= H[i]:
flag = 0
if flag == 1:
count += 1
flag = 1
print(count)
| Statement
There are N observatories in AtCoder Hill, called Obs. 1, Obs. 2, ..., Obs. N.
The elevation of Obs. i is H_i. There are also M roads, each connecting two
different observatories. Road j connects Obs. A_j and Obs. B_j.
Obs. i is said to be good when its elevation is higher than those of all
observatories that can be reached from Obs. i using just one road. Note that
Obs. i is also good when no observatory can be reached from Obs. i using just
one road.
How many good observatories are there? | [{"input": "4 3\n 1 2 3 4\n 1 3\n 2 3\n 2 4", "output": "2\n \n\n * From Obs. 1, you can reach Obs. 3 using just one road. The elevation of Obs. 1 is not higher than that of Obs. 3, so Obs. 1 is not good.\n\n * From Obs. 2, you can reach Obs. 3 and 4 using just one road. The elevation of Obs. 2 is not higher than that of Obs. 3, so Obs. 2 is not good.\n\n * From Obs. 3, you can reach Obs. 1 and 2 using just one road. The elevation of Obs. 3 is higher than those of Obs. 1 and 2, so Obs. 3 is good.\n\n * From Obs. 4, you can reach Obs. 2 using just one road. The elevation of Obs. 4 is higher than that of Obs. 2, so Obs. 4 is good.\n\nThus, the good observatories are Obs. 3 and 4, so there are two good\nobservatories.\n\n* * *"}, {"input": "6 5\n 8 6 9 1 2 1\n 1 3\n 4 2\n 4 3\n 4 6\n 4 6", "output": "3"}] |
Print the number of good observatories.
* * * | s266143061 | Accepted | p02689 | Input is given from Standard Input in the following format:
N M
H_1 H_2 ... H_N
A_1 B_1
A_2 B_2
:
A_M B_M | import sys
input = sys.stdin.readline
# from collections import deque
def linput(_t=int):
return list(map(_t, input().split()))
def gcd(n, m):
while m:
n, m = m, n % m
return n
def lcm(n, m):
return n * m // gcd(n, m)
def main():
# N = int(input())
N, M = linput()
vH = linput()
vE = [
linput()
for _ in [
0,
]
* M
]
vH = [
0,
] + vH
vV = [
0,
] + [
1,
] * N
# res = 0
# for s in S.split("-"):
# res = max(res, len(s))
for a, b in vE:
ha, hb = vH[a], vH[b]
if ha <= hb:
vV[a] = 0
if ha >= hb:
vV[b] = 0
res = sum(vV)
# res = 0
print(res)
# print(("No","Yes")[res%2])
main()
| Statement
There are N observatories in AtCoder Hill, called Obs. 1, Obs. 2, ..., Obs. N.
The elevation of Obs. i is H_i. There are also M roads, each connecting two
different observatories. Road j connects Obs. A_j and Obs. B_j.
Obs. i is said to be good when its elevation is higher than those of all
observatories that can be reached from Obs. i using just one road. Note that
Obs. i is also good when no observatory can be reached from Obs. i using just
one road.
How many good observatories are there? | [{"input": "4 3\n 1 2 3 4\n 1 3\n 2 3\n 2 4", "output": "2\n \n\n * From Obs. 1, you can reach Obs. 3 using just one road. The elevation of Obs. 1 is not higher than that of Obs. 3, so Obs. 1 is not good.\n\n * From Obs. 2, you can reach Obs. 3 and 4 using just one road. The elevation of Obs. 2 is not higher than that of Obs. 3, so Obs. 2 is not good.\n\n * From Obs. 3, you can reach Obs. 1 and 2 using just one road. The elevation of Obs. 3 is higher than those of Obs. 1 and 2, so Obs. 3 is good.\n\n * From Obs. 4, you can reach Obs. 2 using just one road. The elevation of Obs. 4 is higher than that of Obs. 2, so Obs. 4 is good.\n\nThus, the good observatories are Obs. 3 and 4, so there are two good\nobservatories.\n\n* * *"}, {"input": "6 5\n 8 6 9 1 2 1\n 1 3\n 4 2\n 4 3\n 4 6\n 4 6", "output": "3"}] |
For each query, print the LCA of u and v in a line. | s421254994 | Accepted | p02373 | n
k0 c1 c2 ... ck0
k1 c1 c2 ... ck1
:
kn-1 c1 c2 ... ckn-1
q
u1 v1
u2 v2
:
uq vq
The first line of the input includes an integer n, the number of nodes of the
tree.
In the next n lines, the information of node i is given. ki is the number of
children of node i, and c1, ... cki are node IDs of 1st, ... kth child of node
i.
In the next line, the number of queryies q is given. In the next q lines,
pairs of u and v are given as the queries. | from collections import defaultdict
class Tree:
def __init__(self, N):
self.N = N
self.D = (self.N - 1).bit_length()
self.E = defaultdict(dict)
def add_edge(self, init, end, weight, undirected=False):
self.E[init][end] = weight
if undirected:
self.E[end][init] = weight
def dfs(self, root):
# parents[v]: the parent of the vertex v
# depth[v]: the depth of the vertex v from the root
# dist[v]: the distance of the vertex v from the root.
self.parent = [None] * self.N
self.depth = [-1] * self.N
self.dist = [float("inf")] * self.N
self.parent[root] = -1
self.depth[root] = 0
self.dist[root] = 0
stack = [root]
while stack:
v = stack.pop()
for u in self.E[v].keys():
if self.depth[u] != -1:
continue
self.parent[u] = v
self.depth[u] = self.depth[v] + 1
self.dist[u] = self.dist[v] + self.E[v][u]
stack.append(u)
def doubling(self):
# O(N log N) time
self.next = [self.parent]
for d in range(1, self.D):
self.next.append(
[
(
self.next[d - 1][self.next[d - 1][v]]
if self.next[d - 1][v] != -1
else -1
)
for v in range(self.N)
]
)
def lca(self, u, v):
# O(log N) time
# the depth of v is set to be no less than that of u
if self.depth[u] > self.depth[v]:
u, v = v, u
# find the ancestor of v with the same depth as that of u
diff = self.depth[v] - self.depth[u]
for i in range(diff.bit_length()):
if diff & 1:
v = self.next[i][v]
diff >>= 1
if u == v:
return u
for i in range(self.D - 1, -1, -1):
pu, pv = self.next[i][u], self.next[i][v]
if pu != pv:
u, v = pu, pv
return self.next[0][u]
n = int(input())
tr = Tree(n)
for i in range(n):
(
k,
*C,
) = map(int, input().split())
for c in C:
tr.add_edge(i, c, 1, undirected=True)
tr.dfs(0)
tr.doubling()
q = int(input())
for _ in range(q):
u, v = map(int, input().split())
print(tr.lca(u, v))
| LCA: Lowest Common Ancestor
For a rooted tree, find the lowest common ancestor of two nodes u and v.
The given tree consists of n nodes and every node has a unique ID from 0 to
n-1 where 0 is the root. | [{"input": "8\n 3 1 2 3\n 2 4 5\n 0\n 0\n 0\n 2 6 7\n 0\n 0\n 4\n 4 6\n 4 7\n 4 3\n 5 2", "output": "1\n 1\n 0\n 0"}] |
For each query, print the LCA of u and v in a line. | s971778577 | Accepted | p02373 | n
k0 c1 c2 ... ck0
k1 c1 c2 ... ck1
:
kn-1 c1 c2 ... ckn-1
q
u1 v1
u2 v2
:
uq vq
The first line of the input includes an integer n, the number of nodes of the
tree.
In the next n lines, the information of node i is given. ki is the number of
children of node i, and c1, ... cki are node IDs of 1st, ... kth child of node
i.
In the next line, the number of queryies q is given. In the next q lines,
pairs of u and v are given as the queries. | # 参考 https://tjkendev.github.io/procon-library/python/graph/lca-segment-tree.html
# N: 頂点数
# G[v]: 頂点vの子頂点 (親頂点は含まない)
import sys
sys.setrecursionlimit(10**7)
N = int(input())
G = [[] for _ in range(N)]
for v in range(N):
for j, nv in enumerate(map(int, input().split())):
if j == 0:
continue
G[v].append(nv)
# Euler Tour の構築
S = []
F = [0] * N
depth = [0] * N
def dfs(v, d):
F[v] = len(S)
depth[v] = d
S.append(v)
for w in G[v]:
dfs(w, d + 1)
S.append(v)
dfs(0, 0)
# 存在しない範囲は深さが他よりも大きくなるようにする
INF = (N, None)
# LCAを計算するクエリの前計算
M = 2 * N
M0 = 2 ** (M - 1).bit_length()
data = [INF] * (2 * M0)
for i, v in enumerate(S):
data[M0 - 1 + i] = (depth[v], i)
for i in range(M0 - 2, -1, -1):
data[i] = min(data[2 * i + 1], data[2 * i + 2])
# LCAの計算 (generatorで最小値を求める)
def _query(a, b):
yield INF
a += M0
b += M0
while a < b:
if b & 1:
b -= 1
yield data[b - 1]
if a & 1:
yield data[a - 1]
a += 1
a >>= 1
b >>= 1
# LCAの計算 (外から呼び出す関数)
def query(u, v):
fu = F[u]
fv = F[v]
if fu > fv:
fu, fv = fv, fu
return S[min(_query(fu, fv + 1))[1]]
ans_list = []
q = int(input())
for _ in range(q):
u, v = map(int, input().split())
ans = query(u, v)
ans_list.append(ans)
print(*ans_list, sep="\n")
| LCA: Lowest Common Ancestor
For a rooted tree, find the lowest common ancestor of two nodes u and v.
The given tree consists of n nodes and every node has a unique ID from 0 to
n-1 where 0 is the root. | [{"input": "8\n 3 1 2 3\n 2 4 5\n 0\n 0\n 0\n 2 6 7\n 0\n 0\n 4\n 4 6\n 4 7\n 4 3\n 5 2", "output": "1\n 1\n 0\n 0"}] |
If S is coffee-like, print `Yes`; otherwise, print `No`.
* * * | s915639861 | Runtime Error | p02723 | Input is given from Standard Input in the following format:
S | a = int(input())
a -= a % 5
print(2 * a - a % 500)
| Statement
A string of length 6 consisting of lowercase English letters is said to be
coffee-like if and only if its 3-rd and 4-th characters are equal and its 5-th
and 6-th characters are also equal.
Given a string S, determine whether it is coffee-like. | [{"input": "sippuu", "output": "Yes\n \n\nIn `sippuu`, the 3-rd and 4-th characters are equal, and the 5-th and 6-th\ncharacters are also equal.\n\n* * *"}, {"input": "iphone", "output": "No\n \n\n* * *"}, {"input": "coffee", "output": "Yes"}] |
If S is coffee-like, print `Yes`; otherwise, print `No`.
* * * | s172930474 | Runtime Error | p02723 | Input is given from Standard Input in the following format:
S | str = input()
str[2] == str[3] && str[4] == str[5] ? 'Yes' : 'No';
| Statement
A string of length 6 consisting of lowercase English letters is said to be
coffee-like if and only if its 3-rd and 4-th characters are equal and its 5-th
and 6-th characters are also equal.
Given a string S, determine whether it is coffee-like. | [{"input": "sippuu", "output": "Yes\n \n\nIn `sippuu`, the 3-rd and 4-th characters are equal, and the 5-th and 6-th\ncharacters are also equal.\n\n* * *"}, {"input": "iphone", "output": "No\n \n\n* * *"}, {"input": "coffee", "output": "Yes"}] |
If S is coffee-like, print `Yes`; otherwise, print `No`.
* * * | s596491878 | Accepted | p02723 | Input is given from Standard Input in the following format:
S | import sys
input_methods = ["clipboard", "file", "key"]
using_method = 0
input_method = input_methods[using_method]
IN = lambda: map(int, input().split())
mod = 1000000007
# +++++
def main():
# a = int(input())
# b , c = IN()
s = input()
is_coffee_like = (s[2] == s[3]) and (s[4] == s[5])
ret = "Yes" if is_coffee_like else "No"
print(ret)
# +++++
isTest = False
def pa(v):
if isTest:
print(v)
def input_clipboard():
import clipboard
input_text = clipboard.get()
input_l = input_text.splitlines()
for l in input_l:
yield l
if __name__ == "__main__":
if sys.platform == "ios":
if input_method == input_methods[0]:
ic = input_clipboard()
input = lambda: ic.__next__()
elif input_method == input_methods[1]:
sys.stdin = open("inputFile.txt")
else:
pass
isTest = True
else:
pass
# input = sys.stdin.readline
ret = main()
if ret is not None:
print(ret)
| Statement
A string of length 6 consisting of lowercase English letters is said to be
coffee-like if and only if its 3-rd and 4-th characters are equal and its 5-th
and 6-th characters are also equal.
Given a string S, determine whether it is coffee-like. | [{"input": "sippuu", "output": "Yes\n \n\nIn `sippuu`, the 3-rd and 4-th characters are equal, and the 5-th and 6-th\ncharacters are also equal.\n\n* * *"}, {"input": "iphone", "output": "No\n \n\n* * *"}, {"input": "coffee", "output": "Yes"}] |
If S is coffee-like, print `Yes`; otherwise, print `No`.
* * * | s842139017 | Runtime Error | p02723 | Input is given from Standard Input in the following format:
S | import sys
def solve():
input = lambda: sys.stdin.readline().rstrip()
sys.setrecursionlimit(10**7)
mod = 10**9 + 7
def comb(n, r):
if r > n:
return 0
return fac[n] * inv[r] * inv[n - r] % mod
def dfs(v, Pa=-1):
for u in to[v]:
if u == Pa:
continue
dfs(u, v)
size[v] += size[u]
dp[v] *= dp[u] % mod
dp[v] *= comb(size[v], size[u]) % mod
size[v] += 1
def bfs(v, Pa=-1, P_val=1, P_sz=0):
ans[v] = P_val * dp[v] * comb(n - 1, P_sz) % mod
for u in to[v]:
if u == Pa:
continue
val = ans[v] * INV(dp[u] * comb(n - 1, size[u])) % mod
bfs(u, v, val, n - size[u])
n = int(input())
to = [[] for _ in range(n)]
for _ in range(n - 1):
a, b = map(lambda x: int(x) - 1, input().split())
to[a].append(b)
to[b].append(a)
fac = [1] * (n + 2)
inv = [1] * (n + 2)
for i in range(2, n + 1):
fac[i] = fac[i - 1] * i % mod
INV = lambda x: pow(x, mod - 2, mod)
inv[n] = INV(fac[n])
for i in range(n - 1, 1, -1):
inv[i] = inv[i + 1] * (i + 1) % mod
dp = [1] * n
size = [0] * n
ans = [0] * n
dfs(0)
bfs(0)
print(*ans, sep="\n")
if __name__ == "__main__":
solve()
| Statement
A string of length 6 consisting of lowercase English letters is said to be
coffee-like if and only if its 3-rd and 4-th characters are equal and its 5-th
and 6-th characters are also equal.
Given a string S, determine whether it is coffee-like. | [{"input": "sippuu", "output": "Yes\n \n\nIn `sippuu`, the 3-rd and 4-th characters are equal, and the 5-th and 6-th\ncharacters are also equal.\n\n* * *"}, {"input": "iphone", "output": "No\n \n\n* * *"}, {"input": "coffee", "output": "Yes"}] |
If S is coffee-like, print `Yes`; otherwise, print `No`.
* * * | s111117492 | Runtime Error | p02723 | Input is given from Standard Input in the following format:
S | X, Y, A, B, C = map(int, input().split())
p = list(map(int, input().split()))
q = list(map(int, input().split()))
r = list(map(int, input().split()))
p.sort(reverse=True)
q.sort(reverse=True)
r.sort(reverse=True)
p = p[:X]
q = q[:Y]
p.extend(q)
p.extend(r)
p.sort(reverse=True)
p = p[: A + B]
print(sum(p))
| Statement
A string of length 6 consisting of lowercase English letters is said to be
coffee-like if and only if its 3-rd and 4-th characters are equal and its 5-th
and 6-th characters are also equal.
Given a string S, determine whether it is coffee-like. | [{"input": "sippuu", "output": "Yes\n \n\nIn `sippuu`, the 3-rd and 4-th characters are equal, and the 5-th and 6-th\ncharacters are also equal.\n\n* * *"}, {"input": "iphone", "output": "No\n \n\n* * *"}, {"input": "coffee", "output": "Yes"}] |
If S is coffee-like, print `Yes`; otherwise, print `No`.
* * * | s629325619 | Runtime Error | p02723 | Input is given from Standard Input in the following format:
S | x, y, a, b, c = map(int, input().split())
print(
sum(
sorted(
sorted(list(map(int, input().split())), reverse=True)[:x]
+ sorted(list(map(int, input().split())), reverse=True)[:y]
+ list(map(int, input().split())),
reverse=True,
)[: (x + y)]
)
)
| Statement
A string of length 6 consisting of lowercase English letters is said to be
coffee-like if and only if its 3-rd and 4-th characters are equal and its 5-th
and 6-th characters are also equal.
Given a string S, determine whether it is coffee-like. | [{"input": "sippuu", "output": "Yes\n \n\nIn `sippuu`, the 3-rd and 4-th characters are equal, and the 5-th and 6-th\ncharacters are also equal.\n\n* * *"}, {"input": "iphone", "output": "No\n \n\n* * *"}, {"input": "coffee", "output": "Yes"}] |
If S is coffee-like, print `Yes`; otherwise, print `No`.
* * * | s007852536 | Runtime Error | p02723 | Input is given from Standard Input in the following format:
S | K, N = map(int, input().split())
N = N - 1
A = list(map(int, input().split()))
A_d = [A[i + 1] - A[i] for i in range(0, len(A) - 1)]
A_d.append(K - A[-1] + A[0])
print(A_d)
A_d2 = (A_d + A_d[1:]) * 2
print(A_d2)
res = K
for i in range(len(A_d2) - 1):
if res > sum(A_d2[i : i + N]):
res = sum(A_d2[i : i + N])
print(res)
| Statement
A string of length 6 consisting of lowercase English letters is said to be
coffee-like if and only if its 3-rd and 4-th characters are equal and its 5-th
and 6-th characters are also equal.
Given a string S, determine whether it is coffee-like. | [{"input": "sippuu", "output": "Yes\n \n\nIn `sippuu`, the 3-rd and 4-th characters are equal, and the 5-th and 6-th\ncharacters are also equal.\n\n* * *"}, {"input": "iphone", "output": "No\n \n\n* * *"}, {"input": "coffee", "output": "Yes"}] |
If S is coffee-like, print `Yes`; otherwise, print `No`.
* * * | s635021548 | Runtime Error | p02723 | Input is given from Standard Input in the following format:
S | # -*- coding: utf-8 -*-
import sys
from collections import defaultdict
MAX_INT = 2**62 - 1
sys.setrecursionlimit(10**6)
input = sys.stdin.readline
N = 2 * (10**5) + 1
MOD = 10**9 + 7
fact = [1] * N
fact_inv = [0] * N
for i in range(1, 2 * (10**5) + 1):
fact[i] = fact[i - 1] * i % MOD
fact_inv[i] = pow(fact[i], MOD - 2, MOD)
def solve(g):
def dfs(pre, cur):
if pre in memo and cur in memo[pre]:
return memo[pre][cur]
num, ways = 1, 1
for nxt in g[cur]:
if nxt == pre:
continue
n, w = dfs(cur, nxt)
num += n
ways = ways * w % m * fi[n] % m
ways = ways * f[num - 1] % m
memo[pre][cur] = num, ways
return num, ways
m = MOD
memo = defaultdict(dict)
f, fi = fact, fact_inv
for i in range(1, len(g)):
print(dfs(None, i)[1])
def main():
n = int(input())
g = [[] for _ in range(n + 1)]
for _ in range(n - 1):
a, b = map(int, input().split())
g[a].append(b)
g[b].append(a)
solve(g)
if __name__ == "__main__":
main()
| Statement
A string of length 6 consisting of lowercase English letters is said to be
coffee-like if and only if its 3-rd and 4-th characters are equal and its 5-th
and 6-th characters are also equal.
Given a string S, determine whether it is coffee-like. | [{"input": "sippuu", "output": "Yes\n \n\nIn `sippuu`, the 3-rd and 4-th characters are equal, and the 5-th and 6-th\ncharacters are also equal.\n\n* * *"}, {"input": "iphone", "output": "No\n \n\n* * *"}, {"input": "coffee", "output": "Yes"}] |
If S is coffee-like, print `Yes`; otherwise, print `No`.
* * * | s841774129 | Accepted | p02723 | Input is given from Standard Input in the following format:
S | n = input()[2:]
a, b = set(n[:2]), set(n[2:])
print("Yes" if len(a) == len(b) == 1 else "No")
| Statement
A string of length 6 consisting of lowercase English letters is said to be
coffee-like if and only if its 3-rd and 4-th characters are equal and its 5-th
and 6-th characters are also equal.
Given a string S, determine whether it is coffee-like. | [{"input": "sippuu", "output": "Yes\n \n\nIn `sippuu`, the 3-rd and 4-th characters are equal, and the 5-th and 6-th\ncharacters are also equal.\n\n* * *"}, {"input": "iphone", "output": "No\n \n\n* * *"}, {"input": "coffee", "output": "Yes"}] |
If S is coffee-like, print `Yes`; otherwise, print `No`.
* * * | s760574431 | Runtime Error | p02723 | Input is given from Standard Input in the following format:
S | import sys
sys.setrecursionlimit(3 * 10**5)
n = int(input())
edge = [tuple(map(int, input().split())) for _ in range(n - 1)]
mod = 10**9 + 7
def extGCD(a, b):
if b == 0:
return a, 1, 0
g, y, x = extGCD(b, a % b)
y -= a // b * x
return g, x, y
def moddiv(a, b):
_, inv, _ = extGCD(b, mod)
return (a * inv) % mod
N = 10**5 + 10
fact = [0] * (N)
fact[0] = 1
for i in range(1, N):
fact[i] = (fact[i - 1] * i) % mod
def comb(a, b):
return moddiv(moddiv(fact[a], fact[a - b]), fact[b])
connect = [set() for _ in range(n)]
for a, b in edge:
connect[a - 1].add(b - 1)
connect[b - 1].add(a - 1)
d = [{} for _ in range(n)]
def dfs(v, p):
if p in d[v]:
return d[v][p]
num, count = 0, 1
for next in connect[v]:
if next != p:
i, c = dfs(next, v)
num += i
count *= c
count %= mod
count *= comb(num, i)
count %= mod
num += 1
d[v][p] = num, count
return num, count
for i in range(n):
dfs(i, -1)
print(d[i][-1][1])
| Statement
A string of length 6 consisting of lowercase English letters is said to be
coffee-like if and only if its 3-rd and 4-th characters are equal and its 5-th
and 6-th characters are also equal.
Given a string S, determine whether it is coffee-like. | [{"input": "sippuu", "output": "Yes\n \n\nIn `sippuu`, the 3-rd and 4-th characters are equal, and the 5-th and 6-th\ncharacters are also equal.\n\n* * *"}, {"input": "iphone", "output": "No\n \n\n* * *"}, {"input": "coffee", "output": "Yes"}] |
If S is coffee-like, print `Yes`; otherwise, print `No`.
* * * | s137459957 | Accepted | p02723 | Input is given from Standard Input in the following format:
S | i = input()
print("Yes" if (i[2] == i[3] and i[4] == i[5]) else "No")
| Statement
A string of length 6 consisting of lowercase English letters is said to be
coffee-like if and only if its 3-rd and 4-th characters are equal and its 5-th
and 6-th characters are also equal.
Given a string S, determine whether it is coffee-like. | [{"input": "sippuu", "output": "Yes\n \n\nIn `sippuu`, the 3-rd and 4-th characters are equal, and the 5-th and 6-th\ncharacters are also equal.\n\n* * *"}, {"input": "iphone", "output": "No\n \n\n* * *"}, {"input": "coffee", "output": "Yes"}] |
If S is coffee-like, print `Yes`; otherwise, print `No`.
* * * | s594940375 | Wrong Answer | p02723 | Input is given from Standard Input in the following format:
S | s = input()[2::]
print("Yes" if len(set(s)) == 2 else "No")
| Statement
A string of length 6 consisting of lowercase English letters is said to be
coffee-like if and only if its 3-rd and 4-th characters are equal and its 5-th
and 6-th characters are also equal.
Given a string S, determine whether it is coffee-like. | [{"input": "sippuu", "output": "Yes\n \n\nIn `sippuu`, the 3-rd and 4-th characters are equal, and the 5-th and 6-th\ncharacters are also equal.\n\n* * *"}, {"input": "iphone", "output": "No\n \n\n* * *"}, {"input": "coffee", "output": "Yes"}] |
If S is coffee-like, print `Yes`; otherwise, print `No`.
* * * | s860943104 | Runtime Error | p02723 | Input is given from Standard Input in the following format:
S | a, b = divmod(int(input()), 500)
print(a * 1000 + (b // 5) * 5)
| Statement
A string of length 6 consisting of lowercase English letters is said to be
coffee-like if and only if its 3-rd and 4-th characters are equal and its 5-th
and 6-th characters are also equal.
Given a string S, determine whether it is coffee-like. | [{"input": "sippuu", "output": "Yes\n \n\nIn `sippuu`, the 3-rd and 4-th characters are equal, and the 5-th and 6-th\ncharacters are also equal.\n\n* * *"}, {"input": "iphone", "output": "No\n \n\n* * *"}, {"input": "coffee", "output": "Yes"}] |
If S is coffee-like, print `Yes`; otherwise, print `No`.
* * * | s173855943 | Wrong Answer | p02723 | Input is given from Standard Input in the following format:
S | print(True)
| Statement
A string of length 6 consisting of lowercase English letters is said to be
coffee-like if and only if its 3-rd and 4-th characters are equal and its 5-th
and 6-th characters are also equal.
Given a string S, determine whether it is coffee-like. | [{"input": "sippuu", "output": "Yes\n \n\nIn `sippuu`, the 3-rd and 4-th characters are equal, and the 5-th and 6-th\ncharacters are also equal.\n\n* * *"}, {"input": "iphone", "output": "No\n \n\n* * *"}, {"input": "coffee", "output": "Yes"}] |
If S is coffee-like, print `Yes`; otherwise, print `No`.
* * * | s022010122 | Wrong Answer | p02723 | Input is given from Standard Input in the following format:
S | print("No")
| Statement
A string of length 6 consisting of lowercase English letters is said to be
coffee-like if and only if its 3-rd and 4-th characters are equal and its 5-th
and 6-th characters are also equal.
Given a string S, determine whether it is coffee-like. | [{"input": "sippuu", "output": "Yes\n \n\nIn `sippuu`, the 3-rd and 4-th characters are equal, and the 5-th and 6-th\ncharacters are also equal.\n\n* * *"}, {"input": "iphone", "output": "No\n \n\n* * *"}, {"input": "coffee", "output": "Yes"}] |
If S is coffee-like, print `Yes`; otherwise, print `No`.
* * * | s730529252 | Runtime Error | p02723 | Input is given from Standard Input in the following format:
S | a = input()
if a[2] == a[3] && a[4] == a[5]:
print(Yes)
else:
print(No) | Statement
A string of length 6 consisting of lowercase English letters is said to be
coffee-like if and only if its 3-rd and 4-th characters are equal and its 5-th
and 6-th characters are also equal.
Given a string S, determine whether it is coffee-like. | [{"input": "sippuu", "output": "Yes\n \n\nIn `sippuu`, the 3-rd and 4-th characters are equal, and the 5-th and 6-th\ncharacters are also equal.\n\n* * *"}, {"input": "iphone", "output": "No\n \n\n* * *"}, {"input": "coffee", "output": "Yes"}] |
If S is coffee-like, print `Yes`; otherwise, print `No`.
* * * | s061531738 | Runtime Error | p02723 | Input is given from Standard Input in the following format:
S | print("Yes") if list(input().split())[3] == list(input().split())[4] else print("No")
| Statement
A string of length 6 consisting of lowercase English letters is said to be
coffee-like if and only if its 3-rd and 4-th characters are equal and its 5-th
and 6-th characters are also equal.
Given a string S, determine whether it is coffee-like. | [{"input": "sippuu", "output": "Yes\n \n\nIn `sippuu`, the 3-rd and 4-th characters are equal, and the 5-th and 6-th\ncharacters are also equal.\n\n* * *"}, {"input": "iphone", "output": "No\n \n\n* * *"}, {"input": "coffee", "output": "Yes"}] |
If S is coffee-like, print `Yes`; otherwise, print `No`.
* * * | s736042786 | Runtime Error | p02723 | Input is given from Standard Input in the following format:
S | S=input()
s=str(S)
if s[2]=s[3] and s[4]=s[5]:
print("Yes")
else:
print("No") | Statement
A string of length 6 consisting of lowercase English letters is said to be
coffee-like if and only if its 3-rd and 4-th characters are equal and its 5-th
and 6-th characters are also equal.
Given a string S, determine whether it is coffee-like. | [{"input": "sippuu", "output": "Yes\n \n\nIn `sippuu`, the 3-rd and 4-th characters are equal, and the 5-th and 6-th\ncharacters are also equal.\n\n* * *"}, {"input": "iphone", "output": "No\n \n\n* * *"}, {"input": "coffee", "output": "Yes"}] |
If S is coffee-like, print `Yes`; otherwise, print `No`.
* * * | s078977983 | Runtime Error | p02723 | Input is given from Standard Input in the following format:
S | k, n = map(int, input().split())
a = list(map(int, input().split()))
a.sort()
zero = False
if 0 in a:
a.remove(0)
n = n - 1
zero = True
# print("contain 0.")
l1 = a[n - 1] - a[0] # 0を通らない側
l2 = a[0] + k - a[n - 1] # 0を通る側
if zero == True:
ret = l2
else:
ret = l1 if l1 < l2 else l2
print("{}".format(ret))
| Statement
A string of length 6 consisting of lowercase English letters is said to be
coffee-like if and only if its 3-rd and 4-th characters are equal and its 5-th
and 6-th characters are also equal.
Given a string S, determine whether it is coffee-like. | [{"input": "sippuu", "output": "Yes\n \n\nIn `sippuu`, the 3-rd and 4-th characters are equal, and the 5-th and 6-th\ncharacters are also equal.\n\n* * *"}, {"input": "iphone", "output": "No\n \n\n* * *"}, {"input": "coffee", "output": "Yes"}] |
If S is coffee-like, print `Yes`; otherwise, print `No`.
* * * | s635869146 | Runtime Error | p02723 | Input is given from Standard Input in the following format:
S | _in = list(map(int, input().split()))
k = _in[0]
n = _in[1]
p = 0
_i = list(map(int, input().split()))
dis = 0
mdis = k - _i[n - 1] + _i[0]
for i in range(1, n - 2):
dis = _i[i + 1] - _i[i]
if dis >= mdis:
mdis = dis
print(k - mdis)
| Statement
A string of length 6 consisting of lowercase English letters is said to be
coffee-like if and only if its 3-rd and 4-th characters are equal and its 5-th
and 6-th characters are also equal.
Given a string S, determine whether it is coffee-like. | [{"input": "sippuu", "output": "Yes\n \n\nIn `sippuu`, the 3-rd and 4-th characters are equal, and the 5-th and 6-th\ncharacters are also equal.\n\n* * *"}, {"input": "iphone", "output": "No\n \n\n* * *"}, {"input": "coffee", "output": "Yes"}] |
If S is coffee-like, print `Yes`; otherwise, print `No`.
* * * | s318944777 | Runtime Error | p02723 | Input is given from Standard Input in the following format:
S | x, y, a, b, c = map(int, input().split())
pn = list(map(int, input().split()))
qn = list(map(int, input().split()))
rn = list(map(int, input().split()))
pn.sort(reverse=True)
qn.sort(reverse=True)
pqr = pn[:x] + qn[:y] + rn
pqr.sort(reverse=True)
print(sum(pqr[: x + y]))
| Statement
A string of length 6 consisting of lowercase English letters is said to be
coffee-like if and only if its 3-rd and 4-th characters are equal and its 5-th
and 6-th characters are also equal.
Given a string S, determine whether it is coffee-like. | [{"input": "sippuu", "output": "Yes\n \n\nIn `sippuu`, the 3-rd and 4-th characters are equal, and the 5-th and 6-th\ncharacters are also equal.\n\n* * *"}, {"input": "iphone", "output": "No\n \n\n* * *"}, {"input": "coffee", "output": "Yes"}] |
If S is coffee-like, print `Yes`; otherwise, print `No`.
* * * | s578273372 | Runtime Error | p02723 | Input is given from Standard Input in the following format:
S | def dijkstra(s, n, w, cost):
# 始点sから各頂点への最短距離
# n:頂点数, w:辺の数, cost[u][v] : 辺uvのコスト(存在しないときはinf)
d = [float("inf")] * n
used = [False] * n
d[s] = 0
while True:
v = -1
# まだ使われてない頂点の中から最小の距離のものを探す
for i in range(n):
if (not used[i]) and (v == -1):
v = i
elif (not used[i]) and d[i] < d[v]:
v = i
if v == -1:
break
used[v] = True
for j in range(n):
d[j] = min(d[j], d[v] + cost[v][j])
return tuple(d)
n, x, y = map(int, input().split())
# cost[u][v] : 辺uvのコスト(存在しないときはinf この場合は10**10)
cost = [[float("inf") for i in range(n)] for i in range(n)]
for i in range(n - 1):
cost[i][i + 1] = 1
cost[i + 1][i] = 1
cost[x - 1][y - 1] = 1
cost[y - 1][x - 1] = 1
ans = [0 for _ in range(n)]
for i in range(n):
# nは頂点数、wは辺の数
res = dijkstra(i, n, n, cost)
for j in range(i + 1, n):
ans[res[j]] += 1
for i in range(1, n):
print(ans[i])
| Statement
A string of length 6 consisting of lowercase English letters is said to be
coffee-like if and only if its 3-rd and 4-th characters are equal and its 5-th
and 6-th characters are also equal.
Given a string S, determine whether it is coffee-like. | [{"input": "sippuu", "output": "Yes\n \n\nIn `sippuu`, the 3-rd and 4-th characters are equal, and the 5-th and 6-th\ncharacters are also equal.\n\n* * *"}, {"input": "iphone", "output": "No\n \n\n* * *"}, {"input": "coffee", "output": "Yes"}] |
If S is coffee-like, print `Yes`; otherwise, print `No`.
* * * | s325437878 | Wrong Answer | p02723 | Input is given from Standard Input in the following format:
S | S = input()
ans = 0
for n in set(i for i in S[2::]):
if S.count(n) == 2:
ans += 1
print("Yes" if ans > 1 else "No")
| Statement
A string of length 6 consisting of lowercase English letters is said to be
coffee-like if and only if its 3-rd and 4-th characters are equal and its 5-th
and 6-th characters are also equal.
Given a string S, determine whether it is coffee-like. | [{"input": "sippuu", "output": "Yes\n \n\nIn `sippuu`, the 3-rd and 4-th characters are equal, and the 5-th and 6-th\ncharacters are also equal.\n\n* * *"}, {"input": "iphone", "output": "No\n \n\n* * *"}, {"input": "coffee", "output": "Yes"}] |
Print the minimum possible total increase of your fatigue level when you visit
all the towns.
* * * | s086852997 | Runtime Error | p03831 | The input is given from Standard Input in the following format:
N A B
X_1 X_2 ... X_N | a
| Statement
There are N towns on a line running east-west. The towns are numbered 1
through N, in order from west to east. Each point on the line has a one-
dimensional coordinate, and a point that is farther east has a greater
coordinate value. The coordinate of town i is X_i.
You are now at town 1, and you want to visit all the other towns. You have two
ways to travel:
* Walk on the line. Your _fatigue level_ increases by A each time you travel a distance of 1, regardless of direction.
* Teleport to any location of your choice. Your fatigue level increases by B, regardless of the distance covered.
Find the minimum possible total increase of your fatigue level when you visit
all the towns in these two ways. | [{"input": "4 2 5\n 1 2 5 7", "output": "11\n \n\nFrom town 1, walk a distance of 1 to town 2, then teleport to town 3, then\nwalk a distance of 2 to town 4. The total increase of your fatigue level in\nthis case is 2\u00d71+5+2\u00d72=11, which is the minimum possible value.\n\n* * *"}, {"input": "7 1 100\n 40 43 45 105 108 115 124", "output": "84\n \n\nFrom town 1, walk all the way to town 7. The total increase of your fatigue\nlevel in this case is 84, which is the minimum possible value.\n\n* * *"}, {"input": "7 1 2\n 24 35 40 68 72 99 103", "output": "12\n \n\nVisit all the towns in any order by teleporting six times. The total increase\nof your fatigue level in this case is 12, which is the minimum possible value."}] |
Print the minimum possible total increase of your fatigue level when you visit
all the towns.
* * * | s525722321 | Accepted | p03831 | The input is given from Standard Input in the following format:
N A B
X_1 X_2 ... X_N | def s0():
return input()
def s1():
return input().split()
def s2(n):
return [input() for x in range(n)]
def s3(n):
return [input().split() for _ in range(n)]
def s4(n):
return [[x for x in s] for s in s2(n)]
def n0():
return int(input())
def n1():
return [int(x) for x in input().split()]
def n2(n):
return [int(input()) for _ in range(n)]
def n3(n):
return [[int(x) for x in input().split()] for _ in range(n)]
def t3(n):
return [tuple(int(x) for x in input().split()) for _ in range(n)]
def p0(b, yes="Yes", no="No"):
print(yes if b else no)
# from sys import setrecursionlimit
# setrecursionlimit(1000000)
# from collections import Counter,deque,defaultdict
# import itertools
# import math
# import networkx as nx
# from bisect import bisect_left,bisect_right
# from heapq import heapify,heappush,heappop
n, a, b = n1()
X = n1()
ans = 0
for i in range(1, n):
move = a * (X[i] - X[i - 1])
if move > b:
ans += b
else:
ans += move
print(ans)
| Statement
There are N towns on a line running east-west. The towns are numbered 1
through N, in order from west to east. Each point on the line has a one-
dimensional coordinate, and a point that is farther east has a greater
coordinate value. The coordinate of town i is X_i.
You are now at town 1, and you want to visit all the other towns. You have two
ways to travel:
* Walk on the line. Your _fatigue level_ increases by A each time you travel a distance of 1, regardless of direction.
* Teleport to any location of your choice. Your fatigue level increases by B, regardless of the distance covered.
Find the minimum possible total increase of your fatigue level when you visit
all the towns in these two ways. | [{"input": "4 2 5\n 1 2 5 7", "output": "11\n \n\nFrom town 1, walk a distance of 1 to town 2, then teleport to town 3, then\nwalk a distance of 2 to town 4. The total increase of your fatigue level in\nthis case is 2\u00d71+5+2\u00d72=11, which is the minimum possible value.\n\n* * *"}, {"input": "7 1 100\n 40 43 45 105 108 115 124", "output": "84\n \n\nFrom town 1, walk all the way to town 7. The total increase of your fatigue\nlevel in this case is 84, which is the minimum possible value.\n\n* * *"}, {"input": "7 1 2\n 24 35 40 68 72 99 103", "output": "12\n \n\nVisit all the towns in any order by teleporting six times. The total increase\nof your fatigue level in this case is 12, which is the minimum possible value."}] |
Print the minimum possible total increase of your fatigue level when you visit
all the towns.
* * * | s167960437 | Accepted | p03831 | The input is given from Standard Input in the following format:
N A B
X_1 X_2 ... X_N | import numpy as np
import sys
n, a, b = map(int, input().split())
x = list(map(int, input().split()))
if n == 2:
print(min((x[1] - x[0]) * a, b))
sys.exit()
left = 0
right = n - 1
curr = 0
cnt = 0
reverse = False
while left < right:
if not reverse:
if (x[curr + 1] - x[curr]) * a > (x[right] - x[right - 1]) * a + b:
reverse = True
cnt += b
curr = right
left += 1
elif (x[curr + 1] - x[curr]) * a <= b:
left += 1
cnt += (x[curr + 1] - x[curr]) * a
curr = left
else:
left += 1
cnt += b
curr = left
else:
if (x[curr] - x[curr - 1]) * a > (x[left + 1] - x[left]) * a + b:
reverse = False
cnt += b
curr = left
right -= 1
elif (x[curr] - x[curr - 1]) * a <= b:
right -= 1
cnt += (x[curr] - x[curr - 1]) * a
curr = right
else:
right -= 1
cnt += b
curr = right
print(cnt)
| Statement
There are N towns on a line running east-west. The towns are numbered 1
through N, in order from west to east. Each point on the line has a one-
dimensional coordinate, and a point that is farther east has a greater
coordinate value. The coordinate of town i is X_i.
You are now at town 1, and you want to visit all the other towns. You have two
ways to travel:
* Walk on the line. Your _fatigue level_ increases by A each time you travel a distance of 1, regardless of direction.
* Teleport to any location of your choice. Your fatigue level increases by B, regardless of the distance covered.
Find the minimum possible total increase of your fatigue level when you visit
all the towns in these two ways. | [{"input": "4 2 5\n 1 2 5 7", "output": "11\n \n\nFrom town 1, walk a distance of 1 to town 2, then teleport to town 3, then\nwalk a distance of 2 to town 4. The total increase of your fatigue level in\nthis case is 2\u00d71+5+2\u00d72=11, which is the minimum possible value.\n\n* * *"}, {"input": "7 1 100\n 40 43 45 105 108 115 124", "output": "84\n \n\nFrom town 1, walk all the way to town 7. The total increase of your fatigue\nlevel in this case is 84, which is the minimum possible value.\n\n* * *"}, {"input": "7 1 2\n 24 35 40 68 72 99 103", "output": "12\n \n\nVisit all the towns in any order by teleporting six times. The total increase\nof your fatigue level in this case is 12, which is the minimum possible value."}] |
Print the minimum possible total increase of your fatigue level when you visit
all the towns.
* * * | s278053621 | Accepted | p03831 | The input is given from Standard Input in the following format:
N A B
X_1 X_2 ... X_N | from itertools import accumulate
from math import *
from collections import deque
from collections import defaultdict
from itertools import permutations
from heapq import *
from collections import Counter
from itertools import *
from bisect import bisect_left, bisect_right
from copy import deepcopy
inf = 10**18
from functools import reduce
n, a, b = map(int, input().split())
x = list(map(int, input().split()))
edge = []
class UnionFind:
def __init__(self, N):
self.rank = [0] * N
self.par = [i for i in range(N)]
self.counter = [1] * N
def find(self, x):
if self.par[x] == x:
return x
else:
self.par[x] = self.find(self.par[x])
return self.par[x]
def unite(self, x, y):
x = self.find(x)
y = self.find(y)
if x != y:
z = self.counter[x] + self.counter[y]
self.counter[x], self.counter[y] = z, z
if self.rank[x] < self.rank[y]:
self.par[x] = y
else:
self.par[y] = x
if self.rank[x] == self.rank[y]:
self.rank[x] += 1
def size(self, x):
x = self.find(x)
return self.counter[x]
def same(self, x, y):
return self.find(x) == self.find(y)
for i in range(1, n):
c = (x[i] - x[i - 1]) * a
edge.append((c, i - 1, i))
# クラスカル法
uf = UnionFind(n)
edge.sort()
ans = 0
edge_cnt = 0
i = 0
while edge_cnt < n - 1:
cost, i1, i2 = edge[i]
if not uf.same(i1, i2):
ans += min(b, cost)
uf.unite(i1, i2)
edge_cnt += 1
i += 1
print(ans)
| Statement
There are N towns on a line running east-west. The towns are numbered 1
through N, in order from west to east. Each point on the line has a one-
dimensional coordinate, and a point that is farther east has a greater
coordinate value. The coordinate of town i is X_i.
You are now at town 1, and you want to visit all the other towns. You have two
ways to travel:
* Walk on the line. Your _fatigue level_ increases by A each time you travel a distance of 1, regardless of direction.
* Teleport to any location of your choice. Your fatigue level increases by B, regardless of the distance covered.
Find the minimum possible total increase of your fatigue level when you visit
all the towns in these two ways. | [{"input": "4 2 5\n 1 2 5 7", "output": "11\n \n\nFrom town 1, walk a distance of 1 to town 2, then teleport to town 3, then\nwalk a distance of 2 to town 4. The total increase of your fatigue level in\nthis case is 2\u00d71+5+2\u00d72=11, which is the minimum possible value.\n\n* * *"}, {"input": "7 1 100\n 40 43 45 105 108 115 124", "output": "84\n \n\nFrom town 1, walk all the way to town 7. The total increase of your fatigue\nlevel in this case is 84, which is the minimum possible value.\n\n* * *"}, {"input": "7 1 2\n 24 35 40 68 72 99 103", "output": "12\n \n\nVisit all the towns in any order by teleporting six times. The total increase\nof your fatigue level in this case is 12, which is the minimum possible value."}] |
Print the minimum possible total increase of your fatigue level when you visit
all the towns.
* * * | s746643967 | Runtime Error | p03831 | The input is given from Standard Input in the following format:
N A B
X_1 X_2 ... X_N | a = list(map(int,input().split()))
b = list(map(int,input().split()))
su = 0
c = [0]
for i in range(len(b)-2):
c.append(0)
for i in range(a[0] - 1):
c[i] = b[i+1] - b[i]
for i in range(len(c)):
if a[2] <= c[i]*a[1]:
su += a[2]
else:
su += c[i]*a[1]
print(su | Statement
There are N towns on a line running east-west. The towns are numbered 1
through N, in order from west to east. Each point on the line has a one-
dimensional coordinate, and a point that is farther east has a greater
coordinate value. The coordinate of town i is X_i.
You are now at town 1, and you want to visit all the other towns. You have two
ways to travel:
* Walk on the line. Your _fatigue level_ increases by A each time you travel a distance of 1, regardless of direction.
* Teleport to any location of your choice. Your fatigue level increases by B, regardless of the distance covered.
Find the minimum possible total increase of your fatigue level when you visit
all the towns in these two ways. | [{"input": "4 2 5\n 1 2 5 7", "output": "11\n \n\nFrom town 1, walk a distance of 1 to town 2, then teleport to town 3, then\nwalk a distance of 2 to town 4. The total increase of your fatigue level in\nthis case is 2\u00d71+5+2\u00d72=11, which is the minimum possible value.\n\n* * *"}, {"input": "7 1 100\n 40 43 45 105 108 115 124", "output": "84\n \n\nFrom town 1, walk all the way to town 7. The total increase of your fatigue\nlevel in this case is 84, which is the minimum possible value.\n\n* * *"}, {"input": "7 1 2\n 24 35 40 68 72 99 103", "output": "12\n \n\nVisit all the towns in any order by teleporting six times. The total increase\nof your fatigue level in this case is 12, which is the minimum possible value."}] |
Print the minimum possible total increase of your fatigue level when you visit
all the towns.
* * * | s282205303 | Wrong Answer | p03831 | The input is given from Standard Input in the following format:
N A B
X_1 X_2 ... X_N | # coding: utf-8
# Your code here!
# coding: utf-8
from fractions import gcd
from functools import reduce
import sys
sys.setrecursionlimit(200000000)
from inspect import currentframe
# my functions here!
# 標準エラー出力
def printargs2err(*args):
names = {id(v): k for k, v in currentframe().f_back.f_locals.items()}
print(
", ".join(names.get(id(arg), "???") + " : " + repr(arg) for arg in args),
file=sys.stderr,
)
def debug(x):
print(x, file=sys.stderr)
def printglobals():
for symbol, value in globals().items():
print('symbol="%s"、value=%s' % (symbol, value), file=sys.stderr)
def printlocals():
for symbol, value in locals().items():
print('symbol="%s"、value=%s' % (symbol, value), file=sys.stderr)
# 入力(後でいじる)
def pin(type=int):
return map(type, input().split())
# 繰り返し自乗法だよ
# これはnのp乗をmで割ったあまりをだすよ
def modular_w_binary_method(n, m, p):
ans = 1 if n > 0 else 0
while p > 0:
if p % 2 == 1:
ans = (ans * n) % m
n = (n**2) % m
p //= 2
return ans
# mod上でのaの逆元を出すよ
"""
フェルマーの小定理より a**(p)%p==a isTrue
これを利用すれば a**(p-2)%p==a**(-1) isTrue
元と逆元とをかけてpで割れば1が余るよ!
"""
def modular_inverse(a, prime):
return modular_w_binary_method(a, prime, prime - 2)
# 逆元を使うと容易に頑張れるc
def conbination(n, a, mod=10**9 + 7):
# cはイラない
res = 1
for s in range(a):
res = (res * (n - s) * (modular_inverse(s + 1, mod))) % mod
return res
# 操作から作れるものの組み合わせは何個かー>同じものでも違う方法で構成できるかから考える方法もある
"""
"""
# solution:
# input
N, A, B = pin()
X = list(pin())
t = (B + 1) // A
ans = 0
for i in range(1, N):
f = X[i] - X[i - 1]
if f < t:
ans += A * f
else:
ans += B
print(ans)
# print(["No","Yes"][cond])
# print([["NA","YYMM"],["MMYY","AMBIGUOUS"]][cMMYY][cYYMM])
"""
#printデバッグ消した?
#前の問題の結果見てないのに次の問題に行くの?
"""
"""
お前カッコ閉じるの忘れてるだろ
"""
| Statement
There are N towns on a line running east-west. The towns are numbered 1
through N, in order from west to east. Each point on the line has a one-
dimensional coordinate, and a point that is farther east has a greater
coordinate value. The coordinate of town i is X_i.
You are now at town 1, and you want to visit all the other towns. You have two
ways to travel:
* Walk on the line. Your _fatigue level_ increases by A each time you travel a distance of 1, regardless of direction.
* Teleport to any location of your choice. Your fatigue level increases by B, regardless of the distance covered.
Find the minimum possible total increase of your fatigue level when you visit
all the towns in these two ways. | [{"input": "4 2 5\n 1 2 5 7", "output": "11\n \n\nFrom town 1, walk a distance of 1 to town 2, then teleport to town 3, then\nwalk a distance of 2 to town 4. The total increase of your fatigue level in\nthis case is 2\u00d71+5+2\u00d72=11, which is the minimum possible value.\n\n* * *"}, {"input": "7 1 100\n 40 43 45 105 108 115 124", "output": "84\n \n\nFrom town 1, walk all the way to town 7. The total increase of your fatigue\nlevel in this case is 84, which is the minimum possible value.\n\n* * *"}, {"input": "7 1 2\n 24 35 40 68 72 99 103", "output": "12\n \n\nVisit all the towns in any order by teleporting six times. The total increase\nof your fatigue level in this case is 12, which is the minimum possible value."}] |
Print the minimum possible total increase of your fatigue level when you visit
all the towns.
* * * | s779658396 | Accepted | p03831 | The input is given from Standard Input in the following format:
N A B
X_1 X_2 ... X_N | S1 = input()
S1 = S1.split()
S2 = input()
S2 = S2.split()
move = 0
N = int(S1[0])
A = int(S1[1])
B = int(S1[2])
for i in range(N - 1):
div = int(S2[i + 1]) - int(S2[i])
if (div) * A >= B:
move += B
else:
move += A * (div)
print(move)
| Statement
There are N towns on a line running east-west. The towns are numbered 1
through N, in order from west to east. Each point on the line has a one-
dimensional coordinate, and a point that is farther east has a greater
coordinate value. The coordinate of town i is X_i.
You are now at town 1, and you want to visit all the other towns. You have two
ways to travel:
* Walk on the line. Your _fatigue level_ increases by A each time you travel a distance of 1, regardless of direction.
* Teleport to any location of your choice. Your fatigue level increases by B, regardless of the distance covered.
Find the minimum possible total increase of your fatigue level when you visit
all the towns in these two ways. | [{"input": "4 2 5\n 1 2 5 7", "output": "11\n \n\nFrom town 1, walk a distance of 1 to town 2, then teleport to town 3, then\nwalk a distance of 2 to town 4. The total increase of your fatigue level in\nthis case is 2\u00d71+5+2\u00d72=11, which is the minimum possible value.\n\n* * *"}, {"input": "7 1 100\n 40 43 45 105 108 115 124", "output": "84\n \n\nFrom town 1, walk all the way to town 7. The total increase of your fatigue\nlevel in this case is 84, which is the minimum possible value.\n\n* * *"}, {"input": "7 1 2\n 24 35 40 68 72 99 103", "output": "12\n \n\nVisit all the towns in any order by teleporting six times. The total increase\nof your fatigue level in this case is 12, which is the minimum possible value."}] |
Print N integers, with spaces in between. The i-th integer (1 \leq i \leq N)
should be the i-th element in a_K.
* * * | s271022308 | Wrong Answer | p03098 | Input is given from Standard Input in the following format:
N K
p_1 ... p_N
q_1 ... q_N | # D問題
N, K = map(int, input().split())
p = list(map(int, input().split()))
q = list(map(int, input().split()))
r = [0 for i in range(N)]
for i in range(N):
r[p[i] - 1] = q[i]
if K % 2 == 0:
if K % 4 == 0:
for i in range(N):
print(p[i], end=" ")
else:
for i in range(N):
print(r[i], end=" ")
else:
if K % 4 == 1:
for i in range(N):
print(r[i], end=" ")
else:
for i in range(N):
print(q[i], end=" ")
| Statement
For two permutations p and q of the integers from 1 through N, let f(p,q) be
the permutation that satisfies the following:
* The p_i-th element (1 \leq i \leq N) in f(p,q) is q_i. Here, p_i and q_i respectively denote the i-th element in p and q.
You are given two permutations p and q of the integers from 1 through N. We
will now define a sequence {a_n} of permutations of the integers from 1
through N, as follows:
* a_1=p, a_2=q
* a_{n+2}=f(a_n,a_{n+1}) ( n \geq 1 )
Given a positive integer K, find a_K. | [{"input": "3 3\n 1 2 3\n 3 2 1", "output": "3 2 1\n \n\nSince a_3=f(p,q), we just need to find f(p,q). We have p_i=i here, so\nf(p,q)=q.\n\n* * *"}, {"input": "5 5\n 4 5 1 2 3\n 3 2 1 5 4", "output": "4 3 2 1 5\n \n\n* * *"}, {"input": "10 1000000000\n 7 10 6 5 4 2 9 1 3 8\n 4 1 9 2 3 7 8 10 6 5", "output": "7 9 4 8 2 5 1 6 10 3"}] |
Print N integers, with spaces in between. The i-th integer (1 \leq i \leq N)
should be the i-th element in a_K.
* * * | s941328353 | Accepted | p03098 | Input is given from Standard Input in the following format:
N K
p_1 ... p_N
q_1 ... q_N | from operator import itemgetter
def get_identity():
return list(range(1, n + 1))
def composition(ppp, qqq):
return [ppp[q - 1] for q in qqq]
def reverse_composition(ppp, qqq):
return [ppp[i] for i, q in sorted(enumerate(qqq), key=itemgetter(1))]
def solve(k, ppp, qqq):
qp = reverse_composition(qqq, ppp)
qpq = reverse_composition(qp, qqq)
qpqp = composition(qpq, ppp)
l, m = divmod(k - 1, 6)
res = get_identity()
tmp = qpqp
while l:
if l % 2 == 1:
res = composition(res, tmp)
tmp = composition(tmp, tmp)
l >>= 1
m = (k - 1) % 6
if m == 0:
base = ppp
elif m == 1:
base = qqq
elif m == 2:
base = reverse_composition(qqq, ppp)
elif m == 3:
res = composition(res, qqq)
base = reverse_composition(get_identity(), ppp)
elif m == 4:
res = composition(res, qqq)
res = reverse_composition(res, ppp)
base = reverse_composition(get_identity(), qqq)
elif m == 5:
res = composition(res, qqq)
res = reverse_composition(res, ppp)
base = reverse_composition(get_identity(), qqq)
base = composition(base, ppp)
else:
raise NotImplementedError
ans = composition(res, base)
ans = reverse_composition(ans, res)
return ans
n, k = map(int, input().split())
ppp = list(map(int, input().split()))
qqq = list(map(int, input().split()))
print(*solve(k, ppp, qqq))
| Statement
For two permutations p and q of the integers from 1 through N, let f(p,q) be
the permutation that satisfies the following:
* The p_i-th element (1 \leq i \leq N) in f(p,q) is q_i. Here, p_i and q_i respectively denote the i-th element in p and q.
You are given two permutations p and q of the integers from 1 through N. We
will now define a sequence {a_n} of permutations of the integers from 1
through N, as follows:
* a_1=p, a_2=q
* a_{n+2}=f(a_n,a_{n+1}) ( n \geq 1 )
Given a positive integer K, find a_K. | [{"input": "3 3\n 1 2 3\n 3 2 1", "output": "3 2 1\n \n\nSince a_3=f(p,q), we just need to find f(p,q). We have p_i=i here, so\nf(p,q)=q.\n\n* * *"}, {"input": "5 5\n 4 5 1 2 3\n 3 2 1 5 4", "output": "4 3 2 1 5\n \n\n* * *"}, {"input": "10 1000000000\n 7 10 6 5 4 2 9 1 3 8\n 4 1 9 2 3 7 8 10 6 5", "output": "7 9 4 8 2 5 1 6 10 3"}] |
Print N integers, with spaces in between. The i-th integer (1 \leq i \leq N)
should be the i-th element in a_K.
* * * | s983635502 | Wrong Answer | p03098 | Input is given from Standard Input in the following format:
N K
p_1 ... p_N
q_1 ... q_N | N, K = map(int, input().split())
p = [int(i) - 1 for i in input().split()]
q = [int(i) - 1 for i in input().split()]
def inv(seq):
res = [0 for i in range(N)]
for i in range(N):
res[seq[i]] = i
return seq
def times(seq1, seq2):
res = [0 for i in range(N)]
for i in range(N):
res[i] = seq1[seq2[i]]
return res
md = [[0 for i in range(N)] for i in range(6)]
for i in range(N):
md[0][i] = p[i]
md[1][i] = q[i]
for i in range(2, 6):
md[i] = times(md[i - 1], inv(md[i - 2]))
A = times(times(q, inv(p)), times(inv(q), p))
T = (K - 1) // 6
def expseq(seq, k):
if k == 0:
return [i for i in range(N)]
elif k == 1:
return seq
elif k % 2 == 0:
return expseq(times(seq, seq), k // 2)
else:
return times(expseq(times(seq, seq), k // 2), seq)
tmp = expseq(A, T)
ans = times(times(tmp, md[(K - 1) % 6]), inv(tmp))
print(" ".join([str(i + 1) for i in ans]))
| Statement
For two permutations p and q of the integers from 1 through N, let f(p,q) be
the permutation that satisfies the following:
* The p_i-th element (1 \leq i \leq N) in f(p,q) is q_i. Here, p_i and q_i respectively denote the i-th element in p and q.
You are given two permutations p and q of the integers from 1 through N. We
will now define a sequence {a_n} of permutations of the integers from 1
through N, as follows:
* a_1=p, a_2=q
* a_{n+2}=f(a_n,a_{n+1}) ( n \geq 1 )
Given a positive integer K, find a_K. | [{"input": "3 3\n 1 2 3\n 3 2 1", "output": "3 2 1\n \n\nSince a_3=f(p,q), we just need to find f(p,q). We have p_i=i here, so\nf(p,q)=q.\n\n* * *"}, {"input": "5 5\n 4 5 1 2 3\n 3 2 1 5 4", "output": "4 3 2 1 5\n \n\n* * *"}, {"input": "10 1000000000\n 7 10 6 5 4 2 9 1 3 8\n 4 1 9 2 3 7 8 10 6 5", "output": "7 9 4 8 2 5 1 6 10 3"}] |
Print N integers, with spaces in between. The i-th integer (1 \leq i \leq N)
should be the i-th element in a_K.
* * * | s304287662 | Wrong Answer | p03098 | Input is given from Standard Input in the following format:
N K
p_1 ... p_N
q_1 ... q_N | # get f
def make_f(p, q):
N = len(p)
f = [0 for i in range(N)]
for i in range(N):
f[p[i] - 1] = q[i]
return f
# input
N, K = input().split(" ")
N = int(N)
K = int(K)
p = input().split(" ")
p = [int(pi) for pi in p]
q = input().split(" ")
q = [int(qi) for qi in q]
A = [[], p, q]
for i in range(3, K + 1):
A.append(make_f(A[-2], A[-1]))
print(A[-1])
| Statement
For two permutations p and q of the integers from 1 through N, let f(p,q) be
the permutation that satisfies the following:
* The p_i-th element (1 \leq i \leq N) in f(p,q) is q_i. Here, p_i and q_i respectively denote the i-th element in p and q.
You are given two permutations p and q of the integers from 1 through N. We
will now define a sequence {a_n} of permutations of the integers from 1
through N, as follows:
* a_1=p, a_2=q
* a_{n+2}=f(a_n,a_{n+1}) ( n \geq 1 )
Given a positive integer K, find a_K. | [{"input": "3 3\n 1 2 3\n 3 2 1", "output": "3 2 1\n \n\nSince a_3=f(p,q), we just need to find f(p,q). We have p_i=i here, so\nf(p,q)=q.\n\n* * *"}, {"input": "5 5\n 4 5 1 2 3\n 3 2 1 5 4", "output": "4 3 2 1 5\n \n\n* * *"}, {"input": "10 1000000000\n 7 10 6 5 4 2 9 1 3 8\n 4 1 9 2 3 7 8 10 6 5", "output": "7 9 4 8 2 5 1 6 10 3"}] |
Print the number of different integers not exceeding X that can be written on
the blackboard.
* * * | s283497499 | Wrong Answer | p03562 | Input is given from Standard Input in the following format:
N X
A_1
:
A_N | #!/usr/bin/env python3
def divmod(f, g):
assert g
h = 0
for i in reversed(range(f.bit_length() - g.bit_length() + 1)):
if f & (1 << (g.bit_length() + i - 1)):
f ^= g << i
h ^= 1 << i
return h, f
def gcd(f, g):
while g:
q, r = divmod(f, g)
f, g = g, r
return f
import functools
def solve(n, x, a):
# (g) = (a_1, ..., a_n) is a principal ideal since F_2[x] is a PID
g = functools.reduce(gcd, a)
# count h in F_2[x] s.t. h g <= x
cnt = 0
h = 0
for k in reversed(range(x.bit_length() - g.bit_length() + 1)):
bit = 1 << (g.bit_length() + k - 1)
if x & bit:
cnt += 1 << k
if (x & bit) != (h & bit):
h ^= g << k
cnt += 1 # zero
return cnt % 998244353
def main():
n, x = input().split()
n = int(n)
x = int(x, 2)
a = [int(input(), 2) for _ in range(n)]
print(solve(n, x, a))
if __name__ == "__main__":
main()
| Statement
There are N non-negative integers written on a blackboard. The i-th integer is
A_i.
Takahashi can perform the following two kinds of operations any number of
times in any order:
* Select one integer written on the board (let this integer be X). Write 2X on the board, without erasing the selected integer.
* Select two integers, possibly the same, written on the board (let these integers be X and Y). Write X XOR Y (XOR stands for bitwise xor) on the blackboard, without erasing the selected integers.
How many different integers not exceeding X can be written on the blackboard?
We will also count the integers that are initially written on the board. Since
the answer can be extremely large, find the count modulo 998244353. | [{"input": "3 111\n 1111\n 10111\n 10010", "output": "4\n \n\nInitially, 15, 23 and 18 are written on the blackboard. Among the integers not\nexceeding 7, four integers, 0, 3, 5 and 6, can be written. For example, 6 can\nbe written as follows:\n\n * Double 15 to write 30.\n * Take XOR of 30 and 18 to write 12.\n * Double 12 to write 24.\n * Take XOR of 30 and 24 to write 6.\n\n* * *"}, {"input": "4 100100\n 1011\n 1110\n 110101\n 1010110", "output": "37\n \n\n* * *"}, {"input": "4 111001100101001\n 10111110\n 1001000110\n 100000101\n 11110000011", "output": "1843\n \n\n* * *"}, {"input": "1 111111111111111111111111111111111111111111111111111111111111111\n 1", "output": "466025955\n \n\nBe sure to find the count modulo 998244353."}] |
Print the number of different integers not exceeding X that can be written on
the blackboard.
* * * | s947434116 | Accepted | p03562 | Input is given from Standard Input in the following format:
N X
A_1
:
A_N | import random
mod = 998244353
N, X = input().split()
N = int(N)
A = []
for i in range(N):
A.append(int(input(), 2))
A.sort()
a = A[-1]
M = max(len(X) - 1, a.bit_length() - 1)
data = [0] * (M + 1)
n = a.bit_length() - 1
for i in range(M - n, -1, -1):
data[i + n] = a << i
low = n
for i in range(0, N - 1):
a = A[i]
flag = True
while flag:
n = a.bit_length()
for j in range(n - 1, low - 1, -1):
a = min(a, a ^ data[j])
if a != 0:
data[a.bit_length() - 1] = a
id = a.bit_length() - 1
low = id
while data[id + 1] == 0:
data[id + 1] = min((data[id] << 1) ^ a, (data[id] << 1))
id += 1
else:
a = data[id] << 1
else:
break
data2 = [0] * (M + 1)
for i in range(M + 1):
data2[i] = data[i] != 0
for i in range(1, M + 1):
data2[i] += data2[i - 1]
data2 = [0] + data2
# print(data)
# print(data2)
x = 0
ans = 0
n = len(X) - 1
for i in range(len(X)):
if X[i] == "1":
if x >> (n - i) & 1 == 1:
if data[n - i]:
ans += pow(2, data2[n - i], mod)
ans %= mod
else:
ans += pow(2, data2[n - i], mod)
ans %= mod
if data[n - i]:
x = x ^ data[n - i]
else:
break
else:
if x >> (n - i) & 1 == 1:
if data[n - i]:
x = x ^ data[n - i]
else:
break
else:
continue
else:
ans += 1
ans %= mod
print(ans)
| Statement
There are N non-negative integers written on a blackboard. The i-th integer is
A_i.
Takahashi can perform the following two kinds of operations any number of
times in any order:
* Select one integer written on the board (let this integer be X). Write 2X on the board, without erasing the selected integer.
* Select two integers, possibly the same, written on the board (let these integers be X and Y). Write X XOR Y (XOR stands for bitwise xor) on the blackboard, without erasing the selected integers.
How many different integers not exceeding X can be written on the blackboard?
We will also count the integers that are initially written on the board. Since
the answer can be extremely large, find the count modulo 998244353. | [{"input": "3 111\n 1111\n 10111\n 10010", "output": "4\n \n\nInitially, 15, 23 and 18 are written on the blackboard. Among the integers not\nexceeding 7, four integers, 0, 3, 5 and 6, can be written. For example, 6 can\nbe written as follows:\n\n * Double 15 to write 30.\n * Take XOR of 30 and 18 to write 12.\n * Double 12 to write 24.\n * Take XOR of 30 and 24 to write 6.\n\n* * *"}, {"input": "4 100100\n 1011\n 1110\n 110101\n 1010110", "output": "37\n \n\n* * *"}, {"input": "4 111001100101001\n 10111110\n 1001000110\n 100000101\n 11110000011", "output": "1843\n \n\n* * *"}, {"input": "1 111111111111111111111111111111111111111111111111111111111111111\n 1", "output": "466025955\n \n\nBe sure to find the count modulo 998244353."}] |
Print the minimum number of operations required when Ringo can freely decide
how Snuke walks.
* * * | s592226412 | Wrong Answer | p03132 | Input is given from Standard Input in the following format:
L
A_1
:
A_L | 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 SI():
return sys.stdin.readline()[:-1]
def main():
n = II()
inf = 10**16
dpl = [inf] * (n + 1)
dpl[0] = 0
odd = 0
aa = []
for i in range(n):
a = II()
odd += a % 2
dpl[i + 1] = min(odd, dpl[i] + 1 - a % 2)
aa.append(a)
# print(dpl)
dpr = [inf] * (n + 1)
dpr[n] = 0
odd = 0
for i in range(n - 1, -1, -1):
a = aa[i]
odd += a % 2
dpr[i] = min(odd, dpr[i + 1] + 1 - a % 2)
# print(dpr)
even = [0]
for a in aa:
if a % 2:
even.append(even[-1])
else:
even.append(even[-1] + 1)
# print(even)
mn = inf
ans = inf
for i in range(n + 1):
mn = min(mn, dpl[i] - even[i])
cur = mn + dpr[i] + even[i]
ans = min(ans, cur)
# print(aa)
print(ans)
main()
| Statement
Snuke stands on a number line. He has L ears, and he will walk along the line
continuously under the following conditions:
* He never visits a point with coordinate less than 0, or a point with coordinate greater than L.
* He starts walking at a point with integer coordinate, and also finishes walking at a point with integer coordinate.
* He only changes direction at a point with integer coordinate.
Each time when Snuke passes a point with coordinate i-0.5, where i is an
integer, he put a stone in his i-th ear.
After Snuke finishes walking, Ringo will repeat the following operations in
some order so that, for each i, Snuke's i-th ear contains A_i stones:
* Put a stone in one of Snuke's ears.
* Remove a stone from one of Snuke's ears.
Find the minimum number of operations required when Ringo can freely decide
how Snuke walks. | [{"input": "4\n 1\n 0\n 2\n 3", "output": "1\n \n\nAssume that Snuke walks as follows:\n\n * He starts walking at coordinate 3 and finishes walking at coordinate 4, visiting coordinates 3,4,3,2,3,4 in this order.\n\nThen, Snuke's four ears will contain 0,0,2,3 stones, respectively. Ringo can\nsatisfy the requirement by putting one stone in the first ear.\n\n* * *"}, {"input": "8\n 2\n 0\n 0\n 2\n 1\n 3\n 4\n 1", "output": "3\n \n\n* * *"}, {"input": "7\n 314159265\n 358979323\n 846264338\n 327950288\n 419716939\n 937510582\n 0", "output": "1"}] |
Print the minimum number of operations required when Ringo can freely decide
how Snuke walks.
* * * | s307871034 | Runtime Error | p03132 | Input is given from Standard Input in the following format:
L
A_1
:
A_L | N=int(input())
A=[int(input()) for i in range(N)]
B=[0]*N
for i in range(N):
if A[i]>0:
if A[i]%2==0:
B[i]=2
else:
B[i]=1
L=[0,2,1,2,0]
dp=[[10**9]*5 for i in range(N+1)]
for k in range(5):
dp[0][k]=0
for i in range(1,N+1):
for k in range(5):
for k1 in range(k+1):
if 1<=k<=3:
dp[i][k]=min(dp[i][k],dp[i-1][k1]+abs(L[k]-B[i-1]))
else:
dp[i][k]=min(dp[i][k],dp[i-1][k1]+A[i-1])
ans=10**9
#print(B)
#print(dp)
for a in range(5):
ans=min(ans,dp[N][a])
print(ans)v | Statement
Snuke stands on a number line. He has L ears, and he will walk along the line
continuously under the following conditions:
* He never visits a point with coordinate less than 0, or a point with coordinate greater than L.
* He starts walking at a point with integer coordinate, and also finishes walking at a point with integer coordinate.
* He only changes direction at a point with integer coordinate.
Each time when Snuke passes a point with coordinate i-0.5, where i is an
integer, he put a stone in his i-th ear.
After Snuke finishes walking, Ringo will repeat the following operations in
some order so that, for each i, Snuke's i-th ear contains A_i stones:
* Put a stone in one of Snuke's ears.
* Remove a stone from one of Snuke's ears.
Find the minimum number of operations required when Ringo can freely decide
how Snuke walks. | [{"input": "4\n 1\n 0\n 2\n 3", "output": "1\n \n\nAssume that Snuke walks as follows:\n\n * He starts walking at coordinate 3 and finishes walking at coordinate 4, visiting coordinates 3,4,3,2,3,4 in this order.\n\nThen, Snuke's four ears will contain 0,0,2,3 stones, respectively. Ringo can\nsatisfy the requirement by putting one stone in the first ear.\n\n* * *"}, {"input": "8\n 2\n 0\n 0\n 2\n 1\n 3\n 4\n 1", "output": "3\n \n\n* * *"}, {"input": "7\n 314159265\n 358979323\n 846264338\n 327950288\n 419716939\n 937510582\n 0", "output": "1"}] |
Print the minimum number of operations required when Ringo can freely decide
how Snuke walks.
* * * | s310829660 | Accepted | p03132 | Input is given from Standard Input in the following format:
L
A_1
:
A_L | L, *A = map(int, open(0).read().split())
a0 = a1 = a2 = a3 = a4 = 0
rest = sum(A)
P = [2, 1, 0]
Q = [1, 0, 1]
for a in A:
b = (a - 1) % 2 + 1 if a else 0
p = P[b]
q = Q[b]
a0 += a
a1 = min(a0, a1 + p)
a2 = min(a1, a2 + q)
a3 = min(a2, a3 + p)
a4 = min(a3, a4 + a)
print(min(a0, a1, a2, a3, a4))
| Statement
Snuke stands on a number line. He has L ears, and he will walk along the line
continuously under the following conditions:
* He never visits a point with coordinate less than 0, or a point with coordinate greater than L.
* He starts walking at a point with integer coordinate, and also finishes walking at a point with integer coordinate.
* He only changes direction at a point with integer coordinate.
Each time when Snuke passes a point with coordinate i-0.5, where i is an
integer, he put a stone in his i-th ear.
After Snuke finishes walking, Ringo will repeat the following operations in
some order so that, for each i, Snuke's i-th ear contains A_i stones:
* Put a stone in one of Snuke's ears.
* Remove a stone from one of Snuke's ears.
Find the minimum number of operations required when Ringo can freely decide
how Snuke walks. | [{"input": "4\n 1\n 0\n 2\n 3", "output": "1\n \n\nAssume that Snuke walks as follows:\n\n * He starts walking at coordinate 3 and finishes walking at coordinate 4, visiting coordinates 3,4,3,2,3,4 in this order.\n\nThen, Snuke's four ears will contain 0,0,2,3 stones, respectively. Ringo can\nsatisfy the requirement by putting one stone in the first ear.\n\n* * *"}, {"input": "8\n 2\n 0\n 0\n 2\n 1\n 3\n 4\n 1", "output": "3\n \n\n* * *"}, {"input": "7\n 314159265\n 358979323\n 846264338\n 327950288\n 419716939\n 937510582\n 0", "output": "1"}] |
Print the minimum number of operations required when Ringo can freely decide
how Snuke walks.
* * * | s189358798 | Wrong Answer | p03132 | Input is given from Standard Input in the following format:
L
A_1
:
A_L | l = int(input())
a = []
for i in range(l):
a.append(int(input()))
if len(a) == len(set(a)):
print(1)
else:
print(len(a) - len(set(a)))
| Statement
Snuke stands on a number line. He has L ears, and he will walk along the line
continuously under the following conditions:
* He never visits a point with coordinate less than 0, or a point with coordinate greater than L.
* He starts walking at a point with integer coordinate, and also finishes walking at a point with integer coordinate.
* He only changes direction at a point with integer coordinate.
Each time when Snuke passes a point with coordinate i-0.5, where i is an
integer, he put a stone in his i-th ear.
After Snuke finishes walking, Ringo will repeat the following operations in
some order so that, for each i, Snuke's i-th ear contains A_i stones:
* Put a stone in one of Snuke's ears.
* Remove a stone from one of Snuke's ears.
Find the minimum number of operations required when Ringo can freely decide
how Snuke walks. | [{"input": "4\n 1\n 0\n 2\n 3", "output": "1\n \n\nAssume that Snuke walks as follows:\n\n * He starts walking at coordinate 3 and finishes walking at coordinate 4, visiting coordinates 3,4,3,2,3,4 in this order.\n\nThen, Snuke's four ears will contain 0,0,2,3 stones, respectively. Ringo can\nsatisfy the requirement by putting one stone in the first ear.\n\n* * *"}, {"input": "8\n 2\n 0\n 0\n 2\n 1\n 3\n 4\n 1", "output": "3\n \n\n* * *"}, {"input": "7\n 314159265\n 358979323\n 846264338\n 327950288\n 419716939\n 937510582\n 0", "output": "1"}] |
Print the minimum number of operations required when Ringo can freely decide
how Snuke walks.
* * * | s094187821 | Wrong Answer | p03132 | Input is given from Standard Input in the following format:
L
A_1
:
A_L | print(list(map(int, open(0).read().split())).count(0))
| Statement
Snuke stands on a number line. He has L ears, and he will walk along the line
continuously under the following conditions:
* He never visits a point with coordinate less than 0, or a point with coordinate greater than L.
* He starts walking at a point with integer coordinate, and also finishes walking at a point with integer coordinate.
* He only changes direction at a point with integer coordinate.
Each time when Snuke passes a point with coordinate i-0.5, where i is an
integer, he put a stone in his i-th ear.
After Snuke finishes walking, Ringo will repeat the following operations in
some order so that, for each i, Snuke's i-th ear contains A_i stones:
* Put a stone in one of Snuke's ears.
* Remove a stone from one of Snuke's ears.
Find the minimum number of operations required when Ringo can freely decide
how Snuke walks. | [{"input": "4\n 1\n 0\n 2\n 3", "output": "1\n \n\nAssume that Snuke walks as follows:\n\n * He starts walking at coordinate 3 and finishes walking at coordinate 4, visiting coordinates 3,4,3,2,3,4 in this order.\n\nThen, Snuke's four ears will contain 0,0,2,3 stones, respectively. Ringo can\nsatisfy the requirement by putting one stone in the first ear.\n\n* * *"}, {"input": "8\n 2\n 0\n 0\n 2\n 1\n 3\n 4\n 1", "output": "3\n \n\n* * *"}, {"input": "7\n 314159265\n 358979323\n 846264338\n 327950288\n 419716939\n 937510582\n 0", "output": "1"}] |
Print the minimum number of operations required when Ringo can freely decide
how Snuke walks.
* * * | s397657021 | Runtime Error | p03132 | Input is given from Standard Input in the following format:
L
A_1
:
A_L | (
l,
*a,
) = map(int, open(0).read().split())
b = [int(i % 2 == j % 2) for i, j in zip(a, a[1:])]
a = 0
c = b[0]
for i in range(1, len(b)):
if b[i]:
c += 1
else:
a = max(a, c)
c = 0
print(max(a, c))
| Statement
Snuke stands on a number line. He has L ears, and he will walk along the line
continuously under the following conditions:
* He never visits a point with coordinate less than 0, or a point with coordinate greater than L.
* He starts walking at a point with integer coordinate, and also finishes walking at a point with integer coordinate.
* He only changes direction at a point with integer coordinate.
Each time when Snuke passes a point with coordinate i-0.5, where i is an
integer, he put a stone in his i-th ear.
After Snuke finishes walking, Ringo will repeat the following operations in
some order so that, for each i, Snuke's i-th ear contains A_i stones:
* Put a stone in one of Snuke's ears.
* Remove a stone from one of Snuke's ears.
Find the minimum number of operations required when Ringo can freely decide
how Snuke walks. | [{"input": "4\n 1\n 0\n 2\n 3", "output": "1\n \n\nAssume that Snuke walks as follows:\n\n * He starts walking at coordinate 3 and finishes walking at coordinate 4, visiting coordinates 3,4,3,2,3,4 in this order.\n\nThen, Snuke's four ears will contain 0,0,2,3 stones, respectively. Ringo can\nsatisfy the requirement by putting one stone in the first ear.\n\n* * *"}, {"input": "8\n 2\n 0\n 0\n 2\n 1\n 3\n 4\n 1", "output": "3\n \n\n* * *"}, {"input": "7\n 314159265\n 358979323\n 846264338\n 327950288\n 419716939\n 937510582\n 0", "output": "1"}] |
Print the minimum number of operations required when Ringo can freely decide
how Snuke walks.
* * * | s102389952 | Wrong Answer | p03132 | Input is given from Standard Input in the following format:
L
A_1
:
A_L | L = int(input())
stones_count = []
for i in range(0, L):
A = int(input())
if A % 2 == 1:
stones_count.append(1)
elif A == 0:
stones_count.append(0)
else:
stones_count.append(2)
sub_count_0 = []
sub_count_1 = []
sub_count_2 = []
count_0 = 0
count_1 = 0
count_2 = 0
for i in range(0, L):
if stones_count[i] == 0:
if count_1 != 0:
sub_count_1.append(count_1)
if count_2 != 0:
sub_count_2.append(count_2)
count_1 = 0
count_2 = 0
count_0 += 1
elif stones_count[i] == 1:
if count_0 != 0:
sub_count_0.append(count_0)
if count_2 != 0:
sub_count_2.append(count_2)
count_2 = 0
count_1 += 1
else:
if count_0 != 0:
sub_count_0.append(count_0)
count_1 += 1
count_2 += 1
if count_0 != 0:
sub_count_0.append(count_0)
if count_1 != 0:
sub_count_1.append(count_1)
if count_2 != 0:
sub_count_2.append(count_2)
result = min(len(sub_count_1) - 1, sum(sub_count_0))
print(result + len(sub_count_2) - 1)
| Statement
Snuke stands on a number line. He has L ears, and he will walk along the line
continuously under the following conditions:
* He never visits a point with coordinate less than 0, or a point with coordinate greater than L.
* He starts walking at a point with integer coordinate, and also finishes walking at a point with integer coordinate.
* He only changes direction at a point with integer coordinate.
Each time when Snuke passes a point with coordinate i-0.5, where i is an
integer, he put a stone in his i-th ear.
After Snuke finishes walking, Ringo will repeat the following operations in
some order so that, for each i, Snuke's i-th ear contains A_i stones:
* Put a stone in one of Snuke's ears.
* Remove a stone from one of Snuke's ears.
Find the minimum number of operations required when Ringo can freely decide
how Snuke walks. | [{"input": "4\n 1\n 0\n 2\n 3", "output": "1\n \n\nAssume that Snuke walks as follows:\n\n * He starts walking at coordinate 3 and finishes walking at coordinate 4, visiting coordinates 3,4,3,2,3,4 in this order.\n\nThen, Snuke's four ears will contain 0,0,2,3 stones, respectively. Ringo can\nsatisfy the requirement by putting one stone in the first ear.\n\n* * *"}, {"input": "8\n 2\n 0\n 0\n 2\n 1\n 3\n 4\n 1", "output": "3\n \n\n* * *"}, {"input": "7\n 314159265\n 358979323\n 846264338\n 327950288\n 419716939\n 937510582\n 0", "output": "1"}] |
Print the minimum number of operations required when Ringo can freely decide
how Snuke walks.
* * * | s756735555 | Runtime Error | p03132 | Input is given from Standard Input in the following format:
L
A_1
:
A_L | //Pantyhose(black) + glasses = infinity
#include <bits/stdc++.h>
using namespace std;
#define debug(x) cerr << #x << " = " << x << '\n';
#define BP() cerr << "OK!\n";
#define PR(A, n) {cerr << #A << " = "; for (int64_t _=1; _<=n; ++_) cerr << A[_] << ' '; cerr << '\n';}
#define PR0(A, n) {cerr << #A << " = "; for (int64_t _=0; _<n; ++_) cerr << A[_] << ' '; cerr << '\n';}
#define FILE_NAME "sol"
const int64_t MAX_N = 200002;
const int64_t INF = 1e9;
int n;
int64_t a[MAX_N], cost0[MAX_N], cost1[MAX_N];
int64_t f0[MAX_N], f1[MAX_N], f2[MAX_N], f3[MAX_N], f4[MAX_N];
void readInput() {
cin >> n;
for (int i=1; i<=n; ++i)
cin >> a[i];
}
void solve() {
int64_t min_f0, min_f1, min_f2, min_f3;
min_f0 = min_f1 = min_f2 = min_f3 = 0;
for (int i=1; i<=n; ++i) {
cost0[i] = cost0[i-1] + (a[i]==0 ? 2 : a[i]%2);
cost1[i] = cost1[i-1] + (a[i]+1)%2;
f0[i] = f0[i-1] + a[i];
min_f0 = min(min_f0, -cost0[i]+f0[i]);
f1[i] = cost0[i] + min_f0;
min_f1 = min(min_f1, -cost1[i]+f1[i]);
f2[i] = cost1[i] + min_f1;
min_f2 = min(min_f2, -cost0[i]+f2[i]);
f3[i] = cost0[i] + min_f2;
min_f3 = min(min_f3, -f0[i]+f3[i]);
f4[i] = f0[i] + min_f3;
}
// debug(min_f0);
cout << f4[n];
}
int main() {
#ifdef GLASSES_GIRL
freopen(FILE_NAME".inp", "r", stdin);
freopen(FILE_NAME".out", "w", stdout);
#endif
ios::sync_with_stdio(0); cin.tie(0);
readInput();
solve();
} | Statement
Snuke stands on a number line. He has L ears, and he will walk along the line
continuously under the following conditions:
* He never visits a point with coordinate less than 0, or a point with coordinate greater than L.
* He starts walking at a point with integer coordinate, and also finishes walking at a point with integer coordinate.
* He only changes direction at a point with integer coordinate.
Each time when Snuke passes a point with coordinate i-0.5, where i is an
integer, he put a stone in his i-th ear.
After Snuke finishes walking, Ringo will repeat the following operations in
some order so that, for each i, Snuke's i-th ear contains A_i stones:
* Put a stone in one of Snuke's ears.
* Remove a stone from one of Snuke's ears.
Find the minimum number of operations required when Ringo can freely decide
how Snuke walks. | [{"input": "4\n 1\n 0\n 2\n 3", "output": "1\n \n\nAssume that Snuke walks as follows:\n\n * He starts walking at coordinate 3 and finishes walking at coordinate 4, visiting coordinates 3,4,3,2,3,4 in this order.\n\nThen, Snuke's four ears will contain 0,0,2,3 stones, respectively. Ringo can\nsatisfy the requirement by putting one stone in the first ear.\n\n* * *"}, {"input": "8\n 2\n 0\n 0\n 2\n 1\n 3\n 4\n 1", "output": "3\n \n\n* * *"}, {"input": "7\n 314159265\n 358979323\n 846264338\n 327950288\n 419716939\n 937510582\n 0", "output": "1"}] |
Print the minimum number of operations required when Ringo can freely decide
how Snuke walks.
* * * | s425832443 | Runtime Error | p03132 | Input is given from Standard Input in the following format:
L
A_1
:
A_L | def f(n):
if n==0:
return [1,2]
if n%2 == 0:
return [1,0]
return [0,1]
l = int(input())
x = [0]
x1 = 0
y = [0]
y1 = 0
z = [0]
z1 = 0
ll = []
for i in range(l):
a = int(input())
g = f(a)
if a > l:
l.append(i)
x1 += a
y1 += g[0]
z1 += g[1]
x.append(x1)
y.append(y1)
z.append(z1)
mn = min(try ll l-1)
mx = max(try ll else 0)
ans = l
for i in range(mn):
si = x[i-1]
for k in range(mx,l):
sk = x[l-1]-x[k]
for j in range(i-1,k+2):
p = y[j]-y[i-1]
q = z[j] - z[i-1]
r = y[k] - y[j-1]
s = z[k] - z[j-1]
ssss = min(p+s,q+r)
if ssss < ans:
ans = ssss
print(ans)
| Statement
Snuke stands on a number line. He has L ears, and he will walk along the line
continuously under the following conditions:
* He never visits a point with coordinate less than 0, or a point with coordinate greater than L.
* He starts walking at a point with integer coordinate, and also finishes walking at a point with integer coordinate.
* He only changes direction at a point with integer coordinate.
Each time when Snuke passes a point with coordinate i-0.5, where i is an
integer, he put a stone in his i-th ear.
After Snuke finishes walking, Ringo will repeat the following operations in
some order so that, for each i, Snuke's i-th ear contains A_i stones:
* Put a stone in one of Snuke's ears.
* Remove a stone from one of Snuke's ears.
Find the minimum number of operations required when Ringo can freely decide
how Snuke walks. | [{"input": "4\n 1\n 0\n 2\n 3", "output": "1\n \n\nAssume that Snuke walks as follows:\n\n * He starts walking at coordinate 3 and finishes walking at coordinate 4, visiting coordinates 3,4,3,2,3,4 in this order.\n\nThen, Snuke's four ears will contain 0,0,2,3 stones, respectively. Ringo can\nsatisfy the requirement by putting one stone in the first ear.\n\n* * *"}, {"input": "8\n 2\n 0\n 0\n 2\n 1\n 3\n 4\n 1", "output": "3\n \n\n* * *"}, {"input": "7\n 314159265\n 358979323\n 846264338\n 327950288\n 419716939\n 937510582\n 0", "output": "1"}] |
Print the minimum number of operations required when Ringo can freely decide
how Snuke walks.
* * * | s984675375 | Wrong Answer | p03132 | Input is given from Standard Input in the following format:
L
A_1
:
A_L | print(0)
| Statement
Snuke stands on a number line. He has L ears, and he will walk along the line
continuously under the following conditions:
* He never visits a point with coordinate less than 0, or a point with coordinate greater than L.
* He starts walking at a point with integer coordinate, and also finishes walking at a point with integer coordinate.
* He only changes direction at a point with integer coordinate.
Each time when Snuke passes a point with coordinate i-0.5, where i is an
integer, he put a stone in his i-th ear.
After Snuke finishes walking, Ringo will repeat the following operations in
some order so that, for each i, Snuke's i-th ear contains A_i stones:
* Put a stone in one of Snuke's ears.
* Remove a stone from one of Snuke's ears.
Find the minimum number of operations required when Ringo can freely decide
how Snuke walks. | [{"input": "4\n 1\n 0\n 2\n 3", "output": "1\n \n\nAssume that Snuke walks as follows:\n\n * He starts walking at coordinate 3 and finishes walking at coordinate 4, visiting coordinates 3,4,3,2,3,4 in this order.\n\nThen, Snuke's four ears will contain 0,0,2,3 stones, respectively. Ringo can\nsatisfy the requirement by putting one stone in the first ear.\n\n* * *"}, {"input": "8\n 2\n 0\n 0\n 2\n 1\n 3\n 4\n 1", "output": "3\n \n\n* * *"}, {"input": "7\n 314159265\n 358979323\n 846264338\n 327950288\n 419716939\n 937510582\n 0", "output": "1"}] |
Print the minimum number of operations required when Ringo can freely decide
how Snuke walks.
* * * | s872876084 | Wrong Answer | p03132 | Input is given from Standard Input in the following format:
L
A_1
:
A_L | n = int(input())
A = [0] * n
for i in range(0, n):
A[i] = int(input())
ans = 0
res = 0
for i in A:
if i > res:
ans += i - res
res = i
print(ans)
| Statement
Snuke stands on a number line. He has L ears, and he will walk along the line
continuously under the following conditions:
* He never visits a point with coordinate less than 0, or a point with coordinate greater than L.
* He starts walking at a point with integer coordinate, and also finishes walking at a point with integer coordinate.
* He only changes direction at a point with integer coordinate.
Each time when Snuke passes a point with coordinate i-0.5, where i is an
integer, he put a stone in his i-th ear.
After Snuke finishes walking, Ringo will repeat the following operations in
some order so that, for each i, Snuke's i-th ear contains A_i stones:
* Put a stone in one of Snuke's ears.
* Remove a stone from one of Snuke's ears.
Find the minimum number of operations required when Ringo can freely decide
how Snuke walks. | [{"input": "4\n 1\n 0\n 2\n 3", "output": "1\n \n\nAssume that Snuke walks as follows:\n\n * He starts walking at coordinate 3 and finishes walking at coordinate 4, visiting coordinates 3,4,3,2,3,4 in this order.\n\nThen, Snuke's four ears will contain 0,0,2,3 stones, respectively. Ringo can\nsatisfy the requirement by putting one stone in the first ear.\n\n* * *"}, {"input": "8\n 2\n 0\n 0\n 2\n 1\n 3\n 4\n 1", "output": "3\n \n\n* * *"}, {"input": "7\n 314159265\n 358979323\n 846264338\n 327950288\n 419716939\n 937510582\n 0", "output": "1"}] |
Print the minimum number of operations required when Ringo can freely decide
how Snuke walks.
* * * | s288991162 | Runtime Error | p03132 | Input is given from Standard Input in the following format:
L
A_1
:
A_L | l = int(input())
a = []
mountain = []
count = 1
for i in range(l):
x = int(input())
if x == 0 and len(a) > 0:
mountain.append(a)
a = []
elif x != 0:
a.append(x)
if len(a) > 0:
mountain.append(a)
sum_mountain = []
for i in range(len(mountain)):
sum_mountain.append(sum(mountain[i]))
max_sum = max(sum_mountain)
for i in range(len(sum_mountain)):
if max_sum != sum_mountain[i]:
count += sum_mountain[i]
print(count)
| Statement
Snuke stands on a number line. He has L ears, and he will walk along the line
continuously under the following conditions:
* He never visits a point with coordinate less than 0, or a point with coordinate greater than L.
* He starts walking at a point with integer coordinate, and also finishes walking at a point with integer coordinate.
* He only changes direction at a point with integer coordinate.
Each time when Snuke passes a point with coordinate i-0.5, where i is an
integer, he put a stone in his i-th ear.
After Snuke finishes walking, Ringo will repeat the following operations in
some order so that, for each i, Snuke's i-th ear contains A_i stones:
* Put a stone in one of Snuke's ears.
* Remove a stone from one of Snuke's ears.
Find the minimum number of operations required when Ringo can freely decide
how Snuke walks. | [{"input": "4\n 1\n 0\n 2\n 3", "output": "1\n \n\nAssume that Snuke walks as follows:\n\n * He starts walking at coordinate 3 and finishes walking at coordinate 4, visiting coordinates 3,4,3,2,3,4 in this order.\n\nThen, Snuke's four ears will contain 0,0,2,3 stones, respectively. Ringo can\nsatisfy the requirement by putting one stone in the first ear.\n\n* * *"}, {"input": "8\n 2\n 0\n 0\n 2\n 1\n 3\n 4\n 1", "output": "3\n \n\n* * *"}, {"input": "7\n 314159265\n 358979323\n 846264338\n 327950288\n 419716939\n 937510582\n 0", "output": "1"}] |
Print the minimum number of operations required when Ringo can freely decide
how Snuke walks.
* * * | s639541012 | Wrong Answer | p03132 | Input is given from Standard Input in the following format:
L
A_1
:
A_L | import sys
input = sys.stdin.readline
N = int(input())
A = [int(input()) for _ in range(N)]
p1 = 0
p2 = 0
P1 = [0]
P2 = [0]
for a in A:
if a == 0:
p1 -= 2
p2 += 1
elif a % 2 == 0:
p2 -= 1
elif a % 2 == 1:
p1 -= 1
p2 += 1
p1 += a
P1.append(p1)
P2.append(p2)
S = sum(A)
dp = [[0, 0, 0, 0] for _ in range(N + 1)]
dp[N] = [P1[N], P1[N] + P2[N], P1[N], 0]
for i in reversed(range(N)):
dp[i][0] = max(dp[i + 1][0], P1[i])
dp[i][1] = max(dp[i + 1][1], P2[i] + dp[i][0])
dp[i][2] = min(dp[i + 1][2], P2[i] - dp[i][1])
dp[i][3] = min(dp[i + 1][3], P1[i] + dp[i][2])
print(dp[0][3] + S)
| Statement
Snuke stands on a number line. He has L ears, and he will walk along the line
continuously under the following conditions:
* He never visits a point with coordinate less than 0, or a point with coordinate greater than L.
* He starts walking at a point with integer coordinate, and also finishes walking at a point with integer coordinate.
* He only changes direction at a point with integer coordinate.
Each time when Snuke passes a point with coordinate i-0.5, where i is an
integer, he put a stone in his i-th ear.
After Snuke finishes walking, Ringo will repeat the following operations in
some order so that, for each i, Snuke's i-th ear contains A_i stones:
* Put a stone in one of Snuke's ears.
* Remove a stone from one of Snuke's ears.
Find the minimum number of operations required when Ringo can freely decide
how Snuke walks. | [{"input": "4\n 1\n 0\n 2\n 3", "output": "1\n \n\nAssume that Snuke walks as follows:\n\n * He starts walking at coordinate 3 and finishes walking at coordinate 4, visiting coordinates 3,4,3,2,3,4 in this order.\n\nThen, Snuke's four ears will contain 0,0,2,3 stones, respectively. Ringo can\nsatisfy the requirement by putting one stone in the first ear.\n\n* * *"}, {"input": "8\n 2\n 0\n 0\n 2\n 1\n 3\n 4\n 1", "output": "3\n \n\n* * *"}, {"input": "7\n 314159265\n 358979323\n 846264338\n 327950288\n 419716939\n 937510582\n 0", "output": "1"}] |