output_description stringlengths 15 956 | submission_id stringlengths 10 10 | status stringclasses 3 values | problem_id stringlengths 6 6 | input_description stringlengths 9 2.55k | attempt stringlengths 1 13.7k | problem_description stringlengths 7 5.24k | samples stringlengths 2 2.72k |
|---|---|---|---|---|---|---|---|
Print the maximum possible length of the sequence.
* * * | s314166744 | Runtime Error | p03481 | Input is given from Standard Input in the following format:
X Y | x,y=map(int,input().split())
import math
p=math.log(y/x,2)+10**(-18)
print(int(p)+1 | Statement
As a token of his gratitude, Takahashi has decided to give his mother an
integer sequence. The sequence A needs to satisfy the conditions below:
* A consists of integers between X and Y (inclusive).
* For each 1\leq i \leq |A|-1, A_{i+1} is a multiple of A_i and strictly greater than A_i.
Find the maximum possible length of the sequence. | [{"input": "3 20", "output": "3\n \n\nThe sequence 3,6,18 satisfies the conditions.\n\n* * *"}, {"input": "25 100", "output": "3\n \n\n* * *"}, {"input": "314159265 358979323846264338", "output": "31"}] |
Print the maximum possible length of the sequence.
* * * | s908569564 | Runtime Error | p03481 | Input is given from Standard Input in the following format:
X Y | 3 20 | Statement
As a token of his gratitude, Takahashi has decided to give his mother an
integer sequence. The sequence A needs to satisfy the conditions below:
* A consists of integers between X and Y (inclusive).
* For each 1\leq i \leq |A|-1, A_{i+1} is a multiple of A_i and strictly greater than A_i.
Find the maximum possible length of the sequence. | [{"input": "3 20", "output": "3\n \n\nThe sequence 3,6,18 satisfies the conditions.\n\n* * *"}, {"input": "25 100", "output": "3\n \n\n* * *"}, {"input": "314159265 358979323846264338", "output": "31"}] |
Print the maximum possible length of the sequence.
* * * | s761673283 | Runtime Error | p03481 | Input is given from Standard Input in the following format:
X Y | x, y = map(int, input().split())
print(len(str(bin(y//x))[2:]+1) | Statement
As a token of his gratitude, Takahashi has decided to give his mother an
integer sequence. The sequence A needs to satisfy the conditions below:
* A consists of integers between X and Y (inclusive).
* For each 1\leq i \leq |A|-1, A_{i+1} is a multiple of A_i and strictly greater than A_i.
Find the maximum possible length of the sequence. | [{"input": "3 20", "output": "3\n \n\nThe sequence 3,6,18 satisfies the conditions.\n\n* * *"}, {"input": "25 100", "output": "3\n \n\n* * *"}, {"input": "314159265 358979323846264338", "output": "31"}] |
Print the maximum possible length of the sequence.
* * * | s757070269 | Runtime Error | p03481 | Input is given from Standard Input in the following format:
X Y | print(int(1 + np.floor((np.log(y) - np.log(x) + 0.00000001) / np.log(2))))
| Statement
As a token of his gratitude, Takahashi has decided to give his mother an
integer sequence. The sequence A needs to satisfy the conditions below:
* A consists of integers between X and Y (inclusive).
* For each 1\leq i \leq |A|-1, A_{i+1} is a multiple of A_i and strictly greater than A_i.
Find the maximum possible length of the sequence. | [{"input": "3 20", "output": "3\n \n\nThe sequence 3,6,18 satisfies the conditions.\n\n* * *"}, {"input": "25 100", "output": "3\n \n\n* * *"}, {"input": "314159265 358979323846264338", "output": "31"}] |
Print the maximum possible length of the sequence.
* * * | s687641619 | Runtime Error | p03481 | Input is given from Standard Input in the following format:
X Y | def solve():
a,y = map(int,input().split())
ans = 1
while(a<=y){
a*=2
ans+=1
}
print(ans)
if __name__ == "__main__":
solve() | Statement
As a token of his gratitude, Takahashi has decided to give his mother an
integer sequence. The sequence A needs to satisfy the conditions below:
* A consists of integers between X and Y (inclusive).
* For each 1\leq i \leq |A|-1, A_{i+1} is a multiple of A_i and strictly greater than A_i.
Find the maximum possible length of the sequence. | [{"input": "3 20", "output": "3\n \n\nThe sequence 3,6,18 satisfies the conditions.\n\n* * *"}, {"input": "25 100", "output": "3\n \n\n* * *"}, {"input": "314159265 358979323846264338", "output": "31"}] |
Print the maximum possible length of the sequence.
* * * | s592342034 | Runtime Error | p03481 | Input is given from Standard Input in the following format:
X Y | x,y = tuple(map(int,input().split()))
for i in range(1,10*4):
x<<=1
if x>y:
print(i)
break | Statement
As a token of his gratitude, Takahashi has decided to give his mother an
integer sequence. The sequence A needs to satisfy the conditions below:
* A consists of integers between X and Y (inclusive).
* For each 1\leq i \leq |A|-1, A_{i+1} is a multiple of A_i and strictly greater than A_i.
Find the maximum possible length of the sequence. | [{"input": "3 20", "output": "3\n \n\nThe sequence 3,6,18 satisfies the conditions.\n\n* * *"}, {"input": "25 100", "output": "3\n \n\n* * *"}, {"input": "314159265 358979323846264338", "output": "31"}] |
For each query, print the coordinate of the projection point x. The output
values should be in a decimal fraction with an error less than 0.00000001. | s770189976 | Accepted | p02290 | 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. | sx, sy, ex, ey = (int(n) for n in input().split(" "))
trial = int(input())
for _ in range(trial):
x, y = (int(n) for n in input().split(" "))
if sx == ex:
print(sx, y)
elif sy == ey:
print(x, sy)
else:
grad = (ey - sy) / (ex - sx)
y_seg = sy - (grad * sx)
per_grad = -1 / grad
per_y_seg = y - (per_grad * x)
ans_x = (y_seg - per_y_seg) / (-1 * (grad - per_grad))
ans_y = per_grad * ans_x + per_y_seg
print(ans_x, ans_y)
| Projection
For given three points p1, p2, p, find the projection 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 0.0000000000\n 0.0000000000 0.0000000000\n 1.0000000000 0.0000000000"}, {"input": "0 0 3 4\n 1\n 2 5", "output": "3.1200000000 4.1600000000"}] |
For each query, print the coordinate of the projection point x. The output
values should be in a decimal fraction with an error less than 0.00000001. | s401692059 | Accepted | p02290 | 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. | x, y, s, t = map(float, input().split())
a = int(input())
s -= x
t -= y
while a:
a -= 1
p, q = map(float, input().split())
p -= x
q -= y
ans_x = s * (q * t + p * s) / (t * t + s * s)
ans_y = t * (q * t + p * s) / (t * t + s * s)
print(x + ans_x, y + ans_y)
| Projection
For given three points p1, p2, p, find the projection 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 0.0000000000\n 0.0000000000 0.0000000000\n 1.0000000000 0.0000000000"}, {"input": "0 0 3 4\n 1\n 2 5", "output": "3.1200000000 4.1600000000"}] |
For each query, print the coordinate of the projection point x. The output
values should be in a decimal fraction with an error less than 0.00000001. | s317722046 | Accepted | p02290 | 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. | a, b, c, d = map(float, input().split())
c -= a
d -= b
for _ in [0] * int(input()):
x, y = map(float, input().split())
x -= a
y -= b
z = (c * x + d * y) / (c * c + d * d)
print(a + c * z, b + d * z)
| Projection
For given three points p1, p2, p, find the projection 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 0.0000000000\n 0.0000000000 0.0000000000\n 1.0000000000 0.0000000000"}, {"input": "0 0 3 4\n 1\n 2 5", "output": "3.1200000000 4.1600000000"}] |
For each query, print the coordinate of the projection point x. The output
values should be in a decimal fraction with an error less than 0.00000001. | s490727569 | Accepted | p02290 | 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 Vector2:
def __init__(self, x, y):
self.x = x
self.y = y
def __add__(self, v):
return Vector2(self.x + v.x, self.y + v.y)
def __sub__(self, v):
return Vector2(self.x - v.x, self.y - v.y)
def __mul__(self, v):
return Vector2(self.x * v, self.y * v)
def __truediv__(self, v):
return Vector2(self.x / v, self.y / v)
def __abs__(self):
return math.sqrt(float(self.x * self.x + self.y * self.y))
def dot(self, v):
return self.x * v.x + self.y * v.y
def cross(self, v):
return self.x * v.y - self.y * v.x
def norm(self):
d = abs(self)
return Vector2(self.x / d, self.y / d)
x1, y1, x2, y2 = map(int, input().split())
v12 = Vector2(x2 - x1, y2 - y1).norm()
q = int(input())
for i in range(q):
x, y = map(int, input().split())
v = Vector2(x - x1, y - y1)
d = v12.dot(v)
ans = Vector2(x1 + v12.x * d, y1 + v12.y * d)
print(f"{ans.x} {ans.y}")
| Projection
For given three points p1, p2, p, find the projection 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 0.0000000000\n 0.0000000000 0.0000000000\n 1.0000000000 0.0000000000"}, {"input": "0 0 3 4\n 1\n 2 5", "output": "3.1200000000 4.1600000000"}] |
For each query, print the coordinate of the projection point x. The output
values should be in a decimal fraction with an error less than 0.00000001. | s165098181 | Accepted | p02290 | 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. | from math import pi, cos, sin, atan2
EPS = 10 ** (-9)
def eq(value1, value2):
return abs(value1 - value2) <= EPS
class Point:
def __init__(self, x, y):
self.x = x
self.y = y
self.arg = atan2(y, x) # -PI ~ PI
def __str__(self):
return "{0:.8f} {1:.8f}".format(self.x, self.y)
def __add__(self, other):
return Point(self.x + other.x, self.y + other.y)
def __sub__(self, other):
return Point(self.x - other.x, self.y - other.y)
def __mul__(self, scal):
return Point(self.x * scal, self.y * scal)
def __truediv__(self, scal):
return Point(self.x / scal, self.y / scal)
def __eq__(self, other):
return eq(self.x, other.x) and eq(self.y, other.y)
# 原点からの距離
def __abs__(self):
return (self.x**2 + self.y**2) ** 0.5
# 原点を中心にrad角だけ回転した点
def Rotation(vec: Point, rad):
return Point(
vec.x * cos(rad) - vec.y * sin(rad), vec.x * sin(rad) + vec.y * cos(rad)
)
class Circle:
def __init__(self, p, r):
self.p = p
self.r = r
class Line:
# 点a, bを通る
def __init__(self, a, b):
self.a = a
self.b = b
self.arg = (a - b).arg % pi
def __str__(self):
return "[({0}, {1}) - ({2}, {3})]".format(
self.a.x, self.a.y, self.b.x, self.b.y
)
# pointを通って平行
def par(self, point):
return Line(point, point + (self.a - self.b))
# pointを通って垂直
def tan(self, point):
return Line(point, point + Rotation(self.a - self.b, pi / 2))
class Segment(Line):
def __init__(self, a, b):
super(Line, self).__init__(a, b)
# 符号付き面積
def cross(vec1: Point, vec2: Point):
return vec1.x * vec2.y - vec1.y * vec2.x
# 内積
def dot(vec1: Point, vec2: Point):
return vec1.x * vec2.x + vec1.y * vec2.y
# 点a->b->cの回転方向
def ccw(a, b, c):
if cross(b - a, c - a) > EPS:
return +1 # COUNTER_CLOCKWISE
if cross(b - a, c - a) < -EPS:
return -1 # CLOCKWISE
if dot(c - a, b - a) < -EPS:
return +2 # c -> a -> b
if abs(b - a) < abs(c - a):
return -2 # a -> b -> c
return 0 # a -> c -> b
# pのlへの射影
def projection(l, p):
t = dot(l.b - l.a, p - l.a) / abs(l.a - l.b) ** 2
return l.a + (l.b - l.a) * t
# pのlによる反射
def reflection(l, p):
return p + (projection(l, p) - p) * 2
def isPararell(l1, l2):
return eq(cross(l1.a - l1.b, l2.a - l2.b), 0)
def isVertical(l1, l2):
return eq(dot(l1.a - l1.b, l2.a - l2.b), 0)
def isIntersect_lp(l, p):
return abs(ccw(l.a, l.b, p)) != 1
def isIntersect_ll(l1, l2):
return not isPararell(l1, l2) or isIntersect_lp(l1, l2.a)
def isIntersect_sp(s, p):
return ccw(s.a, s.b, p) == 0
def isIntersect_ss(s1, s2):
return (
ccw(s1.a, s1.b, s2.a) * ccw(s1.a, s1.b, s2.b) <= 0
and ccw(s2.a, s2.b, s1.a) * ccw(s2.a, s2.b, s1.b) <= 0
)
def isIntersect_ls(l, s):
return cross(l.b - l.a, s.a - l.a) * cross(l.b - l.a, s.b - l.a) < EPS
def isIntersect_cp(c, p):
return abs(abs(c.p - p) - c.r) < EPS
def isIntersect_cl(c, l):
return distance_lp(l, c.p) <= c.r + EPS
def isIntersect_cs(c, s):
pass
def isIntersect_cc(c1, c2):
pass
def distance_pp(p1, p2):
return abs(p1 - p2)
def distance_lp(l, p):
return abs(projection(l, p) - p)
def distance_ll(l1, l2):
return 0 if isIntersect_ll(l1, l2) else distance_lp(l1, l2.a)
def distance_sp(s, p):
r = projection(s, p)
if isIntersect_sp(s, r):
return abs(r - p)
return min(abs(s.a - p), abs(s.b - p))
def distance_ss(s1, s2):
if isIntersect_ss(s1, s2):
return 0
return min(
[
distance_sp(s1, s2.a),
distance_sp(s1, s2.b),
distance_sp(s2, s1.a),
distance_sp(s2, s1.b),
]
)
def distance_ls(l, s):
if isIntersect_ls(l, s):
return 0
return min(distance_lp(l, s.a), distance_lp(l, s.b))
def crosspoint_ll(l1, l2):
A = cross(l1.b - l1.a, l2.b - l2.a)
B = cross(l1.b - l1.a, l1.b - l2.a)
if eq(abs(A), 0) and eq(abs(B), 0):
return l2.a
return l2.a + (l2.b - l2.a) * B / A
def crosspoint_ss(s1, s2):
return crosspoint_ll(s1, s2)
def crosspoint_lc(l, c):
if eq(distance_lp(l, c.p), c.r):
return [c.p]
p = projection(l, c.p)
e = (l.b - l.a) / abs(l.b - l.a)
dis = (c.r**2 - abs(p - c.p) ** 2) ** 0.5
return [p + e * dis, p - e * dis]
def crosspoint_sc(s, c):
pass
def crosspoint_cc(c1, c2):
d = abs(c1.p - c2.p)
if not abs(c1.r - c2.r) <= d <= c1.r + c2.r:
return []
mid_p = (
c2.p * (c1.r**2 - c2.r**2 + d**2) + c1.p * (c2.r**2 - c1.r**2 + d**2)
) / (2 * d**2)
tanvec = Rotation(c1.p - c2.p, pi / 2)
return crosspoint_lc(Line(mid_p, mid_p + tanvec), c1)
# pからのcの接点
def tangent_cp(c, p):
return crosspoint_cc(c, Circle(p, (abs(p - c.p) ** 2 - c.r**2) ** 0.5))
import sys
input = sys.stdin.readline
def verify_1A():
p1x, p1y, p2x, p2y = map(int, input().split())
l = Line(Point(p1x, p1y), Point(p2x, p2y))
Q = int(input())
Query = [list(map(int, input().split())) for _ in range(Q)]
for px, py in Query:
p = Point(px, py)
print(projection(l, p))
verify_1A()
| Projection
For given three points p1, p2, p, find the projection 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 0.0000000000\n 0.0000000000 0.0000000000\n 1.0000000000 0.0000000000"}, {"input": "0 0 3 4\n 1\n 2 5", "output": "3.1200000000 4.1600000000"}] |
Print the number of ways to minimize the total length of the cables, modulo
10^9+7.
* * * | s546671229 | Runtime Error | p03878 | The input is given from Standard Input in the following format:
N
a_1
:
a_N
b_1
:
b_N | p=1
s=[0]*2
n=int(input())
q=sorted([[int(input()),i//n]for i in range(2*n)])
for i in q:
if s[1-i[1]]==0:
s[i[1]]+=1
else:
p*=s[1-i[1]]
s[1-[i[1]]-=1
print(p%(10**9+7)) | Statement
There are N computers and N sockets in a one-dimensional world. The coordinate
of the i-th computer is a_i, and the coordinate of the i-th socket is b_i. It
is guaranteed that these 2N coordinates are pairwise distinct.
Snuke wants to connect each computer to a socket using a cable. Each socket
can be connected to only one computer.
In how many ways can he minimize the total length of the cables? Compute the
answer modulo 10^9+7. | [{"input": "2\n 0\n 10\n 20\n 30", "output": "2\n \n\nThere are two optimal connections: 0-20, 10-30 and 0-30, 10-20. In both\nconnections the total length of the cables is 40.\n\n* * *"}, {"input": "3\n 3\n 10\n 8\n 7\n 12\n 5", "output": "1"}] |
Print the number of ways to minimize the total length of the cables, modulo
10^9+7.
* * * | s369160822 | Wrong Answer | p03878 | The input is given from Standard Input in the following format:
N
a_1
:
a_N
b_1
:
b_N | import sys
input = sys.stdin.readline
N = int(input())
mod = 10**9 + 7
a = [0] * N
b = [0] * N
for i in range(N):
a[i] = int(input())
for i in range(N):
b[i] = int(input())
a.sort()
b.sort()
da = [0] * (N - 1)
db = [0] * (N - 1)
for i in range(N - 1):
da[i] = a[i + 1] - a[i]
for i in range(N - 1):
db[i] = b[i + 1] - b[i]
class Factorial:
def __init__(self, n, mod):
self.f = [1]
for i in range(1, n + 1):
self.f.append(self.f[-1] * i % mod)
self.i = [pow(self.f[-1], mod - 2, mod)]
for i in range(1, n + 1)[::-1]:
self.i.append(self.i[-1] * i % mod)
self.i.reverse()
def factorial(self, i):
return self.f[i]
def ifactorial(self, i):
return self.i[i]
def combi(self, n, k):
return self.f[n] * self.i[n - k] % mod * self.i[k] % mod
f = Factorial(N, mod)
res = 1
k = 1
for i in range(N - 1):
if da[i] == db[i]:
k += 1
else:
res *= f.factorial(k)
res %= mod
k = 1
res *= f.factorial(k)
res %= mod
print(res)
| Statement
There are N computers and N sockets in a one-dimensional world. The coordinate
of the i-th computer is a_i, and the coordinate of the i-th socket is b_i. It
is guaranteed that these 2N coordinates are pairwise distinct.
Snuke wants to connect each computer to a socket using a cable. Each socket
can be connected to only one computer.
In how many ways can he minimize the total length of the cables? Compute the
answer modulo 10^9+7. | [{"input": "2\n 0\n 10\n 20\n 30", "output": "2\n \n\nThere are two optimal connections: 0-20, 10-30 and 0-30, 10-20. In both\nconnections the total length of the cables is 40.\n\n* * *"}, {"input": "3\n 3\n 10\n 8\n 7\n 12\n 5", "output": "1"}] |
Print the minimum number of times Fennec needs to do Attack (not counting
Special Move) before winning.
* * * | s781782116 | Runtime Error | p02785 | Input is given from Standard Input in the following format:
N K
H_1 ... H_N | number = list(map(int, input().split()))
score = list(map(int, input().split()))
score.sort()
answer = 0
for i in range(number[1]):
score[number[0] - 1 - i] = 0
for j in range(number[0]):
answer += score[j]
print(answer)
| Statement
Fennec is fighting with N monsters.
The _health_ of the i-th monster is H_i.
Fennec can do the following two actions:
* Attack: Fennec chooses one monster. That monster's health will decrease by 1.
* Special Move: Fennec chooses one monster. That monster's health will become 0.
There is no way other than Attack and Special Move to decrease the monsters'
health.
Fennec wins when all the monsters' healths become 0 or below.
Find the minimum number of times Fennec needs to do Attack (not counting
Special Move) before winning when she can use Special Move at most K times. | [{"input": "3 1\n 4 1 5", "output": "5\n \n\nBy using Special Move on the third monster, and doing Attack four times on the\nfirst monster and once on the second monster, Fennec can win with five\nAttacks.\n\n* * *"}, {"input": "8 9\n 7 9 3 2 3 8 4 6", "output": "0\n \n\nShe can use Special Move on all the monsters.\n\n* * *"}, {"input": "3 0\n 1000000000 1000000000 1000000000", "output": "3000000000\n \n\nWatch out for overflow."}] |
Print the minimum number of times Fennec needs to do Attack (not counting
Special Move) before winning.
* * * | s450331009 | Runtime Error | p02785 | Input is given from Standard Input in the following format:
N K
H_1 ... H_N | N,A=map(int,input().split())
B=sorted(list(int(input()) for i n range(N)))
for j in range(A):
B.pop()
print(sum(B)) | Statement
Fennec is fighting with N monsters.
The _health_ of the i-th monster is H_i.
Fennec can do the following two actions:
* Attack: Fennec chooses one monster. That monster's health will decrease by 1.
* Special Move: Fennec chooses one monster. That monster's health will become 0.
There is no way other than Attack and Special Move to decrease the monsters'
health.
Fennec wins when all the monsters' healths become 0 or below.
Find the minimum number of times Fennec needs to do Attack (not counting
Special Move) before winning when she can use Special Move at most K times. | [{"input": "3 1\n 4 1 5", "output": "5\n \n\nBy using Special Move on the third monster, and doing Attack four times on the\nfirst monster and once on the second monster, Fennec can win with five\nAttacks.\n\n* * *"}, {"input": "8 9\n 7 9 3 2 3 8 4 6", "output": "0\n \n\nShe can use Special Move on all the monsters.\n\n* * *"}, {"input": "3 0\n 1000000000 1000000000 1000000000", "output": "3000000000\n \n\nWatch out for overflow."}] |
Print the minimum number of times Fennec needs to do Attack (not counting
Special Move) before winning.
* * * | s369052244 | Runtime Error | p02785 | Input is given from Standard Input in the following format:
N K
H_1 ... H_N | n,k=[int(x) for x in input().split()]
arr=[int(x) for x in input().split()]
s=0
if(n>k):
for i in range(n-k):
s+=arr[i]
print(s)
else:
print(0)
| Statement
Fennec is fighting with N monsters.
The _health_ of the i-th monster is H_i.
Fennec can do the following two actions:
* Attack: Fennec chooses one monster. That monster's health will decrease by 1.
* Special Move: Fennec chooses one monster. That monster's health will become 0.
There is no way other than Attack and Special Move to decrease the monsters'
health.
Fennec wins when all the monsters' healths become 0 or below.
Find the minimum number of times Fennec needs to do Attack (not counting
Special Move) before winning when she can use Special Move at most K times. | [{"input": "3 1\n 4 1 5", "output": "5\n \n\nBy using Special Move on the third monster, and doing Attack four times on the\nfirst monster and once on the second monster, Fennec can win with five\nAttacks.\n\n* * *"}, {"input": "8 9\n 7 9 3 2 3 8 4 6", "output": "0\n \n\nShe can use Special Move on all the monsters.\n\n* * *"}, {"input": "3 0\n 1000000000 1000000000 1000000000", "output": "3000000000\n \n\nWatch out for overflow."}] |
Print the minimum number of times Fennec needs to do Attack (not counting
Special Move) before winning.
* * * | s421173826 | Runtime Error | p02785 | Input is given from Standard Input in the following format:
N K
H_1 ... H_N | N, K = input().split(" ")
H = list(map(int, input().split()))
H.sort()
K = int(K)
if K >= N:
print(0)
elif: K == 0:
print(sum(H))
else:
print(sum(H[:-K])) | Statement
Fennec is fighting with N monsters.
The _health_ of the i-th monster is H_i.
Fennec can do the following two actions:
* Attack: Fennec chooses one monster. That monster's health will decrease by 1.
* Special Move: Fennec chooses one monster. That monster's health will become 0.
There is no way other than Attack and Special Move to decrease the monsters'
health.
Fennec wins when all the monsters' healths become 0 or below.
Find the minimum number of times Fennec needs to do Attack (not counting
Special Move) before winning when she can use Special Move at most K times. | [{"input": "3 1\n 4 1 5", "output": "5\n \n\nBy using Special Move on the third monster, and doing Attack four times on the\nfirst monster and once on the second monster, Fennec can win with five\nAttacks.\n\n* * *"}, {"input": "8 9\n 7 9 3 2 3 8 4 6", "output": "0\n \n\nShe can use Special Move on all the monsters.\n\n* * *"}, {"input": "3 0\n 1000000000 1000000000 1000000000", "output": "3000000000\n \n\nWatch out for overflow."}] |
Print the minimum number of times Fennec needs to do Attack (not counting
Special Move) before winning.
* * * | s429009026 | Runtime Error | p02785 | Input is given from Standard Input in the following format:
N K
H_1 ... H_N | n,k = map(int,input().split())
h = list(map(input().split())
h.sort()
ans = int(0)
if k >= n:
print(ans)
else:
for i in range(n - k):
ans += int(h[i])
print(ans) | Statement
Fennec is fighting with N monsters.
The _health_ of the i-th monster is H_i.
Fennec can do the following two actions:
* Attack: Fennec chooses one monster. That monster's health will decrease by 1.
* Special Move: Fennec chooses one monster. That monster's health will become 0.
There is no way other than Attack and Special Move to decrease the monsters'
health.
Fennec wins when all the monsters' healths become 0 or below.
Find the minimum number of times Fennec needs to do Attack (not counting
Special Move) before winning when she can use Special Move at most K times. | [{"input": "3 1\n 4 1 5", "output": "5\n \n\nBy using Special Move on the third monster, and doing Attack four times on the\nfirst monster and once on the second monster, Fennec can win with five\nAttacks.\n\n* * *"}, {"input": "8 9\n 7 9 3 2 3 8 4 6", "output": "0\n \n\nShe can use Special Move on all the monsters.\n\n* * *"}, {"input": "3 0\n 1000000000 1000000000 1000000000", "output": "3000000000\n \n\nWatch out for overflow."}] |
Print the minimum number of times Fennec needs to do Attack (not counting
Special Move) before winning.
* * * | s106379829 | Accepted | p02785 | Input is given from Standard Input in the following format:
N K
H_1 ... H_N | m, a = (int(x) for x in input().split())
lm = list(map(int, input().split()))
lm.sort(reverse=True)
# print(lm)
del lm[0:a]
# print(lm)
print(sum(lm))
| Statement
Fennec is fighting with N monsters.
The _health_ of the i-th monster is H_i.
Fennec can do the following two actions:
* Attack: Fennec chooses one monster. That monster's health will decrease by 1.
* Special Move: Fennec chooses one monster. That monster's health will become 0.
There is no way other than Attack and Special Move to decrease the monsters'
health.
Fennec wins when all the monsters' healths become 0 or below.
Find the minimum number of times Fennec needs to do Attack (not counting
Special Move) before winning when she can use Special Move at most K times. | [{"input": "3 1\n 4 1 5", "output": "5\n \n\nBy using Special Move on the third monster, and doing Attack four times on the\nfirst monster and once on the second monster, Fennec can win with five\nAttacks.\n\n* * *"}, {"input": "8 9\n 7 9 3 2 3 8 4 6", "output": "0\n \n\nShe can use Special Move on all the monsters.\n\n* * *"}, {"input": "3 0\n 1000000000 1000000000 1000000000", "output": "3000000000\n \n\nWatch out for overflow."}] |
Print the minimum number of times Fennec needs to do Attack (not counting
Special Move) before winning.
* * * | s259502204 | Accepted | p02785 | Input is given from Standard Input in the following format:
N K
H_1 ... H_N | input1 = input().split()
N = int(input1[0])
K = int(input1[1])
input2 = input().split()
Monster_list = list(map(int, input2))
Monster_list.sort(reverse=True)
del Monster_list[0:K]
print(sum(Monster_list))
| Statement
Fennec is fighting with N monsters.
The _health_ of the i-th monster is H_i.
Fennec can do the following two actions:
* Attack: Fennec chooses one monster. That monster's health will decrease by 1.
* Special Move: Fennec chooses one monster. That monster's health will become 0.
There is no way other than Attack and Special Move to decrease the monsters'
health.
Fennec wins when all the monsters' healths become 0 or below.
Find the minimum number of times Fennec needs to do Attack (not counting
Special Move) before winning when she can use Special Move at most K times. | [{"input": "3 1\n 4 1 5", "output": "5\n \n\nBy using Special Move on the third monster, and doing Attack four times on the\nfirst monster and once on the second monster, Fennec can win with five\nAttacks.\n\n* * *"}, {"input": "8 9\n 7 9 3 2 3 8 4 6", "output": "0\n \n\nShe can use Special Move on all the monsters.\n\n* * *"}, {"input": "3 0\n 1000000000 1000000000 1000000000", "output": "3000000000\n \n\nWatch out for overflow."}] |
Print the minimum number of times Fennec needs to do Attack (not counting
Special Move) before winning.
* * * | s401158603 | Wrong Answer | p02785 | Input is given from Standard Input in the following format:
N K
H_1 ... H_N | n, k = (int(z) for z in input().split())
a = [int(z) for z in input().split()]
a.sort()
sm = 0
for i in range(k, n):
sm += a[i]
print(sm)
| Statement
Fennec is fighting with N monsters.
The _health_ of the i-th monster is H_i.
Fennec can do the following two actions:
* Attack: Fennec chooses one monster. That monster's health will decrease by 1.
* Special Move: Fennec chooses one monster. That monster's health will become 0.
There is no way other than Attack and Special Move to decrease the monsters'
health.
Fennec wins when all the monsters' healths become 0 or below.
Find the minimum number of times Fennec needs to do Attack (not counting
Special Move) before winning when she can use Special Move at most K times. | [{"input": "3 1\n 4 1 5", "output": "5\n \n\nBy using Special Move on the third monster, and doing Attack four times on the\nfirst monster and once on the second monster, Fennec can win with five\nAttacks.\n\n* * *"}, {"input": "8 9\n 7 9 3 2 3 8 4 6", "output": "0\n \n\nShe can use Special Move on all the monsters.\n\n* * *"}, {"input": "3 0\n 1000000000 1000000000 1000000000", "output": "3000000000\n \n\nWatch out for overflow."}] |
Print the minimum number of times Fennec needs to do Attack (not counting
Special Move) before winning.
* * * | s443546054 | Wrong Answer | p02785 | Input is given from Standard Input in the following format:
N K
H_1 ... H_N | N, K = [int(i) for i in input().split()]
mon_list = [int(i) for i in input().split()]
mon_list = sorted(mon_list, reverse=True)
if N <= K:
output = 0
else:
if K != 0:
output = sum(mon_list[:K])
else:
output = sum(mon_list)
print(output)
| Statement
Fennec is fighting with N monsters.
The _health_ of the i-th monster is H_i.
Fennec can do the following two actions:
* Attack: Fennec chooses one monster. That monster's health will decrease by 1.
* Special Move: Fennec chooses one monster. That monster's health will become 0.
There is no way other than Attack and Special Move to decrease the monsters'
health.
Fennec wins when all the monsters' healths become 0 or below.
Find the minimum number of times Fennec needs to do Attack (not counting
Special Move) before winning when she can use Special Move at most K times. | [{"input": "3 1\n 4 1 5", "output": "5\n \n\nBy using Special Move on the third monster, and doing Attack four times on the\nfirst monster and once on the second monster, Fennec can win with five\nAttacks.\n\n* * *"}, {"input": "8 9\n 7 9 3 2 3 8 4 6", "output": "0\n \n\nShe can use Special Move on all the monsters.\n\n* * *"}, {"input": "3 0\n 1000000000 1000000000 1000000000", "output": "3000000000\n \n\nWatch out for overflow."}] |
Print the minimum number of times Fennec needs to do Attack (not counting
Special Move) before winning.
* * * | s396861931 | Runtime Error | p02785 | Input is given from Standard Input in the following format:
N K
H_1 ... H_N | N, K = map(int, input().split())
ListH = list(map(int, input().split()))
#ListH.sort(reverse=True)
sum=0
if N<=K:
print(0)
else:
for i in range(N-K):
sum+=ListH[i]
print(sum) | Statement
Fennec is fighting with N monsters.
The _health_ of the i-th monster is H_i.
Fennec can do the following two actions:
* Attack: Fennec chooses one monster. That monster's health will decrease by 1.
* Special Move: Fennec chooses one monster. That monster's health will become 0.
There is no way other than Attack and Special Move to decrease the monsters'
health.
Fennec wins when all the monsters' healths become 0 or below.
Find the minimum number of times Fennec needs to do Attack (not counting
Special Move) before winning when she can use Special Move at most K times. | [{"input": "3 1\n 4 1 5", "output": "5\n \n\nBy using Special Move on the third monster, and doing Attack four times on the\nfirst monster and once on the second monster, Fennec can win with five\nAttacks.\n\n* * *"}, {"input": "8 9\n 7 9 3 2 3 8 4 6", "output": "0\n \n\nShe can use Special Move on all the monsters.\n\n* * *"}, {"input": "3 0\n 1000000000 1000000000 1000000000", "output": "3000000000\n \n\nWatch out for overflow."}] |
Print the minimum number of times Fennec needs to do Attack (not counting
Special Move) before winning.
* * * | s312736281 | Accepted | p02785 | Input is given from Standard Input in the following format:
N K
H_1 ... H_N | # -*- coding: utf-8 -*-
import sys
def input():
return sys.stdin.readline().strip()
def list2d(a, b, c):
return [[c] * b for i in range(a)]
def list3d(a, b, c, d):
return [[[d] * c for j in range(b)] for i in range(a)]
def list4d(a, b, c, d, e):
return [[[[e] * d for j in range(c)] for j in range(b)] for i in range(a)]
def ceil(x, y=1):
return int(-(-x // y))
def INT():
return int(input())
def MAP():
return map(int, input().split())
def LIST(N=None):
return list(MAP()) if N is None else [INT() for i in range(N)]
def Yes():
print("Yes")
def No():
print("No")
def YES():
print("YES")
def NO():
print("NO")
sys.setrecursionlimit(10**9)
INF = 10**18
MOD = 10**9 + 7
N, K = MAP()
A = sorted(LIST(), reverse=1)
if K >= N:
print(0)
exit()
A = A[K:]
print(sum(A))
| Statement
Fennec is fighting with N monsters.
The _health_ of the i-th monster is H_i.
Fennec can do the following two actions:
* Attack: Fennec chooses one monster. That monster's health will decrease by 1.
* Special Move: Fennec chooses one monster. That monster's health will become 0.
There is no way other than Attack and Special Move to decrease the monsters'
health.
Fennec wins when all the monsters' healths become 0 or below.
Find the minimum number of times Fennec needs to do Attack (not counting
Special Move) before winning when she can use Special Move at most K times. | [{"input": "3 1\n 4 1 5", "output": "5\n \n\nBy using Special Move on the third monster, and doing Attack four times on the\nfirst monster and once on the second monster, Fennec can win with five\nAttacks.\n\n* * *"}, {"input": "8 9\n 7 9 3 2 3 8 4 6", "output": "0\n \n\nShe can use Special Move on all the monsters.\n\n* * *"}, {"input": "3 0\n 1000000000 1000000000 1000000000", "output": "3000000000\n \n\nWatch out for overflow."}] |
Print the minimum number of times Fennec needs to do Attack (not counting
Special Move) before winning.
* * * | s847756888 | Accepted | p02785 | Input is given from Standard Input in the following format:
N K
H_1 ... H_N | special_moves = input().split(" ")
_, special_moves = int(special_moves[0]), int(special_moves[1])
health = input().split(" ")
health = [int(h) for h in health]
health.sort(reverse=True)
print(sum(health[special_moves:]))
| Statement
Fennec is fighting with N monsters.
The _health_ of the i-th monster is H_i.
Fennec can do the following two actions:
* Attack: Fennec chooses one monster. That monster's health will decrease by 1.
* Special Move: Fennec chooses one monster. That monster's health will become 0.
There is no way other than Attack and Special Move to decrease the monsters'
health.
Fennec wins when all the monsters' healths become 0 or below.
Find the minimum number of times Fennec needs to do Attack (not counting
Special Move) before winning when she can use Special Move at most K times. | [{"input": "3 1\n 4 1 5", "output": "5\n \n\nBy using Special Move on the third monster, and doing Attack four times on the\nfirst monster and once on the second monster, Fennec can win with five\nAttacks.\n\n* * *"}, {"input": "8 9\n 7 9 3 2 3 8 4 6", "output": "0\n \n\nShe can use Special Move on all the monsters.\n\n* * *"}, {"input": "3 0\n 1000000000 1000000000 1000000000", "output": "3000000000\n \n\nWatch out for overflow."}] |
Print the answer.
* * * | s845403962 | Runtime Error | p03194 | Input is given from Standard Input in the following format:
N P | N,P = map(int,input().split())
ans=1
if N==1|N>=40:
print(P)
exit()
elif P==1:
print(1)
exit()
else:
i=2
while(i*i<=P):
count=0
while(P%i==0):
P=P//i
count+=1
ans*=i**(count//N)
if i==2:
i+=1
else:
i+=2
print(ans) | Statement
There are N integers a_1, a_2, ..., a_N not less than 1. The values of a_1,
a_2, ..., a_N are not known, but it is known that a_1 \times a_2 \times ...
\times a_N = P.
Find the maximum possible greatest common divisor of a_1, a_2, ..., a_N. | [{"input": "3 24", "output": "2\n \n\nThe greatest common divisor would be 2 when, for example, a_1=2, a_2=6 and\na_3=2.\n\n* * *"}, {"input": "5 1", "output": "1\n \n\nAs a_i are positive integers, the only possible case is a_1 = a_2 = a_3 = a_4\n= a_5 = 1.\n\n* * *"}, {"input": "1 111", "output": "111\n \n\n* * *"}, {"input": "4 972439611840", "output": "206"}] |
Print the answer.
* * * | s246451369 | Runtime Error | p03194 | Input is given from Standard Input in the following format:
N P | import math
N, P = map(int, input().split())
result = 1
i = math.floor(math.pow(P, (1.0/N))) + 1
while i > 1:
if P % int(math.pow(i, N) == 0:
result = i
break
i -= 1
print(result)
| Statement
There are N integers a_1, a_2, ..., a_N not less than 1. The values of a_1,
a_2, ..., a_N are not known, but it is known that a_1 \times a_2 \times ...
\times a_N = P.
Find the maximum possible greatest common divisor of a_1, a_2, ..., a_N. | [{"input": "3 24", "output": "2\n \n\nThe greatest common divisor would be 2 when, for example, a_1=2, a_2=6 and\na_3=2.\n\n* * *"}, {"input": "5 1", "output": "1\n \n\nAs a_i are positive integers, the only possible case is a_1 = a_2 = a_3 = a_4\n= a_5 = 1.\n\n* * *"}, {"input": "1 111", "output": "111\n \n\n* * *"}, {"input": "4 972439611840", "output": "206"}] |
Print the answer.
* * * | s239081279 | Runtime Error | p03194 | Input is given from Standard Input in the following format:
N P | n,p=map(int,input().split())
for i in range(1,100000):
if p%(i**n)==0:
x=i
print(x) | Statement
There are N integers a_1, a_2, ..., a_N not less than 1. The values of a_1,
a_2, ..., a_N are not known, but it is known that a_1 \times a_2 \times ...
\times a_N = P.
Find the maximum possible greatest common divisor of a_1, a_2, ..., a_N. | [{"input": "3 24", "output": "2\n \n\nThe greatest common divisor would be 2 when, for example, a_1=2, a_2=6 and\na_3=2.\n\n* * *"}, {"input": "5 1", "output": "1\n \n\nAs a_i are positive integers, the only possible case is a_1 = a_2 = a_3 = a_4\n= a_5 = 1.\n\n* * *"}, {"input": "1 111", "output": "111\n \n\n* * *"}, {"input": "4 972439611840", "output": "206"}] |
Print the answer.
* * * | s636391536 | Runtime Error | p03194 | Input is given from Standard Input in the following format:
N P | n,p = map(int,input().split())
ans = 1
c = [0] * (p+1)
for i in range(2,p+1):
while p % i == 0:
p //= i
c[i] += 1
for i in range(p+1)
if c[i] % n == 0:
ans *= i // n
print(ans)
| Statement
There are N integers a_1, a_2, ..., a_N not less than 1. The values of a_1,
a_2, ..., a_N are not known, but it is known that a_1 \times a_2 \times ...
\times a_N = P.
Find the maximum possible greatest common divisor of a_1, a_2, ..., a_N. | [{"input": "3 24", "output": "2\n \n\nThe greatest common divisor would be 2 when, for example, a_1=2, a_2=6 and\na_3=2.\n\n* * *"}, {"input": "5 1", "output": "1\n \n\nAs a_i are positive integers, the only possible case is a_1 = a_2 = a_3 = a_4\n= a_5 = 1.\n\n* * *"}, {"input": "1 111", "output": "111\n \n\n* * *"}, {"input": "4 972439611840", "output": "206"}] |
Print the answer.
* * * | s948337067 | Runtime Error | p03194 | Input is given from Standard Input in the following format:
N P | import sympy
a = sympy.factorint(2016)
print(a)
| Statement
There are N integers a_1, a_2, ..., a_N not less than 1. The values of a_1,
a_2, ..., a_N are not known, but it is known that a_1 \times a_2 \times ...
\times a_N = P.
Find the maximum possible greatest common divisor of a_1, a_2, ..., a_N. | [{"input": "3 24", "output": "2\n \n\nThe greatest common divisor would be 2 when, for example, a_1=2, a_2=6 and\na_3=2.\n\n* * *"}, {"input": "5 1", "output": "1\n \n\nAs a_i are positive integers, the only possible case is a_1 = a_2 = a_3 = a_4\n= a_5 = 1.\n\n* * *"}, {"input": "1 111", "output": "111\n \n\n* * *"}, {"input": "4 972439611840", "output": "206"}] |
Print the answer.
* * * | s288408826 | Runtime Error | p03194 | Input is given from Standard Input in the following format:
N P | N, P = map(int,input().split())
output=1
if P==1:
else:
for num in range(2,round(P**(1/N))+1):
if P%(num**N) == 0:
output = num
print(output) | Statement
There are N integers a_1, a_2, ..., a_N not less than 1. The values of a_1,
a_2, ..., a_N are not known, but it is known that a_1 \times a_2 \times ...
\times a_N = P.
Find the maximum possible greatest common divisor of a_1, a_2, ..., a_N. | [{"input": "3 24", "output": "2\n \n\nThe greatest common divisor would be 2 when, for example, a_1=2, a_2=6 and\na_3=2.\n\n* * *"}, {"input": "5 1", "output": "1\n \n\nAs a_i are positive integers, the only possible case is a_1 = a_2 = a_3 = a_4\n= a_5 = 1.\n\n* * *"}, {"input": "1 111", "output": "111\n \n\n* * *"}, {"input": "4 972439611840", "output": "206"}] |
Print the answer.
* * * | s312271594 | Runtime Error | p03194 | Input is given from Standard Input in the following format:
N P | n = input("")
p = input("")
print(1)
| Statement
There are N integers a_1, a_2, ..., a_N not less than 1. The values of a_1,
a_2, ..., a_N are not known, but it is known that a_1 \times a_2 \times ...
\times a_N = P.
Find the maximum possible greatest common divisor of a_1, a_2, ..., a_N. | [{"input": "3 24", "output": "2\n \n\nThe greatest common divisor would be 2 when, for example, a_1=2, a_2=6 and\na_3=2.\n\n* * *"}, {"input": "5 1", "output": "1\n \n\nAs a_i are positive integers, the only possible case is a_1 = a_2 = a_3 = a_4\n= a_5 = 1.\n\n* * *"}, {"input": "1 111", "output": "111\n \n\n* * *"}, {"input": "4 972439611840", "output": "206"}] |
Print the answer.
* * * | s329262249 | Runtime Error | p03194 | Input is given from Standard Input in the following format:
N P | import collections
import math
n, p = [int(i) for i in input().split()]
d = collections.defaultdict(lambda: 0)
def bunkai(q):
if q == 1:
return 0
for i in range(2, math.ceil(math.sqrt(p))):
if q % i == 0:
d[i] += 1
return bunkai(q//i)
if n == 1 or p == 1:
print(p)
else:
bunkai(p)
ans = 1
for j in d.key
k = d[j]
if k // n >= 1:
ans *= j**(k//n)
print(ans)
| Statement
There are N integers a_1, a_2, ..., a_N not less than 1. The values of a_1,
a_2, ..., a_N are not known, but it is known that a_1 \times a_2 \times ...
\times a_N = P.
Find the maximum possible greatest common divisor of a_1, a_2, ..., a_N. | [{"input": "3 24", "output": "2\n \n\nThe greatest common divisor would be 2 when, for example, a_1=2, a_2=6 and\na_3=2.\n\n* * *"}, {"input": "5 1", "output": "1\n \n\nAs a_i are positive integers, the only possible case is a_1 = a_2 = a_3 = a_4\n= a_5 = 1.\n\n* * *"}, {"input": "1 111", "output": "111\n \n\n* * *"}, {"input": "4 972439611840", "output": "206"}] |
Print the answer.
* * * | s608919030 | Runtime Error | p03194 | Input is given from Standard Input in the following format:
N P | from collections import Counter
from functools import reduce
from operator import mul
N,P = map(int,input().split())
i = 2
table = []
while i * i <= P:
while P % i == 0:
P /= i
table.append(i)
i += 1
if P > 1:
table.append(P)
c = Counter(table)
temp = [i[0] for i in c.items() if i[1] >= N]
temp.append(1)
print(int(reduce(mul,temp))) | Statement
There are N integers a_1, a_2, ..., a_N not less than 1. The values of a_1,
a_2, ..., a_N are not known, but it is known that a_1 \times a_2 \times ...
\times a_N = P.
Find the maximum possible greatest common divisor of a_1, a_2, ..., a_N. | [{"input": "3 24", "output": "2\n \n\nThe greatest common divisor would be 2 when, for example, a_1=2, a_2=6 and\na_3=2.\n\n* * *"}, {"input": "5 1", "output": "1\n \n\nAs a_i are positive integers, the only possible case is a_1 = a_2 = a_3 = a_4\n= a_5 = 1.\n\n* * *"}, {"input": "1 111", "output": "111\n \n\n* * *"}, {"input": "4 972439611840", "output": "206"}] |
Print the answer.
* * * | s456273785 | Runtime Error | p03194 | Input is given from Standard Input in the following format:
N P | def prime_decomposition(n):
i = 2
table = []
while i * i <= n:
while n % i == 0:
n /= i
table.append(i)
i += 1
if n > 1:
table.append(int(n))
return table
cnt=1
gcd=1
b,p=map(int,input().split())
a=prime_decomposition(p)
print(a)
if b==1:
if b>1:
l=len(a)
for i in range(l-1):
if a[i+1]==a[i]:
cnt+=1
if cnt==b:
gcd*=a[i]
cnt=1
else:
cnt=1
print(gcd)
| Statement
There are N integers a_1, a_2, ..., a_N not less than 1. The values of a_1,
a_2, ..., a_N are not known, but it is known that a_1 \times a_2 \times ...
\times a_N = P.
Find the maximum possible greatest common divisor of a_1, a_2, ..., a_N. | [{"input": "3 24", "output": "2\n \n\nThe greatest common divisor would be 2 when, for example, a_1=2, a_2=6 and\na_3=2.\n\n* * *"}, {"input": "5 1", "output": "1\n \n\nAs a_i are positive integers, the only possible case is a_1 = a_2 = a_3 = a_4\n= a_5 = 1.\n\n* * *"}, {"input": "1 111", "output": "111\n \n\n* * *"}, {"input": "4 972439611840", "output": "206"}] |
Print the answer.
* * * | s815453041 | Runtime Error | p03194 | Input is given from Standard Input in the following format:
N P | def prime_decomposition(n):
i = 2
table = []
while i * i <= n:
while n % i == 0:
n /= i
table.append(i)
i += 1
if n > 1:
table.append(int(n))
return table
cnt=1
gcd=1
b,p=map(int,input().split())
a=prime_decomposition(p)
print(a)
if b==1:
if b>1:
l=len(a)
for i in range(l-1):
if a[i+1]==a[i]:
cnt+=1
if cnt==b:
gcd*=a[i]
cnt=1
else:
cnt=1
print(gcd)
| Statement
There are N integers a_1, a_2, ..., a_N not less than 1. The values of a_1,
a_2, ..., a_N are not known, but it is known that a_1 \times a_2 \times ...
\times a_N = P.
Find the maximum possible greatest common divisor of a_1, a_2, ..., a_N. | [{"input": "3 24", "output": "2\n \n\nThe greatest common divisor would be 2 when, for example, a_1=2, a_2=6 and\na_3=2.\n\n* * *"}, {"input": "5 1", "output": "1\n \n\nAs a_i are positive integers, the only possible case is a_1 = a_2 = a_3 = a_4\n= a_5 = 1.\n\n* * *"}, {"input": "1 111", "output": "111\n \n\n* * *"}, {"input": "4 972439611840", "output": "206"}] |
Print the answer.
* * * | s575886689 | Runtime Error | p03194 | Input is given from Standard Input in the following format:
N P | import math
N, P = map(int, input().split())
ans=1
yakusu = []
for i in range(1,int(math.sqrt(P))+1):
if P%i == 0:
yakusu.append(i)
yakusu.append(P/i)
yakusu.sort()
f=P**(1/N)
bobo = []
for k in yakusu:
if k <= (f+1):
bobo.append(k)
bobo.reverse()
for j in bobo:
if P/((j**(N/2))**2 in yakusu:
ans=int(j)
print(ans)
break | Statement
There are N integers a_1, a_2, ..., a_N not less than 1. The values of a_1,
a_2, ..., a_N are not known, but it is known that a_1 \times a_2 \times ...
\times a_N = P.
Find the maximum possible greatest common divisor of a_1, a_2, ..., a_N. | [{"input": "3 24", "output": "2\n \n\nThe greatest common divisor would be 2 when, for example, a_1=2, a_2=6 and\na_3=2.\n\n* * *"}, {"input": "5 1", "output": "1\n \n\nAs a_i are positive integers, the only possible case is a_1 = a_2 = a_3 = a_4\n= a_5 = 1.\n\n* * *"}, {"input": "1 111", "output": "111\n \n\n* * *"}, {"input": "4 972439611840", "output": "206"}] |
Print the answer.
* * * | s846662979 | Runtime Error | p03194 | Input is given from Standard Input in the following format:
N P | from collections import Counter
import sys
sys.setrecursionlimit(1000000)
def bunkai(q):
res = []
if q == 1:
res.append(1)
return res
else:
n_dummy = q
for i in range(2,int(n_dummy**0.5)+3):
while n_dummy%i == 0:
n_dummy //= i
res.append(i)
if n_dummy >= 2:
for i in range(2,int(n_dummy**0.5)+3):
while n_dummy%i == 0:
n_dummy //= i
res.append(i)
if n_dummy >= 2:
res.append(n_dummy)
return res
def solve():
n,p = (int(i) for i in input().split())
ans = 1
query = bunkai(p)
%print(query)
c = Counter(query)
for i in range(len(c.values())):
number,times = c.most_common()[i]
if times >= n:
timestimes = times//n
ans *= timestimes*number
print(ans)
solve() | Statement
There are N integers a_1, a_2, ..., a_N not less than 1. The values of a_1,
a_2, ..., a_N are not known, but it is known that a_1 \times a_2 \times ...
\times a_N = P.
Find the maximum possible greatest common divisor of a_1, a_2, ..., a_N. | [{"input": "3 24", "output": "2\n \n\nThe greatest common divisor would be 2 when, for example, a_1=2, a_2=6 and\na_3=2.\n\n* * *"}, {"input": "5 1", "output": "1\n \n\nAs a_i are positive integers, the only possible case is a_1 = a_2 = a_3 = a_4\n= a_5 = 1.\n\n* * *"}, {"input": "1 111", "output": "111\n \n\n* * *"}, {"input": "4 972439611840", "output": "206"}] |
Print the answer.
* * * | s914956549 | Runtime Error | p03194 | Input is given from Standard Input in the following format:
N P | from sys import stdin
N,P=[int(x) for x in stdin.readline().rstrip().split()]
for i in reversed(range(int(pow(P,(1/N)))+1)):
if P==1:
ans=1
break
if N==1:
ans=P
break
if P%i==0:
ans=i
break:
print(ans) | Statement
There are N integers a_1, a_2, ..., a_N not less than 1. The values of a_1,
a_2, ..., a_N are not known, but it is known that a_1 \times a_2 \times ...
\times a_N = P.
Find the maximum possible greatest common divisor of a_1, a_2, ..., a_N. | [{"input": "3 24", "output": "2\n \n\nThe greatest common divisor would be 2 when, for example, a_1=2, a_2=6 and\na_3=2.\n\n* * *"}, {"input": "5 1", "output": "1\n \n\nAs a_i are positive integers, the only possible case is a_1 = a_2 = a_3 = a_4\n= a_5 = 1.\n\n* * *"}, {"input": "1 111", "output": "111\n \n\n* * *"}, {"input": "4 972439611840", "output": "206"}] |
Print the answer.
* * * | s816060421 | Runtime Error | p03194 | Input is given from Standard Input in the following format:
N P | import math
N, P = (int(i) for i in input().split())
a = 1
b = math.floor(math.sqrt(P))
i = 2
c = P
if N ==1:
a = P
if N =2 and P = 1000000000000:
a = 1000000
else:
while (i**N <= P) and (i<=b):
if c % (i**N) == 0:
a = i
i = i+1
print(a)
| Statement
There are N integers a_1, a_2, ..., a_N not less than 1. The values of a_1,
a_2, ..., a_N are not known, but it is known that a_1 \times a_2 \times ...
\times a_N = P.
Find the maximum possible greatest common divisor of a_1, a_2, ..., a_N. | [{"input": "3 24", "output": "2\n \n\nThe greatest common divisor would be 2 when, for example, a_1=2, a_2=6 and\na_3=2.\n\n* * *"}, {"input": "5 1", "output": "1\n \n\nAs a_i are positive integers, the only possible case is a_1 = a_2 = a_3 = a_4\n= a_5 = 1.\n\n* * *"}, {"input": "1 111", "output": "111\n \n\n* * *"}, {"input": "4 972439611840", "output": "206"}] |
Assign the numbers 1, 2, 3, \dots, K to the K pieces obtained after the cut,
in any order. Then, let a_{i, j} be the number representing the piece
containing the section at the i-th row from the top and the j-th column from
the left of the cake. Output should be in the following format:
a_{1, 1} \ a_{1, 2} \ \cdots \ a_{1, W}
a_{2, 1} \ a_{2, 2} \ \cdots \ a_{2, W}
:
a_{H, 1} \ a_{H, 2} \ \cdots \ a_{H, W}
If multiple solutions exist, any of them will be accepted.
* * * | s124101398 | Accepted | p02855 | Input is given from Standard Input in the following format:
H W K
s_{1, 1} s_{1, 2} \cdots s_{1, W}
s_{2, 1} s_{2, 2} \cdots s_{2, W}
:
s_{H, 1} s_{H, 2} \cdots s_{H, W} | H, W, K = map(int, input().split())
s = [0] * H
for i in range(0, H):
s[i] = list(input())
ans = [0] * H
for i in range(0, H):
ans[i] = [0] * W
cur = 0
non = 10 * 3
for h in range(0, H):
if "#" in s[h]: # 苺があるとき苺ごとに分ける
cur += 1
for w in range(0, W):
ans[h][w] = cur
if s[h][w] == "#":
if "#" in s[h][w + 1 :]:
cur += 1
else:
if cur == 0:
non = h # 最初の苺の前の列
else:
for w in range(0, W):
ans[h][w] = ans[h - 1][w]
if non != 10 * 3:
for h in range(0, non + 1):
for w in range(0, W):
ans[h][w] = ans[non + 1][w]
for h in range(0, H):
res = ""
for w in range(0, W):
if w != 0:
res += " "
res += str(ans[h][w])
print(res)
| Statement
Chokudai made a rectangular cake for contestants in DDCC 2020 Finals.
The cake has H - 1 horizontal notches and W - 1 vertical notches, which divide
the cake into H \times W equal sections. K of these sections has a strawberry
on top of each of them.
The positions of the strawberries are given to you as H \times W characters
s_{i, j} (1 \leq i \leq H, 1 \leq j \leq W). If s_{i, j} is `#`, the section
at the i-th row from the top and the j-th column from the left contains a
strawberry; if s_{i, j} is `.`, the section does not contain one. There are
exactly K occurrences of `#`s.
Takahashi wants to cut this cake into K pieces and serve them to the
contestants. Each of these pieces must satisfy the following conditions:
* Has a rectangular shape.
* Contains exactly one strawberry.
One possible way to cut the cake is shown below:

Find one way to cut the cake and satisfy the condition. We can show that this
is always possible, regardless of the number and positions of the
strawberries. | [{"input": "3 3 5\n #.#\n .#.\n #.#", "output": "1 2 2\n 1 3 4\n 5 5 4\n \n\nOne way to cut this cake is shown below:\n\n\n\n* * *"}, {"input": "3 7 7\n #...#.#\n ..#...#\n .#..#..", "output": "1 1 2 2 3 4 4\n 6 6 2 2 3 5 5\n 6 6 7 7 7 7 7\n \n\nOne way to cut this cake is shown below:\n\n\n\n* * *"}, {"input": "13 21 106\n .....................\n .####.####.####.####.\n ..#.#..#.#.#....#....\n ..#.#..#.#.#....#....\n ..#.#..#.#.#....#....\n .####.####.####.####.\n .....................\n .####.####.####.####.\n ....#.#..#....#.#..#.\n .####.#..#.####.#..#.\n .#....#..#.#....#..#.\n .####.####.####.####.\n .....................", "output": "12 12 23 34 45 45 60 71 82 93 93 2 13 24 35 35 17 28 39 50 50\n 12 12 23 34 45 45 60 71 82 93 93 2 13 24 35 35 17 28 39 50 50\n 12 12 56 89 89 89 60 104 82 31 31 46 13 24 35 35 61 61 39 50 50\n 12 12 67 67 100 100 60 9 9 42 42 57 13 24 6 72 72 72 72 72 72\n 12 12 78 5 5 5 20 20 20 53 68 68 90 24 6 83 83 83 83 83 83\n 16 16 27 38 49 49 64 75 86 97 79 79 90 101 6 94 94 105 10 21 21\n 16 16 27 38 49 49 64 75 86 97 79 79 90 101 6 94 94 105 10 21 21\n 32 32 43 54 65 65 80 11 106 95 22 22 33 44 55 55 70 1 96 85 85\n 32 32 43 54 76 76 91 11 106 84 84 4 99 66 66 66 81 1 96 74 74\n 14 14 3 98 87 87 102 11 73 73 73 4 99 88 77 77 92 92 63 63 63\n 25 25 3 98 87 87 7 29 62 62 62 15 99 88 77 77 103 19 30 52 52\n 36 36 47 58 69 69 18 29 40 51 51 26 37 48 59 59 8 19 30 41 41\n 36 36 47 58 69 69 18 29 40 51 51 26 37 48 59 59 8 19 30 41 41"}] |
Assign the numbers 1, 2, 3, \dots, K to the K pieces obtained after the cut,
in any order. Then, let a_{i, j} be the number representing the piece
containing the section at the i-th row from the top and the j-th column from
the left of the cake. Output should be in the following format:
a_{1, 1} \ a_{1, 2} \ \cdots \ a_{1, W}
a_{2, 1} \ a_{2, 2} \ \cdots \ a_{2, W}
:
a_{H, 1} \ a_{H, 2} \ \cdots \ a_{H, W}
If multiple solutions exist, any of them will be accepted.
* * * | s039745681 | Accepted | p02855 | Input is given from Standard Input in the following format:
H W K
s_{1, 1} s_{1, 2} \cdots s_{1, W}
s_{2, 1} s_{2, 2} \cdots s_{2, W}
:
s_{H, 1} s_{H, 2} \cdots s_{H, W} | from collections import deque
H, W, K = list(map(int, input().split()))
A = [[0] * W for _ in range(H)]
n = 1
P = []
B = []
for i in range(H):
B.append(input())
for i in range(H):
for j in range(W):
if B[i][j] == "#":
A[i][j] = n
n += 1
P.append([i, j])
def change(A, x, y, z):
if y - 1 >= 0:
if A[x][y - 1] == 0:
A[x][y - 1] = z
change(A, x, y - 1, z)
if y + 1 <= (W - 1):
if A[x][y + 1] == 0:
A[x][y + 1] = z
change(A, x, y + 1, z)
for i in P:
change(A, i[0], i[1], A[i[0]][i[1]])
next_ = []
next_ = deque(next_)
for k in range(H):
if 0 in A[k]:
next_.append(k)
while len(next_) > 0:
l = next_.popleft()
if l == H - 1:
A[l] = A[l - 1]
if 0 in A[l]:
next_.append(l)
elif l == 0:
A[l] = A[l + 1]
if 0 in A[l]:
next_.append(l)
else:
if l + 1 in next_ and l - 1 in next_:
next_.append(l)
elif l + 1 not in next_:
A[l] = A[l + 1]
else:
A[l] = A[l - 1]
for w in range(H):
print(*A[w])
| Statement
Chokudai made a rectangular cake for contestants in DDCC 2020 Finals.
The cake has H - 1 horizontal notches and W - 1 vertical notches, which divide
the cake into H \times W equal sections. K of these sections has a strawberry
on top of each of them.
The positions of the strawberries are given to you as H \times W characters
s_{i, j} (1 \leq i \leq H, 1 \leq j \leq W). If s_{i, j} is `#`, the section
at the i-th row from the top and the j-th column from the left contains a
strawberry; if s_{i, j} is `.`, the section does not contain one. There are
exactly K occurrences of `#`s.
Takahashi wants to cut this cake into K pieces and serve them to the
contestants. Each of these pieces must satisfy the following conditions:
* Has a rectangular shape.
* Contains exactly one strawberry.
One possible way to cut the cake is shown below:

Find one way to cut the cake and satisfy the condition. We can show that this
is always possible, regardless of the number and positions of the
strawberries. | [{"input": "3 3 5\n #.#\n .#.\n #.#", "output": "1 2 2\n 1 3 4\n 5 5 4\n \n\nOne way to cut this cake is shown below:\n\n\n\n* * *"}, {"input": "3 7 7\n #...#.#\n ..#...#\n .#..#..", "output": "1 1 2 2 3 4 4\n 6 6 2 2 3 5 5\n 6 6 7 7 7 7 7\n \n\nOne way to cut this cake is shown below:\n\n\n\n* * *"}, {"input": "13 21 106\n .....................\n .####.####.####.####.\n ..#.#..#.#.#....#....\n ..#.#..#.#.#....#....\n ..#.#..#.#.#....#....\n .####.####.####.####.\n .....................\n .####.####.####.####.\n ....#.#..#....#.#..#.\n .####.#..#.####.#..#.\n .#....#..#.#....#..#.\n .####.####.####.####.\n .....................", "output": "12 12 23 34 45 45 60 71 82 93 93 2 13 24 35 35 17 28 39 50 50\n 12 12 23 34 45 45 60 71 82 93 93 2 13 24 35 35 17 28 39 50 50\n 12 12 56 89 89 89 60 104 82 31 31 46 13 24 35 35 61 61 39 50 50\n 12 12 67 67 100 100 60 9 9 42 42 57 13 24 6 72 72 72 72 72 72\n 12 12 78 5 5 5 20 20 20 53 68 68 90 24 6 83 83 83 83 83 83\n 16 16 27 38 49 49 64 75 86 97 79 79 90 101 6 94 94 105 10 21 21\n 16 16 27 38 49 49 64 75 86 97 79 79 90 101 6 94 94 105 10 21 21\n 32 32 43 54 65 65 80 11 106 95 22 22 33 44 55 55 70 1 96 85 85\n 32 32 43 54 76 76 91 11 106 84 84 4 99 66 66 66 81 1 96 74 74\n 14 14 3 98 87 87 102 11 73 73 73 4 99 88 77 77 92 92 63 63 63\n 25 25 3 98 87 87 7 29 62 62 62 15 99 88 77 77 103 19 30 52 52\n 36 36 47 58 69 69 18 29 40 51 51 26 37 48 59 59 8 19 30 41 41\n 36 36 47 58 69 69 18 29 40 51 51 26 37 48 59 59 8 19 30 41 41"}] |
Assign the numbers 1, 2, 3, \dots, K to the K pieces obtained after the cut,
in any order. Then, let a_{i, j} be the number representing the piece
containing the section at the i-th row from the top and the j-th column from
the left of the cake. Output should be in the following format:
a_{1, 1} \ a_{1, 2} \ \cdots \ a_{1, W}
a_{2, 1} \ a_{2, 2} \ \cdots \ a_{2, W}
:
a_{H, 1} \ a_{H, 2} \ \cdots \ a_{H, W}
If multiple solutions exist, any of them will be accepted.
* * * | s709428095 | Wrong Answer | p02855 | Input is given from Standard Input in the following format:
H W K
s_{1, 1} s_{1, 2} \cdots s_{1, W}
s_{2, 1} s_{2, 2} \cdots s_{2, W}
:
s_{H, 1} s_{H, 2} \cdots s_{H, W} | H, W, K = map(int, input().split())
S = [""] * H
for i in range(H):
S[i] = input()
A = [[0] * W] * H
bg = 1
inflg = 0
outcnt = 1
for i in range(H):
if "#" not in S[i]:
if inflg == 0:
outcnt += 1
continue
else:
A[i] = A[i - 1]
else:
inflg += 1
for j in range(S[i].find("#")):
A[i][j] = bg
for j in range(S[i].find("#"), W):
if S[i][j] == "#":
A[i][j] = bg
bg += 1
else:
A[i][j] = A[i][j - 1]
if inflg == 1:
for i in range(outcnt):
print(" ".join(str(k) for k in A[i]))
else:
print(" ".join(str(k) for k in A[i]))
| Statement
Chokudai made a rectangular cake for contestants in DDCC 2020 Finals.
The cake has H - 1 horizontal notches and W - 1 vertical notches, which divide
the cake into H \times W equal sections. K of these sections has a strawberry
on top of each of them.
The positions of the strawberries are given to you as H \times W characters
s_{i, j} (1 \leq i \leq H, 1 \leq j \leq W). If s_{i, j} is `#`, the section
at the i-th row from the top and the j-th column from the left contains a
strawberry; if s_{i, j} is `.`, the section does not contain one. There are
exactly K occurrences of `#`s.
Takahashi wants to cut this cake into K pieces and serve them to the
contestants. Each of these pieces must satisfy the following conditions:
* Has a rectangular shape.
* Contains exactly one strawberry.
One possible way to cut the cake is shown below:

Find one way to cut the cake and satisfy the condition. We can show that this
is always possible, regardless of the number and positions of the
strawberries. | [{"input": "3 3 5\n #.#\n .#.\n #.#", "output": "1 2 2\n 1 3 4\n 5 5 4\n \n\nOne way to cut this cake is shown below:\n\n\n\n* * *"}, {"input": "3 7 7\n #...#.#\n ..#...#\n .#..#..", "output": "1 1 2 2 3 4 4\n 6 6 2 2 3 5 5\n 6 6 7 7 7 7 7\n \n\nOne way to cut this cake is shown below:\n\n\n\n* * *"}, {"input": "13 21 106\n .....................\n .####.####.####.####.\n ..#.#..#.#.#....#....\n ..#.#..#.#.#....#....\n ..#.#..#.#.#....#....\n .####.####.####.####.\n .....................\n .####.####.####.####.\n ....#.#..#....#.#..#.\n .####.#..#.####.#..#.\n .#....#..#.#....#..#.\n .####.####.####.####.\n .....................", "output": "12 12 23 34 45 45 60 71 82 93 93 2 13 24 35 35 17 28 39 50 50\n 12 12 23 34 45 45 60 71 82 93 93 2 13 24 35 35 17 28 39 50 50\n 12 12 56 89 89 89 60 104 82 31 31 46 13 24 35 35 61 61 39 50 50\n 12 12 67 67 100 100 60 9 9 42 42 57 13 24 6 72 72 72 72 72 72\n 12 12 78 5 5 5 20 20 20 53 68 68 90 24 6 83 83 83 83 83 83\n 16 16 27 38 49 49 64 75 86 97 79 79 90 101 6 94 94 105 10 21 21\n 16 16 27 38 49 49 64 75 86 97 79 79 90 101 6 94 94 105 10 21 21\n 32 32 43 54 65 65 80 11 106 95 22 22 33 44 55 55 70 1 96 85 85\n 32 32 43 54 76 76 91 11 106 84 84 4 99 66 66 66 81 1 96 74 74\n 14 14 3 98 87 87 102 11 73 73 73 4 99 88 77 77 92 92 63 63 63\n 25 25 3 98 87 87 7 29 62 62 62 15 99 88 77 77 103 19 30 52 52\n 36 36 47 58 69 69 18 29 40 51 51 26 37 48 59 59 8 19 30 41 41\n 36 36 47 58 69 69 18 29 40 51 51 26 37 48 59 59 8 19 30 41 41"}] |
Assign the numbers 1, 2, 3, \dots, K to the K pieces obtained after the cut,
in any order. Then, let a_{i, j} be the number representing the piece
containing the section at the i-th row from the top and the j-th column from
the left of the cake. Output should be in the following format:
a_{1, 1} \ a_{1, 2} \ \cdots \ a_{1, W}
a_{2, 1} \ a_{2, 2} \ \cdots \ a_{2, W}
:
a_{H, 1} \ a_{H, 2} \ \cdots \ a_{H, W}
If multiple solutions exist, any of them will be accepted.
* * * | s630228596 | Wrong Answer | p02855 | Input is given from Standard Input in the following format:
H W K
s_{1, 1} s_{1, 2} \cdots s_{1, W}
s_{2, 1} s_{2, 2} \cdots s_{2, W}
:
s_{H, 1} s_{H, 2} \cdots s_{H, W} | print("The question is too complicated")
| Statement
Chokudai made a rectangular cake for contestants in DDCC 2020 Finals.
The cake has H - 1 horizontal notches and W - 1 vertical notches, which divide
the cake into H \times W equal sections. K of these sections has a strawberry
on top of each of them.
The positions of the strawberries are given to you as H \times W characters
s_{i, j} (1 \leq i \leq H, 1 \leq j \leq W). If s_{i, j} is `#`, the section
at the i-th row from the top and the j-th column from the left contains a
strawberry; if s_{i, j} is `.`, the section does not contain one. There are
exactly K occurrences of `#`s.
Takahashi wants to cut this cake into K pieces and serve them to the
contestants. Each of these pieces must satisfy the following conditions:
* Has a rectangular shape.
* Contains exactly one strawberry.
One possible way to cut the cake is shown below:

Find one way to cut the cake and satisfy the condition. We can show that this
is always possible, regardless of the number and positions of the
strawberries. | [{"input": "3 3 5\n #.#\n .#.\n #.#", "output": "1 2 2\n 1 3 4\n 5 5 4\n \n\nOne way to cut this cake is shown below:\n\n\n\n* * *"}, {"input": "3 7 7\n #...#.#\n ..#...#\n .#..#..", "output": "1 1 2 2 3 4 4\n 6 6 2 2 3 5 5\n 6 6 7 7 7 7 7\n \n\nOne way to cut this cake is shown below:\n\n\n\n* * *"}, {"input": "13 21 106\n .....................\n .####.####.####.####.\n ..#.#..#.#.#....#....\n ..#.#..#.#.#....#....\n ..#.#..#.#.#....#....\n .####.####.####.####.\n .....................\n .####.####.####.####.\n ....#.#..#....#.#..#.\n .####.#..#.####.#..#.\n .#....#..#.#....#..#.\n .####.####.####.####.\n .....................", "output": "12 12 23 34 45 45 60 71 82 93 93 2 13 24 35 35 17 28 39 50 50\n 12 12 23 34 45 45 60 71 82 93 93 2 13 24 35 35 17 28 39 50 50\n 12 12 56 89 89 89 60 104 82 31 31 46 13 24 35 35 61 61 39 50 50\n 12 12 67 67 100 100 60 9 9 42 42 57 13 24 6 72 72 72 72 72 72\n 12 12 78 5 5 5 20 20 20 53 68 68 90 24 6 83 83 83 83 83 83\n 16 16 27 38 49 49 64 75 86 97 79 79 90 101 6 94 94 105 10 21 21\n 16 16 27 38 49 49 64 75 86 97 79 79 90 101 6 94 94 105 10 21 21\n 32 32 43 54 65 65 80 11 106 95 22 22 33 44 55 55 70 1 96 85 85\n 32 32 43 54 76 76 91 11 106 84 84 4 99 66 66 66 81 1 96 74 74\n 14 14 3 98 87 87 102 11 73 73 73 4 99 88 77 77 92 92 63 63 63\n 25 25 3 98 87 87 7 29 62 62 62 15 99 88 77 77 103 19 30 52 52\n 36 36 47 58 69 69 18 29 40 51 51 26 37 48 59 59 8 19 30 41 41\n 36 36 47 58 69 69 18 29 40 51 51 26 37 48 59 59 8 19 30 41 41"}] |
Assign the numbers 1, 2, 3, \dots, K to the K pieces obtained after the cut,
in any order. Then, let a_{i, j} be the number representing the piece
containing the section at the i-th row from the top and the j-th column from
the left of the cake. Output should be in the following format:
a_{1, 1} \ a_{1, 2} \ \cdots \ a_{1, W}
a_{2, 1} \ a_{2, 2} \ \cdots \ a_{2, W}
:
a_{H, 1} \ a_{H, 2} \ \cdots \ a_{H, W}
If multiple solutions exist, any of them will be accepted.
* * * | s243039807 | Accepted | p02855 | Input is given from Standard Input in the following format:
H W K
s_{1, 1} s_{1, 2} \cdots s_{1, W}
s_{2, 1} s_{2, 2} \cdots s_{2, W}
:
s_{H, 1} s_{H, 2} \cdots s_{H, W} | import sys
sys.setrecursionlimit(1000000000)
ii = lambda: int(input())
mis = lambda: map(int, input().split())
lmis = lambda: list(mis())
mlmis = lambda: [-int(x) for x in input().split()]
INF = float("inf")
#
def main():
H, W, K = mis()
S = [input() for i in range(H)]
ranges = []
u = b = 0
while u < H:
if "#" in S[b]:
ranges.append(range(u, b + 1))
u = b = b + 1
elif b == H - 1:
last = ranges.pop()
ranges.append(range(last[0], H))
break
else:
b += 1
c = 1
for ran in ranges:
l = r = 0
s = []
while l < W:
s.append(c)
if any(S[i][r] == "#" for i in ran):
c += 1
l = r = r + 1
elif r == W - 1:
for i, elem in enumerate(s):
if elem == c:
s[i] = c - 1
break
else:
r += 1
for _ in ran:
print(" ".join(map(str, s)))
main()
| Statement
Chokudai made a rectangular cake for contestants in DDCC 2020 Finals.
The cake has H - 1 horizontal notches and W - 1 vertical notches, which divide
the cake into H \times W equal sections. K of these sections has a strawberry
on top of each of them.
The positions of the strawberries are given to you as H \times W characters
s_{i, j} (1 \leq i \leq H, 1 \leq j \leq W). If s_{i, j} is `#`, the section
at the i-th row from the top and the j-th column from the left contains a
strawberry; if s_{i, j} is `.`, the section does not contain one. There are
exactly K occurrences of `#`s.
Takahashi wants to cut this cake into K pieces and serve them to the
contestants. Each of these pieces must satisfy the following conditions:
* Has a rectangular shape.
* Contains exactly one strawberry.
One possible way to cut the cake is shown below:

Find one way to cut the cake and satisfy the condition. We can show that this
is always possible, regardless of the number and positions of the
strawberries. | [{"input": "3 3 5\n #.#\n .#.\n #.#", "output": "1 2 2\n 1 3 4\n 5 5 4\n \n\nOne way to cut this cake is shown below:\n\n\n\n* * *"}, {"input": "3 7 7\n #...#.#\n ..#...#\n .#..#..", "output": "1 1 2 2 3 4 4\n 6 6 2 2 3 5 5\n 6 6 7 7 7 7 7\n \n\nOne way to cut this cake is shown below:\n\n\n\n* * *"}, {"input": "13 21 106\n .....................\n .####.####.####.####.\n ..#.#..#.#.#....#....\n ..#.#..#.#.#....#....\n ..#.#..#.#.#....#....\n .####.####.####.####.\n .....................\n .####.####.####.####.\n ....#.#..#....#.#..#.\n .####.#..#.####.#..#.\n .#....#..#.#....#..#.\n .####.####.####.####.\n .....................", "output": "12 12 23 34 45 45 60 71 82 93 93 2 13 24 35 35 17 28 39 50 50\n 12 12 23 34 45 45 60 71 82 93 93 2 13 24 35 35 17 28 39 50 50\n 12 12 56 89 89 89 60 104 82 31 31 46 13 24 35 35 61 61 39 50 50\n 12 12 67 67 100 100 60 9 9 42 42 57 13 24 6 72 72 72 72 72 72\n 12 12 78 5 5 5 20 20 20 53 68 68 90 24 6 83 83 83 83 83 83\n 16 16 27 38 49 49 64 75 86 97 79 79 90 101 6 94 94 105 10 21 21\n 16 16 27 38 49 49 64 75 86 97 79 79 90 101 6 94 94 105 10 21 21\n 32 32 43 54 65 65 80 11 106 95 22 22 33 44 55 55 70 1 96 85 85\n 32 32 43 54 76 76 91 11 106 84 84 4 99 66 66 66 81 1 96 74 74\n 14 14 3 98 87 87 102 11 73 73 73 4 99 88 77 77 92 92 63 63 63\n 25 25 3 98 87 87 7 29 62 62 62 15 99 88 77 77 103 19 30 52 52\n 36 36 47 58 69 69 18 29 40 51 51 26 37 48 59 59 8 19 30 41 41\n 36 36 47 58 69 69 18 29 40 51 51 26 37 48 59 59 8 19 30 41 41"}] |
Assign the numbers 1, 2, 3, \dots, K to the K pieces obtained after the cut,
in any order. Then, let a_{i, j} be the number representing the piece
containing the section at the i-th row from the top and the j-th column from
the left of the cake. Output should be in the following format:
a_{1, 1} \ a_{1, 2} \ \cdots \ a_{1, W}
a_{2, 1} \ a_{2, 2} \ \cdots \ a_{2, W}
:
a_{H, 1} \ a_{H, 2} \ \cdots \ a_{H, W}
If multiple solutions exist, any of them will be accepted.
* * * | s492398639 | Accepted | p02855 | Input is given from Standard Input in the following format:
H W K
s_{1, 1} s_{1, 2} \cdots s_{1, W}
s_{2, 1} s_{2, 2} \cdots s_{2, W}
:
s_{H, 1} s_{H, 2} \cdots s_{H, W} | def solve():
import sys
sys.setrecursionlimit(10**7)
h, w, k = map(int, input().split())
s = tuple(input() for _ in range(h))
def build_table(h, w, s):
"""1-indexed, ケーキ個数の二次元累積和"""
ret = [[0] * (w + 1) for _ in range(h + 1)]
for r in range(h):
for c in range(w):
ret[r + 1][c + 1] = (
ret[r][c + 1]
+ ret[r + 1][c]
- ret[r][c]
+ (1 if s[r][c] == "#" else 0)
)
return ret
def rec(ar=0, ac=0, br=h, bc=w, remains=k) -> None:
# print(ar, ac, br, bc, remains)
nonlocal curr
if remains == 1:
for r in range(ar, br):
for c in range(ac, bc):
ret[r][c] = curr
curr += 1
return
for r in range(ar + 1, br + 1):
t = tbl[r][bc] - tbl[ar][bc] - tbl[r][ac] + tbl[ar][ac]
if 0 < t < remains:
rec(ar, ac, r, bc, t)
rec(r, ac, br, bc, remains - t)
return
for c in range(ac + 1, bc + 1):
t = tbl[br][c] - tbl[br][ac] - tbl[ar][c] + tbl[ar][ac]
if 0 < t < remains:
rec(ar, ac, br, c, t)
rec(ar, c, br, bc, remains - t)
return
tbl = build_table(h, w, s) # 1-indexed, ケーキ個数の二次元累積和
ret = [[-1] * w for _ in range(h)]
curr = 1
rec()
return ret
if __name__ == "__main__":
ret = solve()
for row in ret:
print(*row)
# s(0,0),t(h,w)
# [s,t)
# 二次元累積和を利用して、行または列に平行な直線で、recに与えられた長方形を二分する
# 分割後に含まれるケーキ数が減ることを保証するため、片方の分割にすべてのケーキが含まれるものは認めない
| Statement
Chokudai made a rectangular cake for contestants in DDCC 2020 Finals.
The cake has H - 1 horizontal notches and W - 1 vertical notches, which divide
the cake into H \times W equal sections. K of these sections has a strawberry
on top of each of them.
The positions of the strawberries are given to you as H \times W characters
s_{i, j} (1 \leq i \leq H, 1 \leq j \leq W). If s_{i, j} is `#`, the section
at the i-th row from the top and the j-th column from the left contains a
strawberry; if s_{i, j} is `.`, the section does not contain one. There are
exactly K occurrences of `#`s.
Takahashi wants to cut this cake into K pieces and serve them to the
contestants. Each of these pieces must satisfy the following conditions:
* Has a rectangular shape.
* Contains exactly one strawberry.
One possible way to cut the cake is shown below:

Find one way to cut the cake and satisfy the condition. We can show that this
is always possible, regardless of the number and positions of the
strawberries. | [{"input": "3 3 5\n #.#\n .#.\n #.#", "output": "1 2 2\n 1 3 4\n 5 5 4\n \n\nOne way to cut this cake is shown below:\n\n\n\n* * *"}, {"input": "3 7 7\n #...#.#\n ..#...#\n .#..#..", "output": "1 1 2 2 3 4 4\n 6 6 2 2 3 5 5\n 6 6 7 7 7 7 7\n \n\nOne way to cut this cake is shown below:\n\n\n\n* * *"}, {"input": "13 21 106\n .....................\n .####.####.####.####.\n ..#.#..#.#.#....#....\n ..#.#..#.#.#....#....\n ..#.#..#.#.#....#....\n .####.####.####.####.\n .....................\n .####.####.####.####.\n ....#.#..#....#.#..#.\n .####.#..#.####.#..#.\n .#....#..#.#....#..#.\n .####.####.####.####.\n .....................", "output": "12 12 23 34 45 45 60 71 82 93 93 2 13 24 35 35 17 28 39 50 50\n 12 12 23 34 45 45 60 71 82 93 93 2 13 24 35 35 17 28 39 50 50\n 12 12 56 89 89 89 60 104 82 31 31 46 13 24 35 35 61 61 39 50 50\n 12 12 67 67 100 100 60 9 9 42 42 57 13 24 6 72 72 72 72 72 72\n 12 12 78 5 5 5 20 20 20 53 68 68 90 24 6 83 83 83 83 83 83\n 16 16 27 38 49 49 64 75 86 97 79 79 90 101 6 94 94 105 10 21 21\n 16 16 27 38 49 49 64 75 86 97 79 79 90 101 6 94 94 105 10 21 21\n 32 32 43 54 65 65 80 11 106 95 22 22 33 44 55 55 70 1 96 85 85\n 32 32 43 54 76 76 91 11 106 84 84 4 99 66 66 66 81 1 96 74 74\n 14 14 3 98 87 87 102 11 73 73 73 4 99 88 77 77 92 92 63 63 63\n 25 25 3 98 87 87 7 29 62 62 62 15 99 88 77 77 103 19 30 52 52\n 36 36 47 58 69 69 18 29 40 51 51 26 37 48 59 59 8 19 30 41 41\n 36 36 47 58 69 69 18 29 40 51 51 26 37 48 59 59 8 19 30 41 41"}] |
Assign the numbers 1, 2, 3, \dots, K to the K pieces obtained after the cut,
in any order. Then, let a_{i, j} be the number representing the piece
containing the section at the i-th row from the top and the j-th column from
the left of the cake. Output should be in the following format:
a_{1, 1} \ a_{1, 2} \ \cdots \ a_{1, W}
a_{2, 1} \ a_{2, 2} \ \cdots \ a_{2, W}
:
a_{H, 1} \ a_{H, 2} \ \cdots \ a_{H, W}
If multiple solutions exist, any of them will be accepted.
* * * | s362817501 | Accepted | p02855 | Input is given from Standard Input in the following format:
H W K
s_{1, 1} s_{1, 2} \cdots s_{1, W}
s_{2, 1} s_{2, 2} \cdots s_{2, W}
:
s_{H, 1} s_{H, 2} \cdots s_{H, W} | H, W, K = map(int, input().split())
S = (
[list("#" * (W + 2))]
+ [list("#" + input() + "#") for _ in range(H)]
+ [list("#" * (W + 2))]
)
arr = []
for y, s in enumerate(S[1:-1]):
for x, c in enumerate(s[1:-1]):
if c == "#":
arr.append((y + 1, x + 1))
ans = [[None] * W for _ in range(H)]
for i, a in enumerate(arr):
y, x = a
# S[y][x] = '.'
top = bottom = y
left = right = x
# 横方向に行けるだけ伸ばす
while S[y][left - 1] == ".":
left -= 1
while S[y][right + 1] == ".":
right += 1
# 縦方向に行けるだけ伸ばす
while "#" not in S[top - 1][left : right + 1]:
top -= 1
while "#" not in S[bottom + 1][left : right + 1]:
bottom += 1
for y in range(top, bottom + 1):
for x in range(left, right + 1):
S[y][x] = "#"
ans[y - 1][x - 1] = i + 1
for line in ans:
print(" ".join(map(str, line)))
| Statement
Chokudai made a rectangular cake for contestants in DDCC 2020 Finals.
The cake has H - 1 horizontal notches and W - 1 vertical notches, which divide
the cake into H \times W equal sections. K of these sections has a strawberry
on top of each of them.
The positions of the strawberries are given to you as H \times W characters
s_{i, j} (1 \leq i \leq H, 1 \leq j \leq W). If s_{i, j} is `#`, the section
at the i-th row from the top and the j-th column from the left contains a
strawberry; if s_{i, j} is `.`, the section does not contain one. There are
exactly K occurrences of `#`s.
Takahashi wants to cut this cake into K pieces and serve them to the
contestants. Each of these pieces must satisfy the following conditions:
* Has a rectangular shape.
* Contains exactly one strawberry.
One possible way to cut the cake is shown below:

Find one way to cut the cake and satisfy the condition. We can show that this
is always possible, regardless of the number and positions of the
strawberries. | [{"input": "3 3 5\n #.#\n .#.\n #.#", "output": "1 2 2\n 1 3 4\n 5 5 4\n \n\nOne way to cut this cake is shown below:\n\n\n\n* * *"}, {"input": "3 7 7\n #...#.#\n ..#...#\n .#..#..", "output": "1 1 2 2 3 4 4\n 6 6 2 2 3 5 5\n 6 6 7 7 7 7 7\n \n\nOne way to cut this cake is shown below:\n\n\n\n* * *"}, {"input": "13 21 106\n .....................\n .####.####.####.####.\n ..#.#..#.#.#....#....\n ..#.#..#.#.#....#....\n ..#.#..#.#.#....#....\n .####.####.####.####.\n .....................\n .####.####.####.####.\n ....#.#..#....#.#..#.\n .####.#..#.####.#..#.\n .#....#..#.#....#..#.\n .####.####.####.####.\n .....................", "output": "12 12 23 34 45 45 60 71 82 93 93 2 13 24 35 35 17 28 39 50 50\n 12 12 23 34 45 45 60 71 82 93 93 2 13 24 35 35 17 28 39 50 50\n 12 12 56 89 89 89 60 104 82 31 31 46 13 24 35 35 61 61 39 50 50\n 12 12 67 67 100 100 60 9 9 42 42 57 13 24 6 72 72 72 72 72 72\n 12 12 78 5 5 5 20 20 20 53 68 68 90 24 6 83 83 83 83 83 83\n 16 16 27 38 49 49 64 75 86 97 79 79 90 101 6 94 94 105 10 21 21\n 16 16 27 38 49 49 64 75 86 97 79 79 90 101 6 94 94 105 10 21 21\n 32 32 43 54 65 65 80 11 106 95 22 22 33 44 55 55 70 1 96 85 85\n 32 32 43 54 76 76 91 11 106 84 84 4 99 66 66 66 81 1 96 74 74\n 14 14 3 98 87 87 102 11 73 73 73 4 99 88 77 77 92 92 63 63 63\n 25 25 3 98 87 87 7 29 62 62 62 15 99 88 77 77 103 19 30 52 52\n 36 36 47 58 69 69 18 29 40 51 51 26 37 48 59 59 8 19 30 41 41\n 36 36 47 58 69 69 18 29 40 51 51 26 37 48 59 59 8 19 30 41 41"}] |
Assign the numbers 1, 2, 3, \dots, K to the K pieces obtained after the cut,
in any order. Then, let a_{i, j} be the number representing the piece
containing the section at the i-th row from the top and the j-th column from
the left of the cake. Output should be in the following format:
a_{1, 1} \ a_{1, 2} \ \cdots \ a_{1, W}
a_{2, 1} \ a_{2, 2} \ \cdots \ a_{2, W}
:
a_{H, 1} \ a_{H, 2} \ \cdots \ a_{H, W}
If multiple solutions exist, any of them will be accepted.
* * * | s630946707 | Accepted | p02855 | Input is given from Standard Input in the following format:
H W K
s_{1, 1} s_{1, 2} \cdots s_{1, W}
s_{2, 1} s_{2, 2} \cdots s_{2, W}
:
s_{H, 1} s_{H, 2} \cdots s_{H, W} | import fileinput
import numpy as np
def solve(grid):
groups = np.zeros(grid.shape, dtype=int)
group = 0
group_left = 0
group_right = 0
for i in range(grid.shape[0]):
for j in range(grid.shape[1]):
# Continue to the next SB
if grid[i, j] != "#":
continue
group = group + 1
group_left = j
group_right = j
# Assign to current group
groups[i, j] = group
# Expand right
for j2 in range(j + 1, grid.shape[1]):
# Break if meet a strawberry / already assigned
if grid[i, j2] == "#":
break
if groups[i, j2] != 0:
break
# Expand
groups[i, j2] = group
group_right = j2
# Expand left
for j2 in range(j - 1, -1, -1):
# Break if meet a strawberry / already assigned
if grid[i, j2] == "#":
break
if groups[i, j2] != 0:
break
# Expand
groups[i, j2] = group
group_left = j2
# Expand Down
for i2 in range(i + 1, grid.shape[0]):
# Only expand if none of the squares are SBs or in a group already
expand = True
for j2 in range(group_left, group_right + 1):
if grid[i2, j2] == "#":
expand = False
break
if groups[i2, j2] != 0:
expand = False
break
if not expand:
break
for j2 in range(group_left, group_right + 1):
groups[i2, j2] = group
# Expand Up
for i2 in range(i - 1, -1, -1):
# Only expand if none of the squares are SBs or in a group already
expand = True
for j2 in range(group_left, group_right + 1):
if grid[i2, j2] == "#":
expand = False
break
if groups[i2, j2] != 0:
expand = False
break
if not expand:
break
for j2 in range(group_left, group_right + 1):
groups[i2, j2] = group
return groups
def main():
grid = np.array(
[
(".", ".", ".", ".", ".", ".", "."),
("#", ".", ".", ".", "#", ".", "#"),
(".", ".", ".", ".", "#", ".", "."),
(".", ".", "#", ".", ".", ".", "#"),
(".", "#", ".", ".", "#", ".", "."),
]
)
grid = read_grid()
# print(grid)
groups = solve(grid)
# print(groups)
output_grid(groups)
def output_grid(grid):
for i in range(grid.shape[0]):
for j in range(grid.shape[1]):
print(grid[i, j], end=" ")
print("")
def read_grid():
grid = []
first = True
for line in fileinput.input():
if first:
first = False
continue
grid.append(list(line.rstrip("\n")))
return np.array(grid)
if __name__ == "__main__":
main()
| Statement
Chokudai made a rectangular cake for contestants in DDCC 2020 Finals.
The cake has H - 1 horizontal notches and W - 1 vertical notches, which divide
the cake into H \times W equal sections. K of these sections has a strawberry
on top of each of them.
The positions of the strawberries are given to you as H \times W characters
s_{i, j} (1 \leq i \leq H, 1 \leq j \leq W). If s_{i, j} is `#`, the section
at the i-th row from the top and the j-th column from the left contains a
strawberry; if s_{i, j} is `.`, the section does not contain one. There are
exactly K occurrences of `#`s.
Takahashi wants to cut this cake into K pieces and serve them to the
contestants. Each of these pieces must satisfy the following conditions:
* Has a rectangular shape.
* Contains exactly one strawberry.
One possible way to cut the cake is shown below:

Find one way to cut the cake and satisfy the condition. We can show that this
is always possible, regardless of the number and positions of the
strawberries. | [{"input": "3 3 5\n #.#\n .#.\n #.#", "output": "1 2 2\n 1 3 4\n 5 5 4\n \n\nOne way to cut this cake is shown below:\n\n\n\n* * *"}, {"input": "3 7 7\n #...#.#\n ..#...#\n .#..#..", "output": "1 1 2 2 3 4 4\n 6 6 2 2 3 5 5\n 6 6 7 7 7 7 7\n \n\nOne way to cut this cake is shown below:\n\n\n\n* * *"}, {"input": "13 21 106\n .....................\n .####.####.####.####.\n ..#.#..#.#.#....#....\n ..#.#..#.#.#....#....\n ..#.#..#.#.#....#....\n .####.####.####.####.\n .....................\n .####.####.####.####.\n ....#.#..#....#.#..#.\n .####.#..#.####.#..#.\n .#....#..#.#....#..#.\n .####.####.####.####.\n .....................", "output": "12 12 23 34 45 45 60 71 82 93 93 2 13 24 35 35 17 28 39 50 50\n 12 12 23 34 45 45 60 71 82 93 93 2 13 24 35 35 17 28 39 50 50\n 12 12 56 89 89 89 60 104 82 31 31 46 13 24 35 35 61 61 39 50 50\n 12 12 67 67 100 100 60 9 9 42 42 57 13 24 6 72 72 72 72 72 72\n 12 12 78 5 5 5 20 20 20 53 68 68 90 24 6 83 83 83 83 83 83\n 16 16 27 38 49 49 64 75 86 97 79 79 90 101 6 94 94 105 10 21 21\n 16 16 27 38 49 49 64 75 86 97 79 79 90 101 6 94 94 105 10 21 21\n 32 32 43 54 65 65 80 11 106 95 22 22 33 44 55 55 70 1 96 85 85\n 32 32 43 54 76 76 91 11 106 84 84 4 99 66 66 66 81 1 96 74 74\n 14 14 3 98 87 87 102 11 73 73 73 4 99 88 77 77 92 92 63 63 63\n 25 25 3 98 87 87 7 29 62 62 62 15 99 88 77 77 103 19 30 52 52\n 36 36 47 58 69 69 18 29 40 51 51 26 37 48 59 59 8 19 30 41 41\n 36 36 47 58 69 69 18 29 40 51 51 26 37 48 59 59 8 19 30 41 41"}] |
Assign the numbers 1, 2, 3, \dots, K to the K pieces obtained after the cut,
in any order. Then, let a_{i, j} be the number representing the piece
containing the section at the i-th row from the top and the j-th column from
the left of the cake. Output should be in the following format:
a_{1, 1} \ a_{1, 2} \ \cdots \ a_{1, W}
a_{2, 1} \ a_{2, 2} \ \cdots \ a_{2, W}
:
a_{H, 1} \ a_{H, 2} \ \cdots \ a_{H, W}
If multiple solutions exist, any of them will be accepted.
* * * | s130400825 | Wrong Answer | p02855 | Input is given from Standard Input in the following format:
H W K
s_{1, 1} s_{1, 2} \cdots s_{1, W}
s_{2, 1} s_{2, 2} \cdots s_{2, W}
:
s_{H, 1} s_{H, 2} \cdots s_{H, W} | H, W, K = map(int, input().split())
arr = []
for i in range(H):
A = input()
new = []
for a in A:
if a == "#":
new.append(1)
else:
new.append(0)
arr.append(new)
is_st = [sum(a) > 0 for a in arr]
pos_st = [i for i, e in enumerate(is_st) if e != 0]
first_row = min(pos_st)
current = 0
ans = []
for i, line in enumerate(arr):
# イチゴが最初に出てくる行までは無視(それまでの行は最後に処理)
if i >= first_row:
current += 1
line_ans = []
total = sum(line)
# イチゴがない場合は前の行と同じ値を採用
if total == 0:
ans.append(ans[-1])
# イチゴが少なくともひとつある場合
else:
line_count = 0
for pos in line:
line_ans.append(current)
if pos == 1:
line_count += 1
if line_count < total:
current += 1
ans.append(line_ans)
if first_row > 0:
first_ans = []
for i in range(first_row):
first_ans.append(ans[0])
ans = first_ans + ans
for line in ans:
string = ""
for a in line:
string += str(a) + " "
print(string)
| Statement
Chokudai made a rectangular cake for contestants in DDCC 2020 Finals.
The cake has H - 1 horizontal notches and W - 1 vertical notches, which divide
the cake into H \times W equal sections. K of these sections has a strawberry
on top of each of them.
The positions of the strawberries are given to you as H \times W characters
s_{i, j} (1 \leq i \leq H, 1 \leq j \leq W). If s_{i, j} is `#`, the section
at the i-th row from the top and the j-th column from the left contains a
strawberry; if s_{i, j} is `.`, the section does not contain one. There are
exactly K occurrences of `#`s.
Takahashi wants to cut this cake into K pieces and serve them to the
contestants. Each of these pieces must satisfy the following conditions:
* Has a rectangular shape.
* Contains exactly one strawberry.
One possible way to cut the cake is shown below:

Find one way to cut the cake and satisfy the condition. We can show that this
is always possible, regardless of the number and positions of the
strawberries. | [{"input": "3 3 5\n #.#\n .#.\n #.#", "output": "1 2 2\n 1 3 4\n 5 5 4\n \n\nOne way to cut this cake is shown below:\n\n\n\n* * *"}, {"input": "3 7 7\n #...#.#\n ..#...#\n .#..#..", "output": "1 1 2 2 3 4 4\n 6 6 2 2 3 5 5\n 6 6 7 7 7 7 7\n \n\nOne way to cut this cake is shown below:\n\n\n\n* * *"}, {"input": "13 21 106\n .....................\n .####.####.####.####.\n ..#.#..#.#.#....#....\n ..#.#..#.#.#....#....\n ..#.#..#.#.#....#....\n .####.####.####.####.\n .....................\n .####.####.####.####.\n ....#.#..#....#.#..#.\n .####.#..#.####.#..#.\n .#....#..#.#....#..#.\n .####.####.####.####.\n .....................", "output": "12 12 23 34 45 45 60 71 82 93 93 2 13 24 35 35 17 28 39 50 50\n 12 12 23 34 45 45 60 71 82 93 93 2 13 24 35 35 17 28 39 50 50\n 12 12 56 89 89 89 60 104 82 31 31 46 13 24 35 35 61 61 39 50 50\n 12 12 67 67 100 100 60 9 9 42 42 57 13 24 6 72 72 72 72 72 72\n 12 12 78 5 5 5 20 20 20 53 68 68 90 24 6 83 83 83 83 83 83\n 16 16 27 38 49 49 64 75 86 97 79 79 90 101 6 94 94 105 10 21 21\n 16 16 27 38 49 49 64 75 86 97 79 79 90 101 6 94 94 105 10 21 21\n 32 32 43 54 65 65 80 11 106 95 22 22 33 44 55 55 70 1 96 85 85\n 32 32 43 54 76 76 91 11 106 84 84 4 99 66 66 66 81 1 96 74 74\n 14 14 3 98 87 87 102 11 73 73 73 4 99 88 77 77 92 92 63 63 63\n 25 25 3 98 87 87 7 29 62 62 62 15 99 88 77 77 103 19 30 52 52\n 36 36 47 58 69 69 18 29 40 51 51 26 37 48 59 59 8 19 30 41 41\n 36 36 47 58 69 69 18 29 40 51 51 26 37 48 59 59 8 19 30 41 41"}] |
Assign the numbers 1, 2, 3, \dots, K to the K pieces obtained after the cut,
in any order. Then, let a_{i, j} be the number representing the piece
containing the section at the i-th row from the top and the j-th column from
the left of the cake. Output should be in the following format:
a_{1, 1} \ a_{1, 2} \ \cdots \ a_{1, W}
a_{2, 1} \ a_{2, 2} \ \cdots \ a_{2, W}
:
a_{H, 1} \ a_{H, 2} \ \cdots \ a_{H, W}
If multiple solutions exist, any of them will be accepted.
* * * | s097751799 | Accepted | p02855 | Input is given from Standard Input in the following format:
H W K
s_{1, 1} s_{1, 2} \cdots s_{1, W}
s_{2, 1} s_{2, 2} \cdots s_{2, W}
:
s_{H, 1} s_{H, 2} \cdots s_{H, W} | import numpy as np
inputs = open(0).readlines()
def main(inputs):
h, w, k = map(int, inputs[0].split())
cake, count, coords = np.zeros((h, w), dtype=np.uint), 0, {}
for i, s in enumerate(inputs[1:]):
for j, c in enumerate(s):
if c == "#":
count += 1
cake[i, j] = count
coords[count] = (j, i)
empty_rows = {i for i, rows in enumerate(cake) if not np.any(rows)}
for i in range(1, count + 1):
x, y = coords[i]
x0, y0 = x - 1, y - 1
x1, y1 = x + 1, y + 1
while 0 <= x0 and cake[y, x0] == 0:
cake[y, x0] = i
x0 -= 1
x0 += 1
while x1 < w and cake[y, x1] == 0:
cake[y, x1] = i
x1 += 1
while 0 <= y0 and y0 in empty_rows:
cake[y0, x0:x1] = i
y0 -= 1
while y1 < h and y1 in empty_rows:
cake[y1, x0:x1] = i
y1 += 1
for rows in cake:
print(*rows)
main(inputs)
| Statement
Chokudai made a rectangular cake for contestants in DDCC 2020 Finals.
The cake has H - 1 horizontal notches and W - 1 vertical notches, which divide
the cake into H \times W equal sections. K of these sections has a strawberry
on top of each of them.
The positions of the strawberries are given to you as H \times W characters
s_{i, j} (1 \leq i \leq H, 1 \leq j \leq W). If s_{i, j} is `#`, the section
at the i-th row from the top and the j-th column from the left contains a
strawberry; if s_{i, j} is `.`, the section does not contain one. There are
exactly K occurrences of `#`s.
Takahashi wants to cut this cake into K pieces and serve them to the
contestants. Each of these pieces must satisfy the following conditions:
* Has a rectangular shape.
* Contains exactly one strawberry.
One possible way to cut the cake is shown below:

Find one way to cut the cake and satisfy the condition. We can show that this
is always possible, regardless of the number and positions of the
strawberries. | [{"input": "3 3 5\n #.#\n .#.\n #.#", "output": "1 2 2\n 1 3 4\n 5 5 4\n \n\nOne way to cut this cake is shown below:\n\n\n\n* * *"}, {"input": "3 7 7\n #...#.#\n ..#...#\n .#..#..", "output": "1 1 2 2 3 4 4\n 6 6 2 2 3 5 5\n 6 6 7 7 7 7 7\n \n\nOne way to cut this cake is shown below:\n\n\n\n* * *"}, {"input": "13 21 106\n .....................\n .####.####.####.####.\n ..#.#..#.#.#....#....\n ..#.#..#.#.#....#....\n ..#.#..#.#.#....#....\n .####.####.####.####.\n .....................\n .####.####.####.####.\n ....#.#..#....#.#..#.\n .####.#..#.####.#..#.\n .#....#..#.#....#..#.\n .####.####.####.####.\n .....................", "output": "12 12 23 34 45 45 60 71 82 93 93 2 13 24 35 35 17 28 39 50 50\n 12 12 23 34 45 45 60 71 82 93 93 2 13 24 35 35 17 28 39 50 50\n 12 12 56 89 89 89 60 104 82 31 31 46 13 24 35 35 61 61 39 50 50\n 12 12 67 67 100 100 60 9 9 42 42 57 13 24 6 72 72 72 72 72 72\n 12 12 78 5 5 5 20 20 20 53 68 68 90 24 6 83 83 83 83 83 83\n 16 16 27 38 49 49 64 75 86 97 79 79 90 101 6 94 94 105 10 21 21\n 16 16 27 38 49 49 64 75 86 97 79 79 90 101 6 94 94 105 10 21 21\n 32 32 43 54 65 65 80 11 106 95 22 22 33 44 55 55 70 1 96 85 85\n 32 32 43 54 76 76 91 11 106 84 84 4 99 66 66 66 81 1 96 74 74\n 14 14 3 98 87 87 102 11 73 73 73 4 99 88 77 77 92 92 63 63 63\n 25 25 3 98 87 87 7 29 62 62 62 15 99 88 77 77 103 19 30 52 52\n 36 36 47 58 69 69 18 29 40 51 51 26 37 48 59 59 8 19 30 41 41\n 36 36 47 58 69 69 18 29 40 51 51 26 37 48 59 59 8 19 30 41 41"}] |
Assign the numbers 1, 2, 3, \dots, K to the K pieces obtained after the cut,
in any order. Then, let a_{i, j} be the number representing the piece
containing the section at the i-th row from the top and the j-th column from
the left of the cake. Output should be in the following format:
a_{1, 1} \ a_{1, 2} \ \cdots \ a_{1, W}
a_{2, 1} \ a_{2, 2} \ \cdots \ a_{2, W}
:
a_{H, 1} \ a_{H, 2} \ \cdots \ a_{H, W}
If multiple solutions exist, any of them will be accepted.
* * * | s019010544 | Accepted | p02855 | Input is given from Standard Input in the following format:
H W K
s_{1, 1} s_{1, 2} \cdots s_{1, W}
s_{2, 1} s_{2, 2} \cdots s_{2, W}
:
s_{H, 1} s_{H, 2} \cdots s_{H, W} | N, M, K = map(int, input().split())
chess = [input() for i in range(N)]
ans = [[0 for i in range(M)] for j in range(N)]
index = 0
def ok(r, h, t):
for i in range(h, t + 1):
if ans[r][i] or chess[r][i] == "#":
return False
return True
def color(r, h, t):
for i in range(h, t + 1):
ans[r][i] = index
# mother fucker
for i in range(N):
j = 0
while j < M:
if chess[i][j] == ".":
j += 1
continue
index += 1
l = j - 1
while l >= 0 and chess[i][l] == "." and ans[i][l] == 0:
l -= 1
l += 1
r = j + 1
while r < M and chess[i][r] == "." and ans[i][r] == 0:
r += 1
r -= 1
# [l,r]
# color
color(i, l, r)
for k in range(i - 1, -1, -1):
if ok(k, l, r):
color(k, l, r)
else:
break
for k in range(i + 1, N):
if ok(k, l, r):
color(k, l, r)
else:
break
j = r + 1
for i in range(N):
for j in range(M - 1):
print(ans[i][j], end="")
print(" ", end="")
print(ans[i][M - 1], end="")
print("")
| Statement
Chokudai made a rectangular cake for contestants in DDCC 2020 Finals.
The cake has H - 1 horizontal notches and W - 1 vertical notches, which divide
the cake into H \times W equal sections. K of these sections has a strawberry
on top of each of them.
The positions of the strawberries are given to you as H \times W characters
s_{i, j} (1 \leq i \leq H, 1 \leq j \leq W). If s_{i, j} is `#`, the section
at the i-th row from the top and the j-th column from the left contains a
strawberry; if s_{i, j} is `.`, the section does not contain one. There are
exactly K occurrences of `#`s.
Takahashi wants to cut this cake into K pieces and serve them to the
contestants. Each of these pieces must satisfy the following conditions:
* Has a rectangular shape.
* Contains exactly one strawberry.
One possible way to cut the cake is shown below:

Find one way to cut the cake and satisfy the condition. We can show that this
is always possible, regardless of the number and positions of the
strawberries. | [{"input": "3 3 5\n #.#\n .#.\n #.#", "output": "1 2 2\n 1 3 4\n 5 5 4\n \n\nOne way to cut this cake is shown below:\n\n\n\n* * *"}, {"input": "3 7 7\n #...#.#\n ..#...#\n .#..#..", "output": "1 1 2 2 3 4 4\n 6 6 2 2 3 5 5\n 6 6 7 7 7 7 7\n \n\nOne way to cut this cake is shown below:\n\n\n\n* * *"}, {"input": "13 21 106\n .....................\n .####.####.####.####.\n ..#.#..#.#.#....#....\n ..#.#..#.#.#....#....\n ..#.#..#.#.#....#....\n .####.####.####.####.\n .....................\n .####.####.####.####.\n ....#.#..#....#.#..#.\n .####.#..#.####.#..#.\n .#....#..#.#....#..#.\n .####.####.####.####.\n .....................", "output": "12 12 23 34 45 45 60 71 82 93 93 2 13 24 35 35 17 28 39 50 50\n 12 12 23 34 45 45 60 71 82 93 93 2 13 24 35 35 17 28 39 50 50\n 12 12 56 89 89 89 60 104 82 31 31 46 13 24 35 35 61 61 39 50 50\n 12 12 67 67 100 100 60 9 9 42 42 57 13 24 6 72 72 72 72 72 72\n 12 12 78 5 5 5 20 20 20 53 68 68 90 24 6 83 83 83 83 83 83\n 16 16 27 38 49 49 64 75 86 97 79 79 90 101 6 94 94 105 10 21 21\n 16 16 27 38 49 49 64 75 86 97 79 79 90 101 6 94 94 105 10 21 21\n 32 32 43 54 65 65 80 11 106 95 22 22 33 44 55 55 70 1 96 85 85\n 32 32 43 54 76 76 91 11 106 84 84 4 99 66 66 66 81 1 96 74 74\n 14 14 3 98 87 87 102 11 73 73 73 4 99 88 77 77 92 92 63 63 63\n 25 25 3 98 87 87 7 29 62 62 62 15 99 88 77 77 103 19 30 52 52\n 36 36 47 58 69 69 18 29 40 51 51 26 37 48 59 59 8 19 30 41 41\n 36 36 47 58 69 69 18 29 40 51 51 26 37 48 59 59 8 19 30 41 41"}] |
Assign the numbers 1, 2, 3, \dots, K to the K pieces obtained after the cut,
in any order. Then, let a_{i, j} be the number representing the piece
containing the section at the i-th row from the top and the j-th column from
the left of the cake. Output should be in the following format:
a_{1, 1} \ a_{1, 2} \ \cdots \ a_{1, W}
a_{2, 1} \ a_{2, 2} \ \cdots \ a_{2, W}
:
a_{H, 1} \ a_{H, 2} \ \cdots \ a_{H, W}
If multiple solutions exist, any of them will be accepted.
* * * | s988177688 | Runtime Error | p02855 | Input is given from Standard Input in the following format:
H W K
s_{1, 1} s_{1, 2} \cdots s_{1, W}
s_{2, 1} s_{2, 2} \cdots s_{2, W}
:
s_{H, 1} s_{H, 2} \cdots s_{H, W} | h, w, k = map(int, input().split())
s = []
for i in range(h):
s.append(list(input()))
# print(s)
cnt = []
count = 1
# print(cnt)
ans = []
for i in range(h):
ans.append([0] * w)
if w >= h:
for i in range(h):
for j in range(w):
if s[i][j] == "#":
cnt.append([i, j, str(count)])
count += 1
for i in range(len(cnt)):
if i == 0:
t = cnt[i][0]
for j in range(cnt[i][1] + 1):
ans[t][j] = cnt[i][2]
elif i > 0 and cnt[i - 1][0] == cnt[i][0]:
t = cnt[i - 1][0]
for j in range(cnt[i - 1][1] + 1, cnt[i][1] + 1):
ans[t][j] = cnt[i][2]
elif i > 0 and cnt[i - 1][0] != cnt[i][0]:
for k in range(cnt[i - 1][1] + 1, w):
ans[cnt[i - 1][0]][k] = cnt[i - 1][2]
for j in range(cnt[i][1] + 1):
ans[cnt[i][0]][j] = cnt[i][2]
if i == len(cnt) - 1 and cnt[i][1] < w - 1:
for k in range(cnt[i][1] + 1, w):
ans[cnt[i][0]][k] = cnt[i][2]
# print(ans)
for i in range(h):
for j in range(w):
if ans[i][j] == 0:
if i == 0:
ans[i][j] = ans[i + 1][j]
else:
ans[i][j] = ans[i - 1][j]
# print(ans)
for i in range(h):
print(" ".join(ans[i]))
else:
for i in range(h):
for j in range(w):
if s[i][j] == "#":
cnt.append([i, j, str(count)])
count += 1
print(cnt)
for i in range(len(cnt)):
if i == 0:
t = cnt[i][1]
for j in range(cnt[i][1] + 1):
ans[j][t] = cnt[i][2]
elif i > 0 and cnt[i - 1][1] == cnt[i][1]:
t = cnt[i - 1][1]
for j in range(cnt[i - 1][1] + 1, cnt[i][1] + 1):
ans[j][t] = cnt[i][2]
elif i > 0 and cnt[i - 1][0] != cnt[i][0]:
t = cnt[i - 1][1]
for k in range(cnt[i - 1][1] + 1, h):
ans[k][t] = cnt[i - 1][2]
t = cnt[i][1]
for j in range(cnt[i][1] + 1):
ans[j][t] = cnt[i][2]
if i == len(cnt) - 1 and cnt[i][1] < h - 1:
t = cnt[i][1]
for k in range(cnt[i][1] + 1, h):
ans[k][t] = cnt[i][2]
print(ans)
for i in range(h):
for j in range(w):
if ans[i][j] == 0:
if i == 0:
ans[i][j] = ans[i + 1][j]
else:
ans[i][j] = ans[i - 1][j]
for i in range(h):
for j in range(w):
if ans[i][j] == 0:
if j == 0:
ans[i][j] = ans[i][j + 1]
else:
ans[i][j] = ans[i][j - 1]
# print(ans)
for i in range(h):
print(" ".join(ans[i]))
# for i in range(h):
# print(' '.join(ans[i]))
| Statement
Chokudai made a rectangular cake for contestants in DDCC 2020 Finals.
The cake has H - 1 horizontal notches and W - 1 vertical notches, which divide
the cake into H \times W equal sections. K of these sections has a strawberry
on top of each of them.
The positions of the strawberries are given to you as H \times W characters
s_{i, j} (1 \leq i \leq H, 1 \leq j \leq W). If s_{i, j} is `#`, the section
at the i-th row from the top and the j-th column from the left contains a
strawberry; if s_{i, j} is `.`, the section does not contain one. There are
exactly K occurrences of `#`s.
Takahashi wants to cut this cake into K pieces and serve them to the
contestants. Each of these pieces must satisfy the following conditions:
* Has a rectangular shape.
* Contains exactly one strawberry.
One possible way to cut the cake is shown below:

Find one way to cut the cake and satisfy the condition. We can show that this
is always possible, regardless of the number and positions of the
strawberries. | [{"input": "3 3 5\n #.#\n .#.\n #.#", "output": "1 2 2\n 1 3 4\n 5 5 4\n \n\nOne way to cut this cake is shown below:\n\n\n\n* * *"}, {"input": "3 7 7\n #...#.#\n ..#...#\n .#..#..", "output": "1 1 2 2 3 4 4\n 6 6 2 2 3 5 5\n 6 6 7 7 7 7 7\n \n\nOne way to cut this cake is shown below:\n\n\n\n* * *"}, {"input": "13 21 106\n .....................\n .####.####.####.####.\n ..#.#..#.#.#....#....\n ..#.#..#.#.#....#....\n ..#.#..#.#.#....#....\n .####.####.####.####.\n .....................\n .####.####.####.####.\n ....#.#..#....#.#..#.\n .####.#..#.####.#..#.\n .#....#..#.#....#..#.\n .####.####.####.####.\n .....................", "output": "12 12 23 34 45 45 60 71 82 93 93 2 13 24 35 35 17 28 39 50 50\n 12 12 23 34 45 45 60 71 82 93 93 2 13 24 35 35 17 28 39 50 50\n 12 12 56 89 89 89 60 104 82 31 31 46 13 24 35 35 61 61 39 50 50\n 12 12 67 67 100 100 60 9 9 42 42 57 13 24 6 72 72 72 72 72 72\n 12 12 78 5 5 5 20 20 20 53 68 68 90 24 6 83 83 83 83 83 83\n 16 16 27 38 49 49 64 75 86 97 79 79 90 101 6 94 94 105 10 21 21\n 16 16 27 38 49 49 64 75 86 97 79 79 90 101 6 94 94 105 10 21 21\n 32 32 43 54 65 65 80 11 106 95 22 22 33 44 55 55 70 1 96 85 85\n 32 32 43 54 76 76 91 11 106 84 84 4 99 66 66 66 81 1 96 74 74\n 14 14 3 98 87 87 102 11 73 73 73 4 99 88 77 77 92 92 63 63 63\n 25 25 3 98 87 87 7 29 62 62 62 15 99 88 77 77 103 19 30 52 52\n 36 36 47 58 69 69 18 29 40 51 51 26 37 48 59 59 8 19 30 41 41\n 36 36 47 58 69 69 18 29 40 51 51 26 37 48 59 59 8 19 30 41 41"}] |
Assign the numbers 1, 2, 3, \dots, K to the K pieces obtained after the cut,
in any order. Then, let a_{i, j} be the number representing the piece
containing the section at the i-th row from the top and the j-th column from
the left of the cake. Output should be in the following format:
a_{1, 1} \ a_{1, 2} \ \cdots \ a_{1, W}
a_{2, 1} \ a_{2, 2} \ \cdots \ a_{2, W}
:
a_{H, 1} \ a_{H, 2} \ \cdots \ a_{H, W}
If multiple solutions exist, any of them will be accepted.
* * * | s198195430 | Runtime Error | p02855 | Input is given from Standard Input in the following format:
H W K
s_{1, 1} s_{1, 2} \cdots s_{1, W}
s_{2, 1} s_{2, 2} \cdots s_{2, W}
:
s_{H, 1} s_{H, 2} \cdots s_{H, W} | import copy
class Strawberry:
def __init__(self, id, h, w):
self.id = id
self.h = h
self.w = w
def main():
h, w, k = map(int, input().split())
strawberry_area = [[0 for _ in range(w)] for _ in range(h)]
strawberry_id = 0
first_row_strawberries = []
for h_index in range(h):
line = input()
line_list = list(line)
row_strawberries = 0
strawberries = []
for w_index in range(w):
if line_list[w_index] == "#":
strawberry_id += 1
row_strawberries += 1
strawberries.append(Strawberry(strawberry_id, h_index, w_index))
if len(first_row_strawberries) == 0 and len(strawberries) != 0:
first_row_strawberries = copy.copy(strawberries)
if row_strawberries == 0 and h_index != 0:
for w_index in range(w):
strawberry_area[h_index][w_index] = strawberry_area[h_index - 1][
w_index
]
if row_strawberries != 0:
for strawberry_index in range(len(strawberries)):
strawberry = strawberries[strawberry_index]
if strawberry_index == 0:
for w_index in range(0, strawberry.w + 1):
strawberry_area[h_index][w_index] = strawberry.id
if strawberry_index != len(strawberries) - 1:
next_strawberry = strawberries[strawberry_index + 1]
for w_index in range(strawberry.w, next_strawberry.w):
strawberry_area[h_index][w_index] = strawberry.id
if strawberry_index == len(strawberries) - 1:
for w_index in range(strawberry.w, w):
strawberry_area[h_index][w_index] = strawberry.id
first_h = first_row_strawberries[1].h
for h_index in range(first_h - 1, -1, -1):
for w_index in range(w):
strawberry_area[h_index][w_index] = strawberry_area[h_index + 1][w_index]
print(strawberry_area)
main()
| Statement
Chokudai made a rectangular cake for contestants in DDCC 2020 Finals.
The cake has H - 1 horizontal notches and W - 1 vertical notches, which divide
the cake into H \times W equal sections. K of these sections has a strawberry
on top of each of them.
The positions of the strawberries are given to you as H \times W characters
s_{i, j} (1 \leq i \leq H, 1 \leq j \leq W). If s_{i, j} is `#`, the section
at the i-th row from the top and the j-th column from the left contains a
strawberry; if s_{i, j} is `.`, the section does not contain one. There are
exactly K occurrences of `#`s.
Takahashi wants to cut this cake into K pieces and serve them to the
contestants. Each of these pieces must satisfy the following conditions:
* Has a rectangular shape.
* Contains exactly one strawberry.
One possible way to cut the cake is shown below:

Find one way to cut the cake and satisfy the condition. We can show that this
is always possible, regardless of the number and positions of the
strawberries. | [{"input": "3 3 5\n #.#\n .#.\n #.#", "output": "1 2 2\n 1 3 4\n 5 5 4\n \n\nOne way to cut this cake is shown below:\n\n\n\n* * *"}, {"input": "3 7 7\n #...#.#\n ..#...#\n .#..#..", "output": "1 1 2 2 3 4 4\n 6 6 2 2 3 5 5\n 6 6 7 7 7 7 7\n \n\nOne way to cut this cake is shown below:\n\n\n\n* * *"}, {"input": "13 21 106\n .....................\n .####.####.####.####.\n ..#.#..#.#.#....#....\n ..#.#..#.#.#....#....\n ..#.#..#.#.#....#....\n .####.####.####.####.\n .....................\n .####.####.####.####.\n ....#.#..#....#.#..#.\n .####.#..#.####.#..#.\n .#....#..#.#....#..#.\n .####.####.####.####.\n .....................", "output": "12 12 23 34 45 45 60 71 82 93 93 2 13 24 35 35 17 28 39 50 50\n 12 12 23 34 45 45 60 71 82 93 93 2 13 24 35 35 17 28 39 50 50\n 12 12 56 89 89 89 60 104 82 31 31 46 13 24 35 35 61 61 39 50 50\n 12 12 67 67 100 100 60 9 9 42 42 57 13 24 6 72 72 72 72 72 72\n 12 12 78 5 5 5 20 20 20 53 68 68 90 24 6 83 83 83 83 83 83\n 16 16 27 38 49 49 64 75 86 97 79 79 90 101 6 94 94 105 10 21 21\n 16 16 27 38 49 49 64 75 86 97 79 79 90 101 6 94 94 105 10 21 21\n 32 32 43 54 65 65 80 11 106 95 22 22 33 44 55 55 70 1 96 85 85\n 32 32 43 54 76 76 91 11 106 84 84 4 99 66 66 66 81 1 96 74 74\n 14 14 3 98 87 87 102 11 73 73 73 4 99 88 77 77 92 92 63 63 63\n 25 25 3 98 87 87 7 29 62 62 62 15 99 88 77 77 103 19 30 52 52\n 36 36 47 58 69 69 18 29 40 51 51 26 37 48 59 59 8 19 30 41 41\n 36 36 47 58 69 69 18 29 40 51 51 26 37 48 59 59 8 19 30 41 41"}] |
Assign the numbers 1, 2, 3, \dots, K to the K pieces obtained after the cut,
in any order. Then, let a_{i, j} be the number representing the piece
containing the section at the i-th row from the top and the j-th column from
the left of the cake. Output should be in the following format:
a_{1, 1} \ a_{1, 2} \ \cdots \ a_{1, W}
a_{2, 1} \ a_{2, 2} \ \cdots \ a_{2, W}
:
a_{H, 1} \ a_{H, 2} \ \cdots \ a_{H, W}
If multiple solutions exist, any of them will be accepted.
* * * | s527320551 | Accepted | p02855 | Input is given from Standard Input in the following format:
H W K
s_{1, 1} s_{1, 2} \cdots s_{1, W}
s_{2, 1} s_{2, 2} \cdots s_{2, W}
:
s_{H, 1} s_{H, 2} \cdots s_{H, W} | import sys
sys.setrecursionlimit(10**5)
def solve(cake, start, end, n): # end is not included
s_1 = None
s_2 = None
y = start[0]
while y < end[0] and (not s_1 or not s_2):
x = start[1]
while x < end[1] and (not s_1 or not s_2):
if cake[y][x] == "#":
if not s_1:
s_1 = (y, x)
elif not s_2:
s_2 = (y, x)
x += 1
y += 1
rtn = 0
if s_2:
if s_1[0] != s_2[0]:
rtn = solve(
cake, (s_2[0], start[1]), end, solve(cake, start, (s_2[0], end[1]), n)
)
else:
rtn = solve(
cake, (start[0], s_2[1]), end, solve(cake, start, (end[0], s_2[1]), n)
)
else:
y = start[0]
while y < end[0]:
x = start[1]
while x < end[1]:
cake[y][x] = n
x += 1
y += 1
rtn = n + 1
return rtn
H, W, K = map(int, input().split())
C = [list(input()) for _ in range(H)]
k = solve(C, (0, 0), (H, W), 1)
print("\n".join([" ".join([str(x) for x in c]) for c in C]))
| Statement
Chokudai made a rectangular cake for contestants in DDCC 2020 Finals.
The cake has H - 1 horizontal notches and W - 1 vertical notches, which divide
the cake into H \times W equal sections. K of these sections has a strawberry
on top of each of them.
The positions of the strawberries are given to you as H \times W characters
s_{i, j} (1 \leq i \leq H, 1 \leq j \leq W). If s_{i, j} is `#`, the section
at the i-th row from the top and the j-th column from the left contains a
strawberry; if s_{i, j} is `.`, the section does not contain one. There are
exactly K occurrences of `#`s.
Takahashi wants to cut this cake into K pieces and serve them to the
contestants. Each of these pieces must satisfy the following conditions:
* Has a rectangular shape.
* Contains exactly one strawberry.
One possible way to cut the cake is shown below:

Find one way to cut the cake and satisfy the condition. We can show that this
is always possible, regardless of the number and positions of the
strawberries. | [{"input": "3 3 5\n #.#\n .#.\n #.#", "output": "1 2 2\n 1 3 4\n 5 5 4\n \n\nOne way to cut this cake is shown below:\n\n\n\n* * *"}, {"input": "3 7 7\n #...#.#\n ..#...#\n .#..#..", "output": "1 1 2 2 3 4 4\n 6 6 2 2 3 5 5\n 6 6 7 7 7 7 7\n \n\nOne way to cut this cake is shown below:\n\n\n\n* * *"}, {"input": "13 21 106\n .....................\n .####.####.####.####.\n ..#.#..#.#.#....#....\n ..#.#..#.#.#....#....\n ..#.#..#.#.#....#....\n .####.####.####.####.\n .....................\n .####.####.####.####.\n ....#.#..#....#.#..#.\n .####.#..#.####.#..#.\n .#....#..#.#....#..#.\n .####.####.####.####.\n .....................", "output": "12 12 23 34 45 45 60 71 82 93 93 2 13 24 35 35 17 28 39 50 50\n 12 12 23 34 45 45 60 71 82 93 93 2 13 24 35 35 17 28 39 50 50\n 12 12 56 89 89 89 60 104 82 31 31 46 13 24 35 35 61 61 39 50 50\n 12 12 67 67 100 100 60 9 9 42 42 57 13 24 6 72 72 72 72 72 72\n 12 12 78 5 5 5 20 20 20 53 68 68 90 24 6 83 83 83 83 83 83\n 16 16 27 38 49 49 64 75 86 97 79 79 90 101 6 94 94 105 10 21 21\n 16 16 27 38 49 49 64 75 86 97 79 79 90 101 6 94 94 105 10 21 21\n 32 32 43 54 65 65 80 11 106 95 22 22 33 44 55 55 70 1 96 85 85\n 32 32 43 54 76 76 91 11 106 84 84 4 99 66 66 66 81 1 96 74 74\n 14 14 3 98 87 87 102 11 73 73 73 4 99 88 77 77 92 92 63 63 63\n 25 25 3 98 87 87 7 29 62 62 62 15 99 88 77 77 103 19 30 52 52\n 36 36 47 58 69 69 18 29 40 51 51 26 37 48 59 59 8 19 30 41 41\n 36 36 47 58 69 69 18 29 40 51 51 26 37 48 59 59 8 19 30 41 41"}] |
Assign the numbers 1, 2, 3, \dots, K to the K pieces obtained after the cut,
in any order. Then, let a_{i, j} be the number representing the piece
containing the section at the i-th row from the top and the j-th column from
the left of the cake. Output should be in the following format:
a_{1, 1} \ a_{1, 2} \ \cdots \ a_{1, W}
a_{2, 1} \ a_{2, 2} \ \cdots \ a_{2, W}
:
a_{H, 1} \ a_{H, 2} \ \cdots \ a_{H, W}
If multiple solutions exist, any of them will be accepted.
* * * | s742479552 | Accepted | p02855 | Input is given from Standard Input in the following format:
H W K
s_{1, 1} s_{1, 2} \cdots s_{1, W}
s_{2, 1} s_{2, 2} \cdots s_{2, W}
:
s_{H, 1} s_{H, 2} \cdots s_{H, W} | H, W, K = list(map(int, input().split()))
MAP = [input() for i in range(H)]
CNT = [line.count("#") for line in MAP]
stack = 1
strcnt = 0
for idx, cnt in enumerate(CNT):
sharp_cnt = 0
if cnt == 0:
stack += 1
else:
strcnt += 1
line_lst = []
for char in MAP[idx]:
if char == "#":
sharp_cnt += 1
if sharp_cnt >= 2:
strcnt += 1
line_lst += [str(strcnt)]
for i in range(stack):
print(" ".join(line_lst))
stack = 1
else:
if cnt == 0:
for i in range(stack - 1):
print(" ".join(line_lst))
stack = 1
| Statement
Chokudai made a rectangular cake for contestants in DDCC 2020 Finals.
The cake has H - 1 horizontal notches and W - 1 vertical notches, which divide
the cake into H \times W equal sections. K of these sections has a strawberry
on top of each of them.
The positions of the strawberries are given to you as H \times W characters
s_{i, j} (1 \leq i \leq H, 1 \leq j \leq W). If s_{i, j} is `#`, the section
at the i-th row from the top and the j-th column from the left contains a
strawberry; if s_{i, j} is `.`, the section does not contain one. There are
exactly K occurrences of `#`s.
Takahashi wants to cut this cake into K pieces and serve them to the
contestants. Each of these pieces must satisfy the following conditions:
* Has a rectangular shape.
* Contains exactly one strawberry.
One possible way to cut the cake is shown below:

Find one way to cut the cake and satisfy the condition. We can show that this
is always possible, regardless of the number and positions of the
strawberries. | [{"input": "3 3 5\n #.#\n .#.\n #.#", "output": "1 2 2\n 1 3 4\n 5 5 4\n \n\nOne way to cut this cake is shown below:\n\n\n\n* * *"}, {"input": "3 7 7\n #...#.#\n ..#...#\n .#..#..", "output": "1 1 2 2 3 4 4\n 6 6 2 2 3 5 5\n 6 6 7 7 7 7 7\n \n\nOne way to cut this cake is shown below:\n\n\n\n* * *"}, {"input": "13 21 106\n .....................\n .####.####.####.####.\n ..#.#..#.#.#....#....\n ..#.#..#.#.#....#....\n ..#.#..#.#.#....#....\n .####.####.####.####.\n .....................\n .####.####.####.####.\n ....#.#..#....#.#..#.\n .####.#..#.####.#..#.\n .#....#..#.#....#..#.\n .####.####.####.####.\n .....................", "output": "12 12 23 34 45 45 60 71 82 93 93 2 13 24 35 35 17 28 39 50 50\n 12 12 23 34 45 45 60 71 82 93 93 2 13 24 35 35 17 28 39 50 50\n 12 12 56 89 89 89 60 104 82 31 31 46 13 24 35 35 61 61 39 50 50\n 12 12 67 67 100 100 60 9 9 42 42 57 13 24 6 72 72 72 72 72 72\n 12 12 78 5 5 5 20 20 20 53 68 68 90 24 6 83 83 83 83 83 83\n 16 16 27 38 49 49 64 75 86 97 79 79 90 101 6 94 94 105 10 21 21\n 16 16 27 38 49 49 64 75 86 97 79 79 90 101 6 94 94 105 10 21 21\n 32 32 43 54 65 65 80 11 106 95 22 22 33 44 55 55 70 1 96 85 85\n 32 32 43 54 76 76 91 11 106 84 84 4 99 66 66 66 81 1 96 74 74\n 14 14 3 98 87 87 102 11 73 73 73 4 99 88 77 77 92 92 63 63 63\n 25 25 3 98 87 87 7 29 62 62 62 15 99 88 77 77 103 19 30 52 52\n 36 36 47 58 69 69 18 29 40 51 51 26 37 48 59 59 8 19 30 41 41\n 36 36 47 58 69 69 18 29 40 51 51 26 37 48 59 59 8 19 30 41 41"}] |
Print N lines. The i-th line should contain the coordinate of ant i after T
seconds. Here, each coordinate must be between 0 and L-1, inclusive.
* * * | s422088433 | Runtime Error | p03747 | The input is given from Standard Input in the following format:
N L T
X_1 W_1
X_2 W_2
:
X_N W_N | import sys
readline = sys.stdin.buffer.readline
sys.setrecursionlimit(10 ** 8)
INF = float('inf')
MOD = 10 ** 9 + 7
def main():
N, L, T = map(int, readline().split())
position = []
cnt = 0
for i in range(N):
x,w = map(int, readline().split())
if w==1:
cnt += (x+T)//L
position.append((x+T)%L)
else:
if x-T<0:
cnt += (x-T)//L
position.append((x-T)%L)
position.sort()
cnt %= N
ans = position[cnt:] + position[:cnt]
for i in range(N):
print(ans[i])
| Statement
There is a circle with a circumference of L. Each point on the circumference
has a coordinate value, which represents the arc length from a certain
reference point clockwise to the point. On this circumference, there are N
ants. These ants are numbered 1 through N in order of increasing coordinate,
and ant i is at coordinate X_i.
The N ants have just started walking. For each ant i, you are given the
initial direction W_i. Ant i is initially walking clockwise if W_i is 1;
counterclockwise if W_i is 2. Every ant walks at a constant speed of 1 per
second. Sometimes, two ants bump into each other. Each of these two ants will
then turn around and start walking in the opposite direction.
For each ant, find its position after T seconds. | [{"input": "3 8 3\n 0 1\n 3 2\n 6 1", "output": "1\n 3\n 0\n \n\n1.5 seconds after the ants start walking, ant 1 and 2 bump into each other at\ncoordinate 1.5. 1 second after that, ant 1 and 3 bump into each other at\ncoordinate 0.5. 0.5 seconds after that, that is, 3 seconds after the ants\nstart walking, ants 1, 2 and 3 are at coordinates 1, 3 and 0, respectively.\n\n* * *"}, {"input": "4 20 9\n 7 2\n 9 1\n 12 1\n 18 1", "output": "7\n 18\n 18\n 1"}] |
Print N lines. The i-th line should contain the coordinate of ant i after T
seconds. Here, each coordinate must be between 0 and L-1, inclusive.
* * * | s940152051 | Runtime Error | p03747 | The input is given from Standard Input in the following format:
N L T
X_1 W_1
X_2 W_2
:
X_N W_N | import sys
sys.stdin = open("c2.in")
# sys.stdin = open('gen_c/c10.in')
def solve_it_large(n, l, t, x, w):
ants = []
for i in range(n):
ants.append([x[i], w[i], (x[i] + w[i] * t) % l, i])
# ants.sort()
n_intersections = 0
x0, w0, dest0, i0 = ants[0]
for x, w, dest, i in ants:
if w != w0:
d = (w0 * (x - x0) + l) % l
intersections = 0
if 2 * t >= d:
intersections = (2 * t - d) // l + 1
n_intersections += intersections
res = [0] * n
shift = n_intersections
for i in range(n):
res[ants[(i + w0 * shift) % n][3]] = ants[i][2]
return res
def solve_it_chameleons(n, l, t, x, w):
initial_color = [i for i in range(n)]
chameleons = [[x[i], w[i], initial_color[i]] for i in range(n)]
initial_color_clockwise = [chameleons[i][2] for i in range(n)]
x0, w0, color0 = chameleons[0]
for i in range(n):
if w[i] != w0:
d = (w0 * (x[i] - x0)) % l
meet = 0
if 2 * t >= d:
meet = (2 * t - d) // l + 1
color0 += w0 * meet
color0 %= n
# The chameleon (let's call him chameleon 0) initially at x0 is at (x0 + w0 * t) % l at the end,
# Initially, its color is color0 and it changed <meet> times.
# The final clockwise colors are a translation of the initial clockwise colors.
x_final = [(x[i] + w[i] * t) % l for i in range(n)]
x_final.sort()
i = x_final.index((x0 + w0 * t) % l)
if i + 1 < n and x_final[i] == x_final[i + 1]:
if w0 == 1:
i += 1
res = [0] * n
for k in range(n):
color = (color0 + k) % n
res[color] = x_final[(i + k) % n]
return res
if __name__ == "__main__":
n, l, t = map(int, input().split())
x = []
w = []
for i in range(n):
_x, _w = map(int, input().split())
if _w == 2:
_w = -1
x.append(_x)
w.append(_w)
res = solve_it_chameleons(n, l, t, x, w)
for i in range(n):
print(res[i])
| Statement
There is a circle with a circumference of L. Each point on the circumference
has a coordinate value, which represents the arc length from a certain
reference point clockwise to the point. On this circumference, there are N
ants. These ants are numbered 1 through N in order of increasing coordinate,
and ant i is at coordinate X_i.
The N ants have just started walking. For each ant i, you are given the
initial direction W_i. Ant i is initially walking clockwise if W_i is 1;
counterclockwise if W_i is 2. Every ant walks at a constant speed of 1 per
second. Sometimes, two ants bump into each other. Each of these two ants will
then turn around and start walking in the opposite direction.
For each ant, find its position after T seconds. | [{"input": "3 8 3\n 0 1\n 3 2\n 6 1", "output": "1\n 3\n 0\n \n\n1.5 seconds after the ants start walking, ant 1 and 2 bump into each other at\ncoordinate 1.5. 1 second after that, ant 1 and 3 bump into each other at\ncoordinate 0.5. 0.5 seconds after that, that is, 3 seconds after the ants\nstart walking, ants 1, 2 and 3 are at coordinates 1, 3 and 0, respectively.\n\n* * *"}, {"input": "4 20 9\n 7 2\n 9 1\n 12 1\n 18 1", "output": "7\n 18\n 18\n 1"}] |
Print N lines. The i-th line should contain the coordinate of ant i after T
seconds. Here, each coordinate must be between 0 and L-1, inclusive.
* * * | s953928800 | Wrong Answer | p03747 | The input is given from Standard Input in the following format:
N L T
X_1 W_1
X_2 W_2
:
X_N W_N | import sys
input = sys.stdin.readline
n, l, t = map(int, input().split())
c = []
for i in range(n):
x, w = map(int, input().split())
if w == 1:
c.append((x + t, w, i))
else:
c.append((x - t, w, i))
p, q, r = c[0]
st = 0
ans = c.copy()
for x, w, i in c[::-1]:
if q != w:
if q > w and p < x:
st = i
elif q < w and p > x:
st = i
break
if st != 0:
p, q, r = c[i]
C = c[st:]
for x, w, i in C[::-1]:
if q != w:
if q > w and p < x:
st = i
elif q < w and p > x:
st = i
break
ans_1 = c[i:]
ans_2 = c[:i]
ans = ans_1 + ans_2
for A, N, S in ans:
print(A % l)
| Statement
There is a circle with a circumference of L. Each point on the circumference
has a coordinate value, which represents the arc length from a certain
reference point clockwise to the point. On this circumference, there are N
ants. These ants are numbered 1 through N in order of increasing coordinate,
and ant i is at coordinate X_i.
The N ants have just started walking. For each ant i, you are given the
initial direction W_i. Ant i is initially walking clockwise if W_i is 1;
counterclockwise if W_i is 2. Every ant walks at a constant speed of 1 per
second. Sometimes, two ants bump into each other. Each of these two ants will
then turn around and start walking in the opposite direction.
For each ant, find its position after T seconds. | [{"input": "3 8 3\n 0 1\n 3 2\n 6 1", "output": "1\n 3\n 0\n \n\n1.5 seconds after the ants start walking, ant 1 and 2 bump into each other at\ncoordinate 1.5. 1 second after that, ant 1 and 3 bump into each other at\ncoordinate 0.5. 0.5 seconds after that, that is, 3 seconds after the ants\nstart walking, ants 1, 2 and 3 are at coordinates 1, 3 and 0, respectively.\n\n* * *"}, {"input": "4 20 9\n 7 2\n 9 1\n 12 1\n 18 1", "output": "7\n 18\n 18\n 1"}] |
Print N lines. The i-th line should contain the coordinate of ant i after T
seconds. Here, each coordinate must be between 0 and L-1, inclusive.
* * * | s138648501 | Runtime Error | p03747 | The input is given from Standard Input in the following format:
N L T
X_1 W_1
X_2 W_2
:
X_N W_N | n,l,t=map(int,input().split())
a,cs=[0]*n,0
for i in range(n):
x,y=map(int,input().split())
x+=(t if y==1 else -t)
cs=(cs+x//l)%n
x%=l
a[i]=x
a.sort()
print('\n'.join([str(a[(i+cs)%n]) fori in range(n)]))
| Statement
There is a circle with a circumference of L. Each point on the circumference
has a coordinate value, which represents the arc length from a certain
reference point clockwise to the point. On this circumference, there are N
ants. These ants are numbered 1 through N in order of increasing coordinate,
and ant i is at coordinate X_i.
The N ants have just started walking. For each ant i, you are given the
initial direction W_i. Ant i is initially walking clockwise if W_i is 1;
counterclockwise if W_i is 2. Every ant walks at a constant speed of 1 per
second. Sometimes, two ants bump into each other. Each of these two ants will
then turn around and start walking in the opposite direction.
For each ant, find its position after T seconds. | [{"input": "3 8 3\n 0 1\n 3 2\n 6 1", "output": "1\n 3\n 0\n \n\n1.5 seconds after the ants start walking, ant 1 and 2 bump into each other at\ncoordinate 1.5. 1 second after that, ant 1 and 3 bump into each other at\ncoordinate 0.5. 0.5 seconds after that, that is, 3 seconds after the ants\nstart walking, ants 1, 2 and 3 are at coordinates 1, 3 and 0, respectively.\n\n* * *"}, {"input": "4 20 9\n 7 2\n 9 1\n 12 1\n 18 1", "output": "7\n 18\n 18\n 1"}] |
Print N lines. The i-th line should contain the coordinate of ant i after T
seconds. Here, each coordinate must be between 0 and L-1, inclusive.
* * * | s662020202 | Runtime Error | p03747 | The input is given from Standard Input in the following format:
N L T
X_1 W_1
X_2 W_2
:
X_N W_N | n,l,t=map(int,input().split())
inf=[]
s=0
for _ in range(n)
x,y=map(int,input().split())
if y==1:
x+=t
else:
x-=t
inf.append(x%l)
s+=x//l
inf.sort()
s%n
for i in range(n):
print(inf[(i+p)%n]) | Statement
There is a circle with a circumference of L. Each point on the circumference
has a coordinate value, which represents the arc length from a certain
reference point clockwise to the point. On this circumference, there are N
ants. These ants are numbered 1 through N in order of increasing coordinate,
and ant i is at coordinate X_i.
The N ants have just started walking. For each ant i, you are given the
initial direction W_i. Ant i is initially walking clockwise if W_i is 1;
counterclockwise if W_i is 2. Every ant walks at a constant speed of 1 per
second. Sometimes, two ants bump into each other. Each of these two ants will
then turn around and start walking in the opposite direction.
For each ant, find its position after T seconds. | [{"input": "3 8 3\n 0 1\n 3 2\n 6 1", "output": "1\n 3\n 0\n \n\n1.5 seconds after the ants start walking, ant 1 and 2 bump into each other at\ncoordinate 1.5. 1 second after that, ant 1 and 3 bump into each other at\ncoordinate 0.5. 0.5 seconds after that, that is, 3 seconds after the ants\nstart walking, ants 1, 2 and 3 are at coordinates 1, 3 and 0, respectively.\n\n* * *"}, {"input": "4 20 9\n 7 2\n 9 1\n 12 1\n 18 1", "output": "7\n 18\n 18\n 1"}] |
Print N lines. The i-th line should contain the coordinate of ant i after T
seconds. Here, each coordinate must be between 0 and L-1, inclusive.
* * * | s764723895 | Runtime Error | p03747 | The input is given from Standard Input in the following format:
N L T
X_1 W_1
X_2 W_2
:
X_N W_N | n,l,t=map(int,input().split())
inf=[]
s=0
for _ in range(n):
x,y=map(int,input().split())
if y==1:
x+=t
else:
x-=t
inf.append(x%l)
s+=x//l
inf.sort()
s%n
for i in range(n):
print(inf[(i+p)%n]) | Statement
There is a circle with a circumference of L. Each point on the circumference
has a coordinate value, which represents the arc length from a certain
reference point clockwise to the point. On this circumference, there are N
ants. These ants are numbered 1 through N in order of increasing coordinate,
and ant i is at coordinate X_i.
The N ants have just started walking. For each ant i, you are given the
initial direction W_i. Ant i is initially walking clockwise if W_i is 1;
counterclockwise if W_i is 2. Every ant walks at a constant speed of 1 per
second. Sometimes, two ants bump into each other. Each of these two ants will
then turn around and start walking in the opposite direction.
For each ant, find its position after T seconds. | [{"input": "3 8 3\n 0 1\n 3 2\n 6 1", "output": "1\n 3\n 0\n \n\n1.5 seconds after the ants start walking, ant 1 and 2 bump into each other at\ncoordinate 1.5. 1 second after that, ant 1 and 3 bump into each other at\ncoordinate 0.5. 0.5 seconds after that, that is, 3 seconds after the ants\nstart walking, ants 1, 2 and 3 are at coordinates 1, 3 and 0, respectively.\n\n* * *"}, {"input": "4 20 9\n 7 2\n 9 1\n 12 1\n 18 1", "output": "7\n 18\n 18\n 1"}] |
Print N lines. The i-th line should contain the coordinate of ant i after T
seconds. Here, each coordinate must be between 0 and L-1, inclusive.
* * * | s852841193 | Runtime Error | p03747 | The input is given from Standard Input in the following format:
N L T
X_1 W_1
X_2 W_2
:
X_N W_N | n,l,t=map(int,input().split())
inf=[]
s=0
for _ in range(n):
x,y=map(int,input().split())
if y==1:
x+=t
else:
x-=t
inf.append(x%l)
s+=x//l
inf.sort()
s%n
for i in range(n):
print(inf[(i+s)%n]) | Statement
There is a circle with a circumference of L. Each point on the circumference
has a coordinate value, which represents the arc length from a certain
reference point clockwise to the point. On this circumference, there are N
ants. These ants are numbered 1 through N in order of increasing coordinate,
and ant i is at coordinate X_i.
The N ants have just started walking. For each ant i, you are given the
initial direction W_i. Ant i is initially walking clockwise if W_i is 1;
counterclockwise if W_i is 2. Every ant walks at a constant speed of 1 per
second. Sometimes, two ants bump into each other. Each of these two ants will
then turn around and start walking in the opposite direction.
For each ant, find its position after T seconds. | [{"input": "3 8 3\n 0 1\n 3 2\n 6 1", "output": "1\n 3\n 0\n \n\n1.5 seconds after the ants start walking, ant 1 and 2 bump into each other at\ncoordinate 1.5. 1 second after that, ant 1 and 3 bump into each other at\ncoordinate 0.5. 0.5 seconds after that, that is, 3 seconds after the ants\nstart walking, ants 1, 2 and 3 are at coordinates 1, 3 and 0, respectively.\n\n* * *"}, {"input": "4 20 9\n 7 2\n 9 1\n 12 1\n 18 1", "output": "7\n 18\n 18\n 1"}] |
Print N lines. The i-th line should contain the coordinate of ant i after T
seconds. Here, each coordinate must be between 0 and L-1, inclusive.
* * * | s297780004 | Runtime Error | p03747 | The input is given from Standard Input in the following format:
N L T
X_1 W_1
X_2 W_2
:
X_N W_N | import bisect
import sys
def input():
return sys.stdin.readline()[:-1]
# N = int(input())
# A = [int(x) for x in input().split()]
# a, b, c = map(int, input().split())
# name1 = str(input())
# alph = {"A": 1, "B": 2, "C": 3, "D": 4, "E": 5}
# b = list(map(lambda x: math.ceil(x/10)*10, a))
n, l, t = map(int, input().split())
x = []
w = []
for i in range(n):
a, b = map(int, input().split())
x.append(a)
w.append(b)
def distance(x, y):
if x <= y:
return y - x
else:
return y + l - x
def forward(x):
x += 1
if x == l:
x = 0
return x
def back(x):
x -= 1
if x == -1:
x = l - 1
return x
temp_x = x.copy()
temp_w = w.copy()
for t in range(t):
for i in range(n):
if i == 0:
if w[0] == 2:
if w[n - 1] == 1 and distance(x[n - 1], x[0]) == 2:
temp_x[i] = back(x[i])
temp_w[i] = 1
elif w[n - 1] == 1 and distance(x[n - 1], x[0]) == 1:
temp_w[i] = 1
else:
temp_x[i] = back(x[i])
elif w[i] == 1 and w[i + 1] == 2:
if distance(x[i], x[i + 1]) == 2:
temp_x[i] = forward(x[i])
temp_w[i] = 2
elif distance(x[i], x[i + 1]) == 1:
temp_w[i] = 2
else:
temp_x[i] = forward(x[i])
elif w[i] == 1:
temp_x[i] = forward(x[i])
elif i == n - 1:
if w[n - 1] == 1:
if w[0] == 2 and distance(x[n - 1], x[0]) == 2:
temp_x[i] = forward(x[i])
temp_w[i] = 2
elif w[0] == 2 and distance(x[n - 1], x[0]) == 1:
temp_w[i] = 2
else:
temp_x[i] = forward(x[i])
elif w[i] == 2 and w[i - 1] == 1:
if distance(x[i - 1], x[i]) == 2:
temp_x[i] = back(x[i])
temp_w[i] = 1
elif distance(x[i - 1], x[i]) == 1:
temp_w[i] = 1
else:
temp_x[i] = back(x[i])
elif w[i] == 2:
temp_x[i] = back(x[i])
else:
if w[i] == 1 and w[i + 1] == 2:
if distance(x[i], x[i + 1]) == 2:
temp_x[i] = forward(x[i])
temp_w[i] = 2
elif distance(x[i], x[i + 1]) == 1:
temp_w[i] = 2
else:
temp_x[i] = forward(x[i])
elif w[i] == 1:
temp_x[i] = forward(x[i])
elif w[i] == 2 and w[i - 1] == 1:
if distance(x[i - 1], x[i]) == 2:
temp_x[i] = back(x[i])
temp_w[i] = 1
elif distance(x[i - 1], x[i]) == 1:
temp_w[i] = 1
else:
temp_x[i] = back(x[i])
elif w[i] == 2:
temp_x[i] = back(x[i])
x = temp_x.copy()
w = temp_w.copy()
for i in range(n):
print(x[i])
| Statement
There is a circle with a circumference of L. Each point on the circumference
has a coordinate value, which represents the arc length from a certain
reference point clockwise to the point. On this circumference, there are N
ants. These ants are numbered 1 through N in order of increasing coordinate,
and ant i is at coordinate X_i.
The N ants have just started walking. For each ant i, you are given the
initial direction W_i. Ant i is initially walking clockwise if W_i is 1;
counterclockwise if W_i is 2. Every ant walks at a constant speed of 1 per
second. Sometimes, two ants bump into each other. Each of these two ants will
then turn around and start walking in the opposite direction.
For each ant, find its position after T seconds. | [{"input": "3 8 3\n 0 1\n 3 2\n 6 1", "output": "1\n 3\n 0\n \n\n1.5 seconds after the ants start walking, ant 1 and 2 bump into each other at\ncoordinate 1.5. 1 second after that, ant 1 and 3 bump into each other at\ncoordinate 0.5. 0.5 seconds after that, that is, 3 seconds after the ants\nstart walking, ants 1, 2 and 3 are at coordinates 1, 3 and 0, respectively.\n\n* * *"}, {"input": "4 20 9\n 7 2\n 9 1\n 12 1\n 18 1", "output": "7\n 18\n 18\n 1"}] |
Print N lines. The i-th line should contain the coordinate of ant i after T
seconds. Here, each coordinate must be between 0 and L-1, inclusive.
* * * | s179388993 | Wrong Answer | p03747 | The input is given from Standard Input in the following format:
N L T
X_1 W_1
X_2 W_2
:
X_N W_N | #!/usr/bin/env python
# -*- coding: utf-8 -*-
N, L, T = map(int, input().strip().split())
x = list()
w = list()
for _ in range(N):
x_tmp, w_tmp = map(int, input().strip().split())
x.append(x_tmp)
w.append(w_tmp)
pre_x = list()
pre_w = list()
for _ in range(T):
print("T={}, {}".format(T, x))
pre_x.clear()
pre_w.clear()
for value in x:
pre_x.append(value)
for value in w:
pre_w.append(value)
for i in range(N):
if w[i] == 1:
moved_xi = pre_x[i] + 1
if moved_xi == L:
moved_xi = 0
two_moved_xi = moved_xi + 1
if two_moved_xi == L:
two_moved_xi = 0
if moved_xi in pre_x:
if pre_w[pre_x.index(moved_xi)] == 2:
moved_xi = pre_x[i]
w[i] = 2
elif two_moved_xi in pre_x:
if pre_w[pre_x.index(two_moved_xi)] == 2:
w[i] = 2
x[i] = moved_xi
else:
moved_xi = pre_x[i] - 1
if moved_xi == -1:
moved_xi = L - 1
two_moved_xi = moved_xi - 1
if two_moved_xi == -1:
two_moved_xi = L - 1
if moved_xi in pre_x:
if pre_w[pre_x.index(moved_xi)] == 1:
moved_xi = pre_x[i]
w[i] = 1
elif two_moved_xi in pre_x:
if pre_w[pre_x.index(two_moved_xi)] == 1:
w[i] = 1
x[i] = moved_xi
for i in range(N):
print(x[i])
| Statement
There is a circle with a circumference of L. Each point on the circumference
has a coordinate value, which represents the arc length from a certain
reference point clockwise to the point. On this circumference, there are N
ants. These ants are numbered 1 through N in order of increasing coordinate,
and ant i is at coordinate X_i.
The N ants have just started walking. For each ant i, you are given the
initial direction W_i. Ant i is initially walking clockwise if W_i is 1;
counterclockwise if W_i is 2. Every ant walks at a constant speed of 1 per
second. Sometimes, two ants bump into each other. Each of these two ants will
then turn around and start walking in the opposite direction.
For each ant, find its position after T seconds. | [{"input": "3 8 3\n 0 1\n 3 2\n 6 1", "output": "1\n 3\n 0\n \n\n1.5 seconds after the ants start walking, ant 1 and 2 bump into each other at\ncoordinate 1.5. 1 second after that, ant 1 and 3 bump into each other at\ncoordinate 0.5. 0.5 seconds after that, that is, 3 seconds after the ants\nstart walking, ants 1, 2 and 3 are at coordinates 1, 3 and 0, respectively.\n\n* * *"}, {"input": "4 20 9\n 7 2\n 9 1\n 12 1\n 18 1", "output": "7\n 18\n 18\n 1"}] |
Print N lines. The i-th line should contain the coordinate of ant i after T
seconds. Here, each coordinate must be between 0 and L-1, inclusive.
* * * | s788820091 | Runtime Error | p03747 | The input is given from Standard Input in the following format:
N L T
X_1 W_1
X_2 W_2
:
X_N W_N | n, l, total_t = map(int, input().split())
pos_nt = {i: [] for i in range(n)}
xl = []
wl = []
rrp = []
lrp = []
for i in range(n):
x, w = map(int, input().split())
xl.append(x)
wl.append(w)
if w == 1:
rrp.append(x)
else:
lrp.append(x)
for i in range(n):
if wl[i] == 1:
orig_idx = i
break
is_rr = True
rhead = 0
lhead = 0
for i, p in enumerate(lrp):
if p > rrp[rhead]:
lhead = i
# todo: len(lrp) == 0 の場合
current_pos = rrp[rhead]
t = 0
while True:
if is_rr:
lp = (lrp[lhead] - t) % l
rp = (rrp[rhead] + t) % l
if rp > lp:
rp = rp - l
elapsed = (lp - rp) / 2
if elapsed < 0:
print("oops")
exit()
if t + elapsed > total_t:
break
current_pos = lp - elapsed
t += elapsed
is_rr = False
rhead = (rhead - 1) % len(rrp)
else:
lp = (lrp[lhead] - t) % l
rp = (rrp[rhead] + t) % l
if rp > lp:
rp = rp - l
elapsed = (lp - rp) / 2
if elapsed < 0:
print("oops2")
exit()
if t + elapsed > total_t:
break
current_pos = lp - elapsed
t += elapsed
is_rr = True
lhead = (lhead + 1) % len(lrp)
# rhead = (rhead-1)%len(rrp)
remain_t = total_t - t
is_rr = not is_rr
# print(rrp[rhead])
# print(lrp[lhead])
# exit()
if is_rr:
current_pos = (current_pos + remain_t) % l
else:
current_pos = (current_pos - remain_t) % l
if is_rr:
pos = rrp[rhead] - t
res_list = []
for i in range(n):
if wl[i] == 1:
sl = xl[i] + total_t
else:
sl = xl[i] - total_t
res_list.append(sl % l)
# print(res_list)
# exit()
mod_res_list = []
for i in range(n):
if res_list[i] == current_pos:
hoge = i
break
shift_d = hoge - orig_idx
shift_idx = shift_d % n
for i in range(shift_idx, n):
mod_res_list.append(res_list[i])
for i in range(0, shift_idx):
mod_res_list.append(res_list[i])
# print(mod_res_list)
for r in mod_res_list:
print(r)
# for i in range(hoge, n):
# print(res_list[i])
# for i in range(0, hoge):
# print(res_list[i])
| Statement
There is a circle with a circumference of L. Each point on the circumference
has a coordinate value, which represents the arc length from a certain
reference point clockwise to the point. On this circumference, there are N
ants. These ants are numbered 1 through N in order of increasing coordinate,
and ant i is at coordinate X_i.
The N ants have just started walking. For each ant i, you are given the
initial direction W_i. Ant i is initially walking clockwise if W_i is 1;
counterclockwise if W_i is 2. Every ant walks at a constant speed of 1 per
second. Sometimes, two ants bump into each other. Each of these two ants will
then turn around and start walking in the opposite direction.
For each ant, find its position after T seconds. | [{"input": "3 8 3\n 0 1\n 3 2\n 6 1", "output": "1\n 3\n 0\n \n\n1.5 seconds after the ants start walking, ant 1 and 2 bump into each other at\ncoordinate 1.5. 1 second after that, ant 1 and 3 bump into each other at\ncoordinate 0.5. 0.5 seconds after that, that is, 3 seconds after the ants\nstart walking, ants 1, 2 and 3 are at coordinates 1, 3 and 0, respectively.\n\n* * *"}, {"input": "4 20 9\n 7 2\n 9 1\n 12 1\n 18 1", "output": "7\n 18\n 18\n 1"}] |
Print N lines. The i-th line should contain the coordinate of ant i after T
seconds. Here, each coordinate must be between 0 and L-1, inclusive.
* * * | s570974042 | Accepted | p03747 | The input is given from Standard Input in the following format:
N L T
X_1 W_1
X_2 W_2
:
X_N W_N | from collections import defaultdict, deque, Counter
from heapq import heappush, heappop, heapify
from itertools import (
permutations,
accumulate,
combinations,
combinations_with_replacement,
)
from math import sqrt, ceil, floor, factorial
from bisect import bisect_left, bisect_right, insort_left, insort_right
from copy import deepcopy
from operator import itemgetter
from functools import reduce, lru_cache # @lru_cache(None)
from fractions import gcd
import sys
def input():
return sys.stdin.readline().rstrip()
def I():
return int(input())
def Is():
return (int(x) for x in input().split())
def LI():
return list(Is())
def TI():
return tuple(Is())
def IR(n):
return [I() for _ in range(n)]
def LIR(n):
return [LI() for _ in range(n)]
def TIR(n):
return [TI() for _ in range(n)]
def S():
return input()
def Ss():
return input().split()
def LS():
return list(S())
def SR(n):
return [S() for _ in range(n)]
def SsR(n):
return [Ss() for _ in range(n)]
def LSR(n):
return [LS() for _ in range(n)]
sys.setrecursionlimit(10**6)
MOD = 10**9 + 7
INF = 10**18
# ----------------------------------------------------------- #
n, l, t = Is()
XW = TIR(n)
ANS = []
count = 0
for x, w in XW:
if w == 1:
tmp = (x + t) % l
count += (x + t) // l
else:
tmp = (x - t) % l
count += (x - t) // l
ANS.append(tmp)
count %= n
ANS.sort()
ANS = ANS[count:] + ANS[:count]
for ans in ANS:
print(ans)
| Statement
There is a circle with a circumference of L. Each point on the circumference
has a coordinate value, which represents the arc length from a certain
reference point clockwise to the point. On this circumference, there are N
ants. These ants are numbered 1 through N in order of increasing coordinate,
and ant i is at coordinate X_i.
The N ants have just started walking. For each ant i, you are given the
initial direction W_i. Ant i is initially walking clockwise if W_i is 1;
counterclockwise if W_i is 2. Every ant walks at a constant speed of 1 per
second. Sometimes, two ants bump into each other. Each of these two ants will
then turn around and start walking in the opposite direction.
For each ant, find its position after T seconds. | [{"input": "3 8 3\n 0 1\n 3 2\n 6 1", "output": "1\n 3\n 0\n \n\n1.5 seconds after the ants start walking, ant 1 and 2 bump into each other at\ncoordinate 1.5. 1 second after that, ant 1 and 3 bump into each other at\ncoordinate 0.5. 0.5 seconds after that, that is, 3 seconds after the ants\nstart walking, ants 1, 2 and 3 are at coordinates 1, 3 and 0, respectively.\n\n* * *"}, {"input": "4 20 9\n 7 2\n 9 1\n 12 1\n 18 1", "output": "7\n 18\n 18\n 1"}] |
Print N lines. The i-th line should contain the coordinate of ant i after T
seconds. Here, each coordinate must be between 0 and L-1, inclusive.
* * * | s431295064 | Wrong Answer | p03747 | The input is given from Standard Input in the following format:
N L T
X_1 W_1
X_2 W_2
:
X_N W_N | N, L, T = map(int, input().split())
src = [tuple(map(int, input().split())) for i in range(N)]
mem = []
for x, w in src:
move = -T if w == 2 else T
mem.append((x + move) % L)
first_x = mem[0]
mem.sort()
first_i = mem.index(first_x)
for i in range(first_i, first_i + N):
print(mem[(i - 1) % N])
| Statement
There is a circle with a circumference of L. Each point on the circumference
has a coordinate value, which represents the arc length from a certain
reference point clockwise to the point. On this circumference, there are N
ants. These ants are numbered 1 through N in order of increasing coordinate,
and ant i is at coordinate X_i.
The N ants have just started walking. For each ant i, you are given the
initial direction W_i. Ant i is initially walking clockwise if W_i is 1;
counterclockwise if W_i is 2. Every ant walks at a constant speed of 1 per
second. Sometimes, two ants bump into each other. Each of these two ants will
then turn around and start walking in the opposite direction.
For each ant, find its position after T seconds. | [{"input": "3 8 3\n 0 1\n 3 2\n 6 1", "output": "1\n 3\n 0\n \n\n1.5 seconds after the ants start walking, ant 1 and 2 bump into each other at\ncoordinate 1.5. 1 second after that, ant 1 and 3 bump into each other at\ncoordinate 0.5. 0.5 seconds after that, that is, 3 seconds after the ants\nstart walking, ants 1, 2 and 3 are at coordinates 1, 3 and 0, respectively.\n\n* * *"}, {"input": "4 20 9\n 7 2\n 9 1\n 12 1\n 18 1", "output": "7\n 18\n 18\n 1"}] |
Print N lines. The i-th line should contain the coordinate of ant i after T
seconds. Here, each coordinate must be between 0 and L-1, inclusive.
* * * | s389952802 | Accepted | p03747 | The input is given from Standard Input in the following format:
N L T
X_1 W_1
X_2 W_2
:
X_N W_N | N, L, T = map(int, input().split())
Xs, Ws = [], []
for _ in range(N):
X, W = map(int, input().split())
Xs.append(X)
Ws.append(W)
nums = []
X0, W0 = Xs[0], Ws[0]
for X, W in zip(Xs[1:], Ws[1:]):
if W0 == W:
nums.append(0)
else:
num = T // L * 2
dist = (X - X0) % L if W0 == 1 else (X0 - X) % L
if T % L >= dist / 2 + L / 2:
num += 2
elif T % L >= dist / 2:
num += 1
nums.append(num)
sumNum = sum(nums)
ZekkenAnt0 = sumNum % N if W0 == 1 else (-sumNum) % N
YZekkenAnt0 = (X0 + T) % L if W0 == 1 else (X0 - T) % L
Ys = [(X + T) % L if W == 1 else (X - T) % L for X, W in zip(Xs, Ws)]
Ys.sort()
iZekkenAnt0 = N - 1 - Ys[::-1].index(YZekkenAnt0) if W0 == 1 else Ys.index(YZekkenAnt0)
iZekken0 = (iZekkenAnt0 - ZekkenAnt0) % N
anss = Ys[iZekken0:] + Ys[:iZekken0]
print("\n".join(map(str, anss)))
| Statement
There is a circle with a circumference of L. Each point on the circumference
has a coordinate value, which represents the arc length from a certain
reference point clockwise to the point. On this circumference, there are N
ants. These ants are numbered 1 through N in order of increasing coordinate,
and ant i is at coordinate X_i.
The N ants have just started walking. For each ant i, you are given the
initial direction W_i. Ant i is initially walking clockwise if W_i is 1;
counterclockwise if W_i is 2. Every ant walks at a constant speed of 1 per
second. Sometimes, two ants bump into each other. Each of these two ants will
then turn around and start walking in the opposite direction.
For each ant, find its position after T seconds. | [{"input": "3 8 3\n 0 1\n 3 2\n 6 1", "output": "1\n 3\n 0\n \n\n1.5 seconds after the ants start walking, ant 1 and 2 bump into each other at\ncoordinate 1.5. 1 second after that, ant 1 and 3 bump into each other at\ncoordinate 0.5. 0.5 seconds after that, that is, 3 seconds after the ants\nstart walking, ants 1, 2 and 3 are at coordinates 1, 3 and 0, respectively.\n\n* * *"}, {"input": "4 20 9\n 7 2\n 9 1\n 12 1\n 18 1", "output": "7\n 18\n 18\n 1"}] |
Print N lines. The i-th line should contain the coordinate of ant i after T
seconds. Here, each coordinate must be between 0 and L-1, inclusive.
* * * | s582293140 | Wrong Answer | p03747 | The input is given from Standard Input in the following format:
N L T
X_1 W_1
X_2 W_2
:
X_N W_N | def main():
n, l, t = map(int, input().split())
ls = [list(map(int, input().split())) for _ in range(n)]
ant1 = [
(
(
1 + (t - (ls[i][0] - ls[0][0])) // l
if t - (ls[i][0] - ls[0][0]) >= 0
else 0
)
if ls[i][1] == 2
else 0
)
for i in range(n)
]
ansls = [
(
(t + ls[i][0]) % l
if ls[i][1] == 1
else (
l + (ls[i][0] - t) % l if (ls[i][0] - t) % l < 0 else (ls[i][0] - t) % l
)
)
for i in range(n)
]
ant1p = ansls[0]
ansls.sort()
ant1n = sum(ant1) % n
s = 0
for i in range(n):
if ant1p == ansls[i]:
s = i
break
ansls = ansls[s - ant1n :] + ansls[: s - ant1n]
for i in range(n):
print(ansls[i])
if __name__ == "__main__":
main()
| Statement
There is a circle with a circumference of L. Each point on the circumference
has a coordinate value, which represents the arc length from a certain
reference point clockwise to the point. On this circumference, there are N
ants. These ants are numbered 1 through N in order of increasing coordinate,
and ant i is at coordinate X_i.
The N ants have just started walking. For each ant i, you are given the
initial direction W_i. Ant i is initially walking clockwise if W_i is 1;
counterclockwise if W_i is 2. Every ant walks at a constant speed of 1 per
second. Sometimes, two ants bump into each other. Each of these two ants will
then turn around and start walking in the opposite direction.
For each ant, find its position after T seconds. | [{"input": "3 8 3\n 0 1\n 3 2\n 6 1", "output": "1\n 3\n 0\n \n\n1.5 seconds after the ants start walking, ant 1 and 2 bump into each other at\ncoordinate 1.5. 1 second after that, ant 1 and 3 bump into each other at\ncoordinate 0.5. 0.5 seconds after that, that is, 3 seconds after the ants\nstart walking, ants 1, 2 and 3 are at coordinates 1, 3 and 0, respectively.\n\n* * *"}, {"input": "4 20 9\n 7 2\n 9 1\n 12 1\n 18 1", "output": "7\n 18\n 18\n 1"}] |
Print N lines. The i-th line should contain the coordinate of ant i after T
seconds. Here, each coordinate must be between 0 and L-1, inclusive.
* * * | s199386302 | Wrong Answer | p03747 | The input is given from Standard Input in the following format:
N L T
X_1 W_1
X_2 W_2
:
X_N W_N | N, L, T = [int(item) for item in input().split()]
pos_list = [[int(item) for item in input().split()] for _ in range(N)]
first_ant = pos_list[0]
# N 匹の蟻がいて、それぞれの蟻は 1 から N まで番号の書かれたゼッケンをつけている。
# 二つの蟻が同じ場所についた瞬間、その二つの蟻はゼッケンを交換し、そのまますれ違って同じ方向に歩き続ける。
# 上記問題の言い換えに生息するfirst ant さんの操作後の位置とゼッケンを求める
if first_ant[1] == 1: # 一番の子が1向きの場合
last_pos_of_first_ant = (first_ant[0] + T) % L
num_of_reverse_ant = [item[1] for item in pos_list].count(2)
cnt = 0
reverse_ant_pos = [item[0] for item in pos_list if item[1] == 2]
cnt += T // L * len(reverse_ant_pos)
for i in reverse_ant_pos:
if (i - first_ant[0]) // 2 + 1 <= (T % L):
cnt += 1
last_num_of_first_ant = (1 + cnt) % N
if last_num_of_first_ant == 0:
last_num_of_first_ant += N
else:
last_pos_of_first_ant = (first_ant[0] - T) % L
num_of_reverse_ant = [item[1] for item in pos_list].count(1)
cnt = 0
reverse_ant_pos = [item[0] for item in pos_list if item[1] == 1]
cnt += T // L * len(reverse_ant_pos)
for i in reverse_ant_pos:
if ((first_ant[0] - (i - L)) // 2 + 1) <= (T % L):
cnt += 1
print(T % L)
print(i, first_ant[0] - (i - L), (first_ant[0] - (i - L)) // 2 + 1)
print("cnt", cnt)
last_num_of_first_ant = (1 - cnt) % N
if last_num_of_first_ant <= 0:
last_num_of_first_ant += N
# アリの位置を求める
last_ant_pos = []
for ant_pos, direction in pos_list:
if direction == 1:
last_ant_pos.append((ant_pos + T) % L)
else:
ant_pos = (ant_pos - T) % L
if ant_pos < 0:
ant_pos += L
last_ant_pos.append(ant_pos)
# first ant さんは位置Xにいるので、アリの位置リストからどれがfirst antさんか特定する。
# 特定したらその位置にゼッケンを設定する。
# 1方向のfirst antさんは、その他のゼッケンは時計回りに+1する(他のアリを1減らしながら回っているから)
# 2方向のfirst antさんは、その他のゼッケンを時計回りに-1する(他のアリを1増やしながら回っているから。逆回りに・・・で考えたほうが分かりよいか?)
# 2方向の場合はできたリストを逆順に出力する
res = []
if first_ant[1] == 1:
for i, pos in enumerate(last_ant_pos):
temp_num = (last_num_of_first_ant + i) % N
if temp_num == 0:
temp_num = N
res.append([pos, temp_num])
res.sort(key=lambda x: x[1])
else:
for i, pos in enumerate(last_ant_pos):
temp_num = (last_num_of_first_ant - i) % N
if temp_num == 0:
temp_num = N
res.append([pos, temp_num])
res.sort(key=lambda x: x[1], reverse=True)
# print(first_ant)
# print(num_of_reverse_ant)
# print(reverse_ant_pos)
# print('collison', cnt)
# print('first ant of pos, num',last_pos_of_first_ant, last_num_of_first_ant)
# print(last_ant_pos)
# print(res)
# print('-------ans--------')
print(*[item[0] for item in res])
| Statement
There is a circle with a circumference of L. Each point on the circumference
has a coordinate value, which represents the arc length from a certain
reference point clockwise to the point. On this circumference, there are N
ants. These ants are numbered 1 through N in order of increasing coordinate,
and ant i is at coordinate X_i.
The N ants have just started walking. For each ant i, you are given the
initial direction W_i. Ant i is initially walking clockwise if W_i is 1;
counterclockwise if W_i is 2. Every ant walks at a constant speed of 1 per
second. Sometimes, two ants bump into each other. Each of these two ants will
then turn around and start walking in the opposite direction.
For each ant, find its position after T seconds. | [{"input": "3 8 3\n 0 1\n 3 2\n 6 1", "output": "1\n 3\n 0\n \n\n1.5 seconds after the ants start walking, ant 1 and 2 bump into each other at\ncoordinate 1.5. 1 second after that, ant 1 and 3 bump into each other at\ncoordinate 0.5. 0.5 seconds after that, that is, 3 seconds after the ants\nstart walking, ants 1, 2 and 3 are at coordinates 1, 3 and 0, respectively.\n\n* * *"}, {"input": "4 20 9\n 7 2\n 9 1\n 12 1\n 18 1", "output": "7\n 18\n 18\n 1"}] |
Print N lines. The i-th line should contain the coordinate of ant i after T
seconds. Here, each coordinate must be between 0 and L-1, inclusive.
* * * | s241158579 | Accepted | p03747 | The input is given from Standard Input in the following format:
N L T
X_1 W_1
X_2 W_2
:
X_N W_N | # coding: utf-8
import array, bisect, collections, heapq, itertools, math, random, re, string, sys, time
sys.setrecursionlimit(10**7)
INF = 10**20
MOD = 10**9 + 7
def II():
return int(input())
def ILI():
return list(map(int, input().split()))
def IAI(LINE):
return [ILI() for __ in range(LINE)]
def IDI():
return {key: value for key, value in ILI()}
def solve(N, L, T, pos, dir):
# 円形だからどんなにぶつかっても1-Nまで順番に並んでいることは変わりない。
pos_mov = []
for i in range(1, N + 1):
if dir[i] == 1:
pos_mov.append((pos[i] + T) % L)
elif dir[i] == 2:
pos_mov.append((pos[i] - T) % L)
pos_mov.sort()
count = 0
for i in range(2, N + 1):
dif = pos[i] - pos[1]
if dir[1] == 1:
if dir[i] == 2:
if dif <= 2 * T:
count += (2 * T - dif) // L + 1
elif dir[1] == 2:
if dir[i] == 1:
if (L - dif) <= 2 * T:
count += (2 * T - (L - dif)) // L + 1
if dir[1] == 1:
pos1 = (pos[1] + T) % L
num1 = count % N + 1
elif dir[1] == 2:
pos1 = (pos[1] - T) % L
num1 = -count % N + 1
if dir[1] == 1:
ind = max([i for i in range(1, N + 1) if pos_mov[i - 1] == pos1])
else:
ind = min([i for i in range(1, N + 1) if pos_mov[i - 1] == pos1])
ans = []
for i in range(1, N + 1):
ans.append(pos_mov[(ind - num1 + i) % N - 1])
return ans
def main():
N, L, T = ILI()
pos = dict()
dir = dict()
for i in range(1, N + 1):
X, W = ILI()
pos[i] = X
dir[i] = W
ans = solve(N, L, T, pos, dir)
for i in ans:
print(i)
if __name__ == "__main__":
main()
| Statement
There is a circle with a circumference of L. Each point on the circumference
has a coordinate value, which represents the arc length from a certain
reference point clockwise to the point. On this circumference, there are N
ants. These ants are numbered 1 through N in order of increasing coordinate,
and ant i is at coordinate X_i.
The N ants have just started walking. For each ant i, you are given the
initial direction W_i. Ant i is initially walking clockwise if W_i is 1;
counterclockwise if W_i is 2. Every ant walks at a constant speed of 1 per
second. Sometimes, two ants bump into each other. Each of these two ants will
then turn around and start walking in the opposite direction.
For each ant, find its position after T seconds. | [{"input": "3 8 3\n 0 1\n 3 2\n 6 1", "output": "1\n 3\n 0\n \n\n1.5 seconds after the ants start walking, ant 1 and 2 bump into each other at\ncoordinate 1.5. 1 second after that, ant 1 and 3 bump into each other at\ncoordinate 0.5. 0.5 seconds after that, that is, 3 seconds after the ants\nstart walking, ants 1, 2 and 3 are at coordinates 1, 3 and 0, respectively.\n\n* * *"}, {"input": "4 20 9\n 7 2\n 9 1\n 12 1\n 18 1", "output": "7\n 18\n 18\n 1"}] |
Print the minimum number of operations required.
* * * | s907780782 | Runtime Error | p03317 | Input is given from Standard Input in the following format:
N K
A_1 A_2 ... A_N | N, K = map(int, input().rstrip().split())
A = list(map(int, input().rstrip().split()))
sum = 0
while len(A) >= 2:
sum += 1
A.insert(K, min(A[:K]))
print(A)
del A[0:K]
print(sum)
| Statement
There is a sequence of length N: A_1, A_2, ..., A_N. Initially, this sequence
is a permutation of 1, 2, ..., N.
On this sequence, Snuke can perform the following operation:
* Choose K consecutive elements in the sequence. Then, replace the value of each chosen element with the minimum value among the chosen elements.
Snuke would like to make all the elements in this sequence equal by repeating
the operation above some number of times. Find the minimum number of
operations required. It can be proved that, Under the constraints of this
problem, this objective is always achievable. | [{"input": "4 3\n 2 3 1 4", "output": "2\n \n\nOne optimal strategy is as follows:\n\n * In the first operation, choose the first, second and third elements. The sequence A becomes 1, 1, 1, 4.\n\n * In the second operation, choose the second, third and fourth elements. The sequence A becomes 1, 1, 1, 1.\n\n* * *"}, {"input": "3 3\n 1 2 3", "output": "1\n \n\n* * *"}, {"input": "8 3\n 7 3 1 8 4 6 2 5", "output": "4"}] |
Print the minimum number of operations required.
* * * | s973421755 | Accepted | p03317 | Input is given from Standard Input in the following format:
N K
A_1 A_2 ... A_N | # -*- coding: utf-8 -*-
#############
# Libraries #
#############
import sys
input = sys.stdin.readline
import math
# from math import gcd
import bisect
from collections import defaultdict
from collections import deque
from functools import lru_cache
#############
# Constants #
#############
MOD = 10**9 + 7
INF = float("inf")
#############
# Functions #
#############
######INPUT######
def I():
return int(input().strip())
def S():
return input().strip()
def IL():
return list(map(int, input().split()))
def SL():
return list(map(str, input().split()))
def ILs(n):
return list(int(input()) for _ in range(n))
def SLs(n):
return list(input().strip() for _ in range(n))
def ILL(n):
return [list(map(int, input().split())) for _ in range(n)]
def SLL(n):
return [list(map(str, input().split())) for _ in range(n)]
######OUTPUT######
def P(arg):
print(arg)
return
def Y():
print("Yes")
return
def N():
print("No")
return
def E():
exit()
def PE(arg):
print(arg)
exit()
def YE():
print("Yes")
exit()
def NE():
print("No")
exit()
#####Shorten#####
def DD(arg):
return defaultdict(arg)
#####Inverse#####
def inv(n):
return pow(n, MOD - 2, MOD)
######Combination######
kaijo_memo = []
def kaijo(n):
if len(kaijo_memo) > n:
return kaijo_memo[n]
if len(kaijo_memo) == 0:
kaijo_memo.append(1)
while len(kaijo_memo) <= n:
kaijo_memo.append(kaijo_memo[-1] * len(kaijo_memo) % MOD)
return kaijo_memo[n]
gyaku_kaijo_memo = []
def gyaku_kaijo(n):
if len(gyaku_kaijo_memo) > n:
return gyaku_kaijo_memo[n]
if len(gyaku_kaijo_memo) == 0:
gyaku_kaijo_memo.append(1)
while len(gyaku_kaijo_memo) <= n:
gyaku_kaijo_memo.append(
gyaku_kaijo_memo[-1] * pow(len(gyaku_kaijo_memo), MOD - 2, MOD) % MOD
)
return gyaku_kaijo_memo[n]
def nCr(n, r):
if n == r:
return 1
if n < r or r < 0:
return 0
ret = 1
ret = ret * kaijo(n) % MOD
ret = ret * gyaku_kaijo(r) % MOD
ret = ret * gyaku_kaijo(n - r) % MOD
return ret
######Factorization######
def factorization(n):
arr = []
temp = n
for i in range(2, int(-(-(n**0.5) // 1)) + 1):
if temp % i == 0:
cnt = 0
while temp % i == 0:
cnt += 1
temp //= i
arr.append([i, cnt])
if temp != 1:
arr.append([temp, 1])
if arr == []:
arr.append([n, 1])
return arr
#####MakeDivisors######
def make_divisors(n):
divisors = []
for i in range(1, int(n**0.5) + 1):
if n % i == 0:
divisors.append(i)
if i != n // i:
divisors.append(n // i)
return divisors
#####GCD#####
def gcd(a, b):
while b:
a, b = b, a % b
return a
#####LCM#####
def lcm(a, b):
return a * b // gcd(a, b)
#####BitCount#####
def count_bit(n):
count = 0
while n:
n &= n - 1
count += 1
return count
#####ChangeBase#####
def base_10_to_n(X, n):
if X // n:
return base_10_to_n(X // n, n) + [X % n]
return [X % n]
def base_n_to_10(X, n):
return sum(int(str(X)[-i]) * n**i for i in range(len(str(X))))
#####IntLog#####
def int_log(n, a):
count = 0
while n >= a:
n = n // a
count += 1
if a**count == n:
return count
else:
return count + 1
#############
# Main Code #
#############
N, K = IL()
A = IL()
p = A.index(1)
P(-(-(N - 1) // (K - 1)))
| Statement
There is a sequence of length N: A_1, A_2, ..., A_N. Initially, this sequence
is a permutation of 1, 2, ..., N.
On this sequence, Snuke can perform the following operation:
* Choose K consecutive elements in the sequence. Then, replace the value of each chosen element with the minimum value among the chosen elements.
Snuke would like to make all the elements in this sequence equal by repeating
the operation above some number of times. Find the minimum number of
operations required. It can be proved that, Under the constraints of this
problem, this objective is always achievable. | [{"input": "4 3\n 2 3 1 4", "output": "2\n \n\nOne optimal strategy is as follows:\n\n * In the first operation, choose the first, second and third elements. The sequence A becomes 1, 1, 1, 4.\n\n * In the second operation, choose the second, third and fourth elements. The sequence A becomes 1, 1, 1, 1.\n\n* * *"}, {"input": "3 3\n 1 2 3", "output": "1\n \n\n* * *"}, {"input": "8 3\n 7 3 1 8 4 6 2 5", "output": "4"}] |
Print the minimum number of operations required.
* * * | s877191477 | Wrong Answer | p03317 | Input is given from Standard Input in the following format:
N K
A_1 A_2 ... A_N | # coding: utf-8
import re
import math
from collections import defaultdict
from collections import deque
from fractions import Fraction
import itertools
from copy import deepcopy
import random
import time
import os
import queue
import sys
import datetime
from functools import lru_cache
# @lru_cache(maxsize=None)
readline = sys.stdin.readline
sys.setrecursionlimit(2000000)
# import numpy as np
alphabet = "abcdefghijklmnopqrstuvwxyz"
mod = int(10**9 + 7)
inf = int(10**20)
def yn(b):
if b:
print("yes")
else:
print("no")
def Yn(b):
if b:
print("Yes")
else:
print("No")
def YN(b):
if b:
print("YES")
else:
print("NO")
class union_find:
def __init__(self, n):
self.n = n
self.P = [a for a in range(N)]
self.rank = [0] * n
def find(self, x):
if x != self.P[x]:
self.P[x] = self.find(self.P[x])
return self.P[x]
def same(self, x, y):
return self.find(x) == self.find(y)
def link(self, x, y):
if self.rank[x] < self.rank[y]:
self.P[x] = y
elif self.rank[y] < self.rank[x]:
self.P[y] = x
else:
self.P[x] = y
self.rank[y] += 1
def unite(self, x, y):
self.link(self.find(x), self.find(y))
def size(self):
S = set()
for a in range(self.n):
S.add(self.find(a))
return len(S)
def is_pow(a, b): # aはbの累乗数か
now = b
while now < a:
now *= b
if now == a:
return True
else:
return False
def getbin(num, size):
A = [0] * size
for a in range(size):
if (num >> (size - a - 1)) & 1 == 1:
A[a] = 1
else:
A[a] = 0
return A
def get_facs(n, mod_=0):
A = [1] * (n + 1)
for a in range(2, len(A)):
A[a] = A[a - 1] * a
if mod_ > 0:
A[a] %= mod_
return A
def comb(n, r, mod, fac):
if n - r < 0:
return 0
return (fac[n] * pow(fac[n - r], mod - 2, mod) * pow(fac[r], mod - 2, mod)) % mod
def next_comb(num, size):
x = num & (-num)
y = num + x
z = num & (~y)
z //= x
z = z >> 1
num = y | z
if num >= (1 << size):
return False
else:
return num
def get_primes(n, type="int"):
if n == 0:
if type == "int":
return []
else:
return [False]
A = [True] * (n + 1)
A[0] = False
A[1] = False
for a in range(2, n + 1):
if A[a]:
for b in range(a * 2, n + 1, a):
A[b] = False
if type == "bool":
return A
B = []
for a in range(n + 1):
if A[a]:
B.append(a)
return B
def is_prime(num):
if num <= 1:
return False
i = 2
while i * i <= num:
if num % i == 0:
return False
i += 1
return True
def ifelse(a, b, c):
if a:
return b
else:
return c
def join(A, c=""):
n = len(A)
A = list(map(str, A))
s = ""
for a in range(n):
s += A[a]
if a < n - 1:
s += c
return s
def factorize(n, type_="dict"):
b = 2
list_ = []
while b * b <= n:
while n % b == 0:
n //= b
list_.append(b)
b += 1
if n > 1:
list_.append(n)
if type_ == "dict":
dic = {}
for a in list_:
if a in dic:
dic[a] += 1
else:
dic[a] = 1
return dic
elif type_ == "list":
return list_
else:
return None
def pm(x):
return x // abs(x)
def inputintlist():
return list(map(int, input().split()))
######################################################################################################
def main():
N, K = inputintlist()
A = inputintlist()
K -= 1
ans = N // K
if N % K != 1:
ans += 1
print(ans)
main()
| Statement
There is a sequence of length N: A_1, A_2, ..., A_N. Initially, this sequence
is a permutation of 1, 2, ..., N.
On this sequence, Snuke can perform the following operation:
* Choose K consecutive elements in the sequence. Then, replace the value of each chosen element with the minimum value among the chosen elements.
Snuke would like to make all the elements in this sequence equal by repeating
the operation above some number of times. Find the minimum number of
operations required. It can be proved that, Under the constraints of this
problem, this objective is always achievable. | [{"input": "4 3\n 2 3 1 4", "output": "2\n \n\nOne optimal strategy is as follows:\n\n * In the first operation, choose the first, second and third elements. The sequence A becomes 1, 1, 1, 4.\n\n * In the second operation, choose the second, third and fourth elements. The sequence A becomes 1, 1, 1, 1.\n\n* * *"}, {"input": "3 3\n 1 2 3", "output": "1\n \n\n* * *"}, {"input": "8 3\n 7 3 1 8 4 6 2 5", "output": "4"}] |
Print the minimum number of operations required.
* * * | s955896725 | Accepted | p03317 | Input is given from Standard Input in the following format:
N K
A_1 A_2 ... A_N | n, k = map(int, input().split())
a = input().split()
a = [int(m) for m in a]
t = a.index(min(a))
leftar = []
rightar = []
leftco = 0
rightco = 0
startco = 1
# 左側
for i in range(1, k + 1):
if (t - k + i) / (k - 1) <= 0: # マイナス、0のときは0とする
leftar.append(leftco)
elif (t - k + i) % (k - 1) == 0:
p = int((t - k + i) / (k - 1))
for j in range(1, p + 1):
leftco += 1
leftar.append(leftco)
leftco = 0
else: # 割り切れないときは繰り上げ
p = int((t - k + i) / (k - 1)) + 1
for j in range(1, p + 1):
leftco += 1
leftar.append(leftco)
leftco = 0
# 右側
for i in range(1, k + 1):
if (n - t - i) / (k - 1) <= 0:
rightar.append(rightco)
if (n - t - i) % (k - 1) == 0:
q = int((n - t - i) / (k - 1))
for j in range(1, q + 1):
rightco += 1
rightar.append(rightco)
rightco = 0
else:
q = int((n - t - i) / (k - 1)) + 1
for j in range(1, q + 1):
rightco += 1
rightar.append(rightco)
rightco = 0
sumar = [x + y + startco for (x, y) in zip(leftar, rightar)]
print(min(sumar))
| Statement
There is a sequence of length N: A_1, A_2, ..., A_N. Initially, this sequence
is a permutation of 1, 2, ..., N.
On this sequence, Snuke can perform the following operation:
* Choose K consecutive elements in the sequence. Then, replace the value of each chosen element with the minimum value among the chosen elements.
Snuke would like to make all the elements in this sequence equal by repeating
the operation above some number of times. Find the minimum number of
operations required. It can be proved that, Under the constraints of this
problem, this objective is always achievable. | [{"input": "4 3\n 2 3 1 4", "output": "2\n \n\nOne optimal strategy is as follows:\n\n * In the first operation, choose the first, second and third elements. The sequence A becomes 1, 1, 1, 4.\n\n * In the second operation, choose the second, third and fourth elements. The sequence A becomes 1, 1, 1, 1.\n\n* * *"}, {"input": "3 3\n 1 2 3", "output": "1\n \n\n* * *"}, {"input": "8 3\n 7 3 1 8 4 6 2 5", "output": "4"}] |
Print the minimum number of operations required.
* * * | s884363885 | Accepted | p03317 | Input is given from Standard Input in the following format:
N K
A_1 A_2 ... A_N | n, k = map(int, input().split())
lst = [int(i) for i in input().split()]
for i in range(n):
if lst[i] == 1:
start = i
l = start # 1より左側の数字数
r = n - start - 1 # 1より右側の数字数
if k == 1:
print(n)
elif n == k:
print(1)
else:
if l == 0: # numl : 左側領域の試行回数
numl = 0
elif l <= k - 1:
numl = 1
elif l % (k - 1) == 0:
numl = l // (k - 1)
else:
numl = (l // (k - 1)) + 1
if r == 0: # numr : 右側領域の試行回数
numr = 0
elif r <= k - 1:
numr = 1
elif r % (k - 1) == 0:
numr = r // (k - 1)
else:
numr = (r // (k - 1)) + 1
pat1 = numr + numl
if (n - k) % (k - 1) == 0:
pat2 = 1 + (n - k) // (k - 1)
else:
pat2 = 2 + (n - k) // (k - 1)
print(min(pat1, pat2))
| Statement
There is a sequence of length N: A_1, A_2, ..., A_N. Initially, this sequence
is a permutation of 1, 2, ..., N.
On this sequence, Snuke can perform the following operation:
* Choose K consecutive elements in the sequence. Then, replace the value of each chosen element with the minimum value among the chosen elements.
Snuke would like to make all the elements in this sequence equal by repeating
the operation above some number of times. Find the minimum number of
operations required. It can be proved that, Under the constraints of this
problem, this objective is always achievable. | [{"input": "4 3\n 2 3 1 4", "output": "2\n \n\nOne optimal strategy is as follows:\n\n * In the first operation, choose the first, second and third elements. The sequence A becomes 1, 1, 1, 4.\n\n * In the second operation, choose the second, third and fourth elements. The sequence A becomes 1, 1, 1, 1.\n\n* * *"}, {"input": "3 3\n 1 2 3", "output": "1\n \n\n* * *"}, {"input": "8 3\n 7 3 1 8 4 6 2 5", "output": "4"}] |
Print the minimum number of operations required.
* * * | s990321675 | Wrong Answer | p03317 | Input is given from Standard Input in the following format:
N K
A_1 A_2 ... A_N | n, k = map(int, input().split())
a = list(map(int, input().split()))
ans = 0
m = 0
if a[0] == 1 or a[1] == 1 or a[2] == 1:
for i in range(n - 2):
if a[i] == a[i + 1] == a[i + 2] or a[i] == a[i + 1]:
if a[i + 2] == a[n - 1]:
a[i] = min(a[i], a[i + 1], a[i + 2])
a[i + 1] = min(a[i], a[i + 1], a[i + 2])
a[i + 2] = min(a[i], a[i + 1], a[i + 2])
ans += 1
else:
continue
else:
a[i] = min(a[i], a[i + 1], a[i + 2])
a[i + 1] = min(a[i], a[i + 1], a[i + 2])
a[i + 2] = min(a[i], a[i + 1], a[i + 2])
ans += 1
else:
for i in range(n):
if a[i] == 1:
m = i
break
for i in range(m, n - 2):
if a[i] == a[i + 1] == a[i + 2] or a[i] == a[i + 1]:
if a[i + 2] == a[n - 1]:
a[i] = min(a[i], a[i + 1], a[i + 2])
a[i + 1] = min(a[i], a[i + 1], a[i + 2])
a[i + 2] = min(a[i], a[i + 1], a[i + 2])
ans += 1
else:
continue
else:
a[i] = min(a[i], a[i + 1], a[i + 2])
a[i + 1] = min(a[i], a[i + 1], a[i + 2])
a[i + 2] = min(a[i], a[i + 1], a[i + 2])
ans += 1
for i in reversed(range(0, m + 1)):
if a[i] == a[i - 1] == a[i - 2] or a[i] == a[i - 1]:
if a[i - 2] == a[0]:
a[i] = min(a[i], a[i - 1], a[i - 2])
a[i - 1] = min(a[i], a[i - 1], a[i - 2])
a[i - 2] = min(a[i], a[i - 1], a[i - 2])
ans += 1
break
else:
continue
else:
a[i] = min(a[i], a[i - 1], a[i - 2])
a[i - 1] = min(a[i], a[i - 1], a[i - 2])
a[i - 2] = min(a[i], a[i - 1], a[i - 2])
ans += 1
print(ans)
| Statement
There is a sequence of length N: A_1, A_2, ..., A_N. Initially, this sequence
is a permutation of 1, 2, ..., N.
On this sequence, Snuke can perform the following operation:
* Choose K consecutive elements in the sequence. Then, replace the value of each chosen element with the minimum value among the chosen elements.
Snuke would like to make all the elements in this sequence equal by repeating
the operation above some number of times. Find the minimum number of
operations required. It can be proved that, Under the constraints of this
problem, this objective is always achievable. | [{"input": "4 3\n 2 3 1 4", "output": "2\n \n\nOne optimal strategy is as follows:\n\n * In the first operation, choose the first, second and third elements. The sequence A becomes 1, 1, 1, 4.\n\n * In the second operation, choose the second, third and fourth elements. The sequence A becomes 1, 1, 1, 1.\n\n* * *"}, {"input": "3 3\n 1 2 3", "output": "1\n \n\n* * *"}, {"input": "8 3\n 7 3 1 8 4 6 2 5", "output": "4"}] |
Print the minimum number of operations required.
* * * | s408925122 | Accepted | p03317 | Input is given from Standard Input in the following format:
N K
A_1 A_2 ... A_N | N, K = list(map(int, input().strip().split()))
A = list(map(int, input().strip().split()))
c = N
c -= K
ct = 1
while c > 0:
ct += 1
c -= K - 1
print(ct)
| Statement
There is a sequence of length N: A_1, A_2, ..., A_N. Initially, this sequence
is a permutation of 1, 2, ..., N.
On this sequence, Snuke can perform the following operation:
* Choose K consecutive elements in the sequence. Then, replace the value of each chosen element with the minimum value among the chosen elements.
Snuke would like to make all the elements in this sequence equal by repeating
the operation above some number of times. Find the minimum number of
operations required. It can be proved that, Under the constraints of this
problem, this objective is always achievable. | [{"input": "4 3\n 2 3 1 4", "output": "2\n \n\nOne optimal strategy is as follows:\n\n * In the first operation, choose the first, second and third elements. The sequence A becomes 1, 1, 1, 4.\n\n * In the second operation, choose the second, third and fourth elements. The sequence A becomes 1, 1, 1, 1.\n\n* * *"}, {"input": "3 3\n 1 2 3", "output": "1\n \n\n* * *"}, {"input": "8 3\n 7 3 1 8 4 6 2 5", "output": "4"}] |
Print the minimum number of operations required.
* * * | s316242156 | Runtime Error | p03317 | Input is given from Standard Input in the following format:
N K
A_1 A_2 ... A_N | N,K=map(int,input.split())
TMP=K
ANS=1
if N =< K:
ANS=1
else:
TMP=(K-1)
ANS+=1
if N <= K:
break
print(ANS)
| Statement
There is a sequence of length N: A_1, A_2, ..., A_N. Initially, this sequence
is a permutation of 1, 2, ..., N.
On this sequence, Snuke can perform the following operation:
* Choose K consecutive elements in the sequence. Then, replace the value of each chosen element with the minimum value among the chosen elements.
Snuke would like to make all the elements in this sequence equal by repeating
the operation above some number of times. Find the minimum number of
operations required. It can be proved that, Under the constraints of this
problem, this objective is always achievable. | [{"input": "4 3\n 2 3 1 4", "output": "2\n \n\nOne optimal strategy is as follows:\n\n * In the first operation, choose the first, second and third elements. The sequence A becomes 1, 1, 1, 4.\n\n * In the second operation, choose the second, third and fourth elements. The sequence A becomes 1, 1, 1, 1.\n\n* * *"}, {"input": "3 3\n 1 2 3", "output": "1\n \n\n* * *"}, {"input": "8 3\n 7 3 1 8 4 6 2 5", "output": "4"}] |
Print the minimum number of operations required.
* * * | s529908567 | Runtime Error | p03317 | Input is given from Standard Input in the following format:
N K
A_1 A_2 ... A_N | n,k=map(int,input().split())
print(int((n-1)/(k-1)) | Statement
There is a sequence of length N: A_1, A_2, ..., A_N. Initially, this sequence
is a permutation of 1, 2, ..., N.
On this sequence, Snuke can perform the following operation:
* Choose K consecutive elements in the sequence. Then, replace the value of each chosen element with the minimum value among the chosen elements.
Snuke would like to make all the elements in this sequence equal by repeating
the operation above some number of times. Find the minimum number of
operations required. It can be proved that, Under the constraints of this
problem, this objective is always achievable. | [{"input": "4 3\n 2 3 1 4", "output": "2\n \n\nOne optimal strategy is as follows:\n\n * In the first operation, choose the first, second and third elements. The sequence A becomes 1, 1, 1, 4.\n\n * In the second operation, choose the second, third and fourth elements. The sequence A becomes 1, 1, 1, 1.\n\n* * *"}, {"input": "3 3\n 1 2 3", "output": "1\n \n\n* * *"}, {"input": "8 3\n 7 3 1 8 4 6 2 5", "output": "4"}] |
Print the minimum number of operations required.
* * * | s137842109 | Runtime Error | p03317 | Input is given from Standard Input in the following format:
N K
A_1 A_2 ... A_N | N, K = map(int, input.split())
TMP = K
ANS = 1
if N <= K:
ANS = 1
else:
TMP += K - 1
ANS += 1
if N <= K:
break
print(ANS)
| Statement
There is a sequence of length N: A_1, A_2, ..., A_N. Initially, this sequence
is a permutation of 1, 2, ..., N.
On this sequence, Snuke can perform the following operation:
* Choose K consecutive elements in the sequence. Then, replace the value of each chosen element with the minimum value among the chosen elements.
Snuke would like to make all the elements in this sequence equal by repeating
the operation above some number of times. Find the minimum number of
operations required. It can be proved that, Under the constraints of this
problem, this objective is always achievable. | [{"input": "4 3\n 2 3 1 4", "output": "2\n \n\nOne optimal strategy is as follows:\n\n * In the first operation, choose the first, second and third elements. The sequence A becomes 1, 1, 1, 4.\n\n * In the second operation, choose the second, third and fourth elements. The sequence A becomes 1, 1, 1, 1.\n\n* * *"}, {"input": "3 3\n 1 2 3", "output": "1\n \n\n* * *"}, {"input": "8 3\n 7 3 1 8 4 6 2 5", "output": "4"}] |
Print the minimum number of operations required.
* * * | s684719558 | Runtime Error | p03317 | Input is given from Standard Input in the following format:
N K
A_1 A_2 ... A_N | n,k = map(int,input().split())
A = list(map(int,input.split()))
if (n-1)%%(k-1) == 0:
print(n-1/k-1)
else:
print((n-1//k-1)+1)
| Statement
There is a sequence of length N: A_1, A_2, ..., A_N. Initially, this sequence
is a permutation of 1, 2, ..., N.
On this sequence, Snuke can perform the following operation:
* Choose K consecutive elements in the sequence. Then, replace the value of each chosen element with the minimum value among the chosen elements.
Snuke would like to make all the elements in this sequence equal by repeating
the operation above some number of times. Find the minimum number of
operations required. It can be proved that, Under the constraints of this
problem, this objective is always achievable. | [{"input": "4 3\n 2 3 1 4", "output": "2\n \n\nOne optimal strategy is as follows:\n\n * In the first operation, choose the first, second and third elements. The sequence A becomes 1, 1, 1, 4.\n\n * In the second operation, choose the second, third and fourth elements. The sequence A becomes 1, 1, 1, 1.\n\n* * *"}, {"input": "3 3\n 1 2 3", "output": "1\n \n\n* * *"}, {"input": "8 3\n 7 3 1 8 4 6 2 5", "output": "4"}] |
Print the minimum number of operations required.
* * * | s629785385 | Wrong Answer | p03317 | Input is given from Standard Input in the following format:
N K
A_1 A_2 ... A_N | N, K = map(int, input().split(" "))
nums = list(input().split(" "))
a = nums.index("1")
l = (a + 1) / (K - 1)
r = (N - a) / (K - 1)
print(l + r)
| Statement
There is a sequence of length N: A_1, A_2, ..., A_N. Initially, this sequence
is a permutation of 1, 2, ..., N.
On this sequence, Snuke can perform the following operation:
* Choose K consecutive elements in the sequence. Then, replace the value of each chosen element with the minimum value among the chosen elements.
Snuke would like to make all the elements in this sequence equal by repeating
the operation above some number of times. Find the minimum number of
operations required. It can be proved that, Under the constraints of this
problem, this objective is always achievable. | [{"input": "4 3\n 2 3 1 4", "output": "2\n \n\nOne optimal strategy is as follows:\n\n * In the first operation, choose the first, second and third elements. The sequence A becomes 1, 1, 1, 4.\n\n * In the second operation, choose the second, third and fourth elements. The sequence A becomes 1, 1, 1, 1.\n\n* * *"}, {"input": "3 3\n 1 2 3", "output": "1\n \n\n* * *"}, {"input": "8 3\n 7 3 1 8 4 6 2 5", "output": "4"}] |
Print the minimum number of operations required.
* * * | s623017379 | Runtime Error | p03317 | Input is given from Standard Input in the following format:
N K
A_1 A_2 ... A_N | n, k = map(int, input().split())
a = list(map(int, input().split()))
import math
id_1 = a.index(1)
if n == k:
print(1)
elif id_1 > k - 1 and n - id_1 - 1 > k - 1:
print( math.ceil(id_1 / (k - 1)) + math.ceil((n - id_1 - 1) / (k - 1)) )
else:
print( 1 + math.floor((n - k) / (k - 1)) | Statement
There is a sequence of length N: A_1, A_2, ..., A_N. Initially, this sequence
is a permutation of 1, 2, ..., N.
On this sequence, Snuke can perform the following operation:
* Choose K consecutive elements in the sequence. Then, replace the value of each chosen element with the minimum value among the chosen elements.
Snuke would like to make all the elements in this sequence equal by repeating
the operation above some number of times. Find the minimum number of
operations required. It can be proved that, Under the constraints of this
problem, this objective is always achievable. | [{"input": "4 3\n 2 3 1 4", "output": "2\n \n\nOne optimal strategy is as follows:\n\n * In the first operation, choose the first, second and third elements. The sequence A becomes 1, 1, 1, 4.\n\n * In the second operation, choose the second, third and fourth elements. The sequence A becomes 1, 1, 1, 1.\n\n* * *"}, {"input": "3 3\n 1 2 3", "output": "1\n \n\n* * *"}, {"input": "8 3\n 7 3 1 8 4 6 2 5", "output": "4"}] |
Print the minimum number of operations required.
* * * | s928890647 | Runtime Error | p03317 | Input is given from Standard Input in the following format:
N K
A_1 A_2 ... A_N | import math
N, K =list(map(int,input().split()))
A = list(map(int,input().split()))
cnt = 0
for i in range(N):
if A[i] == 1:
L = i
R = (N - i - 1)
if L == 0:
cnt += 0
elif L < K:
cnt += 1
else:
#cnt += (math.ceil(L / (K - 1)))
cnt += (L / (K - 1))
if R == 0:
cnt += 0
elif R < K:
cnt += 1
else:
#cnt += (math.ceil(R / (K - 1)))
cnt += (R / (K - 1))
#print(L,R)
print(cnt) | Statement
There is a sequence of length N: A_1, A_2, ..., A_N. Initially, this sequence
is a permutation of 1, 2, ..., N.
On this sequence, Snuke can perform the following operation:
* Choose K consecutive elements in the sequence. Then, replace the value of each chosen element with the minimum value among the chosen elements.
Snuke would like to make all the elements in this sequence equal by repeating
the operation above some number of times. Find the minimum number of
operations required. It can be proved that, Under the constraints of this
problem, this objective is always achievable. | [{"input": "4 3\n 2 3 1 4", "output": "2\n \n\nOne optimal strategy is as follows:\n\n * In the first operation, choose the first, second and third elements. The sequence A becomes 1, 1, 1, 4.\n\n * In the second operation, choose the second, third and fourth elements. The sequence A becomes 1, 1, 1, 1.\n\n* * *"}, {"input": "3 3\n 1 2 3", "output": "1\n \n\n* * *"}, {"input": "8 3\n 7 3 1 8 4 6 2 5", "output": "4"}] |
Print the minimum number of operations required.
* * * | s684084333 | Wrong Answer | p03317 | Input is given from Standard Input in the following format:
N K
A_1 A_2 ... A_N | # coding : utf-8
import math
N, K = map(int, input().split())
A = list(map(int, input().split()))
# 全部を最小値1にする必要がある
minNum = 1
minIndex = A.index(minNum)
# 最小値1の左側の個数
leftNum = minIndex
# print(leftNum)
# 最小値1の右側の個数
rightNum = N - leftNum - 1
# print(rightNum)
# 左側の変換について、最初のステップを右側の数を含めても同じ回数になる場合
leftMod = leftNum % (K - 1)
if leftMod != 0:
rightNum -= leftMod
if rightNum < 0:
rightNum = 0
# 右側の変換について、最初のステップを左側の数を含めても同じ回数になる場合
rightMod = rightNum % (K - 1)
if rightMod != 0:
leftNum -= rightMod
if leftNum < 0:
leftNum = 0
leftCount = math.ceil(leftNum / (K - 1))
rightCount = math.ceil(rightNum / (K - 1))
ans = leftCount + rightCount
print(ans)
| Statement
There is a sequence of length N: A_1, A_2, ..., A_N. Initially, this sequence
is a permutation of 1, 2, ..., N.
On this sequence, Snuke can perform the following operation:
* Choose K consecutive elements in the sequence. Then, replace the value of each chosen element with the minimum value among the chosen elements.
Snuke would like to make all the elements in this sequence equal by repeating
the operation above some number of times. Find the minimum number of
operations required. It can be proved that, Under the constraints of this
problem, this objective is always achievable. | [{"input": "4 3\n 2 3 1 4", "output": "2\n \n\nOne optimal strategy is as follows:\n\n * In the first operation, choose the first, second and third elements. The sequence A becomes 1, 1, 1, 4.\n\n * In the second operation, choose the second, third and fourth elements. The sequence A becomes 1, 1, 1, 1.\n\n* * *"}, {"input": "3 3\n 1 2 3", "output": "1\n \n\n* * *"}, {"input": "8 3\n 7 3 1 8 4 6 2 5", "output": "4"}] |
Print the minimum number of operations required.
* * * | s329698651 | Runtime Error | p03317 | Input is given from Standard Input in the following format:
N K
A_1 A_2 ... A_N | #include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)
typedef long long ll;
int main() {
int N, K;
cin >> N >> K;
int A;
int m = 0
for (int i = 1; i < N+1; i++){
cin >> A;
if (A == 1){
m = i;
break;
}
}
int l = (i - 1) / K;
int r = (N - i) / K;
if ((i - 1) % K == 0){
l++;
}
if ((N - i) % K == 0){
r++;
}
cout << l + r << endl;
}
| Statement
There is a sequence of length N: A_1, A_2, ..., A_N. Initially, this sequence
is a permutation of 1, 2, ..., N.
On this sequence, Snuke can perform the following operation:
* Choose K consecutive elements in the sequence. Then, replace the value of each chosen element with the minimum value among the chosen elements.
Snuke would like to make all the elements in this sequence equal by repeating
the operation above some number of times. Find the minimum number of
operations required. It can be proved that, Under the constraints of this
problem, this objective is always achievable. | [{"input": "4 3\n 2 3 1 4", "output": "2\n \n\nOne optimal strategy is as follows:\n\n * In the first operation, choose the first, second and third elements. The sequence A becomes 1, 1, 1, 4.\n\n * In the second operation, choose the second, third and fourth elements. The sequence A becomes 1, 1, 1, 1.\n\n* * *"}, {"input": "3 3\n 1 2 3", "output": "1\n \n\n* * *"}, {"input": "8 3\n 7 3 1 8 4 6 2 5", "output": "4"}] |
Print `Yes` if S is easily playable, and `No` otherwise.
* * * | s784913705 | Runtime Error | p02910 | Input is given from Standard Input in the following format:
S | s=input()
for i in range(len(s)//2+1):
if s[2*i]!='R' and s[2*i]!='U' and s[2*i]!='D' :
print('No')
exit()
if s[2*i+1]!='L' and s[2*i+1]!='U' and s[2*i+1]!='D':
print('No')
exit()
if
print('Yes')
| Statement
Takahashi will do a tap dance. The dance is described by a string S where each
character is `L`, `R`, `U`, or `D`. These characters indicate the positions on
which Takahashi should step. He will follow these instructions one by one in
order, starting with the first character.
S is said to be _easily playable_ if and only if it satisfies both of the
following conditions:
* Every character in an odd position (1-st, 3-rd, 5-th, \ldots) is `R`, `U`, or `D`.
* Every character in an even position (2-nd, 4-th, 6-th, \ldots) is `L`, `U`, or `D`.
Your task is to print `Yes` if S is easily playable, and `No` otherwise. | [{"input": "RUDLUDR", "output": "Yes\n \n\nEvery character in an odd position (1-st, 3-rd, 5-th, 7-th) is `R`, `U`, or\n`D`.\n\nEvery character in an even position (2-nd, 4-th, 6-th) is `L`, `U`, or `D`.\n\nThus, S is easily playable.\n\n* * *"}, {"input": "DULL", "output": "No\n \n\nThe 3-rd character is not `R`, `U`, nor `D`, so S is not easily playable.\n\n* * *"}, {"input": "UUUUUUUUUUUUUUU", "output": "Yes\n \n\n* * *"}, {"input": "ULURU", "output": "No\n \n\n* * *"}, {"input": "RDULULDURURLRDULRLR", "output": "Yes"}] |
Print `Yes` if S is easily playable, and `No` otherwise.
* * * | s907819229 | Runtime Error | p02910 | Input is given from Standard Input in the following format:
S | S = input()
Slist = list(S)
if 'R' in Slist[0::2] || 'U' in Slist[0::2] || 'D' in Slist[0::2]:
if 'L' in Slist[0::1] || 'U' in Slist[0::1] || 'D' in Slist[0::1]:
print('Yes')
else:
print('No')
else:
print('No') | Statement
Takahashi will do a tap dance. The dance is described by a string S where each
character is `L`, `R`, `U`, or `D`. These characters indicate the positions on
which Takahashi should step. He will follow these instructions one by one in
order, starting with the first character.
S is said to be _easily playable_ if and only if it satisfies both of the
following conditions:
* Every character in an odd position (1-st, 3-rd, 5-th, \ldots) is `R`, `U`, or `D`.
* Every character in an even position (2-nd, 4-th, 6-th, \ldots) is `L`, `U`, or `D`.
Your task is to print `Yes` if S is easily playable, and `No` otherwise. | [{"input": "RUDLUDR", "output": "Yes\n \n\nEvery character in an odd position (1-st, 3-rd, 5-th, 7-th) is `R`, `U`, or\n`D`.\n\nEvery character in an even position (2-nd, 4-th, 6-th) is `L`, `U`, or `D`.\n\nThus, S is easily playable.\n\n* * *"}, {"input": "DULL", "output": "No\n \n\nThe 3-rd character is not `R`, `U`, nor `D`, so S is not easily playable.\n\n* * *"}, {"input": "UUUUUUUUUUUUUUU", "output": "Yes\n \n\n* * *"}, {"input": "ULURU", "output": "No\n \n\n* * *"}, {"input": "RDULULDURURLRDULRLR", "output": "Yes"}] |
Print `Yes` if S is easily playable, and `No` otherwise.
* * * | s759523926 | Accepted | p02910 | Input is given from Standard Input in the following format:
S | #!/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")
# A
def A():
d = {"Sunny": 1, "Cloudy": 2, "Rainy": 0}
a = ["Sunny", "Cloudy", "Rainy"]
print(a[d[input()]])
return
# B
def B():
s = S()
for i, si in enumerate(s):
if i % 2:
if si == "R":
print("No")
return
else:
if si == "L":
print("No")
return
print("Yes")
return
# C
def C():
n, k, q = LI()
d = [0] * n
for _ in range(q):
a = II() - 1
d[a] += 1
for a in d:
if k - (q - a) > 0:
print("Yes")
else:
print("No")
return
# D
def D():
(n,) = LI()
a = LI()
q = []
for ai in a:
heappush(q, ai)
for _ in range(m):
heappush(q, heappop(q) / 2)
ans = 0
while q:
ans += int(heappop(q))
print(ans)
return
# E
def E():
return
# F
def F():
return
# Solve
if __name__ == "__main__":
B()
| Statement
Takahashi will do a tap dance. The dance is described by a string S where each
character is `L`, `R`, `U`, or `D`. These characters indicate the positions on
which Takahashi should step. He will follow these instructions one by one in
order, starting with the first character.
S is said to be _easily playable_ if and only if it satisfies both of the
following conditions:
* Every character in an odd position (1-st, 3-rd, 5-th, \ldots) is `R`, `U`, or `D`.
* Every character in an even position (2-nd, 4-th, 6-th, \ldots) is `L`, `U`, or `D`.
Your task is to print `Yes` if S is easily playable, and `No` otherwise. | [{"input": "RUDLUDR", "output": "Yes\n \n\nEvery character in an odd position (1-st, 3-rd, 5-th, 7-th) is `R`, `U`, or\n`D`.\n\nEvery character in an even position (2-nd, 4-th, 6-th) is `L`, `U`, or `D`.\n\nThus, S is easily playable.\n\n* * *"}, {"input": "DULL", "output": "No\n \n\nThe 3-rd character is not `R`, `U`, nor `D`, so S is not easily playable.\n\n* * *"}, {"input": "UUUUUUUUUUUUUUU", "output": "Yes\n \n\n* * *"}, {"input": "ULURU", "output": "No\n \n\n* * *"}, {"input": "RDULULDURURLRDULRLR", "output": "Yes"}] |
Print `Yes` if S is easily playable, and `No` otherwise.
* * * | s923748700 | Runtime Error | p02910 | Input is given from Standard Input in the following format:
S | odd = ["R", "U", "D"]
even = ["L", "U", "D"]
s_list = list(input())
ans = "Yes"
for i in range(s_list):
if i % 2 == 0:
if not s_list[i] in odd:
ans = "No"
if i % 2 == 1:
if not s_list[i] in even:
ans = "No"
print(ans) | Statement
Takahashi will do a tap dance. The dance is described by a string S where each
character is `L`, `R`, `U`, or `D`. These characters indicate the positions on
which Takahashi should step. He will follow these instructions one by one in
order, starting with the first character.
S is said to be _easily playable_ if and only if it satisfies both of the
following conditions:
* Every character in an odd position (1-st, 3-rd, 5-th, \ldots) is `R`, `U`, or `D`.
* Every character in an even position (2-nd, 4-th, 6-th, \ldots) is `L`, `U`, or `D`.
Your task is to print `Yes` if S is easily playable, and `No` otherwise. | [{"input": "RUDLUDR", "output": "Yes\n \n\nEvery character in an odd position (1-st, 3-rd, 5-th, 7-th) is `R`, `U`, or\n`D`.\n\nEvery character in an even position (2-nd, 4-th, 6-th) is `L`, `U`, or `D`.\n\nThus, S is easily playable.\n\n* * *"}, {"input": "DULL", "output": "No\n \n\nThe 3-rd character is not `R`, `U`, nor `D`, so S is not easily playable.\n\n* * *"}, {"input": "UUUUUUUUUUUUUUU", "output": "Yes\n \n\n* * *"}, {"input": "ULURU", "output": "No\n \n\n* * *"}, {"input": "RDULULDURURLRDULRLR", "output": "Yes"}] |
Print `Yes` if S is easily playable, and `No` otherwise.
* * * | s077868720 | Accepted | p02910 | Input is given from Standard Input in the following format:
S | out = "Yes"
str = input()
for i, s in enumerate(str):
if s == "L" and i % 2 == 0:
out = "No"
elif s == "R" and i % 2 == 1:
out = "No"
print(out)
| Statement
Takahashi will do a tap dance. The dance is described by a string S where each
character is `L`, `R`, `U`, or `D`. These characters indicate the positions on
which Takahashi should step. He will follow these instructions one by one in
order, starting with the first character.
S is said to be _easily playable_ if and only if it satisfies both of the
following conditions:
* Every character in an odd position (1-st, 3-rd, 5-th, \ldots) is `R`, `U`, or `D`.
* Every character in an even position (2-nd, 4-th, 6-th, \ldots) is `L`, `U`, or `D`.
Your task is to print `Yes` if S is easily playable, and `No` otherwise. | [{"input": "RUDLUDR", "output": "Yes\n \n\nEvery character in an odd position (1-st, 3-rd, 5-th, 7-th) is `R`, `U`, or\n`D`.\n\nEvery character in an even position (2-nd, 4-th, 6-th) is `L`, `U`, or `D`.\n\nThus, S is easily playable.\n\n* * *"}, {"input": "DULL", "output": "No\n \n\nThe 3-rd character is not `R`, `U`, nor `D`, so S is not easily playable.\n\n* * *"}, {"input": "UUUUUUUUUUUUUUU", "output": "Yes\n \n\n* * *"}, {"input": "ULURU", "output": "No\n \n\n* * *"}, {"input": "RDULULDURURLRDULRLR", "output": "Yes"}] |
Print `Yes` if S is easily playable, and `No` otherwise.
* * * | s224491505 | Wrong Answer | p02910 | Input is given from Standard Input in the following format:
S | S = input()
nikui = False
for i in range(0, len(S) - 1, 2):
if S[i] == "L":
nikui = True
for i in range(1, len(S) - 1, 2):
if S[i] == "R":
nikui = True
print("No" if nikui else "Yes")
| Statement
Takahashi will do a tap dance. The dance is described by a string S where each
character is `L`, `R`, `U`, or `D`. These characters indicate the positions on
which Takahashi should step. He will follow these instructions one by one in
order, starting with the first character.
S is said to be _easily playable_ if and only if it satisfies both of the
following conditions:
* Every character in an odd position (1-st, 3-rd, 5-th, \ldots) is `R`, `U`, or `D`.
* Every character in an even position (2-nd, 4-th, 6-th, \ldots) is `L`, `U`, or `D`.
Your task is to print `Yes` if S is easily playable, and `No` otherwise. | [{"input": "RUDLUDR", "output": "Yes\n \n\nEvery character in an odd position (1-st, 3-rd, 5-th, 7-th) is `R`, `U`, or\n`D`.\n\nEvery character in an even position (2-nd, 4-th, 6-th) is `L`, `U`, or `D`.\n\nThus, S is easily playable.\n\n* * *"}, {"input": "DULL", "output": "No\n \n\nThe 3-rd character is not `R`, `U`, nor `D`, so S is not easily playable.\n\n* * *"}, {"input": "UUUUUUUUUUUUUUU", "output": "Yes\n \n\n* * *"}, {"input": "ULURU", "output": "No\n \n\n* * *"}, {"input": "RDULULDURURLRDULRLR", "output": "Yes"}] |
Print `Yes` if S is easily playable, and `No` otherwise.
* * * | s849765614 | Runtime Error | p02910 | Input is given from Standard Input in the following format:
S | S = input()
kisu = ['R', 'U', 'D']
gusu = ['L', 'U', 'D']
hard = 0
for i in range(len(S)):
moji = S[i]
if i % 2 == 0:
if moji not in gusu:
hard = 1
break
elif i % 2 == 1:
if moji not in kisu:
hard = 1
break
if hard == 0:
print("Yes")
elif:
print("No")
| Statement
Takahashi will do a tap dance. The dance is described by a string S where each
character is `L`, `R`, `U`, or `D`. These characters indicate the positions on
which Takahashi should step. He will follow these instructions one by one in
order, starting with the first character.
S is said to be _easily playable_ if and only if it satisfies both of the
following conditions:
* Every character in an odd position (1-st, 3-rd, 5-th, \ldots) is `R`, `U`, or `D`.
* Every character in an even position (2-nd, 4-th, 6-th, \ldots) is `L`, `U`, or `D`.
Your task is to print `Yes` if S is easily playable, and `No` otherwise. | [{"input": "RUDLUDR", "output": "Yes\n \n\nEvery character in an odd position (1-st, 3-rd, 5-th, 7-th) is `R`, `U`, or\n`D`.\n\nEvery character in an even position (2-nd, 4-th, 6-th) is `L`, `U`, or `D`.\n\nThus, S is easily playable.\n\n* * *"}, {"input": "DULL", "output": "No\n \n\nThe 3-rd character is not `R`, `U`, nor `D`, so S is not easily playable.\n\n* * *"}, {"input": "UUUUUUUUUUUUUUU", "output": "Yes\n \n\n* * *"}, {"input": "ULURU", "output": "No\n \n\n* * *"}, {"input": "RDULULDURURLRDULRLR", "output": "Yes"}] |
Print `Yes` if S is easily playable, and `No` otherwise.
* * * | s873691250 | Runtime Error | p02910 | Input is given from Standard Input in the following format:
S | n = str(input())
d = []
p = []
i = 1
s = 1
l = 1
for k in n:
if i % 2 == 0:
if k == "R" or k == "U" or k == "D":
#print(k,"は満たしています")
else:
#print("偶数","みたしていない")
s = 0
else:
if k == "L" or k == "U" or k == "D":
#print("奇数","番目の",k)
else:
#print("奇数","みたしていない")
l = 0
i = i + 1
if s or l == "1":
print("Yes")
else:
print("No") | Statement
Takahashi will do a tap dance. The dance is described by a string S where each
character is `L`, `R`, `U`, or `D`. These characters indicate the positions on
which Takahashi should step. He will follow these instructions one by one in
order, starting with the first character.
S is said to be _easily playable_ if and only if it satisfies both of the
following conditions:
* Every character in an odd position (1-st, 3-rd, 5-th, \ldots) is `R`, `U`, or `D`.
* Every character in an even position (2-nd, 4-th, 6-th, \ldots) is `L`, `U`, or `D`.
Your task is to print `Yes` if S is easily playable, and `No` otherwise. | [{"input": "RUDLUDR", "output": "Yes\n \n\nEvery character in an odd position (1-st, 3-rd, 5-th, 7-th) is `R`, `U`, or\n`D`.\n\nEvery character in an even position (2-nd, 4-th, 6-th) is `L`, `U`, or `D`.\n\nThus, S is easily playable.\n\n* * *"}, {"input": "DULL", "output": "No\n \n\nThe 3-rd character is not `R`, `U`, nor `D`, so S is not easily playable.\n\n* * *"}, {"input": "UUUUUUUUUUUUUUU", "output": "Yes\n \n\n* * *"}, {"input": "ULURU", "output": "No\n \n\n* * *"}, {"input": "RDULULDURURLRDULRLR", "output": "Yes"}] |
Print `Yes` if S is easily playable, and `No` otherwise.
* * * | s849272501 | Runtime Error | p02910 | Input is given from Standard Input in the following format:
S | S=list(input())
K="Yes"
for i in range (0,len(S)):
if i%2=0
if S[i]=="L" :
K="No"
break
else:
continue
else :
if S[i]=="R" :
K="No"
break
else:
continue
print(K) | Statement
Takahashi will do a tap dance. The dance is described by a string S where each
character is `L`, `R`, `U`, or `D`. These characters indicate the positions on
which Takahashi should step. He will follow these instructions one by one in
order, starting with the first character.
S is said to be _easily playable_ if and only if it satisfies both of the
following conditions:
* Every character in an odd position (1-st, 3-rd, 5-th, \ldots) is `R`, `U`, or `D`.
* Every character in an even position (2-nd, 4-th, 6-th, \ldots) is `L`, `U`, or `D`.
Your task is to print `Yes` if S is easily playable, and `No` otherwise. | [{"input": "RUDLUDR", "output": "Yes\n \n\nEvery character in an odd position (1-st, 3-rd, 5-th, 7-th) is `R`, `U`, or\n`D`.\n\nEvery character in an even position (2-nd, 4-th, 6-th) is `L`, `U`, or `D`.\n\nThus, S is easily playable.\n\n* * *"}, {"input": "DULL", "output": "No\n \n\nThe 3-rd character is not `R`, `U`, nor `D`, so S is not easily playable.\n\n* * *"}, {"input": "UUUUUUUUUUUUUUU", "output": "Yes\n \n\n* * *"}, {"input": "ULURU", "output": "No\n \n\n* * *"}, {"input": "RDULULDURURLRDULRLR", "output": "Yes"}] |
Print `Yes` if S is easily playable, and `No` otherwise.
* * * | s712777828 | Runtime Error | p02910 | Input is given from Standard Input in the following format:
S | S=input()
a=S[::2]
b=S[1::2]
if 'L' not in a:
if 'R' not in b:
print('Yes')
else:
print('No')
else:
print('No') | Statement
Takahashi will do a tap dance. The dance is described by a string S where each
character is `L`, `R`, `U`, or `D`. These characters indicate the positions on
which Takahashi should step. He will follow these instructions one by one in
order, starting with the first character.
S is said to be _easily playable_ if and only if it satisfies both of the
following conditions:
* Every character in an odd position (1-st, 3-rd, 5-th, \ldots) is `R`, `U`, or `D`.
* Every character in an even position (2-nd, 4-th, 6-th, \ldots) is `L`, `U`, or `D`.
Your task is to print `Yes` if S is easily playable, and `No` otherwise. | [{"input": "RUDLUDR", "output": "Yes\n \n\nEvery character in an odd position (1-st, 3-rd, 5-th, 7-th) is `R`, `U`, or\n`D`.\n\nEvery character in an even position (2-nd, 4-th, 6-th) is `L`, `U`, or `D`.\n\nThus, S is easily playable.\n\n* * *"}, {"input": "DULL", "output": "No\n \n\nThe 3-rd character is not `R`, `U`, nor `D`, so S is not easily playable.\n\n* * *"}, {"input": "UUUUUUUUUUUUUUU", "output": "Yes\n \n\n* * *"}, {"input": "ULURU", "output": "No\n \n\n* * *"}, {"input": "RDULULDURURLRDULRLR", "output": "Yes"}] |
Print `Yes` if S is easily playable, and `No` otherwise.
* * * | s903345476 | Runtime Error | p02910 | Input is given from Standard Input in the following format:
S | s = input()
for i in range(len(s))
if i%2==0 and s(i)=='R':
print('No')
exit()
elif i%2==1 and s(i)=='L':
print('No')
exit()
print('Yes') | Statement
Takahashi will do a tap dance. The dance is described by a string S where each
character is `L`, `R`, `U`, or `D`. These characters indicate the positions on
which Takahashi should step. He will follow these instructions one by one in
order, starting with the first character.
S is said to be _easily playable_ if and only if it satisfies both of the
following conditions:
* Every character in an odd position (1-st, 3-rd, 5-th, \ldots) is `R`, `U`, or `D`.
* Every character in an even position (2-nd, 4-th, 6-th, \ldots) is `L`, `U`, or `D`.
Your task is to print `Yes` if S is easily playable, and `No` otherwise. | [{"input": "RUDLUDR", "output": "Yes\n \n\nEvery character in an odd position (1-st, 3-rd, 5-th, 7-th) is `R`, `U`, or\n`D`.\n\nEvery character in an even position (2-nd, 4-th, 6-th) is `L`, `U`, or `D`.\n\nThus, S is easily playable.\n\n* * *"}, {"input": "DULL", "output": "No\n \n\nThe 3-rd character is not `R`, `U`, nor `D`, so S is not easily playable.\n\n* * *"}, {"input": "UUUUUUUUUUUUUUU", "output": "Yes\n \n\n* * *"}, {"input": "ULURU", "output": "No\n \n\n* * *"}, {"input": "RDULULDURURLRDULRLR", "output": "Yes"}] |
Print `Yes` if S is easily playable, and `No` otherwise.
* * * | s886435025 | Runtime Error | p02910 | Input is given from Standard Input in the following format:
S | S = input()
if S[0::2].count("L") + S[1::2].count("R") == 0: print("Yes")
else: print("No")
| Statement
Takahashi will do a tap dance. The dance is described by a string S where each
character is `L`, `R`, `U`, or `D`. These characters indicate the positions on
which Takahashi should step. He will follow these instructions one by one in
order, starting with the first character.
S is said to be _easily playable_ if and only if it satisfies both of the
following conditions:
* Every character in an odd position (1-st, 3-rd, 5-th, \ldots) is `R`, `U`, or `D`.
* Every character in an even position (2-nd, 4-th, 6-th, \ldots) is `L`, `U`, or `D`.
Your task is to print `Yes` if S is easily playable, and `No` otherwise. | [{"input": "RUDLUDR", "output": "Yes\n \n\nEvery character in an odd position (1-st, 3-rd, 5-th, 7-th) is `R`, `U`, or\n`D`.\n\nEvery character in an even position (2-nd, 4-th, 6-th) is `L`, `U`, or `D`.\n\nThus, S is easily playable.\n\n* * *"}, {"input": "DULL", "output": "No\n \n\nThe 3-rd character is not `R`, `U`, nor `D`, so S is not easily playable.\n\n* * *"}, {"input": "UUUUUUUUUUUUUUU", "output": "Yes\n \n\n* * *"}, {"input": "ULURU", "output": "No\n \n\n* * *"}, {"input": "RDULULDURURLRDULRLR", "output": "Yes"}] |
Print `Yes` if S is easily playable, and `No` otherwise.
* * * | s534008799 | Wrong Answer | p02910 | Input is given from Standard Input in the following format:
S | {
"nbformat": 4,
"nbformat_minor": 0,
"metadata": {
"colab": {"name": "py.py", "provenance": []},
"kernelspec": {"name": "python3", "display_name": "Python 3"},
},
"cells": [
{
"cell_type": "code",
"metadata": {
"id": "H3laJejZ8tH7",
"colab_type": "code",
"colab": {"base_uri": "https://localhost:8080/", "height": 35},
"outputId": "13f7e97e-3eae-44b3-ce92-df84580aa0d6",
"executionInfo": {
"status": "ok",
"timestamp": 1569272992629,
"user_tz": -540,
"elapsed": 1544,
"user": {
"displayName": "ryo t",
"photoUrl": "",
"userId": "15768515004963573815",
},
},
},
"source": ['print("a")'],
"execution_count": 1,
"outputs": [{"output_type": "stream", "text": ["a\n"], "name": "stdout"}],
}
],
}
| Statement
Takahashi will do a tap dance. The dance is described by a string S where each
character is `L`, `R`, `U`, or `D`. These characters indicate the positions on
which Takahashi should step. He will follow these instructions one by one in
order, starting with the first character.
S is said to be _easily playable_ if and only if it satisfies both of the
following conditions:
* Every character in an odd position (1-st, 3-rd, 5-th, \ldots) is `R`, `U`, or `D`.
* Every character in an even position (2-nd, 4-th, 6-th, \ldots) is `L`, `U`, or `D`.
Your task is to print `Yes` if S is easily playable, and `No` otherwise. | [{"input": "RUDLUDR", "output": "Yes\n \n\nEvery character in an odd position (1-st, 3-rd, 5-th, 7-th) is `R`, `U`, or\n`D`.\n\nEvery character in an even position (2-nd, 4-th, 6-th) is `L`, `U`, or `D`.\n\nThus, S is easily playable.\n\n* * *"}, {"input": "DULL", "output": "No\n \n\nThe 3-rd character is not `R`, `U`, nor `D`, so S is not easily playable.\n\n* * *"}, {"input": "UUUUUUUUUUUUUUU", "output": "Yes\n \n\n* * *"}, {"input": "ULURU", "output": "No\n \n\n* * *"}, {"input": "RDULULDURURLRDULRLR", "output": "Yes"}] |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.