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 |
|---|---|---|---|---|---|---|---|
For each query, print the coordinate of the reflection point x. The output
values should be in a decimal fraction with an error less than 0.00000001. | s632265017 | Accepted | p02291 | xp1 yp1 xp2 yp2
q
xp0 yp0
xp1 yp1
...
xpq−1 ypq−1
In the first line, integer coordinates of p1 and p2 are given. Then, q queries
are given for integer coordinates of p. | if __name__ == "__main__":
x_p1, y_p1, x_p2, y_p2 = map(lambda x: int(x), input().split())
q = int(input())
p1p2 = (x_p2 - x_p1, y_p2 - y_p1)
for _ in range(q):
x_p0, y_p0 = map(lambda x: int(x), input().split())
p1p0 = (x_p0 - x_p1, y_p0 - y_p1)
r = (p1p2[0] * p1p0[0] + p1p2[1] * p1p0[1]) / (p1p2[0] ** 2 + p1p2[1] ** 2)
proj_p = (x_p1 + p1p2[0] * r, y_p1 + p1p2[1] * r)
proj_v = (proj_p[0] - x_p0, proj_p[1] - y_p0)
print(x_p0 + 2 * proj_v[0], y_p0 + 2 * proj_v[1])
| Reflection
For given three points p1, p2, p, find the reflection point x of p onto p1p2.
 | [{"input": "0 0 2 0\n 3\n -1 1\n 0 1\n 1 1", "output": "-1.0000000000 -1.0000000000\n 0.0000000000 -1.0000000000\n 1.0000000000 -1.0000000000"}, {"input": "0 0 3 4\n 3\n 2 5\n 1 4\n 0 3", "output": "4.2400000000 3.3200000000\n 3.5600000000 2.0800000000\n 2.8800000000 0.8400000000"}] |
For each query, print the coordinate of the reflection point x. The output
values should be in a decimal fraction with an error less than 0.00000001. | s166577078 | Wrong Answer | p02291 | xp1 yp1 xp2 yp2
q
xp0 yp0
xp1 yp1
...
xpq−1 ypq−1
In the first line, integer coordinates of p1 and p2 are given. Then, q queries
are given for integer coordinates of p. | import math
class Point:
def __init__(self, x=None, y=None):
self.x = x
self.y = y
class Line:
def __init__(self, x1, y1, x2, y2):
self.p1 = Point(x1, y1)
self.p2 = Point(x2, y2)
def projection(self, p):
a = (
(self.p2.y - self.p1.y) / (self.p2.x - self.p1.x)
if self.p2.x != self.p1.x
else float("inf")
)
b = self.p2.y - a * self.p2.x
d = abs(-1 * a * p.x + p.y - b) / math.sqrt(1 + a * a)
ans_y = [
p.y + math.sqrt(4 * d * d / (a * a + 1)),
p.y - math.sqrt(4 * d * d / (a * a + 1)),
]
ans_x = [p.x - a * (_y - p.y) for _y in ans_y]
rst_x, rst_y = None, None
tmp = abs(-1 * a * ans_x[0] + ans_y[0] - b) / math.sqrt(1 + a * a) - d
if tmp < abs(-1 * a * ans_x[1] + ans_y[1] - b) / math.sqrt(1 + a * a) - d:
rst_x, rst_y = ans_x[0], ans_y[0]
else:
rst_x, rst_y = ans_x[1], ans_y[1]
return round(rst_x, 9), round(rst_y, 9)
x1, y1, x2, y2 = list(map(int, input().split(" ")))
line = Line(x1, y1, x2, y2)
q = int(input())
for i in range(q):
x, y = list(map(int, input().split(" ")))
p = Point(x, y)
rst_x, rst_y = line.projection(p)
print(rst_x, rst_y)
| Reflection
For given three points p1, p2, p, find the reflection point x of p onto p1p2.
 | [{"input": "0 0 2 0\n 3\n -1 1\n 0 1\n 1 1", "output": "-1.0000000000 -1.0000000000\n 0.0000000000 -1.0000000000\n 1.0000000000 -1.0000000000"}, {"input": "0 0 3 4\n 3\n 2 5\n 1 4\n 0 3", "output": "4.2400000000 3.3200000000\n 3.5600000000 2.0800000000\n 2.8800000000 0.8400000000"}] |
For each query, print the coordinate of the reflection point x. The output
values should be in a decimal fraction with an error less than 0.00000001. | s340391166 | Accepted | p02291 | xp1 yp1 xp2 yp2
q
xp0 yp0
xp1 yp1
...
xpq−1 ypq−1
In the first line, integer coordinates of p1 and p2 are given. Then, q queries
are given for integer coordinates of p. | # これの元のprojectionは通ったが、これはおかしくなる。
# 数字自体は誤差の範囲内に収まった正解なので、-e16みたいな表示になるせいだと思う
# たぶんベクトルのノルムで割る操作が悪い
# 連立方程式を解くべきか
L1 = input().split()
[xp1, yp1, xp2, yp2] = [int(L1[0]), int(L1[1]), int(L1[2]), int(L1[3])]
direction = [xp2 - xp1, yp2 - yp1]
norm_direc = [
(xp2 - xp1) / ((xp2 - xp1) ** 2 + (yp2 - yp1) ** 2) ** (1 / 2),
(yp2 - yp1) / ((xp2 - xp1) ** 2 + (yp2 - yp1) ** 2) ** (1 / 2),
]
q = int(input())
L = []
for i in range(q):
L2 = input().split()
L.append([int(L2[0]), int(L2[1])])
Point = []
for i in range(q):
Point.append([(L[i][0] - xp1), (L[i][1] - yp1)])
Vec = []
for i in range(q):
Vec.append([L[i][0] - xp1, L[i][1] - yp1])
Proj = []
for i in range(q):
inter = Vec[i][0] * norm_direc[0] + Vec[i][1] * norm_direc[1]
Proj.append([norm_direc[0] * inter, norm_direc[1] * inter])
# 以下射影用
# L2=[]
# for i in range(q):
# L2.append([xp1+Proj[i][0],yp1+Proj[i][1]])
# for i in range(q):
# print(*L2[i])
vert = []
for i in range(q):
vert.append([Vec[i][0] - Proj[i][0], Vec[i][1] - Proj[i][1]])
L3 = []
for i in range(q):
a = L[i][0] - 2 * vert[i][0]
b = L[i][1] - 2 * vert[i][1]
if -0.00000001 < a < 0.00000001:
a = 0
if -0.00000001 < b < 0.00000001:
b = 0
L3.append([a, b])
for i in range(q):
print(*L3[i])
| Reflection
For given three points p1, p2, p, find the reflection point x of p onto p1p2.
 | [{"input": "0 0 2 0\n 3\n -1 1\n 0 1\n 1 1", "output": "-1.0000000000 -1.0000000000\n 0.0000000000 -1.0000000000\n 1.0000000000 -1.0000000000"}, {"input": "0 0 3 4\n 3\n 2 5\n 1 4\n 0 3", "output": "4.2400000000 3.3200000000\n 3.5600000000 2.0800000000\n 2.8800000000 0.8400000000"}] |
For each query, print the coordinate of the reflection point x. The output
values should be in a decimal fraction with an error less than 0.00000001. | s663318555 | Accepted | p02291 | xp1 yp1 xp2 yp2
q
xp0 yp0
xp1 yp1
...
xpq−1 ypq−1
In the first line, integer coordinates of p1 and p2 are given. Then, q queries
are given for integer coordinates of p. | import math
class Point:
def __init__(self, x, y):
self.x = x
self.y = y
def __add__(self, a):
return self.__class__(self.x + a.x, self.y + a.y)
def __sub__(self, a):
return self.__class__(self.x - a.x, self.y - a.y)
def __mul__(self, d):
return self.__class__(self.x * d, self.y * d)
def __truediv__(self, d):
return self.__class__(self.x / d, self.y / d)
def __str__(self):
return "%.10f %.10f" % (self.x, self.y)
def abs(self):
return self.norm() ** (1.0 / 2.0)
def norm(self):
return self.x * self.x + self.y * self.y
def rotate(self, d):
r = math.pi * d / 180.0
return self.__class__(
self.x * math.cos(r) - self.y * math.sin(r),
self.x * math.sin(r) + self.y * math.cos(r),
)
def dot(self, p):
return self.x * p.x + self.y * p.y
class Segment:
def __init__(self, p1, p2):
self.p1 = p1
self.p2 = p2
def project(s, p):
v = s.p2 - s.p1
r = v.dot(p - s.p1) / v.norm()
return s.p1 + v * r
def reflect(s, p):
return p + (project(s, p) - p) * 2.0
def main():
a, b, c, d = map(float, input().split())
s = Segment(Point(a, b), Point(c, d))
q = int(input())
for _ in range(q):
e, f = map(float, input().split())
p = Point(e, f)
print(reflect(s, p))
if __name__ == "__main__":
main()
| Reflection
For given three points p1, p2, p, find the reflection point x of p onto p1p2.
 | [{"input": "0 0 2 0\n 3\n -1 1\n 0 1\n 1 1", "output": "-1.0000000000 -1.0000000000\n 0.0000000000 -1.0000000000\n 1.0000000000 -1.0000000000"}, {"input": "0 0 3 4\n 3\n 2 5\n 1 4\n 0 3", "output": "4.2400000000 3.3200000000\n 3.5600000000 2.0800000000\n 2.8800000000 0.8400000000"}] |
For each dataset, print a line containing an integer indicating the maximum
number of discs that can be removed. | s817009003 | Runtime Error | p00756 | The input consists of multiple datasets, each being in the following format
and representing the state of a game just after all the discs are scattered.
> _n_
> _x_ 1 _y_ 1 _r_ 1 _c_ 1
> _x_ 2 _y_ 2 _r_ 2 _c_ 2
> ...
> _x_ _n_ _y_ _n_ _r_ _n_ _c_ _n_
>
The first line consists of a positive integer _n_ representing the number of
discs. The following _n_ lines, each containing 4 integers separated by a
single space, represent the colors, sizes, and initial placings of the _n_
discs in the following manner:
* (_x_ _i_ , _y_ _i_), _r_ _i_ , and _c_ _i_ are the _xy_ -coordinates of the center, the radius, and the color index number, respectively, of the _i_ -th disc, and
* whenever the _i_ -th disc is put on top of the _j_ -th disc, _i_ < _j_ must be satisfied.
You may assume that every color index number is between 1 and 4, inclusive,
and at most 6 discs in a dataset are of the same color. You may also assume
that the _x_ \- and _y_ -coordinates of the center of every disc are between 0
and 100, inclusive, and the radius between 1 and 100, inclusive.
The end of the input is indicated by a single zero. | def xx(x):
return x * x
def pop(overlaps, i, lis):
for k in lis:
if i > k and overlaps[i][k]:
return False
return True
def search(disks, overlaps, lis):
if len(lis) < 2:
return 0
res = 0
for i in lis:
if not pop(overlaps, i, lis):
continue
# print("OK", i)
for k in lis:
if i == k:
continue
if disks[i][3] != disks[k][3]:
continue
if not pop(overlaps, k, lis):
continue
# print("Good", k)
giv = list(lis)
giv.remove(i)
giv.remove(k)
res = max(res, 2 + search(disks, overlaps, giv))
return res
while True:
n = int(input())
if n == 0:
break
disks = [list(map(int, input().split(" "))) for _ in range(n)]
overlaps = []
for i in range(n):
res = []
for k in range(n):
a = disks[i]
b = disks[k]
res.append(xx(a[0] - b[0]) + xx(a[1] - b[1]) < xx(a[2] + b[2]))
overlaps.append(res)
# print(overlaps)
print(search(disks, overlaps, list(range(n))))
| _And Then, How Many Are There?_
To Mr. Solitarius, who is a famous solo play game creator, a new idea occurs
like every day. His new game requires discs of various colors and sizes.
To start with, all the discs are randomly scattered around the center of a
table. During the play, you can remove a pair of discs of the same color if
neither of them has any discs on top of it. Note that a disc is not considered
to be on top of another when they are externally tangent to each other.

Figure D-1: Seven discs on the table
For example, in Figure D-1, you can only remove the two black discs first and
then their removal makes it possible to remove the two white ones. In
contrast, gray ones never become removable.
You are requested to write a computer program that, for given colors, sizes,
and initial placings of discs, calculates the maximum number of discs that can
be removed. | [{"input": "0 0 50 1\n 0 0 50 2\n 100 0 50 1\n 0 0 100 2\n 7\n 12 40 8 1\n 10 40 10 2\n 30 40 10 2\n 10 10 10 1\n 20 10 9 3\n 30 10 8 3\n 40 10 7 3\n 2\n 0 0 100 1\n 100 32 5 1\n 0", "output": "4\n 0"}] |
Print the maximum possible radius of the circles. The absolute error or the
relative error must be at most 10^{-9}.
* * * | s422190226 | Accepted | p03879 | The input is given from Standard Input in the following format:
x_1 y_1
x_2 y_2
x_3 y_3 | import numpy as np
P = np.array([list(map(int, input().split())) for _ in [0] * 3], dtype=float)
def f(r):
R = 0 + P
for i in range(3):
c = r / (1 - e[i].dot(e[i - 1]) ** 2) ** 0.5
R[i] += c * (e[i] - e[i - 1])
return R
def g(p):
r = 0
n = np.linalg.norm
for i in range(3):
r = max(r, n(p[i] - p[i - 1]))
return r
def h(r):
return g(f(r)) < 2 * r
def binary_search_float(l, r, func, d):
if func(l):
return l
if not func(r):
return r
while (r - l) >= d:
i = (l + r) / 2
if func(i):
r = i
else:
l = i
return l
e = -P
for i in range(3):
e[i] += P[(i + 1) % 3]
l = np.linalg.norm(e, axis=1)
L = np.sum(l)
S2 = np.abs(e[0, 0] * e[-1, 1] - e[-1, 0] * e[0, 1])
M = S2 / L
e = e / (l * np.ones((2, 3))).T
print(binary_search_float(0, M, h, 1e-10))
| Statement
Snuke received a triangle as a birthday present. The coordinates of the three
vertices were (x_1, y_1), (x_2, y_2), and (x_3, y_3).
He wants to draw two circles with the same radius inside the triangle such
that the two circles do not overlap (but they may touch). Compute the maximum
possible radius of the circles. | [{"input": "0 0\n 1 1\n 2 0", "output": "0.292893218813\n \n\n* * *"}, {"input": "3 1\n 1 5\n 4 9", "output": "0.889055514217"}] |
Print the maximum possible radius of the circles. The absolute error or the
relative error must be at most 10^{-9}.
* * * | s606202723 | Accepted | p03879 | The input is given from Standard Input in the following format:
x_1 y_1
x_2 y_2
x_3 y_3 | a1, a2 = map(int, input().split())
b1, b2 = map(int, input().split())
c1, c2 = map(int, input().split())
C = ((a1 - b1) ** 2 + (a2 - b2) ** 2) ** (1 / 2)
A = ((b1 - c1) ** 2 + (b2 - c2) ** 2) ** (1 / 2)
B = ((c1 - a1) ** 2 + (c2 - a2) ** 2) ** (1 / 2)
S = abs((b1 - a1) * (c2 - a2) - (b2 - a2) * (c1 - a1))
r1 = B * S / (B * (A + B + C) + 2 * S)
r2 = C * S / (C * (A + B + C) + 2 * S)
r3 = A * S / (A * (A + B + C) + 2 * S)
print(max(r1, r2, r3))
| Statement
Snuke received a triangle as a birthday present. The coordinates of the three
vertices were (x_1, y_1), (x_2, y_2), and (x_3, y_3).
He wants to draw two circles with the same radius inside the triangle such
that the two circles do not overlap (but they may touch). Compute the maximum
possible radius of the circles. | [{"input": "0 0\n 1 1\n 2 0", "output": "0.292893218813\n \n\n* * *"}, {"input": "3 1\n 1 5\n 4 9", "output": "0.889055514217"}] |
Print the maximum possible radius of the circles. The absolute error or the
relative error must be at most 10^{-9}.
* * * | s234690364 | Accepted | p03879 | The input is given from Standard Input in the following format:
x_1 y_1
x_2 y_2
x_3 y_3 | x1, y1 = map(int, input().split())
x2, y2 = map(int, input().split())
x3, y3 = map(int, input().split())
d1 = ((x1 - x2) ** 2 + (y1 - y2) ** 2) ** 0.5
d2 = ((x2 - x3) ** 2 + (y2 - y3) ** 2) ** 0.5
d3 = ((x3 - x1) ** 2 + (y3 - y1) ** 2) ** 0.5
D = max(d1, d2, d3)
s = (d1 + d2 + d3) / 2
S = (s * (s - d1) * (s - d2) * (s - d3)) ** 0.5
R = (2 * S) / (d1 + d2 + d3)
ok, ng = 0, 10000
eps = 1e-9
while abs(ok - ng) > eps:
r = (ok + ng) / 2
if 2 * r <= D * ((R - r) / R):
ok = r
else:
ng = r
print(ok)
| Statement
Snuke received a triangle as a birthday present. The coordinates of the three
vertices were (x_1, y_1), (x_2, y_2), and (x_3, y_3).
He wants to draw two circles with the same radius inside the triangle such
that the two circles do not overlap (but they may touch). Compute the maximum
possible radius of the circles. | [{"input": "0 0\n 1 1\n 2 0", "output": "0.292893218813\n \n\n* * *"}, {"input": "3 1\n 1 5\n 4 9", "output": "0.889055514217"}] |
Print the maximum possible radius of the circles. The absolute error or the
relative error must be at most 10^{-9}.
* * * | s080980909 | Accepted | p03879 | The input is given from Standard Input in the following format:
x_1 y_1
x_2 y_2
x_3 y_3 | from math import hypot
x1, y1, x2, y2, x3, y3 = map(int, open(0).read().split())
a = hypot(x1 - x2, y1 - y2)
b = hypot(x2 - x3, y2 - y3)
c = hypot(x3 - x1, y3 - y1)
R = abs((x2 - x1) * (y3 - y1) - (x3 - x1) * (y2 - y1)) / (a + b + c)
m = max(a, b, c)
r = m / (2 + m / R)
print("{:.12f}".format(r))
| Statement
Snuke received a triangle as a birthday present. The coordinates of the three
vertices were (x_1, y_1), (x_2, y_2), and (x_3, y_3).
He wants to draw two circles with the same radius inside the triangle such
that the two circles do not overlap (but they may touch). Compute the maximum
possible radius of the circles. | [{"input": "0 0\n 1 1\n 2 0", "output": "0.292893218813\n \n\n* * *"}, {"input": "3 1\n 1 5\n 4 9", "output": "0.889055514217"}] |
Print the maximum possible radius of the circles. The absolute error or the
relative error must be at most 10^{-9}.
* * * | s363329554 | Wrong Answer | p03879 | The input is given from Standard Input in the following format:
x_1 y_1
x_2 y_2
x_3 y_3 | import math
xy = []
for i in range(3):
xy.append([int(item) for item in input().split()])
xy.append(xy[0])
dist = []
for i in range(3):
distance = math.sqrt(
(xy[i][0] - xy[i + 1][0]) ** 2.0 + (xy[i][1] - xy[i + 1][1]) ** 2.0
)
dist.append([distance, i, (i + 1) % 3, (i + 2) % 3])
dist.sort(reverse=True)
def get_vector(a, b):
v = [a[0] - b[0], a[1] - b[1]]
return v
def norm(a):
n = math.sqrt(a[0] * a[0] + a[1] * a[1])
return n
a = get_vector(xy[dist[0][-1]], xy[dist[0][-2]])
b = get_vector(xy[dist[0][-3]], xy[dist[0][-2]])
c = get_vector(xy[dist[0][-1]], xy[dist[0][-3]])
d = get_vector(xy[dist[0][-2]], xy[dist[0][-3]])
bc = dist[0][0]
ctheta = (a[0] * b[0] + a[1] * b[1]) / (norm(a) * norm(b))
cphi = (c[0] * d[0] + c[1] * d[1]) / (norm(c) * norm(d))
htheta = (math.pi - math.acos(ctheta)) / 2.0
hphi = (math.pi - math.acos(ctheta)) / 2.0
r = bc / (math.tan(htheta) + math.tan(hphi) + 2)
print(r)
| Statement
Snuke received a triangle as a birthday present. The coordinates of the three
vertices were (x_1, y_1), (x_2, y_2), and (x_3, y_3).
He wants to draw two circles with the same radius inside the triangle such
that the two circles do not overlap (but they may touch). Compute the maximum
possible radius of the circles. | [{"input": "0 0\n 1 1\n 2 0", "output": "0.292893218813\n \n\n* * *"}, {"input": "3 1\n 1 5\n 4 9", "output": "0.889055514217"}] |
For each data set, output the total sales quantity in one line. | s164691992 | Wrong Answer | p00613 | Input file contains several data sets. A single data set has following format:
_K_
_c_ 1 _c_ 2 ... _c_ _K_ ×(_K_ -1)/2
_K_ is an integer that denotes how many kinds of cakes are sold. _c i_ is an
integer that denotes a number written on the card.
The end of input is denoted by a case where _K_ = 0. You should output nothing
for this case. | while True:
K = int(input())
if K == 0:
break
else:
po = [int(i) for i in input().split()]
print(sum(po) / (K - 1))
| I: A Piece of Cake
In the city, there are two pastry shops. One shop was very popular because its
cakes are pretty tasty. However, there was a man who is displeased at the
shop. He was an owner of another shop. Although cause of his shop's
unpopularity is incredibly awful taste of its cakes, he never improved it. He
was just growing hate, ill, envy, and jealousy.
Finally, he decided to vandalize the rival.
His vandalize is to mess up sales record of cakes. The rival shop sells _K_
kinds of cakes and sales quantity is recorded for each kind. He calculates sum
of sales quantities for all pairs of cakes. Getting _K_(_K_ -1)/2 numbers,
then he rearranges them randomly, and replace an original sales record with
them.
An owner of the rival shop is bothered. Could you write, at least, a program
that finds total sales quantity of all cakes for the pitiful owner? | [{"input": "2\n 3\n 5 4 3\n 0", "output": "6"}] |
If Raccoon can win without using the same move twice or more, print `Yes`;
otherwise, print `No`.
* * * | s415080563 | Accepted | p02784 | Input is given from Standard Input in the following format:
H N
A_1 A_2 ... A_N | H, N = [int(i) for i in input().split()]
As = [int(i) for i in input().split()]
print("Yes" if H <= sum(As) else "No")
| Statement
Raccoon is fighting with a monster.
The _health_ of the monster is H.
Raccoon can use N kinds of special moves. Using the i-th move decreases the
monster's health by A_i. There is no other way to decrease the monster's
health.
Raccoon wins when the monster's health becomes 0 or below.
If Raccoon can win without using the same move twice or more, print `Yes`;
otherwise, print `No`. | [{"input": "10 3\n 4 5 6", "output": "Yes\n \n\nThe monster's health will become 0 or below after, for example, using the\nsecond and third moves.\n\n* * *"}, {"input": "20 3\n 4 5 6", "output": "No\n \n\n* * *"}, {"input": "210 5\n 31 41 59 26 53", "output": "Yes\n \n\n* * *"}, {"input": "211 5\n 31 41 59 26 53", "output": "No"}] |
If Raccoon can win without using the same move twice or more, print `Yes`;
otherwise, print `No`.
* * * | s700049457 | Wrong Answer | p02784 | Input is given from Standard Input in the following format:
H N
A_1 A_2 ... A_N | h, a = map(int, input().split())
s = sum(map(int, input().split()))
print("Yes" if s <= h else "No")
| Statement
Raccoon is fighting with a monster.
The _health_ of the monster is H.
Raccoon can use N kinds of special moves. Using the i-th move decreases the
monster's health by A_i. There is no other way to decrease the monster's
health.
Raccoon wins when the monster's health becomes 0 or below.
If Raccoon can win without using the same move twice or more, print `Yes`;
otherwise, print `No`. | [{"input": "10 3\n 4 5 6", "output": "Yes\n \n\nThe monster's health will become 0 or below after, for example, using the\nsecond and third moves.\n\n* * *"}, {"input": "20 3\n 4 5 6", "output": "No\n \n\n* * *"}, {"input": "210 5\n 31 41 59 26 53", "output": "Yes\n \n\n* * *"}, {"input": "211 5\n 31 41 59 26 53", "output": "No"}] |
If Raccoon can win without using the same move twice or more, print `Yes`;
otherwise, print `No`.
* * * | s839379586 | Runtime Error | p02784 | Input is given from Standard Input in the following format:
H N
A_1 A_2 ... A_N | #!/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 = float("INF")
# solve
def solve():
h, n = II()
a = LI()
print("Yes" if h <= sum(a) else "No")
return
# main
if __name__ == "__main__":
solve()
| Statement
Raccoon is fighting with a monster.
The _health_ of the monster is H.
Raccoon can use N kinds of special moves. Using the i-th move decreases the
monster's health by A_i. There is no other way to decrease the monster's
health.
Raccoon wins when the monster's health becomes 0 or below.
If Raccoon can win without using the same move twice or more, print `Yes`;
otherwise, print `No`. | [{"input": "10 3\n 4 5 6", "output": "Yes\n \n\nThe monster's health will become 0 or below after, for example, using the\nsecond and third moves.\n\n* * *"}, {"input": "20 3\n 4 5 6", "output": "No\n \n\n* * *"}, {"input": "210 5\n 31 41 59 26 53", "output": "Yes\n \n\n* * *"}, {"input": "211 5\n 31 41 59 26 53", "output": "No"}] |
If Raccoon can win without using the same move twice or more, print `Yes`;
otherwise, print `No`.
* * * | s641807828 | Accepted | p02784 | Input is given from Standard Input in the following format:
H N
A_1 A_2 ... A_N | f = lambda: map(int, input().split())
h, _ = f()
print("YNeos"[sum(f()) < h :: 2])
| Statement
Raccoon is fighting with a monster.
The _health_ of the monster is H.
Raccoon can use N kinds of special moves. Using the i-th move decreases the
monster's health by A_i. There is no other way to decrease the monster's
health.
Raccoon wins when the monster's health becomes 0 or below.
If Raccoon can win without using the same move twice or more, print `Yes`;
otherwise, print `No`. | [{"input": "10 3\n 4 5 6", "output": "Yes\n \n\nThe monster's health will become 0 or below after, for example, using the\nsecond and third moves.\n\n* * *"}, {"input": "20 3\n 4 5 6", "output": "No\n \n\n* * *"}, {"input": "210 5\n 31 41 59 26 53", "output": "Yes\n \n\n* * *"}, {"input": "211 5\n 31 41 59 26 53", "output": "No"}] |
If Raccoon can win without using the same move twice or more, print `Yes`;
otherwise, print `No`.
* * * | s327031709 | Accepted | p02784 | Input is given from Standard Input in the following format:
H N
A_1 A_2 ... A_N | n, _ = list(map(int, input().split()))
print("YNeos"[sum(map(int, input().split())) < n :: 2])
| Statement
Raccoon is fighting with a monster.
The _health_ of the monster is H.
Raccoon can use N kinds of special moves. Using the i-th move decreases the
monster's health by A_i. There is no other way to decrease the monster's
health.
Raccoon wins when the monster's health becomes 0 or below.
If Raccoon can win without using the same move twice or more, print `Yes`;
otherwise, print `No`. | [{"input": "10 3\n 4 5 6", "output": "Yes\n \n\nThe monster's health will become 0 or below after, for example, using the\nsecond and third moves.\n\n* * *"}, {"input": "20 3\n 4 5 6", "output": "No\n \n\n* * *"}, {"input": "210 5\n 31 41 59 26 53", "output": "Yes\n \n\n* * *"}, {"input": "211 5\n 31 41 59 26 53", "output": "No"}] |
If Raccoon can win without using the same move twice or more, print `Yes`;
otherwise, print `No`.
* * * | s421214224 | Wrong Answer | p02784 | Input is given from Standard Input in the following format:
H N
A_1 A_2 ... A_N | enemy, num = map(int, input().split())
skills = list(map(int, input().split()))
print("Yes") if sum(skills) < enemy else print("No")
| Statement
Raccoon is fighting with a monster.
The _health_ of the monster is H.
Raccoon can use N kinds of special moves. Using the i-th move decreases the
monster's health by A_i. There is no other way to decrease the monster's
health.
Raccoon wins when the monster's health becomes 0 or below.
If Raccoon can win without using the same move twice or more, print `Yes`;
otherwise, print `No`. | [{"input": "10 3\n 4 5 6", "output": "Yes\n \n\nThe monster's health will become 0 or below after, for example, using the\nsecond and third moves.\n\n* * *"}, {"input": "20 3\n 4 5 6", "output": "No\n \n\n* * *"}, {"input": "210 5\n 31 41 59 26 53", "output": "Yes\n \n\n* * *"}, {"input": "211 5\n 31 41 59 26 53", "output": "No"}] |
If Raccoon can win without using the same move twice or more, print `Yes`;
otherwise, print `No`.
* * * | s527851482 | Accepted | p02784 | Input is given from Standard Input in the following format:
H N
A_1 A_2 ... A_N | H, n = map(int, input().split())
print("Yes" if H <= sum(map(int, input().split())) else "No")
| Statement
Raccoon is fighting with a monster.
The _health_ of the monster is H.
Raccoon can use N kinds of special moves. Using the i-th move decreases the
monster's health by A_i. There is no other way to decrease the monster's
health.
Raccoon wins when the monster's health becomes 0 or below.
If Raccoon can win without using the same move twice or more, print `Yes`;
otherwise, print `No`. | [{"input": "10 3\n 4 5 6", "output": "Yes\n \n\nThe monster's health will become 0 or below after, for example, using the\nsecond and third moves.\n\n* * *"}, {"input": "20 3\n 4 5 6", "output": "No\n \n\n* * *"}, {"input": "210 5\n 31 41 59 26 53", "output": "Yes\n \n\n* * *"}, {"input": "211 5\n 31 41 59 26 53", "output": "No"}] |
If Raccoon can win without using the same move twice or more, print `Yes`;
otherwise, print `No`.
* * * | s010902840 | Accepted | p02784 | Input is given from Standard Input in the following format:
H N
A_1 A_2 ... A_N | H, N = [int(x) for x in input().strip().split()]
print("YNeos"[sum([int(x) for x in input().split()]) < H :: 2])
| Statement
Raccoon is fighting with a monster.
The _health_ of the monster is H.
Raccoon can use N kinds of special moves. Using the i-th move decreases the
monster's health by A_i. There is no other way to decrease the monster's
health.
Raccoon wins when the monster's health becomes 0 or below.
If Raccoon can win without using the same move twice or more, print `Yes`;
otherwise, print `No`. | [{"input": "10 3\n 4 5 6", "output": "Yes\n \n\nThe monster's health will become 0 or below after, for example, using the\nsecond and third moves.\n\n* * *"}, {"input": "20 3\n 4 5 6", "output": "No\n \n\n* * *"}, {"input": "210 5\n 31 41 59 26 53", "output": "Yes\n \n\n* * *"}, {"input": "211 5\n 31 41 59 26 53", "output": "No"}] |
If Raccoon can win without using the same move twice or more, print `Yes`;
otherwise, print `No`.
* * * | s192743894 | Wrong Answer | p02784 | Input is given from Standard Input in the following format:
H N
A_1 A_2 ... A_N | N, K = [int(x) for x in input().split()]
n = [int(x) for x in input().split()]
print("Yes" if sum(n) > N else "No")
| Statement
Raccoon is fighting with a monster.
The _health_ of the monster is H.
Raccoon can use N kinds of special moves. Using the i-th move decreases the
monster's health by A_i. There is no other way to decrease the monster's
health.
Raccoon wins when the monster's health becomes 0 or below.
If Raccoon can win without using the same move twice or more, print `Yes`;
otherwise, print `No`. | [{"input": "10 3\n 4 5 6", "output": "Yes\n \n\nThe monster's health will become 0 or below after, for example, using the\nsecond and third moves.\n\n* * *"}, {"input": "20 3\n 4 5 6", "output": "No\n \n\n* * *"}, {"input": "210 5\n 31 41 59 26 53", "output": "Yes\n \n\n* * *"}, {"input": "211 5\n 31 41 59 26 53", "output": "No"}] |
If Raccoon can win without using the same move twice or more, print `Yes`;
otherwise, print `No`.
* * * | s360216544 | Wrong Answer | p02784 | Input is given from Standard Input in the following format:
H N
A_1 A_2 ... A_N | h, a = map(int, input().split())
count = 0
while h > 0:
h -= a
count += 1
print(count)
| Statement
Raccoon is fighting with a monster.
The _health_ of the monster is H.
Raccoon can use N kinds of special moves. Using the i-th move decreases the
monster's health by A_i. There is no other way to decrease the monster's
health.
Raccoon wins when the monster's health becomes 0 or below.
If Raccoon can win without using the same move twice or more, print `Yes`;
otherwise, print `No`. | [{"input": "10 3\n 4 5 6", "output": "Yes\n \n\nThe monster's health will become 0 or below after, for example, using the\nsecond and third moves.\n\n* * *"}, {"input": "20 3\n 4 5 6", "output": "No\n \n\n* * *"}, {"input": "210 5\n 31 41 59 26 53", "output": "Yes\n \n\n* * *"}, {"input": "211 5\n 31 41 59 26 53", "output": "No"}] |
If Raccoon can win without using the same move twice or more, print `Yes`;
otherwise, print `No`.
* * * | s214661322 | Wrong Answer | p02784 | Input is given from Standard Input in the following format:
H N
A_1 A_2 ... A_N | print("No" if int(input().split()[0]) < sum(list(map(int, input().split()))) else "Yes")
| Statement
Raccoon is fighting with a monster.
The _health_ of the monster is H.
Raccoon can use N kinds of special moves. Using the i-th move decreases the
monster's health by A_i. There is no other way to decrease the monster's
health.
Raccoon wins when the monster's health becomes 0 or below.
If Raccoon can win without using the same move twice or more, print `Yes`;
otherwise, print `No`. | [{"input": "10 3\n 4 5 6", "output": "Yes\n \n\nThe monster's health will become 0 or below after, for example, using the\nsecond and third moves.\n\n* * *"}, {"input": "20 3\n 4 5 6", "output": "No\n \n\n* * *"}, {"input": "210 5\n 31 41 59 26 53", "output": "Yes\n \n\n* * *"}, {"input": "211 5\n 31 41 59 26 53", "output": "No"}] |
If you will win, print `first`; if Lunlun will win, print `second`.
* * * | s622115184 | Accepted | p03195 | Input is given from Standard Input in the following format:
N
a_1
a_2
:
a_N | n, *a = map(int, open(0))
print("sfeicrosntd"[any(v % 2 for v in a) :: 2])
| Statement
There is an apple tree that bears apples of N colors. The N colors of these
apples are numbered 1 to N, and there are a_i apples of Color i.
You and Lunlun the dachshund alternately perform the following operation
(starting from you):
* Choose one or more apples from the tree and eat them. Here, the apples chosen at the same time must all have different colors.
The one who eats the last apple from the tree will be declared winner. If both
you and Lunlun play optimally, which will win? | [{"input": "2\n 1\n 2", "output": "first\n \n\nLet Color 1 be red, and Color 2 be blue. In this case, the tree bears one red\napple and two blue apples.\n\nYou should eat the red apple in your first turn. Lunlun is then forced to eat\none of the blue apples, and you can win by eating the other in your next turn.\n\nNote that you are also allowed to eat two apples in your first turn, one red\nand one blue (not a winning move, though).\n\n* * *"}, {"input": "3\n 100000\n 30000\n 20000", "output": "second"}] |
If you will win, print `first`; if Lunlun will win, print `second`.
* * * | s624963655 | Wrong Answer | p03195 | Input is given from Standard Input in the following format:
N
a_1
a_2
:
a_N | print("second")
| Statement
There is an apple tree that bears apples of N colors. The N colors of these
apples are numbered 1 to N, and there are a_i apples of Color i.
You and Lunlun the dachshund alternately perform the following operation
(starting from you):
* Choose one or more apples from the tree and eat them. Here, the apples chosen at the same time must all have different colors.
The one who eats the last apple from the tree will be declared winner. If both
you and Lunlun play optimally, which will win? | [{"input": "2\n 1\n 2", "output": "first\n \n\nLet Color 1 be red, and Color 2 be blue. In this case, the tree bears one red\napple and two blue apples.\n\nYou should eat the red apple in your first turn. Lunlun is then forced to eat\none of the blue apples, and you can win by eating the other in your next turn.\n\nNote that you are also allowed to eat two apples in your first turn, one red\nand one blue (not a winning move, though).\n\n* * *"}, {"input": "3\n 100000\n 30000\n 20000", "output": "second"}] |
If you will win, print `first`; if Lunlun will win, print `second`.
* * * | s721118487 | Runtime Error | p03195 | Input is given from Standard Input in the following format:
N
a_1
a_2
:
a_N | for i in range(10000000000000000000000000000000000):
input() | Statement
There is an apple tree that bears apples of N colors. The N colors of these
apples are numbered 1 to N, and there are a_i apples of Color i.
You and Lunlun the dachshund alternately perform the following operation
(starting from you):
* Choose one or more apples from the tree and eat them. Here, the apples chosen at the same time must all have different colors.
The one who eats the last apple from the tree will be declared winner. If both
you and Lunlun play optimally, which will win? | [{"input": "2\n 1\n 2", "output": "first\n \n\nLet Color 1 be red, and Color 2 be blue. In this case, the tree bears one red\napple and two blue apples.\n\nYou should eat the red apple in your first turn. Lunlun is then forced to eat\none of the blue apples, and you can win by eating the other in your next turn.\n\nNote that you are also allowed to eat two apples in your first turn, one red\nand one blue (not a winning move, though).\n\n* * *"}, {"input": "3\n 100000\n 30000\n 20000", "output": "second"}] |
If you will win, print `first`; if Lunlun will win, print `second`.
* * * | s108199947 | Runtime Error | p03195 | Input is given from Standard Input in the following format:
N
a_1
a_2
:
a_N | n = int(input())
l = []
for i in range(n):
l.append(int(input()))
if n == and sum(l)%2 != 0:
print("first")
else:
print("second")
| Statement
There is an apple tree that bears apples of N colors. The N colors of these
apples are numbered 1 to N, and there are a_i apples of Color i.
You and Lunlun the dachshund alternately perform the following operation
(starting from you):
* Choose one or more apples from the tree and eat them. Here, the apples chosen at the same time must all have different colors.
The one who eats the last apple from the tree will be declared winner. If both
you and Lunlun play optimally, which will win? | [{"input": "2\n 1\n 2", "output": "first\n \n\nLet Color 1 be red, and Color 2 be blue. In this case, the tree bears one red\napple and two blue apples.\n\nYou should eat the red apple in your first turn. Lunlun is then forced to eat\none of the blue apples, and you can win by eating the other in your next turn.\n\nNote that you are also allowed to eat two apples in your first turn, one red\nand one blue (not a winning move, though).\n\n* * *"}, {"input": "3\n 100000\n 30000\n 20000", "output": "second"}] |
If you will win, print `first`; if Lunlun will win, print `second`.
* * * | s067801054 | Runtime Error | p03195 | Input is given from Standard Input in the following format:
N
a_1
a_2
:
a_N | n=int(input())
a=[]
for i in range(n):
a.append(int(input()))
flag=True
for i in a:
if a%2==1:
flag=False
if a.count(1)==len(a):
print("first")
elif flag:
else:
print("second")
| Statement
There is an apple tree that bears apples of N colors. The N colors of these
apples are numbered 1 to N, and there are a_i apples of Color i.
You and Lunlun the dachshund alternately perform the following operation
(starting from you):
* Choose one or more apples from the tree and eat them. Here, the apples chosen at the same time must all have different colors.
The one who eats the last apple from the tree will be declared winner. If both
you and Lunlun play optimally, which will win? | [{"input": "2\n 1\n 2", "output": "first\n \n\nLet Color 1 be red, and Color 2 be blue. In this case, the tree bears one red\napple and two blue apples.\n\nYou should eat the red apple in your first turn. Lunlun is then forced to eat\none of the blue apples, and you can win by eating the other in your next turn.\n\nNote that you are also allowed to eat two apples in your first turn, one red\nand one blue (not a winning move, though).\n\n* * *"}, {"input": "3\n 100000\n 30000\n 20000", "output": "second"}] |
If you will win, print `first`; if Lunlun will win, print `second`.
* * * | s442478545 | Accepted | p03195 | Input is given from Standard Input in the following format:
N
a_1
a_2
:
a_N | print(
"second" if all([int(input()) % 2 == 0 for _ in range(int(input()))]) else "first"
)
| Statement
There is an apple tree that bears apples of N colors. The N colors of these
apples are numbered 1 to N, and there are a_i apples of Color i.
You and Lunlun the dachshund alternately perform the following operation
(starting from you):
* Choose one or more apples from the tree and eat them. Here, the apples chosen at the same time must all have different colors.
The one who eats the last apple from the tree will be declared winner. If both
you and Lunlun play optimally, which will win? | [{"input": "2\n 1\n 2", "output": "first\n \n\nLet Color 1 be red, and Color 2 be blue. In this case, the tree bears one red\napple and two blue apples.\n\nYou should eat the red apple in your first turn. Lunlun is then forced to eat\none of the blue apples, and you can win by eating the other in your next turn.\n\nNote that you are also allowed to eat two apples in your first turn, one red\nand one blue (not a winning move, though).\n\n* * *"}, {"input": "3\n 100000\n 30000\n 20000", "output": "second"}] |
Print the minimum number of people who have to change their directions.
* * * | s653885574 | Runtime Error | p03341 | Input is given from Standard Input in the following format:
N
S | N = input("N: ")
S = input("S: ")
point_list = []
for i in range(0, len(S)):
p = 0
if i >0:
for c in S[:i]:
if c == 'W':
p += 1
if i + 1 < len(S):
for d in S[i+1:]:
if d == 'E':
p += 1
point_list.append(count_point(S, i))
print(min(point_list)) | Statement
There are N people standing in a row from west to east. Each person is facing
east or west. The directions of the people is given as a string S of length N.
The i-th person from the west is facing east if S_i = `E`, and west if S_i =
`W`.
You will appoint one of the N people as the leader, then command the rest of
them to face in the direction of the leader. Here, we do not care which
direction the leader is facing.
The people in the row hate to change their directions, so you would like to
select the leader so that the number of people who have to change their
directions is minimized. Find the minimum number of people who have to change
their directions. | [{"input": "5\n WEEWW", "output": "1\n \n\nAssume that we appoint the third person from the west as the leader. Then, the\nfirst person from the west needs to face east and has to turn around. The\nother people do not need to change their directions, so the number of people\nwho have to change their directions is 1 in this case. It is not possible to\nhave 0 people who have to change their directions, so the answer is 1.\n\n* * *"}, {"input": "12\n WEWEWEEEWWWE", "output": "4\n \n\n* * *"}, {"input": "8\n WWWWWEEE", "output": "3"}] |
Print the minimum number of people who have to change their directions.
* * * | s000796545 | Wrong Answer | p03341 | Input is given from Standard Input in the following format:
N
S | #!/usr/bin/env python
E = "E" # ->
W = "W" # <-
class Line:
def __init__(self, people):
self.people = people
def get_change_count(self, leader):
leader_i = leader - 1
count = 0
for i in range(len(self.people)):
if i == leader_i:
continue
elif i < leader_i:
if self.people[i] == W:
count += 1
elif leader_i < i:
if self.people[i] == E:
count += 1
else:
assert ()
return count
def main():
people_count = int(input().rstrip())
people = input().rstrip()
line = Line(people)
min_leader_no = None
min_change_count = float("inf")
for i in range(1, people_count + 1):
change_count = line.get_change_count(i)
if change_count < min_change_count:
min_leader_no = i
min_change_count = change_count
if min_leader_no <= 1:
break
print(min_change_count)
main()
| Statement
There are N people standing in a row from west to east. Each person is facing
east or west. The directions of the people is given as a string S of length N.
The i-th person from the west is facing east if S_i = `E`, and west if S_i =
`W`.
You will appoint one of the N people as the leader, then command the rest of
them to face in the direction of the leader. Here, we do not care which
direction the leader is facing.
The people in the row hate to change their directions, so you would like to
select the leader so that the number of people who have to change their
directions is minimized. Find the minimum number of people who have to change
their directions. | [{"input": "5\n WEEWW", "output": "1\n \n\nAssume that we appoint the third person from the west as the leader. Then, the\nfirst person from the west needs to face east and has to turn around. The\nother people do not need to change their directions, so the number of people\nwho have to change their directions is 1 in this case. It is not possible to\nhave 0 people who have to change their directions, so the answer is 1.\n\n* * *"}, {"input": "12\n WEWEWEEEWWWE", "output": "4\n \n\n* * *"}, {"input": "8\n WWWWWEEE", "output": "3"}] |
Print the minimum number of people who have to change their directions.
* * * | s494803645 | Runtime Error | p03341 | Input is given from Standard Input in the following format:
N
S | N = int(input())
S = input()
stock = []
#INF = 10**9
for i in range(1,len(S)-1):
if (S[i-1] == "E") & (S[i+1] == "W"): stock.append(i)
dic = {k:0 for k in stock}
dic[0]= S.count("E")
dic[len(S)-1] = S.count("W")
for i in stock:
for j in range(i-1,0,-1):
if j < 0: break
else:
if S[j] == "E" : dic[i] += 1
else: break
for j in range(i+1, len(S)):
if j > len(S)-1: break
else:
if S[j] == "W" : dic[i] += 1
else: break
max_k = max(dic, key=dic.get)
count = 0
for i in range(0,max_k):
if S[i] == "W": count += 1
for i in range(max_k+1, len(S)):
if S[i] == "E": count += 1
print(count) | Statement
There are N people standing in a row from west to east. Each person is facing
east or west. The directions of the people is given as a string S of length N.
The i-th person from the west is facing east if S_i = `E`, and west if S_i =
`W`.
You will appoint one of the N people as the leader, then command the rest of
them to face in the direction of the leader. Here, we do not care which
direction the leader is facing.
The people in the row hate to change their directions, so you would like to
select the leader so that the number of people who have to change their
directions is minimized. Find the minimum number of people who have to change
their directions. | [{"input": "5\n WEEWW", "output": "1\n \n\nAssume that we appoint the third person from the west as the leader. Then, the\nfirst person from the west needs to face east and has to turn around. The\nother people do not need to change their directions, so the number of people\nwho have to change their directions is 1 in this case. It is not possible to\nhave 0 people who have to change their directions, so the answer is 1.\n\n* * *"}, {"input": "12\n WEWEWEEEWWWE", "output": "4\n \n\n* * *"}, {"input": "8\n WWWWWEEE", "output": "3"}] |
Print the minimum number of people who have to change their directions.
* * * | s170005838 | Runtime Error | p03341 | Input is given from Standard Input in the following format:
N
S | ARC098 - Attention
Shoji Taisaku(FJK 庄司 大作)
2020/03/11 (水) 11:33
受信トレイ; 送信済みトレイ
宛先:
Shoji Taisaku(FJK 庄司 大作);
N=int(input())
S=input()
left=[0]*N
right=[0]*N
to_change=[0]*N
if S[0]=="E":
right[0]=1
else:
left[0]=1
for i in range(1,N):
if S[i]=="W":
left[i] = left[i-1]+1
right[i] = right[i-1]
if S[i]=="E":
right[i] = right[i-1]+1
left[i]= left[i-1]
to_change[0]=right[-1]-right[0]
to_change[-1]=left[-2]
for j in range(1,N-1):
to_change[j]=(right[-1]-right[j])+(left[j-1])
#print(to_change)
print(min(to_change)) | Statement
There are N people standing in a row from west to east. Each person is facing
east or west. The directions of the people is given as a string S of length N.
The i-th person from the west is facing east if S_i = `E`, and west if S_i =
`W`.
You will appoint one of the N people as the leader, then command the rest of
them to face in the direction of the leader. Here, we do not care which
direction the leader is facing.
The people in the row hate to change their directions, so you would like to
select the leader so that the number of people who have to change their
directions is minimized. Find the minimum number of people who have to change
their directions. | [{"input": "5\n WEEWW", "output": "1\n \n\nAssume that we appoint the third person from the west as the leader. Then, the\nfirst person from the west needs to face east and has to turn around. The\nother people do not need to change their directions, so the number of people\nwho have to change their directions is 1 in this case. It is not possible to\nhave 0 people who have to change their directions, so the answer is 1.\n\n* * *"}, {"input": "12\n WEWEWEEEWWWE", "output": "4\n \n\n* * *"}, {"input": "8\n WWWWWEEE", "output": "3"}] |
Print the minimum number of people who have to change their directions.
* * * | s771043169 | Runtime Error | p03341 | Input is given from Standard Input in the following format:
N
S | #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<ll> vll;
typedef pair<ll, ll> pll;
typedef vector<pll> vpll;
typedef string str;
const long long INF = INT64_MAX;
#define REP(i, n) for(ll i=0;i<n;i++)
#define ASC(v) sort((v).begin(), (v).end())
#define DESC(v) sort((v).rbegin(), (v).rend())
#define INV(v) reverse((v).rbegin(), (v).rend())
#define FOLDL(src, dst, lambda) partial_sum((src).begin(), (src).end(), (dst).begin(), lambda)
#define FOLDR(src, dst, lambda) INV(src);partial_sum((src).begin(), (src).end(), (dst).begin(), lambda);INV(dst)
#define CUMSUML(src, dst) FOLDL(src, dst, [](auto a, auto b) {return a+b;})
#define CUMSUMR(src, dst) FOLDR(src, dst, [](auto a, auto b) {return a+b;})
#define DESC(v) sort((v).rbegin(), (v).rend())
#define ERASE(v, i) v.erase(v.begin() + i)
#define UNIQ(v) ASC(v);erase(unique(v.begin(), v.end()), v.end())
#define FIO ios_base::sync_with_stdio(false);cin.tie(NULL);
void solve() {
ll N;
str S;
cin >> N >> S;
vll D(N) ,E(N), Es(N), W(N), Ws(N);
for(int i=0;i<N;i++) (S[i] == 'E' ? E[i] : W[i]) = 1;
CUMSUML(W, Ws);
CUMSUMR(E, Es);
ll ans = INF;
for(int i = 0; i < N; i++) {
ll w = (i == 0 ? 0 : Ws[i - 1]);
ll e = (i == N - 1 ? 0 : Es[i + 1]);
ans = min(ans, e+w);
}
cout << ans << endl;
}
int main() {
FIO;
solve();
return 0;
} | Statement
There are N people standing in a row from west to east. Each person is facing
east or west. The directions of the people is given as a string S of length N.
The i-th person from the west is facing east if S_i = `E`, and west if S_i =
`W`.
You will appoint one of the N people as the leader, then command the rest of
them to face in the direction of the leader. Here, we do not care which
direction the leader is facing.
The people in the row hate to change their directions, so you would like to
select the leader so that the number of people who have to change their
directions is minimized. Find the minimum number of people who have to change
their directions. | [{"input": "5\n WEEWW", "output": "1\n \n\nAssume that we appoint the third person from the west as the leader. Then, the\nfirst person from the west needs to face east and has to turn around. The\nother people do not need to change their directions, so the number of people\nwho have to change their directions is 1 in this case. It is not possible to\nhave 0 people who have to change their directions, so the answer is 1.\n\n* * *"}, {"input": "12\n WEWEWEEEWWWE", "output": "4\n \n\n* * *"}, {"input": "8\n WWWWWEEE", "output": "3"}] |
Print the minimum number of people who have to change their directions.
* * * | s582362247 | Runtime Error | p03341 | Input is given from Standard Input in the following format:
N
S | n=int(input())
s=input()
k=n
for i in range(n):
a=s[:i]
b=s[i+1:]
l=a.count("W")+b.count("E")
if l<k:
k=l
print(k | Statement
There are N people standing in a row from west to east. Each person is facing
east or west. The directions of the people is given as a string S of length N.
The i-th person from the west is facing east if S_i = `E`, and west if S_i =
`W`.
You will appoint one of the N people as the leader, then command the rest of
them to face in the direction of the leader. Here, we do not care which
direction the leader is facing.
The people in the row hate to change their directions, so you would like to
select the leader so that the number of people who have to change their
directions is minimized. Find the minimum number of people who have to change
their directions. | [{"input": "5\n WEEWW", "output": "1\n \n\nAssume that we appoint the third person from the west as the leader. Then, the\nfirst person from the west needs to face east and has to turn around. The\nother people do not need to change their directions, so the number of people\nwho have to change their directions is 1 in this case. It is not possible to\nhave 0 people who have to change their directions, so the answer is 1.\n\n* * *"}, {"input": "12\n WEWEWEEEWWWE", "output": "4\n \n\n* * *"}, {"input": "8\n WWWWWEEE", "output": "3"}] |
Print the minimum number of people who have to change their directions.
* * * | s004256280 | Runtime Error | p03341 | Input is given from Standard Input in the following format:
N
S | N = int(input())
S = input()
for i in range(N):
t_prev = 0
t = 0
for j in range(N):
if (j < i and S[j] == ‘W’) or (i < j and S[j] == ‘E’):
t += 1
t_prev = min(t_prev, t)
print(t) | Statement
There are N people standing in a row from west to east. Each person is facing
east or west. The directions of the people is given as a string S of length N.
The i-th person from the west is facing east if S_i = `E`, and west if S_i =
`W`.
You will appoint one of the N people as the leader, then command the rest of
them to face in the direction of the leader. Here, we do not care which
direction the leader is facing.
The people in the row hate to change their directions, so you would like to
select the leader so that the number of people who have to change their
directions is minimized. Find the minimum number of people who have to change
their directions. | [{"input": "5\n WEEWW", "output": "1\n \n\nAssume that we appoint the third person from the west as the leader. Then, the\nfirst person from the west needs to face east and has to turn around. The\nother people do not need to change their directions, so the number of people\nwho have to change their directions is 1 in this case. It is not possible to\nhave 0 people who have to change their directions, so the answer is 1.\n\n* * *"}, {"input": "12\n WEWEWEEEWWWE", "output": "4\n \n\n* * *"}, {"input": "8\n WWWWWEEE", "output": "3"}] |
Print the minimum number of people who have to change their directions.
* * * | s689024349 | Runtime Error | p03341 | Input is given from Standard Input in the following format:
N
S | def foo (s):
ans = 0
count = 0
for i in s:
if i == 'W':
count += 1
elif count :
count -= 1
ans += 1
else:
pass
return ans
n = input()
s = input()
print(foo(s)) | Statement
There are N people standing in a row from west to east. Each person is facing
east or west. The directions of the people is given as a string S of length N.
The i-th person from the west is facing east if S_i = `E`, and west if S_i =
`W`.
You will appoint one of the N people as the leader, then command the rest of
them to face in the direction of the leader. Here, we do not care which
direction the leader is facing.
The people in the row hate to change their directions, so you would like to
select the leader so that the number of people who have to change their
directions is minimized. Find the minimum number of people who have to change
their directions. | [{"input": "5\n WEEWW", "output": "1\n \n\nAssume that we appoint the third person from the west as the leader. Then, the\nfirst person from the west needs to face east and has to turn around. The\nother people do not need to change their directions, so the number of people\nwho have to change their directions is 1 in this case. It is not possible to\nhave 0 people who have to change their directions, so the answer is 1.\n\n* * *"}, {"input": "12\n WEWEWEEEWWWE", "output": "4\n \n\n* * *"}, {"input": "8\n WWWWWEEE", "output": "3"}] |
Print the minimum number of people who have to change their directions.
* * * | s100985310 | Runtime Error | p03341 | Input is given from Standard Input in the following format:
N
S | N=int(input())
S=input()
DP=[0]*N
l=0
for i,x in enumerate(S):
DP[i]+=l
if S[i]=="W":
l+=1
r=0
for j,y in enumerate(S[::-1]):
DP[N-1-j]+=r
if S[N-1-j]=="E":
r+=1
print(min(DP))
| Statement
There are N people standing in a row from west to east. Each person is facing
east or west. The directions of the people is given as a string S of length N.
The i-th person from the west is facing east if S_i = `E`, and west if S_i =
`W`.
You will appoint one of the N people as the leader, then command the rest of
them to face in the direction of the leader. Here, we do not care which
direction the leader is facing.
The people in the row hate to change their directions, so you would like to
select the leader so that the number of people who have to change their
directions is minimized. Find the minimum number of people who have to change
their directions. | [{"input": "5\n WEEWW", "output": "1\n \n\nAssume that we appoint the third person from the west as the leader. Then, the\nfirst person from the west needs to face east and has to turn around. The\nother people do not need to change their directions, so the number of people\nwho have to change their directions is 1 in this case. It is not possible to\nhave 0 people who have to change their directions, so the answer is 1.\n\n* * *"}, {"input": "12\n WEWEWEEEWWWE", "output": "4\n \n\n* * *"}, {"input": "8\n WWWWWEEE", "output": "3"}] |
Print the minimum number of people who have to change their directions.
* * * | s014223413 | Runtime Error | p03341 | Input is given from Standard Input in the following format:
N
S | 8
WWWWWEEE
| Statement
There are N people standing in a row from west to east. Each person is facing
east or west. The directions of the people is given as a string S of length N.
The i-th person from the west is facing east if S_i = `E`, and west if S_i =
`W`.
You will appoint one of the N people as the leader, then command the rest of
them to face in the direction of the leader. Here, we do not care which
direction the leader is facing.
The people in the row hate to change their directions, so you would like to
select the leader so that the number of people who have to change their
directions is minimized. Find the minimum number of people who have to change
their directions. | [{"input": "5\n WEEWW", "output": "1\n \n\nAssume that we appoint the third person from the west as the leader. Then, the\nfirst person from the west needs to face east and has to turn around. The\nother people do not need to change their directions, so the number of people\nwho have to change their directions is 1 in this case. It is not possible to\nhave 0 people who have to change their directions, so the answer is 1.\n\n* * *"}, {"input": "12\n WEWEWEEEWWWE", "output": "4\n \n\n* * *"}, {"input": "8\n WWWWWEEE", "output": "3"}] |
Print the minimum number of people who have to change their directions.
* * * | s113855383 | Runtime Error | p03341 | Input is given from Standard Input in the following format:
N
S | n = input()
a = input()
S = [a[i:i+1] for i in range(len(a))]
left = []
right = []
answer = n
for (i, x) in enumerate(S):
a = 0
left = S[:i]
right = S[i+1:]
a += left.count("W")
a += right.count("E")
if answer > a : answer = a
print(answer)
| Statement
There are N people standing in a row from west to east. Each person is facing
east or west. The directions of the people is given as a string S of length N.
The i-th person from the west is facing east if S_i = `E`, and west if S_i =
`W`.
You will appoint one of the N people as the leader, then command the rest of
them to face in the direction of the leader. Here, we do not care which
direction the leader is facing.
The people in the row hate to change their directions, so you would like to
select the leader so that the number of people who have to change their
directions is minimized. Find the minimum number of people who have to change
their directions. | [{"input": "5\n WEEWW", "output": "1\n \n\nAssume that we appoint the third person from the west as the leader. Then, the\nfirst person from the west needs to face east and has to turn around. The\nother people do not need to change their directions, so the number of people\nwho have to change their directions is 1 in this case. It is not possible to\nhave 0 people who have to change their directions, so the answer is 1.\n\n* * *"}, {"input": "12\n WEWEWEEEWWWE", "output": "4\n \n\n* * *"}, {"input": "8\n WWWWWEEE", "output": "3"}] |
Print the minimum number of people who have to change their directions.
* * * | s077055774 | Runtime Error | p03341 | Input is given from Standard Input in the following format:
N
S | def foo (s):
ans = 0
count = 0
for i in s:
if i == 'W':
count += 1
elif count :
count -= 1
ans += 1
else:
pass
return ans
n = input()
s = input()
print(foo(s)) | Statement
There are N people standing in a row from west to east. Each person is facing
east or west. The directions of the people is given as a string S of length N.
The i-th person from the west is facing east if S_i = `E`, and west if S_i =
`W`.
You will appoint one of the N people as the leader, then command the rest of
them to face in the direction of the leader. Here, we do not care which
direction the leader is facing.
The people in the row hate to change their directions, so you would like to
select the leader so that the number of people who have to change their
directions is minimized. Find the minimum number of people who have to change
their directions. | [{"input": "5\n WEEWW", "output": "1\n \n\nAssume that we appoint the third person from the west as the leader. Then, the\nfirst person from the west needs to face east and has to turn around. The\nother people do not need to change their directions, so the number of people\nwho have to change their directions is 1 in this case. It is not possible to\nhave 0 people who have to change their directions, so the answer is 1.\n\n* * *"}, {"input": "12\n WEWEWEEEWWWE", "output": "4\n \n\n* * *"}, {"input": "8\n WWWWWEEE", "output": "3"}] |
Print the minimum number of people who have to change their directions.
* * * | s220191074 | Runtime Error | p03341 | Input is given from Standard Input in the following format:
N
S | def foo (s):
ans = 0
count = 0
for i in s:
if i == 'W':
count += 1
elif count :
count -= 1
ans += 1
else:
pass
return ans
n = input()
s = input()
print(foo(s)) | Statement
There are N people standing in a row from west to east. Each person is facing
east or west. The directions of the people is given as a string S of length N.
The i-th person from the west is facing east if S_i = `E`, and west if S_i =
`W`.
You will appoint one of the N people as the leader, then command the rest of
them to face in the direction of the leader. Here, we do not care which
direction the leader is facing.
The people in the row hate to change their directions, so you would like to
select the leader so that the number of people who have to change their
directions is minimized. Find the minimum number of people who have to change
their directions. | [{"input": "5\n WEEWW", "output": "1\n \n\nAssume that we appoint the third person from the west as the leader. Then, the\nfirst person from the west needs to face east and has to turn around. The\nother people do not need to change their directions, so the number of people\nwho have to change their directions is 1 in this case. It is not possible to\nhave 0 people who have to change their directions, so the answer is 1.\n\n* * *"}, {"input": "12\n WEWEWEEEWWWE", "output": "4\n \n\n* * *"}, {"input": "8\n WWWWWEEE", "output": "3"}] |
Print the minimum number of people who have to change their directions.
* * * | s127887707 | Runtime Error | p03341 | Input is given from Standard Input in the following format:
N
S | def foo (s):
ans = 0
count = 0
for i in s:
if (not count) and (i == 'E'):pass
elif not count: count += 1
elif i == 'E': count -= 1; ans += 1
else: count += 1
return ans
n = int(input())
s = input()
print(foo(s)) | Statement
There are N people standing in a row from west to east. Each person is facing
east or west. The directions of the people is given as a string S of length N.
The i-th person from the west is facing east if S_i = `E`, and west if S_i =
`W`.
You will appoint one of the N people as the leader, then command the rest of
them to face in the direction of the leader. Here, we do not care which
direction the leader is facing.
The people in the row hate to change their directions, so you would like to
select the leader so that the number of people who have to change their
directions is minimized. Find the minimum number of people who have to change
their directions. | [{"input": "5\n WEEWW", "output": "1\n \n\nAssume that we appoint the third person from the west as the leader. Then, the\nfirst person from the west needs to face east and has to turn around. The\nother people do not need to change their directions, so the number of people\nwho have to change their directions is 1 in this case. It is not possible to\nhave 0 people who have to change their directions, so the answer is 1.\n\n* * *"}, {"input": "12\n WEWEWEEEWWWE", "output": "4\n \n\n* * *"}, {"input": "8\n WWWWWEEE", "output": "3"}] |
Print the minimum number of people who have to change their directions.
* * * | s826180609 | Runtime Error | p03341 | Input is given from Standard Input in the following format:
N
S | N = int(input())
S = input()
W = S.count('W')
E = S.count('E')
counter = len(S)
cost = E
for i in range(len(S)):
if S[i] = 'E':
cost -= 1
if cost < counter:
counter = cost
else:
cost +=1
print(counter) | Statement
There are N people standing in a row from west to east. Each person is facing
east or west. The directions of the people is given as a string S of length N.
The i-th person from the west is facing east if S_i = `E`, and west if S_i =
`W`.
You will appoint one of the N people as the leader, then command the rest of
them to face in the direction of the leader. Here, we do not care which
direction the leader is facing.
The people in the row hate to change their directions, so you would like to
select the leader so that the number of people who have to change their
directions is minimized. Find the minimum number of people who have to change
their directions. | [{"input": "5\n WEEWW", "output": "1\n \n\nAssume that we appoint the third person from the west as the leader. Then, the\nfirst person from the west needs to face east and has to turn around. The\nother people do not need to change their directions, so the number of people\nwho have to change their directions is 1 in this case. It is not possible to\nhave 0 people who have to change their directions, so the answer is 1.\n\n* * *"}, {"input": "12\n WEWEWEEEWWWE", "output": "4\n \n\n* * *"}, {"input": "8\n WWWWWEEE", "output": "3"}] |
Print the minimum number of people who have to change their directions.
* * * | s367143687 | Runtime Error | p03341 | Input is given from Standard Input in the following format:
N
S | from collections import Counter
n = int(input())
s = input()
c = Counter(s)
tmp = c['E'] - (1 if s[0] == 'E' else 0)
best = tmp
for i in range(1, n):
if s[i - 1] == 'W'
tmp += 1
else:
tmp -= 1
if tmp < best:
best = tmp
print(best) | Statement
There are N people standing in a row from west to east. Each person is facing
east or west. The directions of the people is given as a string S of length N.
The i-th person from the west is facing east if S_i = `E`, and west if S_i =
`W`.
You will appoint one of the N people as the leader, then command the rest of
them to face in the direction of the leader. Here, we do not care which
direction the leader is facing.
The people in the row hate to change their directions, so you would like to
select the leader so that the number of people who have to change their
directions is minimized. Find the minimum number of people who have to change
their directions. | [{"input": "5\n WEEWW", "output": "1\n \n\nAssume that we appoint the third person from the west as the leader. Then, the\nfirst person from the west needs to face east and has to turn around. The\nother people do not need to change their directions, so the number of people\nwho have to change their directions is 1 in this case. It is not possible to\nhave 0 people who have to change their directions, so the answer is 1.\n\n* * *"}, {"input": "12\n WEWEWEEEWWWE", "output": "4\n \n\n* * *"}, {"input": "8\n WWWWWEEE", "output": "3"}] |
Print the minimum number of people who have to change their directions.
* * * | s302434323 | Accepted | p03341 | Input is given from Standard Input in the following format:
N
S | from statistics import mean, median, variance, stdev
import numpy as np
import sys
import math
import fractions
import itertools
import copy
import collections
from operator import itemgetter
# 以下てんぷら
def j(q):
if q == 1:
print("You can win")
else:
print("You will lose")
exit(0)
def ct(x, y):
if x > y:
print("+")
elif x < y:
print("-")
else:
print("?")
def ip():
return int(input())
def printrow(a):
for i in range(len(a)):
print(a[i])
def combinations(n, r):
if n < r:
return 0
return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))
def permutations(n, r):
if n < r:
return 0
return math.factorial(n) // math.factorial(n - r)
n = ip() # 入力整数1つ
# a,b,c= (int(i) for i in input().split()) #入力整数横2つ以上
# a = [int(i) for i in input().split()] #入力整数配列
a = input() # 入力文字列
# a = input().split() #入力文字配列
# k = ip() #入力セット(整数改行あり)(1/2)
# a=[ip() for i in range(n)] #入力セット(整数改行あり)(2/2)
# jの変数はしようできないので注意
# 全足しにsum変数使用はsum関数使用できないので注意
# こっから本文
righte = 0
rightw = 0
leftw = 0
lefte = 0
for i in range(n):
if a[i] == "E":
righte += 1
else:
rightw += 1
s = n
for i in range(n):
if a[i] == "E":
righte -= 1
else:
rightw -= 1
s = min(s, leftw + righte)
if a[i] == "E":
lefte += 1
else:
leftw += 1
print(s)
| Statement
There are N people standing in a row from west to east. Each person is facing
east or west. The directions of the people is given as a string S of length N.
The i-th person from the west is facing east if S_i = `E`, and west if S_i =
`W`.
You will appoint one of the N people as the leader, then command the rest of
them to face in the direction of the leader. Here, we do not care which
direction the leader is facing.
The people in the row hate to change their directions, so you would like to
select the leader so that the number of people who have to change their
directions is minimized. Find the minimum number of people who have to change
their directions. | [{"input": "5\n WEEWW", "output": "1\n \n\nAssume that we appoint the third person from the west as the leader. Then, the\nfirst person from the west needs to face east and has to turn around. The\nother people do not need to change their directions, so the number of people\nwho have to change their directions is 1 in this case. It is not possible to\nhave 0 people who have to change their directions, so the answer is 1.\n\n* * *"}, {"input": "12\n WEWEWEEEWWWE", "output": "4\n \n\n* * *"}, {"input": "8\n WWWWWEEE", "output": "3"}] |
Print the minimum number of people who have to change their directions.
* * * | s702179149 | Runtime Error | p03341 | Input is given from Standard Input in the following format:
N
S | # E
from heapq import heappush, heappop
import numpy as np
N, K, Q = map(int, input().split())
A = list(map(int, input().split()))
A_args = np.argsort(A)
nodeid = np.ones(N).astype("int32")
canput = np.ones(N)
nodeid_dict = dict()
nodeid_dict[1] = [0, N]
# initial output
res = A[A_args[Q - 1]] - A[A_args[0]]
ind_del = 0
for i in range(N):
nid = A_args[i]
# update nodeid
ndid = nodeid[nid]
nodeid[nid] = 0
left, right = nodeid_dict[ndid]
nodeid[(nid + 1) : right] = i + 2
nodeid_dict[nid] = [left, nid]
nodeid_dict[i + 2] = [nid + 1, right]
# update canput
canput[nid] = 0
canput[left:nid] = 0
h = []
for j in range(left, nid):
heappush(h, (-A[j], j))
while len(h) >= K:
_, j = heappop(h)
canput[j] = 1
canput[(nid + 1) : right] = 0
h = []
for j in range(nid + 1, right):
heappush(h, (-A[j], j))
while len(h) >= K:
_, j = heappop(h)
canput[j] = 1
# break
if canput.sum() <= Q:
break
# calculate
q = 0
qmin = 10**9
qmax = 1
for i in range(N):
if canput[A_args[i]] == 1:
q += 1
qmin = min(A[A_args[i]], qmin)
qmax = max(A[A_args[i]], qmax)
if q == Q:
r = qmax - qmin
break
res = min(res, r)
print(res)
| Statement
There are N people standing in a row from west to east. Each person is facing
east or west. The directions of the people is given as a string S of length N.
The i-th person from the west is facing east if S_i = `E`, and west if S_i =
`W`.
You will appoint one of the N people as the leader, then command the rest of
them to face in the direction of the leader. Here, we do not care which
direction the leader is facing.
The people in the row hate to change their directions, so you would like to
select the leader so that the number of people who have to change their
directions is minimized. Find the minimum number of people who have to change
their directions. | [{"input": "5\n WEEWW", "output": "1\n \n\nAssume that we appoint the third person from the west as the leader. Then, the\nfirst person from the west needs to face east and has to turn around. The\nother people do not need to change their directions, so the number of people\nwho have to change their directions is 1 in this case. It is not possible to\nhave 0 people who have to change their directions, so the answer is 1.\n\n* * *"}, {"input": "12\n WEWEWEEEWWWE", "output": "4\n \n\n* * *"}, {"input": "8\n WWWWWEEE", "output": "3"}] |
Print the minimum number of people who have to change their directions.
* * * | s548264112 | Accepted | p03341 | Input is given from Standard Input in the following format:
N
S | _ = input()
aa = input()
west_count = [None for _ in aa]
east_count = [None for _ in aa]
west_count[0] = 0
for i in range(len(aa) - 1):
if aa[i] == "W":
west_count[i + 1] = west_count[i] + 1
else:
west_count[i + 1] = west_count[i]
east_count[-1] = 0
for i in range(len(aa) - 1, 0, -1):
if aa[i] == "E":
east_count[i - 1] = east_count[i] + 1
else:
east_count[i - 1] = east_count[i]
candidate_count = len(aa)
for i in range(len(aa)):
candidate_count = min(west_count[i] + east_count[i], candidate_count)
print(candidate_count)
| Statement
There are N people standing in a row from west to east. Each person is facing
east or west. The directions of the people is given as a string S of length N.
The i-th person from the west is facing east if S_i = `E`, and west if S_i =
`W`.
You will appoint one of the N people as the leader, then command the rest of
them to face in the direction of the leader. Here, we do not care which
direction the leader is facing.
The people in the row hate to change their directions, so you would like to
select the leader so that the number of people who have to change their
directions is minimized. Find the minimum number of people who have to change
their directions. | [{"input": "5\n WEEWW", "output": "1\n \n\nAssume that we appoint the third person from the west as the leader. Then, the\nfirst person from the west needs to face east and has to turn around. The\nother people do not need to change their directions, so the number of people\nwho have to change their directions is 1 in this case. It is not possible to\nhave 0 people who have to change their directions, so the answer is 1.\n\n* * *"}, {"input": "12\n WEWEWEEEWWWE", "output": "4\n \n\n* * *"}, {"input": "8\n WWWWWEEE", "output": "3"}] |
Print the minimum number of people who have to change their directions.
* * * | s763046510 | Wrong Answer | p03341 | Input is given from Standard Input in the following format:
N
S | S = int(input())
N = input()
a = S
b = 0
for i in range(S):
c = N.count("E")
if N[i] == "W":
b += 1
if N[i] == "E":
c -= 1
if b - 1 + c < a:
a = b + c - 1
print(a)
| Statement
There are N people standing in a row from west to east. Each person is facing
east or west. The directions of the people is given as a string S of length N.
The i-th person from the west is facing east if S_i = `E`, and west if S_i =
`W`.
You will appoint one of the N people as the leader, then command the rest of
them to face in the direction of the leader. Here, we do not care which
direction the leader is facing.
The people in the row hate to change their directions, so you would like to
select the leader so that the number of people who have to change their
directions is minimized. Find the minimum number of people who have to change
their directions. | [{"input": "5\n WEEWW", "output": "1\n \n\nAssume that we appoint the third person from the west as the leader. Then, the\nfirst person from the west needs to face east and has to turn around. The\nother people do not need to change their directions, so the number of people\nwho have to change their directions is 1 in this case. It is not possible to\nhave 0 people who have to change their directions, so the answer is 1.\n\n* * *"}, {"input": "12\n WEWEWEEEWWWE", "output": "4\n \n\n* * *"}, {"input": "8\n WWWWWEEE", "output": "3"}] |
Print the maximum possible number of moves Aoki has to make.
* * * | s957731057 | Accepted | p02803 | Input is given from Standard Input in the following format:
H W
S_{11}...S_{1W}
:
S_{H1}...S_{HW} | from collections import deque
INF = 10000
H, W = map(int, input().split())
S = [list(input()) for i in range(0, H, 1)]
S_count = [[INF for j in range(0, W, 1)] for i in range(0, H, 1)]
task_list = deque([])
def bfs(x, y, count):
if x < 0 or H - 1 < x or y < 0 or W - 1 < y:
return False
if S[x][y] == "#":
return False
if S_count[x][y] > count:
S_count[x][y] = count
task_list.append([x + 1, y, count + 1])
task_list.append([x - 1, y, count + 1])
task_list.append([x, y - 1, count + 1])
task_list.append([x, y + 1, count + 1])
return True
maxi = 0
for i in range(0, H, 1):
for j in range(0, W, 1):
S_count = [[INF for j in range(0, W, 1)] for i in range(0, H, 1)]
task_list.append([i, j, 0])
while len(task_list):
X, Y, T = task_list.popleft()
if bfs(X, Y, T):
maxi = max(T, maxi)
print(maxi)
| Statement
Takahashi has a maze, which is a grid of H \times W squares with H horizontal
rows and W vertical columns.
The square at the i-th row from the top and the j-th column is a "wall" square
if S_{ij} is `#`, and a "road" square if S_{ij} is `.`.
From a road square, you can move to a horizontally or vertically adjacent road
square.
You cannot move out of the maze, move to a wall square, or move diagonally.
Takahashi will choose a starting square and a goal square, which can be any
road squares, and give the maze to Aoki.
Aoki will then travel from the starting square to the goal square, in the
minimum number of moves required.
In this situation, find the maximum possible number of moves Aoki has to make. | [{"input": "3 3\n ...\n ...\n ...", "output": "4\n \n\nIf Takahashi chooses the top-left square as the starting square and the\nbottom-right square as the goal square, Aoki has to make four moves.\n\n* * *"}, {"input": "3 5\n ...#.\n .#.#.\n .#...", "output": "10\n \n\nIf Takahashi chooses the bottom-left square as the starting square and the\ntop-right square as the goal square, Aoki has to make ten moves."}] |
Print the maximum possible number of moves Aoki has to make.
* * * | s858581330 | Accepted | p02803 | Input is given from Standard Input in the following format:
H W
S_{11}...S_{1W}
:
S_{H1}...S_{HW} | def d_maze_master(INF=float("inf")):
from collections import deque
H, W = [int(i) for i in input().split()]
Maze = [list(input()) for _ in range(H)]
def bfs(start_row, start_col):
diff = ((-1, 0), (0, 1), (1, 0), (0, -1))
def is_inside(row, col):
return 0 <= row < H and 0 <= col < W
queue = deque([(start_row, start_col)])
dist = [[INF for _ in range(W)] for _ in range(H)]
dist[start_row][start_col] = 0
while queue:
row, col = queue.pop()
for dr, dc in diff:
nr, nc = row + dr, col + dc
if is_inside(nr, nc) and Maze[nr][nc] != "#" and dist[nr][nc] == INF:
queue.appendleft((nr, nc))
dist[nr][nc] = dist[row][col] + 1
return dist
ans = 0
for start_row in range(H):
for start_col in range(W):
if Maze[start_row][start_col] == "#":
continue
dist = bfs(start_row, start_col)
for row in range(H):
for col in range(W):
if Maze[row][col] != "#":
ans = max(ans, dist[row][col])
return ans
print(d_maze_master())
| Statement
Takahashi has a maze, which is a grid of H \times W squares with H horizontal
rows and W vertical columns.
The square at the i-th row from the top and the j-th column is a "wall" square
if S_{ij} is `#`, and a "road" square if S_{ij} is `.`.
From a road square, you can move to a horizontally or vertically adjacent road
square.
You cannot move out of the maze, move to a wall square, or move diagonally.
Takahashi will choose a starting square and a goal square, which can be any
road squares, and give the maze to Aoki.
Aoki will then travel from the starting square to the goal square, in the
minimum number of moves required.
In this situation, find the maximum possible number of moves Aoki has to make. | [{"input": "3 3\n ...\n ...\n ...", "output": "4\n \n\nIf Takahashi chooses the top-left square as the starting square and the\nbottom-right square as the goal square, Aoki has to make four moves.\n\n* * *"}, {"input": "3 5\n ...#.\n .#.#.\n .#...", "output": "10\n \n\nIf Takahashi chooses the bottom-left square as the starting square and the\ntop-right square as the goal square, Aoki has to make ten moves."}] |
Print the maximum possible number of moves Aoki has to make.
* * * | s861919091 | Accepted | p02803 | Input is given from Standard Input in the following format:
H W
S_{11}...S_{1W}
:
S_{H1}...S_{HW} | from queue import Queue
INF = float("inf")
R, C = map(int, input().split())
M = [input() for k in range(R)]
ans = 0
for k in range(C):
for l in range(R):
if M[l][k] == ".":
D = [[INF for k in range(C)] for l in range(R)]
sx, sy = l, k
Q = Queue()
Q.put([sx, sy])
D[sx][sy] = 0
dx = [1, 0, -1, 0]
dy = [0, 1, 0, -1]
while not Q.empty():
t = Q.get()
x = t[0]
y = t[1]
for d in range(4):
if 0 <= x + dx[d] < R and 0 <= y + dy[d] < C:
if (
M[x + dx[d]][y + dy[d]] == "."
and D[x + dx[d]][y + dy[d]] > D[x][y] + 1
):
D[x + dx[d]][y + dy[d]] = D[x][y] + 1
Q.put([x + dx[d], y + dy[d]])
for p in range(C):
for q in range(R):
if D[q][p] != float("inf"):
ans = max(ans, D[q][p])
print(ans)
| Statement
Takahashi has a maze, which is a grid of H \times W squares with H horizontal
rows and W vertical columns.
The square at the i-th row from the top and the j-th column is a "wall" square
if S_{ij} is `#`, and a "road" square if S_{ij} is `.`.
From a road square, you can move to a horizontally or vertically adjacent road
square.
You cannot move out of the maze, move to a wall square, or move diagonally.
Takahashi will choose a starting square and a goal square, which can be any
road squares, and give the maze to Aoki.
Aoki will then travel from the starting square to the goal square, in the
minimum number of moves required.
In this situation, find the maximum possible number of moves Aoki has to make. | [{"input": "3 3\n ...\n ...\n ...", "output": "4\n \n\nIf Takahashi chooses the top-left square as the starting square and the\nbottom-right square as the goal square, Aoki has to make four moves.\n\n* * *"}, {"input": "3 5\n ...#.\n .#.#.\n .#...", "output": "10\n \n\nIf Takahashi chooses the bottom-left square as the starting square and the\ntop-right square as the goal square, Aoki has to make ten moves."}] |
Print the maximum possible number of moves Aoki has to make.
* * * | s086767301 | Accepted | p02803 | Input is given from Standard Input in the following format:
H W
S_{11}...S_{1W}
:
S_{H1}...S_{HW} | H, W = list(map(int, input().split()))
MAP = [[i for i in input()] for j in range(H)]
count = sum([l.count(".") for l in MAP])
def exaustive_search(start_h, start_w):
determined = {(start_h, start_w): 0}
f = lambda h, w: (0 <= h < H and 0 <= w < W)
q = [(start_h, start_w)]
q_idx = 0
while count != q_idx:
h, w = q[q_idx]
cost = determined[(h, w)]
for dh, dw in [(-1, 0), (1, 0), (0, -1), (0, 1)]:
if (
f(h + dh, w + dw)
and (h + dh, w + dw) not in determined.keys()
and MAP[h + dh][w + dw] != "#"
):
determined[(h + dh, w + dw)] = cost + 1
q.append((h + dh, w + dw))
q_idx += 1
return max(determined.values())
print(
max(
[exaustive_search(h, w) for h in range(H) for w in range(W) if MAP[h][w] != "#"]
)
)
| Statement
Takahashi has a maze, which is a grid of H \times W squares with H horizontal
rows and W vertical columns.
The square at the i-th row from the top and the j-th column is a "wall" square
if S_{ij} is `#`, and a "road" square if S_{ij} is `.`.
From a road square, you can move to a horizontally or vertically adjacent road
square.
You cannot move out of the maze, move to a wall square, or move diagonally.
Takahashi will choose a starting square and a goal square, which can be any
road squares, and give the maze to Aoki.
Aoki will then travel from the starting square to the goal square, in the
minimum number of moves required.
In this situation, find the maximum possible number of moves Aoki has to make. | [{"input": "3 3\n ...\n ...\n ...", "output": "4\n \n\nIf Takahashi chooses the top-left square as the starting square and the\nbottom-right square as the goal square, Aoki has to make four moves.\n\n* * *"}, {"input": "3 5\n ...#.\n .#.#.\n .#...", "output": "10\n \n\nIf Takahashi chooses the bottom-left square as the starting square and the\ntop-right square as the goal square, Aoki has to make ten moves."}] |
Print the maximum possible number of moves Aoki has to make.
* * * | s773353305 | Wrong Answer | p02803 | Input is given from Standard Input in the following format:
H W
S_{11}...S_{1W}
:
S_{H1}...S_{HW} | import queue
H, W = map(int, input().split())
c = ["#" * (W + 2)] + ["#" + input() + "#" for _ in range(H)] + ["#" * (W + 2)]
ans = 0
for i in range(1, H + 1):
for g in range(1, W + 1):
MAX = 0
s = (i, g)
dist = [[-1] * (W + 2) for _ in range(H + 2)]
que = queue.Queue()
que.put(s)
dist[s[0]][s[1]] = 0
while not que.empty():
h, w = que.get()
direction = [(0, -1), (0, 1), (1, 0), (-1, 0)]
for y, x in direction:
if c[h + y][w + x] == "." and dist[h + y][w + x] == -1:
que.put((h + y, w + x))
dist[h + y][w + x] = dist[h][w] + 1
MAX = max(MAX, dist[h + y][w + x])
ans = max(MAX, ans)
print(ans)
| Statement
Takahashi has a maze, which is a grid of H \times W squares with H horizontal
rows and W vertical columns.
The square at the i-th row from the top and the j-th column is a "wall" square
if S_{ij} is `#`, and a "road" square if S_{ij} is `.`.
From a road square, you can move to a horizontally or vertically adjacent road
square.
You cannot move out of the maze, move to a wall square, or move diagonally.
Takahashi will choose a starting square and a goal square, which can be any
road squares, and give the maze to Aoki.
Aoki will then travel from the starting square to the goal square, in the
minimum number of moves required.
In this situation, find the maximum possible number of moves Aoki has to make. | [{"input": "3 3\n ...\n ...\n ...", "output": "4\n \n\nIf Takahashi chooses the top-left square as the starting square and the\nbottom-right square as the goal square, Aoki has to make four moves.\n\n* * *"}, {"input": "3 5\n ...#.\n .#.#.\n .#...", "output": "10\n \n\nIf Takahashi chooses the bottom-left square as the starting square and the\ntop-right square as the goal square, Aoki has to make ten moves."}] |
Print the maximum possible number of moves Aoki has to make.
* * * | s490730328 | Wrong Answer | p02803 | Input is given from Standard Input in the following format:
H W
S_{11}...S_{1W}
:
S_{H1}...S_{HW} | def two_int():
N, K = map(int, input().split())
return N, K
def one_int():
return int(input())
def one_str():
return input()
def many_int():
return list(map(int, input().split()))
H, W = two_int()
maps = [[0 for i in range(W)] for j in range(H)]
for i in range(H):
S = one_str()
for index, j in enumerate(S):
if j == "#":
maps[i][index] = 1
import copy
def dfs(pos, old_pos, root):
# 停止条件
# 深さに限らず,任意の停止条件を書く
x, y = pos[0], pos[1]
pos_str = str(pos[0]) + "_" + str(pos[1])
if maps[y][x] == 1:
return 0, pos
if pos_str in root:
return len(root) - 1, old_pos
root[pos_str] = 1
ret1, ret2, ret3, ret4 = 0, 0, 0, 0
if x >= 1:
ret1, pos1 = dfs([x - 1, y], pos, copy.deepcopy(root))
if x < W - 1:
ret2, pos2 = dfs([x + 1, y], pos, copy.deepcopy(root))
if y >= 1:
ret3, pos3 = dfs([x, y - 1], pos, copy.deepcopy(root))
if y < H - 1:
ret4, pos4 = dfs([x, y + 1], pos, copy.deepcopy(root))
temp = max(ret1, ret2, ret3, ret4)
if temp == ret1:
return ret1, pos1
if temp == ret2:
return ret2, pos2
if temp == ret3:
return ret3, pos3
if temp == ret4:
return ret4, pos4
def dfs2(pos, root, goal):
# 停止条件
# 深さに限らず,任意の停止条件を書く
x, y = pos[0], pos[1]
pos_str = str(pos[0]) + "_" + str(pos[1])
if pos_str in root or maps[y][x] == 1:
return 1000
if pos_str == goal_str:
return len(root)
root[pos_str] = 1
ret1, ret2, ret3, ret4 = 1000, 1000, 1000, 1000
if x >= 1:
ret1 = dfs2([x - 1, y], copy.deepcopy(root), goal_str)
if x < W - 1:
ret2 = dfs2([x + 1, y], copy.deepcopy(root), goal_str)
if y >= 1:
ret3 = dfs2([x, y - 1], copy.deepcopy(root), goal_str)
if y < H - 1:
ret4 = dfs2([x, y + 1], copy.deepcopy(root), goal_str)
return min(ret1, ret2, ret3, ret4)
# start位置探索
for y in range(H):
for x in range(W):
if maps[y][x] == 0:
break
# max(dfs([0,0],{}), dfs([0,H-1],{}), dfs([W-1,0],{}), dfs([W-1,H-1],{}))
pos, goal = dfs([x, y], [0, 0], {})
goal_str = str(goal[0]) + "_" + str(goal[1])
print(dfs2([x, y], {}, goal_str))
| Statement
Takahashi has a maze, which is a grid of H \times W squares with H horizontal
rows and W vertical columns.
The square at the i-th row from the top and the j-th column is a "wall" square
if S_{ij} is `#`, and a "road" square if S_{ij} is `.`.
From a road square, you can move to a horizontally or vertically adjacent road
square.
You cannot move out of the maze, move to a wall square, or move diagonally.
Takahashi will choose a starting square and a goal square, which can be any
road squares, and give the maze to Aoki.
Aoki will then travel from the starting square to the goal square, in the
minimum number of moves required.
In this situation, find the maximum possible number of moves Aoki has to make. | [{"input": "3 3\n ...\n ...\n ...", "output": "4\n \n\nIf Takahashi chooses the top-left square as the starting square and the\nbottom-right square as the goal square, Aoki has to make four moves.\n\n* * *"}, {"input": "3 5\n ...#.\n .#.#.\n .#...", "output": "10\n \n\nIf Takahashi chooses the bottom-left square as the starting square and the\ntop-right square as the goal square, Aoki has to make ten moves."}] |
Print the maximum possible number of moves Aoki has to make.
* * * | s083825049 | Wrong Answer | p02803 | Input is given from Standard Input in the following format:
H W
S_{11}...S_{1W}
:
S_{H1}...S_{HW} | import copy
H, W = [int(i) for i in input().rstrip().split(" ")]
S = [list(input()) for _ in range(H)]
S1 = copy.deepcopy(S)
start = []
for y in range(H):
b = False
for x in range(W):
if S[y][x] == ".":
start = (y, x)
# print(start)
b = True
break
if b:
break
def dd(P, l, M):
def nexts(y, x, M):
n = []
if y > 0 and M[y - 1][x] == ".":
n += [(y - 1, x)] # up
if y < H - 1 and M[y + 1][x] == ".":
n += [(y + 1, x)] # down
if x > 0 and M[y][x - 1] == ".":
n += [(y, x - 1)] # left
if x < W - 1 and M[y][x + 1] == ".":
n += [(y, x + 1)] # right
return n
n = []
for y, x in P:
# print("dd",l,y,x)
n += nexts(y, x, M)
n = list(set(n))
for y, x in n:
M[y][x] = "#"
if n == []:
return [(l, P[0])]
else:
return dd(n, l + 1, M)
far = sorted(dd([start], 0, S1), reverse=True)[0]
far2 = sorted(dd([far[1]], 0, S), reverse=True)[0]
print(far2[0])
| Statement
Takahashi has a maze, which is a grid of H \times W squares with H horizontal
rows and W vertical columns.
The square at the i-th row from the top and the j-th column is a "wall" square
if S_{ij} is `#`, and a "road" square if S_{ij} is `.`.
From a road square, you can move to a horizontally or vertically adjacent road
square.
You cannot move out of the maze, move to a wall square, or move diagonally.
Takahashi will choose a starting square and a goal square, which can be any
road squares, and give the maze to Aoki.
Aoki will then travel from the starting square to the goal square, in the
minimum number of moves required.
In this situation, find the maximum possible number of moves Aoki has to make. | [{"input": "3 3\n ...\n ...\n ...", "output": "4\n \n\nIf Takahashi chooses the top-left square as the starting square and the\nbottom-right square as the goal square, Aoki has to make four moves.\n\n* * *"}, {"input": "3 5\n ...#.\n .#.#.\n .#...", "output": "10\n \n\nIf Takahashi chooses the bottom-left square as the starting square and the\ntop-right square as the goal square, Aoki has to make ten moves."}] |
Print the maximum possible number of moves Aoki has to make.
* * * | s496701556 | Runtime Error | p02803 | Input is given from Standard Input in the following format:
H W
S_{11}...S_{1W}
:
S_{H1}...S_{HW} | m = 10**9 + 7
f = [1]
for i in range(10**5 + 5):
f.append(f[-1] * (i + 1) % m)
def nCr(n, r, mod=m):
return f[n] * pow(f[r], m - 2, m) * pow(f[n - r], m - 2, m) % m
n, k = map(int, input().split())
a = list(map(int, input().split()))
a.sort()
ans = 0
for i in range(n - k + 1):
ans += (a[-1 - i] - a[i]) * nCr(n - 1 - i, k - 1)
ans %= m
print(ans)
| Statement
Takahashi has a maze, which is a grid of H \times W squares with H horizontal
rows and W vertical columns.
The square at the i-th row from the top and the j-th column is a "wall" square
if S_{ij} is `#`, and a "road" square if S_{ij} is `.`.
From a road square, you can move to a horizontally or vertically adjacent road
square.
You cannot move out of the maze, move to a wall square, or move diagonally.
Takahashi will choose a starting square and a goal square, which can be any
road squares, and give the maze to Aoki.
Aoki will then travel from the starting square to the goal square, in the
minimum number of moves required.
In this situation, find the maximum possible number of moves Aoki has to make. | [{"input": "3 3\n ...\n ...\n ...", "output": "4\n \n\nIf Takahashi chooses the top-left square as the starting square and the\nbottom-right square as the goal square, Aoki has to make four moves.\n\n* * *"}, {"input": "3 5\n ...#.\n .#.#.\n .#...", "output": "10\n \n\nIf Takahashi chooses the bottom-left square as the starting square and the\ntop-right square as the goal square, Aoki has to make ten moves."}] |
Print the maximum possible number of moves Aoki has to make.
* * * | s724519156 | Accepted | p02803 | Input is given from Standard Input in the following format:
H W
S_{11}...S_{1W}
:
S_{H1}...S_{HW} | H, W = map(int, input().split())
S = []
S.append(["#" for _ in range(W + 2)])
for _ in range(H):
s = input()
s = "#" + s + "#"
S.append([])
for k in range(W + 2):
S[-1].append(s[k])
S.append(["#" for _ in range(W + 2)])
b = 0
start = []
for h in range(1, H + 1):
for w in range(1, W + 1):
if S[h][w] == ".":
c = 0
b += 1
if S[h + 1][w] == ".":
c += 1
if S[h - 1][w] == ".":
c += 1
if S[h][w + 1] == ".":
c += 1
if S[h][w - 1] == ".":
c += 1
if c == 1:
start.append([h, w])
if len(start) == 0:
for h in range(1, H + 1):
for w in range(1, W + 1):
if S[h][w] == ".":
c = 0
if S[h + 1][w] == ".":
c += 1
if S[h - 1][w] == ".":
c += 1
if S[h][w + 1] == ".":
c += 1
if S[h][w - 1] == ".":
c += 1
if c == 2:
start.append([h, w])
# dfs 121ms
"""
def solve(nowh, noww, point):
counter[nowh][noww] = point
flag = True
if counter[nowh+1][noww] > point + 1:
solve(nowh+1, noww, point+1)
flag = False
if counter[nowh-1][noww] > point + 1:
solve(nowh-1, noww, point+1)
flag = False
if counter[nowh][noww+1] > point + 1:
solve(nowh, noww+1, point+1)
flag = False
if counter[nowh][noww-1] > point + 1:
solve(nowh, noww-1, point+1)
flag = False
if flag:
return 0
ans = 0
for item in start:
original_counter = [[b for _ in range(W+2)] for _ in range(H+2)]
for k in range(H+2):
for j in range(W+2):
if S[k][j] == '#':
original_counter[k][j] = -1
counter = original_counter
solve(item[0], item[1], 0)
anskouho = 0
for h in range(1, H+1):
for w in range(1, W+1):
anskouho = max(anskouho, counter[h][w])
ans = max(ans, anskouho)
print(ans)
"""
# bfs
def solve(now, point):
nextlist = []
for n in now:
if counter[n[0] + 1][n[1]] > point + 1:
counter[n[0] + 1][n[1]] = point + 1
nextlist.append([n[0] + 1, n[1]])
if counter[n[0]][n[1] + 1] > point + 1:
nextlist.append([n[0], n[1] + 1])
counter[n[0]][n[1] + 1] = point + 1
if counter[n[0] - 1][n[1]] > point + 1:
nextlist.append([n[0] - 1, n[1]])
counter[n[0] - 1][n[1]] = point + 1
if counter[n[0]][n[1] - 1] > point + 1:
nextlist.append([n[0], n[1] - 1])
counter[n[0]][n[1] - 1] = point + 1
if len(nextlist) == 0:
anskouho.append(point)
return 0
else:
solve(nextlist, point + 1)
anskouho = []
for item in start:
original_counter = [[b for _ in range(W + 2)] for _ in range(H + 2)]
for k in range(H + 2):
for j in range(W + 2):
if S[k][j] == "#":
original_counter[k][j] = -1
counter = original_counter
counter[item[0]][item[1]] = 0
solve([item], 0)
print(max(anskouho))
| Statement
Takahashi has a maze, which is a grid of H \times W squares with H horizontal
rows and W vertical columns.
The square at the i-th row from the top and the j-th column is a "wall" square
if S_{ij} is `#`, and a "road" square if S_{ij} is `.`.
From a road square, you can move to a horizontally or vertically adjacent road
square.
You cannot move out of the maze, move to a wall square, or move diagonally.
Takahashi will choose a starting square and a goal square, which can be any
road squares, and give the maze to Aoki.
Aoki will then travel from the starting square to the goal square, in the
minimum number of moves required.
In this situation, find the maximum possible number of moves Aoki has to make. | [{"input": "3 3\n ...\n ...\n ...", "output": "4\n \n\nIf Takahashi chooses the top-left square as the starting square and the\nbottom-right square as the goal square, Aoki has to make four moves.\n\n* * *"}, {"input": "3 5\n ...#.\n .#.#.\n .#...", "output": "10\n \n\nIf Takahashi chooses the bottom-left square as the starting square and the\ntop-right square as the goal square, Aoki has to make ten moves."}] |
Print the maximum possible number of moves Aoki has to make.
* * * | s740777787 | Wrong Answer | p02803 | Input is given from Standard Input in the following format:
H W
S_{11}...S_{1W}
:
S_{H1}...S_{HW} | import sys
input = sys.stdin.readline
H, W = map(int, input().split())
state = [list(input().rstrip()) for _ in range(H)]
def nexts(h, w):
pq = []
if h != 0:
pq.append((h - 1, w))
if w != 0:
pq.append((h, w - 1))
if h != H - 1:
pq.append((h + 1, w))
if w != W - 1:
pq.append((h, w + 1))
return pq
def bfs(sh, sw):
Ds = [[-1] * W for _ in range(H)]
q = [(sh, sw)]
d = 0
Ds[sh][sw] = 0
while q:
qq = []
d += 1
for h, w in q:
for nh, nw in nexts(h, w):
if state[nh][nw] == "#":
Ds[nh][nw] = -2
elif Ds[nh][nw] == -1:
Ds[nh][nw] = d
qq.append((nh, nw))
q = qq
maxd = 0
for h in range(H):
for w in range(W):
if maxd < Ds[h][w]:
maxd = Ds[h][w]
lh, lw = h, w
return lh, lw, maxd
for h in range(H):
for w in range(W):
if state[h][w] == ".":
sh, sw = h, w
break
lh, lw, _ = bfs(sh, sw)
_, _, waaa = bfs(lh, lw)
print(waaa)
| Statement
Takahashi has a maze, which is a grid of H \times W squares with H horizontal
rows and W vertical columns.
The square at the i-th row from the top and the j-th column is a "wall" square
if S_{ij} is `#`, and a "road" square if S_{ij} is `.`.
From a road square, you can move to a horizontally or vertically adjacent road
square.
You cannot move out of the maze, move to a wall square, or move diagonally.
Takahashi will choose a starting square and a goal square, which can be any
road squares, and give the maze to Aoki.
Aoki will then travel from the starting square to the goal square, in the
minimum number of moves required.
In this situation, find the maximum possible number of moves Aoki has to make. | [{"input": "3 3\n ...\n ...\n ...", "output": "4\n \n\nIf Takahashi chooses the top-left square as the starting square and the\nbottom-right square as the goal square, Aoki has to make four moves.\n\n* * *"}, {"input": "3 5\n ...#.\n .#.#.\n .#...", "output": "10\n \n\nIf Takahashi chooses the bottom-left square as the starting square and the\ntop-right square as the goal square, Aoki has to make ten moves."}] |
Print the maximum possible number of moves Aoki has to make.
* * * | s688743701 | Wrong Answer | p02803 | Input is given from Standard Input in the following format:
H W
S_{11}...S_{1W}
:
S_{H1}...S_{HW} | H, W = map(int, input().split())
square = []
for i in range(H):
squaread = ["#"]
squaread += list(input())
squaread += "#"
square.append(squaread)
ad_square = [["#" for i in range(W + 2)]]
ad_square += square
ad_square += [["#" for i in range(W + 2)]]
numbersquare = []
for i in range(H):
numbersquare.append([0 for j in range(W)])
for i in range(H):
i2 = i + 1
for j in range(W):
j2 = j + 1
around = 0
if ad_square[i2][j2] == "#":
pass
else:
if ad_square[i2][j2 - 1] == "#":
around += 1
if ad_square[i2][j2 + 1] == "#":
around += 1
if ad_square[i2 - 1][j2] == "#":
around += 1
if ad_square[i2 + 1][j2] == "#":
around += 1
numbersquare[i2 - 1][j2 - 1] = around
number1 = 0
number2 = 0
number3 = 0
for i in range(len(numbersquare)):
number1 += numbersquare[i].count(1) // 2
number2 += numbersquare[i].count(2)
number3 += numbersquare[i].count(3)
print(sum([number1, number2, number3]) - 1)
| Statement
Takahashi has a maze, which is a grid of H \times W squares with H horizontal
rows and W vertical columns.
The square at the i-th row from the top and the j-th column is a "wall" square
if S_{ij} is `#`, and a "road" square if S_{ij} is `.`.
From a road square, you can move to a horizontally or vertically adjacent road
square.
You cannot move out of the maze, move to a wall square, or move diagonally.
Takahashi will choose a starting square and a goal square, which can be any
road squares, and give the maze to Aoki.
Aoki will then travel from the starting square to the goal square, in the
minimum number of moves required.
In this situation, find the maximum possible number of moves Aoki has to make. | [{"input": "3 3\n ...\n ...\n ...", "output": "4\n \n\nIf Takahashi chooses the top-left square as the starting square and the\nbottom-right square as the goal square, Aoki has to make four moves.\n\n* * *"}, {"input": "3 5\n ...#.\n .#.#.\n .#...", "output": "10\n \n\nIf Takahashi chooses the bottom-left square as the starting square and the\ntop-right square as the goal square, Aoki has to make ten moves."}] |
Print the maximum possible number of moves Aoki has to make.
* * * | s002585158 | Wrong Answer | p02803 | Input is given from Standard Input in the following format:
H W
S_{11}...S_{1W}
:
S_{H1}...S_{HW} | print(10)
| Statement
Takahashi has a maze, which is a grid of H \times W squares with H horizontal
rows and W vertical columns.
The square at the i-th row from the top and the j-th column is a "wall" square
if S_{ij} is `#`, and a "road" square if S_{ij} is `.`.
From a road square, you can move to a horizontally or vertically adjacent road
square.
You cannot move out of the maze, move to a wall square, or move diagonally.
Takahashi will choose a starting square and a goal square, which can be any
road squares, and give the maze to Aoki.
Aoki will then travel from the starting square to the goal square, in the
minimum number of moves required.
In this situation, find the maximum possible number of moves Aoki has to make. | [{"input": "3 3\n ...\n ...\n ...", "output": "4\n \n\nIf Takahashi chooses the top-left square as the starting square and the\nbottom-right square as the goal square, Aoki has to make four moves.\n\n* * *"}, {"input": "3 5\n ...#.\n .#.#.\n .#...", "output": "10\n \n\nIf Takahashi chooses the bottom-left square as the starting square and the\ntop-right square as the goal square, Aoki has to make ten moves."}] |
Print the maximum possible number of moves Aoki has to make.
* * * | s614909184 | Wrong Answer | p02803 | Input is given from Standard Input in the following format:
H W
S_{11}...S_{1W}
:
S_{H1}...S_{HW} | print(39)
| Statement
Takahashi has a maze, which is a grid of H \times W squares with H horizontal
rows and W vertical columns.
The square at the i-th row from the top and the j-th column is a "wall" square
if S_{ij} is `#`, and a "road" square if S_{ij} is `.`.
From a road square, you can move to a horizontally or vertically adjacent road
square.
You cannot move out of the maze, move to a wall square, or move diagonally.
Takahashi will choose a starting square and a goal square, which can be any
road squares, and give the maze to Aoki.
Aoki will then travel from the starting square to the goal square, in the
minimum number of moves required.
In this situation, find the maximum possible number of moves Aoki has to make. | [{"input": "3 3\n ...\n ...\n ...", "output": "4\n \n\nIf Takahashi chooses the top-left square as the starting square and the\nbottom-right square as the goal square, Aoki has to make four moves.\n\n* * *"}, {"input": "3 5\n ...#.\n .#.#.\n .#...", "output": "10\n \n\nIf Takahashi chooses the bottom-left square as the starting square and the\ntop-right square as the goal square, Aoki has to make ten moves."}] |
Print the maximum possible number of moves Aoki has to make.
* * * | s100323841 | Accepted | p02803 | Input is given from Standard Input in the following format:
H W
S_{11}...S_{1W}
:
S_{H1}...S_{HW} | import copy
H, W = list(map(int, input().split()))
F = [] # map
for i in range(H):
a = input()
b = []
for j in range(W):
if a[j] == ".":
b.append(0)
else:
b.append("w")
F.append(b)
# print(F)
# マップからの経路を算出する関数
s = [0, 0]
def n_route(s):
"""
F:マップ配列
s:スタート座標
"""
C = copy.deepcopy(F)
P = [] # 点の座標配列
nP = []
P.append(s)
C[s[0]][s[1]] = -1
c = 1
while P:
# print(c)
for p in P:
# print("p=",p)
for v in [[1, 0], [0, 1], [-1, 0], [0, -1]]:
np = [p[0] + v[0], p[1] + v[1]]
# print(np)
# 行ける点があったら
if 0 <= np[0] < H and 0 <= np[1] < W and C[np[0]][np[1]] == 0:
C[np[0]][np[1]] = c
# 記録
if [np[0], np[1]] not in nP:
nP.append([np[0], np[1]])
# print(nP)
P = []
while nP:
P.append(nP.pop(0))
# print(C)
# print("P:",P)
c += 1
return C
# print(n_route(s))
Mn = [[0] * W for i in range(H)]
# print(Mn)
# Fのうち、すべての0の点でn_routeを回す。
for i in range(H):
for j in range(W):
if F[i][j] == 0:
# print(i,j)
nr = n_route([i, j])
# print(nr)
for k in range(H):
for l in range(W):
if nr[k][l] != "w" and Mn[k][l] < nr[k][l]:
Mn[k][l] = nr[k][l]
# print(Mn)
m = []
for i in Mn:
# print(i)
m.append(max(i))
print(max(m))
| Statement
Takahashi has a maze, which is a grid of H \times W squares with H horizontal
rows and W vertical columns.
The square at the i-th row from the top and the j-th column is a "wall" square
if S_{ij} is `#`, and a "road" square if S_{ij} is `.`.
From a road square, you can move to a horizontally or vertically adjacent road
square.
You cannot move out of the maze, move to a wall square, or move diagonally.
Takahashi will choose a starting square and a goal square, which can be any
road squares, and give the maze to Aoki.
Aoki will then travel from the starting square to the goal square, in the
minimum number of moves required.
In this situation, find the maximum possible number of moves Aoki has to make. | [{"input": "3 3\n ...\n ...\n ...", "output": "4\n \n\nIf Takahashi chooses the top-left square as the starting square and the\nbottom-right square as the goal square, Aoki has to make four moves.\n\n* * *"}, {"input": "3 5\n ...#.\n .#.#.\n .#...", "output": "10\n \n\nIf Takahashi chooses the bottom-left square as the starting square and the\ntop-right square as the goal square, Aoki has to make ten moves."}] |
Print the maximum possible number of moves Aoki has to make.
* * * | s566754358 | Accepted | p02803 | Input is given from Standard Input in the following format:
H W
S_{11}...S_{1W}
:
S_{H1}...S_{HW} | import sys, copy
sys.setrecursionlimit(10**6)
int1 = lambda x: int(x) - 1
p2D = lambda x: print(*x, sep="\n")
def IS():
return sys.stdin.readline()
def II():
return int(sys.stdin.readline())
def MI():
return map(int, sys.stdin.readline().split())
def LI():
return list(map(int, sys.stdin.readline().split()))
def LI1():
return list(map(int1, sys.stdin.readline().split()))
def LII(rows_number):
return [II() for _ in range(rows_number)]
def LLI(rows_number):
return [LI() for _ in range(rows_number)]
def LLI1(rows_number):
return [LI1() for _ in range(rows_number)]
def main():
H, W = MI()
maze = [[-1 for _ in range(W)] for _ in range(H)]
for i in range(H):
S = IS()
for j, s in enumerate(S):
if s == "#":
maze[i][j] = "#"
def bfs(sx, sy):
from collections import deque
que = deque()
dist_map = copy.deepcopy(maze)
dist_map[sy][sx] = 0
que.append((sx, sy))
res = 0
while len(que) > 0:
x, y = que.popleft()
for dx, dy in [(-1, 0), (1, 0), (0, 1), (0, -1)]:
nx = x + dx
ny = y + dy
if 0 <= nx < W and 0 <= ny < H:
if dist_map[ny][nx] == -1:
dist_map[ny][nx] = dist_map[y][x] + 1
res = max(res, dist_map[ny][nx])
que.append((nx, ny))
return res
ans = -1
for i in range(H):
for j in range(W):
if maze[i][j] == -1:
dist = bfs(j, i)
if dist > ans:
ans = dist
print(ans)
main()
| Statement
Takahashi has a maze, which is a grid of H \times W squares with H horizontal
rows and W vertical columns.
The square at the i-th row from the top and the j-th column is a "wall" square
if S_{ij} is `#`, and a "road" square if S_{ij} is `.`.
From a road square, you can move to a horizontally or vertically adjacent road
square.
You cannot move out of the maze, move to a wall square, or move diagonally.
Takahashi will choose a starting square and a goal square, which can be any
road squares, and give the maze to Aoki.
Aoki will then travel from the starting square to the goal square, in the
minimum number of moves required.
In this situation, find the maximum possible number of moves Aoki has to make. | [{"input": "3 3\n ...\n ...\n ...", "output": "4\n \n\nIf Takahashi chooses the top-left square as the starting square and the\nbottom-right square as the goal square, Aoki has to make four moves.\n\n* * *"}, {"input": "3 5\n ...#.\n .#.#.\n .#...", "output": "10\n \n\nIf Takahashi chooses the bottom-left square as the starting square and the\ntop-right square as the goal square, Aoki has to make ten moves."}] |
Print the maximum possible number of moves Aoki has to make.
* * * | s208854133 | Accepted | p02803 | Input is given from Standard Input in the following format:
H W
S_{11}...S_{1W}
:
S_{H1}...S_{HW} | from collections import deque
# N, W = 3, 5
# ARR = [
# ['.', '.', '.', '#', '.'],
# ['.', '#', '.', '#', '.'],
# ['.', '#', '.', '.', '.']
# ]
(
N,
W,
) = (
3,
3,
)
ARR = [
[".", ".", "."],
[".", ".", "."],
[".", ".", "."],
]
N, W = map(int, input().split())
ARR = []
for i in range(N):
ARR.append(list(map(str, input())))
def dfs(start, n, w, arr):
d = deque()
d.append(start)
states = [[0 for j in range(w)] for i in range(n)]
maxDistance = start[2]
while len(d) > 0:
coordinate = d.popleft()
coorY = coordinate[0]
coorX = coordinate[1]
distance = coordinate[2]
if states[coorY][coorX] == 1:
continue
maxDistance = max(distance, maxDistance)
states[coorY][coorX] = 1
leftX, leftY = coorX - 1, coorY
rightX, rightY = coorX + 1, coorY
topX, topY = coorX, coorY - 1
bottomX, bottomY = coorX, coorY + 1
if leftX >= 0 and leftY >= 0:
if arr[leftY][leftX] == ".":
d.append([leftY, leftX, distance + 1])
if rightX <= w - 1 and rightY <= n - 1:
if arr[rightY][rightX] == ".":
d.append([rightY, rightX, distance + 1])
if topY >= 0:
if arr[topY][topX] == ".":
d.append([topY, topX, distance + 1])
if bottomY <= n - 1:
if arr[bottomY][bottomX] == ".":
d.append([bottomY, bottomX, distance + 1])
return maxDistance
def calculate(n, w, arr):
distances = []
for i in range(n):
for j in range(w):
if arr[i][j] == ".":
distance = dfs([i, j, 0], n, w, arr)
distances.append(distance)
maxDistance = max(distances)
print(maxDistance)
# dfs([0, 0, 0], N, W, ARR)
calculate(N, W, ARR)
| Statement
Takahashi has a maze, which is a grid of H \times W squares with H horizontal
rows and W vertical columns.
The square at the i-th row from the top and the j-th column is a "wall" square
if S_{ij} is `#`, and a "road" square if S_{ij} is `.`.
From a road square, you can move to a horizontally or vertically adjacent road
square.
You cannot move out of the maze, move to a wall square, or move diagonally.
Takahashi will choose a starting square and a goal square, which can be any
road squares, and give the maze to Aoki.
Aoki will then travel from the starting square to the goal square, in the
minimum number of moves required.
In this situation, find the maximum possible number of moves Aoki has to make. | [{"input": "3 3\n ...\n ...\n ...", "output": "4\n \n\nIf Takahashi chooses the top-left square as the starting square and the\nbottom-right square as the goal square, Aoki has to make four moves.\n\n* * *"}, {"input": "3 5\n ...#.\n .#.#.\n .#...", "output": "10\n \n\nIf Takahashi chooses the bottom-left square as the starting square and the\ntop-right square as the goal square, Aoki has to make ten moves."}] |
If x and y belong to the same group, print `Yes`; otherwise, print `No`.
* * * | s573659615 | Accepted | p03711 | Input is given from Standard Input in the following format:
x y | from collections import defaultdict, Counter
from itertools import product, groupby, count, permutations, combinations
from math import pi, sqrt
from collections import deque
from bisect import bisect, bisect_left, bisect_right
from string import ascii_lowercase
from functools import lru_cache
import sys
sys.setrecursionlimit(10000)
INF = float("inf")
YES, Yes, yes, NO, No, no = "YES", "Yes", "yes", "NO", "No", "no"
dy4, dx4 = [0, 1, 0, -1], [1, 0, -1, 0]
dy8, dx8 = [0, -1, 0, 1, 1, -1, -1, 1], [1, 0, -1, 0, 1, 1, -1, -1]
def inside(y, x, H, W):
return 0 <= y < H and 0 <= x < W
def ceil(a, b):
return (a + b - 1) // b
def main():
x, y = map(int, input().split())
a = [1, 3, 5, 7, 8, 10, 12]
b = [4, 6, 9, 11]
c = [2]
if (x in a and y in a) or (x in b and y in b) or (x in c and y in c):
print(Yes)
else:
print(No)
if __name__ == "__main__":
main()
| Statement
Based on some criterion, Snuke divided the integers from 1 through 12 into
three groups as shown in the figure below. Given two integers x and y (1 ≤ x <
y ≤ 12), determine whether they belong to the same group.
 | [{"input": "1 3", "output": "Yes\n \n\n* * *"}, {"input": "2 4", "output": "No"}] |
If x and y belong to the same group, print `Yes`; otherwise, print `No`.
* * * | s628313529 | Accepted | p03711 | Input is given from Standard Input in the following format:
x y | import math
import queue
import bisect
import heapq
import time
import itertools
mod = int(1e9 + 7)
def swap(a, b):
return (b, a)
def gcd(a, b): # 最大公約数
if a < b:
a, b = swap(a, b)
if b == 0:
return a
else:
return gcd(b, a % b)
def lcm(a, b): # 最小公倍数
return a / gcd(a, b) * b
def divisors(a): # 約数列挙
divisors = []
for i in range(1, int(a**0.5) + 1):
if a % i == 0:
divisors.append(i)
if i != a // i:
divisors.append(a // i)
return divisors
def is_prime(a): # 素数判定
if a < 2:
return False
elif a == 2:
return True
elif a % 2 == 0:
return False
sqrt_num = int(a**0.5)
for i in range(3, sqrt_num + 1, 2):
if a % i == 0:
return False
return True
def prime_num(a): # 素数列挙
pn = [2]
for i in range(3, int(a**0.5), 2):
prime = True
for j in pn:
if i % j == 0:
prime = False
break
if prime:
pn.append(i)
return pn
def prime_fact(a): # 素因数分解
sqrt = math.sqrt(a)
res = []
i = 2
if is_prime(a):
res.append(a)
else:
while a != 1:
while a % i == 0:
res.append(i)
a //= i
i += 1
return res
def main():
l1 = [1, 3, 5, 7, 8, 10, 12]
l2 = [4, 6, 9, 11]
x, y = map(int, input().split())
if x == 2 or y == 2:
print("No")
elif x in l1 and y in l1:
print("Yes")
elif x in l2 and y in l2:
print("Yes")
else:
print("No")
return
if __name__ == "__main__":
main()
| Statement
Based on some criterion, Snuke divided the integers from 1 through 12 into
three groups as shown in the figure below. Given two integers x and y (1 ≤ x <
y ≤ 12), determine whether they belong to the same group.
 | [{"input": "1 3", "output": "Yes\n \n\n* * *"}, {"input": "2 4", "output": "No"}] |
If x and y belong to the same group, print `Yes`; otherwise, print `No`.
* * * | s217390354 | Accepted | p03711 | Input is given from Standard Input in the following format:
x y | from functools import reduce
import math
def main():
# 文字列の2進数を数値にする
# '101' → '5'
# 文字列の頭に'0b'をつけてint()にわたす
# binary = int('0b'+'101',0)
# 2進数で立っているbitを数える
# 101(0x5) → 2
# cnt_bit = bin(5).count('1')
# N! を求める
# f = math.factorial(N)
# 切り捨て
# 4 // 3
# 切り上げ
# -(-4 // 3)
# 初期値用:十分大きい数(100億)
INF = float("inf")
# 1文字のみを読み込み
# 入力:2
# a = input().rstrip()
# 変数:a='2'
# スペース区切りで標準入力を配列として読み込み
# 入力:2 4 5 7
# a, b, c, d = (int(_) for _ in input().split())
# 変数:a=2 b=4 c=5 d =7
# 1文字ずつ標準入力を配列として読み込み
# 入力:2 4 5 7
# a = list(int(_) for _ in input().split())
# 変数:a = [2, 4, 5, 7]
# 1文字ずつ標準入力を配列として読み込み
# 入力:2457
# a = list(int(_) for _ in input())
# 変数:a = [2, 4, 5, 7]
a, b = (int(_) for _ in input().split())
l1 = [1, 3, 5, 7, 8, 10, 12]
l2 = [4, 6, 9, 11]
if (a in l1 and b in l1) or (a in l2 and b in l2) or (a == 2 and b == 2):
print("Yes")
else:
print("No")
if __name__ == "__main__":
main()
| Statement
Based on some criterion, Snuke divided the integers from 1 through 12 into
three groups as shown in the figure below. Given two integers x and y (1 ≤ x <
y ≤ 12), determine whether they belong to the same group.
 | [{"input": "1 3", "output": "Yes\n \n\n* * *"}, {"input": "2 4", "output": "No"}] |
If x and y belong to the same group, print `Yes`; otherwise, print `No`.
* * * | s195968313 | Accepted | p03711 | Input is given from Standard Input in the following format:
x y | import functools
import os
INF = float("inf")
def inp():
return int(input())
def inpf():
return float(input())
def inps():
return input()
def inl():
return list(map(int, input().split()))
def inlf():
return list(map(float, input().split()))
def inls():
return input().split()
def inpm(line):
return [inp() for _ in range(line)]
def inpfm(line):
return [inpf() for _ in range(line)]
def inpsm(line):
return [inps() for _ in range(line)]
def inlm(line):
return [inl() for _ in range(line)]
def inlfm(line):
return [inlf() for _ in range(line)]
def inlsm(line):
return [inls() for _ in range(line)]
def debug(fn):
if not os.getenv("LOCAL"):
return fn
@functools.wraps(fn)
def wrapper(*args, **kwargs):
print(
"DEBUG: {}({}) -> ".format(
fn.__name__,
", ".join(
list(map(str, args))
+ ["{}={}".format(k, str(v)) for k, v in kwargs.items()]
),
),
end="",
)
ret = fn(*args, **kwargs)
print(ret)
return ret
return wrapper
x, y = inl()
a = [1, 3, 5, 7, 8, 10, 12]
b = [4, 6, 9, 11]
c = [2]
if x in a and y in a or x in b and y in b or x == 2 and b == 2:
print("Yes")
else:
print("No")
| Statement
Based on some criterion, Snuke divided the integers from 1 through 12 into
three groups as shown in the figure below. Given two integers x and y (1 ≤ x <
y ≤ 12), determine whether they belong to the same group.
 | [{"input": "1 3", "output": "Yes\n \n\n* * *"}, {"input": "2 4", "output": "No"}] |
If x and y belong to the same group, print `Yes`; otherwise, print `No`.
* * * | s572845928 | Accepted | p03711 | Input is given from Standard Input in the following format:
x y | #!/usr/bin/env python3
from collections import defaultdict
from collections import deque
from heapq import heappush, heappop
import sys
import math
import bisect
import random
import itertools
sys.setrecursionlimit(10**5)
stdin = sys.stdin
bisect_left = bisect.bisect_left
bisect_right = bisect.bisect_right
def LI():
return list(map(int, stdin.readline().split()))
def LF():
return list(map(float, stdin.readline().split()))
def LI_():
return list(map(lambda x: int(x) - 1, stdin.readline().split()))
def II():
return int(stdin.readline())
def IF():
return float(stdin.readline())
def LS():
return list(map(list, stdin.readline().split()))
def S():
return list(stdin.readline().rstrip())
def IR(n):
return [II() for _ in range(n)]
def LIR(n):
return [LI() for _ in range(n)]
def FR(n):
return [IF() for _ in range(n)]
def LFR(n):
return [LI() for _ in range(n)]
def LIR_(n):
return [LI_() for _ in range(n)]
def SR(n):
return [S() for _ in range(n)]
def LSR(n):
return [LS() for _ in range(n)]
mod = 1000000007
inf = float("INF")
# A
def A():
x, y = LI()
a = [1, 3, 5, 7, 8, 10, 12]
b = [4, 6, 9, 11]
c = [2]
if x in a and y in a:
print("Yes")
return
if x in b and y in b:
print("Yes")
return
if x in c and y in c:
print("Yes")
return
print("No")
return
# B
def B():
return
# C
def C():
return
# D
def D():
return
# E
def E():
return
# F
def F():
return
# G
def G():
return
# H
def H():
return
# Solve
if __name__ == "__main__":
A()
| Statement
Based on some criterion, Snuke divided the integers from 1 through 12 into
three groups as shown in the figure below. Given two integers x and y (1 ≤ x <
y ≤ 12), determine whether they belong to the same group.
 | [{"input": "1 3", "output": "Yes\n \n\n* * *"}, {"input": "2 4", "output": "No"}] |
If x and y belong to the same group, print `Yes`; otherwise, print `No`.
* * * | s279493525 | Runtime Error | p03711 | Input is given from Standard Input in the following format:
x y | x = int(input())
y = int(input())
s1 = [1, 3, 5, 7, 8, 10, 12]
s2 = [4, 6, 9, 11]
if x >= 1:
if x <= 12:
if y >= 1:
if y <= 12:
if x in s1 and y in s1:
print("Yes")
elif x in s2 and y in s2:
print("Yes")
elif x == 2 and y == 2:
print("Yes")
else:
print("No")
| Statement
Based on some criterion, Snuke divided the integers from 1 through 12 into
three groups as shown in the figure below. Given two integers x and y (1 ≤ x <
y ≤ 12), determine whether they belong to the same group.
 | [{"input": "1 3", "output": "Yes\n \n\n* * *"}, {"input": "2 4", "output": "No"}] |
If x and y belong to the same group, print `Yes`; otherwise, print `No`.
* * * | s791848046 | Wrong Answer | p03711 | Input is given from Standard Input in the following format:
x y | import sys
import math
import collections
import itertools
import array
import inspect
# Set max recursion limit
sys.setrecursionlimit(1000000)
# Debug output
def chkprint(*args):
names = {id(v): k for k, v in inspect.currentframe().f_back.f_locals.items()}
print(", ".join(names.get(id(arg), "???") + " = " + repr(arg) for arg in args))
# Binary converter
def to_bin(x):
return bin(x)[2:]
def li_input():
return [int(_) for _ in input().split()]
def gcd(n, m):
if n % m == 0:
return m
else:
return gcd(m, n % m)
def gcd_list(L):
v = L[0]
for i in range(1, len(L)):
v = gcd(v, L[i])
return v
def lcm(n, m):
return (n * m) // gcd(n, m)
def lcm_list(L):
v = L[0]
for i in range(1, len(L)):
v = lcm(v, L[i])
return v
# Width First Search (+ Distance)
def wfs_d(D, N, K):
"""
D: 隣接行列(距離付き)
N: ノード数
K: 始点ノード
"""
dfk = [-1] * (N + 1)
dfk[K] = 0
cps = [(K, 0)]
r = [False] * (N + 1)
r[K] = True
while len(cps) != 0:
n_cps = []
for cp, cd in cps:
for i, dfcp in enumerate(D[cp]):
if dfcp != -1 and not r[i]:
dfk[i] = cd + dfcp
n_cps.append((i, cd + dfcp))
r[i] = True
cps = n_cps[:]
return dfk
# Depth First Search (+Distance)
def dfs_d(v, pre, dist):
"""
v: 現在のノード
pre: 1つ前のノード
dist: 現在の距離
以下は別途用意する
D: 隣接リスト(行列ではない)
D_dfs_d: dfs_d関数で用いる,始点ノードから見た距離リスト
"""
global D
global D_dfs_d
D_dfs_d[v] = dist
for next_v, d in D[v]:
if next_v != pre:
dfs_d(next_v, v, dist + d)
return
def sigma(N):
ans = 0
for i in range(1, N + 1):
ans += i
return ans
class Combination:
def __init__(self, n, mod):
g1 = [1, 1]
g2 = [1, 1]
inverse = [0, 1]
for i in range(2, n + 1):
g1.append((g1[-1] * i) % mod)
inverse.append((-inverse[mod % i] * (mod // i)) % mod)
g2.append((g2[-1] * inverse[-1]) % mod)
self.MOD = mod
self.N = n
self.g1 = g1
self.g2 = g2
self.inverse = inverse
def __call__(self, n, r):
if r < 0 or r > n:
return 0
r = min(r, n - r)
return self.g1[n] * self.g2[r] * self.g2[n - r] % self.MOD
# --------------------------------------------
dp = None
def main():
x, y = input().split()
p1, p2, p3 = "1,3,5,7,8,10,12", "4,6,9,11", "2"
if x in p1:
xg = 1
elif x in p2:
xg = 2
else:
xg = 3
if y in p1:
yg = 1
elif y in p2:
yg = 2
else:
yg = 3
if xg == yg:
print("Yes")
else:
print("No")
main()
| Statement
Based on some criterion, Snuke divided the integers from 1 through 12 into
three groups as shown in the figure below. Given two integers x and y (1 ≤ x <
y ≤ 12), determine whether they belong to the same group.
 | [{"input": "1 3", "output": "Yes\n \n\n* * *"}, {"input": "2 4", "output": "No"}] |
If x and y belong to the same group, print `Yes`; otherwise, print `No`.
* * * | s886621805 | Wrong Answer | p03711 | Input is given from Standard Input in the following format:
x y | H, W = [int(i) for i in input().split()]
if H % 3 == 0 or W % 3 == 0:
print(0)
else:
s = []
for i in range(1, H // 2 + 1):
j = W // 2
a = [i * W, j * (H - i), (W - j) * (H - i)]
b = max(a) - min(a)
s.append(b)
for i in range(1, W // 2 + 1):
j = H // 2
a = [H * i, (W - i) * j, (W - i) * (H - j)]
b = max(a) - min(a)
s.append(b)
print(min(s))
| Statement
Based on some criterion, Snuke divided the integers from 1 through 12 into
three groups as shown in the figure below. Given two integers x and y (1 ≤ x <
y ≤ 12), determine whether they belong to the same group.
 | [{"input": "1 3", "output": "Yes\n \n\n* * *"}, {"input": "2 4", "output": "No"}] |
If x and y belong to the same group, print `Yes`; otherwise, print `No`.
* * * | s087780912 | Accepted | p03711 | Input is given from Standard Input in the following format:
x y | print("YNeos"["2" in input() :: 2])
| Statement
Based on some criterion, Snuke divided the integers from 1 through 12 into
three groups as shown in the figure below. Given two integers x and y (1 ≤ x <
y ≤ 12), determine whether they belong to the same group.
 | [{"input": "1 3", "output": "Yes\n \n\n* * *"}, {"input": "2 4", "output": "No"}] |
If x and y belong to the same group, print `Yes`; otherwise, print `No`.
* * * | s207907184 | Wrong Answer | p03711 | Input is given from Standard Input in the following format:
x y | n1 = [1, 3, 5, 7, 8, 10, 12]
n2 = [4, 6, 9, 11]
n3 = [2]
nums = [map(int, input().split())]
print("Yes" if nums in n1 or nums in n2 or nums in n3 else "No")
| Statement
Based on some criterion, Snuke divided the integers from 1 through 12 into
three groups as shown in the figure below. Given two integers x and y (1 ≤ x <
y ≤ 12), determine whether they belong to the same group.
 | [{"input": "1 3", "output": "Yes\n \n\n* * *"}, {"input": "2 4", "output": "No"}] |
If x and y belong to the same group, print `Yes`; otherwise, print `No`.
* * * | s596567712 | Runtime Error | p03711 | Input is given from Standard Input in the following format:
x y | x,y=map(int,input().split())
a=[0,1,3,1,2,1,2,1,1,2,1,2,1
if a[x]==a[y]:
print("Yes")
else:
print("No")
| Statement
Based on some criterion, Snuke divided the integers from 1 through 12 into
three groups as shown in the figure below. Given two integers x and y (1 ≤ x <
y ≤ 12), determine whether they belong to the same group.
 | [{"input": "1 3", "output": "Yes\n \n\n* * *"}, {"input": "2 4", "output": "No"}] |
If x and y belong to the same group, print `Yes`; otherwise, print `No`.
* * * | s701169803 | Runtime Error | p03711 | Input is given from Standard Input in the following format:
x y | x,y=map(int,input().split())
if x>y:
x,y=y,x
A=[1,3,5,,7,8,10,12]
B=[4,6,9,11]
if x==2 or y==2:
print('No')
elif (x in A and y in B):
print('No')
else:
print('Yes')
| Statement
Based on some criterion, Snuke divided the integers from 1 through 12 into
three groups as shown in the figure below. Given two integers x and y (1 ≤ x <
y ≤ 12), determine whether they belong to the same group.
 | [{"input": "1 3", "output": "Yes\n \n\n* * *"}, {"input": "2 4", "output": "No"}] |
If x and y belong to the same group, print `Yes`; otherwise, print `No`.
* * * | s496491065 | Runtime Error | p03711 | Input is given from Standard Input in the following format:
x y | x,y=map(int,input().split())
group_A=[1,3,5,7,8,10,12]
group_B=[4,6,9,11]
if x in group_A = True and y in group_A =True:
print("Yes")
elif x in group_B = True and y in group_B =True:
print("Yes")
else:
print("No")
| Statement
Based on some criterion, Snuke divided the integers from 1 through 12 into
three groups as shown in the figure below. Given two integers x and y (1 ≤ x <
y ≤ 12), determine whether they belong to the same group.
 | [{"input": "1 3", "output": "Yes\n \n\n* * *"}, {"input": "2 4", "output": "No"}] |
If x and y belong to the same group, print `Yes`; otherwise, print `No`.
* * * | s079833734 | Runtime Error | p03711 | Input is given from Standard Input in the following format:
x y | x,y = map(int, input().split())
if x==2 or y==2:
print("No")
exit()
if x==4 or x==6 or x==9 or x==11:
if y==4 or y==6 or y==9 or y~=11:
print("Yes")
else:
print("No")
else:
print("No")
| Statement
Based on some criterion, Snuke divided the integers from 1 through 12 into
three groups as shown in the figure below. Given two integers x and y (1 ≤ x <
y ≤ 12), determine whether they belong to the same group.
 | [{"input": "1 3", "output": "Yes\n \n\n* * *"}, {"input": "2 4", "output": "No"}] |
If x and y belong to the same group, print `Yes`; otherwise, print `No`.
* * * | s131283911 | Accepted | p03711 | Input is given from Standard Input in the following format:
x y | x, y = map(int, input().split())
t = [0] * 13
t[4] = t[6] = t[9] = t[11] = 1
t[2] = 2
print("Yes" if t[x] == t[y] else "No")
| Statement
Based on some criterion, Snuke divided the integers from 1 through 12 into
three groups as shown in the figure below. Given two integers x and y (1 ≤ x <
y ≤ 12), determine whether they belong to the same group.
 | [{"input": "1 3", "output": "Yes\n \n\n* * *"}, {"input": "2 4", "output": "No"}] |
If x and y belong to the same group, print `Yes`; otherwise, print `No`.
* * * | s806162318 | Runtime Error | p03711 | Input is given from Standard Input in the following format:
x y | # -*- coding; utf-8 -*-
H, W = map(int, input().split())
a = []
for i in range(H):
a.append(map(str, input().split()))
print("#####")
while i < H:
print("#" + str(a[i]) + "#")
i = i + 1
print("#####")
| Statement
Based on some criterion, Snuke divided the integers from 1 through 12 into
three groups as shown in the figure below. Given two integers x and y (1 ≤ x <
y ≤ 12), determine whether they belong to the same group.
 | [{"input": "1 3", "output": "Yes\n \n\n* * *"}, {"input": "2 4", "output": "No"}] |
If x and y belong to the same group, print `Yes`; otherwise, print `No`.
* * * | s826497582 | Accepted | p03711 | Input is given from Standard Input in the following format:
x y | List1 = [1, 3, 5, 7, 8, 10, 12]
List2 = [4, 6, 9, 11]
x, y = map(int, input().split())
count1 = 0
count2 = 0
if x in List1:
count1 += 1
if y in List1:
count1 += 1
if x in List2:
count2 += 1
if y in List2:
count2 += 1
print("Yes" if count1 == 2 or count2 == 2 else "No")
| Statement
Based on some criterion, Snuke divided the integers from 1 through 12 into
three groups as shown in the figure below. Given two integers x and y (1 ≤ x <
y ≤ 12), determine whether they belong to the same group.
 | [{"input": "1 3", "output": "Yes\n \n\n* * *"}, {"input": "2 4", "output": "No"}] |
If x and y belong to the same group, print `Yes`; otherwise, print `No`.
* * * | s896841714 | Wrong Answer | p03711 | Input is given from Standard Input in the following format:
x y | class UnionFind:
def __init__(self, n):
self.n = n
self.parents = [-1] * n
def find(self, x):
if self.parents[x] < 0:
return x
else:
self.parents[x] = self.find(self.parents[x])
return self.parents[x]
def union(self, x, y):
x = self.find(x)
y = self.find(y)
| Statement
Based on some criterion, Snuke divided the integers from 1 through 12 into
three groups as shown in the figure below. Given two integers x and y (1 ≤ x <
y ≤ 12), determine whether they belong to the same group.
 | [{"input": "1 3", "output": "Yes\n \n\n* * *"}, {"input": "2 4", "output": "No"}] |
If x and y belong to the same group, print `Yes`; otherwise, print `No`.
* * * | s646435535 | Runtime Error | p03711 | Input is given from Standard Input in the following format:
x y | H, W = buf.split()
H = int(H)
W = int(W)
pic = []
for i in range(H):
pic.append(input())
# for row in pic:
# print(row)
for i in range(W + 2):
print("#", end="")
print()
for i in range(H):
print("#" + pic[i] + "#")
for i in range(W + 2):
print("#", end="")
| Statement
Based on some criterion, Snuke divided the integers from 1 through 12 into
three groups as shown in the figure below. Given two integers x and y (1 ≤ x <
y ≤ 12), determine whether they belong to the same group.
 | [{"input": "1 3", "output": "Yes\n \n\n* * *"}, {"input": "2 4", "output": "No"}] |
If x and y belong to the same group, print `Yes`; otherwise, print `No`.
* * * | s355690539 | Runtime Error | p03711 | Input is given from Standard Input in the following format:
x y | ls1 = [[1,3,5,7,8,10,12],[4,6,9,11],[2]]
a,b = int(input().split())
if a in ls1[2]:
print('NO')
else if a in ls1[1]:
if b in ls1[1]:
print("Yes")
else:
print("No")
else if a in ls1[0]:
if b in ls1[0]:
print("Yes")
else:
print("No")
| Statement
Based on some criterion, Snuke divided the integers from 1 through 12 into
three groups as shown in the figure below. Given two integers x and y (1 ≤ x <
y ≤ 12), determine whether they belong to the same group.
 | [{"input": "1 3", "output": "Yes\n \n\n* * *"}, {"input": "2 4", "output": "No"}] |
If x and y belong to the same group, print `Yes`; otherwise, print `No`.
* * * | s892705086 | Runtime Error | p03711 | Input is given from Standard Input in the following format:
x y | x,y=map(int,input().split())
a=[1,3,5,7,8,10,12]
b=[4,6,9,11]
c=[2]
if x=2 or y=2:
print("No")
for v in a:
if x=v:
for w in a:
if w =y:
print("Yes")
for v in b:
if x=v:
for w in b:
if w =y:
print("Yes")
else:
print("No")
| Statement
Based on some criterion, Snuke divided the integers from 1 through 12 into
three groups as shown in the figure below. Given two integers x and y (1 ≤ x <
y ≤ 12), determine whether they belong to the same group.
 | [{"input": "1 3", "output": "Yes\n \n\n* * *"}, {"input": "2 4", "output": "No"}] |
If x and y belong to the same group, print `Yes`; otherwise, print `No`.
* * * | s576299319 | Runtime Error | p03711 | Input is given from Standard Input in the following format:
x y | import numpy as np
#from scipy.interpolate import interpld
from matplotlib import pyplot as plt
%matplotlib inline
import sys
x, y = [int(i) for i in input().split()]
list = [1,3,5,7,8,10,12,4,6,9,11,2,0]
slice1 = list[0:7]
slice2 = list[7:11]
slice3 = list[11:12]
if x in slice1 and y in slice1:
print('Yes')
elif x in slice2 and y in slice2:
print ('Yes')
elif x in slice3 and y in slice3:
print ('Yes')
else:
print ('No') | Statement
Based on some criterion, Snuke divided the integers from 1 through 12 into
three groups as shown in the figure below. Given two integers x and y (1 ≤ x <
y ≤ 12), determine whether they belong to the same group.
 | [{"input": "1 3", "output": "Yes\n \n\n* * *"}, {"input": "2 4", "output": "No"}] |
If x and y belong to the same group, print `Yes`; otherwise, print `No`.
* * * | s006132908 | Runtime Error | p03711 | Input is given from Standard Input in the following format:
x y | x、y = map(input().split())
group1 = (1, 3, 5, 7, 8, 10, 12)
group2 = (4, 6, 9, 11)
group3 = 2
if (x in group1) and (y in group1):
print("Yes")
if (x in group2) and (y in group2):
print("Yes")
if (x in group3) and (y in group3):
print("Yes")
else:
print("No")
| Statement
Based on some criterion, Snuke divided the integers from 1 through 12 into
three groups as shown in the figure below. Given two integers x and y (1 ≤ x <
y ≤ 12), determine whether they belong to the same group.
 | [{"input": "1 3", "output": "Yes\n \n\n* * *"}, {"input": "2 4", "output": "No"}] |
If x and y belong to the same group, print `Yes`; otherwise, print `No`.
* * * | s910648867 | Runtime Error | p03711 | Input is given from Standard Input in the following format:
x y | l_1 = [1,3,5,7,8,10,12]
l_2 = [4,6,9,11]
l_3 = [2]
x,y = map(list(int,input()).split())
if x == 2:
if y == 2:
print("yes")
else:
print("no")
elif x in l_1:
if y in x_1:
print("yes")
else:
print("no")
else x in l_2:
if y in l_2:
print("yes")
else:
print("no") | Statement
Based on some criterion, Snuke divided the integers from 1 through 12 into
three groups as shown in the figure below. Given two integers x and y (1 ≤ x <
y ≤ 12), determine whether they belong to the same group.
 | [{"input": "1 3", "output": "Yes\n \n\n* * *"}, {"input": "2 4", "output": "No"}] |
If x and y belong to the same group, print `Yes`; otherwise, print `No`.
* * * | s573356802 | Runtime Error | p03711 | Input is given from Standard Input in the following format:
x y | x,y = map(int, input().split())
if x==2:
print('No')
elif x==4 or x==6 or x==9 or x==11
if y==6 or y==9 or y==11:
print('Yes')
else: print('No')
else:
if y==3 or y==5 or y==7 or y==8 or y==10 or y==12:
print('Yes')
else: print('No') | Statement
Based on some criterion, Snuke divided the integers from 1 through 12 into
three groups as shown in the figure below. Given two integers x and y (1 ≤ x <
y ≤ 12), determine whether they belong to the same group.
 | [{"input": "1 3", "output": "Yes\n \n\n* * *"}, {"input": "2 4", "output": "No"}] |
If x and y belong to the same group, print `Yes`; otherwise, print `No`.
* * * | s286181594 | Runtime Error | p03711 | Input is given from Standard Input in the following format:
x y | import sys
l_1 = [1,3,5,7,8,10,12]
l_2 = [4,6,9,11]
x, y = map(int, input().split())
if x == 2:
if y == 2:
print("yes")
else:
print("no")
elif x in l_1:
if y in x_1:
print("yes")
else:
print("no")
else x in l_2:
if y in l_2:
print("yes")
else:
print("no") | Statement
Based on some criterion, Snuke divided the integers from 1 through 12 into
three groups as shown in the figure below. Given two integers x and y (1 ≤ x <
y ≤ 12), determine whether they belong to the same group.
 | [{"input": "1 3", "output": "Yes\n \n\n* * *"}, {"input": "2 4", "output": "No"}] |
If x and y belong to the same group, print `Yes`; otherwise, print `No`.
* * * | s713169061 | Runtime Error | p03711 | Input is given from Standard Input in the following format:
x y | import sys
X, Y=map(int,input().split())
if X==2 or Y==2:
print('No')
sys.exit()
elif X==4 or X==6 or X==9 or X==11:
if Y==6 or Y==9 or Y==11:
print('Yes')
sys.exit()
else:
print('No')
sys.exit()
else:
if Y==3 or Y==5 or Y==7 or Y==8 or Y==10 Y==12:
print('Yes')
sys.exit()
else:
print('No')
sys.exit()
| Statement
Based on some criterion, Snuke divided the integers from 1 through 12 into
three groups as shown in the figure below. Given two integers x and y (1 ≤ x <
y ≤ 12), determine whether they belong to the same group.
 | [{"input": "1 3", "output": "Yes\n \n\n* * *"}, {"input": "2 4", "output": "No"}] |
If x and y belong to the same group, print `Yes`; otherwise, print `No`.
* * * | s772088225 | Runtime Error | p03711 | Input is given from Standard Input in the following format:
x y | x,y = map(int, input().split())
a = [1,3,5,7,8,10,12]
b = [4,6,9,11]
if (x in a and y in a) or x (in b and y in b):
print("Yes")
else:
print("No") | Statement
Based on some criterion, Snuke divided the integers from 1 through 12 into
three groups as shown in the figure below. Given two integers x and y (1 ≤ x <
y ≤ 12), determine whether they belong to the same group.
 | [{"input": "1 3", "output": "Yes\n \n\n* * *"}, {"input": "2 4", "output": "No"}] |
If x and y belong to the same group, print `Yes`; otherwise, print `No`.
* * * | s710877322 | Runtime Error | p03711 | Input is given from Standard Input in the following format:
x y | x,y = map(int,input().split())
g1 = [1,3,5,7,8,10,12]
g2 = [4,6,9,11]
g3 = [2]
print('Yes') if (x and y) in g1 or (x and y) in g2 or (x and y) in g3 print('No') | Statement
Based on some criterion, Snuke divided the integers from 1 through 12 into
three groups as shown in the figure below. Given two integers x and y (1 ≤ x <
y ≤ 12), determine whether they belong to the same group.
 | [{"input": "1 3", "output": "Yes\n \n\n* * *"}, {"input": "2 4", "output": "No"}] |
If x and y belong to the same group, print `Yes`; otherwise, print `No`.
* * * | s959578173 | Runtime Error | p03711 | Input is given from Standard Input in the following format:
x y | print("YNeos"[2 in input() :: 2])
| Statement
Based on some criterion, Snuke divided the integers from 1 through 12 into
three groups as shown in the figure below. Given two integers x and y (1 ≤ x <
y ≤ 12), determine whether they belong to the same group.
 | [{"input": "1 3", "output": "Yes\n \n\n* * *"}, {"input": "2 4", "output": "No"}] |
If x and y belong to the same group, print `Yes`; otherwise, print `No`.
* * * | s355281340 | Runtime Error | p03711 | Input is given from Standard Input in the following format:
x y | nput().split());a=[4,6,9,11];b=[1,3,5,7,8,10,12];print(['No','Yes'][(x in a and y in a)+x in b and y in b]) | Statement
Based on some criterion, Snuke divided the integers from 1 through 12 into
three groups as shown in the figure below. Given two integers x and y (1 ≤ x <
y ≤ 12), determine whether they belong to the same group.
 | [{"input": "1 3", "output": "Yes\n \n\n* * *"}, {"input": "2 4", "output": "No"}] |
If x and y belong to the same group, print `Yes`; otherwise, print `No`.
* * * | s779105058 | Runtime Error | p03711 | Input is given from Standard Input in the following format:
x y | s = "0131212112121"
print("Yes" if s[x] == s[y] else "No")
| Statement
Based on some criterion, Snuke divided the integers from 1 through 12 into
three groups as shown in the figure below. Given two integers x and y (1 ≤ x <
y ≤ 12), determine whether they belong to the same group.
 | [{"input": "1 3", "output": "Yes\n \n\n* * *"}, {"input": "2 4", "output": "No"}] |
If x and y belong to the same group, print `Yes`; otherwise, print `No`.
* * * | s781218931 | Runtime Error | p03711 | Input is given from Standard Input in the following format:
x y | x,y=[int(i) for in input().split()]
a=[[1,3,5,7,8,10,12],[4,6,9,11]]
ans="No"
for i in [0,1]:
if a[i].count(x) and a[i].count(y):
ans="Yes"
print(ans) | Statement
Based on some criterion, Snuke divided the integers from 1 through 12 into
three groups as shown in the figure below. Given two integers x and y (1 ≤ x <
y ≤ 12), determine whether they belong to the same group.
 | [{"input": "1 3", "output": "Yes\n \n\n* * *"}, {"input": "2 4", "output": "No"}] |
If x and y belong to the same group, print `Yes`; otherwise, print `No`.
* * * | s267152993 | Wrong Answer | p03711 | Input is given from Standard Input in the following format:
x y | A = {1, 3, 5, 7, 8, 10, 12}
B = {4, 6, 9, 11}
C = {2}
D = {map(int, input().split())}
print("Yes" if D <= A or D <= B or D <= C else "No")
| Statement
Based on some criterion, Snuke divided the integers from 1 through 12 into
three groups as shown in the figure below. Given two integers x and y (1 ≤ x <
y ≤ 12), determine whether they belong to the same group.
 | [{"input": "1 3", "output": "Yes\n \n\n* * *"}, {"input": "2 4", "output": "No"}] |
If x and y belong to the same group, print `Yes`; otherwise, print `No`.
* * * | s511893941 | Runtime Error | p03711 | Input is given from Standard Input in the following format:
x y | a=[1,3,5,7,8,10,12]
b=[4,6,9,11]
ans=''
x,y=map(int,input().split(' '))
ans='Yes' if x==y
for c in (a,b):
ans='Yes' if x in c and y in c
if ans=='': ans='No'
print(ans)
| Statement
Based on some criterion, Snuke divided the integers from 1 through 12 into
three groups as shown in the figure below. Given two integers x and y (1 ≤ x <
y ≤ 12), determine whether they belong to the same group.
 | [{"input": "1 3", "output": "Yes\n \n\n* * *"}, {"input": "2 4", "output": "No"}] |
If x and y belong to the same group, print `Yes`; otherwise, print `No`.
* * * | s055252946 | Runtime Error | p03711 | Input is given from Standard Input in the following format:
x y | x,y=map(int,input().split())
a = [1,3,5,7,8,10,12]
b = [4,6,9,11]
c = [2]
if x,y in a:
print("Yes")
elif x,y in b:
print("Yes")
elif x,y in c:
print("Yes")
else:
print("No") | Statement
Based on some criterion, Snuke divided the integers from 1 through 12 into
three groups as shown in the figure below. Given two integers x and y (1 ≤ x <
y ≤ 12), determine whether they belong to the same group.
 | [{"input": "1 3", "output": "Yes\n \n\n* * *"}, {"input": "2 4", "output": "No"}] |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.