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 maximum number of desires that can be satisfied at the same time.
* * * | s861471128 | Wrong Answer | p03460 | Input is given from Standard Input in the following format:
N K
x_1 y_1 c_1
x_2 y_2 c_2
:
x_N y_N c_N | n, k = map(int, input().split())
# xs = []
# ys = []
# cs = []
kk = k * 2
pos = [0] * (kk * kk)
for _ in range(n):
x, y, c = input().split()
x = int(x) % kk
y = int(y) % kk
if c == "B":
x = (x + k) % kk
pos[y * kk + x] += 1
# for i in range(kk):
# print(pos[i*kk:i*kk+kk])
# print('--')
acc = [0] * (kk * kk)
for y in range(kk):
s = acc[y * kk] = sum(pos[y * kk : y * kk + k])
for x in range(1, k + 1):
acc[y * kk + x] = s = s - pos[y * kk + x - 1] + pos[y * kk + x + k - 1]
for x in range(k + 1, kk):
acc[y * kk + x] = s = s - pos[y * kk + x - 1] + pos[y * kk + x - k - 1]
# for i in range(kk):
# print(acc[i*kk:i*kk+kk])
# print('--')
# reuse memory.
ans = pos
for x in range(kk):
s = ans[x] = sum(acc[x : kk * k : kk])
for y in range(1, k + 1):
ans[y * kk + x] = s = s - acc[y * kk + x - kk] + acc[y * kk + x + k - kk]
for y in range(k + 1, kk):
ans[y * kk + x] = s = s - acc[y * kk + x - kk] + acc[y * kk + x - k - kk]
# for i in range(kk):
# print(ans[i*kk:i*kk+kk])
print(max(ans))
| Statement
AtCoDeer is thinking of painting an infinite two-dimensional grid in a
_checked pattern of side K_. Here, a checked pattern of side K is a pattern
where each square is painted black or white so that each connected component
of each color is a K × K square. Below is an example of a checked pattern of
side 3:

AtCoDeer has N desires. The i-th desire is represented by x_i, y_i and c_i. If
c_i is `B`, it means that he wants to paint the square (x_i,y_i) black; if c_i
is `W`, he wants to paint the square (x_i,y_i) white. At most how many desires
can he satisfy at the same time? | [{"input": "4 3\n 0 1 W\n 1 2 W\n 5 3 B\n 5 4 B", "output": "4\n \n\nHe can satisfy all his desires by painting as shown in the example above.\n\n* * *"}, {"input": "2 1000\n 0 0 B\n 0 1 W", "output": "2\n \n\n* * *"}, {"input": "6 2\n 1 2 B\n 2 1 W\n 2 2 B\n 1 0 B\n 0 6 W\n 4 5 W", "output": "4"}] |
Print the maximum number of desires that can be satisfied at the same time.
* * * | s038571803 | Wrong Answer | p03460 | Input is given from Standard Input in the following format:
N K
x_1 y_1 c_1
x_2 y_2 c_2
:
x_N y_N c_N | n, k = map(int, input().split())
l = []
for i in range(n):
a = list(input().split())
l.append(a)
l1 = [[0, 1, 5], [0, 1, 2], [4, 5, 0]]
l2 = [[2, 3, 4], [3, 4, 5], [1, 2, 3]]
count = [0 for i in range(18)]
for i in range(n):
p = int(l[i][0])
q = int(l[i][1])
if p < 0:
p1 = 6 - ((abs(p)) % 6)
if p1 == 6:
p1 = 0
else:
p1 = p % 6
if q < 0:
q1 = 6 - ((abs(q)) % 6)
if q1 == 6:
q1 = 0
else:
q1 = q % 6
c = 0
for j in range(3):
for x in range(3):
if p1 in l1[j]:
if q1 in l1[x]:
if l[i][2] == "W":
count[c] += 1
else:
count[9 + c] += 1
else:
if l[i][2] == "B":
count[c] += 1
else:
count[9 + c] += 1
else:
if q1 in l1[x]:
if l[i][2] == "B":
count[c] += 1
else:
count[9 + c] += 1
else:
if l[i][2] == "W":
count[c] += 1
else:
count[9 + c] += 1
c += 1
print(max(count))
| Statement
AtCoDeer is thinking of painting an infinite two-dimensional grid in a
_checked pattern of side K_. Here, a checked pattern of side K is a pattern
where each square is painted black or white so that each connected component
of each color is a K × K square. Below is an example of a checked pattern of
side 3:

AtCoDeer has N desires. The i-th desire is represented by x_i, y_i and c_i. If
c_i is `B`, it means that he wants to paint the square (x_i,y_i) black; if c_i
is `W`, he wants to paint the square (x_i,y_i) white. At most how many desires
can he satisfy at the same time? | [{"input": "4 3\n 0 1 W\n 1 2 W\n 5 3 B\n 5 4 B", "output": "4\n \n\nHe can satisfy all his desires by painting as shown in the example above.\n\n* * *"}, {"input": "2 1000\n 0 0 B\n 0 1 W", "output": "2\n \n\n* * *"}, {"input": "6 2\n 1 2 B\n 2 1 W\n 2 2 B\n 1 0 B\n 0 6 W\n 4 5 W", "output": "4"}] |
Print N lines. The i-th line (1 ≤ i ≤ N) should contain the identification
number of the restaurant that is introduced i-th in the book.
* * * | s944153552 | Accepted | p03030 | Input is given from Standard Input in the following format:
N
S_1 P_1
:
S_N P_N | # 14 ABC128B
n = int(input())
sp = [[list(input().split()), i] for i in range(n)]
res = sorted(sp, key=lambda x: (x[0][0], -int(x[0][1])))
for t in res:
print(t[1] + 1)
| Statement
You have decided to write a book introducing good restaurants. There are N
restaurants that you want to introduce: Restaurant 1, Restaurant 2, ...,
Restaurant N. Restaurant i is in city S_i, and your assessment score of that
restaurant on a 100-point scale is P_i. No two restaurants have the same
score.
You want to introduce the restaurants in the following order:
* The restaurants are arranged in lexicographical order of the names of their cities.
* If there are multiple restaurants in the same city, they are arranged in descending order of score.
Print the identification numbers of the restaurants in the order they are
introduced in the book. | [{"input": "6\n khabarovsk 20\n moscow 10\n kazan 50\n kazan 35\n moscow 60\n khabarovsk 40", "output": "3\n 4\n 6\n 1\n 5\n 2\n \n\nThe lexicographical order of the names of the three cities is `kazan` <\n`khabarovsk` < `moscow`. For each of these cities, the restaurants in it are\nintroduced in descending order of score. Thus, the restaurants are introduced\nin the order 3,4,6,1,5,2.\n\n* * *"}, {"input": "10\n yakutsk 10\n yakutsk 20\n yakutsk 30\n yakutsk 40\n yakutsk 50\n yakutsk 60\n yakutsk 70\n yakutsk 80\n yakutsk 90\n yakutsk 100", "output": "10\n 9\n 8\n 7\n 6\n 5\n 4\n 3\n 2\n 1"}] |
Print N lines. The i-th line (1 ≤ i ≤ N) should contain the identification
number of the restaurant that is introduced i-th in the book.
* * * | s228416892 | Runtime Error | p03030 | Input is given from Standard Input in the following format:
N
S_1 P_1
:
S_N P_N | n = int(input())
s = list(list(input().split()) for _ in range(n))
ans = [s.index(i)+1 for i in sorted(s, key=lambda x:(x[0], -int(x[1])))]
print(i) for i in ans
| Statement
You have decided to write a book introducing good restaurants. There are N
restaurants that you want to introduce: Restaurant 1, Restaurant 2, ...,
Restaurant N. Restaurant i is in city S_i, and your assessment score of that
restaurant on a 100-point scale is P_i. No two restaurants have the same
score.
You want to introduce the restaurants in the following order:
* The restaurants are arranged in lexicographical order of the names of their cities.
* If there are multiple restaurants in the same city, they are arranged in descending order of score.
Print the identification numbers of the restaurants in the order they are
introduced in the book. | [{"input": "6\n khabarovsk 20\n moscow 10\n kazan 50\n kazan 35\n moscow 60\n khabarovsk 40", "output": "3\n 4\n 6\n 1\n 5\n 2\n \n\nThe lexicographical order of the names of the three cities is `kazan` <\n`khabarovsk` < `moscow`. For each of these cities, the restaurants in it are\nintroduced in descending order of score. Thus, the restaurants are introduced\nin the order 3,4,6,1,5,2.\n\n* * *"}, {"input": "10\n yakutsk 10\n yakutsk 20\n yakutsk 30\n yakutsk 40\n yakutsk 50\n yakutsk 60\n yakutsk 70\n yakutsk 80\n yakutsk 90\n yakutsk 100", "output": "10\n 9\n 8\n 7\n 6\n 5\n 4\n 3\n 2\n 1"}] |
Print N lines. The i-th line (1 ≤ i ≤ N) should contain the identification
number of the restaurant that is introduced i-th in the book.
* * * | s062815538 | Accepted | p03030 | Input is given from Standard Input in the following format:
N
S_1 P_1
:
S_N P_N | n = int(input())
dic1 = {}
bokk = []
list0 = []
for i in range(n):
c, p = map(str, input().split())
p = int(p)
list0.append([c, p])
if c not in dic1:
dic1[c] = []
dic1[c].append(p)
dic1 = dict(sorted(dic1.items()))
for i, k in dic1.items():
k.sort(reverse=True)
for j in k:
bokk.append([i, j])
for i in bokk:
print(list0.index(i) + 1)
| Statement
You have decided to write a book introducing good restaurants. There are N
restaurants that you want to introduce: Restaurant 1, Restaurant 2, ...,
Restaurant N. Restaurant i is in city S_i, and your assessment score of that
restaurant on a 100-point scale is P_i. No two restaurants have the same
score.
You want to introduce the restaurants in the following order:
* The restaurants are arranged in lexicographical order of the names of their cities.
* If there are multiple restaurants in the same city, they are arranged in descending order of score.
Print the identification numbers of the restaurants in the order they are
introduced in the book. | [{"input": "6\n khabarovsk 20\n moscow 10\n kazan 50\n kazan 35\n moscow 60\n khabarovsk 40", "output": "3\n 4\n 6\n 1\n 5\n 2\n \n\nThe lexicographical order of the names of the three cities is `kazan` <\n`khabarovsk` < `moscow`. For each of these cities, the restaurants in it are\nintroduced in descending order of score. Thus, the restaurants are introduced\nin the order 3,4,6,1,5,2.\n\n* * *"}, {"input": "10\n yakutsk 10\n yakutsk 20\n yakutsk 30\n yakutsk 40\n yakutsk 50\n yakutsk 60\n yakutsk 70\n yakutsk 80\n yakutsk 90\n yakutsk 100", "output": "10\n 9\n 8\n 7\n 6\n 5\n 4\n 3\n 2\n 1"}] |
Print N lines. The i-th line (1 ≤ i ≤ N) should contain the identification
number of the restaurant that is introduced i-th in the book.
* * * | s459127815 | Accepted | p03030 | Input is given from Standard Input in the following format:
N
S_1 P_1
:
S_N P_N | list1 = []
N = int(input())
# Looping in the range (N+1)-1
for i in range((N - 1) + 1):
X = input()
S, P = map(str, X.split())
list1.append((i + 1, S, int(P)))
# lamda sorting
list2 = sorted(list1, key=lambda x: (x[1], -x[2]))
for all in list2:
print(all[0])
| Statement
You have decided to write a book introducing good restaurants. There are N
restaurants that you want to introduce: Restaurant 1, Restaurant 2, ...,
Restaurant N. Restaurant i is in city S_i, and your assessment score of that
restaurant on a 100-point scale is P_i. No two restaurants have the same
score.
You want to introduce the restaurants in the following order:
* The restaurants are arranged in lexicographical order of the names of their cities.
* If there are multiple restaurants in the same city, they are arranged in descending order of score.
Print the identification numbers of the restaurants in the order they are
introduced in the book. | [{"input": "6\n khabarovsk 20\n moscow 10\n kazan 50\n kazan 35\n moscow 60\n khabarovsk 40", "output": "3\n 4\n 6\n 1\n 5\n 2\n \n\nThe lexicographical order of the names of the three cities is `kazan` <\n`khabarovsk` < `moscow`. For each of these cities, the restaurants in it are\nintroduced in descending order of score. Thus, the restaurants are introduced\nin the order 3,4,6,1,5,2.\n\n* * *"}, {"input": "10\n yakutsk 10\n yakutsk 20\n yakutsk 30\n yakutsk 40\n yakutsk 50\n yakutsk 60\n yakutsk 70\n yakutsk 80\n yakutsk 90\n yakutsk 100", "output": "10\n 9\n 8\n 7\n 6\n 5\n 4\n 3\n 2\n 1"}] |
Print N lines. The i-th line (1 ≤ i ≤ N) should contain the identification
number of the restaurant that is introduced i-th in the book.
* * * | s751106346 | Accepted | p03030 | Input is given from Standard Input in the following format:
N
S_1 P_1
:
S_N P_N | N = int(input())
M = [input().split() for i in range(N)]
O = [M[j][0] for j in range(N)]
P = list(set(O))
P.sort()
Q = [int(M[k][1]) for k in range(N)]
Q.sort()
Q.reverse()
for l in P:
for m in Q:
R = [l, str(m)]
if (R in M) == True:
print(M.index(R) + 1)
| Statement
You have decided to write a book introducing good restaurants. There are N
restaurants that you want to introduce: Restaurant 1, Restaurant 2, ...,
Restaurant N. Restaurant i is in city S_i, and your assessment score of that
restaurant on a 100-point scale is P_i. No two restaurants have the same
score.
You want to introduce the restaurants in the following order:
* The restaurants are arranged in lexicographical order of the names of their cities.
* If there are multiple restaurants in the same city, they are arranged in descending order of score.
Print the identification numbers of the restaurants in the order they are
introduced in the book. | [{"input": "6\n khabarovsk 20\n moscow 10\n kazan 50\n kazan 35\n moscow 60\n khabarovsk 40", "output": "3\n 4\n 6\n 1\n 5\n 2\n \n\nThe lexicographical order of the names of the three cities is `kazan` <\n`khabarovsk` < `moscow`. For each of these cities, the restaurants in it are\nintroduced in descending order of score. Thus, the restaurants are introduced\nin the order 3,4,6,1,5,2.\n\n* * *"}, {"input": "10\n yakutsk 10\n yakutsk 20\n yakutsk 30\n yakutsk 40\n yakutsk 50\n yakutsk 60\n yakutsk 70\n yakutsk 80\n yakutsk 90\n yakutsk 100", "output": "10\n 9\n 8\n 7\n 6\n 5\n 4\n 3\n 2\n 1"}] |
Print N lines. The i-th line (1 ≤ i ≤ N) should contain the identification
number of the restaurant that is introduced i-th in the book.
* * * | s155443330 | Runtime Error | p03030 | Input is given from Standard Input in the following format:
N
S_1 P_1
:
S_N P_N | n = int(input())
lst = []
for i in range(n):
s, p = input().split()
p = int(p)
lst.append((s, p, i+1))
lst_sorted = sorted(lst, key:lambda x: (x[0], -x[1]))
for _, _, num in lst_sorted:
print(num) | Statement
You have decided to write a book introducing good restaurants. There are N
restaurants that you want to introduce: Restaurant 1, Restaurant 2, ...,
Restaurant N. Restaurant i is in city S_i, and your assessment score of that
restaurant on a 100-point scale is P_i. No two restaurants have the same
score.
You want to introduce the restaurants in the following order:
* The restaurants are arranged in lexicographical order of the names of their cities.
* If there are multiple restaurants in the same city, they are arranged in descending order of score.
Print the identification numbers of the restaurants in the order they are
introduced in the book. | [{"input": "6\n khabarovsk 20\n moscow 10\n kazan 50\n kazan 35\n moscow 60\n khabarovsk 40", "output": "3\n 4\n 6\n 1\n 5\n 2\n \n\nThe lexicographical order of the names of the three cities is `kazan` <\n`khabarovsk` < `moscow`. For each of these cities, the restaurants in it are\nintroduced in descending order of score. Thus, the restaurants are introduced\nin the order 3,4,6,1,5,2.\n\n* * *"}, {"input": "10\n yakutsk 10\n yakutsk 20\n yakutsk 30\n yakutsk 40\n yakutsk 50\n yakutsk 60\n yakutsk 70\n yakutsk 80\n yakutsk 90\n yakutsk 100", "output": "10\n 9\n 8\n 7\n 6\n 5\n 4\n 3\n 2\n 1"}] |
Print N lines. The i-th line (1 ≤ i ≤ N) should contain the identification
number of the restaurant that is introduced i-th in the book.
* * * | s436570069 | Accepted | p03030 | Input is given from Standard Input in the following format:
N
S_1 P_1
:
S_N P_N | N = int(input())
S = [""] * N
P_s = [""] * N
P = [0] * N
Idx = [0] * N
for i in range(N):
S[i], P_s[i] = map(str, input().split())
P[i] = int(P_s[i])
Idx[i] = i
m_i = 0
m_p = -1
for i in range(N - 1):
for j in range(i, N):
if m_p < P[j]:
m_i = j
m_p = P[j]
tmp = P[i]
P[i] = P[m_i]
P[m_i] = tmp
tmp_s = S[i]
S[i] = S[m_i]
S[m_i] = tmp_s
tmp_i = Idx[i]
Idx[i] = Idx[m_i]
Idx[m_i] = tmp_i
m_p = -1
for i in range(0, N - 1):
for j in range(1, N - i):
if S[j] < S[j - 1]:
tmp = P[j]
P[j] = P[j - 1]
P[j - 1] = tmp
tmp_s = S[j]
S[j] = S[j - 1]
S[j - 1] = tmp_s
tmp_i = Idx[j]
Idx[j] = Idx[j - 1]
Idx[j - 1] = tmp_i
for i in range(N):
print(Idx[i] + 1)
| Statement
You have decided to write a book introducing good restaurants. There are N
restaurants that you want to introduce: Restaurant 1, Restaurant 2, ...,
Restaurant N. Restaurant i is in city S_i, and your assessment score of that
restaurant on a 100-point scale is P_i. No two restaurants have the same
score.
You want to introduce the restaurants in the following order:
* The restaurants are arranged in lexicographical order of the names of their cities.
* If there are multiple restaurants in the same city, they are arranged in descending order of score.
Print the identification numbers of the restaurants in the order they are
introduced in the book. | [{"input": "6\n khabarovsk 20\n moscow 10\n kazan 50\n kazan 35\n moscow 60\n khabarovsk 40", "output": "3\n 4\n 6\n 1\n 5\n 2\n \n\nThe lexicographical order of the names of the three cities is `kazan` <\n`khabarovsk` < `moscow`. For each of these cities, the restaurants in it are\nintroduced in descending order of score. Thus, the restaurants are introduced\nin the order 3,4,6,1,5,2.\n\n* * *"}, {"input": "10\n yakutsk 10\n yakutsk 20\n yakutsk 30\n yakutsk 40\n yakutsk 50\n yakutsk 60\n yakutsk 70\n yakutsk 80\n yakutsk 90\n yakutsk 100", "output": "10\n 9\n 8\n 7\n 6\n 5\n 4\n 3\n 2\n 1"}] |
Print N lines. The i-th line (1 ≤ i ≤ N) should contain the identification
number of the restaurant that is introduced i-th in the book.
* * * | s160820844 | Wrong Answer | p03030 | Input is given from Standard Input in the following format:
N
S_1 P_1
:
S_N P_N | N = int(input())
lines = [input().split(" ") for i in range(N)]
for i in lines:
i[1] = int(i[1])
# 数字でソート
l = sorted(lines, key=lambda x: (x[1]), reverse=True)
# 文字でソート
l = sorted(l, key=lambda x: (x[0]))
print(l)
for u in l:
for o in lines:
if o == u:
print(lines.index(o) + 1)
| Statement
You have decided to write a book introducing good restaurants. There are N
restaurants that you want to introduce: Restaurant 1, Restaurant 2, ...,
Restaurant N. Restaurant i is in city S_i, and your assessment score of that
restaurant on a 100-point scale is P_i. No two restaurants have the same
score.
You want to introduce the restaurants in the following order:
* The restaurants are arranged in lexicographical order of the names of their cities.
* If there are multiple restaurants in the same city, they are arranged in descending order of score.
Print the identification numbers of the restaurants in the order they are
introduced in the book. | [{"input": "6\n khabarovsk 20\n moscow 10\n kazan 50\n kazan 35\n moscow 60\n khabarovsk 40", "output": "3\n 4\n 6\n 1\n 5\n 2\n \n\nThe lexicographical order of the names of the three cities is `kazan` <\n`khabarovsk` < `moscow`. For each of these cities, the restaurants in it are\nintroduced in descending order of score. Thus, the restaurants are introduced\nin the order 3,4,6,1,5,2.\n\n* * *"}, {"input": "10\n yakutsk 10\n yakutsk 20\n yakutsk 30\n yakutsk 40\n yakutsk 50\n yakutsk 60\n yakutsk 70\n yakutsk 80\n yakutsk 90\n yakutsk 100", "output": "10\n 9\n 8\n 7\n 6\n 5\n 4\n 3\n 2\n 1"}] |
Print N lines. The i-th line (1 ≤ i ≤ N) should contain the identification
number of the restaurant that is introduced i-th in the book.
* * * | s618542584 | Wrong Answer | p03030 | Input is given from Standard Input in the following format:
N
S_1 P_1
:
S_N P_N | from collections import defaultdict
def solve():
n = input()
s = []
p = []
m = defaultdict(list)
mm = {}
for i in range(0, int(n)):
si, pi = map(str, input().split())
s.append(si)
p.append(int(pi))
m[si].append(int(pi))
mm[int(pi)] = i + 1
s.sort()
ss = set(s)
sss = list(ss)
sss.sort()
for i in range(len(sss)):
s2 = sss[i]
pd = m[s2]
pd.reverse()
for j in range(len(pd)):
print(mm[pd[j]])
if __name__ == "__main__":
solve()
| Statement
You have decided to write a book introducing good restaurants. There are N
restaurants that you want to introduce: Restaurant 1, Restaurant 2, ...,
Restaurant N. Restaurant i is in city S_i, and your assessment score of that
restaurant on a 100-point scale is P_i. No two restaurants have the same
score.
You want to introduce the restaurants in the following order:
* The restaurants are arranged in lexicographical order of the names of their cities.
* If there are multiple restaurants in the same city, they are arranged in descending order of score.
Print the identification numbers of the restaurants in the order they are
introduced in the book. | [{"input": "6\n khabarovsk 20\n moscow 10\n kazan 50\n kazan 35\n moscow 60\n khabarovsk 40", "output": "3\n 4\n 6\n 1\n 5\n 2\n \n\nThe lexicographical order of the names of the three cities is `kazan` <\n`khabarovsk` < `moscow`. For each of these cities, the restaurants in it are\nintroduced in descending order of score. Thus, the restaurants are introduced\nin the order 3,4,6,1,5,2.\n\n* * *"}, {"input": "10\n yakutsk 10\n yakutsk 20\n yakutsk 30\n yakutsk 40\n yakutsk 50\n yakutsk 60\n yakutsk 70\n yakutsk 80\n yakutsk 90\n yakutsk 100", "output": "10\n 9\n 8\n 7\n 6\n 5\n 4\n 3\n 2\n 1"}] |
Print N lines. The i-th line (1 ≤ i ≤ N) should contain the identification
number of the restaurant that is introduced i-th in the book.
* * * | s632860649 | Accepted | p03030 | Input is given from Standard Input in the following format:
N
S_1 P_1
:
S_N P_N | n = [(input().split()) for _ in range(int(input()))]
m = sorted(sorted(n, key=lambda x: int(x[1]), reverse=True), key=lambda x: x[0])
print("\n".join([str(n.index(li) + 1) for li in m]))
| Statement
You have decided to write a book introducing good restaurants. There are N
restaurants that you want to introduce: Restaurant 1, Restaurant 2, ...,
Restaurant N. Restaurant i is in city S_i, and your assessment score of that
restaurant on a 100-point scale is P_i. No two restaurants have the same
score.
You want to introduce the restaurants in the following order:
* The restaurants are arranged in lexicographical order of the names of their cities.
* If there are multiple restaurants in the same city, they are arranged in descending order of score.
Print the identification numbers of the restaurants in the order they are
introduced in the book. | [{"input": "6\n khabarovsk 20\n moscow 10\n kazan 50\n kazan 35\n moscow 60\n khabarovsk 40", "output": "3\n 4\n 6\n 1\n 5\n 2\n \n\nThe lexicographical order of the names of the three cities is `kazan` <\n`khabarovsk` < `moscow`. For each of these cities, the restaurants in it are\nintroduced in descending order of score. Thus, the restaurants are introduced\nin the order 3,4,6,1,5,2.\n\n* * *"}, {"input": "10\n yakutsk 10\n yakutsk 20\n yakutsk 30\n yakutsk 40\n yakutsk 50\n yakutsk 60\n yakutsk 70\n yakutsk 80\n yakutsk 90\n yakutsk 100", "output": "10\n 9\n 8\n 7\n 6\n 5\n 4\n 3\n 2\n 1"}] |
Print N lines. The i-th line (1 ≤ i ≤ N) should contain the identification
number of the restaurant that is introduced i-th in the book.
* * * | s678654873 | Accepted | p03030 | Input is given from Standard Input in the following format:
N
S_1 P_1
:
S_N P_N | n = int(input())
rs = [list(input().split()) for _ in range(n)]
new_rs = sorted(rs, key=lambda x: -int(x[1]))
def mp_count(s):
mps = {}
for (
mp,
_,
) in s: # 2個の変数を用意しないと、1個の変数にリストがいい感じにおさまってしまう
if mp not in mps:
mps[mp] = 0
return sorted(mps)
for m in mp_count(rs):
for r in new_rs:
if m == r[0]:
print(rs.index(r) + 1)
| Statement
You have decided to write a book introducing good restaurants. There are N
restaurants that you want to introduce: Restaurant 1, Restaurant 2, ...,
Restaurant N. Restaurant i is in city S_i, and your assessment score of that
restaurant on a 100-point scale is P_i. No two restaurants have the same
score.
You want to introduce the restaurants in the following order:
* The restaurants are arranged in lexicographical order of the names of their cities.
* If there are multiple restaurants in the same city, they are arranged in descending order of score.
Print the identification numbers of the restaurants in the order they are
introduced in the book. | [{"input": "6\n khabarovsk 20\n moscow 10\n kazan 50\n kazan 35\n moscow 60\n khabarovsk 40", "output": "3\n 4\n 6\n 1\n 5\n 2\n \n\nThe lexicographical order of the names of the three cities is `kazan` <\n`khabarovsk` < `moscow`. For each of these cities, the restaurants in it are\nintroduced in descending order of score. Thus, the restaurants are introduced\nin the order 3,4,6,1,5,2.\n\n* * *"}, {"input": "10\n yakutsk 10\n yakutsk 20\n yakutsk 30\n yakutsk 40\n yakutsk 50\n yakutsk 60\n yakutsk 70\n yakutsk 80\n yakutsk 90\n yakutsk 100", "output": "10\n 9\n 8\n 7\n 6\n 5\n 4\n 3\n 2\n 1"}] |
Print N lines. The i-th line (1 ≤ i ≤ N) should contain the identification
number of the restaurant that is introduced i-th in the book.
* * * | s963143040 | Wrong Answer | p03030 | Input is given from Standard Input in the following format:
N
S_1 P_1
:
S_N P_N | n = int(input())
lists = [list(input().split()) for x in range(n)]
for x in range(n):
lists[x].append(x + 1)
lists.sort(key=lambda t: t[1], reverse=True)
lists.sort(key=lambda t: t[0])
for x in range(n):
print(lists[x][2])
| Statement
You have decided to write a book introducing good restaurants. There are N
restaurants that you want to introduce: Restaurant 1, Restaurant 2, ...,
Restaurant N. Restaurant i is in city S_i, and your assessment score of that
restaurant on a 100-point scale is P_i. No two restaurants have the same
score.
You want to introduce the restaurants in the following order:
* The restaurants are arranged in lexicographical order of the names of their cities.
* If there are multiple restaurants in the same city, they are arranged in descending order of score.
Print the identification numbers of the restaurants in the order they are
introduced in the book. | [{"input": "6\n khabarovsk 20\n moscow 10\n kazan 50\n kazan 35\n moscow 60\n khabarovsk 40", "output": "3\n 4\n 6\n 1\n 5\n 2\n \n\nThe lexicographical order of the names of the three cities is `kazan` <\n`khabarovsk` < `moscow`. For each of these cities, the restaurants in it are\nintroduced in descending order of score. Thus, the restaurants are introduced\nin the order 3,4,6,1,5,2.\n\n* * *"}, {"input": "10\n yakutsk 10\n yakutsk 20\n yakutsk 30\n yakutsk 40\n yakutsk 50\n yakutsk 60\n yakutsk 70\n yakutsk 80\n yakutsk 90\n yakutsk 100", "output": "10\n 9\n 8\n 7\n 6\n 5\n 4\n 3\n 2\n 1"}] |
Print N lines. The i-th line (1 ≤ i ≤ N) should contain the identification
number of the restaurant that is introduced i-th in the book.
* * * | s608936736 | Runtime Error | p03030 | Input is given from Standard Input in the following format:
N
S_1 P_1
:
S_N P_N | n = int(input())
li = [list(map(input().split())) for _ in range(n)]
print(li)
| Statement
You have decided to write a book introducing good restaurants. There are N
restaurants that you want to introduce: Restaurant 1, Restaurant 2, ...,
Restaurant N. Restaurant i is in city S_i, and your assessment score of that
restaurant on a 100-point scale is P_i. No two restaurants have the same
score.
You want to introduce the restaurants in the following order:
* The restaurants are arranged in lexicographical order of the names of their cities.
* If there are multiple restaurants in the same city, they are arranged in descending order of score.
Print the identification numbers of the restaurants in the order they are
introduced in the book. | [{"input": "6\n khabarovsk 20\n moscow 10\n kazan 50\n kazan 35\n moscow 60\n khabarovsk 40", "output": "3\n 4\n 6\n 1\n 5\n 2\n \n\nThe lexicographical order of the names of the three cities is `kazan` <\n`khabarovsk` < `moscow`. For each of these cities, the restaurants in it are\nintroduced in descending order of score. Thus, the restaurants are introduced\nin the order 3,4,6,1,5,2.\n\n* * *"}, {"input": "10\n yakutsk 10\n yakutsk 20\n yakutsk 30\n yakutsk 40\n yakutsk 50\n yakutsk 60\n yakutsk 70\n yakutsk 80\n yakutsk 90\n yakutsk 100", "output": "10\n 9\n 8\n 7\n 6\n 5\n 4\n 3\n 2\n 1"}] |
Print N lines. The i-th line (1 ≤ i ≤ N) should contain the identification
number of the restaurant that is introduced i-th in the book.
* * * | s424463476 | Runtime Error | p03030 | Input is given from Standard Input in the following format:
N
S_1 P_1
:
S_N P_N | args = []
while True:
line = input("put your line")
if line:
line_as_list = line.split(" ")
args.append(line_as_list)
else:
break
order = []
for i in args:
current = 0
for p in args:
if i[0] < p[0]:
current += 1
elif i[0] > p[0]:
current -= 1
elif i[0] == p[0]:
if i[1] < p[1]:
current -= 1
elif i[1] == p[1]:
current += 1
order.append(current)
print(order)
| Statement
You have decided to write a book introducing good restaurants. There are N
restaurants that you want to introduce: Restaurant 1, Restaurant 2, ...,
Restaurant N. Restaurant i is in city S_i, and your assessment score of that
restaurant on a 100-point scale is P_i. No two restaurants have the same
score.
You want to introduce the restaurants in the following order:
* The restaurants are arranged in lexicographical order of the names of their cities.
* If there are multiple restaurants in the same city, they are arranged in descending order of score.
Print the identification numbers of the restaurants in the order they are
introduced in the book. | [{"input": "6\n khabarovsk 20\n moscow 10\n kazan 50\n kazan 35\n moscow 60\n khabarovsk 40", "output": "3\n 4\n 6\n 1\n 5\n 2\n \n\nThe lexicographical order of the names of the three cities is `kazan` <\n`khabarovsk` < `moscow`. For each of these cities, the restaurants in it are\nintroduced in descending order of score. Thus, the restaurants are introduced\nin the order 3,4,6,1,5,2.\n\n* * *"}, {"input": "10\n yakutsk 10\n yakutsk 20\n yakutsk 30\n yakutsk 40\n yakutsk 50\n yakutsk 60\n yakutsk 70\n yakutsk 80\n yakutsk 90\n yakutsk 100", "output": "10\n 9\n 8\n 7\n 6\n 5\n 4\n 3\n 2\n 1"}] |
Print N lines. The i-th line (1 ≤ i ≤ N) should contain the identification
number of the restaurant that is introduced i-th in the book.
* * * | s458052484 | Accepted | p03030 | Input is given from Standard Input in the following format:
N
S_1 P_1
:
S_N P_N | n, *l = open(0).read().split()
print(*sorted(range(1, int(n) + 1), key=lambda i: (l[~-i * 2], -int(l[~-i * 2 + 1]))))
| Statement
You have decided to write a book introducing good restaurants. There are N
restaurants that you want to introduce: Restaurant 1, Restaurant 2, ...,
Restaurant N. Restaurant i is in city S_i, and your assessment score of that
restaurant on a 100-point scale is P_i. No two restaurants have the same
score.
You want to introduce the restaurants in the following order:
* The restaurants are arranged in lexicographical order of the names of their cities.
* If there are multiple restaurants in the same city, they are arranged in descending order of score.
Print the identification numbers of the restaurants in the order they are
introduced in the book. | [{"input": "6\n khabarovsk 20\n moscow 10\n kazan 50\n kazan 35\n moscow 60\n khabarovsk 40", "output": "3\n 4\n 6\n 1\n 5\n 2\n \n\nThe lexicographical order of the names of the three cities is `kazan` <\n`khabarovsk` < `moscow`. For each of these cities, the restaurants in it are\nintroduced in descending order of score. Thus, the restaurants are introduced\nin the order 3,4,6,1,5,2.\n\n* * *"}, {"input": "10\n yakutsk 10\n yakutsk 20\n yakutsk 30\n yakutsk 40\n yakutsk 50\n yakutsk 60\n yakutsk 70\n yakutsk 80\n yakutsk 90\n yakutsk 100", "output": "10\n 9\n 8\n 7\n 6\n 5\n 4\n 3\n 2\n 1"}] |
Print N lines. The i-th line (1 ≤ i ≤ N) should contain the identification
number of the restaurant that is introduced i-th in the book.
* * * | s215819384 | Runtime Error | p03030 | Input is given from Standard Input in the following format:
N
S_1 P_1
:
S_N P_N |
if __name__ == "__main__":
count = input()
work = {}
i = 1;
for line in input():
(city, score) = line.split(' ')
if city not in work:
work[city] = []
work[city].append((int(score),i))
i += 1
for city in sorted(work.keys()):
tuple = work[city]
for restaurant in sorted(tuple, reverse=True):
print(restaurant[1]) | Statement
You have decided to write a book introducing good restaurants. There are N
restaurants that you want to introduce: Restaurant 1, Restaurant 2, ...,
Restaurant N. Restaurant i is in city S_i, and your assessment score of that
restaurant on a 100-point scale is P_i. No two restaurants have the same
score.
You want to introduce the restaurants in the following order:
* The restaurants are arranged in lexicographical order of the names of their cities.
* If there are multiple restaurants in the same city, they are arranged in descending order of score.
Print the identification numbers of the restaurants in the order they are
introduced in the book. | [{"input": "6\n khabarovsk 20\n moscow 10\n kazan 50\n kazan 35\n moscow 60\n khabarovsk 40", "output": "3\n 4\n 6\n 1\n 5\n 2\n \n\nThe lexicographical order of the names of the three cities is `kazan` <\n`khabarovsk` < `moscow`. For each of these cities, the restaurants in it are\nintroduced in descending order of score. Thus, the restaurants are introduced\nin the order 3,4,6,1,5,2.\n\n* * *"}, {"input": "10\n yakutsk 10\n yakutsk 20\n yakutsk 30\n yakutsk 40\n yakutsk 50\n yakutsk 60\n yakutsk 70\n yakutsk 80\n yakutsk 90\n yakutsk 100", "output": "10\n 9\n 8\n 7\n 6\n 5\n 4\n 3\n 2\n 1"}] |
Print N lines. The i-th line (1 ≤ i ≤ N) should contain the identification
number of the restaurant that is introduced i-th in the book.
* * * | s045731393 | Runtime Error | p03030 | Input is given from Standard Input in the following format:
N
S_1 P_1
:
S_N P_N | n=int(input())
data=[]
city=[]
sp=[]
for i in range(n):
data.append(input().rstrip().split(""))
data[i][1]=int(data[i][1])
city.append(data[i][0])
city=sorted(city)
n=0
to=0
while n-1==n:
whlie city[n]==city[to]:
sp.append(data[to][1])
to+=1
sp=sorted(sp)
for i in range(len(sp)):
m=0
while sp[i] != data[m]:
m+=1
print(m+1)
n=to
| Statement
You have decided to write a book introducing good restaurants. There are N
restaurants that you want to introduce: Restaurant 1, Restaurant 2, ...,
Restaurant N. Restaurant i is in city S_i, and your assessment score of that
restaurant on a 100-point scale is P_i. No two restaurants have the same
score.
You want to introduce the restaurants in the following order:
* The restaurants are arranged in lexicographical order of the names of their cities.
* If there are multiple restaurants in the same city, they are arranged in descending order of score.
Print the identification numbers of the restaurants in the order they are
introduced in the book. | [{"input": "6\n khabarovsk 20\n moscow 10\n kazan 50\n kazan 35\n moscow 60\n khabarovsk 40", "output": "3\n 4\n 6\n 1\n 5\n 2\n \n\nThe lexicographical order of the names of the three cities is `kazan` <\n`khabarovsk` < `moscow`. For each of these cities, the restaurants in it are\nintroduced in descending order of score. Thus, the restaurants are introduced\nin the order 3,4,6,1,5,2.\n\n* * *"}, {"input": "10\n yakutsk 10\n yakutsk 20\n yakutsk 30\n yakutsk 40\n yakutsk 50\n yakutsk 60\n yakutsk 70\n yakutsk 80\n yakutsk 90\n yakutsk 100", "output": "10\n 9\n 8\n 7\n 6\n 5\n 4\n 3\n 2\n 1"}] |
Print N lines. The i-th line (1 ≤ i ≤ N) should contain the identification
number of the restaurant that is introduced i-th in the book.
* * * | s230789118 | Runtime Error | p03030 | Input is given from Standard Input in the following format:
N
S_1 P_1
:
S_N P_N | n=int(input())
S=[]
P=[]
for i in range(n):
s,p=input().split()
q=int(p)
S.append(s)
P.append(q)
T=sorted(list(set(S)))
A=[]
for j in range(len(T)):
U=[]
for k in range(n):
if T[j]==S[k]:
U.append(P[k])
sorted(U,reverse=True)
A.append(U)
def flatten(nested_list):
return[e for inner_list in nested_list for e inner_list]
B=flatten(A)
for l in range(n):
print(P.index(B[l]))
| Statement
You have decided to write a book introducing good restaurants. There are N
restaurants that you want to introduce: Restaurant 1, Restaurant 2, ...,
Restaurant N. Restaurant i is in city S_i, and your assessment score of that
restaurant on a 100-point scale is P_i. No two restaurants have the same
score.
You want to introduce the restaurants in the following order:
* The restaurants are arranged in lexicographical order of the names of their cities.
* If there are multiple restaurants in the same city, they are arranged in descending order of score.
Print the identification numbers of the restaurants in the order they are
introduced in the book. | [{"input": "6\n khabarovsk 20\n moscow 10\n kazan 50\n kazan 35\n moscow 60\n khabarovsk 40", "output": "3\n 4\n 6\n 1\n 5\n 2\n \n\nThe lexicographical order of the names of the three cities is `kazan` <\n`khabarovsk` < `moscow`. For each of these cities, the restaurants in it are\nintroduced in descending order of score. Thus, the restaurants are introduced\nin the order 3,4,6,1,5,2.\n\n* * *"}, {"input": "10\n yakutsk 10\n yakutsk 20\n yakutsk 30\n yakutsk 40\n yakutsk 50\n yakutsk 60\n yakutsk 70\n yakutsk 80\n yakutsk 90\n yakutsk 100", "output": "10\n 9\n 8\n 7\n 6\n 5\n 4\n 3\n 2\n 1"}] |
Print N lines. The i-th line (1 ≤ i ≤ N) should contain the identification
number of the restaurant that is introduced i-th in the book.
* * * | s761965267 | Wrong Answer | p03030 | Input is given from Standard Input in the following format:
N
S_1 P_1
:
S_N P_N | lst = [input().split() + [str(i + 1)] for i in range(int(input()))]
print("\n".join([i[2] for i in sorted(lst, key=lambda x: (-1 * int(x[1]), x[0]))]))
| Statement
You have decided to write a book introducing good restaurants. There are N
restaurants that you want to introduce: Restaurant 1, Restaurant 2, ...,
Restaurant N. Restaurant i is in city S_i, and your assessment score of that
restaurant on a 100-point scale is P_i. No two restaurants have the same
score.
You want to introduce the restaurants in the following order:
* The restaurants are arranged in lexicographical order of the names of their cities.
* If there are multiple restaurants in the same city, they are arranged in descending order of score.
Print the identification numbers of the restaurants in the order they are
introduced in the book. | [{"input": "6\n khabarovsk 20\n moscow 10\n kazan 50\n kazan 35\n moscow 60\n khabarovsk 40", "output": "3\n 4\n 6\n 1\n 5\n 2\n \n\nThe lexicographical order of the names of the three cities is `kazan` <\n`khabarovsk` < `moscow`. For each of these cities, the restaurants in it are\nintroduced in descending order of score. Thus, the restaurants are introduced\nin the order 3,4,6,1,5,2.\n\n* * *"}, {"input": "10\n yakutsk 10\n yakutsk 20\n yakutsk 30\n yakutsk 40\n yakutsk 50\n yakutsk 60\n yakutsk 70\n yakutsk 80\n yakutsk 90\n yakutsk 100", "output": "10\n 9\n 8\n 7\n 6\n 5\n 4\n 3\n 2\n 1"}] |
Print N lines. The i-th line (1 ≤ i ≤ N) should contain the identification
number of the restaurant that is introduced i-th in the book.
* * * | s822088530 | Runtime Error | p03030 | Input is given from Standard Input in the following format:
N
S_1 P_1
:
S_N P_N | n = int(input())
r = []
for i in range(1, n + 1):
hoge = list(map(int, input().split()))
hoge.append(i)
r.append(hoge)
tmp = sorted(r, key=lambda x: x[1], reverse=True)
res = sorted(tmp, key=lambda x: x[0])
for arr in res:
print(arr[2])
| Statement
You have decided to write a book introducing good restaurants. There are N
restaurants that you want to introduce: Restaurant 1, Restaurant 2, ...,
Restaurant N. Restaurant i is in city S_i, and your assessment score of that
restaurant on a 100-point scale is P_i. No two restaurants have the same
score.
You want to introduce the restaurants in the following order:
* The restaurants are arranged in lexicographical order of the names of their cities.
* If there are multiple restaurants in the same city, they are arranged in descending order of score.
Print the identification numbers of the restaurants in the order they are
introduced in the book. | [{"input": "6\n khabarovsk 20\n moscow 10\n kazan 50\n kazan 35\n moscow 60\n khabarovsk 40", "output": "3\n 4\n 6\n 1\n 5\n 2\n \n\nThe lexicographical order of the names of the three cities is `kazan` <\n`khabarovsk` < `moscow`. For each of these cities, the restaurants in it are\nintroduced in descending order of score. Thus, the restaurants are introduced\nin the order 3,4,6,1,5,2.\n\n* * *"}, {"input": "10\n yakutsk 10\n yakutsk 20\n yakutsk 30\n yakutsk 40\n yakutsk 50\n yakutsk 60\n yakutsk 70\n yakutsk 80\n yakutsk 90\n yakutsk 100", "output": "10\n 9\n 8\n 7\n 6\n 5\n 4\n 3\n 2\n 1"}] |
Print N lines. The i-th line (1 ≤ i ≤ N) should contain the identification
number of the restaurant that is introduced i-th in the book.
* * * | s253097458 | Runtime Error | p03030 | Input is given from Standard Input in the following format:
N
S_1 P_1
:
S_N P_N | N = int(input())
q=[input().split()+[i]for i in range(N)]
for i in range(N):
q[i][1]=int(q[i][1])
q.append((c,int(p)*-1,i+1))
a = sorted(q)
for s,t,r in q:
print(r+1) | Statement
You have decided to write a book introducing good restaurants. There are N
restaurants that you want to introduce: Restaurant 1, Restaurant 2, ...,
Restaurant N. Restaurant i is in city S_i, and your assessment score of that
restaurant on a 100-point scale is P_i. No two restaurants have the same
score.
You want to introduce the restaurants in the following order:
* The restaurants are arranged in lexicographical order of the names of their cities.
* If there are multiple restaurants in the same city, they are arranged in descending order of score.
Print the identification numbers of the restaurants in the order they are
introduced in the book. | [{"input": "6\n khabarovsk 20\n moscow 10\n kazan 50\n kazan 35\n moscow 60\n khabarovsk 40", "output": "3\n 4\n 6\n 1\n 5\n 2\n \n\nThe lexicographical order of the names of the three cities is `kazan` <\n`khabarovsk` < `moscow`. For each of these cities, the restaurants in it are\nintroduced in descending order of score. Thus, the restaurants are introduced\nin the order 3,4,6,1,5,2.\n\n* * *"}, {"input": "10\n yakutsk 10\n yakutsk 20\n yakutsk 30\n yakutsk 40\n yakutsk 50\n yakutsk 60\n yakutsk 70\n yakutsk 80\n yakutsk 90\n yakutsk 100", "output": "10\n 9\n 8\n 7\n 6\n 5\n 4\n 3\n 2\n 1"}] |
Print N lines. The i-th line (1 ≤ i ≤ N) should contain the identification
number of the restaurant that is introduced i-th in the book.
* * * | s332639819 | Wrong Answer | p03030 | Input is given from Standard Input in the following format:
N
S_1 P_1
:
S_N P_N | N = int(input())
all_point_list = [input().split() for _ in range(N)]
for each_list in all_point_list:
each_list[1] = int(each_list[1])
sorted_all_list = sorted(all_point_list)
for sorted_point in sorted_all_list:
print(all_point_list.index(sorted_point) + 1)
| Statement
You have decided to write a book introducing good restaurants. There are N
restaurants that you want to introduce: Restaurant 1, Restaurant 2, ...,
Restaurant N. Restaurant i is in city S_i, and your assessment score of that
restaurant on a 100-point scale is P_i. No two restaurants have the same
score.
You want to introduce the restaurants in the following order:
* The restaurants are arranged in lexicographical order of the names of their cities.
* If there are multiple restaurants in the same city, they are arranged in descending order of score.
Print the identification numbers of the restaurants in the order they are
introduced in the book. | [{"input": "6\n khabarovsk 20\n moscow 10\n kazan 50\n kazan 35\n moscow 60\n khabarovsk 40", "output": "3\n 4\n 6\n 1\n 5\n 2\n \n\nThe lexicographical order of the names of the three cities is `kazan` <\n`khabarovsk` < `moscow`. For each of these cities, the restaurants in it are\nintroduced in descending order of score. Thus, the restaurants are introduced\nin the order 3,4,6,1,5,2.\n\n* * *"}, {"input": "10\n yakutsk 10\n yakutsk 20\n yakutsk 30\n yakutsk 40\n yakutsk 50\n yakutsk 60\n yakutsk 70\n yakutsk 80\n yakutsk 90\n yakutsk 100", "output": "10\n 9\n 8\n 7\n 6\n 5\n 4\n 3\n 2\n 1"}] |
Print N lines. The i-th line (1 ≤ i ≤ N) should contain the identification
number of the restaurant that is introduced i-th in the book.
* * * | s145390112 | Runtime Error | p03030 | Input is given from Standard Input in the following format:
N
S_1 P_1
:
S_N P_N | N = int(input())
names = set()
citydict = dict()
for i in range(N):
S, P = input().split()
names.append(S)
if S[i] in citydict:
citydict[S].append((int(P),i))
else:
citydict[S] = [(int(P),i)]
for name in sorted(names):
for point in sorted(citydict[name],reverse = True)
print(point[1] + 1) | Statement
You have decided to write a book introducing good restaurants. There are N
restaurants that you want to introduce: Restaurant 1, Restaurant 2, ...,
Restaurant N. Restaurant i is in city S_i, and your assessment score of that
restaurant on a 100-point scale is P_i. No two restaurants have the same
score.
You want to introduce the restaurants in the following order:
* The restaurants are arranged in lexicographical order of the names of their cities.
* If there are multiple restaurants in the same city, they are arranged in descending order of score.
Print the identification numbers of the restaurants in the order they are
introduced in the book. | [{"input": "6\n khabarovsk 20\n moscow 10\n kazan 50\n kazan 35\n moscow 60\n khabarovsk 40", "output": "3\n 4\n 6\n 1\n 5\n 2\n \n\nThe lexicographical order of the names of the three cities is `kazan` <\n`khabarovsk` < `moscow`. For each of these cities, the restaurants in it are\nintroduced in descending order of score. Thus, the restaurants are introduced\nin the order 3,4,6,1,5,2.\n\n* * *"}, {"input": "10\n yakutsk 10\n yakutsk 20\n yakutsk 30\n yakutsk 40\n yakutsk 50\n yakutsk 60\n yakutsk 70\n yakutsk 80\n yakutsk 90\n yakutsk 100", "output": "10\n 9\n 8\n 7\n 6\n 5\n 4\n 3\n 2\n 1"}] |
Print the maximum possible value of s.
* * * | s510118443 | Accepted | p03525 | Input is given from Standard Input in the following format:
N
D_1 D_2 ... D_N | from collections import Counter
N = int(input())
D = [int(i) for i in input().split()]
def solve():
cnt = Counter(D)
one = []
L1 = []
for k, v in cnt.items():
if v >= 3:
return 0
if v == 2:
L1.append(k)
L1.append(24 - k)
if v == 1:
one.append(k)
ret = 0
for i in range(1 << len(one)):
L2 = L1[::]
for j in range(len(one)):
if i & 1:
L2.append(one[j])
else:
L2.append(24 - one[j])
i >>= 1
L2.append(0)
L2.append(24)
L2.sort()
tmp = float("inf")
for i in range(1, len(L2)):
tmp = min(tmp, L2[i] - L2[i - 1])
if tmp != float("inf"):
ret = max(ret, tmp)
return ret
print(solve())
| Statement
In CODE FESTIVAL XXXX, there are N+1 participants from all over the world,
including Takahashi.
Takahashi checked and found that the _time gap_ (defined below) between the
local times in his city and the i-th person's city was D_i hours. The time gap
between two cities is defined as follows. For two cities A and B, if the local
time in city B is d o'clock at the moment when the local time in city A is 0
o'clock, then the time gap between these two cities is defined to be
min(d,24-d) hours. Here, we are using 24-hour notation. That is, the local
time in the i-th person's city is either d o'clock or 24-d o'clock at the
moment when the local time in Takahashi's city is 0 o'clock, for example.
Then, for each pair of two people chosen from the N+1 people, he wrote out the
time gap between their cities. Let the smallest time gap among them be s
hours.
Find the maximum possible value of s. | [{"input": "3\n 7 12 8", "output": "4\n \n\nFor example, consider the situation where it is 7, 12 and 16 o'clock in each\nperson's city at the moment when it is 0 o'clock in Takahashi's city. In this\ncase, the time gap between the second and third persons' cities is 4 hours.\n\n* * *"}, {"input": "2\n 11 11", "output": "2\n \n\n* * *"}, {"input": "1\n 0", "output": "0\n \n\nNote that Takahashi himself is also a participant."}] |
Print the maximum possible value of s.
* * * | s329782303 | Wrong Answer | p03525 | Input is given from Standard Input in the following format:
N
D_1 D_2 ... D_N | print("NO")
| Statement
In CODE FESTIVAL XXXX, there are N+1 participants from all over the world,
including Takahashi.
Takahashi checked and found that the _time gap_ (defined below) between the
local times in his city and the i-th person's city was D_i hours. The time gap
between two cities is defined as follows. For two cities A and B, if the local
time in city B is d o'clock at the moment when the local time in city A is 0
o'clock, then the time gap between these two cities is defined to be
min(d,24-d) hours. Here, we are using 24-hour notation. That is, the local
time in the i-th person's city is either d o'clock or 24-d o'clock at the
moment when the local time in Takahashi's city is 0 o'clock, for example.
Then, for each pair of two people chosen from the N+1 people, he wrote out the
time gap between their cities. Let the smallest time gap among them be s
hours.
Find the maximum possible value of s. | [{"input": "3\n 7 12 8", "output": "4\n \n\nFor example, consider the situation where it is 7, 12 and 16 o'clock in each\nperson's city at the moment when it is 0 o'clock in Takahashi's city. In this\ncase, the time gap between the second and third persons' cities is 4 hours.\n\n* * *"}, {"input": "2\n 11 11", "output": "2\n \n\n* * *"}, {"input": "1\n 0", "output": "0\n \n\nNote that Takahashi himself is also a participant."}] |
Print the maximum possible value of s.
* * * | s594074067 | Runtime Error | p03525 | Input is given from Standard Input in the following format:
N
D_1 D_2 ... D_N | from itertools import product
import random
def solve(n,dl):
# n = int(input())
# dl = list(map(int, input().split()))
if 0 in dl:
return 0
doubles = []
dl1 = []
dl2 = []
for i in range(1,13):
i_cnt = dl.count(i)
if i_cnt > 2:
return 0
elif i_cnt == 2:
dl2.append(24-i)
dl2.append(i)
elif i_cnt == 1:
dl1.append(i)
ans = 0
ite = list(product(range(2),repeat=len(dl1)))
for pattern in ite:
dl24 = [0,24]
for i, v in enumerate(pattern):
if v == 1:
dl24.append(24-dl1[i])
else:
dl24.append(dl1[i])
dl24 = dl24 + dl2
dl24.sort()
diff_min = 24
# print(dl24)
if len(dl24) == 1:
ans = max(ans, min(dl24[0], 24-dl24[0]))
else:
for a,b in zip(dl24[:-1],dl24[1:]):
diff = b-a
if diff != 24
diff_min = min(diff_min,diff)
ans = max(diff_min,ans)
return ans
def solve2(n,dl):
ite = list(product(range(2),repeat=len(dl)))
ans = 0
for pattern in ite:
dl_new = [0]
for i, v in enumerate(pattern):
if v == 1:
dl_new.append(24-dl[i])
else:
dl_new.append(dl[i])
dl_new.sort()
diff_min = 24
for a,b in zip(dl_new[:-1], dl_new[1:]):
diff = b-a
diff_min = min(diff_min, diff)
ans = max(ans,diff_min)
return ans
if __name__ == "__main__":
n = int(input())
dl = list(map(int, input().split()))
ans = solve(n,dl)
print(ans)
# for _ in range(10):
# n = random.randint(1,10)
# dl = [random.randint(1,12) for _ in range(n)]
# ans1 = solve(n, dl[:])
# ans2 = solve2(n,dl[:])
# if ans1 != ans2:
# print(n)
# print(dl)
# print(ans1)
# print(ans2)
# print('----') | Statement
In CODE FESTIVAL XXXX, there are N+1 participants from all over the world,
including Takahashi.
Takahashi checked and found that the _time gap_ (defined below) between the
local times in his city and the i-th person's city was D_i hours. The time gap
between two cities is defined as follows. For two cities A and B, if the local
time in city B is d o'clock at the moment when the local time in city A is 0
o'clock, then the time gap between these two cities is defined to be
min(d,24-d) hours. Here, we are using 24-hour notation. That is, the local
time in the i-th person's city is either d o'clock or 24-d o'clock at the
moment when the local time in Takahashi's city is 0 o'clock, for example.
Then, for each pair of two people chosen from the N+1 people, he wrote out the
time gap between their cities. Let the smallest time gap among them be s
hours.
Find the maximum possible value of s. | [{"input": "3\n 7 12 8", "output": "4\n \n\nFor example, consider the situation where it is 7, 12 and 16 o'clock in each\nperson's city at the moment when it is 0 o'clock in Takahashi's city. In this\ncase, the time gap between the second and third persons' cities is 4 hours.\n\n* * *"}, {"input": "2\n 11 11", "output": "2\n \n\n* * *"}, {"input": "1\n 0", "output": "0\n \n\nNote that Takahashi himself is also a participant."}] |
Print the maximum possible value of s.
* * * | s051535636 | Accepted | p03525 | Input is given from Standard Input in the following format:
N
D_1 D_2 ... D_N | import sys, collections as cl, bisect as bs
sys.setrecursionlimit(100000)
input = sys.stdin.readline
mod = 10**9 + 7
Max = sys.maxsize
def l(): # intのlist
return list(map(int, input().split()))
def m(): # 複数文字
return map(int, input().split())
def onem(): # Nとかの取得
return int(input())
def s(x): # 圧縮
a = []
aa = x[0]
su = 1
for i in range(len(x) - 1):
if aa != x[i + 1]:
a.append([aa, su])
aa = x[i + 1]
su = 1
else:
su += 1
a.append([aa, su])
return a
def jo(x): # listをスペースごとに分ける
return " ".join(map(str, x))
def max2(x): # 他のときもどうように作成可能
return max(map(max, x))
def In(x, a): # aがリスト(sorted)
k = bs.bisect_left(a, x)
if k != len(a) and a[k] == x:
return True
else:
return False
"""
def nibu(x,n,r):
ll = 0
rr = r
while True:
mid = (ll+rr)//2
if rr == mid:
return ll
if (ここに評価入れる):
rr = mid
else:
ll = mid+1
"""
n = onem()
d = l()
d.sort()
a = [0 for i in range(24)]
a[0] += 1
for i in range(n):
if i % 2 == 0:
a[d[i]] += 1
else:
if d[i]:
a[24 - d[i]] += 1
else:
a[0] += 1
co = 12
for i in range(24):
if a[i] >= 2:
co = 0
break
for j in range(i + 1, 24):
if a[i] >= 1 and a[j] >= 1:
co = min(co, min(24 - (j - i), j - i))
print(co)
| Statement
In CODE FESTIVAL XXXX, there are N+1 participants from all over the world,
including Takahashi.
Takahashi checked and found that the _time gap_ (defined below) between the
local times in his city and the i-th person's city was D_i hours. The time gap
between two cities is defined as follows. For two cities A and B, if the local
time in city B is d o'clock at the moment when the local time in city A is 0
o'clock, then the time gap between these two cities is defined to be
min(d,24-d) hours. Here, we are using 24-hour notation. That is, the local
time in the i-th person's city is either d o'clock or 24-d o'clock at the
moment when the local time in Takahashi's city is 0 o'clock, for example.
Then, for each pair of two people chosen from the N+1 people, he wrote out the
time gap between their cities. Let the smallest time gap among them be s
hours.
Find the maximum possible value of s. | [{"input": "3\n 7 12 8", "output": "4\n \n\nFor example, consider the situation where it is 7, 12 and 16 o'clock in each\nperson's city at the moment when it is 0 o'clock in Takahashi's city. In this\ncase, the time gap between the second and third persons' cities is 4 hours.\n\n* * *"}, {"input": "2\n 11 11", "output": "2\n \n\n* * *"}, {"input": "1\n 0", "output": "0\n \n\nNote that Takahashi himself is also a participant."}] |
Print the maximum possible value of s.
* * * | s242670518 | Runtime Error | p03525 | Input is given from Standard Input in the following format:
N
D_1 D_2 ... D_N | #n>=25なら鳩ノ巣で0
#2人以上居るdは一意
#あとはしらみつぶし
n = int(input())
if n>=25:
print(0)
exit()
d = list(map(int, input().split( )))
if 0 in d:##
print(0)
exit()
d.append(0)
dic = {}
for di in d:
if di in dic:
dic[di] += 1
else:
dic[di]= 1
solo = []
times = []
for di in dic:
if dic[di]==1:#di=0はここに入る
solo.append(di)
elif dic[di]==2:
times.append(di)
if di!=12:
times.append(24-di)
else:
print(0):
exit()
else:
print(0)
exit()
ans = 0
m = len(solo)
bit = 1<<m
for i in range(bit):
times2 = []
for t in times:
times2.append(t)
for j in range(m):
if i>>j&1:
times2.append(solo[j])
elif solo[j]:
times2.append(24-solo[j])
times2.sort()
dif = 24
if len(times2)==1:###
print(0)
exit()
#print(times2)
for k in range(len(times2)-1):
dif = min(dif,times2[k+1]-times2[k])
dif = min(dif,times2[0] + 24 - times2[-1])
ans = max(ans,dif)
print(ans)
| Statement
In CODE FESTIVAL XXXX, there are N+1 participants from all over the world,
including Takahashi.
Takahashi checked and found that the _time gap_ (defined below) between the
local times in his city and the i-th person's city was D_i hours. The time gap
between two cities is defined as follows. For two cities A and B, if the local
time in city B is d o'clock at the moment when the local time in city A is 0
o'clock, then the time gap between these two cities is defined to be
min(d,24-d) hours. Here, we are using 24-hour notation. That is, the local
time in the i-th person's city is either d o'clock or 24-d o'clock at the
moment when the local time in Takahashi's city is 0 o'clock, for example.
Then, for each pair of two people chosen from the N+1 people, he wrote out the
time gap between their cities. Let the smallest time gap among them be s
hours.
Find the maximum possible value of s. | [{"input": "3\n 7 12 8", "output": "4\n \n\nFor example, consider the situation where it is 7, 12 and 16 o'clock in each\nperson's city at the moment when it is 0 o'clock in Takahashi's city. In this\ncase, the time gap between the second and third persons' cities is 4 hours.\n\n* * *"}, {"input": "2\n 11 11", "output": "2\n \n\n* * *"}, {"input": "1\n 0", "output": "0\n \n\nNote that Takahashi himself is also a participant."}] |
Print the maximum possible value of s.
* * * | s761022283 | Wrong Answer | p03525 | Input is given from Standard Input in the following format:
N
D_1 D_2 ... D_N | import math
# import sys
# input = sys.stdin.readline
def make_divisors(n):
divisors = []
for i in range(1, int(n**0.5) + 1):
if n % i == 0:
divisors.append(i)
if i != n // i:
divisors.append(n // i)
# divisors.sort()
return divisors
def ValueToBits(x, digit):
res = [0 for i in range(digit)]
now = x
for i in range(digit):
res[i] = now % 2
now = now >> 1
return res
def BitsToValue(arr):
n = len(arr)
ans = 0
for i in range(n):
ans += arr[i] * 2**i
return ans
def ZipArray(a):
aa = [[a[i], i] for i in range(n)]
aa.sort(key=lambda x: x[0])
for i in range(n):
aa[i][0] = i + 1
aa.sort(key=lambda x: x[1])
b = [aa[i][0] for i in range(len(a))]
return b
def ValueToArray10(x, digit):
ans = [0 for i in range(digit)]
now = x
for i in range(digit):
ans[digit - i - 1] = now % 10
now = now // 10
return ans
def Zeros(a, b):
if b <= -1:
return [0 for i in range(a)]
else:
return [[0 for i in range(b)] for i in range(a)]
def AddV2(v, w):
return [v[0] + w[0], v[1] + w[1]]
dir4 = [[1, 0], [0, 1], [-1, 0], [0, -1]]
def clamp(x, y, z):
return max(y, min(z, x))
class Bit:
def __init__(self, n):
self.size = n
self.tree = [0] * (n + 1)
def sum(self, i):
s = 0
while i > 0:
s += self.tree[i]
i -= i & -i
return s
def add(self, i, x):
while i <= self.size:
self.tree[i] += x
i += i & -i
#
def Zaatsu(a):
a.sort()
now = a[0][0]
od = 0
for i in range(n):
if now == a[i][0]:
a[i][0] = od
else:
now = a[i][0]
od += 1
a[i][0] = od
a.sort(key=lambda x: x[1])
return a
class UnionFind:
def __init__(self, n):
self.par = [i for i in range(n + 1)]
self.rank = [0] * (n + 1)
# 検索
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 union(self, x, y):
x = self.find(x)
y = self.find(y)
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 same_check(self, x, y):
return self.find(x) == self.find(y)
"""
def cmb(n, r, p):
if (r < 0) or (n < r):
return 0
r = min(r, n - r)
return fact[n] * factinv[r] * factinv[n-r] % p
p = 2
N = 10 ** 6 + 2
fact = [1, 1] # fact[n] = (n! mod p)
factinv = [1, 1] # factinv[n] = ((n!)^(-1) mod p)
inv = [0, 1] # factinv 計算用
for i in range(2, N + 1):
fact.append((fact[-1] * i) % p)
inv.append((-inv[p % i] * (p // i)) % p)
factinv.append((factinv[-1] * inv[-1]) % p)
"""
def rl(x):
return range(len(x))
# a = list(map(int, input().split()))
#################################################
#################################################
#################################################
#################################################
# 11-
n = int(input())
aa = list(map(int, input().split()))
t = [0 for i in range(13)]
a = []
for i in aa:
if t[i] <= 1:
t[i] += 1
a.append(i)
if t[i] == 2 or i == 0:
print(0)
exit()
# print(a)
n = len(a)
b = [0 for i in range(25)]
ans = 0
count = 0
for i in range(2 ** (n - 1)):
count += 1
for j in range(25):
b[j] = 0
b[0] = 1
b[24] = 1
for j in range(n):
if (i >> j) & 1:
b[24 - a[j]] += 1
else:
b[a[j]] += 1
minim = 24
prev = -24
for j in range(0, 25):
if b[j] == 1:
minim = min(minim, j - prev)
prev = j
elif b[j] >= 2:
minim = 0
break
ans = max(ans, minim)
# print(b)
print(ans)
# print(count)
| Statement
In CODE FESTIVAL XXXX, there are N+1 participants from all over the world,
including Takahashi.
Takahashi checked and found that the _time gap_ (defined below) between the
local times in his city and the i-th person's city was D_i hours. The time gap
between two cities is defined as follows. For two cities A and B, if the local
time in city B is d o'clock at the moment when the local time in city A is 0
o'clock, then the time gap between these two cities is defined to be
min(d,24-d) hours. Here, we are using 24-hour notation. That is, the local
time in the i-th person's city is either d o'clock or 24-d o'clock at the
moment when the local time in Takahashi's city is 0 o'clock, for example.
Then, for each pair of two people chosen from the N+1 people, he wrote out the
time gap between their cities. Let the smallest time gap among them be s
hours.
Find the maximum possible value of s. | [{"input": "3\n 7 12 8", "output": "4\n \n\nFor example, consider the situation where it is 7, 12 and 16 o'clock in each\nperson's city at the moment when it is 0 o'clock in Takahashi's city. In this\ncase, the time gap between the second and third persons' cities is 4 hours.\n\n* * *"}, {"input": "2\n 11 11", "output": "2\n \n\n* * *"}, {"input": "1\n 0", "output": "0\n \n\nNote that Takahashi himself is also a participant."}] |
Print the maximum possible value of s.
* * * | s984343457 | Accepted | p03525 | Input is given from Standard Input in the following format:
N
D_1 D_2 ... D_N | from itertools import product
from collections import Counter
def main():
N, *D = map(int, open(0).read().split())
C = Counter(D)
ans = min(D)
for i in range(1, 12):
if i in C and C[i] >= 3:
ans = 0
if 12 in C and C[12] >= 2:
ans = 0
if ans:
X1 = [k for k, v in C.items() if v == 1]
X2 = [k for k, v in C.items() if v == 2]
Y = [False] * 24
for x in X2:
Y[x] = Y[-x] = True
res = 0
for p in product((True, False), repeat=len(X1)):
Z = Y.copy()
for t, x in zip(p, X1):
if t:
Z[x] = True
else:
Z[-x] = True
res2 = 12
I = [i for i, p in enumerate(Z) if p]
for i in I:
for j in I:
if i == j:
continue
res2 = min(res2, abs(i - j))
res = max(res, res2)
ans = min(ans, res)
print(ans)
if __name__ == "__main__":
main()
| Statement
In CODE FESTIVAL XXXX, there are N+1 participants from all over the world,
including Takahashi.
Takahashi checked and found that the _time gap_ (defined below) between the
local times in his city and the i-th person's city was D_i hours. The time gap
between two cities is defined as follows. For two cities A and B, if the local
time in city B is d o'clock at the moment when the local time in city A is 0
o'clock, then the time gap between these two cities is defined to be
min(d,24-d) hours. Here, we are using 24-hour notation. That is, the local
time in the i-th person's city is either d o'clock or 24-d o'clock at the
moment when the local time in Takahashi's city is 0 o'clock, for example.
Then, for each pair of two people chosen from the N+1 people, he wrote out the
time gap between their cities. Let the smallest time gap among them be s
hours.
Find the maximum possible value of s. | [{"input": "3\n 7 12 8", "output": "4\n \n\nFor example, consider the situation where it is 7, 12 and 16 o'clock in each\nperson's city at the moment when it is 0 o'clock in Takahashi's city. In this\ncase, the time gap between the second and third persons' cities is 4 hours.\n\n* * *"}, {"input": "2\n 11 11", "output": "2\n \n\n* * *"}, {"input": "1\n 0", "output": "0\n \n\nNote that Takahashi himself is also a participant."}] |
Print the maximum possible value of s.
* * * | s693437090 | Accepted | p03525 | Input is given from Standard Input in the following format:
N
D_1 D_2 ... D_N | import copy
def minTG(TG):
indexes1 = [i for i, x in enumerate(TG) if x == 1]
indexes2 = [i for i, x in enumerate(TG) if x == 2]
TG24 = [1] + [0] * 23
if 12 in indexes1:
indexes1.pop(-1)
TG24[12] = 1
for i in indexes1 + indexes2:
TG24[i], TG24[24 - i] = 1, 1
ans = 0
for i in range(2 ** len(indexes1)):
TG24c = copy.copy(TG24)
bit = i
for j in range(len(indexes1)):
if bin(bit >> (j + 1))[-1] == "1":
TG24c[indexes1[j]] = 0
else:
TG24c[24 - indexes1[j]] = 0
temp = minTG_search(TG24c)
if ans < temp:
ans = temp
return ans
def minTG_search(TG24):
s, temp, i = 24, 0, 1
while i < 24:
if TG24[i] == 1:
if i - temp < s:
s = i - temp
temp = i
i += 1
if 24 - temp < s:
s = 24 - temp
return s
N = int(input())
D = sorted(list(map(int, input().split())))
TG = [0] * 13
for i in range(N):
TG[D[i]] += 1
if TG[0] > 0 or max(TG) > 2:
print(0)
else:
print(minTG(TG))
| Statement
In CODE FESTIVAL XXXX, there are N+1 participants from all over the world,
including Takahashi.
Takahashi checked and found that the _time gap_ (defined below) between the
local times in his city and the i-th person's city was D_i hours. The time gap
between two cities is defined as follows. For two cities A and B, if the local
time in city B is d o'clock at the moment when the local time in city A is 0
o'clock, then the time gap between these two cities is defined to be
min(d,24-d) hours. Here, we are using 24-hour notation. That is, the local
time in the i-th person's city is either d o'clock or 24-d o'clock at the
moment when the local time in Takahashi's city is 0 o'clock, for example.
Then, for each pair of two people chosen from the N+1 people, he wrote out the
time gap between their cities. Let the smallest time gap among them be s
hours.
Find the maximum possible value of s. | [{"input": "3\n 7 12 8", "output": "4\n \n\nFor example, consider the situation where it is 7, 12 and 16 o'clock in each\nperson's city at the moment when it is 0 o'clock in Takahashi's city. In this\ncase, the time gap between the second and third persons' cities is 4 hours.\n\n* * *"}, {"input": "2\n 11 11", "output": "2\n \n\n* * *"}, {"input": "1\n 0", "output": "0\n \n\nNote that Takahashi himself is also a participant."}] |
Print the maximum possible value of s.
* * * | s043287476 | Wrong Answer | p03525 | Input is given from Standard Input in the following format:
N
D_1 D_2 ... D_N | N, *D = map(int, open(0).read().split())
D.append(0)
used = [0] * (N + 1)
cnt = N
while True:
ls = []
for i in range(N + 1):
for j in range(N + 1):
if i == j:
continue
a, b = min(D[i], D[j]), max(D[i], D[j])
d = b - a
ls.append((min(d, 24 - d), i, j))
ls.sort(key=lambda x: x[0])
d, a, b = ls[0]
if used[a] == 0 and used[b] == 0:
used[a] = 1
used[b] = 1
da = (24 - D[a]) % 24
ma = 100
for i in range(N + 1):
if i == a:
continue
x = abs(da - D[i])
ma = min(ma, x, 24 - x)
db = (24 - D[b]) % 24
mb = 100
for i in range(N + 1):
if i == b:
continue
x = abs(db - D[i])
mb = min(mb, x, 24 - x)
if ma < mb:
if d >= mb:
print(d)
break
D[b] = db
else:
if d >= ma:
print(d)
break
D[a] = da
elif used[a] == 0:
used[a] = 1
da = (24 - D[a]) % 24
ma = 100
for i in range(N + 1):
if i == a:
continue
x = abs(da - D[i])
ma = min(ma, x, 24 - x)
if d >= ma:
print(d)
break
else:
D[a] = da
elif used[b] == 0:
used[b] = 1
db = (24 - D[b]) % 24
mb = 100
for i in range(N + 1):
if i == b:
continue
x = abs(db - D[i])
mb = min(mb, x, 24 - x)
if d >= mb:
print(d)
break
else:
D[b] = mb
else:
print(d)
break
| Statement
In CODE FESTIVAL XXXX, there are N+1 participants from all over the world,
including Takahashi.
Takahashi checked and found that the _time gap_ (defined below) between the
local times in his city and the i-th person's city was D_i hours. The time gap
between two cities is defined as follows. For two cities A and B, if the local
time in city B is d o'clock at the moment when the local time in city A is 0
o'clock, then the time gap between these two cities is defined to be
min(d,24-d) hours. Here, we are using 24-hour notation. That is, the local
time in the i-th person's city is either d o'clock or 24-d o'clock at the
moment when the local time in Takahashi's city is 0 o'clock, for example.
Then, for each pair of two people chosen from the N+1 people, he wrote out the
time gap between their cities. Let the smallest time gap among them be s
hours.
Find the maximum possible value of s. | [{"input": "3\n 7 12 8", "output": "4\n \n\nFor example, consider the situation where it is 7, 12 and 16 o'clock in each\nperson's city at the moment when it is 0 o'clock in Takahashi's city. In this\ncase, the time gap between the second and third persons' cities is 4 hours.\n\n* * *"}, {"input": "2\n 11 11", "output": "2\n \n\n* * *"}, {"input": "1\n 0", "output": "0\n \n\nNote that Takahashi himself is also a participant."}] |
Print the maximum possible value of s.
* * * | s900149900 | Wrong Answer | p03525 | Input is given from Standard Input in the following format:
N
D_1 D_2 ... D_N | from collections import Counter
N = int(input())
now_time = []
D = list(map(int, input().split()))
c = Counter(D)
candidate = []
for num, amount in c.items():
if num == 0:
print(0)
exit()
if amount > 2:
print(0)
exit()
if amount == 2:
# 確定した時間
now_time.append(num)
now_time.append(24 - num)
if amount == 1:
candidate.append((num, 24 - num)) # 選択の余地がある時間
ans = 0
# 確定した時間に、選択の余地がある組を追加していく
for mask in range(1 << len(candidate)):
list_0_1 = []
time_list = now_time.copy() # 確定している時間
for i in range(len(candidate)):
list_0_1.append(int((mask >> i) & 1))
for i, num in enumerate(list_0_1):
time_list.append(candidate[i][num])
# exit()
tmp = 100
for i in range(len(time_list)):
for j in range(i + 1, len(time_list)):
tmp = min(tmp, abs(time_list[i] - time_list[j]))
ans = max(tmp, ans)
print(ans)
| Statement
In CODE FESTIVAL XXXX, there are N+1 participants from all over the world,
including Takahashi.
Takahashi checked and found that the _time gap_ (defined below) between the
local times in his city and the i-th person's city was D_i hours. The time gap
between two cities is defined as follows. For two cities A and B, if the local
time in city B is d o'clock at the moment when the local time in city A is 0
o'clock, then the time gap between these two cities is defined to be
min(d,24-d) hours. Here, we are using 24-hour notation. That is, the local
time in the i-th person's city is either d o'clock or 24-d o'clock at the
moment when the local time in Takahashi's city is 0 o'clock, for example.
Then, for each pair of two people chosen from the N+1 people, he wrote out the
time gap between their cities. Let the smallest time gap among them be s
hours.
Find the maximum possible value of s. | [{"input": "3\n 7 12 8", "output": "4\n \n\nFor example, consider the situation where it is 7, 12 and 16 o'clock in each\nperson's city at the moment when it is 0 o'clock in Takahashi's city. In this\ncase, the time gap between the second and third persons' cities is 4 hours.\n\n* * *"}, {"input": "2\n 11 11", "output": "2\n \n\n* * *"}, {"input": "1\n 0", "output": "0\n \n\nNote that Takahashi himself is also a participant."}] |
Print the maximum possible value of s.
* * * | s801381125 | Runtime Error | p03525 | Input is given from Standard Input in the following format:
N
D_1 D_2 ... D_N | n = int(input())
ds = list(map(int, input().split()))
from collections import defaultdict
d = defaultdict(int)
d[0] = 1
for d_ in ds:
d[d_] += 1
if d_ == 12 and d[d_] == 2:
print(0)
exit()
elif d_ == 0 and d[d_] == 2:
print(0)
exit()
elif d[d_] == 3:
print(0)
exit()
def calcmin(tmp):
n = len(tmp)
ret = 1 << 50
for i in range(n):
for j in range(i+1,n):
ret = min(ret, abs(tmp[i]-tmp[j]))
return ret
two = []
x = []
for k in d.keys():
if d[k] == 2:
two.append(k)
two.append(24-k)
if d[k] == 1:
x.append(k)
two = list(set(two))
n = len(x)
ans = 0
for i in range(1 << n):
tmp[] = x[:]
for j in range(n):
if i & (1 << j):
tmp[j] = 24-x[j]
tmp.extend(two)
ans = max(calcmin(tmp), ans)
print(ans) | Statement
In CODE FESTIVAL XXXX, there are N+1 participants from all over the world,
including Takahashi.
Takahashi checked and found that the _time gap_ (defined below) between the
local times in his city and the i-th person's city was D_i hours. The time gap
between two cities is defined as follows. For two cities A and B, if the local
time in city B is d o'clock at the moment when the local time in city A is 0
o'clock, then the time gap between these two cities is defined to be
min(d,24-d) hours. Here, we are using 24-hour notation. That is, the local
time in the i-th person's city is either d o'clock or 24-d o'clock at the
moment when the local time in Takahashi's city is 0 o'clock, for example.
Then, for each pair of two people chosen from the N+1 people, he wrote out the
time gap between their cities. Let the smallest time gap among them be s
hours.
Find the maximum possible value of s. | [{"input": "3\n 7 12 8", "output": "4\n \n\nFor example, consider the situation where it is 7, 12 and 16 o'clock in each\nperson's city at the moment when it is 0 o'clock in Takahashi's city. In this\ncase, the time gap between the second and third persons' cities is 4 hours.\n\n* * *"}, {"input": "2\n 11 11", "output": "2\n \n\n* * *"}, {"input": "1\n 0", "output": "0\n \n\nNote that Takahashi himself is also a participant."}] |
Print the maximum possible value of s.
* * * | s349764199 | Accepted | p03525 | Input is given from Standard Input in the following format:
N
D_1 D_2 ... D_N | N = int(input())
D = [0] + [int(x) for x in input().split()]
m = D[1]
D.sort()
for i in range(1, N + 1):
D[i] = D[i] if i & 1 else 24 - D[i]
D.sort()
for i in range(1, N + 1):
m = min(m, D[i] - D[i - 1])
print(m)
| Statement
In CODE FESTIVAL XXXX, there are N+1 participants from all over the world,
including Takahashi.
Takahashi checked and found that the _time gap_ (defined below) between the
local times in his city and the i-th person's city was D_i hours. The time gap
between two cities is defined as follows. For two cities A and B, if the local
time in city B is d o'clock at the moment when the local time in city A is 0
o'clock, then the time gap between these two cities is defined to be
min(d,24-d) hours. Here, we are using 24-hour notation. That is, the local
time in the i-th person's city is either d o'clock or 24-d o'clock at the
moment when the local time in Takahashi's city is 0 o'clock, for example.
Then, for each pair of two people chosen from the N+1 people, he wrote out the
time gap between their cities. Let the smallest time gap among them be s
hours.
Find the maximum possible value of s. | [{"input": "3\n 7 12 8", "output": "4\n \n\nFor example, consider the situation where it is 7, 12 and 16 o'clock in each\nperson's city at the moment when it is 0 o'clock in Takahashi's city. In this\ncase, the time gap between the second and third persons' cities is 4 hours.\n\n* * *"}, {"input": "2\n 11 11", "output": "2\n \n\n* * *"}, {"input": "1\n 0", "output": "0\n \n\nNote that Takahashi himself is also a participant."}] |
Print the maximum possible value of s.
* * * | s749706953 | Wrong Answer | p03525 | Input is given from Standard Input in the following format:
N
D_1 D_2 ... D_N | print(0)
| Statement
In CODE FESTIVAL XXXX, there are N+1 participants from all over the world,
including Takahashi.
Takahashi checked and found that the _time gap_ (defined below) between the
local times in his city and the i-th person's city was D_i hours. The time gap
between two cities is defined as follows. For two cities A and B, if the local
time in city B is d o'clock at the moment when the local time in city A is 0
o'clock, then the time gap between these two cities is defined to be
min(d,24-d) hours. Here, we are using 24-hour notation. That is, the local
time in the i-th person's city is either d o'clock or 24-d o'clock at the
moment when the local time in Takahashi's city is 0 o'clock, for example.
Then, for each pair of two people chosen from the N+1 people, he wrote out the
time gap between their cities. Let the smallest time gap among them be s
hours.
Find the maximum possible value of s. | [{"input": "3\n 7 12 8", "output": "4\n \n\nFor example, consider the situation where it is 7, 12 and 16 o'clock in each\nperson's city at the moment when it is 0 o'clock in Takahashi's city. In this\ncase, the time gap between the second and third persons' cities is 4 hours.\n\n* * *"}, {"input": "2\n 11 11", "output": "2\n \n\n* * *"}, {"input": "1\n 0", "output": "0\n \n\nNote that Takahashi himself is also a participant."}] |
Print the maximum possible value of s.
* * * | s312944139 | Runtime Error | p03525 | Input is given from Standard Input in the following format:
N
D_1 D_2 ... D_N | N = int(input())
D = list(map(int, input().split()))
diff = [0]*13
D.sort()
for i in range(N):
diff[D[i]] += 1
if diff[0] > 0:
print(0)
exit(0)
else:
diff2 = [diff[12 - i] for i in range(1, N-1)]
for i in range(13):
if diff[i] > 2:
print(0)
exit(0)
ans = [0]
for i in range(N):
if i % 2 == 0:
ans.append(D[i])
else:
ans.append(24 - D[i])
ans = [abs(ans[i+1] - ans[i]) for i in range(N-1)]
print(min(ans))
| Statement
In CODE FESTIVAL XXXX, there are N+1 participants from all over the world,
including Takahashi.
Takahashi checked and found that the _time gap_ (defined below) between the
local times in his city and the i-th person's city was D_i hours. The time gap
between two cities is defined as follows. For two cities A and B, if the local
time in city B is d o'clock at the moment when the local time in city A is 0
o'clock, then the time gap between these two cities is defined to be
min(d,24-d) hours. Here, we are using 24-hour notation. That is, the local
time in the i-th person's city is either d o'clock or 24-d o'clock at the
moment when the local time in Takahashi's city is 0 o'clock, for example.
Then, for each pair of two people chosen from the N+1 people, he wrote out the
time gap between their cities. Let the smallest time gap among them be s
hours.
Find the maximum possible value of s. | [{"input": "3\n 7 12 8", "output": "4\n \n\nFor example, consider the situation where it is 7, 12 and 16 o'clock in each\nperson's city at the moment when it is 0 o'clock in Takahashi's city. In this\ncase, the time gap between the second and third persons' cities is 4 hours.\n\n* * *"}, {"input": "2\n 11 11", "output": "2\n \n\n* * *"}, {"input": "1\n 0", "output": "0\n \n\nNote that Takahashi himself is also a participant."}] |
Print the maximum possible value of s.
* * * | s310259026 | Runtime Error | p03525 | Input is given from Standard Input in the following format:
N
D_1 D_2 ... D_N | #include <iostream>
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep_r(i, n) for (int i = n - 1; i >= 0; i--)
#define rep1(i, n) for (int i = 1; i <= (int)(n); i++)
#define REP(i, n) for (int i = 0, i##_len = (n); i < i##_len; ++i)
#define all(x) (x).begin(), (x).end()
#define SZ(x) ((ll)(x).size())
#define bit(n) (1LL << (n))
#define UNIQUE(v) v.erase(unique(v.begin(), v.end()), v.end());
#define INF bit(60)
#define pb push_back
#define mod 1000000007
using namespace std;
using uif = uint_fast64_t;
using ll = long long int;
using tTree = __gnu_pbds::tree<ll, __gnu_pbds::null_type, less<ll>, __gnu_pbds::rb_tree_tag, __gnu_pbds::tree_order_statistics_node_update>;
ll dx[4] = {1, 0, -1, 0};
ll dy[4] = {0, 1, 0, -1};
#define FACSIZE 200002
ll invfac[FACSIZE];
ll fac[FACSIZE];
template <class T>
bool chmax(T &, const T &);
template <class T>
bool chmin(T &, const T &);
ll gcd(ll, ll);
ll powLL(ll x, ll y);
ll mod_pow(ll, ll);
ll mod_add(ll, ll);
ll mod_mul(ll, ll);
ll mod_div(ll, ll);
ll comb(ll, ll);
void make_fact(ll);
void make_invfact(ll);
void fact_init();
int main(void)
{
ll n;
cin >> n;
vector<ll> D(n);
rep(i, n) cin >> D[i];
vector<ll> vec;
vec.push_back(0);
vec.push_back(D[0]);
for (ll i = 1; i < n; i++)
{
ll d1, d2;
d1 = D[i];
d2 = (24 - D[i]) % 24;
ll min1 = 100, min2 = 100;
for (auto x : vec)
{
ll diff = abs(x - d1);
min1 = min(diff, min1);
}
for (auto x : vec)
{
ll diff = abs(x - d2);
min2 = min(diff, min2);
}
if (min1 < min2)
vec.push_back(d2);
else
vec.push_back(d1);
}
ll ans = 100;
rep(i, n + 1)
{
for (ll j = i + 1; j < n + 1; j++)
{
ans = min(ans, abs(vec[i] - vec[j]) % 24);
}
}
cout << ans << endl;
return 0;
}
ll mod_pow(ll x, ll r)
{
if (r == 0)
return 1;
else if (r == 1)
return x % mod;
else if (r % 2 == 0)
{
ll t = mod_pow(x, r / 2) % mod;
return mod_mul(t, t);
}
else
{
ll t = mod_pow(x, r / 2) % mod;
ll k = mod_mul(t, t);
return (k % mod) * (x % mod);
}
}
ll mod_add(ll a, ll b)
{
return ((a % mod) + (b % mod)) % mod;
}
ll mod_mul(ll a, ll b)
{
return ((a % mod) * (b % mod)) % mod;
}
ll mod_div(ll a, ll b)
{
return mod_mul(a, mod_pow(b, mod - 2));
}
void fact_init()
{
make_fact(FACSIZE - 1);
make_invfact(FACSIZE);
}
void make_fact(ll n)
{
fac[0] = 1;
rep(i, n)
{
fac[i + 1] = mod_mul(fac[i], i + 1);
}
}
void make_invfact(ll n)
{
invfac[n] = mod_pow(fac[n], mod - 2);
for (int i = n - 1; i >= 0; i--)
{
invfac[i] = mod_mul(invfac[i + 1], i + 1);
}
}
ll comb(ll n, ll r)
{
return mod_mul(mod_mul(fac[n], invfac[r]), invfac[n - r]);
}
template <class T>
bool chmax(T &a, const T &b)
{
if (a < b)
{
a = b;
return 1;
}
return 0;
}
template <class T>
bool chmin(T &a, const T &b)
{
if (b < a)
{
a = b;
return 1;
}
return 0;
}
ll qp(ll a, ll b)
{
ll ans = 1LL;
do
{
if (b & 1LL)
ans = 1LL * mod_mul(ans, a) % mod;
a = 1LL * mod_mul(a, a) % mod;
} while (b >>= 1LL);
return ans;
}
ll qp(ll a, ll b, ll mo)
{
ll ans = 1LL;
do
{
if (b & 1LL)
ans = 1LL * (ans % mo) * (a % mo);
a = 1LL * (a % mo) * (a % mo);
} while (b >>= 1LL);
return ans;
}
ll gcd(ll a, ll b)
{
return b ? gcd(b, a % b) : a;
}
ll powLL(ll x, ll y)
{
ll ans = 1LL;
for (ll i = 0LL; i < y; i++)
ans *= x;
return ans;
} | Statement
In CODE FESTIVAL XXXX, there are N+1 participants from all over the world,
including Takahashi.
Takahashi checked and found that the _time gap_ (defined below) between the
local times in his city and the i-th person's city was D_i hours. The time gap
between two cities is defined as follows. For two cities A and B, if the local
time in city B is d o'clock at the moment when the local time in city A is 0
o'clock, then the time gap between these two cities is defined to be
min(d,24-d) hours. Here, we are using 24-hour notation. That is, the local
time in the i-th person's city is either d o'clock or 24-d o'clock at the
moment when the local time in Takahashi's city is 0 o'clock, for example.
Then, for each pair of two people chosen from the N+1 people, he wrote out the
time gap between their cities. Let the smallest time gap among them be s
hours.
Find the maximum possible value of s. | [{"input": "3\n 7 12 8", "output": "4\n \n\nFor example, consider the situation where it is 7, 12 and 16 o'clock in each\nperson's city at the moment when it is 0 o'clock in Takahashi's city. In this\ncase, the time gap between the second and third persons' cities is 4 hours.\n\n* * *"}, {"input": "2\n 11 11", "output": "2\n \n\n* * *"}, {"input": "1\n 0", "output": "0\n \n\nNote that Takahashi himself is also a participant."}] |
Print the number of ways in which the vertices can be painted, modulo 10^9 +
7.
* * * | s303905752 | Accepted | p03175 | Input is given from Standard Input in the following format:
N
x_1 y_1
x_2 y_2
:
x_{N - 1} y_{N - 1} | ######################################################
############Created by Devesh Kumar###################
#############devesh1102@gmail.com####################
##########For CodeForces(Devesh1102)#################
#####################2020#############################
######################################################
import sys
input = sys.stdin.readline
# import sys
import heapq
import copy
import math
import decimal
# import sys.stdout.flush as flush
# from decimal import *
# heapq.heapify(li)
#
# heapq.heappush(li,4)
#
# heapq.heappop(li)
#
# & Bitwise AND Operator 10 & 7 = 2
# | Bitwise OR Operator 10 | 7 = 15
# ^ Bitwise XOR Operator 10 ^ 7 = 13
# << Bitwise Left Shift operator 10<<2 = 40
# >> Bitwise Right Shift Operator
# '''############ ---- Input Functions ---- #######Start#####'''
def inp():
return int(input())
def inlt():
return list(map(int, input().split()))
def insr():
s = input()
return list(s[: len(s) - 1])
def insr2():
s = input()
return s[: len(s) - 1]
def invr():
return map(int, input().split())
############ ---- Input Functions ---- #######End
# #####
def pr_list(a):
print(*a, sep=" ")
def main():
# tests = inp()
tests = 1
mod = 1000000007
limit = 10**18
ans = 0
start = {}
def pre_sum(arr):
ans = [arr[0]]
for i in range(1, len(arr)):
ans.append(ans[-1] + arr[i])
return ans
for test in range(tests):
n = inp()
branch = {}
# parent = [0 for i in range(n+1)]
for i in range(n - 1):
[p, r] = inlt()
if p in branch:
branch[p].append(r)
else:
branch[p] = [r]
if r in branch:
branch[r].append(p)
else:
branch[r] = [p]
parent = [-1 for i in range(n + 1)]
# print(branch)
# print(parent)
# print(branch)
dp = [[0 for j in range(n + 1)] for i in range(2)]
leaf = {}
ans = 2
stack = [1]
parent[1] = 0
if n == 1:
print(2)
continue
while stack != []:
# print(stack)
curr = stack[-1]
flag = 0
for i in branch[curr]:
if parent[i] == -1:
parent[i] = curr
stack.append(i)
flag = 1
if flag == 0:
curr = stack.pop()
white = 1
black = 1
for i in branch[curr]:
if i != parent[curr]:
white = (white * (dp[0][i] + dp[1][i])) % mod
black = (black * (dp[0][i])) % mod
dp[0][curr] = white
dp[1][curr] = black
print((dp[0][1] + dp[1][1]) % mod)
# for i in range(1,n+1):
# if i not in branch:
# leaf[i] = 1
# dp[0][i] =1
# dp[1][i] =1
# # print(leaf)
# while(leaf!={}):
# nexts = {}
# for i in leaf:
# nexts[parent[i]] = 1
# # print(nexts)
# if 0 in nexts:
# del nexts[0]
# for i in nexts:
# white = 1
# black = 1
# for j in branch[i]:
# white = white*(dp[0][j] + dp[1][j])
# black = black * dp[1][j]##1 is white
# dp[0][i] = black
# dp[1][i] = white
# ans= max(ans, dp[0][i]+dp[1][i])
# leaf = nexts
# print(ans)
if __name__ == "__main__":
main()
| Statement
There is a tree with N vertices, numbered 1, 2, \ldots, N. For each i (1 \leq
i \leq N - 1), the i-th edge connects Vertex x_i and y_i.
Taro has decided to paint each vertex in white or black. Here, it is not
allowed to paint two adjacent vertices both in black.
Find the number of ways in which the vertices can be painted, modulo 10^9 + 7. | [{"input": "3\n 1 2\n 2 3", "output": "5\n \n\nThere are five ways to paint the vertices, as follows:\n\n\n\n* * *"}, {"input": "4\n 1 2\n 1 3\n 1 4", "output": "9\n \n\nThere are nine ways to paint the vertices, as follows:\n\n\n\n* * *"}, {"input": "1", "output": "2\n \n\n* * *"}, {"input": "10\n 8 5\n 10 8\n 6 5\n 1 5\n 4 8\n 2 10\n 3 6\n 9 2\n 1 7", "output": "157"}] |
Print the number of ways in which the vertices can be painted, modulo 10^9 +
7.
* * * | s465421831 | Runtime Error | p03175 | Input is given from Standard Input in the following format:
N
x_1 y_1
x_2 y_2
:
x_{N - 1} y_{N - 1} | ######################################################
############Created by Devesh Kumar###################
#############devesh1102@gmail.com####################
##########For CodeForces(Devesh1102)#################
#####################2020#############################
######################################################
import sys
input = sys.stdin.readline
# import sys
import heapq
import copy
import math
import decimal
# import sys.stdout.flush as flush
# from decimal import *
#heapq.heapify(li)
#
#heapq.heappush(li,4)
#
#heapq.heappop(li)
#
# & Bitwise AND Operator 10 & 7 = 2
# | Bitwise OR Operator 10 | 7 = 15
# ^ Bitwise XOR Operator 10 ^ 7 = 13
# << Bitwise Left Shift operator 10<<2 = 40
# >> Bitwise Right Shift Operator
# '''############ ---- Input Functions ---- #######Start#####'''
def inp():
return(int(input()))
def inlt():
return(list(map(int,input().split())))
def insr():
s = input()
return(list(s[:len(s) - 1]))
def insr2():
s = input()
return((s[:len(s) - 1]))
def invr():
return(map(int,input().split()))
############ ---- Input Functions ---- #######End
# #####
def pr_list(a):
print(*a, sep=" ")
def main():
# tests = inp()
tests = 1
mod = 1000000007
limit = 10**18
ans = 0
start = {}
def pre_sum(arr):
ans = [arr[0]]
for i in range(1,len(arr)):
ans.append(ans[-1]+ arr[i])
return ans
for test in range(tests):
n = inp()
branch = {}
# parent = [0 for i in range(n+1)]
for i in range(n-1):
[p,r] = inlt()
if p in branch:
branch[p].append(r)
else:
branch[p] = [r]
if r in branch:
branch[r].append(p)
else:
branch[r] = [p]
parent = [-1 for i in range(n+1)]
# print(branch)
# print(parent)
# print(branch)
dp = [[0 for j in range(n+1)] for i in range(2)]
leaf = {}
ans = 2
stack = [1]
parent[1] = 0
if n == 1:
print(2)
continue
while(stack!=[]):
# print(stack)
curr = stack[-1]
flag = 0
for i in branch[curr]:
if parent[i] == -1:
parent[i] = curr
stack.append(i)
flag = 1
if flag == 0:
curr= stack.pop()
white = 1
black = 1
for i in branch[curr]:
if i !=parent[curr]:
white = white*(dp[0][i] + dp[1][i])
black = black*(dp[0][i])
dp[0][curr] = white
dp[1][curr] = black
print(dp[0][1] + dp[1][1])
# for i in range(1,n+1):
# if i not in branch:
# leaf[i] = 1
# dp[0][i] =1
# dp[1][i] =1
# # print(leaf)
# while(leaf!={}):
# nexts = {}
# for i in leaf:
# nexts[parent[i]] = 1
# # print(nexts)
# if 0 in nexts:
# del nexts[0]
# for i in nexts:
# white = 1
# black = 1
# for j in branch[i]:
# white = white*(dp[0][j] + dp[1][j])
# black = black * dp[1][j]##1 is white
# dp[0][i] = black
# dp[1][i] = white
# ans= max(ans, dp[0][i]+dp[1][i])
# leaf = nexts
# print(ans)
if __name__== "__main__":
main() | Statement
There is a tree with N vertices, numbered 1, 2, \ldots, N. For each i (1 \leq
i \leq N - 1), the i-th edge connects Vertex x_i and y_i.
Taro has decided to paint each vertex in white or black. Here, it is not
allowed to paint two adjacent vertices both in black.
Find the number of ways in which the vertices can be painted, modulo 10^9 + 7. | [{"input": "3\n 1 2\n 2 3", "output": "5\n \n\nThere are five ways to paint the vertices, as follows:\n\n\n\n* * *"}, {"input": "4\n 1 2\n 1 3\n 1 4", "output": "9\n \n\nThere are nine ways to paint the vertices, as follows:\n\n\n\n* * *"}, {"input": "1", "output": "2\n \n\n* * *"}, {"input": "10\n 8 5\n 10 8\n 6 5\n 1 5\n 4 8\n 2 10\n 3 6\n 9 2\n 1 7", "output": "157"}] |
Print the number of ways in which the vertices can be painted, modulo 10^9 +
7.
* * * | s683359346 | Runtime Error | p03175 | Input is given from Standard Input in the following format:
N
x_1 y_1
x_2 y_2
:
x_{N - 1} y_{N - 1} | import sys
sys.setrecursionlimit(10**6)
MOD = 10**9+7
N = int(input())
edge = [[] for _ in range(N+1)]
dp = [[0]*2 for i in range(100005)]
# dp[v][c]: 頂点vを色cの根とする部分木の塗り分け方の総数
# 葉が決まると順々に求まっていく
for i in range(N-1):
x,y = map(int,input().split())
edge[x].append(y)
edge[y].append(x)
# 0:white,1:black
def dfs(v,last=-1):
dp[v][0] = 1
dp[v][1] = 1
for nv in edge[v]:
if nv == last:
continue
dfs(nv, v)
dp[v][0] = dp[v][0] * ((dp[nv][0] + dp[nv][1]) % MOD) % MOD
dp[v][1] = dp[v][1] * dp[nv][0] % MOD
dfs(1)
print(dp[1][0] + dp[1][1])MOD = 10**9+7
N = int(input())
edge = [[] for _ in range(N+1)]
dp = [[0]*2 for i in range(100005)]
# dp[v][c]: 頂点vを色cの根とする部分木の塗り分け方の総数
# 葉が決まると順々に求まっていく
for i in range(N-1):
x,y = map(int,input().split())
edge[x].append(y)
edge[y].append(x)
# 0:white,1:black
def dfs(v,last=-1):
dp[v][0] = 1
dp[v][1] = 1
for nv in edge[v]:
if nv == last:
continue
dfs(nv, v)
dp[v][0] = dp[v][0] * ((dp[nv][0] + dp[nv][1]) % MOD) % MOD
dp[v][1] = dp[v][1] * dp[nv][0] % MOD
dfs(1)
print(dp[1][0] + dp[1][1]) | Statement
There is a tree with N vertices, numbered 1, 2, \ldots, N. For each i (1 \leq
i \leq N - 1), the i-th edge connects Vertex x_i and y_i.
Taro has decided to paint each vertex in white or black. Here, it is not
allowed to paint two adjacent vertices both in black.
Find the number of ways in which the vertices can be painted, modulo 10^9 + 7. | [{"input": "3\n 1 2\n 2 3", "output": "5\n \n\nThere are five ways to paint the vertices, as follows:\n\n\n\n* * *"}, {"input": "4\n 1 2\n 1 3\n 1 4", "output": "9\n \n\nThere are nine ways to paint the vertices, as follows:\n\n\n\n* * *"}, {"input": "1", "output": "2\n \n\n* * *"}, {"input": "10\n 8 5\n 10 8\n 6 5\n 1 5\n 4 8\n 2 10\n 3 6\n 9 2\n 1 7", "output": "157"}] |
Print the number of ways in which the vertices can be painted, modulo 10^9 +
7.
* * * | s129246805 | Runtime Error | p03175 | Input is given from Standard Input in the following format:
N
x_1 y_1
x_2 y_2
:
x_{N - 1} y_{N - 1} | from heapq import heappush, heappop
import collections
import math
import heapq
from collections import defaultdict
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10 ** 7)
MOD = 10 ** 9 + 7
inf = float("inf")
def main():
N = int(input())
E = {}
for i in range(0, N+1):
E[i] = []
for i in range(N-1):
a, b = map(int, input().split())
a -= 1
b -= 1
E[a].append(b)
E[b].append(a)
dp = [[0 for i in range(2)] for j in range(100100)]
def dfs(c, p):
dp[c][0], dp[c][1] = 1, 1
for to in E[c]:
if to != p:
dfs(to, c)
dp[c][0] *= dp[to][0] + dp[to][1]
dp[c][1] *= dp[to][0]
dfs(0, -1)
ans = (dp[0][0] + dp[0][1]) % MOD
print(ans)
if __name__ == '__main__':
main()
| Statement
There is a tree with N vertices, numbered 1, 2, \ldots, N. For each i (1 \leq
i \leq N - 1), the i-th edge connects Vertex x_i and y_i.
Taro has decided to paint each vertex in white or black. Here, it is not
allowed to paint two adjacent vertices both in black.
Find the number of ways in which the vertices can be painted, modulo 10^9 + 7. | [{"input": "3\n 1 2\n 2 3", "output": "5\n \n\nThere are five ways to paint the vertices, as follows:\n\n\n\n* * *"}, {"input": "4\n 1 2\n 1 3\n 1 4", "output": "9\n \n\nThere are nine ways to paint the vertices, as follows:\n\n\n\n* * *"}, {"input": "1", "output": "2\n \n\n* * *"}, {"input": "10\n 8 5\n 10 8\n 6 5\n 1 5\n 4 8\n 2 10\n 3 6\n 9 2\n 1 7", "output": "157"}] |
Print the number of ways in which the vertices can be painted, modulo 10^9 +
7.
* * * | s513278311 | Runtime Error | p03175 | Input is given from Standard Input in the following format:
N
x_1 y_1
x_2 y_2
:
x_{N - 1} y_{N - 1} | from heapq import heappush, heappop
import collections
import math
import heapq
from collections import defaultdict
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10 ** 7)
MOD = 10 ** 9 + 7
inf = float("inf")
def main():
N = int(input())
E = {}
for i in range(0, N+1):
E[i] = []
for i in range(N-1):
a, b = map(int, input().split())
a -= 1
b -= 1
E[a].append(b)
E[b].append(a)
dp = [[0 for i in range(2)] for j in range(100100)]
def dfs(c, p):
dp[c][0], dp[c][1] = 1, 1
for to in E[c]:
if to != p:
dfs(to, c)
dp[c][0] *= dp[to][0] + dp[to][1]
dp[c][1] *= dp[to][0]
dfs(0, -1)
ans = (dp[0][0] + dp[0][1]) % MOD
print(ans)
if __name__ == '__main__':
main() | Statement
There is a tree with N vertices, numbered 1, 2, \ldots, N. For each i (1 \leq
i \leq N - 1), the i-th edge connects Vertex x_i and y_i.
Taro has decided to paint each vertex in white or black. Here, it is not
allowed to paint two adjacent vertices both in black.
Find the number of ways in which the vertices can be painted, modulo 10^9 + 7. | [{"input": "3\n 1 2\n 2 3", "output": "5\n \n\nThere are five ways to paint the vertices, as follows:\n\n\n\n* * *"}, {"input": "4\n 1 2\n 1 3\n 1 4", "output": "9\n \n\nThere are nine ways to paint the vertices, as follows:\n\n\n\n* * *"}, {"input": "1", "output": "2\n \n\n* * *"}, {"input": "10\n 8 5\n 10 8\n 6 5\n 1 5\n 4 8\n 2 10\n 3 6\n 9 2\n 1 7", "output": "157"}] |
Print the number of ways in which the vertices can be painted, modulo 10^9 +
7.
* * * | s227423461 | Accepted | p03175 | Input is given from Standard Input in the following format:
N
x_1 y_1
x_2 y_2
:
x_{N - 1} y_{N - 1} | #!/usr/bin/env python3
from collections import defaultdict, deque
from heapq import heappush, heappop
from bisect import bisect_left, bisect_right
import sys, random, itertools, math
sys.setrecursionlimit(10**5)
input = sys.stdin.readline
sqrt = math.sqrt
def LI():
return list(map(int, input().split()))
def LF():
return list(map(float, input().split()))
def LI_():
return list(map(lambda x: int(x) - 1, input().split()))
def II():
return int(input())
def IF():
return float(input())
def LS():
return list(map(list, input().split()))
def S():
return list(input().rstrip())
def IR(n):
return [II() for _ in range(n)]
def LIR(n):
return [LI() for _ in range(n)]
def FR(n):
return [IF() for _ in range(n)]
def LFR(n):
return [LI() for _ in range(n)]
def LIR_(n):
return [LI_() for _ in range(n)]
def SR(n):
return [S() for _ in range(n)]
def LSR(n):
return [LS() for _ in range(n)]
mod = 1000000007
inf = 1e10
"""
URL: https://atcoder.jp/contests/dp/tasks/dp_p
P - Independent Set /
実行時間制限: 2 sec / メモリ制限: 1024 MB
配点 :
100 点
問題文
N 頂点の木があります。
頂点には 1,2,…,N と番号が振られています。
各 i (1≤i≤N−1) について、i 番目の辺は頂点 xi と yi を結んでいます。
太郎君は、各頂点を白または黒で塗ることにしました。 ただし、隣り合う頂点どうしをともに黒で塗ってはいけません。
頂点の色の組合せは何通りでしょうか?
10**9+7 で割った余りを求めてください。
制約
入力はすべて整数である。
1≤N≤10**5
1≤xi,yi≤N
与えられるグラフは木である。
"""
# solve
def solve():
n = II()
edg = [[] for _ in range(n)]
for _ in range(n - 1):
x, y = LI_()
edg[x].append(y)
edg[y].append(x)
black = [1] * n
white = [1] * n
rank = [-1] * n
rank[0] = [0, None]
q = deque()
q.append([0, -1])
while q:
node, pre = q.pop()
for nex in edg[node]:
if nex == pre:
continue
rank[nex] = [rank[node][0] + 1, node]
q.appendleft((nex, node))
ans = []
for i in range(n):
ans.append((-rank[i][0], rank[i][1], i))
ans.sort()
for _, i, j in ans[:-1]:
black[i] *= white[j]
white[i] *= white[j] + black[j]
black[i] %= mod
white[i] %= mod
print((white[0] + black[0]) % mod)
return
# main
if __name__ == "__main__":
solve()
| Statement
There is a tree with N vertices, numbered 1, 2, \ldots, N. For each i (1 \leq
i \leq N - 1), the i-th edge connects Vertex x_i and y_i.
Taro has decided to paint each vertex in white or black. Here, it is not
allowed to paint two adjacent vertices both in black.
Find the number of ways in which the vertices can be painted, modulo 10^9 + 7. | [{"input": "3\n 1 2\n 2 3", "output": "5\n \n\nThere are five ways to paint the vertices, as follows:\n\n\n\n* * *"}, {"input": "4\n 1 2\n 1 3\n 1 4", "output": "9\n \n\nThere are nine ways to paint the vertices, as follows:\n\n\n\n* * *"}, {"input": "1", "output": "2\n \n\n* * *"}, {"input": "10\n 8 5\n 10 8\n 6 5\n 1 5\n 4 8\n 2 10\n 3 6\n 9 2\n 1 7", "output": "157"}] |
Print the number of ways in which the vertices can be painted, modulo 10^9 +
7.
* * * | s447793697 | Wrong Answer | p03175 | Input is given from Standard Input in the following format:
N
x_1 y_1
x_2 y_2
:
x_{N - 1} y_{N - 1} | (N,) = map(int, input().split())
M = 10**9 + 7
d = [set() for _ in range(N + 1)]
from collections import deque
for _ in range(N - 1):
a, b = map(int, input().split())
d[a].add(b)
d[b].add(a)
stack = deque([1])
leafs = set()
p = [0 for _ in range(N + 1)]
vs = set([1])
vv = list()
while stack:
v = stack.popleft()
vv.append(v)
for u in d[v]:
if u in vs:
continue
p[u] = v
vs.add(u)
stack.append(u)
dp1 = [-1 for _ in range(N + 1)]
dp2 = [-1 for _ in range(N + 1)]
for v in vv[::-1]:
if len(d[v]) == 1 and v != 1:
dp1[v] = 1
dp2[v] = 1
continue
xx = yy = 1
for u in d[v]:
if p[v] == u:
continue
xx = (xx * dp2[u]) % M
yy = (yy * (dp1[u] + dp2[u])) % M
dp1[v] = xx
dp2[v] = yy
print(dp1[1] + dp2[1])
| Statement
There is a tree with N vertices, numbered 1, 2, \ldots, N. For each i (1 \leq
i \leq N - 1), the i-th edge connects Vertex x_i and y_i.
Taro has decided to paint each vertex in white or black. Here, it is not
allowed to paint two adjacent vertices both in black.
Find the number of ways in which the vertices can be painted, modulo 10^9 + 7. | [{"input": "3\n 1 2\n 2 3", "output": "5\n \n\nThere are five ways to paint the vertices, as follows:\n\n\n\n* * *"}, {"input": "4\n 1 2\n 1 3\n 1 4", "output": "9\n \n\nThere are nine ways to paint the vertices, as follows:\n\n\n\n* * *"}, {"input": "1", "output": "2\n \n\n* * *"}, {"input": "10\n 8 5\n 10 8\n 6 5\n 1 5\n 4 8\n 2 10\n 3 6\n 9 2\n 1 7", "output": "157"}] |
Print the number of ways in which the vertices can be painted, modulo 10^9 +
7.
* * * | s793662168 | Runtime Error | p03175 | Input is given from Standard Input in the following format:
N
x_1 y_1
x_2 y_2
:
x_{N - 1} y_{N - 1} | n = int(input())
li = []
mod = 10**9 + 7
for _ in range(n - 1):
li.append([int(k) for k in input().split()])
adjl = [[] for i in range(n + 1)]
for j in li:
adjl[j[0]].append(j[1])
adjl[j[1]].append(j[0])
# print(adjl)
visited = [0] * (n + 1)
fl = 0
dp = [[1 for i in range(2)] for j in range(n + 1)]
def findans(adjl, st):
# print(1)
fl = 0
visited[st] = 1
for k in range(len(adjl[st])):
if visited[adjl[st][k]] == 0:
fl = 1
ansli = findans(adjl, adjl[st][k])
dp[st][0] = ansli[1] * dp[st][0]
dp[st][1] = (ansli[1] + ansli[0]) * dp[st][1]
if len(adjl[st]) == 1 and fl == 0:
dp[st][0] = 1
dp[st][1] = 1
return dp[st]
findans(adjl, 1)
# print(visited)
# print(dp)
print((dp[1][0] + dp[1][1]) % mod)
| Statement
There is a tree with N vertices, numbered 1, 2, \ldots, N. For each i (1 \leq
i \leq N - 1), the i-th edge connects Vertex x_i and y_i.
Taro has decided to paint each vertex in white or black. Here, it is not
allowed to paint two adjacent vertices both in black.
Find the number of ways in which the vertices can be painted, modulo 10^9 + 7. | [{"input": "3\n 1 2\n 2 3", "output": "5\n \n\nThere are five ways to paint the vertices, as follows:\n\n\n\n* * *"}, {"input": "4\n 1 2\n 1 3\n 1 4", "output": "9\n \n\nThere are nine ways to paint the vertices, as follows:\n\n\n\n* * *"}, {"input": "1", "output": "2\n \n\n* * *"}, {"input": "10\n 8 5\n 10 8\n 6 5\n 1 5\n 4 8\n 2 10\n 3 6\n 9 2\n 1 7", "output": "157"}] |
Print the number of ways in which the vertices can be painted, modulo 10^9 +
7.
* * * | s660057004 | Runtime Error | p03175 | Input is given from Standard Input in the following format:
N
x_1 y_1
x_2 y_2
:
x_{N - 1} y_{N - 1} | n = int(input())
G = [[] for i in range(n)]
for i in range(n - 1):
x, y = map(int, input().split())
G[x - 1].append(y - 1)
G[y - 1].append(x - 1)
p = 10**9 + 7
Q = [0]
V = [False for i in range(n)]
C = [[] for i in range(n)]
while Q:
x = Q.pop()
V[x] = True
for y in G[x]:
if not V[y]:
C[x].append(y)
Q.append(y)
DP = [[None, None] for i in range(n)]
def dp(i, c):
if DP[i][c] != None:
return DP[i][c]
tmp = 1
for j in C[i]:
if c == 0:
tmp = (tmp * (dp(j, 0) + dp(j, 1))) % p
else:
tmp = (tmp * dp(j, 0)) % p
DP[i][c] = tmp
return DP[i][c]
print(dp(0, 0) + dp(0, 1))
| Statement
There is a tree with N vertices, numbered 1, 2, \ldots, N. For each i (1 \leq
i \leq N - 1), the i-th edge connects Vertex x_i and y_i.
Taro has decided to paint each vertex in white or black. Here, it is not
allowed to paint two adjacent vertices both in black.
Find the number of ways in which the vertices can be painted, modulo 10^9 + 7. | [{"input": "3\n 1 2\n 2 3", "output": "5\n \n\nThere are five ways to paint the vertices, as follows:\n\n\n\n* * *"}, {"input": "4\n 1 2\n 1 3\n 1 4", "output": "9\n \n\nThere are nine ways to paint the vertices, as follows:\n\n\n\n* * *"}, {"input": "1", "output": "2\n \n\n* * *"}, {"input": "10\n 8 5\n 10 8\n 6 5\n 1 5\n 4 8\n 2 10\n 3 6\n 9 2\n 1 7", "output": "157"}] |
Print the number of ways modulo $10^9+7$ in a line. | s107207127 | Accepted | p02334 | $n$ $k$
The first line will contain two integers $n$ and $k$. | N, K = map(int, input().split())
mod = 10**9 + 7
def mod_cmb(n, r, mod=10**9 + 7):
assert n >= r >= 0
def ex_euclid(x, y):
a, b = 1, 0
while y != 0:
a, b = b, (a - x // y * b)
x, y = y, x % y
return a
p = q = 1
for i in range(n - r + 1, n + 1):
p *= i
p %= mod
for i in range(2, r + 1):
q *= i
q %= mod
p *= ex_euclid(q, mod)
p %= mod
return p
print(mod_cmb(N + K - 1, N))
| You have $n$ balls and $k$ boxes. You want to put these balls into the boxes.
Find the number of ways to put the balls under the following conditions:
* Each ball is **not** distinguished from the other.
* Each box is distinguished from the other.
* Each ball can go into only one box and no one remains outside of the boxes.
* Each box can contain an arbitrary number of balls (including zero).
Note that you must print this count modulo $10^9+7$. | [{"input": "5 3", "output": "21"}, {"input": "10 5", "output": "1001"}, {"input": "100 100", "output": "703668401"}] |
Print the number of ways modulo $10^9+7$ in a line. | s089324673 | Accepted | p02334 | $n$ $k$
The first line will contain two integers $n$ and $k$. | N, K = map(int, input().split())
MOD = 10**9 + 7
p = q = 1
for i in range(N):
p = p * (N + K - 1 - i) % MOD
q = q * (i + 1) % MOD
print(p * pow(q, MOD - 2, MOD) % MOD)
| You have $n$ balls and $k$ boxes. You want to put these balls into the boxes.
Find the number of ways to put the balls under the following conditions:
* Each ball is **not** distinguished from the other.
* Each box is distinguished from the other.
* Each ball can go into only one box and no one remains outside of the boxes.
* Each box can contain an arbitrary number of balls (including zero).
Note that you must print this count modulo $10^9+7$. | [{"input": "5 3", "output": "21"}, {"input": "10 5", "output": "1001"}, {"input": "100 100", "output": "703668401"}] |
Print the answer.
It will be considered correct if its absolute or relative error from our
answer is at most 10^{-6}.
* * * | s593807985 | Accepted | p02764 | Input is given from Standard Input in the following format:
N K
x_1 y_1 c_1
\vdots
x_N y_N c_N | """
答えをにブタン
円がKこ以上重なる点が生まれる最小のtを求める
どうやって判定する?
"""
def wantnum(m):
plis = []
for i in range(N):
plis.append([xyc[i][0], xyc[i][1]])
for i in range(N):
for j in range(i):
xA = xyc[i][0]
yA = xyc[i][1]
xB = xyc[j][0]
yB = xyc[j][1]
r1 = m / xyc[i][2]
r2 = m / xyc[j][2]
X = xB - xA
Y = yB - yA
a = (X**2 + Y**2 + r1**2 - r2**2) / 2
retx1 = (a * X + Y * (((X**2 + Y**2) * (r1**2) - a**2) ** 0.5)) / (
X**2 + Y**2
)
rety1 = (a * Y - X * (((X**2 + Y**2) * (r1**2) - a**2) ** 0.5)) / (
X**2 + Y**2
)
retx1 += xA
rety1 += yA
retx2 = (a * X - Y * (((X**2 + Y**2) * (r1**2) - a**2) ** 0.5)) / (
X**2 + Y**2
)
rety2 = (a * Y + X * (((X**2 + Y**2) * (r1**2) - a**2) ** 0.5)) / (
X**2 + Y**2
)
retx2 += xA
rety2 += yA
if type(retx1) is not complex and type(rety1) is not complex:
plis.append([retx1, rety1])
if type(retx2) is not complex and type(rety2) is not complex:
plis.append([retx2, rety2])
ans = 0
for nx, ny in plis:
nnum = 0
for i, j, r in xyc:
if (i - nx) ** 2 + (j - ny) ** 2 < (m / r) ** 2 + 10 ** (-7):
nnum += 1
ans = max(ans, nnum)
return ans
N, K = map(int, input().split())
xyc = []
l = 0
r = 0
for i in range(N):
x, y, c = map(int, input().split())
xyc.append([x, y, c])
r = max(r, c * ((x**2 + y**2) ** 0.5))
while r - l > 10 ** (-7) and r - l > l * (10 ** (-7)):
m = (r + l) / 2
ret = wantnum(m)
# print (ret,m)
if ret >= K:
r = m
else:
l = m
print(r)
| Statement
Takahashi wants to grill N pieces of meat on a grilling net, which can be seen
as a two-dimensional plane. The coordinates of the i-th piece of meat are
\left(x_i, y_i\right), and its _hardness_ is c_i.
Takahashi can use one heat source to grill the meat. If he puts the heat
source at coordinates \left(X, Y\right), where X and Y are real numbers, the
i-th piece of meat will be ready to eat in c_i \times \sqrt{\left(X -
x_i\right)^2 + \left(Y-y_i\right)^2} seconds.
Takahashi wants to eat K pieces of meat. Find the time required to have K or
more pieces of meat ready if he put the heat source to minimize this time. | [{"input": "4 3\n -1 0 3\n 0 0 3\n 1 0 2\n 1 1 40", "output": "2.4\n \n\nIf we put the heat source at \\left(-0.2, 0\\right), the 1-st, 2-nd, and 3-rd\npieces of meat will be ready to eat within 2.4 seconds. This is the optimal\nplace to put the heat source.\n\n* * *"}, {"input": "10 5\n -879 981 26\n 890 -406 81\n 512 859 97\n 362 -955 25\n 128 553 17\n -885 763 2\n 449 310 57\n -656 -204 11\n -270 76 40\n 184 170 16", "output": "7411.2252"}] |
Print the answer.
It will be considered correct if its absolute or relative error from our
answer is at most 10^{-6}.
* * * | s845192020 | Wrong Answer | p02764 | Input is given from Standard Input in the following format:
N K
x_1 y_1 c_1
\vdots
x_N y_N c_N | import sys
input = sys.stdin.readline
n, K = map(int, input().split())
x = []
y = []
c = []
pc = []
for i in range(n):
xx, yy, cc = map(int, input().split())
x.append(xx)
y.append(yy)
c.append(1.0 / cc)
pc.append(cc)
esp = 0.000000001
def timecount(px, py, time):
cnt = 0
for i in range(n):
tmp = pc[i] * ((x[i] - px) ** 2 + (y[i] - py) ** 2) ** 0.5
if tmp - esp <= time:
cnt += 1
return cnt >= K
res = 10**9
for i in range(n):
for j in range(i + 1, n):
p, q = c[i], c[j]
px, py = (q * x[i] + p * x[j]) / (p + q), (q * y[i] + p * y[j]) / (p + q)
time = pc[i] * ((x[i] - px) ** 2 + (y[i] - py) ** 2) ** 0.5
# print(i,j,px,py,time)
if timecount(px, py, time):
res = min(res, time)
for i in range(n):
for j in range(i + 1, n):
for k in range(j + 1, n):
s = c[i] + c[j] + c[k]
A = c[i] * 2 / s
B = c[j] * 2 / s
C = c[k] * 2 / s
p = 1 - A
q = C - 1 + A
r = B - 1 + A
px, py = (p * x[i] + q * x[j] + r * x[k]) / (p + q + r), (
p * y[i] + q * y[j] + r * y[k]
) / (p + q + r)
time = max(
pc[i] * ((x[i] - px) ** 2 + (y[i] - py) ** 2) ** 0.5,
pc[j] * ((x[j] - px) ** 2 + (y[j] - py) ** 2) ** 0.5,
pc[k] * ((x[k] - px) ** 2 + (y[k] - py) ** 2) ** 0.5,
)
# print(i,j,k,px,py,time)
if timecount(px, py, time):
res = min(res, time)
print(res)
| Statement
Takahashi wants to grill N pieces of meat on a grilling net, which can be seen
as a two-dimensional plane. The coordinates of the i-th piece of meat are
\left(x_i, y_i\right), and its _hardness_ is c_i.
Takahashi can use one heat source to grill the meat. If he puts the heat
source at coordinates \left(X, Y\right), where X and Y are real numbers, the
i-th piece of meat will be ready to eat in c_i \times \sqrt{\left(X -
x_i\right)^2 + \left(Y-y_i\right)^2} seconds.
Takahashi wants to eat K pieces of meat. Find the time required to have K or
more pieces of meat ready if he put the heat source to minimize this time. | [{"input": "4 3\n -1 0 3\n 0 0 3\n 1 0 2\n 1 1 40", "output": "2.4\n \n\nIf we put the heat source at \\left(-0.2, 0\\right), the 1-st, 2-nd, and 3-rd\npieces of meat will be ready to eat within 2.4 seconds. This is the optimal\nplace to put the heat source.\n\n* * *"}, {"input": "10 5\n -879 981 26\n 890 -406 81\n 512 859 97\n 362 -955 25\n 128 553 17\n -885 763 2\n 449 310 57\n -656 -204 11\n -270 76 40\n 184 170 16", "output": "7411.2252"}] |
Print the answer.
It will be considered correct if its absolute or relative error from our
answer is at most 10^{-6}.
* * * | s291382759 | Accepted | p02764 | Input is given from Standard Input in the following format:
N K
x_1 y_1 c_1
\vdots
x_N y_N c_N | import sys
stdin = sys.stdin
ns = lambda: stdin.readline().rstrip()
ni = lambda: int(stdin.readline().rstrip())
nm = lambda: map(int, stdin.readline().split())
nl = lambda: list(map(int, stdin.readline().split()))
def intersection(p, q, eps=10**-7):
x1, y1, r1 = p
x2, y2, r2 = q
X = x2 - x1
Y = y2 - y1
d = X**2 + Y**2
c1 = r1**2
c2 = r2**2
rc = (d + c1 - c2) / 2
rs = d * c1 - rc**2
if rs < eps:
return list()
rs **= 0.5
p1x = x1 + (rc * X + rs * Y) / d
p1y = y1 + (rc * Y - rs * X) / d
p2x = x1 + (rc * X + rs * Y) / d
p2y = y1 + (rc * Y + rs * X) / d
return [(p1x, p1y), (p2x, p2y)]
eps = 10**-7
n, k = nm()
if k == 1:
print(0)
exit(0)
niku = [tuple(nm()) for _ in range(n)]
l = [c * (x**2 + y**2) ** 0.5 for x, y, c in niku]
l.sort()
hi = l[k - 1]
lo = 0
for _ in range(50):
mid = (hi + lo) / 2
l = [(x, y, mid / c) for x, y, c in niku]
p = [(x, y) for x, y, c in niku]
for i in range(n - 1):
for j in range(i + 1, n):
p.extend(intersection(l[i], l[j]))
for x, y in p:
f = sum((v - x) ** 2 + (w - y) ** 2 <= r**2 + eps for v, w, r in l)
if f >= k:
hi = mid
break
else:
lo = mid
print(hi)
| Statement
Takahashi wants to grill N pieces of meat on a grilling net, which can be seen
as a two-dimensional plane. The coordinates of the i-th piece of meat are
\left(x_i, y_i\right), and its _hardness_ is c_i.
Takahashi can use one heat source to grill the meat. If he puts the heat
source at coordinates \left(X, Y\right), where X and Y are real numbers, the
i-th piece of meat will be ready to eat in c_i \times \sqrt{\left(X -
x_i\right)^2 + \left(Y-y_i\right)^2} seconds.
Takahashi wants to eat K pieces of meat. Find the time required to have K or
more pieces of meat ready if he put the heat source to minimize this time. | [{"input": "4 3\n -1 0 3\n 0 0 3\n 1 0 2\n 1 1 40", "output": "2.4\n \n\nIf we put the heat source at \\left(-0.2, 0\\right), the 1-st, 2-nd, and 3-rd\npieces of meat will be ready to eat within 2.4 seconds. This is the optimal\nplace to put the heat source.\n\n* * *"}, {"input": "10 5\n -879 981 26\n 890 -406 81\n 512 859 97\n 362 -955 25\n 128 553 17\n -885 763 2\n 449 310 57\n -656 -204 11\n -270 76 40\n 184 170 16", "output": "7411.2252"}] |
Print the answer.
It will be considered correct if its absolute or relative error from our
answer is at most 10^{-6}.
* * * | s402602186 | Wrong Answer | p02764 | Input is given from Standard Input in the following format:
N K
x_1 y_1 c_1
\vdots
x_N y_N c_N | import math
n, k = map(int, input().split())
xyc = [list(map(int, input().split())) for i in range(n)]
def time(p, q):
ls = []
for x, y, c in xyc:
ls.append(math.hypot(x - p, y - q) * c)
ls.sort()
return ls[k - 1]
def tsearch(u):
lx = -1000
rx = 1000
for _ in range(100):
mlx = lx * (2 / 3) + rx * (1 / 3)
mrx = lx * (1 / 3) + rx * (2 / 3)
if time(mlx, u) > time(mrx, u):
lx = mlx
else:
rx = mrx
return lx
ly = -1000
ry = 1000
for _ in range(100):
mly = ly * (2 / 3) + ry * (1 / 3)
mry = ly * (1 / 3) + ry * (2 / 3)
if tsearch(mly) > tsearch(mry):
ly = mly
else:
ry = mry
lx = tsearch(ly)
print(time(lx, ly))
| Statement
Takahashi wants to grill N pieces of meat on a grilling net, which can be seen
as a two-dimensional plane. The coordinates of the i-th piece of meat are
\left(x_i, y_i\right), and its _hardness_ is c_i.
Takahashi can use one heat source to grill the meat. If he puts the heat
source at coordinates \left(X, Y\right), where X and Y are real numbers, the
i-th piece of meat will be ready to eat in c_i \times \sqrt{\left(X -
x_i\right)^2 + \left(Y-y_i\right)^2} seconds.
Takahashi wants to eat K pieces of meat. Find the time required to have K or
more pieces of meat ready if he put the heat source to minimize this time. | [{"input": "4 3\n -1 0 3\n 0 0 3\n 1 0 2\n 1 1 40", "output": "2.4\n \n\nIf we put the heat source at \\left(-0.2, 0\\right), the 1-st, 2-nd, and 3-rd\npieces of meat will be ready to eat within 2.4 seconds. This is the optimal\nplace to put the heat source.\n\n* * *"}, {"input": "10 5\n -879 981 26\n 890 -406 81\n 512 859 97\n 362 -955 25\n 128 553 17\n -885 763 2\n 449 310 57\n -656 -204 11\n -270 76 40\n 184 170 16", "output": "7411.2252"}] |
Print the answer.
It will be considered correct if its absolute or relative error from our
answer is at most 10^{-6}.
* * * | s433716702 | Runtime Error | p02764 | Input is given from Standard Input in the following format:
N K
x_1 y_1 c_1
\vdots
x_N y_N c_N | import sys
input = lambda: sys.stdin.readline().rstrip()
sys.setrecursionlimit(max(1000, 10**9))
write = lambda x: sys.stdout.write(x + "\n")
k, q = map(int, input().split())
d = list(map(int, input().split()))
def sub(n, x, m):
X = 0
init = x % m
x %= m
if n <= k:
for i in range(n - 1):
if x < (x + d[i]) % m:
X += 1
x = (x + d[i]) % m
ans = X
else:
for i in range(k):
if x < (x + d[i]) % m:
X += 1
x = (x + d[i]) % m
diff = x - init
ans = (n // k) * X - (init + (diff * (n // k))) // m
nn = n - (n // k) * k
xx = (init + (diff * (n // k))) % m
# if xx<init:
# ans -= 1
for i in range(nn - 1):
if xx < (xx + d[i]) % m:
ans += 1
xx = (xx + d[i]) % m
return ans
# else:
# ans = (n//k) * X + (init + (diff*(n//k)))
ans = [None] * q
for i in range(q):
n, x, m = map(int, input().split())
ans[i] = sub(n, x, m)
write("\n".join(map(str, ans)))
| Statement
Takahashi wants to grill N pieces of meat on a grilling net, which can be seen
as a two-dimensional plane. The coordinates of the i-th piece of meat are
\left(x_i, y_i\right), and its _hardness_ is c_i.
Takahashi can use one heat source to grill the meat. If he puts the heat
source at coordinates \left(X, Y\right), where X and Y are real numbers, the
i-th piece of meat will be ready to eat in c_i \times \sqrt{\left(X -
x_i\right)^2 + \left(Y-y_i\right)^2} seconds.
Takahashi wants to eat K pieces of meat. Find the time required to have K or
more pieces of meat ready if he put the heat source to minimize this time. | [{"input": "4 3\n -1 0 3\n 0 0 3\n 1 0 2\n 1 1 40", "output": "2.4\n \n\nIf we put the heat source at \\left(-0.2, 0\\right), the 1-st, 2-nd, and 3-rd\npieces of meat will be ready to eat within 2.4 seconds. This is the optimal\nplace to put the heat source.\n\n* * *"}, {"input": "10 5\n -879 981 26\n 890 -406 81\n 512 859 97\n 362 -955 25\n 128 553 17\n -885 763 2\n 449 310 57\n -656 -204 11\n -270 76 40\n 184 170 16", "output": "7411.2252"}] |
Print the answer.
It will be considered correct if its absolute or relative error from our
answer is at most 10^{-6}.
* * * | s551592584 | Wrong Answer | p02764 | Input is given from Standard Input in the following format:
N K
x_1 y_1 c_1
\vdots
x_N y_N c_N | import math
N, K = map(int, input().split())
xyc_array = [list(map(float, input().split())) for _ in range(N)]
# print(xyc_array)
ans = 100000
for i in range(N):
for j in range(i + 1, N):
x_i, y_i, c_i = xyc_array[i]
x_j, y_j, c_j = xyc_array[j]
gx = (c_i * x_i + c_j * x_j) / (c_i + c_j)
gy = (c_i * y_i + c_j * y_j) / (c_i + c_j)
time_array = [
c * math.sqrt((x - gx) ** 2 + (y - gy) ** 2) for x, y, c in xyc_array
]
time_array.sort()
ans = min(ans, time_array[K - 1])
if c_i != c_j:
gx = (-c_i * x_i + c_j * x_j) / (c_i - c_j)
gy = (-c_i * y_i + c_j * y_j) / (c_i - c_j)
# print(gx,gy)
time_array = [
c * math.sqrt((x - gx) ** 2 + (y - gy) ** 2) for x, y, c in xyc_array
]
time_array.sort()
ans = min(ans, time_array[K - 1])
print(ans)
| Statement
Takahashi wants to grill N pieces of meat on a grilling net, which can be seen
as a two-dimensional plane. The coordinates of the i-th piece of meat are
\left(x_i, y_i\right), and its _hardness_ is c_i.
Takahashi can use one heat source to grill the meat. If he puts the heat
source at coordinates \left(X, Y\right), where X and Y are real numbers, the
i-th piece of meat will be ready to eat in c_i \times \sqrt{\left(X -
x_i\right)^2 + \left(Y-y_i\right)^2} seconds.
Takahashi wants to eat K pieces of meat. Find the time required to have K or
more pieces of meat ready if he put the heat source to minimize this time. | [{"input": "4 3\n -1 0 3\n 0 0 3\n 1 0 2\n 1 1 40", "output": "2.4\n \n\nIf we put the heat source at \\left(-0.2, 0\\right), the 1-st, 2-nd, and 3-rd\npieces of meat will be ready to eat within 2.4 seconds. This is the optimal\nplace to put the heat source.\n\n* * *"}, {"input": "10 5\n -879 981 26\n 890 -406 81\n 512 859 97\n 362 -955 25\n 128 553 17\n -885 763 2\n 449 310 57\n -656 -204 11\n -270 76 40\n 184 170 16", "output": "7411.2252"}] |
Print the answer.
It will be considered correct if its absolute or relative error from our
answer is at most 10^{-6}.
* * * | s434477620 | Wrong Answer | p02764 | Input is given from Standard Input in the following format:
N K
x_1 y_1 c_1
\vdots
x_N y_N c_N | # 三分探索だと思うけど違う気もする
# 乱択でもいけるのかな(力が…欲しか…)
| Statement
Takahashi wants to grill N pieces of meat on a grilling net, which can be seen
as a two-dimensional plane. The coordinates of the i-th piece of meat are
\left(x_i, y_i\right), and its _hardness_ is c_i.
Takahashi can use one heat source to grill the meat. If he puts the heat
source at coordinates \left(X, Y\right), where X and Y are real numbers, the
i-th piece of meat will be ready to eat in c_i \times \sqrt{\left(X -
x_i\right)^2 + \left(Y-y_i\right)^2} seconds.
Takahashi wants to eat K pieces of meat. Find the time required to have K or
more pieces of meat ready if he put the heat source to minimize this time. | [{"input": "4 3\n -1 0 3\n 0 0 3\n 1 0 2\n 1 1 40", "output": "2.4\n \n\nIf we put the heat source at \\left(-0.2, 0\\right), the 1-st, 2-nd, and 3-rd\npieces of meat will be ready to eat within 2.4 seconds. This is the optimal\nplace to put the heat source.\n\n* * *"}, {"input": "10 5\n -879 981 26\n 890 -406 81\n 512 859 97\n 362 -955 25\n 128 553 17\n -885 763 2\n 449 310 57\n -656 -204 11\n -270 76 40\n 184 170 16", "output": "7411.2252"}] |
Print the answer.
It will be considered correct if its absolute or relative error from our
answer is at most 10^{-6}.
* * * | s358731949 | Wrong Answer | p02764 | Input is given from Standard Input in the following format:
N K
x_1 y_1 c_1
\vdots
x_N y_N c_N | from itertools import combinations
def main():
EPS = 1e-8
N, K, *XYC = map(int, open(0).read().split())
PC = [(complex(x, y), c) for x, y, c in zip(*[iter(XYC)] * 3)]
def intersection(A, r, B, s):
D = B - A
d = abs(D)
cos_t = (d * d + r * r - s * s) / (2 * d * r)
sin_t = max(1 - cos_t * cos_t, 0.0) ** 0.5
R = r * complex(cos_t, sin_t)
D /= d
return (
A + D * R,
A + D * R.conjugate(),
)
def is_ok(T):
A = [p for p, _ in PC]
for (p1, c1), (p2, c2) in combinations(PC, 2):
A += intersection(p1, T / c1, p2, T / c2)
return any(K <= sum(1 for p, c in PC if c * abs(a - p) < T + EPS) for a in A)
ng, ok = 0, 100000
for _ in range(100):
md = (ng + ok) / 2
if is_ok(md):
ok = md
else:
ng = md
print(ok)
main()
| Statement
Takahashi wants to grill N pieces of meat on a grilling net, which can be seen
as a two-dimensional plane. The coordinates of the i-th piece of meat are
\left(x_i, y_i\right), and its _hardness_ is c_i.
Takahashi can use one heat source to grill the meat. If he puts the heat
source at coordinates \left(X, Y\right), where X and Y are real numbers, the
i-th piece of meat will be ready to eat in c_i \times \sqrt{\left(X -
x_i\right)^2 + \left(Y-y_i\right)^2} seconds.
Takahashi wants to eat K pieces of meat. Find the time required to have K or
more pieces of meat ready if he put the heat source to minimize this time. | [{"input": "4 3\n -1 0 3\n 0 0 3\n 1 0 2\n 1 1 40", "output": "2.4\n \n\nIf we put the heat source at \\left(-0.2, 0\\right), the 1-st, 2-nd, and 3-rd\npieces of meat will be ready to eat within 2.4 seconds. This is the optimal\nplace to put the heat source.\n\n* * *"}, {"input": "10 5\n -879 981 26\n 890 -406 81\n 512 859 97\n 362 -955 25\n 128 553 17\n -885 763 2\n 449 310 57\n -656 -204 11\n -270 76 40\n 184 170 16", "output": "7411.2252"}] |
Print the answer.
It will be considered correct if its absolute or relative error from our
answer is at most 10^{-6}.
* * * | s922043484 | Wrong Answer | p02764 | Input is given from Standard Input in the following format:
N K
x_1 y_1 c_1
\vdots
x_N y_N c_N | N, K = map(int, input().split())
X = [list(map(int, input().split())) for i in range(N)]
eps = 1e-12
L, R, M, C, Yes, Y = eps, 10**6, 0, 0, 0, []
D = [0] * N
def dist(x, y):
return ((x[0] - y[0]) ** 2 + (x[1] - y[1]) ** 2) ** 0.5
def solve(E1, E2):
Z = [
2 * (E2[0] - E1[0]),
2 * (E2[1] - E1[1]),
(E1[0] + E2[0]) * (E1[0] - E2[0])
+ (E1[1] + E2[1]) * (E1[1] - E2[1])
+ (E1[2] + E2[2]) * (E2[2] - E1[2]),
]
d = abs(Z[0] * E1[0] + Z[1] * E1[1] + Z[2])
x = Z[0] * Z[0] + Z[1] * Z[1]
r = [
Z[1] * ((x * E1[2] * E1[2] - d * d) ** 0.5),
Z[0] * ((x * E1[2] * E1[2] - d * d) ** 0.5),
]
return [
[((Z[0] * d - r[0]) / x) + E1[0], ((Z[1] * d + r[1]) / x) + E1[1]],
[((Z[0] * d + r[0]) / x) + E1[0], ((Z[1] * d - r[1]) / x) + E1[1]],
]
for r in range(100):
M = (L + R) / 2
for i in range(N):
D[i] = M / X[i][2]
Yes = False
for i in range(N):
for j in range(i + 1, N):
if (
D[i] + D[j] - eps < dist(X[i], X[j])
or dist(X[i], X[j]) < abs(D[i] - D[j]) + eps
):
continue
Y = solve([X[i][0], X[i][1], D[i]], [X[j][0], X[j][1], D[j]])
for l in range(2):
C = 0
for k in range(N):
if (dist(X[k], Y[l]) - eps) * X[k][2] <= M:
C += 1
if C >= K:
Yes = True
if Yes:
R = M
else:
L = M
print(L)
| Statement
Takahashi wants to grill N pieces of meat on a grilling net, which can be seen
as a two-dimensional plane. The coordinates of the i-th piece of meat are
\left(x_i, y_i\right), and its _hardness_ is c_i.
Takahashi can use one heat source to grill the meat. If he puts the heat
source at coordinates \left(X, Y\right), where X and Y are real numbers, the
i-th piece of meat will be ready to eat in c_i \times \sqrt{\left(X -
x_i\right)^2 + \left(Y-y_i\right)^2} seconds.
Takahashi wants to eat K pieces of meat. Find the time required to have K or
more pieces of meat ready if he put the heat source to minimize this time. | [{"input": "4 3\n -1 0 3\n 0 0 3\n 1 0 2\n 1 1 40", "output": "2.4\n \n\nIf we put the heat source at \\left(-0.2, 0\\right), the 1-st, 2-nd, and 3-rd\npieces of meat will be ready to eat within 2.4 seconds. This is the optimal\nplace to put the heat source.\n\n* * *"}, {"input": "10 5\n -879 981 26\n 890 -406 81\n 512 859 97\n 362 -955 25\n 128 553 17\n -885 763 2\n 449 310 57\n -656 -204 11\n -270 76 40\n 184 170 16", "output": "7411.2252"}] |
Print the converted text. | s569940460 | Accepted | p00020 | A text including lower-case letters, periods, and space is given in a line.
The number of characters in the text is less than or equal to 200. | w = input()
print(w.upper())
| Capitalize
Write a program which replace all the lower-case letters of a given text with
the corresponding captital letters. | [{"input": "this is a pen.", "output": "THIS IS A PEN."}] |
Print the converted text. | s824630623 | Accepted | p00020 | A text including lower-case letters, periods, and space is given in a line.
The number of characters in the text is less than or equal to 200. | print("".join(map(str.upper, input())))
| Capitalize
Write a program which replace all the lower-case letters of a given text with
the corresponding captital letters. | [{"input": "this is a pen.", "output": "THIS IS A PEN."}] |
Print the converted text. | s359065427 | Accepted | p00020 | A text including lower-case letters, periods, and space is given in a line.
The number of characters in the text is less than or equal to 200. | A = input()
print(A.swapcase())
| Capitalize
Write a program which replace all the lower-case letters of a given text with
the corresponding captital letters. | [{"input": "this is a pen.", "output": "THIS IS A PEN."}] |
Print the converted text. | s303287747 | Accepted | p00020 | A text including lower-case letters, periods, and space is given in a line.
The number of characters in the text is less than or equal to 200. | print(str(input()).upper())
| Capitalize
Write a program which replace all the lower-case letters of a given text with
the corresponding captital letters. | [{"input": "this is a pen.", "output": "THIS IS A PEN."}] |
Print the converted text. | s784310404 | Accepted | p00020 | A text including lower-case letters, periods, and space is given in a line.
The number of characters in the text is less than or equal to 200. | t = input()
print(t.upper())
| Capitalize
Write a program which replace all the lower-case letters of a given text with
the corresponding captital letters. | [{"input": "this is a pen.", "output": "THIS IS A PEN."}] |
Print the converted text. | s679609019 | Accepted | p00020 | A text including lower-case letters, periods, and space is given in a line.
The number of characters in the text is less than or equal to 200. | try:
while True:
str = str(input())
print(str.upper())
except EOFError:
pass
| Capitalize
Write a program which replace all the lower-case letters of a given text with
the corresponding captital letters. | [{"input": "this is a pen.", "output": "THIS IS A PEN."}] |
Print the converted text. | s365195073 | Accepted | p00020 | A text including lower-case letters, periods, and space is given in a line.
The number of characters in the text is less than or equal to 200. | str = str(input())
str = str.upper()
print(str)
| Capitalize
Write a program which replace all the lower-case letters of a given text with
the corresponding captital letters. | [{"input": "this is a pen.", "output": "THIS IS A PEN."}] |
Print the converted text. | s419809680 | Accepted | p00020 | A text including lower-case letters, periods, and space is given in a line.
The number of characters in the text is less than or equal to 200. | w = str(input())
ans = ""
for c in w:
if 96 < ord(c) < 123:
c = c.upper()
ans += c
print(ans)
| Capitalize
Write a program which replace all the lower-case letters of a given text with
the corresponding captital letters. | [{"input": "this is a pen.", "output": "THIS IS A PEN."}] |
Print the converted text. | s485340820 | Accepted | p00020 | A text including lower-case letters, periods, and space is given in a line.
The number of characters in the text is less than or equal to 200. | x = input().upper()
print(x)
| Capitalize
Write a program which replace all the lower-case letters of a given text with
the corresponding captital letters. | [{"input": "this is a pen.", "output": "THIS IS A PEN."}] |
Print the converted text. | s731136722 | Wrong Answer | p00020 | A text including lower-case letters, periods, and space is given in a line.
The number of characters in the text is less than or equal to 200. | print(input().capitalize())
| Capitalize
Write a program which replace all the lower-case letters of a given text with
the corresponding captital letters. | [{"input": "this is a pen.", "output": "THIS IS A PEN."}] |
Print the converted text. | s090221134 | Accepted | p00020 | A text including lower-case letters, periods, and space is given in a line.
The number of characters in the text is less than or equal to 200. | print(input().rstrip().upper())
| Capitalize
Write a program which replace all the lower-case letters of a given text with
the corresponding captital letters. | [{"input": "this is a pen.", "output": "THIS IS A PEN."}] |
Print the converted text. | s067175017 | Accepted | p00020 | A text including lower-case letters, periods, and space is given in a line.
The number of characters in the text is less than or equal to 200. | line = input()
print(line.upper())
| Capitalize
Write a program which replace all the lower-case letters of a given text with
the corresponding captital letters. | [{"input": "this is a pen.", "output": "THIS IS A PEN."}] |
Print the minimum number of operations required.
* * * | s954602746 | Wrong Answer | p03319 | Input is given from Standard Input in the following format:
N K
A_1 A_2 ... A_N | a, b = map(int, input().split())
c = list(map(int, input().split()))
num = c.index(1)
left = num
right = a - left - 1
left_2 = left % (b - 1)
right_2 = right % (b - 1)
for i in range(b + 1):
if (left - i) % (b - 1) == 0:
amari = (right - (b - 1 - i)) % (b - 1)
kaisu_left = (left - i) // (b - 1)
kaisu_right = (right - (b - 1 - i)) // (b - 1)
print(kaisu_left + kaisu_right + 1 + amari)
| Statement
There is a sequence of length N: A_1, A_2, ..., A_N. Initially, this sequence
is a permutation of 1, 2, ..., N.
On this sequence, Snuke can perform the following operation:
* Choose K consecutive elements in the sequence. Then, replace the value of each chosen element with the minimum value among the chosen elements.
Snuke would like to make all the elements in this sequence equal by repeating
the operation above some number of times. Find the minimum number of
operations required. It can be proved that, Under the constraints of this
problem, this objective is always achievable. | [{"input": "4 3\n 2 3 1 4", "output": "2\n \n\nOne optimal strategy is as follows:\n\n * In the first operation, choose the first, second and third elements. The sequence A becomes 1, 1, 1, 4.\n\n * In the second operation, choose the second, third and fourth elements. The sequence A becomes 1, 1, 1, 1.\n\n* * *"}, {"input": "3 3\n 1 2 3", "output": "1\n \n\n* * *"}, {"input": "8 3\n 7 3 1 8 4 6 2 5", "output": "4"}] |
Print the minimum number of operations required.
* * * | s049684458 | Accepted | p03319 | Input is given from Standard Input in the following format:
N K
A_1 A_2 ... A_N | def examA():
N, M = LI()
l = 1
r = N
for _ in range(M):
L, R = LI()
l = max(L, l)
r = min(R, r)
ans = max(0, r - l + 1)
print(ans)
return
def examB():
N = I()
S = [I() for _ in range(N)]
rest = []
for s in S:
if s % 10 == 0:
continue
rest.append(s)
if sum(S) % 10 == 0:
if not rest:
print(0)
return
ans = sum(S) - min(rest)
else:
ans = sum(S)
print(ans)
return
def examC():
N, K = LI()
K -= 1
A = LI()
L = A.index(1)
# print(L)
ans = (N - 1 + K - 1) // K
print(ans)
return
def examD():
ans = 0
print(ans)
return
def examE():
ans = 0
print(ans)
return
def examF():
ans = 0
print(ans)
return
import sys, bisect, itertools, heapq, math, random
from copy import deepcopy
from heapq import heappop, heappush, heapify
from collections import Counter, defaultdict, deque
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
def I():
return int(readline())
def LI():
return list(map(int, readline().split()))
def LSI():
return list(map(str, sys.stdin.readline().split()))
def LS():
return sys.stdin.readline().split()
def SI():
return read().rstrip().decode("utf-8")
global mod, mod2, inf, alphabet, _ep
mod = 10**9 + 7
mod2 = 998244353
inf = 10**18
_ep = 10 ** (-12)
alphabet = [chr(ord("a") + i) for i in range(26)]
sys.setrecursionlimit(10**7)
if __name__ == "__main__":
examC()
"""
142
12 9 1445 0 1
asd dfg hj o o
aidn
"""
| Statement
There is a sequence of length N: A_1, A_2, ..., A_N. Initially, this sequence
is a permutation of 1, 2, ..., N.
On this sequence, Snuke can perform the following operation:
* Choose K consecutive elements in the sequence. Then, replace the value of each chosen element with the minimum value among the chosen elements.
Snuke would like to make all the elements in this sequence equal by repeating
the operation above some number of times. Find the minimum number of
operations required. It can be proved that, Under the constraints of this
problem, this objective is always achievable. | [{"input": "4 3\n 2 3 1 4", "output": "2\n \n\nOne optimal strategy is as follows:\n\n * In the first operation, choose the first, second and third elements. The sequence A becomes 1, 1, 1, 4.\n\n * In the second operation, choose the second, third and fourth elements. The sequence A becomes 1, 1, 1, 1.\n\n* * *"}, {"input": "3 3\n 1 2 3", "output": "1\n \n\n* * *"}, {"input": "8 3\n 7 3 1 8 4 6 2 5", "output": "4"}] |
Print the minimum number of operations required.
* * * | s966005387 | Runtime Error | p03319 | Input is given from Standard Input in the following format:
N K
A_1 A_2 ... A_N | N, M = map(int, input())
print(N // 2)
| Statement
There is a sequence of length N: A_1, A_2, ..., A_N. Initially, this sequence
is a permutation of 1, 2, ..., N.
On this sequence, Snuke can perform the following operation:
* Choose K consecutive elements in the sequence. Then, replace the value of each chosen element with the minimum value among the chosen elements.
Snuke would like to make all the elements in this sequence equal by repeating
the operation above some number of times. Find the minimum number of
operations required. It can be proved that, Under the constraints of this
problem, this objective is always achievable. | [{"input": "4 3\n 2 3 1 4", "output": "2\n \n\nOne optimal strategy is as follows:\n\n * In the first operation, choose the first, second and third elements. The sequence A becomes 1, 1, 1, 4.\n\n * In the second operation, choose the second, third and fourth elements. The sequence A becomes 1, 1, 1, 1.\n\n* * *"}, {"input": "3 3\n 1 2 3", "output": "1\n \n\n* * *"}, {"input": "8 3\n 7 3 1 8 4 6 2 5", "output": "4"}] |
Print the minimum number of operations required.
* * * | s315398341 | Accepted | p03319 | Input is given from Standard Input in the following format:
N K
A_1 A_2 ... A_N | read = lambda: map(int, input().split())
n, k = read()
a = list(read())
x = a.index(1)
ans = (n - 2) // (k - 1) + 1
print(ans)
| Statement
There is a sequence of length N: A_1, A_2, ..., A_N. Initially, this sequence
is a permutation of 1, 2, ..., N.
On this sequence, Snuke can perform the following operation:
* Choose K consecutive elements in the sequence. Then, replace the value of each chosen element with the minimum value among the chosen elements.
Snuke would like to make all the elements in this sequence equal by repeating
the operation above some number of times. Find the minimum number of
operations required. It can be proved that, Under the constraints of this
problem, this objective is always achievable. | [{"input": "4 3\n 2 3 1 4", "output": "2\n \n\nOne optimal strategy is as follows:\n\n * In the first operation, choose the first, second and third elements. The sequence A becomes 1, 1, 1, 4.\n\n * In the second operation, choose the second, third and fourth elements. The sequence A becomes 1, 1, 1, 1.\n\n* * *"}, {"input": "3 3\n 1 2 3", "output": "1\n \n\n* * *"}, {"input": "8 3\n 7 3 1 8 4 6 2 5", "output": "4"}] |
Print the minimum number of operations required.
* * * | s421155671 | Accepted | p03319 | Input is given from Standard Input in the following format:
N K
A_1 A_2 ... A_N | # -*- coding: utf-8 -*-
import sys
import math
import os
import itertools
import string
import heapq
import _collections
from collections import Counter
from collections import defaultdict
from functools import lru_cache
import bisect
class Scanner:
@staticmethod
def int():
return int(sys.stdin.readline().rstrip())
@staticmethod
def string():
return sys.stdin.readline().rstrip()
@staticmethod
def map_int():
return [int(x) for x in Scanner.string().split()]
@staticmethod
def string_list(n):
return [input() for i in range(n)]
@staticmethod
def int_list_list(n):
return [Scanner.map_int() for i in range(n)]
@staticmethod
def int_cols_list(n):
return [int(input()) for i in range(n)]
class Math:
@staticmethod
def gcd(a, b):
if b == 0:
return a
return Math.gcd(b, a % b)
@staticmethod
def lcm(a, b):
return (a * b) // Math.gcd(a, b)
@staticmethod
def roundUp(a, b):
return -(-a // b)
@staticmethod
def toUpperMultiple(a, x):
return Math.roundUp(a, x) * x
@staticmethod
def toLowerMultiple(a, x):
return (a // x) * x
@staticmethod
def nearPow2(n):
if n <= 0:
return 0
if n & (n - 1) == 0:
return n
ret = 1
while n > 0:
ret <<= 1
n >>= 1
return ret
@staticmethod
def isPrime(n):
if n < 2:
return False
if n == 2:
return True
if n % 2 == 0:
return False
d = int(n**0.5) + 1
for i in range(3, d + 1, 2):
if n % i == 0:
return False
return True
MOD = int(1e09) + 7
def main():
# sys.stdin = open("sample.txt")
N, K = Scanner.map_int()
A = Scanner.map_int()
print(Math.roundUp(N - 1, (K - 1)))
if __name__ == "__main__":
main()
| Statement
There is a sequence of length N: A_1, A_2, ..., A_N. Initially, this sequence
is a permutation of 1, 2, ..., N.
On this sequence, Snuke can perform the following operation:
* Choose K consecutive elements in the sequence. Then, replace the value of each chosen element with the minimum value among the chosen elements.
Snuke would like to make all the elements in this sequence equal by repeating
the operation above some number of times. Find the minimum number of
operations required. It can be proved that, Under the constraints of this
problem, this objective is always achievable. | [{"input": "4 3\n 2 3 1 4", "output": "2\n \n\nOne optimal strategy is as follows:\n\n * In the first operation, choose the first, second and third elements. The sequence A becomes 1, 1, 1, 4.\n\n * In the second operation, choose the second, third and fourth elements. The sequence A becomes 1, 1, 1, 1.\n\n* * *"}, {"input": "3 3\n 1 2 3", "output": "1\n \n\n* * *"}, {"input": "8 3\n 7 3 1 8 4 6 2 5", "output": "4"}] |
Print the minimum number of operations required.
* * * | s619677468 | Runtime Error | p03319 | Input is given from Standard Input in the following format:
N K
A_1 A_2 ... A_N | def resolve():
n, k = map(int, input().split())
a = list(map(int, input().split()))
lena = len(a)
if (lena-k) % (k-1) == 0:
print(((lena-k) // (k-1))+1)
else :
print(((lena-k) // (k-1))+2)
resolve() | Statement
There is a sequence of length N: A_1, A_2, ..., A_N. Initially, this sequence
is a permutation of 1, 2, ..., N.
On this sequence, Snuke can perform the following operation:
* Choose K consecutive elements in the sequence. Then, replace the value of each chosen element with the minimum value among the chosen elements.
Snuke would like to make all the elements in this sequence equal by repeating
the operation above some number of times. Find the minimum number of
operations required. It can be proved that, Under the constraints of this
problem, this objective is always achievable. | [{"input": "4 3\n 2 3 1 4", "output": "2\n \n\nOne optimal strategy is as follows:\n\n * In the first operation, choose the first, second and third elements. The sequence A becomes 1, 1, 1, 4.\n\n * In the second operation, choose the second, third and fourth elements. The sequence A becomes 1, 1, 1, 1.\n\n* * *"}, {"input": "3 3\n 1 2 3", "output": "1\n \n\n* * *"}, {"input": "8 3\n 7 3 1 8 4 6 2 5", "output": "4"}] |
Print the minimum number of operations required.
* * * | s155575786 | Wrong Answer | p03319 | Input is given from Standard Input in the following format:
N K
A_1 A_2 ... A_N | import numpy as np
print(0)
| Statement
There is a sequence of length N: A_1, A_2, ..., A_N. Initially, this sequence
is a permutation of 1, 2, ..., N.
On this sequence, Snuke can perform the following operation:
* Choose K consecutive elements in the sequence. Then, replace the value of each chosen element with the minimum value among the chosen elements.
Snuke would like to make all the elements in this sequence equal by repeating
the operation above some number of times. Find the minimum number of
operations required. It can be proved that, Under the constraints of this
problem, this objective is always achievable. | [{"input": "4 3\n 2 3 1 4", "output": "2\n \n\nOne optimal strategy is as follows:\n\n * In the first operation, choose the first, second and third elements. The sequence A becomes 1, 1, 1, 4.\n\n * In the second operation, choose the second, third and fourth elements. The sequence A becomes 1, 1, 1, 1.\n\n* * *"}, {"input": "3 3\n 1 2 3", "output": "1\n \n\n* * *"}, {"input": "8 3\n 7 3 1 8 4 6 2 5", "output": "4"}] |
Print the minimum number of operations required.
* * * | s624642622 | Wrong Answer | p03319 | Input is given from Standard Input in the following format:
N K
A_1 A_2 ... A_N | n, k, *lst = map(int, open(0).read().split())
one = lst.index(1)
print((one + 1) // (k - 1) + (n - one) // (k - 1))
| Statement
There is a sequence of length N: A_1, A_2, ..., A_N. Initially, this sequence
is a permutation of 1, 2, ..., N.
On this sequence, Snuke can perform the following operation:
* Choose K consecutive elements in the sequence. Then, replace the value of each chosen element with the minimum value among the chosen elements.
Snuke would like to make all the elements in this sequence equal by repeating
the operation above some number of times. Find the minimum number of
operations required. It can be proved that, Under the constraints of this
problem, this objective is always achievable. | [{"input": "4 3\n 2 3 1 4", "output": "2\n \n\nOne optimal strategy is as follows:\n\n * In the first operation, choose the first, second and third elements. The sequence A becomes 1, 1, 1, 4.\n\n * In the second operation, choose the second, third and fourth elements. The sequence A becomes 1, 1, 1, 1.\n\n* * *"}, {"input": "3 3\n 1 2 3", "output": "1\n \n\n* * *"}, {"input": "8 3\n 7 3 1 8 4 6 2 5", "output": "4"}] |
Print the minimum number of operations required.
* * * | s291418845 | Runtime Error | p03319 | Input is given from Standard Input in the following format:
N K
A_1 A_2 ... A_N | n, k, *_ = open(0)
print(((int(n) - 2) // (int(k) - 1)) + 1)
| Statement
There is a sequence of length N: A_1, A_2, ..., A_N. Initially, this sequence
is a permutation of 1, 2, ..., N.
On this sequence, Snuke can perform the following operation:
* Choose K consecutive elements in the sequence. Then, replace the value of each chosen element with the minimum value among the chosen elements.
Snuke would like to make all the elements in this sequence equal by repeating
the operation above some number of times. Find the minimum number of
operations required. It can be proved that, Under the constraints of this
problem, this objective is always achievable. | [{"input": "4 3\n 2 3 1 4", "output": "2\n \n\nOne optimal strategy is as follows:\n\n * In the first operation, choose the first, second and third elements. The sequence A becomes 1, 1, 1, 4.\n\n * In the second operation, choose the second, third and fourth elements. The sequence A becomes 1, 1, 1, 1.\n\n* * *"}, {"input": "3 3\n 1 2 3", "output": "1\n \n\n* * *"}, {"input": "8 3\n 7 3 1 8 4 6 2 5", "output": "4"}] |
Print the minimum number of operations required.
* * * | s496197629 | Runtime Error | p03319 | Input is given from Standard Input in the following format:
N K
A_1 A_2 ... A_N | n, k = int(input().split)
print((n + k - 3) / (k - 1))
| Statement
There is a sequence of length N: A_1, A_2, ..., A_N. Initially, this sequence
is a permutation of 1, 2, ..., N.
On this sequence, Snuke can perform the following operation:
* Choose K consecutive elements in the sequence. Then, replace the value of each chosen element with the minimum value among the chosen elements.
Snuke would like to make all the elements in this sequence equal by repeating
the operation above some number of times. Find the minimum number of
operations required. It can be proved that, Under the constraints of this
problem, this objective is always achievable. | [{"input": "4 3\n 2 3 1 4", "output": "2\n \n\nOne optimal strategy is as follows:\n\n * In the first operation, choose the first, second and third elements. The sequence A becomes 1, 1, 1, 4.\n\n * In the second operation, choose the second, third and fourth elements. The sequence A becomes 1, 1, 1, 1.\n\n* * *"}, {"input": "3 3\n 1 2 3", "output": "1\n \n\n* * *"}, {"input": "8 3\n 7 3 1 8 4 6 2 5", "output": "4"}] |
Print the minimum number of operations required.
* * * | s256320119 | Runtime Error | p03319 | Input is given from Standard Input in the following format:
N K
A_1 A_2 ... A_N | N, K = map(int, input().split())
A = list(map(int, input().split()))
mini = min(A)
idx = N + 1
mid = N / 2
for i, a in enumerate(A):
if a == mini and abs(idx - mid) > abs(i - mid):
idx = i
ans = i // (K - 1)
rem = i % (K - 1)
if rem:
ans += 1
if (N - i - 1 - (K - rem)) // (K - 1) > 0:
ans += (N - i - 1 - (K - rem)) // (K - 1)
if (N - i - 1 - (K - rem)) % (K - 1) != 0:
ans += 1
else:
if (N - i - 1) // (K - 1) > 0:
ans += (N - i - 1) // (K - 1)
if (N - i - 1) % (K - 1) != 0::
ans += 1
print(ans) | Statement
There is a sequence of length N: A_1, A_2, ..., A_N. Initially, this sequence
is a permutation of 1, 2, ..., N.
On this sequence, Snuke can perform the following operation:
* Choose K consecutive elements in the sequence. Then, replace the value of each chosen element with the minimum value among the chosen elements.
Snuke would like to make all the elements in this sequence equal by repeating
the operation above some number of times. Find the minimum number of
operations required. It can be proved that, Under the constraints of this
problem, this objective is always achievable. | [{"input": "4 3\n 2 3 1 4", "output": "2\n \n\nOne optimal strategy is as follows:\n\n * In the first operation, choose the first, second and third elements. The sequence A becomes 1, 1, 1, 4.\n\n * In the second operation, choose the second, third and fourth elements. The sequence A becomes 1, 1, 1, 1.\n\n* * *"}, {"input": "3 3\n 1 2 3", "output": "1\n \n\n* * *"}, {"input": "8 3\n 7 3 1 8 4 6 2 5", "output": "4"}] |
Print the minimum number of operations required.
* * * | s797120708 | Runtime Error | p03319 | Input is given from Standard Input in the following format:
N K
A_1 A_2 ... A_N | def sunuke_sum(arg):
sum_digit = 0
for char in arg:
sum_digit += int(char)
return sum_digit
input_num = int(input())
sunuke_list = []
min_sunuke_div = 10**20
for d in reversed(range(1, 16)):
for n in reversed(range(10, 100)):
i = n * (10**d) + (10**d - 1)
sunuke_div = i / sunuke_sum(str(i))
if min_sunuke_div >= sunuke_div:
sunuke_list.append(i)
min_sunuke_div = sunuke_div
for i in reversed(range(1, 101)):
sunuke_div = i / sunuke_sum(str(i))
if min_sunuke_div >= sunuke_div:
sunuke_list.append(i)
min_sunuke_div = sunuke_div
sunuke_list.reverse()
for i in range(0, input_num):
print(sunuke_list[i])
| Statement
There is a sequence of length N: A_1, A_2, ..., A_N. Initially, this sequence
is a permutation of 1, 2, ..., N.
On this sequence, Snuke can perform the following operation:
* Choose K consecutive elements in the sequence. Then, replace the value of each chosen element with the minimum value among the chosen elements.
Snuke would like to make all the elements in this sequence equal by repeating
the operation above some number of times. Find the minimum number of
operations required. It can be proved that, Under the constraints of this
problem, this objective is always achievable. | [{"input": "4 3\n 2 3 1 4", "output": "2\n \n\nOne optimal strategy is as follows:\n\n * In the first operation, choose the first, second and third elements. The sequence A becomes 1, 1, 1, 4.\n\n * In the second operation, choose the second, third and fourth elements. The sequence A becomes 1, 1, 1, 1.\n\n* * *"}, {"input": "3 3\n 1 2 3", "output": "1\n \n\n* * *"}, {"input": "8 3\n 7 3 1 8 4 6 2 5", "output": "4"}] |
Print the minimum number of operations required.
* * * | s091087706 | Runtime Error | p03319 | Input is given from Standard Input in the following format:
N K
A_1 A_2 ... A_N | k = input()
n=1
if k =< 9:
for cnt in range(1,k+1):
print(cnt)
else:
for cnt in range(1,10):
print(cnt)
for cnt in range(19,19+10*(k-9),10):
print(cnt)
| Statement
There is a sequence of length N: A_1, A_2, ..., A_N. Initially, this sequence
is a permutation of 1, 2, ..., N.
On this sequence, Snuke can perform the following operation:
* Choose K consecutive elements in the sequence. Then, replace the value of each chosen element with the minimum value among the chosen elements.
Snuke would like to make all the elements in this sequence equal by repeating
the operation above some number of times. Find the minimum number of
operations required. It can be proved that, Under the constraints of this
problem, this objective is always achievable. | [{"input": "4 3\n 2 3 1 4", "output": "2\n \n\nOne optimal strategy is as follows:\n\n * In the first operation, choose the first, second and third elements. The sequence A becomes 1, 1, 1, 4.\n\n * In the second operation, choose the second, third and fourth elements. The sequence A becomes 1, 1, 1, 1.\n\n* * *"}, {"input": "3 3\n 1 2 3", "output": "1\n \n\n* * *"}, {"input": "8 3\n 7 3 1 8 4 6 2 5", "output": "4"}] |
Print the minimum number of operations required.
* * * | s058067990 | Runtime Error | p03319 | Input is given from Standard Input in the following format:
N K
A_1 A_2 ... A_N | N, K = map(int, input().split())
A = input().split()
count = 0
if N = K:
print(1)
else:
count += 1
rem = N-K
add = 1 if (N-K)%(K-1) else 0
count += (N-K)//(K-1) + add
print(count) | Statement
There is a sequence of length N: A_1, A_2, ..., A_N. Initially, this sequence
is a permutation of 1, 2, ..., N.
On this sequence, Snuke can perform the following operation:
* Choose K consecutive elements in the sequence. Then, replace the value of each chosen element with the minimum value among the chosen elements.
Snuke would like to make all the elements in this sequence equal by repeating
the operation above some number of times. Find the minimum number of
operations required. It can be proved that, Under the constraints of this
problem, this objective is always achievable. | [{"input": "4 3\n 2 3 1 4", "output": "2\n \n\nOne optimal strategy is as follows:\n\n * In the first operation, choose the first, second and third elements. The sequence A becomes 1, 1, 1, 4.\n\n * In the second operation, choose the second, third and fourth elements. The sequence A becomes 1, 1, 1, 1.\n\n* * *"}, {"input": "3 3\n 1 2 3", "output": "1\n \n\n* * *"}, {"input": "8 3\n 7 3 1 8 4 6 2 5", "output": "4"}] |
Print the minimum number of operations required.
* * * | s857739710 | Accepted | p03319 | Input is given from Standard Input in the following format:
N K
A_1 A_2 ... A_N | def ii():
return int(input())
def lii():
return list(map(int, input().split(" ")))
def lvi(N):
l = []
for _ in range(N):
l.append(ii())
return l
def lv(N):
l = []
for _ in range(N):
l.append(input())
return l
def main():
N, K = lii()
a = lii()
min_ix = None
for i, v in enumerate(a):
if v == 1:
min_ix = i
break
def t(n, k):
if n <= 0:
return 0, 0
ans = n // k
if n % k:
ans += 1
return ans, n % k
if N - 1 - min_ix >= K - 1 and min_ix >= K - 1:
ans1, p1 = t(min_ix, K - 1)
ans2, p2 = t(N - 1 - min_ix, K - 1)
ans = ans1 + ans2
if p1 > 0 and p2 > 0 and p1 + p2 <= K - 1:
ans -= 1
return ans
elif min_ix < K - 1:
d = K - 1 - min_ix
ans, _ = t(N - 1 - min_ix - d, K - 1)
return 1 + ans
elif N - 1 - min_ix < K - 1:
d = K - 1 - (N - 1 - min_ix)
ans, _ = t(min_ix - d, K - 1)
return ans + 1
if __name__ == "__main__":
print(main())
| Statement
There is a sequence of length N: A_1, A_2, ..., A_N. Initially, this sequence
is a permutation of 1, 2, ..., N.
On this sequence, Snuke can perform the following operation:
* Choose K consecutive elements in the sequence. Then, replace the value of each chosen element with the minimum value among the chosen elements.
Snuke would like to make all the elements in this sequence equal by repeating
the operation above some number of times. Find the minimum number of
operations required. It can be proved that, Under the constraints of this
problem, this objective is always achievable. | [{"input": "4 3\n 2 3 1 4", "output": "2\n \n\nOne optimal strategy is as follows:\n\n * In the first operation, choose the first, second and third elements. The sequence A becomes 1, 1, 1, 4.\n\n * In the second operation, choose the second, third and fourth elements. The sequence A becomes 1, 1, 1, 1.\n\n* * *"}, {"input": "3 3\n 1 2 3", "output": "1\n \n\n* * *"}, {"input": "8 3\n 7 3 1 8 4 6 2 5", "output": "4"}] |
Print `Yes` if we pass the coordinate of House 3 on the straight way from
House 1 to House 2 without making a detour, and print `No` otherwise.
* * * | s898983007 | Accepted | p03067 | Input is given from Standard Input in the following format:
A B C | L = [int(T) for T in input().split()]
print(["No", "Yes"][sorted(L)[1] == L[2]])
| Statement
There are three houses on a number line: House 1, 2 and 3, with coordinates A,
B and C, respectively. Print `Yes` if we pass the coordinate of House 3 on the
straight way from House 1 to House 2 without making a detour, and print `No`
otherwise. | [{"input": "3 8 5", "output": "Yes\n \n\nWe pass the coordinate 5 on the straight way from the house at coordinate 3 to\nthe house at coordinate 8.\n\n* * *"}, {"input": "7 3 1", "output": "No\n \n\n* * *"}, {"input": "10 2 4", "output": "Yes\n \n\n* * *"}, {"input": "31 41 59", "output": "No"}] |
Print `Yes` if we pass the coordinate of House 3 on the straight way from
House 1 to House 2 without making a detour, and print `No` otherwise.
* * * | s296687803 | Runtime Error | p03067 | Input is given from Standard Input in the following format:
A B C | # 左端が黒 - > すべての黒を白にするかすべての白を黒にしなくちゃいけない(反転は2倍ひっくりかえさなければいけないぶん意味がない)
# 左端が白 -> 左端から連続する白を除いたところ以降の白を全て黒にするか、黒をすべて白にするか、あるいは左端を含む白をすべて黒にする
n = int(input())
s = input() + "髭"
arr = []
l, r = 0, 0
while l < n:
while r < n + 1 and s[r] == s[l]:
r += 1
arr.append(r - l)
l = r
ruiseki = [0]
for a in arr:
ruiseki.append(ruiseki[-1] + a)
if s[0] == "#":
ans = min(s.count("#"), s.count("."))
print(ans)
else:
h = 0
if s[-2] == "#":
h = arr[-1]
ans = min(s[ruiseki[1] :].count("#") - h, s[ruiseki[1] :].count("."), s.count("."))
print(ans)
| Statement
There are three houses on a number line: House 1, 2 and 3, with coordinates A,
B and C, respectively. Print `Yes` if we pass the coordinate of House 3 on the
straight way from House 1 to House 2 without making a detour, and print `No`
otherwise. | [{"input": "3 8 5", "output": "Yes\n \n\nWe pass the coordinate 5 on the straight way from the house at coordinate 3 to\nthe house at coordinate 8.\n\n* * *"}, {"input": "7 3 1", "output": "No\n \n\n* * *"}, {"input": "10 2 4", "output": "Yes\n \n\n* * *"}, {"input": "31 41 59", "output": "No"}] |
Print `Yes` if we pass the coordinate of House 3 on the straight way from
House 1 to House 2 without making a detour, and print `No` otherwise.
* * * | s327155129 | Runtime Error | p03067 | Input is given from Standard Input in the following format:
A B C | # -*- coding: utf-8 -*-
n = int(input())
s = str(input())
s = s.replace(".", "0").replace("#", "1")
b = s.find("1")
a = 0
for i in range(b, n):
a += int(s[i])
s = [int(n) for n in s]
sums = sum(list(s))
print(min(sums, n - sums, n - b - a))
| Statement
There are three houses on a number line: House 1, 2 and 3, with coordinates A,
B and C, respectively. Print `Yes` if we pass the coordinate of House 3 on the
straight way from House 1 to House 2 without making a detour, and print `No`
otherwise. | [{"input": "3 8 5", "output": "Yes\n \n\nWe pass the coordinate 5 on the straight way from the house at coordinate 3 to\nthe house at coordinate 8.\n\n* * *"}, {"input": "7 3 1", "output": "No\n \n\n* * *"}, {"input": "10 2 4", "output": "Yes\n \n\n* * *"}, {"input": "31 41 59", "output": "No"}] |
Print `Yes` if we pass the coordinate of House 3 on the straight way from
House 1 to House 2 without making a detour, and print `No` otherwise.
* * * | s802201837 | Runtime Error | p03067 | Input is given from Standard Input in the following format:
A B C | stone = input()
color = input()
a = int(stone)
counter = 0
counter2 = 0
black = 0
white = 0
xxx = []
yyy = []
list = []
for i in range(a):
list.append(color[i])
for i in range(a):
if list[i] == "#":
xxx.append(i)
black += 1
if list[i] == ".":
yyy.append(i)
white += 1
if white == 0 or black == 0:
print("0")
else:
s = min(xxx)
t = max(yyy)
for k in range(s, a):
if list[k] == ".":
counter = 1 + counter
for j in range(0, t):
if list[j] == "#":
counter2 = 1 + counter2
if counter < counter2:
print(counter)
else:
print(counter2)
| Statement
There are three houses on a number line: House 1, 2 and 3, with coordinates A,
B and C, respectively. Print `Yes` if we pass the coordinate of House 3 on the
straight way from House 1 to House 2 without making a detour, and print `No`
otherwise. | [{"input": "3 8 5", "output": "Yes\n \n\nWe pass the coordinate 5 on the straight way from the house at coordinate 3 to\nthe house at coordinate 8.\n\n* * *"}, {"input": "7 3 1", "output": "No\n \n\n* * *"}, {"input": "10 2 4", "output": "Yes\n \n\n* * *"}, {"input": "31 41 59", "output": "No"}] |
Print `Yes` if we pass the coordinate of House 3 on the straight way from
House 1 to House 2 without making a detour, and print `No` otherwise.
* * * | s709253948 | Runtime Error | p03067 | Input is given from Standard Input in the following format:
A B C | # C - Stones
n = int(input())
s = list(input())
isFound = False
cnt = 0
right = 0
# 一番右の白を見つける
for i in range(n):
if s[i] == ".":
right = max(right, i)
# rightまでの黒を数える
for i in range(right + 1):
if s[i] == "#":
cnt += 1
print(min(s.count("."), s.count("#"), cnt))
| Statement
There are three houses on a number line: House 1, 2 and 3, with coordinates A,
B and C, respectively. Print `Yes` if we pass the coordinate of House 3 on the
straight way from House 1 to House 2 without making a detour, and print `No`
otherwise. | [{"input": "3 8 5", "output": "Yes\n \n\nWe pass the coordinate 5 on the straight way from the house at coordinate 3 to\nthe house at coordinate 8.\n\n* * *"}, {"input": "7 3 1", "output": "No\n \n\n* * *"}, {"input": "10 2 4", "output": "Yes\n \n\n* * *"}, {"input": "31 41 59", "output": "No"}] |
Print `Yes` if we pass the coordinate of House 3 on the straight way from
House 1 to House 2 without making a detour, and print `No` otherwise.
* * * | s714616451 | Runtime Error | p03067 | Input is given from Standard Input in the following format:
A B C | a = int(input())
strings = input()
num = int(input())
target = strings[num - 1]
for i in range(a):
if target != strings[i]:
strings = strings[:i] + "*" + strings[i + 1 :]
print(strings)
| Statement
There are three houses on a number line: House 1, 2 and 3, with coordinates A,
B and C, respectively. Print `Yes` if we pass the coordinate of House 3 on the
straight way from House 1 to House 2 without making a detour, and print `No`
otherwise. | [{"input": "3 8 5", "output": "Yes\n \n\nWe pass the coordinate 5 on the straight way from the house at coordinate 3 to\nthe house at coordinate 8.\n\n* * *"}, {"input": "7 3 1", "output": "No\n \n\n* * *"}, {"input": "10 2 4", "output": "Yes\n \n\n* * *"}, {"input": "31 41 59", "output": "No"}] |
Print `Yes` if we pass the coordinate of House 3 on the straight way from
House 1 to House 2 without making a detour, and print `No` otherwise.
* * * | s828408361 | Wrong Answer | p03067 | Input is given from Standard Input in the following format:
A B C | if __name__ == "main":
[a, b, c] = map(lambda x: int(x), input().split())
answer = "Yes" if (a - b > a - c) else "no"
print(answer)
| Statement
There are three houses on a number line: House 1, 2 and 3, with coordinates A,
B and C, respectively. Print `Yes` if we pass the coordinate of House 3 on the
straight way from House 1 to House 2 without making a detour, and print `No`
otherwise. | [{"input": "3 8 5", "output": "Yes\n \n\nWe pass the coordinate 5 on the straight way from the house at coordinate 3 to\nthe house at coordinate 8.\n\n* * *"}, {"input": "7 3 1", "output": "No\n \n\n* * *"}, {"input": "10 2 4", "output": "Yes\n \n\n* * *"}, {"input": "31 41 59", "output": "No"}] |
Print `Yes` if we pass the coordinate of House 3 on the straight way from
House 1 to House 2 without making a detour, and print `No` otherwise.
* * * | s098296028 | Runtime Error | p03067 | Input is given from Standard Input in the following format:
A B C | N = int(input())
# S=input()
S = ["#" for i in range(200000)]
S[0] = "."
S = "".join(S)
cnt1 = 0
cnt2 = 0
for idx, s in enumerate(S):
if s == "#" and idx < N - 1:
cnt1 += 1
if s == "." and N == 0:
cnt2 += 1
if cnt1 < cnt2:
print(cnt1)
else:
print(cnt2)
| Statement
There are three houses on a number line: House 1, 2 and 3, with coordinates A,
B and C, respectively. Print `Yes` if we pass the coordinate of House 3 on the
straight way from House 1 to House 2 without making a detour, and print `No`
otherwise. | [{"input": "3 8 5", "output": "Yes\n \n\nWe pass the coordinate 5 on the straight way from the house at coordinate 3 to\nthe house at coordinate 8.\n\n* * *"}, {"input": "7 3 1", "output": "No\n \n\n* * *"}, {"input": "10 2 4", "output": "Yes\n \n\n* * *"}, {"input": "31 41 59", "output": "No"}] |
Print `Yes` if we pass the coordinate of House 3 on the straight way from
House 1 to House 2 without making a detour, and print `No` otherwise.
* * * | s737905278 | Accepted | p03067 | Input is given from Standard Input in the following format:
A B C | # 2019/10/15
A, B, C = map(int, open(0).read().split())
print("Yes" if A < C < B or A > C > B else "No")
| Statement
There are three houses on a number line: House 1, 2 and 3, with coordinates A,
B and C, respectively. Print `Yes` if we pass the coordinate of House 3 on the
straight way from House 1 to House 2 without making a detour, and print `No`
otherwise. | [{"input": "3 8 5", "output": "Yes\n \n\nWe pass the coordinate 5 on the straight way from the house at coordinate 3 to\nthe house at coordinate 8.\n\n* * *"}, {"input": "7 3 1", "output": "No\n \n\n* * *"}, {"input": "10 2 4", "output": "Yes\n \n\n* * *"}, {"input": "31 41 59", "output": "No"}] |
Print `Yes` if we pass the coordinate of House 3 on the straight way from
House 1 to House 2 without making a detour, and print `No` otherwise.
* * * | s365789190 | Runtime Error | p03067 | Input is given from Standard Input in the following format:
A B C | n = int(input())
s = list(input())
k = int(input())
l = s[k - 1]
for i in range(n):
if s[i] != l:
s[i] = "*"
print("".join(s))
| Statement
There are three houses on a number line: House 1, 2 and 3, with coordinates A,
B and C, respectively. Print `Yes` if we pass the coordinate of House 3 on the
straight way from House 1 to House 2 without making a detour, and print `No`
otherwise. | [{"input": "3 8 5", "output": "Yes\n \n\nWe pass the coordinate 5 on the straight way from the house at coordinate 3 to\nthe house at coordinate 8.\n\n* * *"}, {"input": "7 3 1", "output": "No\n \n\n* * *"}, {"input": "10 2 4", "output": "Yes\n \n\n* * *"}, {"input": "31 41 59", "output": "No"}] |
Print a positive integer not greater than 10^{18} that is a multiple of X but
not a multiple of Y, or print -1 if it does not exist.
* * * | s940582125 | Runtime Error | p03437 | Input is given from Standard Input in the following format:
X Y | x,y = input().split(' ')
x = int(x)
y = int(y)
if y == 1:
print(-1)
else:
if 0 < x and x <= 1e18:
print(x)
else :
print(=1) | Statement
You are given positive integers X and Y. If there exists a positive integer
not greater than 10^{18} that is a multiple of X but not a multiple of Y,
choose one such integer and print it. If it does not exist, print -1. | [{"input": "8 6", "output": "16\n \n\nFor example, 16 is a multiple of 8 but not a multiple of 6.\n\n* * *"}, {"input": "3 3", "output": "-1\n \n\nA multiple of 3 is a multiple of 3."}] |
Print a positive integer not greater than 10^{18} that is a multiple of X but
not a multiple of Y, or print -1 if it does not exist.
* * * | s354979399 | Runtime Error | p03437 | Input is given from Standard Input in the following format:
X Y | n = int(input())
a = list(map(int,input().split()))
b = list(map(int,input().split()))
cou = 0
for j,k in zip(a,b):
if j<k:
cou += (k-j)//2
elif j>k:
cou -= (j-k)
if cou=>0:
print("Yes")
else:
print("No") | Statement
You are given positive integers X and Y. If there exists a positive integer
not greater than 10^{18} that is a multiple of X but not a multiple of Y,
choose one such integer and print it. If it does not exist, print -1. | [{"input": "8 6", "output": "16\n \n\nFor example, 16 is a multiple of 8 but not a multiple of 6.\n\n* * *"}, {"input": "3 3", "output": "-1\n \n\nA multiple of 3 is a multiple of 3."}] |
Print a positive integer not greater than 10^{18} that is a multiple of X but
not a multiple of Y, or print -1 if it does not exist.
* * * | s386948337 | Runtime Error | p03437 | Input is given from Standard Input in the following format:
X Y | X , Y = map(int, input()split())
if X%Y == 0:
print(-1)
else:
i = 1
while True:
if X*i%Y != 0:
print(X*i)
break | Statement
You are given positive integers X and Y. If there exists a positive integer
not greater than 10^{18} that is a multiple of X but not a multiple of Y,
choose one such integer and print it. If it does not exist, print -1. | [{"input": "8 6", "output": "16\n \n\nFor example, 16 is a multiple of 8 but not a multiple of 6.\n\n* * *"}, {"input": "3 3", "output": "-1\n \n\nA multiple of 3 is a multiple of 3."}] |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.