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 |
|---|---|---|---|---|---|---|---|
1x1=1
1x2=2
.
.
9x8=72
9x9=81 | s894427786 | Accepted | p00000 | No input. | for a in range(9):
for i in range(9):
print(a + 1, "x", (i + 1), "=", (i + 1) * (a + 1), sep="")
| QQ
Write a program which prints multiplication tables in the following format:
1x1=1
1x2=2
.
.
9x8=72
9x9=81 | [] |
1x1=1
1x2=2
.
.
9x8=72
9x9=81 | s955597450 | Accepted | p00000 | No input. | for b in range(1, 10):
for a in range(1, 10):
print(str(b) + "x" + str(a) + "=" + str(b * a))
| QQ
Write a program which prints multiplication tables in the following format:
1x1=1
1x2=2
.
.
9x8=72
9x9=81 | [] |
1x1=1
1x2=2
.
.
9x8=72
9x9=81 | s912792307 | Accepted | p00000 | No input. | for i in range(1, 10):
a = 1 * i
print("1x{0}={1}".format(i, a))
for i in range(1, 10):
b = 2 * i
print("2x{0}={1}".format(i, b))
for i in range(1, 10):
c = 3 * i
print("3x{0}={1}".format(i, c))
for i in range(1, 10):
d = 4 * i
print("4x{0}={1}".format(i, d))
for i in range(1, 10):
e = 5 * i
print("5x{0}={1}".format(i, e))
for i in range(1, 10):
f = 6 * i
print("6x{0}={1}".format(i, f))
for i in range(1, 10):
g = 7 * i
print("7x{0}={1}".format(i, g))
for i in range(1, 10):
h = 8 * i
print("8x{0}={1}".format(i, h))
for i in range(1, 10):
j = 9 * i
print("9x{0}={1}".format(i, j))
| QQ
Write a program which prints multiplication tables in the following format:
1x1=1
1x2=2
.
.
9x8=72
9x9=81 | [] |
1x1=1
1x2=2
.
.
9x8=72
9x9=81 | s918047391 | Accepted | p00000 | No input. | [[print("{}x{}={}".format(j, i, i * j)) for i in range(1, 10)] for j in range(1, 10)]
| QQ
Write a program which prints multiplication tables in the following format:
1x1=1
1x2=2
.
.
9x8=72
9x9=81 | [] |
1x1=1
1x2=2
.
.
9x8=72
9x9=81 | s052361414 | Accepted | p00000 | No input. | r = range(1, 10)
[print("%dx%d=%d" % (i, j, i * j)) for i in r for j in r]
| QQ
Write a program which prints multiplication tables in the following format:
1x1=1
1x2=2
.
.
9x8=72
9x9=81 | [] |
1x1=1
1x2=2
.
.
9x8=72
9x9=81 | s017142398 | Wrong Answer | p00000 | No input. | [[print("{}+{}={}".format(i, j, i * j)) for j in range(1, 10)] for i in range(1, 10)]
| QQ
Write a program which prints multiplication tables in the following format:
1x1=1
1x2=2
.
.
9x8=72
9x9=81 | [] |
1x1=1
1x2=2
.
.
9x8=72
9x9=81 | s807709080 | Accepted | p00000 | No input. | a = [
"1x1=1",
"1x2=2",
"1x3=3",
"1x4=4",
"1x5=5",
"1x6=6",
"1x7=7",
"1x8=8",
"1x9=9",
"2x1=2",
"2x2=4",
"2x3=6",
"2x4=8",
"2x5=10",
"2x6=12",
"2x7=14",
"2x8=16",
"2x9=18",
"3x1=3",
"3x2=6",
"3x3=9",
"3x4=12",
"3x5=15",
"3x6=18",
"3x7=21",
"3x8=24",
"3x9=27",
"4x1=4",
"4x2=8",
"4x3=12",
"4x4=16",
"4x5=20",
"4x6=24",
"4x7=28",
"4x8=32",
"4x9=36",
"5x1=5",
"5x2=10",
"5x3=15",
"5x4=20",
"5x5=25",
"5x6=30",
"5x7=35",
"5x8=40",
"5x9=45",
"6x1=6",
"6x2=12",
"6x3=18",
"6x4=24",
"6x5=30",
"6x6=36",
"6x7=42",
"6x8=48",
"6x9=54",
"7x1=7",
"7x2=14",
"7x3=21",
"7x4=28",
"7x5=35",
"7x6=42",
"7x7=49",
"7x8=56",
"7x9=63",
"8x1=8",
"8x2=16",
"8x3=24",
"8x4=32",
"8x5=40",
"8x6=48",
"8x7=56",
"8x8=64",
"8x9=72",
"9x1=9",
"9x2=18",
"9x3=27",
"9x4=36",
"9x5=45",
"9x6=54",
"9x7=63",
"9x8=72",
"9x9=81",
]
n = 0
for i in range(81):
print(a[n])
n += 1
| QQ
Write a program which prints multiplication tables in the following format:
1x1=1
1x2=2
.
.
9x8=72
9x9=81 | [] |
1x1=1
1x2=2
.
.
9x8=72
9x9=81 | s049519143 | Wrong Answer | p00000 | No input. | kuku = [i + 1 for i in range(9)]
for i in kuku:
for e in kuku:
print("%i??%i=%i" % (i, e, i * e))
| QQ
Write a program which prints multiplication tables in the following format:
1x1=1
1x2=2
.
.
9x8=72
9x9=81 | [] |
1x1=1
1x2=2
.
.
9x8=72
9x9=81 | s045733196 | Accepted | p00000 | No input. | a = range(1, 10)
[print("{}x{}={}".format(i, j, i * j)) for i in a for j in a]
| QQ
Write a program which prints multiplication tables in the following format:
1x1=1
1x2=2
.
.
9x8=72
9x9=81 | [] |
1x1=1
1x2=2
.
.
9x8=72
9x9=81 | s681832133 | Accepted | p00000 | No input. | [print("{0}x{1}={2}".format(a, b, a * b)) for a in range(1, 10) for b in range(1, 10)]
| QQ
Write a program which prints multiplication tables in the following format:
1x1=1
1x2=2
.
.
9x8=72
9x9=81 | [] |
1x1=1
1x2=2
.
.
9x8=72
9x9=81 | s802398656 | Accepted | p00000 | No input. | [print("{}x{}={}".format(i, j, i * j)) for i in range(1, 10) for j in range(1, 10)]
| QQ
Write a program which prints multiplication tables in the following format:
1x1=1
1x2=2
.
.
9x8=72
9x9=81 | [] |
1x1=1
1x2=2
.
.
9x8=72
9x9=81 | s930397742 | Accepted | p00000 | No input. | [print("%dx%d=%d" % (i, j, i * j)) for i in range(1, 10) for j in range(1, 10)]
| QQ
Write a program which prints multiplication tables in the following format:
1x1=1
1x2=2
.
.
9x8=72
9x9=81 | [] |
1x1=1
1x2=2
.
.
9x8=72
9x9=81 | s228859526 | Wrong Answer | p00000 | No input. | print("<div>po</div>")
| QQ
Write a program which prints multiplication tables in the following format:
1x1=1
1x2=2
.
.
9x8=72
9x9=81 | [] |
1x1=1
1x2=2
.
.
9x8=72
9x9=81 | s688743112 | Wrong Answer | p00000 | No input. | print("test")
| QQ
Write a program which prints multiplication tables in the following format:
1x1=1
1x2=2
.
.
9x8=72
9x9=81 | [] |
1x1=1
1x2=2
.
.
9x8=72
9x9=81 | s992358171 | Wrong Answer | p00000 | No input. | for i in range(1, 10, 1):
for j in range(1, 10, 1):
print(i, "*", j, "=", i * j, sep="")
| QQ
Write a program which prints multiplication tables in the following format:
1x1=1
1x2=2
.
.
9x8=72
9x9=81 | [] |
1x1=1
1x2=2
.
.
9x8=72
9x9=81 | s695781549 | Wrong Answer | p00000 | No input. | for i in list(range(1, 10)):
for ii in list(range(1, 10)):
print("%d x %d = %d * %d" % (i, ii, i, ii))
| QQ
Write a program which prints multiplication tables in the following format:
1x1=1
1x2=2
.
.
9x8=72
9x9=81 | [] |
1x1=1
1x2=2
.
.
9x8=72
9x9=81 | s159807336 | Accepted | p00000 | No input. | QQ = [
"{}x{}={}".format(x + 1, y + 1, (x + 1) * (y + 1))
for x in range(9)
for y in range(9)
]
for o in QQ:
print(o)
| QQ
Write a program which prints multiplication tables in the following format:
1x1=1
1x2=2
.
.
9x8=72
9x9=81 | [] |
1x1=1
1x2=2
.
.
9x8=72
9x9=81 | s993100800 | Wrong Answer | p00000 | No input. | for i in range(0, 9):
for j in range(0, 9):
print("{0}*{1}={2}".format(i + 1, j + 1, (i + 1) * (j + 1)))
| QQ
Write a program which prints multiplication tables in the following format:
1x1=1
1x2=2
.
.
9x8=72
9x9=81 | [] |
If it is estimated that Hikuhashi will never become Kaiden, print `-1`.
Otherwise, print the estimated number of contests before he become Kaiden for
the first time.
* * * | s787409823 | Runtime Error | p03505 | Input is given from Standard Input in the following format:
K A B | p,a,b = map(int,input().split())
if(a<=b):
print(-1)
else:
p-=a
up=a-b
if(p<=0):
print(1)
else
num=p//up+(p%up!=0)
print(num*2+1)
| Statement
_ButCoder Inc._ runs a programming competition site called _ButCoder_. In
this site, a user is given an integer value called rating that represents
his/her skill, which changes each time he/she participates in a contest. The
initial value of a new user's rating is 0, and a user whose rating reaches K
or higher is called _Kaiden_ ("total transmission"). Note that a user's rating
may become negative.
Hikuhashi is a new user in ButCoder. It is estimated that, his rating
increases by A in each of his odd-numbered contests (first, third, fifth,
...), and decreases by B in each of his even-numbered contests (second,
fourth, sixth, ...).
According to this estimate, after how many contests will he become Kaiden for
the first time, or will he never become Kaiden? | [{"input": "4000 2000 500", "output": "5\n \n\nEach time Hikuhashi participates in a contest, his rating is estimated to\nchange as 0 \u2192 2000 \u2192 1500 \u2192 3500 \u2192 3000 \u2192 5000 \u2192 \u2026 After his fifth contest,\nhis rating will reach 4000 or higher for the first time.\n\n* * *"}, {"input": "4000 500 2000", "output": "-1\n \n\nEach time Hikuhashi participates in a contest, his rating is estimated to\nchange as 0 \u2192 500 \u2192 -1500 \u2192 -1000 \u2192 -3000 \u2192 -2500 \u2192 \u2026 He will never become\nKaiden.\n\n* * *"}, {"input": "1000000000000000000 2 1", "output": "1999999999999999997\n \n\nThe input and output values may not fit into 32-bit integers."}] |
If it is estimated that Hikuhashi will never become Kaiden, print `-1`.
Otherwise, print the estimated number of contests before he become Kaiden for
the first time.
* * * | s014837594 | Runtime Error | p03505 | Input is given from Standard Input in the following format:
K A B | s =input().split()
a=0
b=0
while a<int(s[0]) :
b+=1
a+=int(s[1])
if a>int(s[0]) :
break
b+=1
a=a-int(s[2])
if a<0 :
break
if a<0 :
print(-1)
if a>int(s[0]) :
print(int(b) | Statement
_ButCoder Inc._ runs a programming competition site called _ButCoder_. In
this site, a user is given an integer value called rating that represents
his/her skill, which changes each time he/she participates in a contest. The
initial value of a new user's rating is 0, and a user whose rating reaches K
or higher is called _Kaiden_ ("total transmission"). Note that a user's rating
may become negative.
Hikuhashi is a new user in ButCoder. It is estimated that, his rating
increases by A in each of his odd-numbered contests (first, third, fifth,
...), and decreases by B in each of his even-numbered contests (second,
fourth, sixth, ...).
According to this estimate, after how many contests will he become Kaiden for
the first time, or will he never become Kaiden? | [{"input": "4000 2000 500", "output": "5\n \n\nEach time Hikuhashi participates in a contest, his rating is estimated to\nchange as 0 \u2192 2000 \u2192 1500 \u2192 3500 \u2192 3000 \u2192 5000 \u2192 \u2026 After his fifth contest,\nhis rating will reach 4000 or higher for the first time.\n\n* * *"}, {"input": "4000 500 2000", "output": "-1\n \n\nEach time Hikuhashi participates in a contest, his rating is estimated to\nchange as 0 \u2192 500 \u2192 -1500 \u2192 -1000 \u2192 -3000 \u2192 -2500 \u2192 \u2026 He will never become\nKaiden.\n\n* * *"}, {"input": "1000000000000000000 2 1", "output": "1999999999999999997\n \n\nThe input and output values may not fit into 32-bit integers."}] |
Print the answer.
* * * | s288142793 | Runtime Error | p03155 | Input is given from Standard Input in the following format:
N
H
W | a
| Statement
It has been decided that a programming contest sponsored by company A will be
held, so we will post the notice on a bulletin board.
The bulletin board is in the form of a grid with N rows and N columns, and the
notice will occupy a rectangular region with H rows and W columns.
How many ways are there to choose where to put the notice so that it
completely covers exactly HW squares? | [{"input": "3\n 2\n 3", "output": "2\n \n\nThere are two ways to put the notice, as follows:\n\n \n \n ### ...\n ### ###\n ... ###\n \n\nHere, `#` represents a square covered by the notice, and `.` represents a\nsquare not covered.\n\n* * *"}, {"input": "100\n 1\n 1", "output": "10000\n \n\n* * *"}, {"input": "5\n 4\n 2", "output": "8"}] |
Print the answer.
* * * | s878933173 | Runtime Error | p03155 | Input is given from Standard Input in the following format:
N
H
W | # H,W = 3,3
# s = [".#.", "..#", "#.."]
from collections import deque
H, W = map(int, input().split())
s = [input() for _ in range(H)]
ans = 0
kaburi = 0
for i in range(H):
for j in range(W):
if s[i][j] == ".":
continue
stk = deque([(i, j)]) # stktack
visited = set([(i, j)])
while stk: # なくなるまで
y, x = stk.popleft()
for dy, dx in ([1, 0], [0, 1], [-1, 0], [0, -1]):
if 0 <= y + dy < H and 0 <= x + dx < W:
if (s[y][x] == "." and s[y + dy][x + dx] == "#") or (
s[y][x] == "#" and s[y + dy][x + dx] == "."
):
if (y + dy, x + dx) in visited:
continue
stk.append([y + dy, x + dx])
visited.add((y + dy, x + dx))
# print(i,j, y+dy,x+dx, ans)
if s[y + dy][x + dx] == "#":
kaburi += 1
ans += 1
print(ans - kaburi)
| Statement
It has been decided that a programming contest sponsored by company A will be
held, so we will post the notice on a bulletin board.
The bulletin board is in the form of a grid with N rows and N columns, and the
notice will occupy a rectangular region with H rows and W columns.
How many ways are there to choose where to put the notice so that it
completely covers exactly HW squares? | [{"input": "3\n 2\n 3", "output": "2\n \n\nThere are two ways to put the notice, as follows:\n\n \n \n ### ...\n ### ###\n ... ###\n \n\nHere, `#` represents a square covered by the notice, and `.` represents a\nsquare not covered.\n\n* * *"}, {"input": "100\n 1\n 1", "output": "10000\n \n\n* * *"}, {"input": "5\n 4\n 2", "output": "8"}] |
Print the answer.
* * * | s176468530 | Runtime Error | p03155 | Input is given from Standard Input in the following format:
N
H
W | N, Q = list(map(int, input().split(" ")))
A_list = list(map(int, input().split(" ")))
def game(A_list, X, N):
aoki_A_list = sorted(A_list, key=lambda val: abs(val - X))
count = 0
aoki_last_plus = None
aoki_minus_plus = None
aoki_last_minus = None
while True:
taka_val = A_list[-count - 1]
aoki_val = aoki_A_list[count]
aoki_view_val = aoki_val - X
if aoki_view_val >= 0:
aoki_last_plus = aoki_val
now_plus = True
else:
now_plus = False
# print(taka_val, aoki_val, aoki_last_plus, aoki_view_val)
if aoki_last_plus is not None and aoki_last_plus >= taka_val:
if not now_plus:
aoki_fail = False
if now_plus:
if aoki_last_plus == taka_val:
aoki_fail = True
else:
aoki_fail = False
break
if aoki_view_val < 0:
aoki_last_minus = aoki_val
count += 1
conflict_count = count
first_sum = sum(aoki_A_list[:conflict_count])
if aoki_last_minus is not None:
aoki_minus_last_i = A_list.index(aoki_last_minus)
else:
if conflict_count >= 1:
aoki_minus_last_i = A_list.index(aoki_A_list[0])
else:
aoki_minus_last_i = None
last_i = aoki_minus_last_i
if last_i is not None:
if aoki_fail:
if last_i >= 1:
if last_i % 2 == 1:
nokori_sum = sum(A_list[0:last_i:2])
else:
nokori_sum = sum(A_list[1:last_i:2])
else:
nokori_sum = 0
else:
if last_i >= 2:
nokori_sum = sum(A_list[(last_i % 2) : last_i - 1 : 2])
else:
nokori_sum = 0
out = sum(A_list) - (first_sum + nokori_sum)
else:
if N % 2 == 1:
out = sum(A_list[0::2])
else:
out = sum(A_list[1::2])
return out
for i in range(Q):
X = int(input())
out = game(A_list, X, N)
print(out)
| Statement
It has been decided that a programming contest sponsored by company A will be
held, so we will post the notice on a bulletin board.
The bulletin board is in the form of a grid with N rows and N columns, and the
notice will occupy a rectangular region with H rows and W columns.
How many ways are there to choose where to put the notice so that it
completely covers exactly HW squares? | [{"input": "3\n 2\n 3", "output": "2\n \n\nThere are two ways to put the notice, as follows:\n\n \n \n ### ...\n ### ###\n ... ###\n \n\nHere, `#` represents a square covered by the notice, and `.` represents a\nsquare not covered.\n\n* * *"}, {"input": "100\n 1\n 1", "output": "10000\n \n\n* * *"}, {"input": "5\n 4\n 2", "output": "8"}] |
Print the answer.
* * * | s129860784 | Accepted | p03155 | Input is given from Standard Input in the following format:
N
H
W | a = lambda: int(input())
b = a()
print((-~b - a()) * (-~b - a()))
| Statement
It has been decided that a programming contest sponsored by company A will be
held, so we will post the notice on a bulletin board.
The bulletin board is in the form of a grid with N rows and N columns, and the
notice will occupy a rectangular region with H rows and W columns.
How many ways are there to choose where to put the notice so that it
completely covers exactly HW squares? | [{"input": "3\n 2\n 3", "output": "2\n \n\nThere are two ways to put the notice, as follows:\n\n \n \n ### ...\n ### ###\n ... ###\n \n\nHere, `#` represents a square covered by the notice, and `.` represents a\nsquare not covered.\n\n* * *"}, {"input": "100\n 1\n 1", "output": "10000\n \n\n* * *"}, {"input": "5\n 4\n 2", "output": "8"}] |
Print the answer.
* * * | s394765707 | Accepted | p03155 | Input is given from Standard Input in the following format:
N
H
W | N, H, W = map(int, open(0).read().split())
print((1 + N - H) * (1 + N - W))
| Statement
It has been decided that a programming contest sponsored by company A will be
held, so we will post the notice on a bulletin board.
The bulletin board is in the form of a grid with N rows and N columns, and the
notice will occupy a rectangular region with H rows and W columns.
How many ways are there to choose where to put the notice so that it
completely covers exactly HW squares? | [{"input": "3\n 2\n 3", "output": "2\n \n\nThere are two ways to put the notice, as follows:\n\n \n \n ### ...\n ### ###\n ... ###\n \n\nHere, `#` represents a square covered by the notice, and `.` represents a\nsquare not covered.\n\n* * *"}, {"input": "100\n 1\n 1", "output": "10000\n \n\n* * *"}, {"input": "5\n 4\n 2", "output": "8"}] |
Print the answer.
* * * | s174283832 | Runtime Error | p03155 | Input is given from Standard Input in the following format:
N
H
W | n1, n2, n3 = list(map(int, input().split()))
print((n1 - n2) * (n1 - n3))
| Statement
It has been decided that a programming contest sponsored by company A will be
held, so we will post the notice on a bulletin board.
The bulletin board is in the form of a grid with N rows and N columns, and the
notice will occupy a rectangular region with H rows and W columns.
How many ways are there to choose where to put the notice so that it
completely covers exactly HW squares? | [{"input": "3\n 2\n 3", "output": "2\n \n\nThere are two ways to put the notice, as follows:\n\n \n \n ### ...\n ### ###\n ... ###\n \n\nHere, `#` represents a square covered by the notice, and `.` represents a\nsquare not covered.\n\n* * *"}, {"input": "100\n 1\n 1", "output": "10000\n \n\n* * *"}, {"input": "5\n 4\n 2", "output": "8"}] |
Print the answer.
* * * | s290132923 | Runtime Error | p03155 | Input is given from Standard Input in the following format:
N
H
W | n, x, y = map(int, input().split())
print((n - x + 1) * (n - y + 1))
| Statement
It has been decided that a programming contest sponsored by company A will be
held, so we will post the notice on a bulletin board.
The bulletin board is in the form of a grid with N rows and N columns, and the
notice will occupy a rectangular region with H rows and W columns.
How many ways are there to choose where to put the notice so that it
completely covers exactly HW squares? | [{"input": "3\n 2\n 3", "output": "2\n \n\nThere are two ways to put the notice, as follows:\n\n \n \n ### ...\n ### ###\n ... ###\n \n\nHere, `#` represents a square covered by the notice, and `.` represents a\nsquare not covered.\n\n* * *"}, {"input": "100\n 1\n 1", "output": "10000\n \n\n* * *"}, {"input": "5\n 4\n 2", "output": "8"}] |
Print the answer.
* * * | s634720555 | Runtime Error | p03155 | Input is given from Standard Input in the following format:
N
H
W | n = set[int(input()) for i in range(3)]
print((n[0] - n[1] + 1) * (n[0] - n[2] + 1) ) | Statement
It has been decided that a programming contest sponsored by company A will be
held, so we will post the notice on a bulletin board.
The bulletin board is in the form of a grid with N rows and N columns, and the
notice will occupy a rectangular region with H rows and W columns.
How many ways are there to choose where to put the notice so that it
completely covers exactly HW squares? | [{"input": "3\n 2\n 3", "output": "2\n \n\nThere are two ways to put the notice, as follows:\n\n \n \n ### ...\n ### ###\n ... ###\n \n\nHere, `#` represents a square covered by the notice, and `.` represents a\nsquare not covered.\n\n* * *"}, {"input": "100\n 1\n 1", "output": "10000\n \n\n* * *"}, {"input": "5\n 4\n 2", "output": "8"}] |
Print the answer.
* * * | s034466238 | Runtime Error | p03155 | Input is given from Standard Input in the following format:
N
H
W | n = list[int(input()) for i in range(3)]
print((n[0] - n[1] + 1) * (n[0] - n[2] + 1) ) | Statement
It has been decided that a programming contest sponsored by company A will be
held, so we will post the notice on a bulletin board.
The bulletin board is in the form of a grid with N rows and N columns, and the
notice will occupy a rectangular region with H rows and W columns.
How many ways are there to choose where to put the notice so that it
completely covers exactly HW squares? | [{"input": "3\n 2\n 3", "output": "2\n \n\nThere are two ways to put the notice, as follows:\n\n \n \n ### ...\n ### ###\n ... ###\n \n\nHere, `#` represents a square covered by the notice, and `.` represents a\nsquare not covered.\n\n* * *"}, {"input": "100\n 1\n 1", "output": "10000\n \n\n* * *"}, {"input": "5\n 4\n 2", "output": "8"}] |
Print the answer.
* * * | s046813105 | Accepted | p03155 | Input is given from Standard Input in the following format:
N
H
W | a = [int(input()) for _ in range(3)]
print((a[0] + 1 - a[1]) * (a[0] + 1 - a[2]))
| Statement
It has been decided that a programming contest sponsored by company A will be
held, so we will post the notice on a bulletin board.
The bulletin board is in the form of a grid with N rows and N columns, and the
notice will occupy a rectangular region with H rows and W columns.
How many ways are there to choose where to put the notice so that it
completely covers exactly HW squares? | [{"input": "3\n 2\n 3", "output": "2\n \n\nThere are two ways to put the notice, as follows:\n\n \n \n ### ...\n ### ###\n ... ###\n \n\nHere, `#` represents a square covered by the notice, and `.` represents a\nsquare not covered.\n\n* * *"}, {"input": "100\n 1\n 1", "output": "10000\n \n\n* * *"}, {"input": "5\n 4\n 2", "output": "8"}] |
Print the answer.
* * * | s855388730 | Runtime Error | p03155 | Input is given from Standard Input in the following format:
N
H
W | n, h, w = map(int, input() for i in range(3))
print((n - h + 1) * (n - w + 1))
| Statement
It has been decided that a programming contest sponsored by company A will be
held, so we will post the notice on a bulletin board.
The bulletin board is in the form of a grid with N rows and N columns, and the
notice will occupy a rectangular region with H rows and W columns.
How many ways are there to choose where to put the notice so that it
completely covers exactly HW squares? | [{"input": "3\n 2\n 3", "output": "2\n \n\nThere are two ways to put the notice, as follows:\n\n \n \n ### ...\n ### ###\n ... ###\n \n\nHere, `#` represents a square covered by the notice, and `.` represents a\nsquare not covered.\n\n* * *"}, {"input": "100\n 1\n 1", "output": "10000\n \n\n* * *"}, {"input": "5\n 4\n 2", "output": "8"}] |
Print the answer.
* * * | s181465788 | Accepted | p03155 | Input is given from Standard Input in the following format:
N
H
W | N = list(map(int, input().split()))
H = list(map(int, input().split()))
W = list(map(int, input().split()))
print((N[0] - H[0] + 1) * (N[0] - W[0] + 1))
| Statement
It has been decided that a programming contest sponsored by company A will be
held, so we will post the notice on a bulletin board.
The bulletin board is in the form of a grid with N rows and N columns, and the
notice will occupy a rectangular region with H rows and W columns.
How many ways are there to choose where to put the notice so that it
completely covers exactly HW squares? | [{"input": "3\n 2\n 3", "output": "2\n \n\nThere are two ways to put the notice, as follows:\n\n \n \n ### ...\n ### ###\n ... ###\n \n\nHere, `#` represents a square covered by the notice, and `.` represents a\nsquare not covered.\n\n* * *"}, {"input": "100\n 1\n 1", "output": "10000\n \n\n* * *"}, {"input": "5\n 4\n 2", "output": "8"}] |
Print the answer.
* * * | s448586649 | Runtime Error | p03155 | Input is given from Standard Input in the following format:
N
H
W | n, q = map(int, input().split())
card_num = list(map(int, input().split()))
card_num.sort()
x_i = []
for i in range(q):
x_i.append(int(input()))
for i in range(q):
card = []
for num in range(n):
card.append(card_num[num])
taka = []
for j in range(n // 2):
temp = max(card)
card.remove(temp)
taka.append(temp)
up = [x for x in card if x >= x_i[i]]
down = [y for y in card if y < x_i[i]]
if up == []:
card.remove(down[-1])
elif down == []:
card.remove(up[0])
elif up[0] - x_i[i] < x_i[i] - down[-1]:
card.remove(up[0])
else:
card.remove(down[-1])
if n % 2 == 1:
taka.append(card[0])
print(sum(taka))
| Statement
It has been decided that a programming contest sponsored by company A will be
held, so we will post the notice on a bulletin board.
The bulletin board is in the form of a grid with N rows and N columns, and the
notice will occupy a rectangular region with H rows and W columns.
How many ways are there to choose where to put the notice so that it
completely covers exactly HW squares? | [{"input": "3\n 2\n 3", "output": "2\n \n\nThere are two ways to put the notice, as follows:\n\n \n \n ### ...\n ### ###\n ... ###\n \n\nHere, `#` represents a square covered by the notice, and `.` represents a\nsquare not covered.\n\n* * *"}, {"input": "100\n 1\n 1", "output": "10000\n \n\n* * *"}, {"input": "5\n 4\n 2", "output": "8"}] |
Print the answer.
* * * | s280032146 | Runtime Error | p03155 | Input is given from Standard Input in the following format:
N
H
W | # from sys import stdout
# from math import *
# from math import log as lg
# from bisect import bisect_left as bs
log = lambda *x: print(*x)
def cin(*fn, def_fn=str):
i, r = 0, []
if fn:
def_fn = fn[0]
for c in input().split(" "):
r += [(fn[i] if len(fn) > i else def_fn)(c)]
i += 1
return r
##################################################
n, h, w = cin(int)
log(round(n / h) * round(n / h))
| Statement
It has been decided that a programming contest sponsored by company A will be
held, so we will post the notice on a bulletin board.
The bulletin board is in the form of a grid with N rows and N columns, and the
notice will occupy a rectangular region with H rows and W columns.
How many ways are there to choose where to put the notice so that it
completely covers exactly HW squares? | [{"input": "3\n 2\n 3", "output": "2\n \n\nThere are two ways to put the notice, as follows:\n\n \n \n ### ...\n ### ###\n ... ###\n \n\nHere, `#` represents a square covered by the notice, and `.` represents a\nsquare not covered.\n\n* * *"}, {"input": "100\n 1\n 1", "output": "10000\n \n\n* * *"}, {"input": "5\n 4\n 2", "output": "8"}] |
Print the answer.
* * * | s572731852 | Runtime Error | p03155 | Input is given from Standard Input in the following format:
N
H
W | h, w = list(map(int, input().split()))
field = []
for i in range(h):
si = input()
field.append([c for c in si])
def visalizer():
global field
print("=========================")
for i in range(h):
for j in range(w):
print(field[i][j], end=" ")
print("\n")
print("=========================")
def maeke_last(c):
if c == "#":
return "."
else:
return "#"
pair_list = []
dx = [0, 0, -1, 1]
dy = [1, -1, 0, 0]
def dfs(
last,
s_row=0,
s_colmun=0,
row=0,
column=0,
):
global field
global dict
if not ((0 <= row and row <= h - 1) and (0 <= column and column <= w - 1)):
return
if field[row][column] == "@":
return
here = field[row][column]
if here == last:
return
else:
if not ((s_row, s_colmun), (row, column)) in pair_list:
if here == ".":
pair_list.append(((s_row, s_colmun), (row, column)))
here_was = field[row][column]
field[row][column] = "@"
# visalizer()
for i in range(len(dx)):
n_row = row + dx[i]
n_column = column + dy[i]
dfs(last=here, s_row=s_row, s_colmun=s_colmun, row=n_row, column=n_column)
field[row][column] = here_was
# for s_row in range(h):
# for s_column in range(w):
# dfs(last = field[s_row][s_column], s_row=s_row, s_colmun=s_column, row=s_row, column=s_column)
for s_row in range(h):
for s_column in range(w):
if field[s_row][s_column] == "#":
dfs(
last=maeke_last(field[s_row][s_column]),
s_row=s_row,
s_colmun=s_column,
row=s_row,
column=s_column,
)
for ele in pair_list:
if ele[0] == ele[1]:
pair_list.remove(ele)
# pair_list.remove((ele[1], ele[0]))
pair_list2 = []
# for ele in pair_list:
# if (not (ele[1], ele[0]) in pair_list2) :
# pair_list2.append(ele)
# for ele in pair_list2:
# print(ele)
print(len(pair_list))
# visalizer()
| Statement
It has been decided that a programming contest sponsored by company A will be
held, so we will post the notice on a bulletin board.
The bulletin board is in the form of a grid with N rows and N columns, and the
notice will occupy a rectangular region with H rows and W columns.
How many ways are there to choose where to put the notice so that it
completely covers exactly HW squares? | [{"input": "3\n 2\n 3", "output": "2\n \n\nThere are two ways to put the notice, as follows:\n\n \n \n ### ...\n ### ###\n ... ###\n \n\nHere, `#` represents a square covered by the notice, and `.` represents a\nsquare not covered.\n\n* * *"}, {"input": "100\n 1\n 1", "output": "10000\n \n\n* * *"}, {"input": "5\n 4\n 2", "output": "8"}] |
Print the answer.
* * * | s578252958 | Runtime Error | p03155 | Input is given from Standard Input in the following format:
N
H
W | h, w = map(int, input().split())
lis = [str(input()) for i in range(h)]
ans = 0
ch = [[0] * w for i in range(h)]
def firstcheck(x, y):
if lis[x][y] != "#" or ch[x][y] != 0:
return False
if x > 0:
if lis[x - 1][y] == ".":
return True
if x < h - 1:
if lis[x + 1][y] == ".":
return True
if y > 0:
if lis[x][y - 1] == ".":
return True
if y < w - 1:
if lis[x][y + 1] == ".":
return True
return False
for sx in range(h):
for sy in range(w):
if firstcheck(sx, sy):
cnt = 1
nu = 0
ch[sx][sy] = 1
num = [[0] * w for i in range(h)]
now = {(sx, sy, 1)}
while len(now) != 0:
tmp = set()
for x, y, iro in now:
if x > 0:
if lis[x - 1][y] != lis[x][y] and num[x - 1][y] == 0:
nu += iro
tmp.add((x - 1, y, (iro + 1) % 2))
num[x - 1][y] = 1
if lis[x - 1][y] == "#" and ch[x - 1][y] == 0:
cnt += 1
ch[x - 1][y] = 1
if x < h - 1:
if lis[x + 1][y] != lis[x][y] and num[x + 1][y] == 0:
nu += iro
tmp.add((x + 1, y, (iro + 1) % 2))
num[x + 1][y] = 1
if lis[x + 1][y] == "#" and ch[x + 1][y] == 0:
cnt += 1
ch[x + 1][y] = 1
if y > 0:
if lis[x][y - 1] != lis[x][y] and num[x][y - 1] == 0:
nu += iro
tmp.add((x, y - 1, (iro + 1) % 2))
num[x][y - 1] = 1
if lis[x][y - 1] == "#" and ch[x][y - 1] == 0:
cnt += 1
ch[x][y - 1] = 1
if y < w - 1:
if lis[x][y + 1] != lis[x][y] and num[x][y + 1] == 0:
nu += iro
tmp.add((x, y + 1, (iro + 1) % 2))
num[x][y + 1] = 1
if lis[x][y + 1] == "#" and ch[x][y + 1] == 0:
cnt += 1
ch[x][y + 1] = 1
now = tmp
ans += nu * cnt
print(ans)
| Statement
It has been decided that a programming contest sponsored by company A will be
held, so we will post the notice on a bulletin board.
The bulletin board is in the form of a grid with N rows and N columns, and the
notice will occupy a rectangular region with H rows and W columns.
How many ways are there to choose where to put the notice so that it
completely covers exactly HW squares? | [{"input": "3\n 2\n 3", "output": "2\n \n\nThere are two ways to put the notice, as follows:\n\n \n \n ### ...\n ### ###\n ... ###\n \n\nHere, `#` represents a square covered by the notice, and `.` represents a\nsquare not covered.\n\n* * *"}, {"input": "100\n 1\n 1", "output": "10000\n \n\n* * *"}, {"input": "5\n 4\n 2", "output": "8"}] |
Print the answer.
* * * | s186462857 | Runtime Error | p03155 | Input is given from Standard Input in the following format:
N
H
W | H, W = map(int, input().split())
S = [input() for i in range(H)]
b_list = []
for row in S:
tmp_raw = []
for j, t in enumerate(row):
if t == "#":
tmp_raw.append(j)
b_list.append(tmp_raw)
tmp = -1
res = {}
raw_before = []
for i, raw in enumerate(b_list):
res[i] = {}
for j in raw:
res[i][j] = []
if not ((j - 1) in raw or j == 0):
res[i][j].append((i, j - 1))
if not ((j + 1) in raw or j == W - 1):
res[i][j].append((i, j + 1))
if not (i == 0 or j in raw_before):
res[i][j].append((i - 1, j))
if not (i == H - 1):
if not (j in b_list[i + 1]):
res[i][j].append((i + 1, j))
raw_before = raw
before = 0
for i, raw in enumerate(b_list):
for j in raw:
before += len(res[i][j])
while True:
for i, raw in enumerate(b_list):
for j in raw:
try:
if S[i - 1][j] == "." or S[i][j - 1] == ".":
res[i][j] += res[i - 1][j - 1]
except:
pass
try:
if S[i + 1][j] == "." or S[i][j - 1] == ".":
res[i][j] += res[i + 1][j - 1]
except:
pass
try:
if S[i - 1][j] == "." or S[i][j + 1] == ".":
res[i][j] += res[i - 1][j + 1]
except:
pass
try:
if S[i + 1][j] == "." or S[i][j + 1] == ".":
res[i][j] += res[i + 1][j + 1]
except:
pass
before = result
for i, raw in enumerate(b_list):
for j in raw:
res[i][j] = list(set(res[i][j]))
result = 0
for i, raw in enumerate(b_list):
for j in raw:
result += len(res[i][j])
if before == result:
break
print(result)
| Statement
It has been decided that a programming contest sponsored by company A will be
held, so we will post the notice on a bulletin board.
The bulletin board is in the form of a grid with N rows and N columns, and the
notice will occupy a rectangular region with H rows and W columns.
How many ways are there to choose where to put the notice so that it
completely covers exactly HW squares? | [{"input": "3\n 2\n 3", "output": "2\n \n\nThere are two ways to put the notice, as follows:\n\n \n \n ### ...\n ### ###\n ... ###\n \n\nHere, `#` represents a square covered by the notice, and `.` represents a\nsquare not covered.\n\n* * *"}, {"input": "100\n 1\n 1", "output": "10000\n \n\n* * *"}, {"input": "5\n 4\n 2", "output": "8"}] |
Print the minimum number of coins in a line. | s838148079 | Wrong Answer | p02314 | n m
d1 d2 ... dm
Two integers n and m are given in the first line. The available denominations
are given in the second line. | from collections import deque
n, m = map(int, input().split())
d = list(map(int, input().split()))
dp = [100000 for i in range(n + 1)]
dp[n] = 0
que = deque()
que.append(n)
while len(que) > 0:
front = que.popleft()
for i in d:
if front - i == 0:
print(dp[front] + 1)
que.clear()
break
if front > i:
dp[front - i] = min(dp[front] + 1, dp[front - i])
que.append(front - i)
else:
break
| Coin Changing Problem
Find the minimum number of coins to make change for n cents using coins of
denominations d1, d2,.., dm. The coins can be used any number of times. | [{"input": "55 4\n 1 5 10 50", "output": "2"}, {"input": "15 6\n 1 2 7 8 12 50", "output": "2"}, {"input": "65 6\n 1 2 7 8 12 50", "output": "3"}] |
Print the minimum number of coins in a line. | s404485977 | Accepted | p02314 | n m
d1 d2 ... dm
Two integers n and m are given in the first line. The available denominations
are given in the second line. | n, m = map(int, input().split())
a = [i for i in range(n + 1)]
for i in list(map(int, input().split())):
for j in range(i, n + 1):
a[j] = min(a[j - i] + 1, a[j])
print(a[-1])
| Coin Changing Problem
Find the minimum number of coins to make change for n cents using coins of
denominations d1, d2,.., dm. The coins can be used any number of times. | [{"input": "55 4\n 1 5 10 50", "output": "2"}, {"input": "15 6\n 1 2 7 8 12 50", "output": "2"}, {"input": "65 6\n 1 2 7 8 12 50", "output": "3"}] |
Print the minimum number of coins in a line. | s628869141 | Accepted | p02314 | n m
d1 d2 ... dm
Two integers n and m are given in the first line. The available denominations
are given in the second line. | def resolve():
Nyens, Mtypes = map(
int, input().split()
) # N円をM種類のコインで最小枚数で払うという問題
types = list(map(int, input().split())) # 何円玉があるかのリスト
def knapsack(Nyens, Mtypes, types):
# dp[i][j]:i種類目までのコイン限定でj円払うのに必要な最小枚数
# 最小で無限枚必要として初期化
dp = [[float("inf")] * (Nyens + 1) for _ in range(Mtypes + 1)]
# 0円は0枚で払える
for ii in range(Mtypes):
dp[ii][0] = 0
for i in range(Mtypes):
for j in range(Nyens + 1):
if j >= types[i]: # 最小枚数更新の可能性
dp[i + 1][j] = min(dp[i][j], dp[i + 1][j - types[i]] + 1)
else: # 可能性なし
dp[i + 1][j] = dp[i][j]
return dp[Mtypes][Nyens]
print(knapsack(Nyens, Mtypes, types))
resolve()
| Coin Changing Problem
Find the minimum number of coins to make change for n cents using coins of
denominations d1, d2,.., dm. The coins can be used any number of times. | [{"input": "55 4\n 1 5 10 50", "output": "2"}, {"input": "15 6\n 1 2 7 8 12 50", "output": "2"}, {"input": "65 6\n 1 2 7 8 12 50", "output": "3"}] |
Print the minimum number of coins in a line. | s571011768 | Wrong Answer | p02314 | n m
d1 d2 ... dm
Two integers n and m are given in the first line. The available denominations
are given in the second line. | n, m = [int(w) for w in input().split()]
cs = [int(w) for w in input().split()]
res = 50001
def comb(i, acc):
global cs, m
if i >= m:
compute(acc)
return
comb(i + 1, acc)
acc.append(cs[i])
comb(i + 1, acc)
acc.pop()
def compute(lst):
global res, n
lst = reversed(sorted(lst))
r = 0
v = n
for e in lst:
r += v // e
v %= e
if v == 0:
res = min(res, r)
break
comb(0, [])
print(res)
| Coin Changing Problem
Find the minimum number of coins to make change for n cents using coins of
denominations d1, d2,.., dm. The coins can be used any number of times. | [{"input": "55 4\n 1 5 10 50", "output": "2"}, {"input": "15 6\n 1 2 7 8 12 50", "output": "2"}, {"input": "65 6\n 1 2 7 8 12 50", "output": "3"}] |
If it is possible to obtain S = T, print `YES`. Otherwise, print `NO`.
* * * | s984251189 | Accepted | p03856 | The input is given from Standard Input in the following format:
S | s = list(input())
n = len(s)
c = 0
k = 0
while c == 0:
if k == n:
c = 1
else:
if (
k + 7 <= n - 1
and s[k] == "d"
and s[k + 1] == "r"
and s[k + 2] == "e"
and s[k + 3] == "a"
and s[k + 4] == "m"
and s[k + 5] == "e"
and s[k + 6] == "r"
and s[k + 7] == "a"
):
k += 5
elif (
k + 6 <= n - 1
and s[k] == "d"
and s[k + 1] == "r"
and s[k + 2] == "e"
and s[k + 3] == "a"
and s[k + 4] == "m"
and s[k + 5] == "e"
and s[k + 6] == "r"
):
k += 7
elif (
k + 4 <= n - 1
and s[k] == "d"
and s[k + 1] == "r"
and s[k + 2] == "e"
and s[k + 3] == "a"
and s[k + 4] == "m"
):
k += 5
elif (
k + 6 <= n - 1
and s[k] == "e"
and s[k + 1] == "r"
and s[k + 2] == "a"
and s[k + 3] == "s"
and s[k + 4] == "e"
and s[k + 5] == "r"
and s[k + 6] == "a"
):
k += 5
elif (
k + 5 <= n - 1
and s[k] == "e"
and s[k + 1] == "r"
and s[k + 2] == "a"
and s[k + 3] == "s"
and s[k + 4] == "e"
and s[k + 5] == "r"
):
k += 6
elif (
k + 4 <= n - 1
and s[k] == "e"
and s[k + 1] == "r"
and s[k + 2] == "a"
and s[k + 3] == "s"
and s[k + 4] == "e"
):
k += 5
else:
c = 1
if k == n:
print("YES")
else:
print("NO")
| Statement
You are given a string S consisting of lowercase English letters. Another
string T is initially empty. Determine whether it is possible to obtain S = T
by performing the following operation an arbitrary number of times:
* Append one of the following at the end of T: `dream`, `dreamer`, `erase` and `eraser`. | [{"input": "erasedream", "output": "YES\n \n\nAppend `erase` and `dream` at the end of T in this order, to obtain S = T.\n\n* * *"}, {"input": "dreameraser", "output": "YES\n \n\nAppend `dream` and `eraser` at the end of T in this order, to obtain S = T.\n\n* * *"}, {"input": "dreamerer", "output": "NO"}] |
If it is possible to obtain S = T, print `YES`. Otherwise, print `NO`.
* * * | s892647273 | Accepted | p03856 | The input is given from Standard Input in the following format:
S | from collections import deque
def solve(s):
stack = deque()
stack.append(s)
while len(stack) > 0:
top = stack.pop()
if top == "":
return "YES"
if top[:5] == "dream":
if top[5:7] == "er":
stack.append(top[7:])
stack.append(top[5:])
elif top[:5] == "erase":
if len(top) > 5 and top[5] == "r":
stack.append(top[6:])
else:
stack.append(top[5:])
return "NO"
print(solve(input()))
| Statement
You are given a string S consisting of lowercase English letters. Another
string T is initially empty. Determine whether it is possible to obtain S = T
by performing the following operation an arbitrary number of times:
* Append one of the following at the end of T: `dream`, `dreamer`, `erase` and `eraser`. | [{"input": "erasedream", "output": "YES\n \n\nAppend `erase` and `dream` at the end of T in this order, to obtain S = T.\n\n* * *"}, {"input": "dreameraser", "output": "YES\n \n\nAppend `dream` and `eraser` at the end of T in this order, to obtain S = T.\n\n* * *"}, {"input": "dreamerer", "output": "NO"}] |
If it is possible to obtain S = T, print `YES`. Otherwise, print `NO`.
* * * | s913768548 | Runtime Error | p03856 | The input is given from Standard Input in the following format:
S | import sys
from collections import Counter
class UnionFind:
def __init__(self, n):
self.p = list(range(n))
self.rank = [0] * n
def find_root(self, x):
if x != self.p[x]:
self.p[x] = self.find_root(self.p[x])
return self.p[x]
def is_same(self, x, y):
return self.find_root(x) == self.find_root(y)
def unite(self, x, y):
u = self.find_root(x)
v = self.find_root(y)
if u == v:
return
if self.rank[u] < self.rank[v]:
self.p[u] = v
else:
self.p[v] = u
if self.rank[u] == self.rank[v]:
self.rank[u] += 1
N, K, L = map(int, sys.stdin.readline().split())
uf1 = UnionFind(N)
uf2 = UnionFind(N)
for i in range(K):
p, q = map(int, sys.stdin.readline().split())
p, q = p - 1, q - 1
uf1.unite(p, q)
for i in range(L):
r, s = map(int, sys.stdin.readline().split())
r, s = r - 1, s - 1
uf2.unite(r, s)
cntr = Counter()
for i in range(N):
u = uf1.find_root(i)
v = uf2.find_root(i)
cntr[(u, v)] += 1
ans = []
for i in range(N):
u = uf1.find_root(i)
v = uf2.find_root(i)
ans.append(cntr[(u, v)])
print(*ans)
| Statement
You are given a string S consisting of lowercase English letters. Another
string T is initially empty. Determine whether it is possible to obtain S = T
by performing the following operation an arbitrary number of times:
* Append one of the following at the end of T: `dream`, `dreamer`, `erase` and `eraser`. | [{"input": "erasedream", "output": "YES\n \n\nAppend `erase` and `dream` at the end of T in this order, to obtain S = T.\n\n* * *"}, {"input": "dreameraser", "output": "YES\n \n\nAppend `dream` and `eraser` at the end of T in this order, to obtain S = T.\n\n* * *"}, {"input": "dreamerer", "output": "NO"}] |
If it is possible to obtain S = T, print `YES`. Otherwise, print `NO`.
* * * | s703633877 | Runtime Error | p03856 | The input is given from Standard Input in the following format:
S | # coding: utf-8
# Your code here!
import sys
sys.setrecursionlimit(10**9)
from collections import Counter
from collections import defaultdict
n, k, l = map(int, input().split())
p = [0] * (k + 1)
q = [0] * (k + 1)
rd = [[] for _ in range(n + 1)]
r = [0] * (l + 1)
s = [0] * (l + 1)
rw = [[] for _ in range(n + 1)]
for i in range(k):
a, b = map(int, input().split())
p[i], q[i] = a, b
rd[a].append(b)
rd[b].append(a)
for i in range(l):
a, b = map(int, input().split())
r[i], s[i] = a, b
rw[a].append(b)
rw[b].append(a)
prd = [i for i in range(n + 1)]
def union(x, y):
rx = root(x)
ry = root(y)
if rx == ry:
return
p[rx] = ry
def root(x):
if p[x] == x:
return x
p[x] = root(p[x])
return p[x]
cnt = [[] for _ in range(n + 1)]
# print(rd)
# print(rw)
p = prd
for i in range(1, n + 1):
for j in rd[i]:
union(i, j)
for i in range(1, n + 1):
rt = root(i)
prd[i] = rt
# cnt[i].append(rt)
p = [i for i in range(n + 1)]
for i in range(1, n + 1):
for j in rw[i]:
union(i, j)
for i in range(1, n + 1):
rt = root(i)
p[i] = rt
# cnt[i].append(rt)
# print(cnt)
# c=Counter(cnt)
dc = defaultdict(int)
for i in range(1, n + 1):
dc[prd[i], p[i]] += 1
# for i in range(n+1):
print(*[dc[prd[i], p[i]] for i in range(1, n + 1)])
| Statement
You are given a string S consisting of lowercase English letters. Another
string T is initially empty. Determine whether it is possible to obtain S = T
by performing the following operation an arbitrary number of times:
* Append one of the following at the end of T: `dream`, `dreamer`, `erase` and `eraser`. | [{"input": "erasedream", "output": "YES\n \n\nAppend `erase` and `dream` at the end of T in this order, to obtain S = T.\n\n* * *"}, {"input": "dreameraser", "output": "YES\n \n\nAppend `dream` and `eraser` at the end of T in this order, to obtain S = T.\n\n* * *"}, {"input": "dreamerer", "output": "NO"}] |
If it is possible to obtain S = T, print `YES`. Otherwise, print `NO`.
* * * | s714017966 | Accepted | p03856 | The input is given from Standard Input in the following format:
S | s = input()
x = 0
a = s.count("dream")
b = s.count("dreamer")
c = s.count("erase")
d = s.count("eraser")
reigai1 = s.count("dreamerase")
reigai2 = s.count("dreameraser")
reigai1 = reigai1 - reigai2
b = b - reigai1 - reigai2
a = a - reigai1 - reigai2
c = c - reigai1 - reigai2
d = d - reigai2
a2 = a - b
c2 = c - d
# print(a,b,c,d)
# print(a2,c2)
# print(reigai1,reigai2)
# print(a2*5+b*7+c2*5+d*6+reigai1*10+reigai2*11)
if a2 * 5 + b * 7 + c2 * 5 + d * 6 + reigai1 * 10 + reigai2 * 11 == len(s):
print("YES")
else:
print("NO")
| Statement
You are given a string S consisting of lowercase English letters. Another
string T is initially empty. Determine whether it is possible to obtain S = T
by performing the following operation an arbitrary number of times:
* Append one of the following at the end of T: `dream`, `dreamer`, `erase` and `eraser`. | [{"input": "erasedream", "output": "YES\n \n\nAppend `erase` and `dream` at the end of T in this order, to obtain S = T.\n\n* * *"}, {"input": "dreameraser", "output": "YES\n \n\nAppend `dream` and `eraser` at the end of T in this order, to obtain S = T.\n\n* * *"}, {"input": "dreamerer", "output": "NO"}] |
If it is possible to obtain S = T, print `YES`. Otherwise, print `NO`.
* * * | s072498758 | Runtime Error | p03856 | The input is given from Standard Input in the following format:
S | s = input().strip()
strings = "eraser erase dreamer dream".split()
exceptions = "dreameraser dreamerase".split()
while 1:
for string in strings:
if s.startswith(string):
if string == "dreamer":
for exception in exceptions:
if startswith(exception):
s = s[len(exception):]
else:
s = s[len(string):]
break
else:
break
print("NO" if s else "YES") | Statement
You are given a string S consisting of lowercase English letters. Another
string T is initially empty. Determine whether it is possible to obtain S = T
by performing the following operation an arbitrary number of times:
* Append one of the following at the end of T: `dream`, `dreamer`, `erase` and `eraser`. | [{"input": "erasedream", "output": "YES\n \n\nAppend `erase` and `dream` at the end of T in this order, to obtain S = T.\n\n* * *"}, {"input": "dreameraser", "output": "YES\n \n\nAppend `dream` and `eraser` at the end of T in this order, to obtain S = T.\n\n* * *"}, {"input": "dreamerer", "output": "NO"}] |
If it is possible to obtain S = T, print `YES`. Otherwise, print `NO`.
* * * | s993300189 | Runtime Error | p03856 | The input is given from Standard Input in the following format:
S | no
| Statement
You are given a string S consisting of lowercase English letters. Another
string T is initially empty. Determine whether it is possible to obtain S = T
by performing the following operation an arbitrary number of times:
* Append one of the following at the end of T: `dream`, `dreamer`, `erase` and `eraser`. | [{"input": "erasedream", "output": "YES\n \n\nAppend `erase` and `dream` at the end of T in this order, to obtain S = T.\n\n* * *"}, {"input": "dreameraser", "output": "YES\n \n\nAppend `dream` and `eraser` at the end of T in this order, to obtain S = T.\n\n* * *"}, {"input": "dreamerer", "output": "NO"}] |
If it is possible to obtain S = T, print `YES`. Otherwise, print `NO`.
* * * | s181584945 | Runtime Error | p03856 | The input is given from Standard Input in the following format:
S | from collections import *
class UNION_FIND(object):
def __init__(self, n):
# 親の番号を格納する。親だった場合は-(その集合のサイズ)
# 作るときはParentの値を全て-1にする
# こうすると全てバラバラになる
self.parent = [-1 for i in range(n)]
def root(self, x):
# Aがどのグループに属しているか調べる
if self.parent[x] < 0:
return x
else:
self.parent[x] = self.root(
self.parent[x]
) # 親を再帰で探知 再帰は最後に上のifにひっかかる
return self.parent[x]
def size(self, x):
# 自分のいるグループの頂点数を調べる
return -self.parent[self.root(x)] # 親をとってきたい
def union(self, x, y):
# AとBをくっ付ける
# AとBを直接つなぐのではなく、root(A)にroot(B)をくっつける
# print(self.parent)
x = self.root(x)
y = self.root(y)
# print(x,y)
if x == y: # すでにくっついてるからくっ付けない
return False
# 大きい方(A)に小さいほう(B)をくっ付けたい
# 大小が逆だったらひっくり返しちゃう。
if self.size(x) < self.size(y):
x, y = y, x
self.parent[x] += self.parent[y] # Aのサイズを更新する
self.parent[y] = x # Bの親をAに変更する
return True
n, k, l = map(int, input().split())
u1 = UNION_FIND(n)
u2 = UNION_FIND(n)
d = defaultdict(int)
for i in range(k):
p, q = map(int, input().split())
u1.union(p - 1, q - 1)
for i in range(l):
p, q = map(int, input().split())
u2.union(p - 1, q - 1)
| Statement
You are given a string S consisting of lowercase English letters. Another
string T is initially empty. Determine whether it is possible to obtain S = T
by performing the following operation an arbitrary number of times:
* Append one of the following at the end of T: `dream`, `dreamer`, `erase` and `eraser`. | [{"input": "erasedream", "output": "YES\n \n\nAppend `erase` and `dream` at the end of T in this order, to obtain S = T.\n\n* * *"}, {"input": "dreameraser", "output": "YES\n \n\nAppend `dream` and `eraser` at the end of T in this order, to obtain S = T.\n\n* * *"}, {"input": "dreamerer", "output": "NO"}] |
If it is possible to obtain S = T, print `YES`. Otherwise, print `NO`.
* * * | s830154619 | Wrong Answer | p03856 | The input is given from Standard Input in the following format:
S | d = {"dream": 5, "dreamer": 7, "erase": 5, "eraser": 6}
st = input().strip()
cnt = 0
if st.find("dream") != -1:
cnt += st.count("dream") * d["dream"]
if st.find("dreamer") != -1:
cnt += st.count("dreamer") * d["dreamer"]
if st.find("erase") != -1:
cnt += st.count("erase") * d["erase"]
if st.find("eraser") != -1:
cnt += st.count("eraser") * d["eraser"]
print("YES" if cnt == len(st) else "NO")
| Statement
You are given a string S consisting of lowercase English letters. Another
string T is initially empty. Determine whether it is possible to obtain S = T
by performing the following operation an arbitrary number of times:
* Append one of the following at the end of T: `dream`, `dreamer`, `erase` and `eraser`. | [{"input": "erasedream", "output": "YES\n \n\nAppend `erase` and `dream` at the end of T in this order, to obtain S = T.\n\n* * *"}, {"input": "dreameraser", "output": "YES\n \n\nAppend `dream` and `eraser` at the end of T in this order, to obtain S = T.\n\n* * *"}, {"input": "dreamerer", "output": "NO"}] |
If it is possible to obtain S = T, print `YES`. Otherwise, print `NO`.
* * * | s894227964 | Runtime Error | p03856 | The input is given from Standard Input in the following format:
S | dreameraser
| Statement
You are given a string S consisting of lowercase English letters. Another
string T is initially empty. Determine whether it is possible to obtain S = T
by performing the following operation an arbitrary number of times:
* Append one of the following at the end of T: `dream`, `dreamer`, `erase` and `eraser`. | [{"input": "erasedream", "output": "YES\n \n\nAppend `erase` and `dream` at the end of T in this order, to obtain S = T.\n\n* * *"}, {"input": "dreameraser", "output": "YES\n \n\nAppend `dream` and `eraser` at the end of T in this order, to obtain S = T.\n\n* * *"}, {"input": "dreamerer", "output": "NO"}] |
If it is possible to obtain S = T, print `YES`. Otherwise, print `NO`.
* * * | s423214975 | Runtime Error | p03856 | The input is given from Standard Input in the following format:
S | s = input()
while s != '':
if s[:5] == 'dream' or s[:5] == 'erase':
if s[5] = 'r':
s = s[6:]
else:
s = s[5:]
else:
print('NO')
quit(0)
print('YES')
| Statement
You are given a string S consisting of lowercase English letters. Another
string T is initially empty. Determine whether it is possible to obtain S = T
by performing the following operation an arbitrary number of times:
* Append one of the following at the end of T: `dream`, `dreamer`, `erase` and `eraser`. | [{"input": "erasedream", "output": "YES\n \n\nAppend `erase` and `dream` at the end of T in this order, to obtain S = T.\n\n* * *"}, {"input": "dreameraser", "output": "YES\n \n\nAppend `dream` and `eraser` at the end of T in this order, to obtain S = T.\n\n* * *"}, {"input": "dreamerer", "output": "NO"}] |
Assume that there are K strings of length N that are in normal form: w_1,
\ldots, w_K in lexicographical order. Output should be in the following
format:
w_1
:
w_K
* * * | s958304575 | Accepted | p02744 | Input is given from Standard Input in the following format:
N | from sys import stdin
def dfs(str, mx):
if len(str) == N:
print(str)
return
for i in range(ord("a"), mx + 2):
# print(i,mx+2)
if i > mx:
mx = i
t = str
t = t + chr(i)
# print(str)
dfs(t, mx)
# print(str)
# S = stdin.readline().rstrip().split()
N = [int(x) for x in stdin.readline().rstrip().split()][0]
dfs("", ord("a") - 1)
| Statement
In this problem, we only consider strings consisting of lowercase English
letters.
Strings s and t are said to be **isomorphic** when the following conditions
are satisfied:
* |s| = |t| holds.
* For every pair i, j, one of the following holds:
* s_i = s_j and t_i = t_j.
* s_i \neq s_j and t_i \neq t_j.
For example, `abcac` and `zyxzx` are isomorphic, while `abcac` and `ppppp` are
not.
A string s is said to be in **normal form** when the following condition is
satisfied:
* For every string t that is isomorphic to s, s \leq t holds. Here \leq denotes lexicographic comparison.
For example, `abcac` is in normal form, but `zyxzx` is not since it is
isomorphic to `abcac`, which is lexicographically smaller than `zyxzx`.
You are given an integer N. Print all strings of length N that are in normal
form, in lexicographically ascending order. | [{"input": "1", "output": "a\n \n\n* * *"}, {"input": "2", "output": "aa\n ab"}] |
Assume that there are K strings of length N that are in normal form: w_1,
\ldots, w_K in lexicographical order. Output should be in the following
format:
w_1
:
w_K
* * * | s051685321 | Runtime Error | p02744 | Input is given from Standard Input in the following format:
N | import itertools
bells = [[], [[0]]] + [None for i in range(9)]
bell_n = [1, 1, 2, 5, 15, 52, 203, 877, 4140, 21147, 115975]
def search(n):
ret = []
ret.append([0 for _ in range(n)])
for k in range(1, n):
for bi in bells[k]:
for ids in itertools.combinations(range(1, n), k):
st = [0 for _ in range(n)]
for i, id in enumerate(ids):
st[id] = bi[i] + 1
ret.append(st)
return ret
for i in range(2, 10):
bells[i] = search(i)
assert bell_n[i] == len(bells[i])
N = int(input())
table = "abcdefghij"
outs = []
for bi in bells[N]:
out = ""
for b in bi:
out += table[b]
outs.append(out)
print("\n".join(sorted(outs)))
| Statement
In this problem, we only consider strings consisting of lowercase English
letters.
Strings s and t are said to be **isomorphic** when the following conditions
are satisfied:
* |s| = |t| holds.
* For every pair i, j, one of the following holds:
* s_i = s_j and t_i = t_j.
* s_i \neq s_j and t_i \neq t_j.
For example, `abcac` and `zyxzx` are isomorphic, while `abcac` and `ppppp` are
not.
A string s is said to be in **normal form** when the following condition is
satisfied:
* For every string t that is isomorphic to s, s \leq t holds. Here \leq denotes lexicographic comparison.
For example, `abcac` is in normal form, but `zyxzx` is not since it is
isomorphic to `abcac`, which is lexicographically smaller than `zyxzx`.
You are given an integer N. Print all strings of length N that are in normal
form, in lexicographically ascending order. | [{"input": "1", "output": "a\n \n\n* * *"}, {"input": "2", "output": "aa\n ab"}] |
Assume that there are K strings of length N that are in normal form: w_1,
\ldots, w_K in lexicographical order. Output should be in the following
format:
w_1
:
w_K
* * * | s704826845 | Wrong Answer | p02744 | Input is given from Standard Input in the following format:
N | n = int(input())
s = [[] for i in range(n + 1)]
s[1].append("a")
ans_s = []
for num in range(1, n):
for st in s[num]:
for add in range(97, max(map(ord, st)) + 2):
s[num + 1].append(st + chr(add))
print(s[n])
| Statement
In this problem, we only consider strings consisting of lowercase English
letters.
Strings s and t are said to be **isomorphic** when the following conditions
are satisfied:
* |s| = |t| holds.
* For every pair i, j, one of the following holds:
* s_i = s_j and t_i = t_j.
* s_i \neq s_j and t_i \neq t_j.
For example, `abcac` and `zyxzx` are isomorphic, while `abcac` and `ppppp` are
not.
A string s is said to be in **normal form** when the following condition is
satisfied:
* For every string t that is isomorphic to s, s \leq t holds. Here \leq denotes lexicographic comparison.
For example, `abcac` is in normal form, but `zyxzx` is not since it is
isomorphic to `abcac`, which is lexicographically smaller than `zyxzx`.
You are given an integer N. Print all strings of length N that are in normal
form, in lexicographically ascending order. | [{"input": "1", "output": "a\n \n\n* * *"}, {"input": "2", "output": "aa\n ab"}] |
Assume that there are K strings of length N that are in normal form: w_1,
\ldots, w_K in lexicographical order. Output should be in the following
format:
w_1
:
w_K
* * * | s113536776 | Runtime Error | p02744 | Input is given from Standard Input in the following format:
N | # パナソニック2020D
import sys
def write(x):
sys.stdout.write(x)
sys.stdout.write("\n")
from queue import deque
n = int(input())
q = deque([("a", "a")])
while True:
s, m = q.pop()
if len(s)==n:
write(s)
elif len(s)>=n+1:
break
for o in range(ord("a"), ord(m)+2):
if ord(m)<o:
m = chr(o)
q.appendleft((s + chr(o), m)) | Statement
In this problem, we only consider strings consisting of lowercase English
letters.
Strings s and t are said to be **isomorphic** when the following conditions
are satisfied:
* |s| = |t| holds.
* For every pair i, j, one of the following holds:
* s_i = s_j and t_i = t_j.
* s_i \neq s_j and t_i \neq t_j.
For example, `abcac` and `zyxzx` are isomorphic, while `abcac` and `ppppp` are
not.
A string s is said to be in **normal form** when the following condition is
satisfied:
* For every string t that is isomorphic to s, s \leq t holds. Here \leq denotes lexicographic comparison.
For example, `abcac` is in normal form, but `zyxzx` is not since it is
isomorphic to `abcac`, which is lexicographically smaller than `zyxzx`.
You are given an integer N. Print all strings of length N that are in normal
form, in lexicographically ascending order. | [{"input": "1", "output": "a\n \n\n* * *"}, {"input": "2", "output": "aa\n ab"}] |
Assume that there are K strings of length N that are in normal form: w_1,
\ldots, w_K in lexicographical order. Output should be in the following
format:
w_1
:
w_K
* * * | s156109662 | Accepted | p02744 | Input is given from Standard Input in the following format:
N | n = int(input())
ans = []
def rec(i, s):
if i == n:
ans.append(s)
return True
else:
if len(set(s)) == 1:
rec(i + 1, s + "a")
rec(i + 1, s + "b")
if len(set(s)) == 2:
rec(i + 1, s + "a")
rec(i + 1, s + "b")
rec(i + 1, s + "c")
if len(set(s)) == 3:
rec(i + 1, s + "a")
rec(i + 1, s + "b")
rec(i + 1, s + "c")
rec(i + 1, s + "d")
if len(set(s)) == 4:
rec(i + 1, s + "a")
rec(i + 1, s + "b")
rec(i + 1, s + "c")
rec(i + 1, s + "d")
rec(i + 1, s + "e")
if len(set(s)) == 5:
rec(i + 1, s + "a")
rec(i + 1, s + "b")
rec(i + 1, s + "c")
rec(i + 1, s + "d")
rec(i + 1, s + "e")
rec(i + 1, s + "f")
if len(set(s)) == 6:
rec(i + 1, s + "a")
rec(i + 1, s + "b")
rec(i + 1, s + "c")
rec(i + 1, s + "d")
rec(i + 1, s + "e")
rec(i + 1, s + "f")
rec(i + 1, s + "g")
if len(set(s)) == 7:
rec(i + 1, s + "a")
rec(i + 1, s + "b")
rec(i + 1, s + "c")
rec(i + 1, s + "d")
rec(i + 1, s + "e")
rec(i + 1, s + "f")
rec(i + 1, s + "g")
rec(i + 1, s + "h")
if len(set(s)) == 8:
rec(i + 1, s + "a")
rec(i + 1, s + "b")
rec(i + 1, s + "c")
rec(i + 1, s + "d")
rec(i + 1, s + "e")
rec(i + 1, s + "f")
rec(i + 1, s + "g")
rec(i + 1, s + "h")
rec(i + 1, s + "i")
if len(set(s)) == 9:
rec(i + 1, s + "a")
rec(i + 1, s + "b")
rec(i + 1, s + "c")
rec(i + 1, s + "d")
rec(i + 1, s + "e")
rec(i + 1, s + "f")
rec(i + 1, s + "g")
rec(i + 1, s + "h")
rec(i + 1, s + "i")
rec(i + 1, s + "j")
rec(1, "a")
print("\n".join(ans))
| Statement
In this problem, we only consider strings consisting of lowercase English
letters.
Strings s and t are said to be **isomorphic** when the following conditions
are satisfied:
* |s| = |t| holds.
* For every pair i, j, one of the following holds:
* s_i = s_j and t_i = t_j.
* s_i \neq s_j and t_i \neq t_j.
For example, `abcac` and `zyxzx` are isomorphic, while `abcac` and `ppppp` are
not.
A string s is said to be in **normal form** when the following condition is
satisfied:
* For every string t that is isomorphic to s, s \leq t holds. Here \leq denotes lexicographic comparison.
For example, `abcac` is in normal form, but `zyxzx` is not since it is
isomorphic to `abcac`, which is lexicographically smaller than `zyxzx`.
You are given an integer N. Print all strings of length N that are in normal
form, in lexicographically ascending order. | [{"input": "1", "output": "a\n \n\n* * *"}, {"input": "2", "output": "aa\n ab"}] |
Assume that there are K strings of length N that are in normal form: w_1,
\ldots, w_K in lexicographical order. Output should be in the following
format:
w_1
:
w_K
* * * | s390937718 | Wrong Answer | p02744 | Input is given from Standard Input in the following format:
N | N = int(input().rstrip())
zumi = []
for i in range(1, N + 1):
ret = "a" * i + "b" * (N - i)
# print(f'origin: {ret}')
for j in range(i, N + 1):
# print(f'1: {ret[:j-1]}, 2: {ret[j:]}')
tmp = ret[: j - 1] + "a" + ret[j:]
if tmp not in zumi:
zumi.append(tmp)
for x in sorted(zumi):
print(x)
| Statement
In this problem, we only consider strings consisting of lowercase English
letters.
Strings s and t are said to be **isomorphic** when the following conditions
are satisfied:
* |s| = |t| holds.
* For every pair i, j, one of the following holds:
* s_i = s_j and t_i = t_j.
* s_i \neq s_j and t_i \neq t_j.
For example, `abcac` and `zyxzx` are isomorphic, while `abcac` and `ppppp` are
not.
A string s is said to be in **normal form** when the following condition is
satisfied:
* For every string t that is isomorphic to s, s \leq t holds. Here \leq denotes lexicographic comparison.
For example, `abcac` is in normal form, but `zyxzx` is not since it is
isomorphic to `abcac`, which is lexicographically smaller than `zyxzx`.
You are given an integer N. Print all strings of length N that are in normal
form, in lexicographically ascending order. | [{"input": "1", "output": "a\n \n\n* * *"}, {"input": "2", "output": "aa\n ab"}] |
Assume that there are K strings of length N that are in normal form: w_1,
\ldots, w_K in lexicographical order. Output should be in the following
format:
w_1
:
w_K
* * * | s354091120 | Wrong Answer | p02744 | Input is given from Standard Input in the following format:
N | S = "abcdefghijklmnop"
def main():
N = int(input())
if N == 1:
for i in range(1):
print(S[i])
elif N == 2:
for i in range(1):
for j in range(i + 2):
print(S[i] + S[j])
elif N == 3:
for i in range(1):
for j in range(i + 2):
for k in range(j + 2):
print(S[i] + S[j] + S[k])
elif N == 4:
for i in range(1):
for j in range(i + 2):
for k in range(j + 2):
for l in range(k + 2):
print(S[i] + S[j] + S[k] + S[l])
elif N == 5:
for i in range(1):
for j in range(i + 2):
for k in range(j + 2):
for l in range(k + 2):
for m in range(l + 2):
print(S[i] + S[j] + S[k] + S[l] + S[m])
elif N == 6:
for i in range(1):
for j in range(i + 2):
for k in range(j + 2):
for l in range(k + 2):
for m in range(l + 2):
for n in range(m + 2):
print(S[i] + S[j] + S[k] + S[l] + S[m] + S[n])
elif N == 7:
for i in range(1):
for j in range(i + 2):
for k in range(j + 2):
for l in range(k + 2):
for m in range(l + 2):
for n in range(m + 2):
for o in range(n + 2):
print(
S[i] + S[j] + S[k] + S[l] + S[m] + S[n] + S[o]
)
elif N == 8:
for i in range(1):
for j in range(i + 2):
for k in range(j + 2):
for l in range(k + 2):
for m in range(l + 2):
for n in range(m + 2):
for o in range(n + 2):
for p in range(o + 2):
print(
S[i]
+ S[j]
+ S[k]
+ S[l]
+ S[m]
+ S[n]
+ S[o]
+ S[p]
)
elif N == 9:
for i in range(1):
for j in range(i + 2):
for k in range(j + 2):
for l in range(k + 2):
for m in range(l + 2):
for n in range(m + 2):
for o in range(n + 2):
for p in range(o + 2):
for q in range(p + 2):
print(
S[i]
+ S[j]
+ S[k]
+ S[l]
+ S[m]
+ S[n]
+ S[o]
+ S[p]
+ S[q]
)
elif N == 10:
for i in range(1):
for j in range(i + 2):
for k in range(j + 2):
for l in range(k + 2):
for m in range(l + 2):
for n in range(m + 2):
for o in range(n + 2):
for p in range(o + 2):
for q in range(p + 2):
for r in range(q + 2):
print(
S[i]
+ S[j]
+ S[k]
+ S[l]
+ S[m]
+ S[n]
+ S[o]
+ S[p]
+ S[q]
+ S[r]
)
main()
| Statement
In this problem, we only consider strings consisting of lowercase English
letters.
Strings s and t are said to be **isomorphic** when the following conditions
are satisfied:
* |s| = |t| holds.
* For every pair i, j, one of the following holds:
* s_i = s_j and t_i = t_j.
* s_i \neq s_j and t_i \neq t_j.
For example, `abcac` and `zyxzx` are isomorphic, while `abcac` and `ppppp` are
not.
A string s is said to be in **normal form** when the following condition is
satisfied:
* For every string t that is isomorphic to s, s \leq t holds. Here \leq denotes lexicographic comparison.
For example, `abcac` is in normal form, but `zyxzx` is not since it is
isomorphic to `abcac`, which is lexicographically smaller than `zyxzx`.
You are given an integer N. Print all strings of length N that are in normal
form, in lexicographically ascending order. | [{"input": "1", "output": "a\n \n\n* * *"}, {"input": "2", "output": "aa\n ab"}] |
Assume that there are K strings of length N that are in normal form: w_1,
\ldots, w_K in lexicographical order. Output should be in the following
format:
w_1
:
w_K
* * * | s130541760 | Wrong Answer | p02744 | Input is given from Standard Input in the following format:
N | import glob
# 問題ごとのディレクトリのトップからの相対パス
REL_PATH = "ABC\\159\\D"
# テスト用ファイル置き場のトップ
TOP_PATH = "C:\\AtCoder"
class Common:
problem = []
index = 0
def __init__(self, rel_path):
self.rel_path = rel_path
def initialize(self, path):
file = open(path)
self.problem = file.readlines()
self.index = 0
return
def input_data(self):
try:
IS_TEST
self.index += 1
return self.problem[self.index - 1]
except NameError:
return input()
def resolve(self):
pass
def exec_resolve(self):
try:
IS_TEST
for path in glob.glob(TOP_PATH + "\\" + self.rel_path + "/*.txt"):
print("Test: " + path)
self.initialize(path)
self.resolve()
print("\n\n")
except NameError:
self.resolve()
class Solver(Common):
alph = []
def rec(self, result, now, N):
if now == N:
res = ""
for i in result:
res += self.alph[i]
print(res)
return
if now == 0:
result[0] = 0
self.rec(result, now + 1, N)
return
if result[now - 1] == 25:
result[now] = 25
self.rec(result, now + 1, N)
return
for i in range(result[now - 1], result[now - 1] + 2):
result[now] = i
self.rec(result, now + 1, N)
def resolve(self):
N = int(self.input_data())
self.alph = "a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t,u,v,w,x,y,z".split(",")
self.result = [0 for i in range(N)]
self.rec(self.result, 0, N)
solver = Solver(REL_PATH)
solver.exec_resolve()
| Statement
In this problem, we only consider strings consisting of lowercase English
letters.
Strings s and t are said to be **isomorphic** when the following conditions
are satisfied:
* |s| = |t| holds.
* For every pair i, j, one of the following holds:
* s_i = s_j and t_i = t_j.
* s_i \neq s_j and t_i \neq t_j.
For example, `abcac` and `zyxzx` are isomorphic, while `abcac` and `ppppp` are
not.
A string s is said to be in **normal form** when the following condition is
satisfied:
* For every string t that is isomorphic to s, s \leq t holds. Here \leq denotes lexicographic comparison.
For example, `abcac` is in normal form, but `zyxzx` is not since it is
isomorphic to `abcac`, which is lexicographically smaller than `zyxzx`.
You are given an integer N. Print all strings of length N that are in normal
form, in lexicographically ascending order. | [{"input": "1", "output": "a\n \n\n* * *"}, {"input": "2", "output": "aa\n ab"}] |
Assume that there are K strings of length N that are in normal form: w_1,
\ldots, w_K in lexicographical order. Output should be in the following
format:
w_1
:
w_K
* * * | s080361556 | Accepted | p02744 | Input is given from Standard Input in the following format:
N | nag = int(input())
def dfs(rootlist, deep, n):
global nag
if len(rootlist) != nag:
for i in range(n + 1):
nextroot = rootlist[:]
nextroot.append(i)
if i < n:
dfs(nextroot, deep + 1, n)
else:
dfs(nextroot, deep + 1, n + 1)
else:
answer = ""
wordlist = ["a", "b", "c", "d", "e", "f", "g", "h", "i", "j"]
for index in rootlist:
answer += wordlist[index]
print(answer)
dfs([0], 0, 1)
| Statement
In this problem, we only consider strings consisting of lowercase English
letters.
Strings s and t are said to be **isomorphic** when the following conditions
are satisfied:
* |s| = |t| holds.
* For every pair i, j, one of the following holds:
* s_i = s_j and t_i = t_j.
* s_i \neq s_j and t_i \neq t_j.
For example, `abcac` and `zyxzx` are isomorphic, while `abcac` and `ppppp` are
not.
A string s is said to be in **normal form** when the following condition is
satisfied:
* For every string t that is isomorphic to s, s \leq t holds. Here \leq denotes lexicographic comparison.
For example, `abcac` is in normal form, but `zyxzx` is not since it is
isomorphic to `abcac`, which is lexicographically smaller than `zyxzx`.
You are given an integer N. Print all strings of length N that are in normal
form, in lexicographically ascending order. | [{"input": "1", "output": "a\n \n\n* * *"}, {"input": "2", "output": "aa\n ab"}] |
Assume that there are K strings of length N that are in normal form: w_1,
\ldots, w_K in lexicographical order. Output should be in the following
format:
w_1
:
w_K
* * * | s769315441 | Wrong Answer | p02744 | Input is given from Standard Input in the following format:
N | alp = ["a", "b", "c", "d", "e", "f", "g", "h", "i", "j"]
N = int(input())
ans_list = []
for i in range(N):
ans_list.append([])
for i in range(N):
if i == 0:
ans_list[0].append("a")
else:
for j in range(len(ans_list[i - 1])):
if ans_list[i - 1][j][-1] == "a":
for l in range(2):
temp = ans_list[i - 1][j] + alp[l]
ans_list[i].append(temp)
elif ans_list[i - 1][j][-1] == "b":
for l in range(3):
temp = ans_list[i - 1][j] + alp[l]
ans_list[i].append(temp)
elif ans_list[i - 1][j][-1] == "c":
for l in range(4):
temp = ans_list[i - 1][j] + alp[l]
ans_list[i].append(temp)
elif ans_list[i - 1][j][-1] == "d":
for l in range(5):
temp = ans_list[i - 1][j] + alp[l]
ans_list[i].append(temp)
elif ans_list[i - 1][j][-1] == "e":
for l in range(6):
temp = ans_list[i - 1][j] + alp[l]
ans_list[i].append(temp)
elif ans_list[i - 1][j][-1] == "f":
for l in range(7):
temp = ans_list[i - 1][j] + alp[l]
ans_list[i].append(temp)
elif ans_list[i - 1][j][-1] == "g":
for l in range(8):
temp = ans_list[i - 1][j] + alp[l]
ans_list[i].append(temp)
elif ans_list[i - 1][j][-1] == "h":
for l in range(9):
temp = ans_list[i - 1][j] + alp[l]
ans_list[i].append(temp)
elif ans_list[i - 1][j][-1] == "i":
for l in range(10):
temp = ans_list[i - 1][j] + alp[l]
ans_list[i].append(temp)
ans_list[N - 1].sort()
for i in range(len(ans_list[N - 1])):
print(ans_list[N - 1][i])
| Statement
In this problem, we only consider strings consisting of lowercase English
letters.
Strings s and t are said to be **isomorphic** when the following conditions
are satisfied:
* |s| = |t| holds.
* For every pair i, j, one of the following holds:
* s_i = s_j and t_i = t_j.
* s_i \neq s_j and t_i \neq t_j.
For example, `abcac` and `zyxzx` are isomorphic, while `abcac` and `ppppp` are
not.
A string s is said to be in **normal form** when the following condition is
satisfied:
* For every string t that is isomorphic to s, s \leq t holds. Here \leq denotes lexicographic comparison.
For example, `abcac` is in normal form, but `zyxzx` is not since it is
isomorphic to `abcac`, which is lexicographically smaller than `zyxzx`.
You are given an integer N. Print all strings of length N that are in normal
form, in lexicographically ascending order. | [{"input": "1", "output": "a\n \n\n* * *"}, {"input": "2", "output": "aa\n ab"}] |
Assume that there are K strings of length N that are in normal form: w_1,
\ldots, w_K in lexicographical order. Output should be in the following
format:
w_1
:
w_K
* * * | s190823373 | Wrong Answer | p02744 | Input is given from Standard Input in the following format:
N | # a,b,c = [int(x) for x in input().split()]
n = int(input())
l = [0] * n
ans = ""
al = ["a", "b", "c", "d", "e", "f", "g", "h", "i", "j"]
if n == 1:
print("a")
elif n == 2:
for x in range(2):
l[1] = x
for i in range(n):
for k in range(n):
if l[i] == k:
ans = ans + al[k]
print(ans)
ans = ""
elif n == 3:
for x in range(2):
l[1] = x
for a in range(l[1] + 2):
l[2] = a
for i in range(n):
for k in range(n):
if l[i] == k:
ans = ans + al[k]
print(ans)
ans = ""
elif n == 4:
for x in range(2):
l[1] = x
for a in range(l[1] + 2):
l[2] = a
for b in range(l[2] + 2):
l[3] = b
for i in range(n):
for k in range(n):
if l[i] == k:
ans = ans + al[k]
print(ans)
ans = ""
elif n == 5:
for x in range(2):
l[1] = x
for a in range(l[1] + 2):
l[2] = a
for b in range(l[2] + 2):
l[3] = b
for c in range(l[3] + 2):
l[4] = c
for i in range(n):
for k in range(n):
if l[i] == k:
ans = ans + al[k]
print(ans)
ans = ""
elif n == 6:
for x in range(2):
l[1] = x
for a in range(l[1] + 2):
l[2] = a
for b in range(l[2] + 2):
l[3] = b
for c in range(l[3] + 2):
l[4] = c
for d in range(l[4] + 2):
l[5] = d
for i in range(n):
for k in range(n):
if l[i] == k:
ans = ans + al[k]
print(ans)
ans = ""
elif n == 7:
for x in range(2):
l[1] = x
for a in range(l[1] + 2):
l[2] = a
for b in range(l[2] + 2):
l[3] = b
for c in range(l[3] + 2):
l[4] = c
for d in range(l[4] + 2):
l[5] = d
for e in range(l[5] + 2):
l[6] = e
for i in range(n):
for k in range(n):
if l[i] == k:
ans = ans + al[k]
print(ans)
ans = ""
elif n == 8:
for x in range(2):
l[1] = x
for a in range(l[1] + 2):
l[2] = a
for b in range(l[2] + 2):
l[3] = b
for c in range(l[3] + 2):
l[4] = c
for d in range(l[4] + 2):
l[5] = d
for e in range(l[5] + 2):
l[6] = e
for f in range(l[6] + 2):
l[7] = f
for i in range(n):
for k in range(n):
if l[i] == k:
ans = ans + al[k]
print(ans)
ans = ""
elif n == 9:
for x in range(2):
l[1] = x
for a in range(l[1] + 2):
l[2] = a
for b in range(l[2] + 2):
l[3] = b
for c in range(l[3] + 2):
l[4] = c
for d in range(l[4] + 2):
l[5] = d
for e in range(l[5] + 2):
l[6] = e
for f in range(l[6] + 2):
l[7] = f
for g in range(l[7] + 2):
l[8] = g
for i in range(n):
for k in range(n):
if l[i] == k:
ans = ans + al[k]
print(ans)
ans = ""
elif n == 10:
for x in range(2):
l[1] = x
for a in range(l[1] + 2):
l[2] = a
for b in range(l[2] + 2):
l[3] = b
for c in range(l[3] + 2):
l[4] = c
for d in range(l[4] + 2):
l[5] = d
for e in range(l[5] + 2):
l[6] = e
for f in range(l[6] + 2):
l[7] = f
for g in range(l[7] + 2):
l[8] = g
for h in range(l[8] + 2):
l[9] = h
for i in range(n):
for k in range(n):
if l[i] == k:
ans = ans + al[k]
print(ans)
ans = ""
| Statement
In this problem, we only consider strings consisting of lowercase English
letters.
Strings s and t are said to be **isomorphic** when the following conditions
are satisfied:
* |s| = |t| holds.
* For every pair i, j, one of the following holds:
* s_i = s_j and t_i = t_j.
* s_i \neq s_j and t_i \neq t_j.
For example, `abcac` and `zyxzx` are isomorphic, while `abcac` and `ppppp` are
not.
A string s is said to be in **normal form** when the following condition is
satisfied:
* For every string t that is isomorphic to s, s \leq t holds. Here \leq denotes lexicographic comparison.
For example, `abcac` is in normal form, but `zyxzx` is not since it is
isomorphic to `abcac`, which is lexicographically smaller than `zyxzx`.
You are given an integer N. Print all strings of length N that are in normal
form, in lexicographically ascending order. | [{"input": "1", "output": "a\n \n\n* * *"}, {"input": "2", "output": "aa\n ab"}] |
Assume that there are K strings of length N that are in normal form: w_1,
\ldots, w_K in lexicographical order. Output should be in the following
format:
w_1
:
w_K
* * * | s217309901 | Accepted | p02744 | Input is given from Standard Input in the following format:
N | k = ("a",)
for _ in range(int(input()) - 1):
k = {a + b for a in k for b in a + chr(ord(max(a)) + 1)}
print(*sorted(k), sep="\n")
| Statement
In this problem, we only consider strings consisting of lowercase English
letters.
Strings s and t are said to be **isomorphic** when the following conditions
are satisfied:
* |s| = |t| holds.
* For every pair i, j, one of the following holds:
* s_i = s_j and t_i = t_j.
* s_i \neq s_j and t_i \neq t_j.
For example, `abcac` and `zyxzx` are isomorphic, while `abcac` and `ppppp` are
not.
A string s is said to be in **normal form** when the following condition is
satisfied:
* For every string t that is isomorphic to s, s \leq t holds. Here \leq denotes lexicographic comparison.
For example, `abcac` is in normal form, but `zyxzx` is not since it is
isomorphic to `abcac`, which is lexicographically smaller than `zyxzx`.
You are given an integer N. Print all strings of length N that are in normal
form, in lexicographically ascending order. | [{"input": "1", "output": "a\n \n\n* * *"}, {"input": "2", "output": "aa\n ab"}] |
Assume that there are K strings of length N that are in normal form: w_1,
\ldots, w_K in lexicographical order. Output should be in the following
format:
w_1
:
w_K
* * * | s109281704 | Wrong Answer | p02744 | Input is given from Standard Input in the following format:
N | n = int(input())
L = [["a", "a"]]
for i in range(1, n):
new = []
for j in range(len(L)):
temp = L[j][1]
cur = ord(L[j][0]) - 96
for k in range(cur + 1):
ap = temp + chr(97 + k)
if chr(97 + k) < L[j][0]:
new.append([L[j][0], ap])
else:
new.append([chr(97 + k), ap])
L = new
L.sort()
for i in range(len(L)):
print(L[i][1])
| Statement
In this problem, we only consider strings consisting of lowercase English
letters.
Strings s and t are said to be **isomorphic** when the following conditions
are satisfied:
* |s| = |t| holds.
* For every pair i, j, one of the following holds:
* s_i = s_j and t_i = t_j.
* s_i \neq s_j and t_i \neq t_j.
For example, `abcac` and `zyxzx` are isomorphic, while `abcac` and `ppppp` are
not.
A string s is said to be in **normal form** when the following condition is
satisfied:
* For every string t that is isomorphic to s, s \leq t holds. Here \leq denotes lexicographic comparison.
For example, `abcac` is in normal form, but `zyxzx` is not since it is
isomorphic to `abcac`, which is lexicographically smaller than `zyxzx`.
You are given an integer N. Print all strings of length N that are in normal
form, in lexicographically ascending order. | [{"input": "1", "output": "a\n \n\n* * *"}, {"input": "2", "output": "aa\n ab"}] |
Assume that there are K strings of length N that are in normal form: w_1,
\ldots, w_K in lexicographical order. Output should be in the following
format:
w_1
:
w_K
* * * | s205338425 | Accepted | p02744 | Input is given from Standard Input in the following format:
N | n = int(input())
a = "abcdefghij"
ans = [[""]]
for i in range(n):
s = ans[-1][::]
l = len(s)
t = []
for j in range(i + 1):
for k in range(l):
if j > 0:
if a[j - 1] not in s[k]:
continue
t.append(s[k] + a[j])
ans.append(t)
t = sorted(ans[-1])
for s in t:
print(s)
| Statement
In this problem, we only consider strings consisting of lowercase English
letters.
Strings s and t are said to be **isomorphic** when the following conditions
are satisfied:
* |s| = |t| holds.
* For every pair i, j, one of the following holds:
* s_i = s_j and t_i = t_j.
* s_i \neq s_j and t_i \neq t_j.
For example, `abcac` and `zyxzx` are isomorphic, while `abcac` and `ppppp` are
not.
A string s is said to be in **normal form** when the following condition is
satisfied:
* For every string t that is isomorphic to s, s \leq t holds. Here \leq denotes lexicographic comparison.
For example, `abcac` is in normal form, but `zyxzx` is not since it is
isomorphic to `abcac`, which is lexicographically smaller than `zyxzx`.
You are given an integer N. Print all strings of length N that are in normal
form, in lexicographically ascending order. | [{"input": "1", "output": "a\n \n\n* * *"}, {"input": "2", "output": "aa\n ab"}] |
Assume that there are K strings of length N that are in normal form: w_1,
\ldots, w_K in lexicographical order. Output should be in the following
format:
w_1
:
w_K
* * * | s157382638 | Runtime Error | p02744 | Input is given from Standard Input in the following format:
N | from collections import deque
N = int(input())
queue = deque()
queue.append((0,)
while queue:
s = queue.popleft()
if len(s) == N:
print(''.join('abcdefghij'[i] for i in s))
continue
for i in range(max(s) + 2):
queue.append(s + (i,)) | Statement
In this problem, we only consider strings consisting of lowercase English
letters.
Strings s and t are said to be **isomorphic** when the following conditions
are satisfied:
* |s| = |t| holds.
* For every pair i, j, one of the following holds:
* s_i = s_j and t_i = t_j.
* s_i \neq s_j and t_i \neq t_j.
For example, `abcac` and `zyxzx` are isomorphic, while `abcac` and `ppppp` are
not.
A string s is said to be in **normal form** when the following condition is
satisfied:
* For every string t that is isomorphic to s, s \leq t holds. Here \leq denotes lexicographic comparison.
For example, `abcac` is in normal form, but `zyxzx` is not since it is
isomorphic to `abcac`, which is lexicographically smaller than `zyxzx`.
You are given an integer N. Print all strings of length N that are in normal
form, in lexicographically ascending order. | [{"input": "1", "output": "a\n \n\n* * *"}, {"input": "2", "output": "aa\n ab"}] |
Assume that there are K strings of length N that are in normal form: w_1,
\ldots, w_K in lexicographical order. Output should be in the following
format:
w_1
:
w_K
* * * | s515929468 | Accepted | p02744 | Input is given from Standard Input in the following format:
N | N = int(input())
if N == 1:
for i0 in range(1):
print(chr(i0 + 97), sep="")
if N == 2:
for i0 in range(1):
for i1 in range(i0 + 2):
print(chr(i0 + 97), chr(i1 + 97), sep="")
if N == 3:
for i0 in range(1):
for i1 in range(i0 + 2):
for i2 in range(max(i0, i1) + 2):
print(chr(i0 + 97), chr(i1 + 97), chr(i2 + 97), sep="")
if N == 4:
for i0 in range(1):
for i1 in range(i0 + 2):
for i2 in range(max(i0, i1) + 2):
for i3 in range(max(i0, i1, i2) + 2):
print(
chr(i0 + 97), chr(i1 + 97), chr(i2 + 97), chr(i3 + 97), sep=""
)
if N == 5:
for i0 in range(1):
for i1 in range(i0 + 2):
for i2 in range(max(i0, i1) + 2):
for i3 in range(max(i0, i1, i2) + 2):
for i4 in range(max(i0, i1, i2, i3) + 2):
print(
chr(i0 + 97),
chr(i1 + 97),
chr(i2 + 97),
chr(i3 + 97),
chr(i4 + 97),
sep="",
)
if N == 6:
for i0 in range(1):
for i1 in range(i0 + 2):
for i2 in range(max(i0, i1) + 2):
for i3 in range(max(i0, i1, i2) + 2):
for i4 in range(max(i0, i1, i2, i3) + 2):
for i5 in range(max(i0, i1, i2, i3, i4) + 2):
print(
chr(i0 + 97),
chr(i1 + 97),
chr(i2 + 97),
chr(i3 + 97),
chr(i4 + 97),
chr(i5 + 97),
sep="",
)
if N == 7:
for i0 in range(1):
for i1 in range(i0 + 2):
for i2 in range(max(i0, i1) + 2):
for i3 in range(max(i0, i1, i2) + 2):
for i4 in range(max(i0, i1, i2, i3) + 2):
for i5 in range(max(i0, i1, i2, i3, i4) + 2):
for i6 in range(max(i0, i1, i2, i3, i4, i5) + 2):
print(
chr(i0 + 97),
chr(i1 + 97),
chr(i2 + 97),
chr(i3 + 97),
chr(i4 + 97),
chr(i5 + 97),
chr(i6 + 97),
sep="",
)
if N == 8:
for i0 in range(1):
for i1 in range(i0 + 2):
for i2 in range(max(i0, i1) + 2):
for i3 in range(max(i0, i1, i2) + 2):
for i4 in range(max(i0, i1, i2, i3) + 2):
for i5 in range(max(i0, i1, i2, i3, i4) + 2):
for i6 in range(max(i0, i1, i2, i3, i4, i5) + 2):
for i7 in range(max(i0, i1, i2, i3, i4, i5, i6) + 2):
print(
chr(i0 + 97),
chr(i1 + 97),
chr(i2 + 97),
chr(i3 + 97),
chr(i4 + 97),
chr(i5 + 97),
chr(i6 + 97),
chr(i7 + 97),
sep="",
)
if N == 9:
for i0 in range(1):
for i1 in range(i0 + 2):
for i2 in range(max(i0, i1) + 2):
for i3 in range(max(i0, i1, i2) + 2):
for i4 in range(max(i0, i1, i2, i3) + 2):
for i5 in range(max(i0, i1, i2, i3, i4) + 2):
for i6 in range(max(i0, i1, i2, i3, i4, i5) + 2):
for i7 in range(max(i0, i1, i2, i3, i4, i5, i6) + 2):
for i8 in range(
max(i0, i1, i2, i3, i4, i5, i6, i7) + 2
):
print(
chr(i0 + 97),
chr(i1 + 97),
chr(i2 + 97),
chr(i3 + 97),
chr(i4 + 97),
chr(i5 + 97),
chr(i6 + 97),
chr(i7 + 97),
chr(i8 + 97),
sep="",
)
if N == 10:
for i0 in range(1):
for i1 in range(i0 + 2):
for i2 in range(max(i0, i1) + 2):
for i3 in range(max(i0, i1, i2) + 2):
for i4 in range(max(i0, i1, i2, i3) + 2):
for i5 in range(max(i0, i1, i2, i3, i4) + 2):
for i6 in range(max(i0, i1, i2, i3, i4, i5) + 2):
for i7 in range(max(i0, i1, i2, i3, i4, i5, i6) + 2):
for i8 in range(
max(i0, i1, i2, i3, i4, i5, i6, i7) + 2
):
for i9 in range(
max(i0, i1, i2, i3, i4, i5, i6, i7, i8) + 2
):
print(
chr(i0 + 97),
chr(i1 + 97),
chr(i2 + 97),
chr(i3 + 97),
chr(i4 + 97),
chr(i5 + 97),
chr(i6 + 97),
chr(i7 + 97),
chr(i8 + 97),
chr(i9 + 97),
sep="",
)
| Statement
In this problem, we only consider strings consisting of lowercase English
letters.
Strings s and t are said to be **isomorphic** when the following conditions
are satisfied:
* |s| = |t| holds.
* For every pair i, j, one of the following holds:
* s_i = s_j and t_i = t_j.
* s_i \neq s_j and t_i \neq t_j.
For example, `abcac` and `zyxzx` are isomorphic, while `abcac` and `ppppp` are
not.
A string s is said to be in **normal form** when the following condition is
satisfied:
* For every string t that is isomorphic to s, s \leq t holds. Here \leq denotes lexicographic comparison.
For example, `abcac` is in normal form, but `zyxzx` is not since it is
isomorphic to `abcac`, which is lexicographically smaller than `zyxzx`.
You are given an integer N. Print all strings of length N that are in normal
form, in lexicographically ascending order. | [{"input": "1", "output": "a\n \n\n* * *"}, {"input": "2", "output": "aa\n ab"}] |
Assume that there are K strings of length N that are in normal form: w_1,
\ldots, w_K in lexicographical order. Output should be in the following
format:
w_1
:
w_K
* * * | s491834137 | Wrong Answer | p02744 | Input is given from Standard Input in the following format:
N | # coding:utf-8
n = int(input()) # 1 <= n <= 10
lis = [0 for i in range(n)]
last = 0
now = 0
now_s = ""
a_list = ["a", "b", "c", "d", "e", "f", "g", "h", "i", "j"]
def converter(x, a, n):
# a進数からn進数への変換
t = 0
out = 0
y = -1
while not x == 0:
y = x % n
out += y * (a**t)
x = (x - y) / n
t += 1
return int(out)
for i in range(n):
last += i * (10 ** (n - i - 1))
last = converter(last, n, 10) + 1
while not now == last:
now = converter(now, 10, n)
d = now
now_s = ""
for i in range(n):
c = d // (10 ** (n - i - 1))
now_s += a_list[c]
d -= c * (10 ** (n - i - 1))
print(now_s)
now = converter(now, n, 10)
now += 1
| Statement
In this problem, we only consider strings consisting of lowercase English
letters.
Strings s and t are said to be **isomorphic** when the following conditions
are satisfied:
* |s| = |t| holds.
* For every pair i, j, one of the following holds:
* s_i = s_j and t_i = t_j.
* s_i \neq s_j and t_i \neq t_j.
For example, `abcac` and `zyxzx` are isomorphic, while `abcac` and `ppppp` are
not.
A string s is said to be in **normal form** when the following condition is
satisfied:
* For every string t that is isomorphic to s, s \leq t holds. Here \leq denotes lexicographic comparison.
For example, `abcac` is in normal form, but `zyxzx` is not since it is
isomorphic to `abcac`, which is lexicographically smaller than `zyxzx`.
You are given an integer N. Print all strings of length N that are in normal
form, in lexicographically ascending order. | [{"input": "1", "output": "a\n \n\n* * *"}, {"input": "2", "output": "aa\n ab"}] |
Assume that there are K strings of length N that are in normal form: w_1,
\ldots, w_K in lexicographical order. Output should be in the following
format:
w_1
:
w_K
* * * | s204347336 | Wrong Answer | p02744 | Input is given from Standard Input in the following format:
N | import itertools
n = int(input())
t = ord("a")
cnt = []
s = []
# print(chr(t))
for i in range(10):
k = 0
s = []
while k <= i:
s.append(chr(t + k))
k += 1
cnt.append(s)
c0 = cnt[0]
c1 = cnt[1]
c2 = cnt[2]
c3 = cnt[3]
c4 = cnt[4]
c5 = cnt[5]
c6 = cnt[6]
c7 = cnt[7]
c8 = cnt[8]
c9 = cnt[9]
if n == 1:
print("a")
if n == 2:
print("aa")
print("bb")
if n == 3:
for i, j, k in itertools.product(c0, c1, c2):
print(i + j + k)
if n == 4:
for i0, i1, i2, i3 in itertools.product(c0, c1, c2, c3):
print(i0 + i1 + i2 + i3)
if n == 5:
for i0, i1, i2, i3, i4 in itertools.product(c0, c1, c2, c3, c4):
print(i0 + i1 + i2 + i3 + i4)
if n == 6:
for i0, i1, i2, i3, i4, i5 in itertools.product(c0, c1, c2, c3, c4, c5):
print(i0 + i1 + i2 + i3 + i4 + i5)
if n == 7:
for i0, i1, i2, i3, i4, i5, i6 in itertools.product(c0, c1, c2, c3, c4, c5, c6):
print(i0 + i1 + i2 + i3 + i4 + i5 + i6)
if n == 8:
for i0, i1, i2, i3, i4, i5, i6, i7 in itertools.product(
c0, c1, c2, c3, c4, c5, c6, c7
):
print(i0 + i1 + i2 + i3 + i4 + i5 + i6 + i7)
if n == 9:
for i0, i1, i2, i3, i4, i5, i6, i7, i8 in itertools.product(
c0, c1, c2, c3, c4, c5, c6, c7, c8
):
print(i0 + i1 + i2 + i3 + i4 + i5 + i5 + i7 + i8)
if n == 10:
for i0, i1, i2, i3, i4, i5, i6, i7, i8, i9 in itertools.product(
c0, c1, c2, c3, c4, c5, c6, c7, c8, c9
):
print(i0 + i1 + i2 + i3 + i4 + i5 + i5 + i7 + i8 + i9)
| Statement
In this problem, we only consider strings consisting of lowercase English
letters.
Strings s and t are said to be **isomorphic** when the following conditions
are satisfied:
* |s| = |t| holds.
* For every pair i, j, one of the following holds:
* s_i = s_j and t_i = t_j.
* s_i \neq s_j and t_i \neq t_j.
For example, `abcac` and `zyxzx` are isomorphic, while `abcac` and `ppppp` are
not.
A string s is said to be in **normal form** when the following condition is
satisfied:
* For every string t that is isomorphic to s, s \leq t holds. Here \leq denotes lexicographic comparison.
For example, `abcac` is in normal form, but `zyxzx` is not since it is
isomorphic to `abcac`, which is lexicographically smaller than `zyxzx`.
You are given an integer N. Print all strings of length N that are in normal
form, in lexicographically ascending order. | [{"input": "1", "output": "a\n \n\n* * *"}, {"input": "2", "output": "aa\n ab"}] |
Assume that there are K strings of length N that are in normal form: w_1,
\ldots, w_K in lexicographical order. Output should be in the following
format:
w_1
:
w_K
* * * | s163619443 | Accepted | p02744 | Input is given from Standard Input in the following format:
N | n = int(input())
c = "abcdefghijk"
d = [[0]]
for i in range(n - 1):
pd, d = d, []
for j in pd:
m = max(j)
for k in range(m + 2):
d.append(j + [k])
for i in d:
for j in i[:-1]:
print(c[j], end="")
print(c[i[-1]])
| Statement
In this problem, we only consider strings consisting of lowercase English
letters.
Strings s and t are said to be **isomorphic** when the following conditions
are satisfied:
* |s| = |t| holds.
* For every pair i, j, one of the following holds:
* s_i = s_j and t_i = t_j.
* s_i \neq s_j and t_i \neq t_j.
For example, `abcac` and `zyxzx` are isomorphic, while `abcac` and `ppppp` are
not.
A string s is said to be in **normal form** when the following condition is
satisfied:
* For every string t that is isomorphic to s, s \leq t holds. Here \leq denotes lexicographic comparison.
For example, `abcac` is in normal form, but `zyxzx` is not since it is
isomorphic to `abcac`, which is lexicographically smaller than `zyxzx`.
You are given an integer N. Print all strings of length N that are in normal
form, in lexicographically ascending order. | [{"input": "1", "output": "a\n \n\n* * *"}, {"input": "2", "output": "aa\n ab"}] |
Assume that there are K strings of length N that are in normal form: w_1,
\ldots, w_K in lexicographical order. Output should be in the following
format:
w_1
:
w_K
* * * | s978154766 | Accepted | p02744 | Input is given from Standard Input in the following format:
N | numal = lambda c: chr(c + 97)
n = int(input())
unchi = [[], [], [], [], [], [], [], [], [], []]
unchi[0].append("0")
k = 1
if n >= 2:
while k < n:
for i in range(len(unchi[k - 1])):
t = max(map(int, unchi[k - 1][i]))
for u in range(t + 2):
unchi[k].append(unchi[k - 1][i] + str(u))
k += 1
for i in range(len(unchi[n - 1])):
s = []
for k in range(n):
s.append(numal(int(unchi[n - 1][i][k])))
print("".join(s))
| Statement
In this problem, we only consider strings consisting of lowercase English
letters.
Strings s and t are said to be **isomorphic** when the following conditions
are satisfied:
* |s| = |t| holds.
* For every pair i, j, one of the following holds:
* s_i = s_j and t_i = t_j.
* s_i \neq s_j and t_i \neq t_j.
For example, `abcac` and `zyxzx` are isomorphic, while `abcac` and `ppppp` are
not.
A string s is said to be in **normal form** when the following condition is
satisfied:
* For every string t that is isomorphic to s, s \leq t holds. Here \leq denotes lexicographic comparison.
For example, `abcac` is in normal form, but `zyxzx` is not since it is
isomorphic to `abcac`, which is lexicographically smaller than `zyxzx`.
You are given an integer N. Print all strings of length N that are in normal
form, in lexicographically ascending order. | [{"input": "1", "output": "a\n \n\n* * *"}, {"input": "2", "output": "aa\n ab"}] |
Assume that there are K strings of length N that are in normal form: w_1,
\ldots, w_K in lexicographical order. Output should be in the following
format:
w_1
:
w_K
* * * | s387288888 | Accepted | p02744 | Input is given from Standard Input in the following format:
N | import numpy as np
N = int(input())
letters = "abcdefghij"
count = 0
L = [""]
while count < N:
next_L = []
for i in L:
n = len(np.unique(i))
for l in letters[: n + 1]:
next_L.append(i + l)
L = next_L
count += 1
for j in next_L:
print(j)
| Statement
In this problem, we only consider strings consisting of lowercase English
letters.
Strings s and t are said to be **isomorphic** when the following conditions
are satisfied:
* |s| = |t| holds.
* For every pair i, j, one of the following holds:
* s_i = s_j and t_i = t_j.
* s_i \neq s_j and t_i \neq t_j.
For example, `abcac` and `zyxzx` are isomorphic, while `abcac` and `ppppp` are
not.
A string s is said to be in **normal form** when the following condition is
satisfied:
* For every string t that is isomorphic to s, s \leq t holds. Here \leq denotes lexicographic comparison.
For example, `abcac` is in normal form, but `zyxzx` is not since it is
isomorphic to `abcac`, which is lexicographically smaller than `zyxzx`.
You are given an integer N. Print all strings of length N that are in normal
form, in lexicographically ascending order. | [{"input": "1", "output": "a\n \n\n* * *"}, {"input": "2", "output": "aa\n ab"}] |
Assume that there are K strings of length N that are in normal form: w_1,
\ldots, w_K in lexicographical order. Output should be in the following
format:
w_1
:
w_K
* * * | s611539949 | Runtime Error | p02744 | Input is given from Standard Input in the following format:
N | a = int(input())
b = [1] * a
c = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
d = 0
core = c[0:a]
print("a" * a)
while b != core:
b[-1] = b[-1] + 1
for i in range(10):
if b[-i - 1] - 1 > b[-i - 2]:
b[-i - 2] = b[-i - 2] + 1
b[-i - 1] = 1
else:
break
answer = ""
for j in range(a):
answer = answer + chr(b[j] + 96)
print(answer)
| Statement
In this problem, we only consider strings consisting of lowercase English
letters.
Strings s and t are said to be **isomorphic** when the following conditions
are satisfied:
* |s| = |t| holds.
* For every pair i, j, one of the following holds:
* s_i = s_j and t_i = t_j.
* s_i \neq s_j and t_i \neq t_j.
For example, `abcac` and `zyxzx` are isomorphic, while `abcac` and `ppppp` are
not.
A string s is said to be in **normal form** when the following condition is
satisfied:
* For every string t that is isomorphic to s, s \leq t holds. Here \leq denotes lexicographic comparison.
For example, `abcac` is in normal form, but `zyxzx` is not since it is
isomorphic to `abcac`, which is lexicographically smaller than `zyxzx`.
You are given an integer N. Print all strings of length N that are in normal
form, in lexicographically ascending order. | [{"input": "1", "output": "a\n \n\n* * *"}, {"input": "2", "output": "aa\n ab"}] |
Print the shortest time needed to produce at least N cookies not yet eaten.
* * * | s838897196 | Accepted | p03913 | The input is given from Standard Input in the following format:
N A | import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
N, A = map(int, read().split())
"""
最適解の構造を観察する。
・最後のトドメ以外に関しては、「コストn+A払って倍率をn倍する」
・nとして現れるのは2種まで
・結局、nをx回、n+1をy回という形で、パラメータn,x,yで書ける(x\geq 1とする)
・最終枚数は、n^x(n+1)^y、これがN以上になって欲しい
・コストは、A(x+y-1) + nx + (n+1)y
・x+yを固定するごとに解く
"""
def F(K):
# x+y = K
# n^K <= N < (n+1)^K
n = int(N ** (1 / K))
while (n - 1) * n ** (K - 1) > N:
n -= 1
while n * (n + 1) ** (K - 1) < N:
n += 1
# n^x(n+1)^y >= N, yを最小にとる。面倒なので全探索
for y in range(K):
x = K - y
if n**x * (n + 1) ** y >= N:
break
cost = A * (K - 1) + n * x + (n + 1) * y
return cost
answer = min(F(K) for K in range(1, 50))
print(answer)
| Statement
Rng is baking cookies.
Initially, he can bake one cookie per second.
He can also eat the cookies baked by himself. When there are x cookies not yet
eaten, he can choose to eat all those cookies. After he finishes eating those
cookies, the number of cookies he can bake per second becomes x. Note that a
cookie always needs to be baked for 1 second, that is, he cannot bake a cookie
in 1/x seconds when x > 1. When he choose to eat the cookies, he must eat all
of them; he cannot choose to eat only part of them. It takes him A seconds to
eat the cookies regardless of how many, during which no cookies can be baked.
He wants to give N cookies to Grandma. Find the shortest time needed to
produce at least N cookies not yet eaten. | [{"input": "8 1", "output": "7\n \n\nIt is possible to produce 8 cookies in 7 seconds, as follows:\n\n * After 1 second: 1 cookie is done.\n * After 2 seconds: 1 more cookie is done, totaling 2. Now, Rng starts eating those 2 cookies.\n * After 3 seconds: He finishes eating the cookies, and he can now bake 2 cookies per second.\n * After 4 seconds: 2 cookies are done.\n * After 5 seconds: 2 more cookies are done, totaling 4.\n * After 6 seconds: 2 more cookies are done, totaling 6.\n * After 7 seconds: 2 more cookies are done, totaling 8.\n\n* * *"}, {"input": "1000000000000 1000000000000", "output": "1000000000000"}] |
Print the shortest time needed to produce at least N cookies not yet eaten.
* * * | s640011246 | Runtime Error | p03913 | The input is given from Standard Input in the following format:
N A | import sys
from math import ceil
N, A = [int(i) for i in input().split()]
if N > 10**6 or A > 10**6:
print(-1)
sys.exit()
dp = [float("inf")] * (N + 1)
dp[1] = 0
for i in range(1, N // 2 + 1):
for n, j in enumerate(range(i + i, N + 1, i), start=2):
dp[j] = min(dp[j], dp[i] + n + A)
ans = min(dp[i] + ceil(N / i) for i in range(1, N // 2 + 1), default=N)
print(ans)
| Statement
Rng is baking cookies.
Initially, he can bake one cookie per second.
He can also eat the cookies baked by himself. When there are x cookies not yet
eaten, he can choose to eat all those cookies. After he finishes eating those
cookies, the number of cookies he can bake per second becomes x. Note that a
cookie always needs to be baked for 1 second, that is, he cannot bake a cookie
in 1/x seconds when x > 1. When he choose to eat the cookies, he must eat all
of them; he cannot choose to eat only part of them. It takes him A seconds to
eat the cookies regardless of how many, during which no cookies can be baked.
He wants to give N cookies to Grandma. Find the shortest time needed to
produce at least N cookies not yet eaten. | [{"input": "8 1", "output": "7\n \n\nIt is possible to produce 8 cookies in 7 seconds, as follows:\n\n * After 1 second: 1 cookie is done.\n * After 2 seconds: 1 more cookie is done, totaling 2. Now, Rng starts eating those 2 cookies.\n * After 3 seconds: He finishes eating the cookies, and he can now bake 2 cookies per second.\n * After 4 seconds: 2 cookies are done.\n * After 5 seconds: 2 more cookies are done, totaling 4.\n * After 6 seconds: 2 more cookies are done, totaling 6.\n * After 7 seconds: 2 more cookies are done, totaling 8.\n\n* * *"}, {"input": "1000000000000 1000000000000", "output": "1000000000000"}] |
Print the shortest time needed to produce at least N cookies not yet eaten.
* * * | s416600007 | Wrong Answer | p03913 | The input is given from Standard Input in the following format:
N A | def examA():
H, W = LI()
S = [LSI() for _ in range(H)]
Alpha = [chr(ord("A") + i) for i in range(26)]
for i in range(H):
for j in range(W):
if S[i][j] == "snuke":
ans = str(Alpha[j]) + str(i + 1)
print(ans)
return
def examB():
N = I()
ans = []
cur = int((N * 2 - 1) ** 0.5) + 1
ansC = (cur + 1) * cur // 2
neg = ansC - N
if neg > cur:
cur -= 1
ansC = (cur + 1) * cur // 2
neg = ansC - N
for i in range(1, cur + 1):
if i != neg:
ans.append(i)
for v in ans:
print(v)
# print(cur,neg)
return
def bfs(n, e, fordfs):
# 点の数、スタートの点、有向グラフ
que = deque()
que.append(e)
len = [10**9] * n
len[e] = 0
while que:
now = que.popleft()
nowlen = len[now]
for ne in fordfs[now]:
if len[ne] == 10**9:
len[ne] = nowlen + 1
que.append(ne)
return len
def examC():
N, M = LI()
V = [[] for _ in range(N + M)]
for i in range(N):
L = LI()
for k in range(1, L[0] + 1):
V[i].append(L[k] + N - 1)
V[L[k] + N - 1].append(i)
length = bfs(N + M, 0, V)
ans = "YES"
for i in length[:N]:
if i == 10**9:
ans = "NO"
print(ans)
return
def examD():
N, M = LI()
X = LI()
maxX = max(X) + 1
dx = defaultdict(int)
dm = [set() for _ in range(M)]
d = defaultdict(int)
for x in X:
dx[x] += 1
d[x % M] += 1
dm[x % M].add(x)
ans = 0
# print(d); print(dx); print(dm)
ans += d[0] // 2
d[0] = 0
for i in range(1, 1 + M // 2):
cur = min(d[i], d[M - i])
ans += cur
d[i] -= cur
d[M - i] -= cur
# print(ans); print(d)
for i in d.keys():
for j in dm[i]:
cur = min(dx[j] // 2, d[i] // 2)
d[i] -= cur * 2
ans += cur
if d[i] <= 1:
break
print(ans)
return
def caneat(x, A, n):
cur = n - A * x
l = cur // (x + 1)
r = cur % (x + 1)
if l == 0:
return 1
now = pow(l, (x - r + 1)) * pow((l + 1), r)
return now
def ternarySearch(A, n, e):
# 何回喰うか
fr, to = 0, e
while to - fr > 2:
x1, x2 = (2 * fr + to) // 3, (2 * to + fr) // 3
f1, f2 = caneat(x1, A, n), caneat(x2, A, n)
if f1 > f2:
to = x2
elif f1 < f2:
fr = x1
else:
fr, to = x1, x2
return max(caneat(fr, A, n), caneat(fr + 1, A, n), caneat(to, A, n))
def examE():
N, A = LI()
l = 0
r = N + 1
while r - l > 1:
now = (l + r) // 2
maxE = now // (A + 1)
cur = ternarySearch(A, now, maxE)
if N <= cur:
r = now
else:
l = now
# print(l,r,cur)
# print(l,r)
if A >= N // 2:
ans = N
else:
ans = r
print(ans)
return
import sys, copy, bisect, itertools, heapq, math
from heapq import heappop, heappush, heapify
from collections import Counter, defaultdict, deque
def I():
return int(sys.stdin.readline())
def LI():
return list(map(int, sys.stdin.readline().split()))
def LSI():
return list(map(str, sys.stdin.readline().split()))
def LS():
return sys.stdin.readline().split()
def SI():
return sys.stdin.readline().strip()
mod = 10**9 + 7
inf = float("inf")
if __name__ == "__main__":
examE()
| Statement
Rng is baking cookies.
Initially, he can bake one cookie per second.
He can also eat the cookies baked by himself. When there are x cookies not yet
eaten, he can choose to eat all those cookies. After he finishes eating those
cookies, the number of cookies he can bake per second becomes x. Note that a
cookie always needs to be baked for 1 second, that is, he cannot bake a cookie
in 1/x seconds when x > 1. When he choose to eat the cookies, he must eat all
of them; he cannot choose to eat only part of them. It takes him A seconds to
eat the cookies regardless of how many, during which no cookies can be baked.
He wants to give N cookies to Grandma. Find the shortest time needed to
produce at least N cookies not yet eaten. | [{"input": "8 1", "output": "7\n \n\nIt is possible to produce 8 cookies in 7 seconds, as follows:\n\n * After 1 second: 1 cookie is done.\n * After 2 seconds: 1 more cookie is done, totaling 2. Now, Rng starts eating those 2 cookies.\n * After 3 seconds: He finishes eating the cookies, and he can now bake 2 cookies per second.\n * After 4 seconds: 2 cookies are done.\n * After 5 seconds: 2 more cookies are done, totaling 4.\n * After 6 seconds: 2 more cookies are done, totaling 6.\n * After 7 seconds: 2 more cookies are done, totaling 8.\n\n* * *"}, {"input": "1000000000000 1000000000000", "output": "1000000000000"}] |
Print the shortest time needed to produce at least N cookies not yet eaten.
* * * | s824609751 | Wrong Answer | p03913 | The input is given from Standard Input in the following format:
N A | from math import ceil
import sys
n, a = map(int, next(sys.stdin).strip().split())
stats = [(0, 1, 2)]
time = n
while len(stats) > 0:
t, s, k = stats.pop(0)
time = min(time, t + ceil(n / s))
for d in range(k, 2 + a + 1):
stats.append((t + d + a, d * s, d))
stats = sorted((t, s, k) for t, s, k in stats if t < time)
print(time)
| Statement
Rng is baking cookies.
Initially, he can bake one cookie per second.
He can also eat the cookies baked by himself. When there are x cookies not yet
eaten, he can choose to eat all those cookies. After he finishes eating those
cookies, the number of cookies he can bake per second becomes x. Note that a
cookie always needs to be baked for 1 second, that is, he cannot bake a cookie
in 1/x seconds when x > 1. When he choose to eat the cookies, he must eat all
of them; he cannot choose to eat only part of them. It takes him A seconds to
eat the cookies regardless of how many, during which no cookies can be baked.
He wants to give N cookies to Grandma. Find the shortest time needed to
produce at least N cookies not yet eaten. | [{"input": "8 1", "output": "7\n \n\nIt is possible to produce 8 cookies in 7 seconds, as follows:\n\n * After 1 second: 1 cookie is done.\n * After 2 seconds: 1 more cookie is done, totaling 2. Now, Rng starts eating those 2 cookies.\n * After 3 seconds: He finishes eating the cookies, and he can now bake 2 cookies per second.\n * After 4 seconds: 2 cookies are done.\n * After 5 seconds: 2 more cookies are done, totaling 4.\n * After 6 seconds: 2 more cookies are done, totaling 6.\n * After 7 seconds: 2 more cookies are done, totaling 8.\n\n* * *"}, {"input": "1000000000000 1000000000000", "output": "1000000000000"}] |
If the magic can be successful, print `Yes`; otherwise, print `No`.
* * * | s423837863 | Wrong Answer | p02601 | Input is given from Standard Input in the following format:
A B C
K | r, g, b = [int(x) for x in input().split()]
ops = int(input())
m = 0
if g < r:
while g <= r:
g *= 2
m += 1
if b < g:
while b <= g:
b *= 2
m += 1
print("Yes" if m < ops else "No")
| Statement
M-kun has the following three cards:
* A red card with the integer A.
* A green card with the integer B.
* A blue card with the integer C.
He is a genius magician who can do the following operation at most K times:
* Choose one of the three cards and multiply the written integer by 2.
His magic is successful if both of the following conditions are satisfied
after the operations:
* The integer on the green card is **strictly** greater than the integer on the red card.
* The integer on the blue card is **strictly** greater than the integer on the green card.
Determine whether the magic can be successful. | [{"input": "7 2 5\n 3", "output": "Yes\n \n\nThe magic will be successful if, for example, he does the following\noperations:\n\n * First, choose the blue card. The integers on the red, green, and blue cards are now 7, 2, and 10, respectively.\n * Second, choose the green card. The integers on the red, green, and blue cards are now 7, 4, and 10, respectively.\n * Third, choose the green card. The integers on the red, green, and blue cards are now 7, 8, and 10, respectively.\n\n* * *"}, {"input": "7 4 2\n 3", "output": "No\n \n\nHe has no way to succeed in the magic with at most three operations."}] |
If the magic can be successful, print `Yes`; otherwise, print `No`.
* * * | s738775062 | Runtime Error | p02601 | Input is given from Standard Input in the following format:
A B C
K | A, B, C = int(input().split())
print(A)
| Statement
M-kun has the following three cards:
* A red card with the integer A.
* A green card with the integer B.
* A blue card with the integer C.
He is a genius magician who can do the following operation at most K times:
* Choose one of the three cards and multiply the written integer by 2.
His magic is successful if both of the following conditions are satisfied
after the operations:
* The integer on the green card is **strictly** greater than the integer on the red card.
* The integer on the blue card is **strictly** greater than the integer on the green card.
Determine whether the magic can be successful. | [{"input": "7 2 5\n 3", "output": "Yes\n \n\nThe magic will be successful if, for example, he does the following\noperations:\n\n * First, choose the blue card. The integers on the red, green, and blue cards are now 7, 2, and 10, respectively.\n * Second, choose the green card. The integers on the red, green, and blue cards are now 7, 4, and 10, respectively.\n * Third, choose the green card. The integers on the red, green, and blue cards are now 7, 8, and 10, respectively.\n\n* * *"}, {"input": "7 4 2\n 3", "output": "No\n \n\nHe has no way to succeed in the magic with at most three operations."}] |
If the magic can be successful, print `Yes`; otherwise, print `No`.
* * * | s873844488 | Accepted | p02601 | Input is given from Standard Input in the following format:
A B C
K | cards = input()
times = int(input())
card = cards.split(" ")
result = "No"
wktimes = 0
idx = 0
div = int(card[0]) / int(card[1])
while (2**idx) <= div:
idx = idx + 1
wktimes = idx
card[1] = int(card[1]) * (2**idx)
idx = 0
div = int(card[1]) / int(card[2])
while (2**idx) <= div:
idx = idx + 1
wktimes = wktimes + idx
card[2] = int(card[2]) * (2**idx)
if wktimes <= times:
result = "Yes"
print(result)
| Statement
M-kun has the following three cards:
* A red card with the integer A.
* A green card with the integer B.
* A blue card with the integer C.
He is a genius magician who can do the following operation at most K times:
* Choose one of the three cards and multiply the written integer by 2.
His magic is successful if both of the following conditions are satisfied
after the operations:
* The integer on the green card is **strictly** greater than the integer on the red card.
* The integer on the blue card is **strictly** greater than the integer on the green card.
Determine whether the magic can be successful. | [{"input": "7 2 5\n 3", "output": "Yes\n \n\nThe magic will be successful if, for example, he does the following\noperations:\n\n * First, choose the blue card. The integers on the red, green, and blue cards are now 7, 2, and 10, respectively.\n * Second, choose the green card. The integers on the red, green, and blue cards are now 7, 4, and 10, respectively.\n * Third, choose the green card. The integers on the red, green, and blue cards are now 7, 8, and 10, respectively.\n\n* * *"}, {"input": "7 4 2\n 3", "output": "No\n \n\nHe has no way to succeed in the magic with at most three operations."}] |
Print the minimum total cost required to make the forest connected, or print
`Impossible` if it is impossible.
* * * | s324834273 | Accepted | p03440 | Input is given from Standard Input in the following format:
N M
a_0 a_1 .. a_{N-1}
x_1 y_1
x_2 y_2
:
x_M y_M | from heapq import heapify, heappop, heappush
def solve():
N, M = map(int, input().split())
a = list(map(int, input().split()))
if M == N - 1:
ans = 0
elif 2 * (N - M - 1) > N:
ans = "Impossible"
else:
g2i = [[i] for i in range(N)]
i2g = list(range(N))
def merge(ia, ib):
# print(g2i, i2g, ia, ib)
if len(g2i[i2g[ia]]) < len(g2i[i2g[ib]]):
ia, ib = ib, ia
ga, gb = i2g[ia], i2g[ib]
for j in g2i[gb]:
i2g[j] = ga
g2i[ga].extend(g2i[gb])
g2i[gb] = []
for _ in range(M):
tx, ty = map(int, input().split())
merge(tx, ty)
ans = 0
need = 2 * (N - M - 1)
rest = []
for gi in range(len(g2i)):
t = []
for i in g2i[gi]:
t.append(a[i])
if not t:
continue
heapify(t)
ans += heappop(t)
need -= 1
rest += t
ans += sum(sorted(rest)[:need])
print(ans)
if __name__ == "__main__":
solve()
| Statement
You are given a forest with N vertices and M edges. The vertices are numbered
0 through N-1. The edges are given in the format (x_i,y_i), which means that
Vertex x_i and y_i are connected by an edge.
Each vertex i has a value a_i. You want to add edges in the given forest so
that the forest becomes connected. To add an edge, you choose two different
vertices i and j, then span an edge between i and j. This operation costs a_i
+ a_j dollars, and afterward neither Vertex i nor j can be selected again.
Find the minimum total cost required to make the forest connected, or print
`Impossible` if it is impossible. | [{"input": "7 5\n 1 2 3 4 5 6 7\n 3 0\n 4 0\n 1 2\n 1 3\n 5 6", "output": "7\n \n\nIf we connect vertices 0 and 5, the graph becomes connected, for the cost of 1\n+ 6 = 7 dollars.\n\n* * *"}, {"input": "5 0\n 3 1 4 1 5", "output": "Impossible\n \n\nWe can't make the graph connected.\n\n* * *"}, {"input": "1 0\n 5", "output": "0\n \n\nThe graph is already connected, so we do not need to add any edges."}] |
Print the minimum total cost required to make the forest connected, or print
`Impossible` if it is impossible.
* * * | s670402495 | Wrong Answer | p03440 | Input is given from Standard Input in the following format:
N M
a_0 a_1 .. a_{N-1}
x_1 y_1
x_2 y_2
:
x_M y_M | n, m = map(int, input().split())
k = n - m
we = list(map(int, input().split()))
pre = [i for i in range(n)]
for _ in range(m):
a, b = map(int, input().split())
while a != pre[a]:
a = pre[a]
while b != pre[b]:
b = pre[b]
if a != b:
pre[b] = a
# print(pre)
root = []
for i in range(n):
I = int(i)
while I != pre[I]:
I = pre[I]
root.append(I)
# print(root)
rel = [-1 for _ in range(n)]
cnt = 0
for i in range(n):
if root[i] == i:
rel[i] = cnt
cnt += 1
# print(rel)
trees = [[] for _ in range(k)]
for i in range(n):
trees[rel[root[i]]].append([we[i], i])
# print(trees)
import heapq
now = trees[0]
heapq.heapify(now)
ans = 0
for j in range(1, k):
if not now:
print("Impossible")
exit()
w0, i0 = heapq.heappop(now)
w1, i1 = min(trees[j])
ans += w0 + w1
for x in trees[j]:
if x[1] != i1:
heapq.heappush(now, x)
print(ans)
| Statement
You are given a forest with N vertices and M edges. The vertices are numbered
0 through N-1. The edges are given in the format (x_i,y_i), which means that
Vertex x_i and y_i are connected by an edge.
Each vertex i has a value a_i. You want to add edges in the given forest so
that the forest becomes connected. To add an edge, you choose two different
vertices i and j, then span an edge between i and j. This operation costs a_i
+ a_j dollars, and afterward neither Vertex i nor j can be selected again.
Find the minimum total cost required to make the forest connected, or print
`Impossible` if it is impossible. | [{"input": "7 5\n 1 2 3 4 5 6 7\n 3 0\n 4 0\n 1 2\n 1 3\n 5 6", "output": "7\n \n\nIf we connect vertices 0 and 5, the graph becomes connected, for the cost of 1\n+ 6 = 7 dollars.\n\n* * *"}, {"input": "5 0\n 3 1 4 1 5", "output": "Impossible\n \n\nWe can't make the graph connected.\n\n* * *"}, {"input": "1 0\n 5", "output": "0\n \n\nThe graph is already connected, so we do not need to add any edges."}] |
Print the minimum total cost required to make the forest connected, or print
`Impossible` if it is impossible.
* * * | s781455698 | Wrong Answer | p03440 | Input is given from Standard Input in the following format:
N M
a_0 a_1 .. a_{N-1}
x_1 y_1
x_2 y_2
:
x_M y_M | def a():
x, y = map(int, input().split())
def b():
import numpy as np
n = int(input())
a = np.asarray(list(map(int, input().split())))
b = np.asarray(list(map(int, input().split())))
x = b.sum() - a.sum()
d = b - a
a_req = 0
b_req = 0
for i in d:
if i <= 0:
b_req += i // -1
else:
a_req += i // 2 + i % 2
b_req += i % 2
# total require
if (a_req >= b_req and (0 < a_req + (a_req - b_req) == x)) or (
a_req == 0 and b_req == 0
):
print("Yes")
else:
print("No")
def d():
n, m = map(int, input().split())
a = list(map(int, input().split()))
G = []
for _ in range(m):
s = set(map(int, input().split()))
for S in G:
if s & S:
s |= S
G = [i for i in G if not s >= i]
G.append(s)
G = [sorted([a[i] for i in S], reverse=True) for S in G]
# 見なしのv, e
_v = len(G)
_e = _v - 1
e = _e * 2
cost = 0
tmp = []
for D in G:
cost += D.pop()
tmp += D
tbd = e - _v
cost += sum(sorted(tmp[:tbd]))
print(cost)
if __name__ == "__main__":
d()
| Statement
You are given a forest with N vertices and M edges. The vertices are numbered
0 through N-1. The edges are given in the format (x_i,y_i), which means that
Vertex x_i and y_i are connected by an edge.
Each vertex i has a value a_i. You want to add edges in the given forest so
that the forest becomes connected. To add an edge, you choose two different
vertices i and j, then span an edge between i and j. This operation costs a_i
+ a_j dollars, and afterward neither Vertex i nor j can be selected again.
Find the minimum total cost required to make the forest connected, or print
`Impossible` if it is impossible. | [{"input": "7 5\n 1 2 3 4 5 6 7\n 3 0\n 4 0\n 1 2\n 1 3\n 5 6", "output": "7\n \n\nIf we connect vertices 0 and 5, the graph becomes connected, for the cost of 1\n+ 6 = 7 dollars.\n\n* * *"}, {"input": "5 0\n 3 1 4 1 5", "output": "Impossible\n \n\nWe can't make the graph connected.\n\n* * *"}, {"input": "1 0\n 5", "output": "0\n \n\nThe graph is already connected, so we do not need to add any edges."}] |
Print the minimum total cost required to make the forest connected, or print
`Impossible` if it is impossible.
* * * | s481150696 | Wrong Answer | p03440 | Input is given from Standard Input in the following format:
N M
a_0 a_1 .. a_{N-1}
x_1 y_1
x_2 y_2
:
x_M y_M | print(0)
| Statement
You are given a forest with N vertices and M edges. The vertices are numbered
0 through N-1. The edges are given in the format (x_i,y_i), which means that
Vertex x_i and y_i are connected by an edge.
Each vertex i has a value a_i. You want to add edges in the given forest so
that the forest becomes connected. To add an edge, you choose two different
vertices i and j, then span an edge between i and j. This operation costs a_i
+ a_j dollars, and afterward neither Vertex i nor j can be selected again.
Find the minimum total cost required to make the forest connected, or print
`Impossible` if it is impossible. | [{"input": "7 5\n 1 2 3 4 5 6 7\n 3 0\n 4 0\n 1 2\n 1 3\n 5 6", "output": "7\n \n\nIf we connect vertices 0 and 5, the graph becomes connected, for the cost of 1\n+ 6 = 7 dollars.\n\n* * *"}, {"input": "5 0\n 3 1 4 1 5", "output": "Impossible\n \n\nWe can't make the graph connected.\n\n* * *"}, {"input": "1 0\n 5", "output": "0\n \n\nThe graph is already connected, so we do not need to add any edges."}] |
Print the minimum total cost required to make the forest connected, or print
`Impossible` if it is impossible.
* * * | s278264511 | Wrong Answer | p03440 | Input is given from Standard Input in the following format:
N M
a_0 a_1 .. a_{N-1}
x_1 y_1
x_2 y_2
:
x_M y_M | import sys
readline = sys.stdin.readline
MOD = 10**9 + 7
INF = float("INF")
sys.setrecursionlimit(10**5)
import heapq
class PriorityQueue:
class Reverse:
def __init__(self, val):
self.val = val
def __lt__(self, other):
return self.val > other.val
def __repr__(self):
return repr(self.val)
def __init__(self, x=None, desc=False):
if not x:
x = []
if desc:
for i in range(len(x)):
x[i] = self.Reverse(x[i])
self._desc = desc
self._container = x
heapq.heapify(self._container)
@property
def is_empty(self):
return not self._container
def pop(self):
if self._desc:
return heapq.heappop(self._container).val
else:
return heapq.heappop(self._container)
def push(self, item):
if self._desc:
heapq.heappush(self._container, self.Reverse(item))
else:
heapq.heappush(self._container, item)
def top(self):
if self._desc:
return self._container[0].val
else:
return self._container[0]
def sum(self):
return sum(self._container)
def __len__(self):
return len(self._container)
def main():
def solve():
from collections import deque, defaultdict
N, M = map(int, readline().split())
a = list(map(int, readline().split()))
edge = defaultdict(list)
ans = 0
for _ in range(M):
x, y = map(int, readline().split())
edge[x].append(y)
edge[y].append(x)
visited = [False] * N
def bfs(s):
que = deque()
pq = PriorityQueue()
que.append(s)
visited[s] = True
while que:
cur = que.popleft()
pq.push(a[cur])
for nx in edge[cur]:
if not visited[nx]:
visited[nx] = True
que.append(nx)
return pq
costs = bfs(0)
for i in range(1, N):
if not visited[i]:
next_costs = bfs(i)
if not costs:
return -1
ans += costs.pop()
ans += next_costs.pop()
while next_costs:
costs.push(next_costs.pop())
return ans
ans = solve()
if ans == -1:
print("Impossible")
else:
print(ans)
if __name__ == "__main__":
main()
| Statement
You are given a forest with N vertices and M edges. The vertices are numbered
0 through N-1. The edges are given in the format (x_i,y_i), which means that
Vertex x_i and y_i are connected by an edge.
Each vertex i has a value a_i. You want to add edges in the given forest so
that the forest becomes connected. To add an edge, you choose two different
vertices i and j, then span an edge between i and j. This operation costs a_i
+ a_j dollars, and afterward neither Vertex i nor j can be selected again.
Find the minimum total cost required to make the forest connected, or print
`Impossible` if it is impossible. | [{"input": "7 5\n 1 2 3 4 5 6 7\n 3 0\n 4 0\n 1 2\n 1 3\n 5 6", "output": "7\n \n\nIf we connect vertices 0 and 5, the graph becomes connected, for the cost of 1\n+ 6 = 7 dollars.\n\n* * *"}, {"input": "5 0\n 3 1 4 1 5", "output": "Impossible\n \n\nWe can't make the graph connected.\n\n* * *"}, {"input": "1 0\n 5", "output": "0\n \n\nThe graph is already connected, so we do not need to add any edges."}] |
Print the minimum total cost required to make the forest connected, or print
`Impossible` if it is impossible.
* * * | s862124409 | Runtime Error | p03440 | Input is given from Standard Input in the following format:
N M
a_0 a_1 .. a_{N-1}
x_1 y_1
x_2 y_2
:
x_M y_M | def LI(): return list(map(int, input().split()))
def LS(): return input().split()
def I(): return int(input())
def S(): return input()
n, m = LI()
a = LI()
d = dict([(i, [i])for i in range(n)])
for i in range(m):
x, y = LI()
d[x].append(y)
d[y].append(x)
pow = [1]*n
def mori(num, mori_list):
for c in d[num]:
if pow[c] == 1:
mori_list.append(a[c])
pow[c] = 0
mori(c, mori_list)
zen_mori = []
for i in range(n):
if pow[i] == 1:
mori_list = []
mori(i, mori_list)
zen_mori.append(sorted(mori_list)[::-1])
l = len(zen_mori)
check_list = [0]*l
if n - l < l - 2:
print("Impossible")
exit()
ans = 0
for cnt in range(l-1):
pos = 0
one, two = 0, 0
use = []
while True:
min_list = [[zen_mori[i][-1] if len(zen_mori[i]) > 0 else (10**9 + 1), i] for i in range(l)]
use = sorted(min_list)
one, two = use[pos][1], use[pos+1][1]
if check_list[one] == 1 and check_list[two] == 1:
pos += 1
continue
if len(zen_mori[one]) == 1 and len(zen_mori[two]) == 1:
pos += 1
continue
break
ans += use[pos][0] + use[pos+1][0]
try:
zen_mori[one].pop()
except:
pass
try:
zen_mori[two].pop()
except:
pass
check_list[one] = 1
check_list[two] = 1
print(ans) | Statement
You are given a forest with N vertices and M edges. The vertices are numbered
0 through N-1. The edges are given in the format (x_i,y_i), which means that
Vertex x_i and y_i are connected by an edge.
Each vertex i has a value a_i. You want to add edges in the given forest so
that the forest becomes connected. To add an edge, you choose two different
vertices i and j, then span an edge between i and j. This operation costs a_i
+ a_j dollars, and afterward neither Vertex i nor j can be selected again.
Find the minimum total cost required to make the forest connected, or print
`Impossible` if it is impossible. | [{"input": "7 5\n 1 2 3 4 5 6 7\n 3 0\n 4 0\n 1 2\n 1 3\n 5 6", "output": "7\n \n\nIf we connect vertices 0 and 5, the graph becomes connected, for the cost of 1\n+ 6 = 7 dollars.\n\n* * *"}, {"input": "5 0\n 3 1 4 1 5", "output": "Impossible\n \n\nWe can't make the graph connected.\n\n* * *"}, {"input": "1 0\n 5", "output": "0\n \n\nThe graph is already connected, so we do not need to add any edges."}] |
Print the minimum total cost required to make the forest connected, or print
`Impossible` if it is impossible.
* * * | s834996423 | Wrong Answer | p03440 | Input is given from Standard Input in the following format:
N M
a_0 a_1 .. a_{N-1}
x_1 y_1
x_2 y_2
:
x_M y_M | import heapq
n, m = map(int, input().split())
a = list(map(int, input().split()))
qs = {}
graph = [[] for x in range(n)]
for i in range(m):
_from, _to = map(int, input().split())
graph[_from].append(_to)
graph[_to].append(_from)
| Statement
You are given a forest with N vertices and M edges. The vertices are numbered
0 through N-1. The edges are given in the format (x_i,y_i), which means that
Vertex x_i and y_i are connected by an edge.
Each vertex i has a value a_i. You want to add edges in the given forest so
that the forest becomes connected. To add an edge, you choose two different
vertices i and j, then span an edge between i and j. This operation costs a_i
+ a_j dollars, and afterward neither Vertex i nor j can be selected again.
Find the minimum total cost required to make the forest connected, or print
`Impossible` if it is impossible. | [{"input": "7 5\n 1 2 3 4 5 6 7\n 3 0\n 4 0\n 1 2\n 1 3\n 5 6", "output": "7\n \n\nIf we connect vertices 0 and 5, the graph becomes connected, for the cost of 1\n+ 6 = 7 dollars.\n\n* * *"}, {"input": "5 0\n 3 1 4 1 5", "output": "Impossible\n \n\nWe can't make the graph connected.\n\n* * *"}, {"input": "1 0\n 5", "output": "0\n \n\nThe graph is already connected, so we do not need to add any edges."}] |
Print the minimum total cost required to make the forest connected, or print
`Impossible` if it is impossible.
* * * | s803791411 | Accepted | p03440 | Input is given from Standard Input in the following format:
N M
a_0 a_1 .. a_{N-1}
x_1 y_1
x_2 y_2
:
x_M y_M | import sys
sys.setrecursionlimit(10**7) # 再帰関数の上限,10**5以上の場合python
import math
from copy import copy, deepcopy
from operator import itemgetter
from bisect import bisect_left, bisect, bisect_right # 2分探索
# bisect_left(l,x), bisect(l,x)#aはソート済みである必要あり。aの中からx未満の要素数を返す。rightだと以下
from collections import deque
# deque(l), pop(), append(x), popleft(), appendleft(x)
##listでqueの代用をするとO(N)の計算量がかかってしまうので注意
from collections import Counter # 文字列を個数カウント辞書に、
# S=Counter(l),S.most_common(x),S.keys(),S.values(),S.items()
from itertools import accumulate # 累積和
# list(accumulate(l))
from heapq import heapify, heappop, heappush
# heapify(q),heappush(q,a),heappop(q) #q=heapify(q)としないこと、返り値はNone
# import fractions#古いatcoderコンテストの場合GCDなどはここからimportする
from functools import lru_cache # pypyでもうごく
# @lru_cache(maxsize = None)#maxsizeは保存するデータ数の最大値、2**nが最も高効率
def input():
return sys.stdin.readline()[:-1]
def printl(li):
print(*li, sep="\n")
def argsort(s, return_sorted=False):
inds = sorted(range(len(s)), key=lambda k: s[k])
if return_sorted:
return inds, [s[i] for i in inds]
return inds
def alp2num(c, cap=False):
return ord(c) - 97 if not cap else ord(c) - 65
def num2alp(i, cap=False):
return chr(i + 97) if not cap else chr(i + 65)
def matmat(A, B):
K, N, M = len(B), len(A), len(B[0])
return [
[sum([(A[i][k] * B[k][j]) for k in range(K)]) for j in range(M)]
for i in range(N)
]
def matvec(M, v):
N, size = len(v), len(M)
return [sum([M[i][j] * v[j] for j in range(N)]) for i in range(size)]
def T(M):
n, m = len(M), len(M[0])
return [[M[j][i] for j in range(n)] for i in range(m)]
class UnionFind: # 早いunionfind,親はclass[i]のように要素指定すればok
def __init__(self, elements=None):
"""Create a new empty union-find structure.
If *elements* is an iterable, this structure will be initialized
with the discrete partition on the given set of elements.
"""
if elements is None:
elements = ()
self.parents = {}
self.weights = {}
for x in elements:
self.weights[x] = 1
self.parents[x] = x
def __getitem__(self, i):
"""Find and return the name of the set containing the i."""
# check for previously unknown i
if i not in self.parents:
self.parents[i] = i
self.weights[i] = 1
return i
# find path of is leading to the root
path = [i]
root = self.parents[i]
while root != path[-1]:
path.append(root)
root = self.parents[root]
# compress the path and return
for ancestor in path:
self.parents[ancestor] = root
return root
def __iter__(self): # for parent in Class:
return iter(self.parents)
def union(self, *objects): # union the parents of objects
"""Find the sets containing the objects and merge them all."""
roots = [self[x] for x in objects]
# Find the heaviest root according to its weight.
heaviest = max(roots, key=lambda r: self.weights[r])
for r in roots:
if r != heaviest:
self.weights[heaviest] += self.weights[r]
self.parents[r] = heaviest
def __len__(self):
return len(self.parents)
def main():
mod = 10**9 + 7
# w.sort(key=itemgetter(1),reversed=True) #二個目の要素で降順並び替え
# N = int(input())
N, M = map(int, input().split())
A = tuple(map(int, input().split())) # 1行ベクトル
# L = tuple(int(input()) for i in range(N)) #改行ベクトル
# S = tuple(tuple(map(int, input().split())) for i in range(N)) #改行行列
tree = UnionFind(list(range(N)))
for i in range(M):
x, y = map(int, input().split())
tree.union(x, y)
d = dict()
for i in range(N):
root = tree[i]
if root not in d:
d[root] = []
heappush(d[root], A[i])
nr = len(d.keys())
if nr == 1:
print(0)
return
if 2 * (nr - 1) > N:
print("Impossible")
return
ans = 0
# print(d)
ocount = 0
As = []
for j, q in d.items():
a = heappop(q)
ans += a
As += q
As.sort()
for i in range(0, nr - 2):
ans += As[i]
print(ans)
if __name__ == "__main__":
main()
| Statement
You are given a forest with N vertices and M edges. The vertices are numbered
0 through N-1. The edges are given in the format (x_i,y_i), which means that
Vertex x_i and y_i are connected by an edge.
Each vertex i has a value a_i. You want to add edges in the given forest so
that the forest becomes connected. To add an edge, you choose two different
vertices i and j, then span an edge between i and j. This operation costs a_i
+ a_j dollars, and afterward neither Vertex i nor j can be selected again.
Find the minimum total cost required to make the forest connected, or print
`Impossible` if it is impossible. | [{"input": "7 5\n 1 2 3 4 5 6 7\n 3 0\n 4 0\n 1 2\n 1 3\n 5 6", "output": "7\n \n\nIf we connect vertices 0 and 5, the graph becomes connected, for the cost of 1\n+ 6 = 7 dollars.\n\n* * *"}, {"input": "5 0\n 3 1 4 1 5", "output": "Impossible\n \n\nWe can't make the graph connected.\n\n* * *"}, {"input": "1 0\n 5", "output": "0\n \n\nThe graph is already connected, so we do not need to add any edges."}] |
Print a set of the lengths of the roads that meets the objective, in the
following format:
w_{1, 1} \ w_{1, 2} \ w_{1, 3} \ ... \ w_{1, N}
w_{2, 1} \ w_{2, 2} \ w_{2, 3} \ ... \ w_{2, N}
: : :
w_{N, 1} \ w_{N, 2} \ w_{N, 3} \ ... \ w_{N, N}
where w_{i, j} is the length of the road connecting Town i and Town j, which
must satisfy the following conditions:
* w_{i, i} = 0
* w_{i, j} = w_{j, i} \ (i \neq j)
* 1 \leq w_{i, j} \leq 10^{11} \ (i \neq j)
If there are multiple sets of lengths of the roads that meet the objective,
any of them will be accepted.
* * * | s923593885 | Wrong Answer | p03010 | Input is given from Standard Input in the following format:
N | def print_map(m, n):
for i in range(n):
for j in range(n):
if j == 0:
h = ""
else:
h = " "
print(h + str(m[i][j]), end="")
print()
def calc_distance(r, m, n):
p = r[0]
total_dist = 0
for i in range(1, n):
np = r[i]
dist = m[p][np]
total_dist += dist
p = np
return total_dist
N = int(input())
Map = [[0 for i in range(N)] for j in range(N)]
# print_map(Map,N)
dist = 1
for i in range(N):
for j in range(N):
if i == j:
continue
if Map[i][j] != 0 or Map[j][i] != 0:
continue
Map[i][j] = dist
Map[j][i] = dist
# print(i,j,dist)
dist += 1
# print_map(Map,N)
route_seed = [i for i in range(N)]
import itertools
route = list(itertools.permutations(route_seed))
for i in range(len(route)):
dist_list = []
# print(route[i])
r = route[i]
dist = calc_distance(r, Map, N)
if dist in dist_list:
print("same distance")
break
dist_list.append(dist)
print_map(Map, N)
| Statement
Diverta City is a new city consisting of N towns numbered 1, 2, ..., N.
The mayor Ringo is planning to connect every pair of two different towns with
a bidirectional road. The length of each road is undecided.
A _Hamiltonian path_ is a path that starts at one of the towns and visits each
of the other towns exactly once. The reversal of a Hamiltonian path is
considered the same as the original Hamiltonian path.
There are N! / 2 Hamiltonian paths. Ringo wants all these paths to have
distinct total lengths (the sum of the lengths of the roads on a path), to
make the city diverse.
Find one such set of the lengths of the roads, under the following conditions:
* The length of each road must be a positive integer.
* The maximum total length of a Hamiltonian path must be at most 10^{11}. | [{"input": "3", "output": "0 6 15\n 6 0 21\n 15 21 0\n \n\nThere are three Hamiltonian paths. The total lengths of these paths are as\nfollows:\n\n * 1 \u2192 2 \u2192 3: The total length is 6 + 21 = 27.\n * 1 \u2192 3 \u2192 2: The total length is 15 + 21 = 36.\n * 2 \u2192 1 \u2192 3: The total length is 6 + 15 = 21.\n\nThey are distinct, so the objective is met.\n\n* * *"}, {"input": "4", "output": "0 111 157 193\n 111 0 224 239\n 157 224 0 258\n 193 239 258 0\n \n\nThere are 12 Hamiltonian paths, with distinct total lengths."}] |
Print a set of the lengths of the roads that meets the objective, in the
following format:
w_{1, 1} \ w_{1, 2} \ w_{1, 3} \ ... \ w_{1, N}
w_{2, 1} \ w_{2, 2} \ w_{2, 3} \ ... \ w_{2, N}
: : :
w_{N, 1} \ w_{N, 2} \ w_{N, 3} \ ... \ w_{N, N}
where w_{i, j} is the length of the road connecting Town i and Town j, which
must satisfy the following conditions:
* w_{i, i} = 0
* w_{i, j} = w_{j, i} \ (i \neq j)
* 1 \leq w_{i, j} \leq 10^{11} \ (i \neq j)
If there are multiple sets of lengths of the roads that meet the objective,
any of them will be accepted.
* * * | s662880307 | Wrong Answer | p03010 | Input is given from Standard Input in the following format:
N | import sys
sys.setrecursionlimit(10**6)
int1 = lambda x: int(x) - 1
p2D = lambda x: print(*x, sep="\n")
def II():
return int(sys.stdin.readline())
def MI():
return map(int, sys.stdin.readline().split())
def LI():
return list(map(int, sys.stdin.readline().split()))
def LLI(rows_number):
return [LI() for _ in range(rows_number)]
def SI():
return sys.stdin.readline()[:-1]
def main():
n = II()
base = [1, 2]
for i in range(7):
base.append(base[-1] + base[-2])
mx = 0
ans = [[0] * n for _ in range(n)]
for i in range(n):
last = 0
for j in range(i):
ans[i][j] = ans[j][i] = base[j] * (mx + 1)
last = ans[i][j]
mx += last
for row in ans:
print(*row)
main()
| Statement
Diverta City is a new city consisting of N towns numbered 1, 2, ..., N.
The mayor Ringo is planning to connect every pair of two different towns with
a bidirectional road. The length of each road is undecided.
A _Hamiltonian path_ is a path that starts at one of the towns and visits each
of the other towns exactly once. The reversal of a Hamiltonian path is
considered the same as the original Hamiltonian path.
There are N! / 2 Hamiltonian paths. Ringo wants all these paths to have
distinct total lengths (the sum of the lengths of the roads on a path), to
make the city diverse.
Find one such set of the lengths of the roads, under the following conditions:
* The length of each road must be a positive integer.
* The maximum total length of a Hamiltonian path must be at most 10^{11}. | [{"input": "3", "output": "0 6 15\n 6 0 21\n 15 21 0\n \n\nThere are three Hamiltonian paths. The total lengths of these paths are as\nfollows:\n\n * 1 \u2192 2 \u2192 3: The total length is 6 + 21 = 27.\n * 1 \u2192 3 \u2192 2: The total length is 15 + 21 = 36.\n * 2 \u2192 1 \u2192 3: The total length is 6 + 15 = 21.\n\nThey are distinct, so the objective is met.\n\n* * *"}, {"input": "4", "output": "0 111 157 193\n 111 0 224 239\n 157 224 0 258\n 193 239 258 0\n \n\nThere are 12 Hamiltonian paths, with distinct total lengths."}] |
Print a set of the lengths of the roads that meets the objective, in the
following format:
w_{1, 1} \ w_{1, 2} \ w_{1, 3} \ ... \ w_{1, N}
w_{2, 1} \ w_{2, 2} \ w_{2, 3} \ ... \ w_{2, N}
: : :
w_{N, 1} \ w_{N, 2} \ w_{N, 3} \ ... \ w_{N, N}
where w_{i, j} is the length of the road connecting Town i and Town j, which
must satisfy the following conditions:
* w_{i, i} = 0
* w_{i, j} = w_{j, i} \ (i \neq j)
* 1 \leq w_{i, j} \leq 10^{11} \ (i \neq j)
If there are multiple sets of lengths of the roads that meet the objective,
any of them will be accepted.
* * * | s450473963 | Wrong Answer | p03010 | Input is given from Standard Input in the following format:
N | a = "3"
| Statement
Diverta City is a new city consisting of N towns numbered 1, 2, ..., N.
The mayor Ringo is planning to connect every pair of two different towns with
a bidirectional road. The length of each road is undecided.
A _Hamiltonian path_ is a path that starts at one of the towns and visits each
of the other towns exactly once. The reversal of a Hamiltonian path is
considered the same as the original Hamiltonian path.
There are N! / 2 Hamiltonian paths. Ringo wants all these paths to have
distinct total lengths (the sum of the lengths of the roads on a path), to
make the city diverse.
Find one such set of the lengths of the roads, under the following conditions:
* The length of each road must be a positive integer.
* The maximum total length of a Hamiltonian path must be at most 10^{11}. | [{"input": "3", "output": "0 6 15\n 6 0 21\n 15 21 0\n \n\nThere are three Hamiltonian paths. The total lengths of these paths are as\nfollows:\n\n * 1 \u2192 2 \u2192 3: The total length is 6 + 21 = 27.\n * 1 \u2192 3 \u2192 2: The total length is 15 + 21 = 36.\n * 2 \u2192 1 \u2192 3: The total length is 6 + 15 = 21.\n\nThey are distinct, so the objective is met.\n\n* * *"}, {"input": "4", "output": "0 111 157 193\n 111 0 224 239\n 157 224 0 258\n 193 239 258 0\n \n\nThere are 12 Hamiltonian paths, with distinct total lengths."}] |
The output is a sequence of pairs of positive integers. The _i_ -th output
pair corresponds to the _i_ -th input triplet. The integers of each output
pair are the width _p_ and the height _q_ described above, in this order.
Each output line contains a single pair. A space character is put between the
integers as a delimiter. No other characters should appear in the output. | s665794656 | Wrong Answer | p00811 | The input is a sequence of at most 2000 triplets of positive integers,
delimited by a space character in between. Each line contains a single
triplet. The sequence is followed by a triplet of zeros, 0 0 0, which
indicates the end of the input and should not be treated as data to be
processed.
The integers of each input triplet are the integer _m_ , the numerator _a_ ,
and the denominator _b_ described above, in this order. You may assume 4 < _m_
< 100000 and 1 ≤ _a_ ≤ _b_ ≤ 1000\. | MAXN = 320
sieve = [0, 0] + [1] * MAXN
primes = []
p = 2
while p * p <= MAXN:
if sieve[p]:
primes.append(p)
for q in range(p * 2, MAXN + 1, p):
sieve[q] = 0
p += 1
for q in range(p, MAXN):
if sieve[q]:
primes.append(q)
while True:
M, A, B = map(int, input().split())
if M == 0:
break
opt_p = opt_q = 0
for p in primes:
for q in primes:
if p > q:
continue
if p * q > M:
break
if A * q > B * p:
continue
if p * q > opt_p * opt_q:
opt_p, opt_q = p, q
print("{0} {1}".format(opt_p, opt_q))
| A: Calling Extraterrestrial Intelligence Again
A message from humans to extraterrestrial intelligence was sent through the
Arecibo radio telescope in Puerto Rico on the afternoon of Saturday November
l6, l974. The message consisted of l679 bits and was meant to be translated to
a rectangular picture with 23 × 73 pixels. Since both 23 and 73 are prime
numbers, 23 × 73 is the unique possible size of the translated rectangular
picture each edge of which is longer than l pixel. Of course, there was no
guarantee that the receivers would try to translate the message to a
rectangular picture. Even if they would, they might put the pixels into the
rectangle incorrectly. The senders of the Arecibo message were optimistic.
We are planning a similar project. Your task in the project is to find the
most suitable width and height of the translated rectangular picture. The term
``most suitable'' is defined as follows. An integer m greater than 4 is given.
A positive fraction _a_ /_b_ less than or equal to 1 is also given. The area
of the picture should not be greater than _m_. Both of the width and the
height of the translated picture should be prime numbers. The ratio of the
width to the height should not be less than _a_ /_b_ nor greater than 1. You
should maximize the area of the picture under these constraints.
In other words, you will receive an integer _m_ and a fraction _a_ /_b_ . It
holds that _m_ > 4 and 0 < _a_ /_b_ ≤ 1 . You should find the pair of prime
numbers _p_ , _q_ such that _pq_ ≤ _m_ and _a_ /_b_ ≤ _p_ /_q_ ≤ 1 , and
furthermore, the product _pq_ takes the maximum value among such pairs of two
prime numbers. You should report _p_ and _q_ as the "most suitable" width and
height of the translated picture. | [{"input": "1 2\n 99999 999 999\n 1680 5 16\n 1970 1 1\n 2002 4 11\n 0 0 0", "output": "2\n 313 313\n 23 73\n 43 43\n 37 53"}] |
Print the minimum distance to be traveled.
* * * | s576252004 | Accepted | p03694 | Input is given from Standard Input in the following format:
N
a_1 a_2 ... a_N | M = int(input())
LL = input().split()
list1 = []
for i in LL:
a = int(i)
list1.append(a)
list1.sort()
print(list1[-1] - list1[0])
| Statement
It is only six months until Christmas, and AtCoDeer the reindeer is now
planning his travel to deliver gifts.
There are N houses along _TopCoDeer street_. The i-th house is located at
coordinate a_i. He has decided to deliver gifts to all these houses.
Find the minimum distance to be traveled when AtCoDeer can start and end his
travel at any positions. | [{"input": "4\n 2 3 7 9", "output": "7\n \n\nThe travel distance of 7 can be achieved by starting at coordinate 9 and\ntraveling straight to coordinate 2. \nIt is not possible to do with a travel distance of less than 7, and thus 7 is\nthe minimum distance to be traveled.\n\n* * *"}, {"input": "8\n 3 1 4 1 5 9 2 6", "output": "8\n \n\nThere may be more than one house at a position."}] |
Print the minimum distance to be traveled.
* * * | s526639459 | Accepted | p03694 | Input is given from Standard Input in the following format:
N
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 inputI():
return int(input().strip())
def inputS():
return input().strip()
def inputIL():
return list(map(int, input().split()))
def inputSL():
return list(map(str, input().split()))
def inputILs(n):
return list(int(input()) for _ in range(n))
def inputSLs(n):
return list(input().strip() for _ in range(n))
def inputILL(n):
return [list(map(int, input().split())) for _ in range(n)]
def inputSLL(n):
return [list(map(str, input().split())) for _ in range(n)]
######OUTPUT######
def Yes():
print("Yes")
return
def No():
print("No")
return
#####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
#####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 //= a
count += 1
return count
#############
# Main Code #
#############
N = inputI()
a = inputIL()
print(max(a) - min(a))
| Statement
It is only six months until Christmas, and AtCoDeer the reindeer is now
planning his travel to deliver gifts.
There are N houses along _TopCoDeer street_. The i-th house is located at
coordinate a_i. He has decided to deliver gifts to all these houses.
Find the minimum distance to be traveled when AtCoDeer can start and end his
travel at any positions. | [{"input": "4\n 2 3 7 9", "output": "7\n \n\nThe travel distance of 7 can be achieved by starting at coordinate 9 and\ntraveling straight to coordinate 2. \nIt is not possible to do with a travel distance of less than 7, and thus 7 is\nthe minimum distance to be traveled.\n\n* * *"}, {"input": "8\n 3 1 4 1 5 9 2 6", "output": "8\n \n\nThere may be more than one house at a position."}] |
Print the minimum distance to be traveled.
* * * | s360475335 | Runtime Error | p03694 | Input is given from Standard Input in the following format:
N
a_1 a_2 ... a_N | use proconio::*;
use std::cmp::*;
use std::vec::Vec;
fn main() {
input! {
n: usize,
mut A: [i32; n],
}
A.sort();
let res = A[n - 1] - A[0];
println!("{}", res);
} | Statement
It is only six months until Christmas, and AtCoDeer the reindeer is now
planning his travel to deliver gifts.
There are N houses along _TopCoDeer street_. The i-th house is located at
coordinate a_i. He has decided to deliver gifts to all these houses.
Find the minimum distance to be traveled when AtCoDeer can start and end his
travel at any positions. | [{"input": "4\n 2 3 7 9", "output": "7\n \n\nThe travel distance of 7 can be achieved by starting at coordinate 9 and\ntraveling straight to coordinate 2. \nIt is not possible to do with a travel distance of less than 7, and thus 7 is\nthe minimum distance to be traveled.\n\n* * *"}, {"input": "8\n 3 1 4 1 5 9 2 6", "output": "8\n \n\nThere may be more than one house at a position."}] |
Print the minimum distance to be traveled.
* * * | s316052664 | Runtime Error | p03694 | Input is given from Standard Input in the following format:
N
a_1 a_2 ... a_N | import sys
import math
import itertools
import collections
import heapq
import re
import numpy as np
from functools import reduce
rr = lambda: sys.stdin.readline().rstrip()
rs = lambda: sys.stdin.readline().split()
ri = lambda: int(sys.stdin.readline())
rm = lambda: map(int, sys.stdin.readline().split())
rl = lambda: list(map(int, sys.stdin.readline().split()))
inf = float('inf')
mod = 10**9 + 7
n = ri()
li = rl()
print(max(li) - min(li)
| Statement
It is only six months until Christmas, and AtCoDeer the reindeer is now
planning his travel to deliver gifts.
There are N houses along _TopCoDeer street_. The i-th house is located at
coordinate a_i. He has decided to deliver gifts to all these houses.
Find the minimum distance to be traveled when AtCoDeer can start and end his
travel at any positions. | [{"input": "4\n 2 3 7 9", "output": "7\n \n\nThe travel distance of 7 can be achieved by starting at coordinate 9 and\ntraveling straight to coordinate 2. \nIt is not possible to do with a travel distance of less than 7, and thus 7 is\nthe minimum distance to be traveled.\n\n* * *"}, {"input": "8\n 3 1 4 1 5 9 2 6", "output": "8\n \n\nThere may be more than one house at a position."}] |
Print the minimum distance to be traveled.
* * * | s513051881 | Accepted | p03694 | Input is given from Standard Input in the following format:
N
a_1 a_2 ... a_N | n = int(input())
line = list(map(int, input().split()))
line.sort(key=int)
print(line[-1] - line[0])
| Statement
It is only six months until Christmas, and AtCoDeer the reindeer is now
planning his travel to deliver gifts.
There are N houses along _TopCoDeer street_. The i-th house is located at
coordinate a_i. He has decided to deliver gifts to all these houses.
Find the minimum distance to be traveled when AtCoDeer can start and end his
travel at any positions. | [{"input": "4\n 2 3 7 9", "output": "7\n \n\nThe travel distance of 7 can be achieved by starting at coordinate 9 and\ntraveling straight to coordinate 2. \nIt is not possible to do with a travel distance of less than 7, and thus 7 is\nthe minimum distance to be traveled.\n\n* * *"}, {"input": "8\n 3 1 4 1 5 9 2 6", "output": "8\n \n\nThere may be more than one house at a position."}] |
Print the minimum distance to be traveled.
* * * | s448229233 | Runtime Error | p03694 | Input is given from Standard Input in the following format:
N
a_1 a_2 ... a_N | n=int(input())
a=list(map(int,input().split()))
a.sort()
print(a[n-1]a[0]) | Statement
It is only six months until Christmas, and AtCoDeer the reindeer is now
planning his travel to deliver gifts.
There are N houses along _TopCoDeer street_. The i-th house is located at
coordinate a_i. He has decided to deliver gifts to all these houses.
Find the minimum distance to be traveled when AtCoDeer can start and end his
travel at any positions. | [{"input": "4\n 2 3 7 9", "output": "7\n \n\nThe travel distance of 7 can be achieved by starting at coordinate 9 and\ntraveling straight to coordinate 2. \nIt is not possible to do with a travel distance of less than 7, and thus 7 is\nthe minimum distance to be traveled.\n\n* * *"}, {"input": "8\n 3 1 4 1 5 9 2 6", "output": "8\n \n\nThere may be more than one house at a position."}] |
Print the minimum distance to be traveled.
* * * | s943933550 | Accepted | p03694 | Input is given from Standard Input in the following format:
N
a_1 a_2 ... a_N | # Author: cr4zjh0bp
# Created: Sun Mar 22 23:25:40 UTC 2020
import sys
stdin = sys.stdin
inf = 1 << 60
mod = 1000000007
ni = lambda: int(ns())
nin = lambda y: [ni() for _ in range(y)]
na = lambda: list(map(int, stdin.readline().split()))
nan = lambda y: [na() for _ in range(y)]
nf = lambda: float(ns())
nfn = lambda y: [nf() for _ in range(y)]
nfa = lambda: list(map(float, stdin.readline().split()))
nfan = lambda y: [nfa() for _ in range(y)]
ns = lambda: stdin.readline().rstrip()
nsn = lambda y: [ns() for _ in range(y)]
ncl = lambda y: [list(ns()) for _ in range(y)]
nas = lambda: stdin.readline().split()
n = ni()
a = na()
print(max(a) - min(a))
| Statement
It is only six months until Christmas, and AtCoDeer the reindeer is now
planning his travel to deliver gifts.
There are N houses along _TopCoDeer street_. The i-th house is located at
coordinate a_i. He has decided to deliver gifts to all these houses.
Find the minimum distance to be traveled when AtCoDeer can start and end his
travel at any positions. | [{"input": "4\n 2 3 7 9", "output": "7\n \n\nThe travel distance of 7 can be achieved by starting at coordinate 9 and\ntraveling straight to coordinate 2. \nIt is not possible to do with a travel distance of less than 7, and thus 7 is\nthe minimum distance to be traveled.\n\n* * *"}, {"input": "8\n 3 1 4 1 5 9 2 6", "output": "8\n \n\nThere may be more than one house at a position."}] |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.