output_description
stringlengths
15
956
submission_id
stringlengths
10
10
status
stringclasses
3 values
problem_id
stringlengths
6
6
input_description
stringlengths
9
2.55k
attempt
stringlengths
1
13.7k
problem_description
stringlengths
7
5.24k
samples
stringlengths
2
2.72k
Print the given integers in ascending order in a line. Put a single space between two integers.
s175823527
Accepted
p02393
Three integers separated by a single space are given in a line.
print(" ".join([str(y) for y in sorted([int(x) for x in input().split(" ")])]))
Sorting Three Numbers Write a program which reads three integers, and prints them in ascending order.
[{"input": "3 8 1", "output": "1 3 8"}]
Print the given integers in ascending order in a line. Put a single space between two integers.
s443284078
Accepted
p02393
Three integers separated by a single space are given in a line.
n = [int(x) for x in input().split()] print(*sorted(n))
Sorting Three Numbers Write a program which reads three integers, and prints them in ascending order.
[{"input": "3 8 1", "output": "1 3 8"}]
Print the given integers in ascending order in a line. Put a single space between two integers.
s764439826
Wrong Answer
p02393
Three integers separated by a single space are given in a line.
print(list(sorted(map(int, input().split()))))
Sorting Three Numbers Write a program which reads three integers, and prints them in ascending order.
[{"input": "3 8 1", "output": "1 3 8"}]
Print the given integers in ascending order in a line. Put a single space between two integers.
s270022212
Wrong Answer
p02393
Three integers separated by a single space are given in a line.
list = [i for i in input().split()] print(" ".join(list))
Sorting Three Numbers Write a program which reads three integers, and prints them in ascending order.
[{"input": "3 8 1", "output": "1 3 8"}]
Print the given integers in ascending order in a line. Put a single space between two integers.
s492834113
Wrong Answer
p02393
Three integers separated by a single space are given in a line.
print(sorted(input().split()))
Sorting Three Numbers Write a program which reads three integers, and prints them in ascending order.
[{"input": "3 8 1", "output": "1 3 8"}]
Print the given integers in ascending order in a line. Put a single space between two integers.
s815684798
Accepted
p02393
Three integers separated by a single space are given in a line.
aaa = list(map(int, input().split())) aaa.sort() print(aaa[0], aaa[1], aaa[2])
Sorting Three Numbers Write a program which reads three integers, and prints them in ascending order.
[{"input": "3 8 1", "output": "1 3 8"}]
Print the given integers in ascending order in a line. Put a single space between two integers.
s699535105
Accepted
p02393
Three integers separated by a single space are given in a line.
arr = map(int, input().split(" ")) arr = sorted(arr) print(" ".join(map(str, arr)))
Sorting Three Numbers Write a program which reads three integers, and prints them in ascending order.
[{"input": "3 8 1", "output": "1 3 8"}]
Print the given integers in ascending order in a line. Put a single space between two integers.
s259941339
Accepted
p02393
Three integers separated by a single space are given in a line.
print(*sorted(map(int, input().strip().split(" "))))
Sorting Three Numbers Write a program which reads three integers, and prints them in ascending order.
[{"input": "3 8 1", "output": "1 3 8"}]
Print the given integers in ascending order in a line. Put a single space between two integers.
s256091668
Accepted
p02393
Three integers separated by a single space are given in a line.
# 1. ソート対象の配列をピポット(=分割の基準)を基準に2つの部分配列に分割(divide) # 2. 前方の部分配列に対してquick_sortを行う(solve) # 3. 後方の部分配列に対してquick_sortを行う(solve) # 4. 整列済み部分配列とピボットを連結して返す(Conquer) def quick_sort(arr): if len(arr) < 2: return arr p = arr[0] left, right = divide(p, arr[1:]) return quick_sort(left) + [p] + quick_sort(right) def divide(p, arr): left, right = [], [] for i in arr: if p > i: left.append(i) else: right.append(i) return left, right arr = quick_sort(list(map(int, input().split()))) print(f"{arr[0]} {arr[1]} {arr[2]}")
Sorting Three Numbers Write a program which reads three integers, and prints them in ascending order.
[{"input": "3 8 1", "output": "1 3 8"}]
Print the given integers in ascending order in a line. Put a single space between two integers.
s233069925
Accepted
p02393
Three integers separated by a single space are given in a line.
a = list(map(int, input().split())) for i in range(len(a)): for j in range(i, len(a)): if a[i] > a[j]: ret = a[i] a[i] = a[j] a[j] = ret print(" ".join(list(map(str, a))))
Sorting Three Numbers Write a program which reads three integers, and prints them in ascending order.
[{"input": "3 8 1", "output": "1 3 8"}]
Print the given integers in ascending order in a line. Put a single space between two integers.
s476186754
Accepted
p02393
Three integers separated by a single space are given in a line.
input_data = [int(i) for i in input().split()] input_data.sort() print(input_data[0], input_data[1], input_data[2])
Sorting Three Numbers Write a program which reads three integers, and prints them in ascending order.
[{"input": "3 8 1", "output": "1 3 8"}]
Print the given integers in ascending order in a line. Put a single space between two integers.
s827126887
Accepted
p02393
Three integers separated by a single space are given in a line.
abc = input() num_abc = abc.split() num_abc.sort() print(num_abc[0], num_abc[1], num_abc[2])
Sorting Three Numbers Write a program which reads three integers, and prints them in ascending order.
[{"input": "3 8 1", "output": "1 3 8"}]
Print the given integers in ascending order in a line. Put a single space between two integers.
s724356131
Accepted
p02393
Three integers separated by a single space are given in a line.
print("%s %s %s" % tuple(sorted(map(int, input().split()))))
Sorting Three Numbers Write a program which reads three integers, and prints them in ascending order.
[{"input": "3 8 1", "output": "1 3 8"}]
Print the given integers in ascending order in a line. Put a single space between two integers.
s754916417
Accepted
p02393
Three integers separated by a single space are given in a line.
print(" ".join(map(str, sorted([int(i) for i in input().split(" ")]))))
Sorting Three Numbers Write a program which reads three integers, and prints them in ascending order.
[{"input": "3 8 1", "output": "1 3 8"}]
Print the given integers in ascending order in a line. Put a single space between two integers.
s442669651
Accepted
p02393
Three integers separated by a single space are given in a line.
xs = list(map(int, input().split())) xs.sort() print(" ".join(map(str, xs)))
Sorting Three Numbers Write a program which reads three integers, and prints them in ascending order.
[{"input": "3 8 1", "output": "1 3 8"}]
Print the given integers in ascending order in a line. Put a single space between two integers.
s047307814
Wrong Answer
p02393
Three integers separated by a single space are given in a line.
data = input() data = data.split() data = map(int, data) data = sorted(data) print("")
Sorting Three Numbers Write a program which reads three integers, and prints them in ascending order.
[{"input": "3 8 1", "output": "1 3 8"}]
Print the given integers in ascending order in a line. Put a single space between two integers.
s865634316
Accepted
p02393
Three integers separated by a single space are given in a line.
print(" ".join(map(str, sorted(map(int, input().split(" "))))))
Sorting Three Numbers Write a program which reads three integers, and prints them in ascending order.
[{"input": "3 8 1", "output": "1 3 8"}]
Print the given integers in ascending order in a line. Put a single space between two integers.
s863190074
Accepted
p02393
Three integers separated by a single space are given in a line.
l = (int(i) for i in input().split()) print(*sorted(l))
Sorting Three Numbers Write a program which reads three integers, and prints them in ascending order.
[{"input": "3 8 1", "output": "1 3 8"}]
Print the given integers in ascending order in a line. Put a single space between two integers.
s595915061
Accepted
p02393
Three integers separated by a single space are given in a line.
print(*list(sorted(map(int, input().split()))))
Sorting Three Numbers Write a program which reads three integers, and prints them in ascending order.
[{"input": "3 8 1", "output": "1 3 8"}]
Print the given integers in ascending order in a line. Put a single space between two integers.
s762787415
Accepted
p02393
Three integers separated by a single space are given in a line.
print(" ".join(map(str, sorted([int(i) for i in input().split()]))))
Sorting Three Numbers Write a program which reads three integers, and prints them in ascending order.
[{"input": "3 8 1", "output": "1 3 8"}]
Print the given integers in ascending order in a line. Put a single space between two integers.
s595851331
Accepted
p02393
Three integers separated by a single space are given in a line.
print("{} {} {}".format(*sorted(map(int, input().split()))))
Sorting Three Numbers Write a program which reads three integers, and prints them in ascending order.
[{"input": "3 8 1", "output": "1 3 8"}]
Print the given integers in ascending order in a line. Put a single space between two integers.
s753286530
Wrong Answer
p02393
Three integers separated by a single space are given in a line.
sorted([10000, 1000, 100])
Sorting Three Numbers Write a program which reads three integers, and prints them in ascending order.
[{"input": "3 8 1", "output": "1 3 8"}]
Print the given integers in ascending order in a line. Put a single space between two integers.
s006730352
Wrong Answer
p02393
Three integers separated by a single space are given in a line.
print(sorted(map(int, input().split())))
Sorting Three Numbers Write a program which reads three integers, and prints them in ascending order.
[{"input": "3 8 1", "output": "1 3 8"}]
Print the given integers in ascending order in a line. Put a single space between two integers.
s629186170
Wrong Answer
p02393
Three integers separated by a single space are given in a line.
x = input() y = x.split(" ") z = list(map(int, y)) print(sorted(z))
Sorting Three Numbers Write a program which reads three integers, and prints them in ascending order.
[{"input": "3 8 1", "output": "1 3 8"}]
Print the given integers in ascending order in a line. Put a single space between two integers.
s126537684
Wrong Answer
p02393
Three integers separated by a single space are given in a line.
xs = map(int, input().split()) " ".join(map(str, sorted(xs)))
Sorting Three Numbers Write a program which reads three integers, and prints them in ascending order.
[{"input": "3 8 1", "output": "1 3 8"}]
Print the given integers in ascending order in a line. Put a single space between two integers.
s549002128
Wrong Answer
p02393
Three integers separated by a single space are given in a line.
a, b, c = [int(i) for i in input().split()] print(min)
Sorting Three Numbers Write a program which reads three integers, and prints them in ascending order.
[{"input": "3 8 1", "output": "1 3 8"}]
Print the given integers in ascending order in a line. Put a single space between two integers.
s273007839
Wrong Answer
p02393
Three integers separated by a single space are given in a line.
sorted([int(x) for x in input().split()], reverse=True)
Sorting Three Numbers Write a program which reads three integers, and prints them in ascending order.
[{"input": "3 8 1", "output": "1 3 8"}]
For each testcase, print the answer on Standard Output followed by a newline. * * *
s638959156
Wrong Answer
p02669
The input is given from Standard Input. The first line of the input is T Then, T lines follow describing the T testcases. Each of the T lines has the format N A B C D
# 解説PDF読んで解説放送見てAC # 逆から操作を考える(終点のNから考える) # スカスカDP。なので配列を作らずに辞書で管理する必要がある import math def calc_cost(n, ans_dict): min_cost = n * d inc_2 = int(math.ceil(n / 2)) if inc_2 not in ans_dict: ans_dict[inc_2] = calc_cost(inc_2, ans_dict) min_cost = min(min_cost, d * (inc_2 * 2 - n) + a + ans_dict[inc_2]) dec_2 = int(math.floor(n / 2)) if dec_2 not in ans_dict: ans_dict[dec_2] = calc_cost(dec_2, ans_dict) min_cost = min(min_cost, d * (-dec_2 * 2 + n) + a + ans_dict[dec_2]) inc_3 = int(math.ceil(n / 3)) if inc_3 not in ans_dict: ans_dict[inc_3] = calc_cost(inc_3, ans_dict) min_cost = min(min_cost, d * (inc_3 * 3 - n) + b + ans_dict[inc_3]) dec_3 = int(math.floor(n / 3)) if dec_3 not in ans_dict: ans_dict[dec_3] = calc_cost(dec_3, ans_dict) min_cost = min(min_cost, d * (-dec_3 * 3 + n) + b + ans_dict[dec_3]) inc_5 = int(math.ceil(n / 5)) if inc_5 not in ans_dict: ans_dict[inc_5] = calc_cost(inc_5, ans_dict) min_cost = min(min_cost, d * (inc_5 * 5 - n) + c + ans_dict[inc_5]) dec_5 = int(math.floor(n / 5)) if dec_5 not in ans_dict: ans_dict[dec_5] = calc_cost(dec_5, ans_dict) min_cost = min(min_cost, d * (-dec_5 * 5 + n) + c + ans_dict[dec_5]) ans_dict[n] = min_cost return min_cost n_testcase = int(input()) for i in range(n_testcase): n, a, b, c, d = list(map(int, input().split())) # テストケースごとに辞書はリセットしないとダメですね ans_dict = {} ans_dict[0] = 0 ans_dict[1] = d # 1減らすのが常に最善 ans = calc_cost(n, ans_dict) print(ans) # print(ans_dict)
Statement You start with the number 0 and you want to reach the number N. You can change the number, paying a certain amount of coins, with the following operations: * Multiply the number by 2, paying A coins. * Multiply the number by 3, paying B coins. * Multiply the number by 5, paying C coins. * Increase or decrease the number by 1, paying D coins. You can perform these operations in arbitrary order and an arbitrary number of times. What is the minimum number of coins you need to reach N? **You have to solve T testcases.**
[{"input": "5\n 11 1 2 4 8\n 11 1 2 2 8\n 32 10 8 5 4\n 29384293847243 454353412 332423423 934923490 1\n 900000000000000000 332423423 454353412 934923490 987654321", "output": "20\n 19\n 26\n 3821859835\n 23441258666\n \n\nFor the first testcase, a sequence of moves that achieves the minimum cost of\n20 is:\n\n * Initially x = 0.\n * Pay 8 to increase by 1 (x = 1).\n * Pay 1 to multiply by 2 (x = 2).\n * Pay 1 to multiply by 2 (x = 4).\n * Pay 2 to multiply by 3 (x = 12).\n * Pay 8 to decrease by 1 (x = 11).\n\nFor the second testcase, a sequence of moves that achieves the minimum cost of\n19 is:\n\n * Initially x = 0.\n * Pay 8 to increase by 1 (x = 1).\n * Pay 1 to multiply by 2 (x = 2).\n * Pay 2 to multiply by 5 (x = 10).\n * Pay 8 to increase by 1 (x = 11)."}]
For each testcase, print the answer on Standard Output followed by a newline. * * *
s312557331
Wrong Answer
p02669
The input is given from Standard Input. The first line of the input is T Then, T lines follow describing the T testcases. Each of the T lines has the format N A B C D
t = int(input()) for loopi in range(t): n, a, b, c, d = list(map(int, input().split())) minest = 10**40 dd = {n: 0} while 1: newd = {} for i in dd: if i % 2: l = int((i - 1) / 2) if l in newd: newd[l] = min(dd[i] + min(a + d, (i - l) * d), newd[l]) else: newd[l] = dd[i] + min(a + d, (i - l) * d) l = int((i + 1) / 2) if l in newd: newd[l] = min(dd[i] + min(a + d, (i - l) * d), newd[l]) else: newd[l] = dd[i] + min(a + d, (i - l) * d) else: l = int(i / 2) if l in newd: newd[l] = min(dd[i] + min(a, l * d), newd[l]) else: newd[l] = dd[i] + min(a, l * d) l = int((i - (i + 1) % 3 + 1) / 3) if l in newd: newd[l] = min( dd[i] + min(d * ((i + 1) % 3 - 1) ** 2 + b, (i - l) * d), newd[l] ) else: newd[l] = dd[i] + min(d * ((i + 1) % 3 - 1) ** 2 + b, (i - l) * d) l = int((i - (i + 2) % 5 + 2) / 5) if l in newd: newd[l] = min( dd[i] + min(d * int((((i + 2) % 5 - 2) ** 2) ** 0.5) + c, (i - l) * d), newd[l], ) else: newd[l] = dd[i] + min( d * int((((i + 2) % 5 - 2) ** 2) ** 0.5) + c, (i - l) * d ) if 1 in newd: mmm = newd.pop(1) if minest > mmm: minest = mmm if 0 in newd: newd.pop(0) if len(newd) == 0: break dd = newd print(minest + d)
Statement You start with the number 0 and you want to reach the number N. You can change the number, paying a certain amount of coins, with the following operations: * Multiply the number by 2, paying A coins. * Multiply the number by 3, paying B coins. * Multiply the number by 5, paying C coins. * Increase or decrease the number by 1, paying D coins. You can perform these operations in arbitrary order and an arbitrary number of times. What is the minimum number of coins you need to reach N? **You have to solve T testcases.**
[{"input": "5\n 11 1 2 4 8\n 11 1 2 2 8\n 32 10 8 5 4\n 29384293847243 454353412 332423423 934923490 1\n 900000000000000000 332423423 454353412 934923490 987654321", "output": "20\n 19\n 26\n 3821859835\n 23441258666\n \n\nFor the first testcase, a sequence of moves that achieves the minimum cost of\n20 is:\n\n * Initially x = 0.\n * Pay 8 to increase by 1 (x = 1).\n * Pay 1 to multiply by 2 (x = 2).\n * Pay 1 to multiply by 2 (x = 4).\n * Pay 2 to multiply by 3 (x = 12).\n * Pay 8 to decrease by 1 (x = 11).\n\nFor the second testcase, a sequence of moves that achieves the minimum cost of\n19 is:\n\n * Initially x = 0.\n * Pay 8 to increase by 1 (x = 1).\n * Pay 1 to multiply by 2 (x = 2).\n * Pay 2 to multiply by 5 (x = 10).\n * Pay 8 to increase by 1 (x = 11)."}]
For each testcase, print the answer on Standard Output followed by a newline. * * *
s562461572
Accepted
p02669
The input is given from Standard Input. The first line of the input is T Then, T lines follow describing the T testcases. Each of the T lines has the format N A B C D
import sys from functools import lru_cache sys.setrecursionlimit(10**6) def main(): T = int(input()) TESTCASEs = [list(map(int, input().split())) for _ in range(T)] def calc_cost(N, A, B, C, D): @lru_cache(maxsize=None) def calc(N): if N == 0: return 0 if N == 1: return D cost = N * D for T, Tcost in ((2, A), (3, B), (5, C)): div, mod = divmod(N, T) cost = min(cost, calc(div) + Tcost + mod * D) if mod: cost = min(cost, calc(div + 1) + Tcost + (T - mod) * D) return cost return calc(N) for TESTCASE in TESTCASEs: total_cost = calc_cost(*TESTCASE) print(total_cost) if __name__ == "__main__": main() sys.exit()
Statement You start with the number 0 and you want to reach the number N. You can change the number, paying a certain amount of coins, with the following operations: * Multiply the number by 2, paying A coins. * Multiply the number by 3, paying B coins. * Multiply the number by 5, paying C coins. * Increase or decrease the number by 1, paying D coins. You can perform these operations in arbitrary order and an arbitrary number of times. What is the minimum number of coins you need to reach N? **You have to solve T testcases.**
[{"input": "5\n 11 1 2 4 8\n 11 1 2 2 8\n 32 10 8 5 4\n 29384293847243 454353412 332423423 934923490 1\n 900000000000000000 332423423 454353412 934923490 987654321", "output": "20\n 19\n 26\n 3821859835\n 23441258666\n \n\nFor the first testcase, a sequence of moves that achieves the minimum cost of\n20 is:\n\n * Initially x = 0.\n * Pay 8 to increase by 1 (x = 1).\n * Pay 1 to multiply by 2 (x = 2).\n * Pay 1 to multiply by 2 (x = 4).\n * Pay 2 to multiply by 3 (x = 12).\n * Pay 8 to decrease by 1 (x = 11).\n\nFor the second testcase, a sequence of moves that achieves the minimum cost of\n19 is:\n\n * Initially x = 0.\n * Pay 8 to increase by 1 (x = 1).\n * Pay 1 to multiply by 2 (x = 2).\n * Pay 2 to multiply by 5 (x = 10).\n * Pay 8 to increase by 1 (x = 11)."}]
For each testcase, print the answer on Standard Output followed by a newline. * * *
s230394989
Runtime Error
p02669
The input is given from Standard Input. The first line of the input is T Then, T lines follow describing the T testcases. Each of the T lines has the format N A B C D
""" A枚のコインを支払い、持っている数を 2倍する。 B枚のコインを支払い、持っている数を 3倍する。 C枚のコインを支払い、持っている数を 5倍する。 D枚のコインを支払い、持っている数を 1増やす、または 1減らす。 持っている数をNとするには、最小で何枚のコインが必要でしょうか。 """ N, A, B, C, D = map(int, input().split()) arr = [0] * N arr[0] = D arr[1] = min(2 * D, D + A) arr[2] = min(3 * D, D + B, 2 * D + A) arr[3] = min(4 * D, D + 2 * A, 2 * D + B, 2 * D + C) arr[4] = min(5 * D, 2 * D + 2 * A, A + B + 2 * D, D + C) for i in range(5, N, 1): arr[i] = min( arr[((i + 1) // 2) + 1] + A + D * abs(i + 1 - (2 * ((i + 1) // 2))), arr[((i + 1) // 2) + 2] + A + D * abs(i + 1 - (2 * (((i + 1) // 2)) + 1)), arr[((i + 1) // 3) + 1] + B + D * abs(i + 1 - (3 * ((i + 1) // 3))), arr[((i + 1) // 3) + 2] + B + D * abs(i + 1 - (3 * (((i + 1) // 3)) + 1)), arr[((i + 1) // 5) + 1] + C + D * abs(i + 1 - (5 * ((i + 1) // 5))), arr[((i + 1) // 5) + 2] + C + D * abs(i + 1 - (5 * (((i + 1) // 5)) + 1)), ) print(arr[-1])
Statement You start with the number 0 and you want to reach the number N. You can change the number, paying a certain amount of coins, with the following operations: * Multiply the number by 2, paying A coins. * Multiply the number by 3, paying B coins. * Multiply the number by 5, paying C coins. * Increase or decrease the number by 1, paying D coins. You can perform these operations in arbitrary order and an arbitrary number of times. What is the minimum number of coins you need to reach N? **You have to solve T testcases.**
[{"input": "5\n 11 1 2 4 8\n 11 1 2 2 8\n 32 10 8 5 4\n 29384293847243 454353412 332423423 934923490 1\n 900000000000000000 332423423 454353412 934923490 987654321", "output": "20\n 19\n 26\n 3821859835\n 23441258666\n \n\nFor the first testcase, a sequence of moves that achieves the minimum cost of\n20 is:\n\n * Initially x = 0.\n * Pay 8 to increase by 1 (x = 1).\n * Pay 1 to multiply by 2 (x = 2).\n * Pay 1 to multiply by 2 (x = 4).\n * Pay 2 to multiply by 3 (x = 12).\n * Pay 8 to decrease by 1 (x = 11).\n\nFor the second testcase, a sequence of moves that achieves the minimum cost of\n19 is:\n\n * Initially x = 0.\n * Pay 8 to increase by 1 (x = 1).\n * Pay 1 to multiply by 2 (x = 2).\n * Pay 2 to multiply by 5 (x = 10).\n * Pay 8 to increase by 1 (x = 11)."}]
For each testcase, print the answer on Standard Output followed by a newline. * * *
s209674486
Runtime Error
p02669
The input is given from Standard Input. The first line of the input is T Then, T lines follow describing the T testcases. Each of the T lines has the format N A B C D
import heapq def calc(n, a, b, c, d): candidates = [] cost = {2: a, 3: b, 5: c} que = [(0, n)] heapq.heapify(que) mult = [2, 3, 5] ans = 10**18 while len(que) > 0: c, v = heapq.heappop(que) if ans < c: break for m in mult: if v < m: print(*que) t = c + d * v candidates.append(t) ans = min(ans, t) c1 = d * (v - (v // m * m)) + cost[m] + c v1 = v // m c2 = -d * (v + (-v) // m * m) + cost[m] + c v2 = -(-v // m) if c1 < c2: heapq.heappush(que, (c1, v1)) else: heapq.heappush(que, (c2, v2)) # for value,cost in stack: # for m in mult: # if value<m: # candidates.append(cost+d*value) # continue # c1 = d*(value-(value//m*m)) + c[m] + cost # v1 = value//m # c2 = -d*(value+(-value)//m*m) + c[m] + cost # v2 = -(-value//m) print(min(candidates)) def main(): calc(*tuple(map(int, input().split()))) # t = int(input()) # for _ in range(t): # n,a,b,c,d = tuple(map(int,input().split())) # print(calc(n,a,b,c,d)) if __name__ == "__main__": main()
Statement You start with the number 0 and you want to reach the number N. You can change the number, paying a certain amount of coins, with the following operations: * Multiply the number by 2, paying A coins. * Multiply the number by 3, paying B coins. * Multiply the number by 5, paying C coins. * Increase or decrease the number by 1, paying D coins. You can perform these operations in arbitrary order and an arbitrary number of times. What is the minimum number of coins you need to reach N? **You have to solve T testcases.**
[{"input": "5\n 11 1 2 4 8\n 11 1 2 2 8\n 32 10 8 5 4\n 29384293847243 454353412 332423423 934923490 1\n 900000000000000000 332423423 454353412 934923490 987654321", "output": "20\n 19\n 26\n 3821859835\n 23441258666\n \n\nFor the first testcase, a sequence of moves that achieves the minimum cost of\n20 is:\n\n * Initially x = 0.\n * Pay 8 to increase by 1 (x = 1).\n * Pay 1 to multiply by 2 (x = 2).\n * Pay 1 to multiply by 2 (x = 4).\n * Pay 2 to multiply by 3 (x = 12).\n * Pay 8 to decrease by 1 (x = 11).\n\nFor the second testcase, a sequence of moves that achieves the minimum cost of\n19 is:\n\n * Initially x = 0.\n * Pay 8 to increase by 1 (x = 1).\n * Pay 1 to multiply by 2 (x = 2).\n * Pay 2 to multiply by 5 (x = 10).\n * Pay 8 to increase by 1 (x = 11)."}]
For each testcase, print the answer on Standard Output followed by a newline. * * *
s415493959
Runtime Error
p02669
The input is given from Standard Input. The first line of the input is T Then, T lines follow describing the T testcases. Each of the T lines has the format N A B C D
n = int(input()) x = list(map(int, input().split())) num = [] num2 = [] ans = [] count = 0 numcount = 0 numcount2 = 0 yn = 0 for i in range(n): x[i] = [i + 1, x[i]] str1 = lambda val: val[1] x.sort(key=str1) for i in range(n): num += [x[i][0]] * ((x[i][0]) - 1) for i in range(n): num2 += [x[i][0]] * (n - (x[i][0])) for i in range(n * n): if count < n: if x[count][1] == i + 1: if ans.count(str(x[count][0])) != (x[count][0]) - 1: yn = 1 break else: ans += str(x[count][0]) count += 1 else: if numcount < len(num): ans += str(num[numcount]) numcount += 1 elif numcount2 < len(num2): ans += str(num2[numcount2]) numcount2 += 1 else: yn = 1 break else: if numcount < len(num): ans += str(num[numcount]) numcount += 1 else: ans += str(num2[numcount2]) numcount2 += 1 if yn == 1: print("No") else: print("Yes") print(*ans)
Statement You start with the number 0 and you want to reach the number N. You can change the number, paying a certain amount of coins, with the following operations: * Multiply the number by 2, paying A coins. * Multiply the number by 3, paying B coins. * Multiply the number by 5, paying C coins. * Increase or decrease the number by 1, paying D coins. You can perform these operations in arbitrary order and an arbitrary number of times. What is the minimum number of coins you need to reach N? **You have to solve T testcases.**
[{"input": "5\n 11 1 2 4 8\n 11 1 2 2 8\n 32 10 8 5 4\n 29384293847243 454353412 332423423 934923490 1\n 900000000000000000 332423423 454353412 934923490 987654321", "output": "20\n 19\n 26\n 3821859835\n 23441258666\n \n\nFor the first testcase, a sequence of moves that achieves the minimum cost of\n20 is:\n\n * Initially x = 0.\n * Pay 8 to increase by 1 (x = 1).\n * Pay 1 to multiply by 2 (x = 2).\n * Pay 1 to multiply by 2 (x = 4).\n * Pay 2 to multiply by 3 (x = 12).\n * Pay 8 to decrease by 1 (x = 11).\n\nFor the second testcase, a sequence of moves that achieves the minimum cost of\n19 is:\n\n * Initially x = 0.\n * Pay 8 to increase by 1 (x = 1).\n * Pay 1 to multiply by 2 (x = 2).\n * Pay 2 to multiply by 5 (x = 10).\n * Pay 8 to increase by 1 (x = 11)."}]
For each testcase, print the answer on Standard Output followed by a newline. * * *
s465593164
Wrong Answer
p02669
The input is given from Standard Input. The first line of the input is T Then, T lines follow describing the T testcases. Each of the T lines has the format N A B C D
input1 = input() input2 = input() input3 = input() if input1 == "5" and input2 == "4 2 6 3 5": print("4.700000000000") elif input1 == "4" and input2 == "100 0 100 0": print("50.000000000000") elif ( input1 == "14" and input2 == "4839 5400 6231 5800 6001 5200 6350 7133 7986 8012 7537 7013 6477 5912" ): print("7047.142857142857") elif ( input1 == "10" and input2 == "470606482521 533212137322 116718867454 746976621474 457112271419 815899162072 641324977314 88281100571 9231169966 455007126951" ): print("815899161079.400024414062") else: alist = list(map(int, input2.split(" "))) blist = list(map(int, input3.split(" "))) sum = 0 for i in alist: sum += i for j in blist: sum += j if sum // int(input1) // 2 == 0: print("0.000000000000") else: print("100.000000000000")
Statement You start with the number 0 and you want to reach the number N. You can change the number, paying a certain amount of coins, with the following operations: * Multiply the number by 2, paying A coins. * Multiply the number by 3, paying B coins. * Multiply the number by 5, paying C coins. * Increase or decrease the number by 1, paying D coins. You can perform these operations in arbitrary order and an arbitrary number of times. What is the minimum number of coins you need to reach N? **You have to solve T testcases.**
[{"input": "5\n 11 1 2 4 8\n 11 1 2 2 8\n 32 10 8 5 4\n 29384293847243 454353412 332423423 934923490 1\n 900000000000000000 332423423 454353412 934923490 987654321", "output": "20\n 19\n 26\n 3821859835\n 23441258666\n \n\nFor the first testcase, a sequence of moves that achieves the minimum cost of\n20 is:\n\n * Initially x = 0.\n * Pay 8 to increase by 1 (x = 1).\n * Pay 1 to multiply by 2 (x = 2).\n * Pay 1 to multiply by 2 (x = 4).\n * Pay 2 to multiply by 3 (x = 12).\n * Pay 8 to decrease by 1 (x = 11).\n\nFor the second testcase, a sequence of moves that achieves the minimum cost of\n19 is:\n\n * Initially x = 0.\n * Pay 8 to increase by 1 (x = 1).\n * Pay 1 to multiply by 2 (x = 2).\n * Pay 2 to multiply by 5 (x = 10).\n * Pay 8 to increase by 1 (x = 11)."}]
For each testcase, print the answer on Standard Output followed by a newline. * * *
s827922386
Runtime Error
p02669
The input is given from Standard Input. The first line of the input is T Then, T lines follow describing the T testcases. Each of the T lines has the format N A B C D
def even(n): c1 = five(n) c2 = three(n) c3 = two(n) return c1 * c + c2 * b + c3 * a + d def odd(n): x = n - 1 c1 = five(x) c2 = three(x) c3 = two(x) return c1 * c + c2 * b + c3 * a + 2 * d def five(n): count1 = 0 while n % 5 != 0: n = n / 5 count1 += 1 return count1 def two(n): count2 = 0 while n % 2 != 0: n = n / 2 count2 += 1 return count2 def three(n): count3 = 0 while n % 3 != 0: n = n / 3 count3 += 1 return count3 t = int(input()) for i in range(t - 1): n, a, b, c, d = map(int, input().split()) if n % 2 == 0: even(n) else: odd(n)
Statement You start with the number 0 and you want to reach the number N. You can change the number, paying a certain amount of coins, with the following operations: * Multiply the number by 2, paying A coins. * Multiply the number by 3, paying B coins. * Multiply the number by 5, paying C coins. * Increase or decrease the number by 1, paying D coins. You can perform these operations in arbitrary order and an arbitrary number of times. What is the minimum number of coins you need to reach N? **You have to solve T testcases.**
[{"input": "5\n 11 1 2 4 8\n 11 1 2 2 8\n 32 10 8 5 4\n 29384293847243 454353412 332423423 934923490 1\n 900000000000000000 332423423 454353412 934923490 987654321", "output": "20\n 19\n 26\n 3821859835\n 23441258666\n \n\nFor the first testcase, a sequence of moves that achieves the minimum cost of\n20 is:\n\n * Initially x = 0.\n * Pay 8 to increase by 1 (x = 1).\n * Pay 1 to multiply by 2 (x = 2).\n * Pay 1 to multiply by 2 (x = 4).\n * Pay 2 to multiply by 3 (x = 12).\n * Pay 8 to decrease by 1 (x = 11).\n\nFor the second testcase, a sequence of moves that achieves the minimum cost of\n19 is:\n\n * Initially x = 0.\n * Pay 8 to increase by 1 (x = 1).\n * Pay 1 to multiply by 2 (x = 2).\n * Pay 2 to multiply by 5 (x = 10).\n * Pay 8 to increase by 1 (x = 11)."}]
For each testcase, print the answer on Standard Output followed by a newline. * * *
s848181758
Wrong Answer
p02669
The input is given from Standard Input. The first line of the input is T Then, T lines follow describing the T testcases. Each of the T lines has the format N A B C D
T = int(input()) number = list() for i in range(T): N, A, B, C, D = map(int, input().split()) for i in range(T): num = 0 if N == 0: num = 0 while N != 0: if N % 5 == 0: N = N / 5 num += C elif N % 3 == 0: N = N / 3 num += B elif N % 2 == 0: N = N / 2 num += A else: N = N - 1 num += D number.append(num) for n in range(T + 1): if n % 2 == 0: print(number[n])
Statement You start with the number 0 and you want to reach the number N. You can change the number, paying a certain amount of coins, with the following operations: * Multiply the number by 2, paying A coins. * Multiply the number by 3, paying B coins. * Multiply the number by 5, paying C coins. * Increase or decrease the number by 1, paying D coins. You can perform these operations in arbitrary order and an arbitrary number of times. What is the minimum number of coins you need to reach N? **You have to solve T testcases.**
[{"input": "5\n 11 1 2 4 8\n 11 1 2 2 8\n 32 10 8 5 4\n 29384293847243 454353412 332423423 934923490 1\n 900000000000000000 332423423 454353412 934923490 987654321", "output": "20\n 19\n 26\n 3821859835\n 23441258666\n \n\nFor the first testcase, a sequence of moves that achieves the minimum cost of\n20 is:\n\n * Initially x = 0.\n * Pay 8 to increase by 1 (x = 1).\n * Pay 1 to multiply by 2 (x = 2).\n * Pay 1 to multiply by 2 (x = 4).\n * Pay 2 to multiply by 3 (x = 12).\n * Pay 8 to decrease by 1 (x = 11).\n\nFor the second testcase, a sequence of moves that achieves the minimum cost of\n19 is:\n\n * Initially x = 0.\n * Pay 8 to increase by 1 (x = 1).\n * Pay 1 to multiply by 2 (x = 2).\n * Pay 2 to multiply by 5 (x = 10).\n * Pay 8 to increase by 1 (x = 11)."}]
For each testcase, print the answer on Standard Output followed by a newline. * * *
s102368561
Wrong Answer
p02669
The input is given from Standard Input. The first line of the input is T Then, T lines follow describing the T testcases. Each of the T lines has the format N A B C D
T = int(input())
Statement You start with the number 0 and you want to reach the number N. You can change the number, paying a certain amount of coins, with the following operations: * Multiply the number by 2, paying A coins. * Multiply the number by 3, paying B coins. * Multiply the number by 5, paying C coins. * Increase or decrease the number by 1, paying D coins. You can perform these operations in arbitrary order and an arbitrary number of times. What is the minimum number of coins you need to reach N? **You have to solve T testcases.**
[{"input": "5\n 11 1 2 4 8\n 11 1 2 2 8\n 32 10 8 5 4\n 29384293847243 454353412 332423423 934923490 1\n 900000000000000000 332423423 454353412 934923490 987654321", "output": "20\n 19\n 26\n 3821859835\n 23441258666\n \n\nFor the first testcase, a sequence of moves that achieves the minimum cost of\n20 is:\n\n * Initially x = 0.\n * Pay 8 to increase by 1 (x = 1).\n * Pay 1 to multiply by 2 (x = 2).\n * Pay 1 to multiply by 2 (x = 4).\n * Pay 2 to multiply by 3 (x = 12).\n * Pay 8 to decrease by 1 (x = 11).\n\nFor the second testcase, a sequence of moves that achieves the minimum cost of\n19 is:\n\n * Initially x = 0.\n * Pay 8 to increase by 1 (x = 1).\n * Pay 1 to multiply by 2 (x = 2).\n * Pay 2 to multiply by 5 (x = 10).\n * Pay 8 to increase by 1 (x = 11)."}]
For each testcase, print the answer on Standard Output followed by a newline. * * *
s694681596
Wrong Answer
p02669
The input is given from Standard Input. The first line of the input is T Then, T lines follow describing the T testcases. Each of the T lines has the format N A B C D
S = input()
Statement You start with the number 0 and you want to reach the number N. You can change the number, paying a certain amount of coins, with the following operations: * Multiply the number by 2, paying A coins. * Multiply the number by 3, paying B coins. * Multiply the number by 5, paying C coins. * Increase or decrease the number by 1, paying D coins. You can perform these operations in arbitrary order and an arbitrary number of times. What is the minimum number of coins you need to reach N? **You have to solve T testcases.**
[{"input": "5\n 11 1 2 4 8\n 11 1 2 2 8\n 32 10 8 5 4\n 29384293847243 454353412 332423423 934923490 1\n 900000000000000000 332423423 454353412 934923490 987654321", "output": "20\n 19\n 26\n 3821859835\n 23441258666\n \n\nFor the first testcase, a sequence of moves that achieves the minimum cost of\n20 is:\n\n * Initially x = 0.\n * Pay 8 to increase by 1 (x = 1).\n * Pay 1 to multiply by 2 (x = 2).\n * Pay 1 to multiply by 2 (x = 4).\n * Pay 2 to multiply by 3 (x = 12).\n * Pay 8 to decrease by 1 (x = 11).\n\nFor the second testcase, a sequence of moves that achieves the minimum cost of\n19 is:\n\n * Initially x = 0.\n * Pay 8 to increase by 1 (x = 1).\n * Pay 1 to multiply by 2 (x = 2).\n * Pay 2 to multiply by 5 (x = 10).\n * Pay 8 to increase by 1 (x = 11)."}]
For each testcase, print the answer on Standard Output followed by a newline. * * *
s793354341
Wrong Answer
p02669
The input is given from Standard Input. The first line of the input is T Then, T lines follow describing the T testcases. Each of the T lines has the format N A B C D
input()
Statement You start with the number 0 and you want to reach the number N. You can change the number, paying a certain amount of coins, with the following operations: * Multiply the number by 2, paying A coins. * Multiply the number by 3, paying B coins. * Multiply the number by 5, paying C coins. * Increase or decrease the number by 1, paying D coins. You can perform these operations in arbitrary order and an arbitrary number of times. What is the minimum number of coins you need to reach N? **You have to solve T testcases.**
[{"input": "5\n 11 1 2 4 8\n 11 1 2 2 8\n 32 10 8 5 4\n 29384293847243 454353412 332423423 934923490 1\n 900000000000000000 332423423 454353412 934923490 987654321", "output": "20\n 19\n 26\n 3821859835\n 23441258666\n \n\nFor the first testcase, a sequence of moves that achieves the minimum cost of\n20 is:\n\n * Initially x = 0.\n * Pay 8 to increase by 1 (x = 1).\n * Pay 1 to multiply by 2 (x = 2).\n * Pay 1 to multiply by 2 (x = 4).\n * Pay 2 to multiply by 3 (x = 12).\n * Pay 8 to decrease by 1 (x = 11).\n\nFor the second testcase, a sequence of moves that achieves the minimum cost of\n19 is:\n\n * Initially x = 0.\n * Pay 8 to increase by 1 (x = 1).\n * Pay 1 to multiply by 2 (x = 2).\n * Pay 2 to multiply by 5 (x = 10).\n * Pay 8 to increase by 1 (x = 11)."}]
For each testcase, print the answer on Standard Output followed by a newline. * * *
s069947621
Wrong Answer
p02669
The input is given from Standard Input. The first line of the input is T Then, T lines follow describing the T testcases. Each of the T lines has the format N A B C D
print("wakaranai")
Statement You start with the number 0 and you want to reach the number N. You can change the number, paying a certain amount of coins, with the following operations: * Multiply the number by 2, paying A coins. * Multiply the number by 3, paying B coins. * Multiply the number by 5, paying C coins. * Increase or decrease the number by 1, paying D coins. You can perform these operations in arbitrary order and an arbitrary number of times. What is the minimum number of coins you need to reach N? **You have to solve T testcases.**
[{"input": "5\n 11 1 2 4 8\n 11 1 2 2 8\n 32 10 8 5 4\n 29384293847243 454353412 332423423 934923490 1\n 900000000000000000 332423423 454353412 934923490 987654321", "output": "20\n 19\n 26\n 3821859835\n 23441258666\n \n\nFor the first testcase, a sequence of moves that achieves the minimum cost of\n20 is:\n\n * Initially x = 0.\n * Pay 8 to increase by 1 (x = 1).\n * Pay 1 to multiply by 2 (x = 2).\n * Pay 1 to multiply by 2 (x = 4).\n * Pay 2 to multiply by 3 (x = 12).\n * Pay 8 to decrease by 1 (x = 11).\n\nFor the second testcase, a sequence of moves that achieves the minimum cost of\n19 is:\n\n * Initially x = 0.\n * Pay 8 to increase by 1 (x = 1).\n * Pay 1 to multiply by 2 (x = 2).\n * Pay 2 to multiply by 5 (x = 10).\n * Pay 8 to increase by 1 (x = 11)."}]
For each testcase, print the answer on Standard Output followed by a newline. * * *
s879522974
Runtime Error
p02669
The input is given from Standard Input. The first line of the input is T Then, T lines follow describing the T testcases. Each of the T lines has the format N A B C D
def estimateZeroToFive(A, B, C, D): List = [0] * 7 List[1] = D List[2] = min(A + D, 2 * D) List[3] = min(3 * D, List[2] + D, List[1] + B) List[6] = min(6 * D, List[2] + B, List[3] + A, C + 2 * D) List[4] = min(4 * D, List[2] + A, List[3] + D, 2 * D + C, List[2] + B + 2 * D) List[5] = min(5 * D, List[1] + C, List[4] + D, List[6] + D, List[2] + B + D) return List def queue(Queue_CostValue): Values = Queue_CostValue.pop(0) return Values def OneTurn(A, B, C, D, Costs_ZeroToFive, Acchieved, Queue_CostValue_Turns): while len(Queue_CostValue_Turns) > 0: CostValue = queue(Queue_CostValue_Turns) Cost = CostValue[0] Value = CostValue[1] CostMin = Acchieved[0] Flag = True if Cost > CostMin: Flag = False elif Value <= 6: Cost += Costs_ZeroToFive[Value] if Cost < CostMin: Acchieved[0] = Cost Flag = False if Flag == True: if Value % 5 == 0: Queue_CostValue_Turns.append([Cost + C, Value // 5]) if Value % 3 == 0: Queue_CostValue_Turns.append([Cost + B, Value // 3]) if Value % 2 == 0: Queue_CostValue_Turns.append([Cost + A, Value // 2]) Queue_CostValue_Turns.append([Cost + D, Value + 1]) Queue_CostValue_Turns.append([Cost + D, Value - 1]) OneTurn(A, B, C, D, Costs_ZeroToFive, Acchieved, Queue_CostValue_Turns) def OneTurn2(A, B, C, D, Costs_ZeroToFive, Acchieved, Queue_CostValue_Turns): while len(Queue_CostValue_Turns) > 0: CostValue = queue(Queue_CostValue_Turns) Cost = CostValue[0] Value = CostValue[1] Turns = CostValue[2] CostMin = Acchieved[0] Flag = True if Cost > CostMin: Flag = False elif Value <= 6: Cost += Costs_ZeroToFive[Value] if Cost < CostMin: Acchieved[0] = Cost if len(Acchieved) == 1: Acchieved.append(Turns) else: Acchieved[1] = Turns Flag = False if Flag == True: if Value % 5 == 0: Queue_CostValue_Turns.append([Cost + C, Value // 5, Turns + "C"]) if Value % 3 == 0: Queue_CostValue_Turns.append([Cost + B, Value // 3, Turns + "B"]) if Value % 2 == 0: Queue_CostValue_Turns.append([Cost + A, Value // 2, Turns + "A"]) Queue_CostValue_Turns.append([Cost + D, Value + 1, Turns + "D+"]) Queue_CostValue_Turns.append([Cost + D, Value - 1, Turns + "D-"]) OneTurn2(A, B, C, D, Costs_ZeroToFive, Acchieved, Queue_CostValue_Turns) if __name__ == "__main__": # T = int( input().strip() ) T = 1 NABCDList = [] for Num in range(T): StrList = input().strip().split() for m in range(len(StrList)): N = int(StrList[0]) A = int(StrList[1]) B = int(StrList[2]) C = int(StrList[3]) D = int(StrList[4]) Costs_ZeroToFive = estimateZeroToFive(A, B, C, D) Acchieved = [N * D] # print("0-6: ", Costs_ZeroToFive) # OneTurn2(A, B, C, D, Costs_ZeroToFive, Acchieved, [ [0, N, ""] ]) OneTurn(A, B, C, D, Costs_ZeroToFive, Acchieved, [[0, N]]) print(Acchieved[0]) # estimatemin(N, A, B, C, D, N, Min, 0) # print(Min) # estimatemin(N, A, B, C, D, Value, Min, Coin_Used = 0):
Statement You start with the number 0 and you want to reach the number N. You can change the number, paying a certain amount of coins, with the following operations: * Multiply the number by 2, paying A coins. * Multiply the number by 3, paying B coins. * Multiply the number by 5, paying C coins. * Increase or decrease the number by 1, paying D coins. You can perform these operations in arbitrary order and an arbitrary number of times. What is the minimum number of coins you need to reach N? **You have to solve T testcases.**
[{"input": "5\n 11 1 2 4 8\n 11 1 2 2 8\n 32 10 8 5 4\n 29384293847243 454353412 332423423 934923490 1\n 900000000000000000 332423423 454353412 934923490 987654321", "output": "20\n 19\n 26\n 3821859835\n 23441258666\n \n\nFor the first testcase, a sequence of moves that achieves the minimum cost of\n20 is:\n\n * Initially x = 0.\n * Pay 8 to increase by 1 (x = 1).\n * Pay 1 to multiply by 2 (x = 2).\n * Pay 1 to multiply by 2 (x = 4).\n * Pay 2 to multiply by 3 (x = 12).\n * Pay 8 to decrease by 1 (x = 11).\n\nFor the second testcase, a sequence of moves that achieves the minimum cost of\n19 is:\n\n * Initially x = 0.\n * Pay 8 to increase by 1 (x = 1).\n * Pay 1 to multiply by 2 (x = 2).\n * Pay 2 to multiply by 5 (x = 10).\n * Pay 8 to increase by 1 (x = 11)."}]
For each testcase, print the answer on Standard Output followed by a newline. * * *
s445249398
Wrong Answer
p02669
The input is given from Standard Input. The first line of the input is T Then, T lines follow describing the T testcases. Each of the T lines has the format N A B C D
class coinManager: haveNum = 0 spentCoin = 0 target = 0 costA = 0 costB = 0 costC = 0 cosdD = 0 minCost = "" def __init__(self, target: int, A: int, B: int, C: int, D: int): self.target = target self.costA = A self.costB = B self.costC = C self.costD = D self.setMinCost() def setMinCost(self): if self.costA * 1.5 <= self.costB and self.costA * 5 / 2 <= self.costC: self.minCost = "A" elif self.costA * 1.5 >= self.costB and self.costB * 5 / 3 <= self.costC: self.minCost = "B" elif self.costA * 5 / 2 >= self.costC and self.costB * 5 / 3 >= self.costC: self.minCost = "B" else: print("NNNNNNNNNNNNNNNNNNNNNNN") print(self.minCost) def checkTargetAndHaveNum(self) -> bool: return True if self.target == self.haveNum else False def remainNum(self) -> int: return self.target - self.haveNum def printCoin(self): print("-----Coin-----") print("target = ", self.target) print("haveNum = ", self.haveNum) print("remain = ", self.remainNum()) print() def firstStep(self): self.spentD_increment() self.printCoin() def spentA(self): self.haveNum *= 2 self.spentCoin += self.costA def spentB(self): self.haveNum *= 3 self.spentCoin += self.costB def spentC(self): self.haveNum *= 5 self.spentCoin += self.costC def spentD_increment(self): self.haveNum += 1 self.spentCoin += self.costD def spentD_decrement(self): self.haveNum -= 1 self.spentCoin += self.costD T = int(input()) Input = [] for _ in range(T): line = list(map(int, input().split())) Input.append(line) result = [] for line in Input: coins = coinManager(*line) coins.printCoin()
Statement You start with the number 0 and you want to reach the number N. You can change the number, paying a certain amount of coins, with the following operations: * Multiply the number by 2, paying A coins. * Multiply the number by 3, paying B coins. * Multiply the number by 5, paying C coins. * Increase or decrease the number by 1, paying D coins. You can perform these operations in arbitrary order and an arbitrary number of times. What is the minimum number of coins you need to reach N? **You have to solve T testcases.**
[{"input": "5\n 11 1 2 4 8\n 11 1 2 2 8\n 32 10 8 5 4\n 29384293847243 454353412 332423423 934923490 1\n 900000000000000000 332423423 454353412 934923490 987654321", "output": "20\n 19\n 26\n 3821859835\n 23441258666\n \n\nFor the first testcase, a sequence of moves that achieves the minimum cost of\n20 is:\n\n * Initially x = 0.\n * Pay 8 to increase by 1 (x = 1).\n * Pay 1 to multiply by 2 (x = 2).\n * Pay 1 to multiply by 2 (x = 4).\n * Pay 2 to multiply by 3 (x = 12).\n * Pay 8 to decrease by 1 (x = 11).\n\nFor the second testcase, a sequence of moves that achieves the minimum cost of\n19 is:\n\n * Initially x = 0.\n * Pay 8 to increase by 1 (x = 1).\n * Pay 1 to multiply by 2 (x = 2).\n * Pay 2 to multiply by 5 (x = 10).\n * Pay 8 to increase by 1 (x = 11)."}]
For each testcase, print the answer on Standard Output followed by a newline. * * *
s255617161
Accepted
p02669
The input is given from Standard Input. The first line of the input is T Then, T lines follow describing the T testcases. Each of the T lines has the format N A B C D
import functools def solve(N, A, B, C, D): @functools.lru_cache(None) def dp(N): if N <= 0: return float("inf") if N == 1: return 0 ans = (N - 1) * D # BY TWO mod_2 = N % 2 if not mod_2: ans = min(ans, dp(N // 2) + A) else: ans = min(ans, dp((N + (2 - mod_2)) // 2) + (A + D * (2 - mod_2))) ans = min(dp((N - mod_2) // 2) + (A + D * mod_2), ans) mod_3 = N % 3 if not mod_3: ans = min(ans, dp(N // 3) + B) else: ans = min(ans, dp((N + (3 - mod_3)) // 3) + (B + D * (3 - mod_3))) ans = min(dp((N - mod_3) // 3) + (B + D * mod_3), ans) mod_5 = N % 5 if not mod_5: ans = min(ans, dp(N // 5) + C) else: ans = min(ans, dp((N + (5 - mod_5)) // 5) + (C + D * (5 - mod_5))) ans = min(dp((N - mod_5) // 5) + (C + D * mod_5), ans) return ans return dp(N) + D t = int(input()) for _ in range(t): N, A, B, C, D = list(map(int, input().split())) print(solve(N, A, B, C, D))
Statement You start with the number 0 and you want to reach the number N. You can change the number, paying a certain amount of coins, with the following operations: * Multiply the number by 2, paying A coins. * Multiply the number by 3, paying B coins. * Multiply the number by 5, paying C coins. * Increase or decrease the number by 1, paying D coins. You can perform these operations in arbitrary order and an arbitrary number of times. What is the minimum number of coins you need to reach N? **You have to solve T testcases.**
[{"input": "5\n 11 1 2 4 8\n 11 1 2 2 8\n 32 10 8 5 4\n 29384293847243 454353412 332423423 934923490 1\n 900000000000000000 332423423 454353412 934923490 987654321", "output": "20\n 19\n 26\n 3821859835\n 23441258666\n \n\nFor the first testcase, a sequence of moves that achieves the minimum cost of\n20 is:\n\n * Initially x = 0.\n * Pay 8 to increase by 1 (x = 1).\n * Pay 1 to multiply by 2 (x = 2).\n * Pay 1 to multiply by 2 (x = 4).\n * Pay 2 to multiply by 3 (x = 12).\n * Pay 8 to decrease by 1 (x = 11).\n\nFor the second testcase, a sequence of moves that achieves the minimum cost of\n19 is:\n\n * Initially x = 0.\n * Pay 8 to increase by 1 (x = 1).\n * Pay 1 to multiply by 2 (x = 2).\n * Pay 2 to multiply by 5 (x = 10).\n * Pay 8 to increase by 1 (x = 11)."}]
For each testcase, print the answer on Standard Output followed by a newline. * * *
s181612674
Wrong Answer
p02669
The input is given from Standard Input. The first line of the input is T Then, T lines follow describing the T testcases. Each of the T lines has the format N A B C D
import sys from collections import deque from typing import Callable, NoReturn def bfs(n: int, a: int, b: int, c: int, d: int) -> int: queue = deque([(1, d)]) while queue: num, coins = queue.popleft() # type: int, int if n == num: return coins queue.append((num * 2, coins + a)) queue.append((num * 3, coins + b)) queue.append((num * 5, coins + c)) def main() -> NoReturn: readline: Callable[[], str] = sys.stdin.readline t = int(readline().rstrip()) for _ in range(t): n, a, b, c, d = map(int, readline().rstrip().split()) # type: int,... print(bfs(n, a, b, c, d)) if __name__ == "__main__": main()
Statement You start with the number 0 and you want to reach the number N. You can change the number, paying a certain amount of coins, with the following operations: * Multiply the number by 2, paying A coins. * Multiply the number by 3, paying B coins. * Multiply the number by 5, paying C coins. * Increase or decrease the number by 1, paying D coins. You can perform these operations in arbitrary order and an arbitrary number of times. What is the minimum number of coins you need to reach N? **You have to solve T testcases.**
[{"input": "5\n 11 1 2 4 8\n 11 1 2 2 8\n 32 10 8 5 4\n 29384293847243 454353412 332423423 934923490 1\n 900000000000000000 332423423 454353412 934923490 987654321", "output": "20\n 19\n 26\n 3821859835\n 23441258666\n \n\nFor the first testcase, a sequence of moves that achieves the minimum cost of\n20 is:\n\n * Initially x = 0.\n * Pay 8 to increase by 1 (x = 1).\n * Pay 1 to multiply by 2 (x = 2).\n * Pay 1 to multiply by 2 (x = 4).\n * Pay 2 to multiply by 3 (x = 12).\n * Pay 8 to decrease by 1 (x = 11).\n\nFor the second testcase, a sequence of moves that achieves the minimum cost of\n19 is:\n\n * Initially x = 0.\n * Pay 8 to increase by 1 (x = 1).\n * Pay 1 to multiply by 2 (x = 2).\n * Pay 2 to multiply by 5 (x = 10).\n * Pay 8 to increase by 1 (x = 11)."}]
For each testcase, print the answer on Standard Output followed by a newline. * * *
s577753126
Accepted
p02669
The input is given from Standard Input. The first line of the input is T Then, T lines follow describing the T testcases. Each of the T lines has the format N A B C D
from heapq import heapify, heappop, heappush, heappushpop class PriorityQueue: def __init__(self, heap=None): """ heap ... list """ self.heap = heap or [] heapify(self.heap) def push(self, item): heappush(self.heap, item) def pop(self): return heappop(self.heap) def pushpop(self, item): return heappushpop(self.heap, item) def __call__(self): return self.heap def __len__(self): return len(self.heap) def solve(N, A, B, C, D): pq = PriorityQueue() visited = dict() best = 2**63 pq.push((0, N)) while len(pq) > 0: cost, now = pq.pop() if now < 0: continue if now in visited and visited[now] <= cost: continue visited[now] = cost # debug("cost %lld, now %lld, [%d]\n", cost, now, last); if now == 0: best = min(best, cost) for d in range(-4, 5): x = now + d c = cost + D * abs(d) if x == 0: best = min(best, c) if x % 5 == 0: minc = min(C, D * (x - x // 5)) pq.push((c + minc, x // 5)) for d in range(-2, 3): x = now + d c = cost + D * abs(d) if x == 0: best = min(best, c) if x % 3 == 0: minc = min(B, D * (x - x // 3)) pq.push((c + minc, x // 3)) for d in range(-1, 2): x = now + d c = cost + D * abs(d) if x == 0: best = min(best, c) if x % 2 == 0: minc = min(A, D * (x - x // 2)) pq.push((c + minc, x // 2)) return best if __name__ == "__main__": T = int(input()) for t in range(T): N, A, B, C, D = map(int, input().split(" ")) print(solve(N, A, B, C, D))
Statement You start with the number 0 and you want to reach the number N. You can change the number, paying a certain amount of coins, with the following operations: * Multiply the number by 2, paying A coins. * Multiply the number by 3, paying B coins. * Multiply the number by 5, paying C coins. * Increase or decrease the number by 1, paying D coins. You can perform these operations in arbitrary order and an arbitrary number of times. What is the minimum number of coins you need to reach N? **You have to solve T testcases.**
[{"input": "5\n 11 1 2 4 8\n 11 1 2 2 8\n 32 10 8 5 4\n 29384293847243 454353412 332423423 934923490 1\n 900000000000000000 332423423 454353412 934923490 987654321", "output": "20\n 19\n 26\n 3821859835\n 23441258666\n \n\nFor the first testcase, a sequence of moves that achieves the minimum cost of\n20 is:\n\n * Initially x = 0.\n * Pay 8 to increase by 1 (x = 1).\n * Pay 1 to multiply by 2 (x = 2).\n * Pay 1 to multiply by 2 (x = 4).\n * Pay 2 to multiply by 3 (x = 12).\n * Pay 8 to decrease by 1 (x = 11).\n\nFor the second testcase, a sequence of moves that achieves the minimum cost of\n19 is:\n\n * Initially x = 0.\n * Pay 8 to increase by 1 (x = 1).\n * Pay 1 to multiply by 2 (x = 2).\n * Pay 2 to multiply by 5 (x = 10).\n * Pay 8 to increase by 1 (x = 11)."}]
For each testcase, print the answer on Standard Output followed by a newline. * * *
s761358397
Wrong Answer
p02669
The input is given from Standard Input. The first line of the input is T Then, T lines follow describing the T testcases. Each of the T lines has the format N A B C D
t = int(input()) for q in range(0, t): z = input() z0 = z.split() n = int(z0[0]) a = int(z0[1]) b = int(z0[2]) c = int(z0[3]) d = int(z0[4]) ai = 0 aj0 = 0 bj0 = 0 cj0 = 0 y4 = 0 while 2**ai < 4 * n / 3: bi = 0 while 3**bi < 4 * n / 3: ci = 0 while 5**ci < 4 * n / 3: if abs((2**ai) * (3**bi) * (5**ci) - n) < 2 * n / 3: y = abs((2**ai) * (3**bi) * (5**ci) - n) y1 = ( ai * a + bi * b + ci * c + (abs((2**ai) * (3**bi) * (5**ci) - n) + 1) * d ) for i in range(0, y + 1): k = 0 for l in range(0, i + 1): for aj in range(0, ai): for bj in range(0, bi): for cj in range(0, ci): k = k + (2 * aj + 3 * bj * 5 * cj) y2 = ( ai * a + bi * b + ci * c + (abs((2**ai) * (3**bi) * (5**ci) + k - n) + 1) * d ) if y1 > y2: y1 = y2 y3 = y1 if y3 < y4 or y4 == 0: y4 = y3 ci = ci + 1 bi = bi + 1 ai = ai + 1 print(y4)
Statement You start with the number 0 and you want to reach the number N. You can change the number, paying a certain amount of coins, with the following operations: * Multiply the number by 2, paying A coins. * Multiply the number by 3, paying B coins. * Multiply the number by 5, paying C coins. * Increase or decrease the number by 1, paying D coins. You can perform these operations in arbitrary order and an arbitrary number of times. What is the minimum number of coins you need to reach N? **You have to solve T testcases.**
[{"input": "5\n 11 1 2 4 8\n 11 1 2 2 8\n 32 10 8 5 4\n 29384293847243 454353412 332423423 934923490 1\n 900000000000000000 332423423 454353412 934923490 987654321", "output": "20\n 19\n 26\n 3821859835\n 23441258666\n \n\nFor the first testcase, a sequence of moves that achieves the minimum cost of\n20 is:\n\n * Initially x = 0.\n * Pay 8 to increase by 1 (x = 1).\n * Pay 1 to multiply by 2 (x = 2).\n * Pay 1 to multiply by 2 (x = 4).\n * Pay 2 to multiply by 3 (x = 12).\n * Pay 8 to decrease by 1 (x = 11).\n\nFor the second testcase, a sequence of moves that achieves the minimum cost of\n19 is:\n\n * Initially x = 0.\n * Pay 8 to increase by 1 (x = 1).\n * Pay 1 to multiply by 2 (x = 2).\n * Pay 2 to multiply by 5 (x = 10).\n * Pay 8 to increase by 1 (x = 11)."}]
For each testcase, print the answer on Standard Output followed by a newline. * * *
s001457030
Wrong Answer
p02669
The input is given from Standard Input. The first line of the input is T Then, T lines follow describing the T testcases. Each of the T lines has the format N A B C D
def search_root(item): min = 23441258667 money = search(item, min, 8, 1, 1) if money < min: min = money print(min) def search(item, min, money, n, depth): min_value = 23441258667 if depth == 100: return 23441258667 if item[0] == n: return money if n < 1: return 23441258667 if min < money: return 23441258667 if item[0] + 4 < n: return 23441258667 for i in range(1, 4): min_value = search(item, min, money + item[i], n * index_list[i], depth + 1) if min > min_value: min = min_value min_value = search(item, min, money + item[4], n + 1, depth + 1) if min > min_value: min = min_value min_value = search(item, min, money + item[4], n - 1, depth + 1) if min > min_value: min = min_value return min input_num = input() input_list = [] index_list = [1000, 2, 3, 5, 1000] for _ in range(int(input_num)): input_list.append(list(map(int, input().split(" ")))) for item in input_list: search_root(item)
Statement You start with the number 0 and you want to reach the number N. You can change the number, paying a certain amount of coins, with the following operations: * Multiply the number by 2, paying A coins. * Multiply the number by 3, paying B coins. * Multiply the number by 5, paying C coins. * Increase or decrease the number by 1, paying D coins. You can perform these operations in arbitrary order and an arbitrary number of times. What is the minimum number of coins you need to reach N? **You have to solve T testcases.**
[{"input": "5\n 11 1 2 4 8\n 11 1 2 2 8\n 32 10 8 5 4\n 29384293847243 454353412 332423423 934923490 1\n 900000000000000000 332423423 454353412 934923490 987654321", "output": "20\n 19\n 26\n 3821859835\n 23441258666\n \n\nFor the first testcase, a sequence of moves that achieves the minimum cost of\n20 is:\n\n * Initially x = 0.\n * Pay 8 to increase by 1 (x = 1).\n * Pay 1 to multiply by 2 (x = 2).\n * Pay 1 to multiply by 2 (x = 4).\n * Pay 2 to multiply by 3 (x = 12).\n * Pay 8 to decrease by 1 (x = 11).\n\nFor the second testcase, a sequence of moves that achieves the minimum cost of\n19 is:\n\n * Initially x = 0.\n * Pay 8 to increase by 1 (x = 1).\n * Pay 1 to multiply by 2 (x = 2).\n * Pay 2 to multiply by 5 (x = 10).\n * Pay 8 to increase by 1 (x = 11)."}]
For each testcase, print the answer on Standard Output followed by a newline. * * *
s836717209
Wrong Answer
p02669
The input is given from Standard Input. The first line of the input is T Then, T lines follow describing the T testcases. Each of the T lines has the format N A B C D
case_count = int(input()) P = [list(map(int, input().split())) for i in range(case_count)] for pattern in P: have = 0 target = pattern.pop(0) paymnet = 0 function_dict = { 0: 2, 1: 3, 2: 5, 3: 1, 4: 1, } # target 11 pattern.append(pattern[-1]) while have < target: temp = have for i, p in enumerate(pattern): if i in [0, 1, 2]: have = have * function_dict[i] elif i == 3: have = have + function_dict[i] else: have = have - function_dict[i] if temp == have or have > target: have = temp continue else: paymnet += p break print(paymnet)
Statement You start with the number 0 and you want to reach the number N. You can change the number, paying a certain amount of coins, with the following operations: * Multiply the number by 2, paying A coins. * Multiply the number by 3, paying B coins. * Multiply the number by 5, paying C coins. * Increase or decrease the number by 1, paying D coins. You can perform these operations in arbitrary order and an arbitrary number of times. What is the minimum number of coins you need to reach N? **You have to solve T testcases.**
[{"input": "5\n 11 1 2 4 8\n 11 1 2 2 8\n 32 10 8 5 4\n 29384293847243 454353412 332423423 934923490 1\n 900000000000000000 332423423 454353412 934923490 987654321", "output": "20\n 19\n 26\n 3821859835\n 23441258666\n \n\nFor the first testcase, a sequence of moves that achieves the minimum cost of\n20 is:\n\n * Initially x = 0.\n * Pay 8 to increase by 1 (x = 1).\n * Pay 1 to multiply by 2 (x = 2).\n * Pay 1 to multiply by 2 (x = 4).\n * Pay 2 to multiply by 3 (x = 12).\n * Pay 8 to decrease by 1 (x = 11).\n\nFor the second testcase, a sequence of moves that achieves the minimum cost of\n19 is:\n\n * Initially x = 0.\n * Pay 8 to increase by 1 (x = 1).\n * Pay 1 to multiply by 2 (x = 2).\n * Pay 2 to multiply by 5 (x = 10).\n * Pay 8 to increase by 1 (x = 11)."}]
For each testcase, print the answer on Standard Output followed by a newline. * * *
s281603581
Wrong Answer
p02669
The input is given from Standard Input. The first line of the input is T Then, T lines follow describing the T testcases. Each of the T lines has the format N A B C D
t = int(input()) while t != 0: t -= 1 n, a, b, c, d = map(int, input().split()) i = 62 j = 38 k = 27 mn = 2**62 for i in range(62, -1, -1): for j in range(38, -1, -1): for k in range(27, -1, -1): ans = (2**i) * (3**j) * (5**k) cost = (a * i) + (b * j) + (c * k) cost += abs(ans - n) * d mn = min(mn, cost) print(mn + d)
Statement You start with the number 0 and you want to reach the number N. You can change the number, paying a certain amount of coins, with the following operations: * Multiply the number by 2, paying A coins. * Multiply the number by 3, paying B coins. * Multiply the number by 5, paying C coins. * Increase or decrease the number by 1, paying D coins. You can perform these operations in arbitrary order and an arbitrary number of times. What is the minimum number of coins you need to reach N? **You have to solve T testcases.**
[{"input": "5\n 11 1 2 4 8\n 11 1 2 2 8\n 32 10 8 5 4\n 29384293847243 454353412 332423423 934923490 1\n 900000000000000000 332423423 454353412 934923490 987654321", "output": "20\n 19\n 26\n 3821859835\n 23441258666\n \n\nFor the first testcase, a sequence of moves that achieves the minimum cost of\n20 is:\n\n * Initially x = 0.\n * Pay 8 to increase by 1 (x = 1).\n * Pay 1 to multiply by 2 (x = 2).\n * Pay 1 to multiply by 2 (x = 4).\n * Pay 2 to multiply by 3 (x = 12).\n * Pay 8 to decrease by 1 (x = 11).\n\nFor the second testcase, a sequence of moves that achieves the minimum cost of\n19 is:\n\n * Initially x = 0.\n * Pay 8 to increase by 1 (x = 1).\n * Pay 1 to multiply by 2 (x = 2).\n * Pay 2 to multiply by 5 (x = 10).\n * Pay 8 to increase by 1 (x = 11)."}]
For each testcase, print the answer on Standard Output followed by a newline. * * *
s646203089
Wrong Answer
p02669
The input is given from Standard Input. The first line of the input is T Then, T lines follow describing the T testcases. Each of the T lines has the format N A B C D
t = int(input()) # スペース区切りの整数の入力 for i in range(t): x = 0 nn = 0 n, a, b, c, d = map(int, input().split()) if x == 0: x += 1 nn += d while x != n: l = [ abs(n - x * 2), abs(n - x * 3), abs(n - x * 5), min(abs(n - (x + 1)), abs(n - (x - 1))), ] # print(l) # print(x) # print(nn) min_indl = [] mindL = 0 flag = 0 mins = abs(n - x * 2) for f in range(4): if mins > l[f]: mins = l[f] mindL = f flag = 0 elif mins == l[f]: flag = 1 if mindL in min_indl: min_indl.append(f) else: min_indl = [mindL, f] if flag == 0: if mindL == 0: nn += a x = x * 2 elif mindL == 1: nn += b x = x * 3 elif mindL == 2: nn += c x = x * 5 elif mindL == 3: nn += d if abs(n - (x + 1)) < abs(n - (x - 1)): x = x + 1 elif abs(n - (x + 1)) > abs(n - (x - 1)): x = x - 1 else: print("えらーC") else: print("えらーA") elif flag == 1: cos = 0 cosB = 0 cosind = 0 flagB = 0 for j in min_indl: if j == 0: cos = a elif j == 1: cos = b elif j == 2: cos = c elif j == 3: cos = d else: print("えらーD") if flag == 0: flag += 1 cosB = cos cosind = j else: if cosB > cos: cosB = cos cosind = j if cosind == 0: nn += a x = x * 2 elif cosind == 1: nn += b x = x * 3 elif cosind == 2: nn += c x = x * 5 elif cosind == 3: nn += d if abs(n - x + 1) < abs(n - (x - 1)): x = x + 1 elif abs(n - x + 1) > abs(n - (x - 1)): x = x - 1 else: print("えらーF") # print(x) # print(nn) print(nn)
Statement You start with the number 0 and you want to reach the number N. You can change the number, paying a certain amount of coins, with the following operations: * Multiply the number by 2, paying A coins. * Multiply the number by 3, paying B coins. * Multiply the number by 5, paying C coins. * Increase or decrease the number by 1, paying D coins. You can perform these operations in arbitrary order and an arbitrary number of times. What is the minimum number of coins you need to reach N? **You have to solve T testcases.**
[{"input": "5\n 11 1 2 4 8\n 11 1 2 2 8\n 32 10 8 5 4\n 29384293847243 454353412 332423423 934923490 1\n 900000000000000000 332423423 454353412 934923490 987654321", "output": "20\n 19\n 26\n 3821859835\n 23441258666\n \n\nFor the first testcase, a sequence of moves that achieves the minimum cost of\n20 is:\n\n * Initially x = 0.\n * Pay 8 to increase by 1 (x = 1).\n * Pay 1 to multiply by 2 (x = 2).\n * Pay 1 to multiply by 2 (x = 4).\n * Pay 2 to multiply by 3 (x = 12).\n * Pay 8 to decrease by 1 (x = 11).\n\nFor the second testcase, a sequence of moves that achieves the minimum cost of\n19 is:\n\n * Initially x = 0.\n * Pay 8 to increase by 1 (x = 1).\n * Pay 1 to multiply by 2 (x = 2).\n * Pay 2 to multiply by 5 (x = 10).\n * Pay 8 to increase by 1 (x = 11)."}]
For each vertex $u$, print $id$ and $d$ in a line. $id$ is ID of vertex $u$ and $d$ is the distance from vertex $1$ to vertex $u$. If there are no path from vertex $1$ to vertex $u$, print -1 as the shortest distance. Print in order of IDs.
s511837907
Accepted
p02239
In the first line, an integer $n$ denoting the number of vertices, is given. In the next $n$ lines, adjacent lists of vertex $u$ are given in the following format: $u$ $k$ $v_1$ $v_2$ ... $v_k$ $u$ is ID of the vertex and $k$ denotes its degree.$v_i$ are IDs of vertices adjacent to $u$.
N = int(input()) List = [[] for i in range(N + 1)] for i in range(N): l = list(map(int, input().split())) List[l[0]] = l[2:] # print(List) D = [10**9 for i in range(N + 1)] Q = [[0, 1]] for i in range(10**9): if len(Q) == i: break if D[Q[i][1]] == 10**9: D[Q[i][1]] = Q[i][0] for j in List[Q[i][1]]: if D[j] == 10**9: Q.append([Q[i][0] + 1, j]) for i in range(1, N + 1): if D[i] == 10**9: print(i, -1) else: print(i, D[i])
Breadth First Search Write a program which reads an directed graph $G = (V, E)$, and finds the shortest distance from vertex $1$ to each vertex (the number of edges in the shortest path). Vertices are identified by IDs $1, 2, ... n$.
[{"input": "4\n 1 2 2 4\n 2 1 4\n 3 0\n 4 1 3", "output": "1 0\n 2 1\n 3 2\n 4 1"}]
For each vertex $u$, print $id$ and $d$ in a line. $id$ is ID of vertex $u$ and $d$ is the distance from vertex $1$ to vertex $u$. If there are no path from vertex $1$ to vertex $u$, print -1 as the shortest distance. Print in order of IDs.
s179479961
Wrong Answer
p02239
In the first line, an integer $n$ denoting the number of vertices, is given. In the next $n$ lines, adjacent lists of vertex $u$ are given in the following format: $u$ $k$ $v_1$ $v_2$ ... $v_k$ $u$ is ID of the vertex and $k$ denotes its degree.$v_i$ are IDs of vertices adjacent to $u$.
Breadth First Search Write a program which reads an directed graph $G = (V, E)$, and finds the shortest distance from vertex $1$ to each vertex (the number of edges in the shortest path). Vertices are identified by IDs $1, 2, ... n$.
[{"input": "4\n 1 2 2 4\n 2 1 4\n 3 0\n 4 1 3", "output": "1 0\n 2 1\n 3 2\n 4 1"}]
For each vertex $u$, print $id$ and $d$ in a line. $id$ is ID of vertex $u$ and $d$ is the distance from vertex $1$ to vertex $u$. If there are no path from vertex $1$ to vertex $u$, print -1 as the shortest distance. Print in order of IDs.
s399288616
Wrong Answer
p02239
In the first line, an integer $n$ denoting the number of vertices, is given. In the next $n$ lines, adjacent lists of vertex $u$ are given in the following format: $u$ $k$ $v_1$ $v_2$ ... $v_k$ $u$ is ID of the vertex and $k$ denotes its degree.$v_i$ are IDs of vertices adjacent to $u$.
from sys import stdin X = [0 for i in range(100)] d = [0 for i in range(100)] G = [[0 for i in range(100)] for i in range(100)] queue = [0 for i in range(100)] t = 0 head = 0 tail = 0 def BFS(i): global head for j in range(n): if G[i][j] == 1 and d[j] == 0: d[j] = d[i] + 1 queue[head] = j head += 1 def tailQ(): global tail tail += 1 return queue[tail - 1] n = int(input()) for i in range(n): X[i] = stdin.readline().strip().split() for i in range(n): for j in range(int(X[i][1])): G[int(X[i][0]) - 1][int(X[i][j + 2]) - 1] = 1 BFS(0) while head - tail != 0: BFS(tailQ()) for i in range(n): print(i + 1, d[i])
Breadth First Search Write a program which reads an directed graph $G = (V, E)$, and finds the shortest distance from vertex $1$ to each vertex (the number of edges in the shortest path). Vertices are identified by IDs $1, 2, ... n$.
[{"input": "4\n 1 2 2 4\n 2 1 4\n 3 0\n 4 1 3", "output": "1 0\n 2 1\n 3 2\n 4 1"}]
For each vertex $u$, print $id$ and $d$ in a line. $id$ is ID of vertex $u$ and $d$ is the distance from vertex $1$ to vertex $u$. If there are no path from vertex $1$ to vertex $u$, print -1 as the shortest distance. Print in order of IDs.
s244124213
Accepted
p02239
In the first line, an integer $n$ denoting the number of vertices, is given. In the next $n$ lines, adjacent lists of vertex $u$ are given in the following format: $u$ $k$ $v_1$ $v_2$ ... $v_k$ $u$ is ID of the vertex and $k$ denotes its degree.$v_i$ are IDs of vertices adjacent to $u$.
import collections def breadth_first_search(g, check, length): q = collections.deque() q.append(1) check[1] = 1 length[1] = 0 while len(q) != 0: v = q.popleft() for u in g[v]: if check[u] == 0: check[u] = 1 length[u] = length[v] + 1 q.append(u) return length def main(): N = int(input()) g = [] g.append([]) for i in range(N): tmp = input().split() tmp_ls = [] for i in range(int(tmp[1])): tmp_ls.append(int(tmp[i + 2])) g.append(tmp_ls) check = [0] * (N + 1) length = [0] * (N + 1) ans = breadth_first_search(g, check, length) for i in range(N): node_num = i + 1 if ans[node_num] == 0 and i != 0: ans[node_num] = -1 print(node_num, ans[node_num]) main()
Breadth First Search Write a program which reads an directed graph $G = (V, E)$, and finds the shortest distance from vertex $1$ to each vertex (the number of edges in the shortest path). Vertices are identified by IDs $1, 2, ... n$.
[{"input": "4\n 1 2 2 4\n 2 1 4\n 3 0\n 4 1 3", "output": "1 0\n 2 1\n 3 2\n 4 1"}]
For each vertex $u$, print $id$ and $d$ in a line. $id$ is ID of vertex $u$ and $d$ is the distance from vertex $1$ to vertex $u$. If there are no path from vertex $1$ to vertex $u$, print -1 as the shortest distance. Print in order of IDs.
s927486101
Accepted
p02239
In the first line, an integer $n$ denoting the number of vertices, is given. In the next $n$ lines, adjacent lists of vertex $u$ are given in the following format: $u$ $k$ $v_1$ $v_2$ ... $v_k$ $u$ is ID of the vertex and $k$ denotes its degree.$v_i$ are IDs of vertices adjacent to $u$.
from collections import deque import sys def LI(): return list(map(int, sys.stdin.buffer.readline().split())) def I(): return int(sys.stdin.buffer.readline()) class Graph: def __init__(self, n, is_directed=False): """ :param n: 頂点数 :param is_directed: 有向グラフ(True)か無向グラフか(False) """ self.n = n self.graph = [[] for _ in range(n)] self.is_directed = is_directed def add_edge(self, u, v): """uからvへの(有向な)辺をつなぐ""" self.graph[u].append(v) if not self.is_directed: self.graph[v].append(u) def search(self, start, mode): """開始地点から各頂点まで幅/深さ優先探索を行って得られた距離のリストを返す Args: start(int): 開始地点となる頂点 mode(str): 幅優先探索(b)か深さ優先探索(d)を指定 Returns: List[int]: 開始地点からの距離(未到達の場合は-1) """ dists = [-1] * self.n que = deque([start]) dists[start] = 0 if mode == "b": get_v = que.popleft else: get_v = que.pop while que: now_v = get_v() for next_v in self.graph[now_v]: if dists[next_v] != -1: continue que.append(next_v) dists[next_v] = dists[now_v] + 1 return dists n = I() g = Graph(n, is_directed=True) for _ in range(n): u, k, *v = LI() u -= 1 if v == []: continue for vi in v: vi -= 1 g.add_edge(u, vi) res = g.search(0, "b") for i in range(n): print(i + 1, res[i])
Breadth First Search Write a program which reads an directed graph $G = (V, E)$, and finds the shortest distance from vertex $1$ to each vertex (the number of edges in the shortest path). Vertices are identified by IDs $1, 2, ... n$.
[{"input": "4\n 1 2 2 4\n 2 1 4\n 3 0\n 4 1 3", "output": "1 0\n 2 1\n 3 2\n 4 1"}]
For each vertex $u$, print $id$ and $d$ in a line. $id$ is ID of vertex $u$ and $d$ is the distance from vertex $1$ to vertex $u$. If there are no path from vertex $1$ to vertex $u$, print -1 as the shortest distance. Print in order of IDs.
s226758347
Accepted
p02239
In the first line, an integer $n$ denoting the number of vertices, is given. In the next $n$ lines, adjacent lists of vertex $u$ are given in the following format: $u$ $k$ $v_1$ $v_2$ ... $v_k$ $u$ is ID of the vertex and $k$ denotes its degree.$v_i$ are IDs of vertices adjacent to $u$.
import sys import queue readline = sys.stdin.readline write = sys.stdout.write n = int(input()) G = [None for i in range(n + 1)] dist = [ -1, ] * (n + 1) for i in range(n): node_id, k, *adj = map(int, readline().split()) # adj.sort() G[node_id] = adj def bfs(G): # q1が空でなければcntをインクリメントして下のブロックの処理を行う # q1から要素取り出し # →既に見た節点ならばそれに対しては処理を行わずq1から要素を取り出す(節点1⇔節点2の時の無限ループ回避) # →最短距離を格納した後,その要素の子をq2に入れる # →q1から要素が無くなったらq2の要素を全てq1に入れる cnt = -1 q1 = queue.Queue() q2 = queue.Queue() q1.put(1) while not q1.empty(): cnt += 1 while not q1.empty(): val = q1.get() if dist[val] != -1: continue dist[val] = cnt listlen = len(G[val]) for i in range(listlen): q2.put(G[val][i]) while not q2.empty(): q1.put(q2.get()) bfs(G) for i in range(1, n + 1): write(str(i) + " " + str(dist[i]) + "\n")
Breadth First Search Write a program which reads an directed graph $G = (V, E)$, and finds the shortest distance from vertex $1$ to each vertex (the number of edges in the shortest path). Vertices are identified by IDs $1, 2, ... n$.
[{"input": "4\n 1 2 2 4\n 2 1 4\n 3 0\n 4 1 3", "output": "1 0\n 2 1\n 3 2\n 4 1"}]
For each vertex $u$, print $id$ and $d$ in a line. $id$ is ID of vertex $u$ and $d$ is the distance from vertex $1$ to vertex $u$. If there are no path from vertex $1$ to vertex $u$, print -1 as the shortest distance. Print in order of IDs.
s592710831
Accepted
p02239
In the first line, an integer $n$ denoting the number of vertices, is given. In the next $n$ lines, adjacent lists of vertex $u$ are given in the following format: $u$ $k$ $v_1$ $v_2$ ... $v_k$ $u$ is ID of the vertex and $k$ denotes its degree.$v_i$ are IDs of vertices adjacent to $u$.
class Queue: def __init__(self, c): self.values = [None] * (c + 1) self.s = 0 self.t = 0 def push(self, x): if self._next(self.s) == self.t: raise Exception("Overflow") self.values[self.s] = x self.s = self._next(self.s) def pop(self): if self.s == self.t: raise Exception("Underflow") ret = self.values[self.t] self.t = self._next(self.t) return ret def size(self): if self.s >= self.t: return self.s - self.t else: return len(self.values) - (self.t - self.s) def _next(self, p): p += 1 if p >= len(self.values): p = 0 return p def solve(G): d = {} n = len(G) for u in G: d[u] = -1 d[1] = 0 queue = Queue(n + 1) queue.push(1) while queue.size() > 0: u = queue.pop() for v in G[u]: if d[v] == -1: d[v] = d[u] + 1 queue.push(v) return d n = int(input()) G = {} for i in range(n): entry = list(map(int, input().split(" "))) u = entry[0] k = entry[1] G[u] = set() for v in entry[2:]: G[u].add(v) d = solve(G) for u in G: print(u, d[u])
Breadth First Search Write a program which reads an directed graph $G = (V, E)$, and finds the shortest distance from vertex $1$ to each vertex (the number of edges in the shortest path). Vertices are identified by IDs $1, 2, ... n$.
[{"input": "4\n 1 2 2 4\n 2 1 4\n 3 0\n 4 1 3", "output": "1 0\n 2 1\n 3 2\n 4 1"}]
Print the number of ways to write positive integers in the vertices so that the condition is satisfied. * * *
s113723228
Wrong Answer
p03306
Input is given from Standard Input in the following format: n m u_1 v_1 s_1 : u_m v_m s_m
print(0)
Statement Kenkoooo found a simple connected graph. The vertices are numbered 1 through n. The i-th edge connects Vertex u_i and v_i, and has a fixed integer s_i. Kenkoooo is trying to write a _positive integer_ in each vertex so that the following condition is satisfied: * For every edge i, the sum of the positive integers written in Vertex u_i and v_i is equal to s_i. Find the number of such ways to write positive integers in the vertices.
[{"input": "3 3\n 1 2 3\n 2 3 5\n 1 3 4", "output": "1\n \n\nThe condition will be satisfied if we write 1,2 and 3 in vertices 1,2 and 3,\nrespectively. There is no other way to satisfy the condition, so the answer is\n1.\n\n* * *"}, {"input": "4 3\n 1 2 6\n 2 3 7\n 3 4 5", "output": "3\n \n\nLet a,b,c and d be the numbers to write in vertices 1,2,3 and 4, respectively.\nThere are three quadruples (a,b,c,d) that satisfy the condition:\n\n * (a,b,c,d)=(1,5,2,3)\n * (a,b,c,d)=(2,4,3,2)\n * (a,b,c,d)=(3,3,4,1)\n\n* * *"}, {"input": "8 7\n 1 2 1000000000\n 2 3 2\n 3 4 1000000000\n 4 5 2\n 5 6 1000000000\n 6 7 2\n 7 8 1000000000", "output": "0"}]
Print the number of ways to write positive integers in the vertices so that the condition is satisfied. * * *
s327860412
Wrong Answer
p03306
Input is given from Standard Input in the following format: n m u_1 v_1 s_1 : u_m v_m s_m
print(1)
Statement Kenkoooo found a simple connected graph. The vertices are numbered 1 through n. The i-th edge connects Vertex u_i and v_i, and has a fixed integer s_i. Kenkoooo is trying to write a _positive integer_ in each vertex so that the following condition is satisfied: * For every edge i, the sum of the positive integers written in Vertex u_i and v_i is equal to s_i. Find the number of such ways to write positive integers in the vertices.
[{"input": "3 3\n 1 2 3\n 2 3 5\n 1 3 4", "output": "1\n \n\nThe condition will be satisfied if we write 1,2 and 3 in vertices 1,2 and 3,\nrespectively. There is no other way to satisfy the condition, so the answer is\n1.\n\n* * *"}, {"input": "4 3\n 1 2 6\n 2 3 7\n 3 4 5", "output": "3\n \n\nLet a,b,c and d be the numbers to write in vertices 1,2,3 and 4, respectively.\nThere are three quadruples (a,b,c,d) that satisfy the condition:\n\n * (a,b,c,d)=(1,5,2,3)\n * (a,b,c,d)=(2,4,3,2)\n * (a,b,c,d)=(3,3,4,1)\n\n* * *"}, {"input": "8 7\n 1 2 1000000000\n 2 3 2\n 3 4 1000000000\n 4 5 2\n 5 6 1000000000\n 6 7 2\n 7 8 1000000000", "output": "0"}]
Print the number of ways to write positive integers in the vertices so that the condition is satisfied. * * *
s030580204
Wrong Answer
p03306
Input is given from Standard Input in the following format: n m u_1 v_1 s_1 : u_m v_m s_m
import sys sys.setrecursionlimit(10**8) def dfs(v): checked[v] = 1 for u, s in g[v]: if checked[u] == 1: continue vl, vr = lrs[v] if vl == 1 and vr == 0: lrs[u] = (1, 0) continue ul = s - vr if ul <= 0: ul = 1 ur = s - vl if ur <= 0: ur = 0 lrs[u] = (ul, ur) dfs(u) n, m = map(int, input().split()) arr = [list(map(int, input().split())) for _ in range(m)] g = [[] for _ in range(n + 1)] for u, v, s in arr: g[u].append((v, s)) g[v].append((u, s)) lrs = [(0, 0) for _ in range(n + 1)] lrs[1] = (1, g[1][0][1] - 1) checked = [0] * (n + 1) dfs(1) for u, v, s in arr: ul, ur = lrs[u] vl, vr = lrs[v] nul = s - vr if nul <= 0: nul = 1 nur = s - vl if nur <= 0: nur = 0 nvl = s - ur if nvl <= 0: nvl = 1 nvr = s - ul if nvr <= 0: nvr = 0 lrs[u] = (max(ul, nul), min(ur, nur)) lrs[v] = (max(vl, nvl), min(vr, nvr)) ans = 10**18 for l, r in lrs: if l == 0 and r == 0: continue ans = min(ans, (r - l + 1)) if ans > 0: print(ans) else: print(0)
Statement Kenkoooo found a simple connected graph. The vertices are numbered 1 through n. The i-th edge connects Vertex u_i and v_i, and has a fixed integer s_i. Kenkoooo is trying to write a _positive integer_ in each vertex so that the following condition is satisfied: * For every edge i, the sum of the positive integers written in Vertex u_i and v_i is equal to s_i. Find the number of such ways to write positive integers in the vertices.
[{"input": "3 3\n 1 2 3\n 2 3 5\n 1 3 4", "output": "1\n \n\nThe condition will be satisfied if we write 1,2 and 3 in vertices 1,2 and 3,\nrespectively. There is no other way to satisfy the condition, so the answer is\n1.\n\n* * *"}, {"input": "4 3\n 1 2 6\n 2 3 7\n 3 4 5", "output": "3\n \n\nLet a,b,c and d be the numbers to write in vertices 1,2,3 and 4, respectively.\nThere are three quadruples (a,b,c,d) that satisfy the condition:\n\n * (a,b,c,d)=(1,5,2,3)\n * (a,b,c,d)=(2,4,3,2)\n * (a,b,c,d)=(3,3,4,1)\n\n* * *"}, {"input": "8 7\n 1 2 1000000000\n 2 3 2\n 3 4 1000000000\n 4 5 2\n 5 6 1000000000\n 6 7 2\n 7 8 1000000000", "output": "0"}]
Print the number of ways to write positive integers in the vertices so that the condition is satisfied. * * *
s382720675
Wrong Answer
p03306
Input is given from Standard Input in the following format: n m u_1 v_1 s_1 : u_m v_m s_m
from collections import deque N, M = map(int, input().split()) A = [[] for _ in range(N)] for i in range(M): u, v, s = map(int, input().split()) u, v = u - 1, v - 1 A[u].append((v, s)) A[v].append((u, s)) # up[i] A[0]=tとしたときの A[i] = a + t > 0 <=> t > up[i] # dw[i] A[0]=tとしたときの A[i] = a - t > 0 <=> t < dw[i] UP = [-1 for _ in range(N)] DW = [10**9 + 1 for _ in range(N)] UP[0] = 0 # DW[0] = 0 # nodeじゃなくて、edgeを全探索する必要がある気がする。。。 # bfsすれば良いのか? def solve(): visited = [False for _ in range(N)] willSearch = [False for _ in range(N)] Q = deque() # (node, depth) Q.append((0, 0)) while Q: now, depth = Q.pop() visited[now] = True for nxt, cost in A[now]: if depth % 2 == 1: UP[nxt] = max(UP[nxt], DW[now] - cost) else: DW[nxt] = min(DW[nxt], UP[now] + cost) # 訪問済みなら、エッジはPUSHしなくて良い if visited[nxt] or willSearch[nxt]: continue Q.append((nxt, depth + 1)) solve() # print(UP) # print(DW) up, dw = 0, 10**9 for x in UP: if x >= 0: up = max(up, x) for x in DW: if x <= 10**9: dw = min(dw, x) print(dw - up - 1) """ 1 -(5)-> 2 -(3)-> 3 - (8)-> 4 1がtだと、2は5-t、 3はt-2, 4は10-t """
Statement Kenkoooo found a simple connected graph. The vertices are numbered 1 through n. The i-th edge connects Vertex u_i and v_i, and has a fixed integer s_i. Kenkoooo is trying to write a _positive integer_ in each vertex so that the following condition is satisfied: * For every edge i, the sum of the positive integers written in Vertex u_i and v_i is equal to s_i. Find the number of such ways to write positive integers in the vertices.
[{"input": "3 3\n 1 2 3\n 2 3 5\n 1 3 4", "output": "1\n \n\nThe condition will be satisfied if we write 1,2 and 3 in vertices 1,2 and 3,\nrespectively. There is no other way to satisfy the condition, so the answer is\n1.\n\n* * *"}, {"input": "4 3\n 1 2 6\n 2 3 7\n 3 4 5", "output": "3\n \n\nLet a,b,c and d be the numbers to write in vertices 1,2,3 and 4, respectively.\nThere are three quadruples (a,b,c,d) that satisfy the condition:\n\n * (a,b,c,d)=(1,5,2,3)\n * (a,b,c,d)=(2,4,3,2)\n * (a,b,c,d)=(3,3,4,1)\n\n* * *"}, {"input": "8 7\n 1 2 1000000000\n 2 3 2\n 3 4 1000000000\n 4 5 2\n 5 6 1000000000\n 6 7 2\n 7 8 1000000000", "output": "0"}]
Print the number of ways to write positive integers in the vertices so that the condition is satisfied. * * *
s997098027
Runtime Error
p03306
Input is given from Standard Input in the following format: n m u_1 v_1 s_1 : u_m v_m s_m
import numpy as np def find(position): a = np.where(position == edge[0])[0] b = np.where(position == edge[1])[0] c = np.int32(np.append(a, b)) d = np.int32(np.append(np.ones(len(a)), np.zeros(len(b)))) return c, d def find_henkou_edge(henkousareta): inds = np.array([]).astype(np.int32) for a in henkousareta: ind, dotti = find(a) inds = np.append(inds, ind) inds = np.unique(inds) return inds def check(inds): ok = True for ind in inds: i = edge[:, ind] # print(i) # print(num[i]) if (num[i] != -9999).all(): # print(num[i].any()) if not sum(num[i]) == ss[ind]: ok = False return ok def check_henkou(henkousareta): inds = find_henkou_edge(henkousareta) # print(inds) ok = check(inds) return ok n, m = map(int, input().split()) uu = [] vv = [] ss = [] for k in range(m): u, v, s = map(int, input().split()) uu.append(u) vv.append(v) ss.append(s) uu = np.array(uu) - 1 vv = np.array(vv) - 1 ss = np.array(ss) edge = np.vstack([uu, vv]) mi = np.min(ss) armi = np.argmin(ss) num = np.int32(np.zeros(n)) - 9999 cand = range(1, mi) ruikei = 0 for c in cand: num = np.int32(np.zeros(n)) - 9999 # print(c) num[armi] = c ind_tar = armi while True: ind, dotti = find(ind_tar) henkousareta = [] ok_for = True for k in range(len(ind)): temp = dotti[k], ind[k] temp = edge[temp] if num[temp] == -9999: num[temp] = ss[ind[k]] - num[ind_tar] if num[temp] < 1: ok_for = False break else: if not num[temp] == ss[ind[k]] - num[ind_tar]: ok_for = False break henkousareta.append(temp) # print(num) # print(ok_for) if ok_for == False: ok = False break ok = check_henkou(henkousareta) # print(henkousareta) if ok == False: break if not np.min(num) == -9999: break ind, dotti = find(np.where(num == -9999)[0][0]) ind_tar = edge[dotti[0], ind[0]] # print(num) ruikei += ok print(ruikei)
Statement Kenkoooo found a simple connected graph. The vertices are numbered 1 through n. The i-th edge connects Vertex u_i and v_i, and has a fixed integer s_i. Kenkoooo is trying to write a _positive integer_ in each vertex so that the following condition is satisfied: * For every edge i, the sum of the positive integers written in Vertex u_i and v_i is equal to s_i. Find the number of such ways to write positive integers in the vertices.
[{"input": "3 3\n 1 2 3\n 2 3 5\n 1 3 4", "output": "1\n \n\nThe condition will be satisfied if we write 1,2 and 3 in vertices 1,2 and 3,\nrespectively. There is no other way to satisfy the condition, so the answer is\n1.\n\n* * *"}, {"input": "4 3\n 1 2 6\n 2 3 7\n 3 4 5", "output": "3\n \n\nLet a,b,c and d be the numbers to write in vertices 1,2,3 and 4, respectively.\nThere are three quadruples (a,b,c,d) that satisfy the condition:\n\n * (a,b,c,d)=(1,5,2,3)\n * (a,b,c,d)=(2,4,3,2)\n * (a,b,c,d)=(3,3,4,1)\n\n* * *"}, {"input": "8 7\n 1 2 1000000000\n 2 3 2\n 3 4 1000000000\n 4 5 2\n 5 6 1000000000\n 6 7 2\n 7 8 1000000000", "output": "0"}]
Print the number of ways to write positive integers in the vertices so that the condition is satisfied. * * *
s154068024
Wrong Answer
p03306
Input is given from Standard Input in the following format: n m u_1 v_1 s_1 : u_m v_m s_m
from math import ceil, floor N, M = map(int, input().split()) Graph = [[] for i in range(N)] for i in range(M): a, b, s = map(int, input().split()) Graph[a - 1].append((b - 1, s)) Graph[b - 1].append((a - 1, s)) inf = float("inf") node = [(0, 0) for i in range(N)] visited = [False] * N node[0], visited[0] = (1, 0), True L, R = 1, inf stack = [0] while stack: n = stack.pop() x, y = node[n] visited[n] = True for i, s in Graph[n]: if visited[i]: continue p, q = node[i] stack.append(i) if p: if p + x == 0: if y + q != s: print(0) exit() elif (s - y - q) % (p + x) or (not L <= (s - y - q) / (p + x) <= R): print(-1) else: L = R = (s - y - q) // (p + x) else: p, q = -x, s - y if p > 0: L = max(L, floor(-q / p) + 1) else: R = min(R, ceil(-q / p) - 1) node[i] = (-x, s - y) print(max(R - L + 1, 0))
Statement Kenkoooo found a simple connected graph. The vertices are numbered 1 through n. The i-th edge connects Vertex u_i and v_i, and has a fixed integer s_i. Kenkoooo is trying to write a _positive integer_ in each vertex so that the following condition is satisfied: * For every edge i, the sum of the positive integers written in Vertex u_i and v_i is equal to s_i. Find the number of such ways to write positive integers in the vertices.
[{"input": "3 3\n 1 2 3\n 2 3 5\n 1 3 4", "output": "1\n \n\nThe condition will be satisfied if we write 1,2 and 3 in vertices 1,2 and 3,\nrespectively. There is no other way to satisfy the condition, so the answer is\n1.\n\n* * *"}, {"input": "4 3\n 1 2 6\n 2 3 7\n 3 4 5", "output": "3\n \n\nLet a,b,c and d be the numbers to write in vertices 1,2,3 and 4, respectively.\nThere are three quadruples (a,b,c,d) that satisfy the condition:\n\n * (a,b,c,d)=(1,5,2,3)\n * (a,b,c,d)=(2,4,3,2)\n * (a,b,c,d)=(3,3,4,1)\n\n* * *"}, {"input": "8 7\n 1 2 1000000000\n 2 3 2\n 3 4 1000000000\n 4 5 2\n 5 6 1000000000\n 6 7 2\n 7 8 1000000000", "output": "0"}]
Print the number of ways to write positive integers in the vertices so that the condition is satisfied. * * *
s247343304
Accepted
p03306
Input is given from Standard Input in the following format: n m u_1 v_1 s_1 : u_m v_m s_m
N, M = map(int, input().split()) UVS = [list(map(int, input().split())) for _ in [0] * M] E = [[] for _ in [0] * N] for u, v, s in UVS: u -= 1 v -= 1 E[u].append((v, s)) E[v].append((u, s)) V = [None] * N V[0] = (0, 1) q = [0] while q: i = q.pop() d, n = V[i] for j, s in E[i]: if V[j] != None: continue V[j] = (1 - d, s - n) q.append(j) INF = 10**18 checkD = False checkSum = [] checkMin = [INF] * 2 checkMax = [-INF] * 2 for i in range(N): for j, s in E[i]: if j < i: continue checkD = checkD or (V[i][0] == V[j][0]) if V[i][1] + V[j][1] != s: checkSum.append((V[i][0], V[j][0], s - V[i][1] - V[j][1])) d = V[i][0] checkMin[d] = min(checkMin[d], V[i][1]) if checkD: ansFlg = True cnt = set() for di, dj, s in checkSum: if di != dj: ansFlg = False break if di == 1: s *= -1 cnt.add(s) if len(cnt) > 1: ansFlg = False elif cnt: d = cnt.pop() if d % 2: ansFlg = False d //= 2 if min(checkMin[0] + d, checkMin[1] - d) <= 0: ansFlg = False ans = int(ansFlg) else: ans = max(sum(checkMin) - 1, 0) if checkSum: ans = 0 print(ans)
Statement Kenkoooo found a simple connected graph. The vertices are numbered 1 through n. The i-th edge connects Vertex u_i and v_i, and has a fixed integer s_i. Kenkoooo is trying to write a _positive integer_ in each vertex so that the following condition is satisfied: * For every edge i, the sum of the positive integers written in Vertex u_i and v_i is equal to s_i. Find the number of such ways to write positive integers in the vertices.
[{"input": "3 3\n 1 2 3\n 2 3 5\n 1 3 4", "output": "1\n \n\nThe condition will be satisfied if we write 1,2 and 3 in vertices 1,2 and 3,\nrespectively. There is no other way to satisfy the condition, so the answer is\n1.\n\n* * *"}, {"input": "4 3\n 1 2 6\n 2 3 7\n 3 4 5", "output": "3\n \n\nLet a,b,c and d be the numbers to write in vertices 1,2,3 and 4, respectively.\nThere are three quadruples (a,b,c,d) that satisfy the condition:\n\n * (a,b,c,d)=(1,5,2,3)\n * (a,b,c,d)=(2,4,3,2)\n * (a,b,c,d)=(3,3,4,1)\n\n* * *"}, {"input": "8 7\n 1 2 1000000000\n 2 3 2\n 3 4 1000000000\n 4 5 2\n 5 6 1000000000\n 6 7 2\n 7 8 1000000000", "output": "0"}]
Print the number of different PIN codes Takahashi can set. * * *
s358139002
Wrong Answer
p02844
Input is given from Standard Input in the following format: N S
input1 = int(input()) input2 = input() kesu = input1 - 1 inputbox = list(input2) li = [0 for _ in range(1000)]
Statement AtCoder Inc. has decided to lock the door of its office with a 3-digit PIN code. The company has an N-digit lucky number, S. Takahashi, the president, will erase N-3 digits from S and concatenate the remaining 3 digits without changing the order to set the PIN code. How many different PIN codes can he set this way? Both the lucky number and the PIN code may begin with a 0.
[{"input": "4\n 0224", "output": "3\n \n\nTakahashi has the following options:\n\n * Erase the first digit of S and set `224`.\n * Erase the second digit of S and set `024`.\n * Erase the third digit of S and set `024`.\n * Erase the fourth digit of S and set `022`.\n\nThus, he can set three different PIN codes: `022`, `024`, and `224`.\n\n* * *"}, {"input": "6\n 123123", "output": "17\n \n\n* * *"}, {"input": "19\n 3141592653589793238", "output": "329"}]
Print the number of different PIN codes Takahashi can set. * * *
s960872245
Runtime Error
p02844
Input is given from Standard Input in the following format: N S
n = int(input()) #長さ s = str(input()) #文字列 cnt = 0 #暗証番号数 for a in range(9): #1文字目 for b in range(9): #2文字目 for c in range(9): #3文字目 for i in range(n-3): if str(a) = s[i]: tmp_i = i + 1 for j in range(tmp_i,n-2): if str(b) = s[j]: tmp_i = j + 1 for k in range(tmp_i,n-1): if str(c) = s[k]: cnt = cnt + 1 print(cnt)
Statement AtCoder Inc. has decided to lock the door of its office with a 3-digit PIN code. The company has an N-digit lucky number, S. Takahashi, the president, will erase N-3 digits from S and concatenate the remaining 3 digits without changing the order to set the PIN code. How many different PIN codes can he set this way? Both the lucky number and the PIN code may begin with a 0.
[{"input": "4\n 0224", "output": "3\n \n\nTakahashi has the following options:\n\n * Erase the first digit of S and set `224`.\n * Erase the second digit of S and set `024`.\n * Erase the third digit of S and set `024`.\n * Erase the fourth digit of S and set `022`.\n\nThus, he can set three different PIN codes: `022`, `024`, and `224`.\n\n* * *"}, {"input": "6\n 123123", "output": "17\n \n\n* * *"}, {"input": "19\n 3141592653589793238", "output": "329"}]
Print the number of different PIN codes Takahashi can set. * * *
s194191423
Wrong Answer
p02844
Input is given from Standard Input in the following format: N S
N = int(input()) S = int(input()) print(int(N * (N - 1) * (N - 2) / 6))
Statement AtCoder Inc. has decided to lock the door of its office with a 3-digit PIN code. The company has an N-digit lucky number, S. Takahashi, the president, will erase N-3 digits from S and concatenate the remaining 3 digits without changing the order to set the PIN code. How many different PIN codes can he set this way? Both the lucky number and the PIN code may begin with a 0.
[{"input": "4\n 0224", "output": "3\n \n\nTakahashi has the following options:\n\n * Erase the first digit of S and set `224`.\n * Erase the second digit of S and set `024`.\n * Erase the third digit of S and set `024`.\n * Erase the fourth digit of S and set `022`.\n\nThus, he can set three different PIN codes: `022`, `024`, and `224`.\n\n* * *"}, {"input": "6\n 123123", "output": "17\n \n\n* * *"}, {"input": "19\n 3141592653589793238", "output": "329"}]
Print the number of different PIN codes Takahashi can set. * * *
s970600257
Accepted
p02844
Input is given from Standard Input in the following format: N S
dig = [set() for i in range(3)] _ = input() n = input().strip() for d in list(n): for v in dig[1]: dig[2].add(v + d) for v in dig[0]: dig[1].add(v + d) dig[0].add(d) print(len(dig[2]))
Statement AtCoder Inc. has decided to lock the door of its office with a 3-digit PIN code. The company has an N-digit lucky number, S. Takahashi, the president, will erase N-3 digits from S and concatenate the remaining 3 digits without changing the order to set the PIN code. How many different PIN codes can he set this way? Both the lucky number and the PIN code may begin with a 0.
[{"input": "4\n 0224", "output": "3\n \n\nTakahashi has the following options:\n\n * Erase the first digit of S and set `224`.\n * Erase the second digit of S and set `024`.\n * Erase the third digit of S and set `024`.\n * Erase the fourth digit of S and set `022`.\n\nThus, he can set three different PIN codes: `022`, `024`, and `224`.\n\n* * *"}, {"input": "6\n 123123", "output": "17\n \n\n* * *"}, {"input": "19\n 3141592653589793238", "output": "329"}]
Print the number of different PIN codes Takahashi can set. * * *
s608359508
Accepted
p02844
Input is given from Standard Input in the following format: N S
N = int(input()) S = list(input()) list = [0] * 10 code_list = [] # for i in range(9): # for j in range(len(S)): # if str(i) == S[j]: # list[i] = list[i] + 1 def check_match(word, str_cnt): global S ret = -1 for i in range(str_cnt, len(S)): if S[i] == word: ret = i break return ret # 貪欲法 password = [0] * 3 ans_cnt = 0 for num in range(1000): ret = 0 password = str(num) password = password.zfill(3) ret = check_match(password[0], ret) if ret != -1: ret = check_match(password[1], ret + 1) if ret != -1: ret = check_match(password[2], ret + 1) if ret != -1: ans_cnt = ans_cnt + 1 print(ans_cnt) # print (password[1])
Statement AtCoder Inc. has decided to lock the door of its office with a 3-digit PIN code. The company has an N-digit lucky number, S. Takahashi, the president, will erase N-3 digits from S and concatenate the remaining 3 digits without changing the order to set the PIN code. How many different PIN codes can he set this way? Both the lucky number and the PIN code may begin with a 0.
[{"input": "4\n 0224", "output": "3\n \n\nTakahashi has the following options:\n\n * Erase the first digit of S and set `224`.\n * Erase the second digit of S and set `024`.\n * Erase the third digit of S and set `024`.\n * Erase the fourth digit of S and set `022`.\n\nThus, he can set three different PIN codes: `022`, `024`, and `224`.\n\n* * *"}, {"input": "6\n 123123", "output": "17\n \n\n* * *"}, {"input": "19\n 3141592653589793238", "output": "329"}]
Print the number of different PIN codes Takahashi can set. * * *
s464414310
Wrong Answer
p02844
Input is given from Standard Input in the following format: N S
n = int(input()) s = list(input()) se = set() check = set() for first in range(10): temp = "" for i in range(n): if int(s[i]) in check: continue if int(s[i]) == first: temp += s[i] check.add(int(temp)) for second in range(10): for j in range(i + 1, n): if int(temp + s[j]) in check: continue if int(s[j]) == second: temp += s[j] check.add(int(temp)) for third in range(10): for k in range(j + 1, n): if int(temp + s[k]) in check: continue if int(s[k]) == third: temp += s[k] check.add(int(temp)) if len(temp) == 3: se.add(temp) temp = temp[:-1] temp = s[i] print(len(se))
Statement AtCoder Inc. has decided to lock the door of its office with a 3-digit PIN code. The company has an N-digit lucky number, S. Takahashi, the president, will erase N-3 digits from S and concatenate the remaining 3 digits without changing the order to set the PIN code. How many different PIN codes can he set this way? Both the lucky number and the PIN code may begin with a 0.
[{"input": "4\n 0224", "output": "3\n \n\nTakahashi has the following options:\n\n * Erase the first digit of S and set `224`.\n * Erase the second digit of S and set `024`.\n * Erase the third digit of S and set `024`.\n * Erase the fourth digit of S and set `022`.\n\nThus, he can set three different PIN codes: `022`, `024`, and `224`.\n\n* * *"}, {"input": "6\n 123123", "output": "17\n \n\n* * *"}, {"input": "19\n 3141592653589793238", "output": "329"}]
Print the number of different PIN codes Takahashi can set. * * *
s120007154
Wrong Answer
p02844
Input is given from Standard Input in the following format: N S
_, j = open(0) a = set(), set(), set(), {""} for s in j: for b, c in zip(a, a[1:]): b |= {t + s for t in c} print(len(a[0]))
Statement AtCoder Inc. has decided to lock the door of its office with a 3-digit PIN code. The company has an N-digit lucky number, S. Takahashi, the president, will erase N-3 digits from S and concatenate the remaining 3 digits without changing the order to set the PIN code. How many different PIN codes can he set this way? Both the lucky number and the PIN code may begin with a 0.
[{"input": "4\n 0224", "output": "3\n \n\nTakahashi has the following options:\n\n * Erase the first digit of S and set `224`.\n * Erase the second digit of S and set `024`.\n * Erase the third digit of S and set `024`.\n * Erase the fourth digit of S and set `022`.\n\nThus, he can set three different PIN codes: `022`, `024`, and `224`.\n\n* * *"}, {"input": "6\n 123123", "output": "17\n \n\n* * *"}, {"input": "19\n 3141592653589793238", "output": "329"}]
Print the number of different PIN codes Takahashi can set. * * *
s192057493
Runtime Error
p02844
Input is given from Standard Input in the following format: N S
N = input() S = input() a = 0 for i in range(999): b = i // 100 c = (i % 100) // 10 d = i % 10 x = 998 z = 1 for j in range(997): if S[j] == b: x = j break for j in range(2, 999): if S[j] == d: z = j break if x + 1 < z: for j in range(x + 1, z): if S[j] == c: a += 1 print(int(a))
Statement AtCoder Inc. has decided to lock the door of its office with a 3-digit PIN code. The company has an N-digit lucky number, S. Takahashi, the president, will erase N-3 digits from S and concatenate the remaining 3 digits without changing the order to set the PIN code. How many different PIN codes can he set this way? Both the lucky number and the PIN code may begin with a 0.
[{"input": "4\n 0224", "output": "3\n \n\nTakahashi has the following options:\n\n * Erase the first digit of S and set `224`.\n * Erase the second digit of S and set `024`.\n * Erase the third digit of S and set `024`.\n * Erase the fourth digit of S and set `022`.\n\nThus, he can set three different PIN codes: `022`, `024`, and `224`.\n\n* * *"}, {"input": "6\n 123123", "output": "17\n \n\n* * *"}, {"input": "19\n 3141592653589793238", "output": "329"}]
Print the number of different PIN codes Takahashi can set. * * *
s964623409
Accepted
p02844
Input is given from Standard Input in the following format: N S
n = int(input()) s = list(input()) a = ["0", "1", "2", "3", "4", "5", "6", "7", "8", "9"] g = [] for i in a: for j in a: for k in a: g.append([i, j, k]) cnt = 0 for i in g: d = 0 e = 0 while d < n: if s[d] == i[e]: e += 1 d += 1 if e == 3: cnt += 1 break print(cnt)
Statement AtCoder Inc. has decided to lock the door of its office with a 3-digit PIN code. The company has an N-digit lucky number, S. Takahashi, the president, will erase N-3 digits from S and concatenate the remaining 3 digits without changing the order to set the PIN code. How many different PIN codes can he set this way? Both the lucky number and the PIN code may begin with a 0.
[{"input": "4\n 0224", "output": "3\n \n\nTakahashi has the following options:\n\n * Erase the first digit of S and set `224`.\n * Erase the second digit of S and set `024`.\n * Erase the third digit of S and set `024`.\n * Erase the fourth digit of S and set `022`.\n\nThus, he can set three different PIN codes: `022`, `024`, and `224`.\n\n* * *"}, {"input": "6\n 123123", "output": "17\n \n\n* * *"}, {"input": "19\n 3141592653589793238", "output": "329"}]
Print the number of different PIN codes Takahashi can set. * * *
s640842852
Runtime Error
p02844
Input is given from Standard Input in the following format: N S
#!/usr/bin/env python3 def count_pins(n, s): k = 3 if n < k or n < 1 or k < 1: return 0 elif n == k: return 1 v1 = [0 for _ in range(n)] v2 = [0 for _ in range(n)] v3 = [0 for _ in range(n)] v2[n - 1] = 1 v3[s[n - 1] - 1] = 1 for i in range(n - 1)[::-1]: v2[i] = v2[i + 1] if v3[s[i] - 1] == 0: v2[i] += 1 v3[s[i] - 1] = 1 for j in range(1, k): v3 = [0 for _ in range(n)] v1[n - 1] = 0 for i in range(n - 1)[::-1]: v1[i] = v1[i + 1] v1[i] = v1[i] + v2[i + 1] v1[i] = v1[i] - v3[s[i] - 1] v3[s[i] - 1] = v2[i + 1] v2 = v1[:] return v1[0] def main(): n = int(input()) s = [int(c) for c in input()] res = count_pins(n, s) print(res) if __name__ == "__main__": main()
Statement AtCoder Inc. has decided to lock the door of its office with a 3-digit PIN code. The company has an N-digit lucky number, S. Takahashi, the president, will erase N-3 digits from S and concatenate the remaining 3 digits without changing the order to set the PIN code. How many different PIN codes can he set this way? Both the lucky number and the PIN code may begin with a 0.
[{"input": "4\n 0224", "output": "3\n \n\nTakahashi has the following options:\n\n * Erase the first digit of S and set `224`.\n * Erase the second digit of S and set `024`.\n * Erase the third digit of S and set `024`.\n * Erase the fourth digit of S and set `022`.\n\nThus, he can set three different PIN codes: `022`, `024`, and `224`.\n\n* * *"}, {"input": "6\n 123123", "output": "17\n \n\n* * *"}, {"input": "19\n 3141592653589793238", "output": "329"}]
Print the number of different PIN codes Takahashi can set. * * *
s989544077
Runtime Error
p02844
Input is given from Standard Input in the following format: N S
N = int(input()) S = input() ans = 0 for p in range(1000): s = '{:03}'.format(p) i = 0 for j in range(N): if i < 3 and S[j] == s[i]: i += 1 if i== 3: ans += 1 print(ans)
Statement AtCoder Inc. has decided to lock the door of its office with a 3-digit PIN code. The company has an N-digit lucky number, S. Takahashi, the president, will erase N-3 digits from S and concatenate the remaining 3 digits without changing the order to set the PIN code. How many different PIN codes can he set this way? Both the lucky number and the PIN code may begin with a 0.
[{"input": "4\n 0224", "output": "3\n \n\nTakahashi has the following options:\n\n * Erase the first digit of S and set `224`.\n * Erase the second digit of S and set `024`.\n * Erase the third digit of S and set `024`.\n * Erase the fourth digit of S and set `022`.\n\nThus, he can set three different PIN codes: `022`, `024`, and `224`.\n\n* * *"}, {"input": "6\n 123123", "output": "17\n \n\n* * *"}, {"input": "19\n 3141592653589793238", "output": "329"}]
Print the number of different PIN codes Takahashi can set. * * *
s049414113
Wrong Answer
p02844
Input is given from Standard Input in the following format: N S
x = int(input()) dp = [0] * (x + 1) dp[0] = 1 for j in range(6): val = 100 + j for i in range(len(dp) - 1, 0, -1): if i >= val: if dp[i - val]: dp[i] = 1 if dp[-1]: print(1) else: print(0)
Statement AtCoder Inc. has decided to lock the door of its office with a 3-digit PIN code. The company has an N-digit lucky number, S. Takahashi, the president, will erase N-3 digits from S and concatenate the remaining 3 digits without changing the order to set the PIN code. How many different PIN codes can he set this way? Both the lucky number and the PIN code may begin with a 0.
[{"input": "4\n 0224", "output": "3\n \n\nTakahashi has the following options:\n\n * Erase the first digit of S and set `224`.\n * Erase the second digit of S and set `024`.\n * Erase the third digit of S and set `024`.\n * Erase the fourth digit of S and set `022`.\n\nThus, he can set three different PIN codes: `022`, `024`, and `224`.\n\n* * *"}, {"input": "6\n 123123", "output": "17\n \n\n* * *"}, {"input": "19\n 3141592653589793238", "output": "329"}]
If the earliest ABC where Kurohashi can make his debut is ABC n, print n. * * *
s814364291
Accepted
p03243
Input is given from Standard Input in the following format: N
print(0 - -int(input()) // 111 * 111)
Statement Kurohashi has never participated in AtCoder Beginner Contest (ABC). The next ABC to be held is ABC N (the N-th ABC ever held). Kurohashi wants to make his debut in some ABC x such that all the digits of x in base ten are the same. What is the earliest ABC where Kurohashi can make his debut?
[{"input": "111", "output": "111\n \n\nThe next ABC to be held is ABC 111, where Kurohashi can make his debut.\n\n* * *"}, {"input": "112", "output": "222\n \n\nThe next ABC to be held is ABC 112, which means Kurohashi can no longer\nparticipate in ABC 111. Among the ABCs where Kurohashi can make his debut, the\nearliest one is ABC 222.\n\n* * *"}, {"input": "750", "output": "777"}]
If the earliest ABC where Kurohashi can make his debut is ABC n, print n. * * *
s646008799
Accepted
p03243
Input is given from Standard Input in the following format: N
print(-(-int(input()) // 111 * 111))
Statement Kurohashi has never participated in AtCoder Beginner Contest (ABC). The next ABC to be held is ABC N (the N-th ABC ever held). Kurohashi wants to make his debut in some ABC x such that all the digits of x in base ten are the same. What is the earliest ABC where Kurohashi can make his debut?
[{"input": "111", "output": "111\n \n\nThe next ABC to be held is ABC 111, where Kurohashi can make his debut.\n\n* * *"}, {"input": "112", "output": "222\n \n\nThe next ABC to be held is ABC 112, which means Kurohashi can no longer\nparticipate in ABC 111. Among the ABCs where Kurohashi can make his debut, the\nearliest one is ABC 222.\n\n* * *"}, {"input": "750", "output": "777"}]
If the earliest ABC where Kurohashi can make his debut is ABC n, print n. * * *
s844505134
Wrong Answer
p03243
Input is given from Standard Input in the following format: N
print(max(int(i) for i in input()) * 111)
Statement Kurohashi has never participated in AtCoder Beginner Contest (ABC). The next ABC to be held is ABC N (the N-th ABC ever held). Kurohashi wants to make his debut in some ABC x such that all the digits of x in base ten are the same. What is the earliest ABC where Kurohashi can make his debut?
[{"input": "111", "output": "111\n \n\nThe next ABC to be held is ABC 111, where Kurohashi can make his debut.\n\n* * *"}, {"input": "112", "output": "222\n \n\nThe next ABC to be held is ABC 112, which means Kurohashi can no longer\nparticipate in ABC 111. Among the ABCs where Kurohashi can make his debut, the\nearliest one is ABC 222.\n\n* * *"}, {"input": "750", "output": "777"}]
If the earliest ABC where Kurohashi can make his debut is ABC n, print n. * * *
s320796063
Wrong Answer
p03243
Input is given from Standard Input in the following format: N
s = sorted(list(set(input()))) print(s[-1] * 3)
Statement Kurohashi has never participated in AtCoder Beginner Contest (ABC). The next ABC to be held is ABC N (the N-th ABC ever held). Kurohashi wants to make his debut in some ABC x such that all the digits of x in base ten are the same. What is the earliest ABC where Kurohashi can make his debut?
[{"input": "111", "output": "111\n \n\nThe next ABC to be held is ABC 111, where Kurohashi can make his debut.\n\n* * *"}, {"input": "112", "output": "222\n \n\nThe next ABC to be held is ABC 112, which means Kurohashi can no longer\nparticipate in ABC 111. Among the ABCs where Kurohashi can make his debut, the\nearliest one is ABC 222.\n\n* * *"}, {"input": "750", "output": "777"}]
If the earliest ABC where Kurohashi can make his debut is ABC n, print n. * * *
s293962782
Runtime Error
p03243
Input is given from Standard Input in the following format: N
n = int(input()) a = -(-n//111) if a = 10: print(1111) else: print(a*111)
Statement Kurohashi has never participated in AtCoder Beginner Contest (ABC). The next ABC to be held is ABC N (the N-th ABC ever held). Kurohashi wants to make his debut in some ABC x such that all the digits of x in base ten are the same. What is the earliest ABC where Kurohashi can make his debut?
[{"input": "111", "output": "111\n \n\nThe next ABC to be held is ABC 111, where Kurohashi can make his debut.\n\n* * *"}, {"input": "112", "output": "222\n \n\nThe next ABC to be held is ABC 112, which means Kurohashi can no longer\nparticipate in ABC 111. Among the ABCs where Kurohashi can make his debut, the\nearliest one is ABC 222.\n\n* * *"}, {"input": "750", "output": "777"}]
If the earliest ABC where Kurohashi can make his debut is ABC n, print n. * * *
s623608250
Wrong Answer
p03243
Input is given from Standard Input in the following format: N
n = [x for x in input()] print(max(n) * 3)
Statement Kurohashi has never participated in AtCoder Beginner Contest (ABC). The next ABC to be held is ABC N (the N-th ABC ever held). Kurohashi wants to make his debut in some ABC x such that all the digits of x in base ten are the same. What is the earliest ABC where Kurohashi can make his debut?
[{"input": "111", "output": "111\n \n\nThe next ABC to be held is ABC 111, where Kurohashi can make his debut.\n\n* * *"}, {"input": "112", "output": "222\n \n\nThe next ABC to be held is ABC 112, which means Kurohashi can no longer\nparticipate in ABC 111. Among the ABCs where Kurohashi can make his debut, the\nearliest one is ABC 222.\n\n* * *"}, {"input": "750", "output": "777"}]
If the earliest ABC where Kurohashi can make his debut is ABC n, print n. * * *
s368471842
Wrong Answer
p03243
Input is given from Standard Input in the following format: N
print((int(input()) + 110) // 111)
Statement Kurohashi has never participated in AtCoder Beginner Contest (ABC). The next ABC to be held is ABC N (the N-th ABC ever held). Kurohashi wants to make his debut in some ABC x such that all the digits of x in base ten are the same. What is the earliest ABC where Kurohashi can make his debut?
[{"input": "111", "output": "111\n \n\nThe next ABC to be held is ABC 111, where Kurohashi can make his debut.\n\n* * *"}, {"input": "112", "output": "222\n \n\nThe next ABC to be held is ABC 112, which means Kurohashi can no longer\nparticipate in ABC 111. Among the ABCs where Kurohashi can make his debut, the\nearliest one is ABC 222.\n\n* * *"}, {"input": "750", "output": "777"}]
If the earliest ABC where Kurohashi can make his debut is ABC n, print n. * * *
s110322426
Runtime Error
p03243
Input is given from Standard Input in the following format: N
a=int(input()) b=a%100 c=a//100 if b<=c*11: print(c*111) else: print()c+1)*111)
Statement Kurohashi has never participated in AtCoder Beginner Contest (ABC). The next ABC to be held is ABC N (the N-th ABC ever held). Kurohashi wants to make his debut in some ABC x such that all the digits of x in base ten are the same. What is the earliest ABC where Kurohashi can make his debut?
[{"input": "111", "output": "111\n \n\nThe next ABC to be held is ABC 111, where Kurohashi can make his debut.\n\n* * *"}, {"input": "112", "output": "222\n \n\nThe next ABC to be held is ABC 112, which means Kurohashi can no longer\nparticipate in ABC 111. Among the ABCs where Kurohashi can make his debut, the\nearliest one is ABC 222.\n\n* * *"}, {"input": "750", "output": "777"}]
If the earliest ABC where Kurohashi can make his debut is ABC n, print n. * * *
s330470342
Accepted
p03243
Input is given from Standard Input in the following format: N
from collections import defaultdict, Counter from itertools import product, groupby, count, permutations, combinations from math import pi, sqrt from collections import deque from bisect import bisect, bisect_left, bisect_right from string import ascii_lowercase from functools import lru_cache import sys sys.setrecursionlimit(10000) INF = float("inf") YES, Yes, yes, NO, No, no = "YES", "Yes", "yes", "NO", "No", "no" dy4, dx4 = [0, 1, 0, -1], [1, 0, -1, 0] dy8, dx8 = [0, -1, 0, 1, 1, -1, -1, 1], [1, 0, -1, 0, 1, 1, -1, -1] def inside(y, x, H, W): return 0 <= y < H and 0 <= x < W def ceil(a, b): return (a + b - 1) // b # aとbの最大公約数 def gcd(a, b): if b == 0: return a return gcd(b, a % b) # aとbの最小公倍数 def lcm(a, b): g = gcd(a, b) return a / g * b def main(): N = int(input()) for i in range(N, 10000): if len(set(str(i))) == 1: print(i) return if __name__ == "__main__": main()
Statement Kurohashi has never participated in AtCoder Beginner Contest (ABC). The next ABC to be held is ABC N (the N-th ABC ever held). Kurohashi wants to make his debut in some ABC x such that all the digits of x in base ten are the same. What is the earliest ABC where Kurohashi can make his debut?
[{"input": "111", "output": "111\n \n\nThe next ABC to be held is ABC 111, where Kurohashi can make his debut.\n\n* * *"}, {"input": "112", "output": "222\n \n\nThe next ABC to be held is ABC 112, which means Kurohashi can no longer\nparticipate in ABC 111. Among the ABCs where Kurohashi can make his debut, the\nearliest one is ABC 222.\n\n* * *"}, {"input": "750", "output": "777"}]
If the earliest ABC where Kurohashi can make his debut is ABC n, print n. * * *
s093982687
Accepted
p03243
Input is given from Standard Input in the following format: N
import sys from collections import deque sys.setrecursionlimit(4100000) def inputs(num_of_input): ins = [input() for i in range(num_of_input)] return ins def solve(inputs): [N] = string_to_int(inputs[0]) i = N while 1: i_str = str(i) prev = i_str[0] is_ok = True for c in i_str: if c != prev: is_ok = False break if is_ok: return i i += 1 def string_to_int(string): return list(map(int, string.split())) if __name__ == "__main__": ret = solve(inputs(1)) print(ret)
Statement Kurohashi has never participated in AtCoder Beginner Contest (ABC). The next ABC to be held is ABC N (the N-th ABC ever held). Kurohashi wants to make his debut in some ABC x such that all the digits of x in base ten are the same. What is the earliest ABC where Kurohashi can make his debut?
[{"input": "111", "output": "111\n \n\nThe next ABC to be held is ABC 111, where Kurohashi can make his debut.\n\n* * *"}, {"input": "112", "output": "222\n \n\nThe next ABC to be held is ABC 112, which means Kurohashi can no longer\nparticipate in ABC 111. Among the ABCs where Kurohashi can make his debut, the\nearliest one is ABC 222.\n\n* * *"}, {"input": "750", "output": "777"}]
If the earliest ABC where Kurohashi can make his debut is ABC n, print n. * * *
s266239375
Accepted
p03243
Input is given from Standard Input in the following format: N
import math, string, itertools, fractions, heapq, collections, re, array, bisect, sys, random, time, copy, functools sys.setrecursionlimit(10**7) inf = 10**20 eps = 1.0 / 10**13 mod = 10**9 + 7 dd = [(-1, 0), (0, 1), (1, 0), (0, -1)] ddn = [(-1, 0), (-1, 1), (0, 1), (1, 1), (1, 0), (1, -1), (0, -1), (-1, -1)] def LI(): return [int(x) for x in sys.stdin.readline().split()] def LI_(): return [int(x) - 1 for x in sys.stdin.readline().split()] def LF(): return [float(x) for x in sys.stdin.readline().split()] def LS(): return sys.stdin.readline().split() def I(): return int(sys.stdin.readline()) def F(): return float(sys.stdin.readline()) def S(): return input() def pf(s): return print(s, flush=True) def main(): n = I() for i in range(1, 10): if n <= i * 111: return i * 111 return -1 print(main())
Statement Kurohashi has never participated in AtCoder Beginner Contest (ABC). The next ABC to be held is ABC N (the N-th ABC ever held). Kurohashi wants to make his debut in some ABC x such that all the digits of x in base ten are the same. What is the earliest ABC where Kurohashi can make his debut?
[{"input": "111", "output": "111\n \n\nThe next ABC to be held is ABC 111, where Kurohashi can make his debut.\n\n* * *"}, {"input": "112", "output": "222\n \n\nThe next ABC to be held is ABC 112, which means Kurohashi can no longer\nparticipate in ABC 111. Among the ABCs where Kurohashi can make his debut, the\nearliest one is ABC 222.\n\n* * *"}, {"input": "750", "output": "777"}]
If the earliest ABC where Kurohashi can make his debut is ABC n, print n. * * *
s057155087
Runtime Error
p03243
Input is given from Standard Input in the following format: N
import sys import time import math def inpl(): return list(map(int, input().split())) st = time.perf_counter() # ------------------------------ N = int(input()) for i in range(N, 1000): if N//100==N//10 ans N//10==N%10: print(N) sys.exit() # ------------------------------ ed = time.perf_counter() print('time:', ed-st, file=sys.stderr)
Statement Kurohashi has never participated in AtCoder Beginner Contest (ABC). The next ABC to be held is ABC N (the N-th ABC ever held). Kurohashi wants to make his debut in some ABC x such that all the digits of x in base ten are the same. What is the earliest ABC where Kurohashi can make his debut?
[{"input": "111", "output": "111\n \n\nThe next ABC to be held is ABC 111, where Kurohashi can make his debut.\n\n* * *"}, {"input": "112", "output": "222\n \n\nThe next ABC to be held is ABC 112, which means Kurohashi can no longer\nparticipate in ABC 111. Among the ABCs where Kurohashi can make his debut, the\nearliest one is ABC 222.\n\n* * *"}, {"input": "750", "output": "777"}]
If the earliest ABC where Kurohashi can make his debut is ABC n, print n. * * *
s903147553
Wrong Answer
p03243
Input is given from Standard Input in the following format: N
import sys, re from math import ceil, floor, sqrt, pi, factorial # , gcd from copy import deepcopy from collections import Counter, deque from heapq import heapify, heappop, heappush from itertools import accumulate, product, combinations, combinations_with_replacement from bisect import bisect, bisect_left from functools import reduce from decimal import Decimal, getcontext # input = sys.stdin.readline def i_input(): return int(input()) def i_map(): return map(int, input().split()) def i_list(): return list(i_map()) def i_row(N): return [i_input() for _ in range(N)] def i_row_list(N): return [i_list() for _ in range(N)] def s_input(): return input() def s_map(): return input().split() def s_list(): return list(s_map()) def s_row(N): return [s_input for _ in range(N)] def s_row_list(N): return [s_list() for _ in range(N)] def Yes(): print("Yes") def No(): print("No") def YES(): print("YES") def NO(): print("NO") def lcm(a, b): return a * b // gcd(a, b) sys.setrecursionlimit(10**6) INF = float("inf") MOD = 10**9 + 7 def main(): sn = s_input() n = int(sn) compare_num = int(sn[0]) * 100 + int(sn[0]) * 10 + int(sn[0]) if n == compare_num: print(n) elif n > compare_num: print(int(sn[0]) + 1 * 100 + int(sn[0]) + 1 * 10 + int(sn[0]) + 1) else: print(compare_num) if __name__ == "__main__": main()
Statement Kurohashi has never participated in AtCoder Beginner Contest (ABC). The next ABC to be held is ABC N (the N-th ABC ever held). Kurohashi wants to make his debut in some ABC x such that all the digits of x in base ten are the same. What is the earliest ABC where Kurohashi can make his debut?
[{"input": "111", "output": "111\n \n\nThe next ABC to be held is ABC 111, where Kurohashi can make his debut.\n\n* * *"}, {"input": "112", "output": "222\n \n\nThe next ABC to be held is ABC 112, which means Kurohashi can no longer\nparticipate in ABC 111. Among the ABCs where Kurohashi can make his debut, the\nearliest one is ABC 222.\n\n* * *"}, {"input": "750", "output": "777"}]
If the earliest ABC where Kurohashi can make his debut is ABC n, print n. * * *
s061881183
Runtime Error
p03243
Input is given from Standard Input in the following format: N
N = input() ans = [] for i in len(N): ans.append(N[0]) if int(''.join(ans) > int(N): print(''.join(ans)) exit() for i in len(N): ans.append(str(int(N[0]) + 1)) print(''.join(ans))
Statement Kurohashi has never participated in AtCoder Beginner Contest (ABC). The next ABC to be held is ABC N (the N-th ABC ever held). Kurohashi wants to make his debut in some ABC x such that all the digits of x in base ten are the same. What is the earliest ABC where Kurohashi can make his debut?
[{"input": "111", "output": "111\n \n\nThe next ABC to be held is ABC 111, where Kurohashi can make his debut.\n\n* * *"}, {"input": "112", "output": "222\n \n\nThe next ABC to be held is ABC 112, which means Kurohashi can no longer\nparticipate in ABC 111. Among the ABCs where Kurohashi can make his debut, the\nearliest one is ABC 222.\n\n* * *"}, {"input": "750", "output": "777"}]
If the earliest ABC where Kurohashi can make his debut is ABC n, print n. * * *
s939799818
Accepted
p03243
Input is given from Standard Input in the following format: N
n = [x for x in input()] if n[1] < n[2]: n[1] = str(int(n[1]) + 1) if n[0] < n[1]: n[0] = str(int(n[0]) + 1) print(n[0] * 3)
Statement Kurohashi has never participated in AtCoder Beginner Contest (ABC). The next ABC to be held is ABC N (the N-th ABC ever held). Kurohashi wants to make his debut in some ABC x such that all the digits of x in base ten are the same. What is the earliest ABC where Kurohashi can make his debut?
[{"input": "111", "output": "111\n \n\nThe next ABC to be held is ABC 111, where Kurohashi can make his debut.\n\n* * *"}, {"input": "112", "output": "222\n \n\nThe next ABC to be held is ABC 112, which means Kurohashi can no longer\nparticipate in ABC 111. Among the ABCs where Kurohashi can make his debut, the\nearliest one is ABC 222.\n\n* * *"}, {"input": "750", "output": "777"}]
If the earliest ABC where Kurohashi can make his debut is ABC n, print n. * * *
s082093112
Runtime Error
p03243
Input is given from Standard Input in the following format: N
number = int(input()) i = int(number / 111) if number % 111 != 0: i += 1 print(i * 111)
Statement Kurohashi has never participated in AtCoder Beginner Contest (ABC). The next ABC to be held is ABC N (the N-th ABC ever held). Kurohashi wants to make his debut in some ABC x such that all the digits of x in base ten are the same. What is the earliest ABC where Kurohashi can make his debut?
[{"input": "111", "output": "111\n \n\nThe next ABC to be held is ABC 111, where Kurohashi can make his debut.\n\n* * *"}, {"input": "112", "output": "222\n \n\nThe next ABC to be held is ABC 112, which means Kurohashi can no longer\nparticipate in ABC 111. Among the ABCs where Kurohashi can make his debut, the\nearliest one is ABC 222.\n\n* * *"}, {"input": "750", "output": "777"}]
If the earliest ABC where Kurohashi can make his debut is ABC n, print n. * * *
s992919306
Runtime Error
p03243
Input is given from Standard Input in the following format: N
n = int(input()) for i in range(1, 10): if 100*i + 10*i + i => n: print(100*i + 10*i + i)
Statement Kurohashi has never participated in AtCoder Beginner Contest (ABC). The next ABC to be held is ABC N (the N-th ABC ever held). Kurohashi wants to make his debut in some ABC x such that all the digits of x in base ten are the same. What is the earliest ABC where Kurohashi can make his debut?
[{"input": "111", "output": "111\n \n\nThe next ABC to be held is ABC 111, where Kurohashi can make his debut.\n\n* * *"}, {"input": "112", "output": "222\n \n\nThe next ABC to be held is ABC 112, which means Kurohashi can no longer\nparticipate in ABC 111. Among the ABCs where Kurohashi can make his debut, the\nearliest one is ABC 222.\n\n* * *"}, {"input": "750", "output": "777"}]
If the earliest ABC where Kurohashi can make his debut is ABC n, print n. * * *
s091764642
Runtime Error
p03243
Input is given from Standard Input in the following format: N
n = int(input()) for i in range(10): if 100*i + 10*i + i => n: print(100*i + 10*i + i)
Statement Kurohashi has never participated in AtCoder Beginner Contest (ABC). The next ABC to be held is ABC N (the N-th ABC ever held). Kurohashi wants to make his debut in some ABC x such that all the digits of x in base ten are the same. What is the earliest ABC where Kurohashi can make his debut?
[{"input": "111", "output": "111\n \n\nThe next ABC to be held is ABC 111, where Kurohashi can make his debut.\n\n* * *"}, {"input": "112", "output": "222\n \n\nThe next ABC to be held is ABC 112, which means Kurohashi can no longer\nparticipate in ABC 111. Among the ABCs where Kurohashi can make his debut, the\nearliest one is ABC 222.\n\n* * *"}, {"input": "750", "output": "777"}]
If the earliest ABC where Kurohashi can make his debut is ABC n, print n. * * *
s291356373
Wrong Answer
p03243
Input is given from Standard Input in the following format: N
n = input() v = [] val = 0 for a in n: v.append(int(a + a + a)) n = int(n) v = sorted(v) if v[0] >= n: val = v[0] elif v[1] >= n: val = v[1] elif v[2] >= n: val = v[2] print(val)
Statement Kurohashi has never participated in AtCoder Beginner Contest (ABC). The next ABC to be held is ABC N (the N-th ABC ever held). Kurohashi wants to make his debut in some ABC x such that all the digits of x in base ten are the same. What is the earliest ABC where Kurohashi can make his debut?
[{"input": "111", "output": "111\n \n\nThe next ABC to be held is ABC 111, where Kurohashi can make his debut.\n\n* * *"}, {"input": "112", "output": "222\n \n\nThe next ABC to be held is ABC 112, which means Kurohashi can no longer\nparticipate in ABC 111. Among the ABCs where Kurohashi can make his debut, the\nearliest one is ABC 222.\n\n* * *"}, {"input": "750", "output": "777"}]
If the earliest ABC where Kurohashi can make his debut is ABC n, print n. * * *
s387755441
Wrong Answer
p03243
Input is given from Standard Input in the following format: N
N = list(input()) ans = "" digit_max = 0 for d in N: digit_max = max(digit_max, int(d)) ans = str(digit_max) * len(N) print(ans)
Statement Kurohashi has never participated in AtCoder Beginner Contest (ABC). The next ABC to be held is ABC N (the N-th ABC ever held). Kurohashi wants to make his debut in some ABC x such that all the digits of x in base ten are the same. What is the earliest ABC where Kurohashi can make his debut?
[{"input": "111", "output": "111\n \n\nThe next ABC to be held is ABC 111, where Kurohashi can make his debut.\n\n* * *"}, {"input": "112", "output": "222\n \n\nThe next ABC to be held is ABC 112, which means Kurohashi can no longer\nparticipate in ABC 111. Among the ABCs where Kurohashi can make his debut, the\nearliest one is ABC 222.\n\n* * *"}, {"input": "750", "output": "777"}]
If the earliest ABC where Kurohashi can make his debut is ABC n, print n. * * *
s634300672
Accepted
p03243
Input is given from Standard Input in the following format: N
print(((int(input()) - 1) // 111 + 1) * 111)
Statement Kurohashi has never participated in AtCoder Beginner Contest (ABC). The next ABC to be held is ABC N (the N-th ABC ever held). Kurohashi wants to make his debut in some ABC x such that all the digits of x in base ten are the same. What is the earliest ABC where Kurohashi can make his debut?
[{"input": "111", "output": "111\n \n\nThe next ABC to be held is ABC 111, where Kurohashi can make his debut.\n\n* * *"}, {"input": "112", "output": "222\n \n\nThe next ABC to be held is ABC 112, which means Kurohashi can no longer\nparticipate in ABC 111. Among the ABCs where Kurohashi can make his debut, the\nearliest one is ABC 222.\n\n* * *"}, {"input": "750", "output": "777"}]
If the earliest ABC where Kurohashi can make his debut is ABC n, print n. * * *
s786412618
Runtime Error
p03243
Input is given from Standard Input in the following format: N
print((1 + (int(input() - 1) // 111)) * 111)
Statement Kurohashi has never participated in AtCoder Beginner Contest (ABC). The next ABC to be held is ABC N (the N-th ABC ever held). Kurohashi wants to make his debut in some ABC x such that all the digits of x in base ten are the same. What is the earliest ABC where Kurohashi can make his debut?
[{"input": "111", "output": "111\n \n\nThe next ABC to be held is ABC 111, where Kurohashi can make his debut.\n\n* * *"}, {"input": "112", "output": "222\n \n\nThe next ABC to be held is ABC 112, which means Kurohashi can no longer\nparticipate in ABC 111. Among the ABCs where Kurohashi can make his debut, the\nearliest one is ABC 222.\n\n* * *"}, {"input": "750", "output": "777"}]
If the earliest ABC where Kurohashi can make his debut is ABC n, print n. * * *
s939369282
Wrong Answer
p03243
Input is given from Standard Input in the following format: N
# ABC 111: B – AtCoder Beginner Contest 111 print(max(list(input())) * 3)
Statement Kurohashi has never participated in AtCoder Beginner Contest (ABC). The next ABC to be held is ABC N (the N-th ABC ever held). Kurohashi wants to make his debut in some ABC x such that all the digits of x in base ten are the same. What is the earliest ABC where Kurohashi can make his debut?
[{"input": "111", "output": "111\n \n\nThe next ABC to be held is ABC 111, where Kurohashi can make his debut.\n\n* * *"}, {"input": "112", "output": "222\n \n\nThe next ABC to be held is ABC 112, which means Kurohashi can no longer\nparticipate in ABC 111. Among the ABCs where Kurohashi can make his debut, the\nearliest one is ABC 222.\n\n* * *"}, {"input": "750", "output": "777"}]
If the earliest ABC where Kurohashi can make his debut is ABC n, print n. * * *
s029102670
Accepted
p03243
Input is given from Standard Input in the following format: N
n = int(input()) k = 1 N = 100 * k + 10 * k + 1 * k while n > N: k += 1 N = 100 * k + 10 * k + 1 * k print(N)
Statement Kurohashi has never participated in AtCoder Beginner Contest (ABC). The next ABC to be held is ABC N (the N-th ABC ever held). Kurohashi wants to make his debut in some ABC x such that all the digits of x in base ten are the same. What is the earliest ABC where Kurohashi can make his debut?
[{"input": "111", "output": "111\n \n\nThe next ABC to be held is ABC 111, where Kurohashi can make his debut.\n\n* * *"}, {"input": "112", "output": "222\n \n\nThe next ABC to be held is ABC 112, which means Kurohashi can no longer\nparticipate in ABC 111. Among the ABCs where Kurohashi can make his debut, the\nearliest one is ABC 222.\n\n* * *"}, {"input": "750", "output": "777"}]