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 minimum number of operations needed. * * *
s940743332
Wrong Answer
p02735
Input is given from Standard Input in the following format: H W s_{11} s_{12} \cdots s_{1W} s_{21} s_{22} \cdots s_{2W} \vdots s_{H1} s_{H2} \cdots s_{HW} Here s_{rc} represents the color of (r, c) \- `#` stands for black, and `.` stands for white.
r, c = map(int, input().split()) def minCost(cost, m, n): tc = [[0 for x in range(c)] for x in range(r)] tc[0][0] = cost[0][0] for i in range(1, m + 1): tc[i][0] = tc[i - 1][0] + cost[i][0] for j in range(1, n + 1): tc[0][j] = tc[0][j - 1] + cost[0][j] for i in range(1, m + 1): for j in range(1, n + 1): tc[i][j] = min(tc[i - 1][j], tc[i][j - 1]) + cost[i][j] return tc[m][n] a = [] x = 0 for i in range(r): s = input().replace(".", "0").replace("#", "1") ss = [int(i) for i in s] a.append(ss) print(minCost(a, r - 1, c - 1))
Statement Consider a grid with H rows and W columns of squares. Let (r, c) denote the square at the r-th row from the top and the c-th column from the left. Each square is painted black or white. The grid is said to be _good_ if and only if the following condition is satisfied: * From (1, 1), we can reach (H, W) by moving one square **right or down** repeatedly, while always being on a white square. Note that (1, 1) and (H, W) must be white if the grid is good. Your task is to make the grid good by repeating the operation below. Find the minimum number of operations needed to complete the task. It can be proved that you can always complete the task in a finite number of operations. * Choose four integers r_0, c_0, r_1, c_1(1 \leq r_0 \leq r_1 \leq H, 1 \leq c_0 \leq c_1 \leq W). For each pair r, c (r_0 \leq r \leq r_1, c_0 \leq c \leq c_1), invert the color of (r, c) \- that is, from white to black and vice versa.
[{"input": "3 3\n .##\n .#.\n ##.", "output": "1\n \n\nDo the operation with (r_0, c_0, r_1, c_1) = (2, 2, 2, 2) to change just the\ncolor of (2, 2), and we are done.\n\n* * *"}, {"input": "2 2\n #.\n .#", "output": "2\n \n\n* * *"}, {"input": "4 4\n ..##\n #...\n ###.\n ###.", "output": "0\n \n\nNo operation may be needed.\n\n* * *"}, {"input": "5 5\n .#.#.\n #.#.#\n .#.#.\n #.#.#\n .#.#.", "output": "4"}]
Print the minimum number of operations needed. * * *
s711792854
Wrong Answer
p02735
Input is given from Standard Input in the following format: H W s_{11} s_{12} \cdots s_{1W} s_{21} s_{22} \cdots s_{2W} \vdots s_{H1} s_{H2} \cdots s_{HW} Here s_{rc} represents the color of (r, c) \- `#` stands for black, and `.` stands for white.
from collections import defaultdict as dd def func(): return float("inf") def solve(M, H, W): dic = dd(func) for i in range(h - 1, -1, -1): for j in range(w - 1, -1, -1): dic[(i, j)] = min(dic[(i + 1, j)], dic[(i, j + 1)]) if dic[(i, j)] == float("inf"): dic[(i, j)] = 0 if M[i][j] == "#": dic[(i, j)] += 1 print(dic[(0, 0)]) h, w = map(int, input().split()) M = [] for i in range(h): arr = list(input()) M.append(arr) solve(M, h, w)
Statement Consider a grid with H rows and W columns of squares. Let (r, c) denote the square at the r-th row from the top and the c-th column from the left. Each square is painted black or white. The grid is said to be _good_ if and only if the following condition is satisfied: * From (1, 1), we can reach (H, W) by moving one square **right or down** repeatedly, while always being on a white square. Note that (1, 1) and (H, W) must be white if the grid is good. Your task is to make the grid good by repeating the operation below. Find the minimum number of operations needed to complete the task. It can be proved that you can always complete the task in a finite number of operations. * Choose four integers r_0, c_0, r_1, c_1(1 \leq r_0 \leq r_1 \leq H, 1 \leq c_0 \leq c_1 \leq W). For each pair r, c (r_0 \leq r \leq r_1, c_0 \leq c \leq c_1), invert the color of (r, c) \- that is, from white to black and vice versa.
[{"input": "3 3\n .##\n .#.\n ##.", "output": "1\n \n\nDo the operation with (r_0, c_0, r_1, c_1) = (2, 2, 2, 2) to change just the\ncolor of (2, 2), and we are done.\n\n* * *"}, {"input": "2 2\n #.\n .#", "output": "2\n \n\n* * *"}, {"input": "4 4\n ..##\n #...\n ###.\n ###.", "output": "0\n \n\nNo operation may be needed.\n\n* * *"}, {"input": "5 5\n .#.#.\n #.#.#\n .#.#.\n #.#.#\n .#.#.", "output": "4"}]
Print the minimum number of operations needed. * * *
s383934055
Accepted
p02735
Input is given from Standard Input in the following format: H W s_{11} s_{12} \cdots s_{1W} s_{21} s_{22} \cdots s_{2W} \vdots s_{H1} s_{H2} \cdots s_{HW} Here s_{rc} represents the color of (r, c) \- `#` stands for black, and `.` stands for white.
h, *s = open(0) h, w = map(int, h.split()) dp = [[9e9] * w for _ in s] dp[0][0] = s[0][0] < "." for i in range(h * w): i, j = i // w, i % w for y, x in ((i + 1, j), (i, j + 1)): if y < h and x < w: dp[y][x] = min(dp[y][x], dp[i][j] + (s[i][j] == "." > s[y][x])) print(dp[-1][-1])
Statement Consider a grid with H rows and W columns of squares. Let (r, c) denote the square at the r-th row from the top and the c-th column from the left. Each square is painted black or white. The grid is said to be _good_ if and only if the following condition is satisfied: * From (1, 1), we can reach (H, W) by moving one square **right or down** repeatedly, while always being on a white square. Note that (1, 1) and (H, W) must be white if the grid is good. Your task is to make the grid good by repeating the operation below. Find the minimum number of operations needed to complete the task. It can be proved that you can always complete the task in a finite number of operations. * Choose four integers r_0, c_0, r_1, c_1(1 \leq r_0 \leq r_1 \leq H, 1 \leq c_0 \leq c_1 \leq W). For each pair r, c (r_0 \leq r \leq r_1, c_0 \leq c \leq c_1), invert the color of (r, c) \- that is, from white to black and vice versa.
[{"input": "3 3\n .##\n .#.\n ##.", "output": "1\n \n\nDo the operation with (r_0, c_0, r_1, c_1) = (2, 2, 2, 2) to change just the\ncolor of (2, 2), and we are done.\n\n* * *"}, {"input": "2 2\n #.\n .#", "output": "2\n \n\n* * *"}, {"input": "4 4\n ..##\n #...\n ###.\n ###.", "output": "0\n \n\nNo operation may be needed.\n\n* * *"}, {"input": "5 5\n .#.#.\n #.#.#\n .#.#.\n #.#.#\n .#.#.", "output": "4"}]
Print the minimum number of operations needed. * * *
s490917807
Accepted
p02735
Input is given from Standard Input in the following format: H W s_{11} s_{12} \cdots s_{1W} s_{21} s_{22} \cdots s_{2W} \vdots s_{H1} s_{H2} \cdots s_{HW} Here s_{rc} represents the color of (r, c) \- `#` stands for black, and `.` stands for white.
import sys import heapq H, W = map(int, input().split()) maze = [list(input()) for i in range(H)] def removeWalls(wallPointH, wallPointW): if maze[wallPointH][wallPointW] == "#": changeTo = "." elif maze[wallPointH][wallPointW] == "1": changeTo = "0" if maze[wallPointH][wallPointW] == "#" or maze[wallPointH][wallPointW] == "1": maze[wallPointH][wallPointW] = changeTo if wallPointH + 1 <= H - 1: removeWalls(wallPointH + 1, wallPointW) if wallPointW + 1 <= W - 1: removeWalls(wallPointH, wallPointW + 1) if maze[0][0] == "#": flag = 1 else: flag = 0 que = [[flag, 0, 0]] heapq.heapify(que) count = 0 while que: qu = heapq.heappop(que) if qu[0] == 1: heapq.heappush(que, qu) count += 1 for q in que: # いったん"#"の撤去作業を行う q[0] = 0 removeWalls(q[1], q[2]) else: # queの中身にまだ進める場所があるなら nowH = qu[1] nowW = qu[2] if nowH == H - 1 and nowW == W - 1: # ゴールの場合 print(count) sys.exit() else: # それ以外の場合 # 右近傍と下近傍、それぞれマップの中ならqueに格納。 if nowH + 1 <= H - 1: if maze[nowH + 1][nowW] == "#": maze[nowH + 1][nowW] = "1" heapq.heappush(que, [1, nowH + 1, nowW]) elif maze[nowH + 1][nowW] == ".": maze[nowH + 1][nowW] = "0" heapq.heappush(que, [0, nowH + 1, nowW]) if nowW + 1 <= W - 1: if maze[nowH][nowW + 1] == "#": maze[nowH][nowW + 1] = "1" heapq.heappush(que, [1, nowH, nowW + 1]) elif maze[nowH][nowW + 1] == ".": maze[nowH][nowW + 1] = "0" heapq.heappush(que, [0, nowH, nowW + 1])
Statement Consider a grid with H rows and W columns of squares. Let (r, c) denote the square at the r-th row from the top and the c-th column from the left. Each square is painted black or white. The grid is said to be _good_ if and only if the following condition is satisfied: * From (1, 1), we can reach (H, W) by moving one square **right or down** repeatedly, while always being on a white square. Note that (1, 1) and (H, W) must be white if the grid is good. Your task is to make the grid good by repeating the operation below. Find the minimum number of operations needed to complete the task. It can be proved that you can always complete the task in a finite number of operations. * Choose four integers r_0, c_0, r_1, c_1(1 \leq r_0 \leq r_1 \leq H, 1 \leq c_0 \leq c_1 \leq W). For each pair r, c (r_0 \leq r \leq r_1, c_0 \leq c \leq c_1), invert the color of (r, c) \- that is, from white to black and vice versa.
[{"input": "3 3\n .##\n .#.\n ##.", "output": "1\n \n\nDo the operation with (r_0, c_0, r_1, c_1) = (2, 2, 2, 2) to change just the\ncolor of (2, 2), and we are done.\n\n* * *"}, {"input": "2 2\n #.\n .#", "output": "2\n \n\n* * *"}, {"input": "4 4\n ..##\n #...\n ###.\n ###.", "output": "0\n \n\nNo operation may be needed.\n\n* * *"}, {"input": "5 5\n .#.#.\n #.#.#\n .#.#.\n #.#.#\n .#.#.", "output": "4"}]
Print the minimum number of operations needed. * * *
s723541495
Runtime Error
p02735
Input is given from Standard Input in the following format: H W s_{11} s_{12} \cdots s_{1W} s_{21} s_{22} \cdots s_{2W} \vdots s_{H1} s_{H2} \cdots s_{HW} Here s_{rc} represents the color of (r, c) \- `#` stands for black, and `.` stands for white.
def update(black): return "." if black == "#" else "#" def dp(i, j, w_end, h_end, black="#", memo={}): if (i, j, w_end, h_end, black) in memo: return memo[i, j, w_end, h_end, black] elif i < 0 or j < 0 or w_end >= W or h_end >= H: return float("inf") elif i == w_end and j == h_end: return 1 if grid[i][j] == black else 0 elif grid[i][j] == black and grid[w_end][h_end] == black: not_flip = 1 + min( dp(i - 1, j, w_end, h_end, black, memo), dp(i, j - 1, w_end, h_end, black, memo), dp(i, j, w_end + 1, h_end, black, memo), dp(i, j, w_end, h_end + 1, black, memo), ) new = update(black) flip = 1 + min( dp(i - 1, j, w_end + 1, h_end, new, memo), dp(i - 1, j, w_end, h_end + 1, new, memo), dp(i, j - 1, w_end + 1, h_end, new, memo), dp(i, j - 1, w_end, h_end + 1, new, memo), ) res = min(not_flip, flip) memo[i, j, w_end, h_end, black] = res return res elif grid[i][j] == black: not_flip = 1 + min( dp(i - 1, j, w_end + 1, h_end, black, memo), dp(i - 1, j, w_end, h_end + 1, black, memo), dp(i, j - 1, w_end + 1, h_end, black, memo), dp(i, j - 1, w_end, h_end + 1, black, memo), ) new = update(black) flip = 1 + min( dp(i - 1, j, w_end + 1, h_end + 1, new, memo), dp(i, j - 1, w_end + 1, h_end + 1, new, memo), ) flip += min( dp(w_end + 1, h_end, w_end + 1, h_end, black, memo), dp(w_end, h_end + 1, w_end, h_end + 1, black, memo), ) res = min(not_flip, flip) memo[i, j, w_end, h_end, black] = res return res elif grid[w_end][h_end] == black: not_flip = 1 + min( dp(i - 1, j, w_end + 1, h_end, black, memo), dp(i - 1, j, w_end, h_end + 1, black, memo), dp(i, j - 1, w_end + 1, h_end, black, memo), dp(i, j - 1, w_end, h_end + 1, black, memo), ) new = update(black) flip = 1 + min( dp(i - 1, j - 1, w_end + 1, h_end, new, memo), dp(i - 1, j - 1, w_end, h_end + 1, new, memo), ) flip += min( dp(i - 1, j, i - 1, j, black, memo), dp(i, j - 1, i, j - 1, black, memo) ) res = min(not_flip, flip) memo[i, j, w_end, h_end, black] = res return res else: res = min( dp(i - 1, j, w_end + 1, h_end, black, memo), dp(i - 1, j, w_end, h_end + 1, black, memo), dp(i, j - 1, w_end + 1, h_end, black, memo), dp(i, j - 1, w_end, h_end + 1, black, memo), ) memo[i, j, w_end, h_end, black] = res return res H, W = map(int, input().split()) grid = [[None] * W for _ in range(H)] for i in range(H): for j, x in enumerate(input()): grid[i][j] = x memo = {} print(min(dp(H - 1, W - 1, 0, 0, "#", memo), 1 + dp(H - 1, W - 1, 0, 0, ".", memo)))
Statement Consider a grid with H rows and W columns of squares. Let (r, c) denote the square at the r-th row from the top and the c-th column from the left. Each square is painted black or white. The grid is said to be _good_ if and only if the following condition is satisfied: * From (1, 1), we can reach (H, W) by moving one square **right or down** repeatedly, while always being on a white square. Note that (1, 1) and (H, W) must be white if the grid is good. Your task is to make the grid good by repeating the operation below. Find the minimum number of operations needed to complete the task. It can be proved that you can always complete the task in a finite number of operations. * Choose four integers r_0, c_0, r_1, c_1(1 \leq r_0 \leq r_1 \leq H, 1 \leq c_0 \leq c_1 \leq W). For each pair r, c (r_0 \leq r \leq r_1, c_0 \leq c \leq c_1), invert the color of (r, c) \- that is, from white to black and vice versa.
[{"input": "3 3\n .##\n .#.\n ##.", "output": "1\n \n\nDo the operation with (r_0, c_0, r_1, c_1) = (2, 2, 2, 2) to change just the\ncolor of (2, 2), and we are done.\n\n* * *"}, {"input": "2 2\n #.\n .#", "output": "2\n \n\n* * *"}, {"input": "4 4\n ..##\n #...\n ###.\n ###.", "output": "0\n \n\nNo operation may be needed.\n\n* * *"}, {"input": "5 5\n .#.#.\n #.#.#\n .#.#.\n #.#.#\n .#.#.", "output": "4"}]
Print the minimum number of operations needed. * * *
s776878604
Accepted
p02735
Input is given from Standard Input in the following format: H W s_{11} s_{12} \cdots s_{1W} s_{21} s_{22} \cdots s_{2W} \vdots s_{H1} s_{H2} \cdots s_{HW} Here s_{rc} represents the color of (r, c) \- `#` stands for black, and `.` stands for white.
##### import numpy as np # from numpy import int32, int8 # from collections import deque ##### def getIntList(inp): return [int(_) for _ in inp] from sys import stdin import sys sys.setrecursionlimit(10**8) def getInputs(): inputs = [] for line in stdin: line = line.split() inputs.append(line) return inputs def main(inputs): h, w = getIntList(inputs[0]) colors = np.empty((h, w), np.bool) for hi in range(h): for wi in range(w): colors[hi, wi] = inputs[1 + hi][0][wi] == "." # h=20 # w=20 # np.random.seed(0) # colors=np.random.randint(0,2,(h,w)) # from matplotlib import pyplot as plt # for hi in range(h): # for wi in range(w): # plt.annotate(str((hi,wi)), (wi-0.5,hi), color="g") # plt.imshow(colors) # plt.show() # print(colors.astype(np.int32)) flipSize = np.empty((h, w), np.int32) if colors[0, 0]: flipSize[0, 0] = 0 else: flipSize[0, 0] = 1 for hi in range(h): for wi in range(w): if hi == 0 and wi == 0: continue c = colors[hi, wi] fs = [] if hi > 0: d = int(colors[hi - 1, wi] and (not c)) s = flipSize[hi - 1, wi] + d fs.append(s) if wi > 0: d = int(colors[hi, wi - 1] and (not c)) s = flipSize[hi, wi - 1] + d fs.append(s) fs = min(fs) flipSize[hi, wi] = fs print(flipSize[h - 1, w - 1]) if __name__ == "__main__": inputs = getInputs() # inputs=simInputs() main(inputs)
Statement Consider a grid with H rows and W columns of squares. Let (r, c) denote the square at the r-th row from the top and the c-th column from the left. Each square is painted black or white. The grid is said to be _good_ if and only if the following condition is satisfied: * From (1, 1), we can reach (H, W) by moving one square **right or down** repeatedly, while always being on a white square. Note that (1, 1) and (H, W) must be white if the grid is good. Your task is to make the grid good by repeating the operation below. Find the minimum number of operations needed to complete the task. It can be proved that you can always complete the task in a finite number of operations. * Choose four integers r_0, c_0, r_1, c_1(1 \leq r_0 \leq r_1 \leq H, 1 \leq c_0 \leq c_1 \leq W). For each pair r, c (r_0 \leq r \leq r_1, c_0 \leq c \leq c_1), invert the color of (r, c) \- that is, from white to black and vice versa.
[{"input": "3 3\n .##\n .#.\n ##.", "output": "1\n \n\nDo the operation with (r_0, c_0, r_1, c_1) = (2, 2, 2, 2) to change just the\ncolor of (2, 2), and we are done.\n\n* * *"}, {"input": "2 2\n #.\n .#", "output": "2\n \n\n* * *"}, {"input": "4 4\n ..##\n #...\n ###.\n ###.", "output": "0\n \n\nNo operation may be needed.\n\n* * *"}, {"input": "5 5\n .#.#.\n #.#.#\n .#.#.\n #.#.#\n .#.#.", "output": "4"}]
Print the minimum number of operations needed. * * *
s403335617
Wrong Answer
p02735
Input is given from Standard Input in the following format: H W s_{11} s_{12} \cdots s_{1W} s_{21} s_{22} \cdots s_{2W} \vdots s_{H1} s_{H2} \cdots s_{HW} Here s_{rc} represents the color of (r, c) \- `#` stands for black, and `.` stands for white.
# coding: utf-8 import queue H, W = map(int, input().split()) field = [list(input()) for _ in range(H)] dist = [[0 for _ in range(W)] for _ in range(H)] check = [[False for _ in range(W)] for _ in range(H)] q = queue.Queue() q.put([0, 0]) while not q.empty(): p = q.get() h, w = p[0], p[1] if h >= H or w >= W: continue elif field[h][w] == ".": # 値の更新 dist[h][w] = min(dist[h - 1][w], dist[h][w - 1]) check[h][w] = True # 周辺のput q.put([h, w + 1]) q.put([h + 1, w]) elif field[h][w] == "#" and check[h][w] == False: # 長方形の判定 dh = 0 while field[h + dh][w] == "#": dh += 1 if h + dh == H: break cnt = [0] * dh for j in range(dh): dw = 0 while field[h + j][w + dw] == "#": dw += 1 if w + dw == W: break cnt[j] = dw dw = min(cnt) # 値の更新 c = min(dist[h - 1][w], dist[h][w - 1]) + 1 for j in range(dh): for i in range(dw): if check[h + j][w + i] == False: dist[h + j][w + i] = c check[h + j][w + i] = True # 周辺のput for j in range(dh): q.put([h + j, w + dw]) for i in range(dw): q.put([h + dh, w + i]) print(dist[-1][-1])
Statement Consider a grid with H rows and W columns of squares. Let (r, c) denote the square at the r-th row from the top and the c-th column from the left. Each square is painted black or white. The grid is said to be _good_ if and only if the following condition is satisfied: * From (1, 1), we can reach (H, W) by moving one square **right or down** repeatedly, while always being on a white square. Note that (1, 1) and (H, W) must be white if the grid is good. Your task is to make the grid good by repeating the operation below. Find the minimum number of operations needed to complete the task. It can be proved that you can always complete the task in a finite number of operations. * Choose four integers r_0, c_0, r_1, c_1(1 \leq r_0 \leq r_1 \leq H, 1 \leq c_0 \leq c_1 \leq W). For each pair r, c (r_0 \leq r \leq r_1, c_0 \leq c \leq c_1), invert the color of (r, c) \- that is, from white to black and vice versa.
[{"input": "3 3\n .##\n .#.\n ##.", "output": "1\n \n\nDo the operation with (r_0, c_0, r_1, c_1) = (2, 2, 2, 2) to change just the\ncolor of (2, 2), and we are done.\n\n* * *"}, {"input": "2 2\n #.\n .#", "output": "2\n \n\n* * *"}, {"input": "4 4\n ..##\n #...\n ###.\n ###.", "output": "0\n \n\nNo operation may be needed.\n\n* * *"}, {"input": "5 5\n .#.#.\n #.#.#\n .#.#.\n #.#.#\n .#.#.", "output": "4"}]
Print the minimum number of operations needed. * * *
s326263557
Accepted
p02735
Input is given from Standard Input in the following format: H W s_{11} s_{12} \cdots s_{1W} s_{21} s_{22} \cdots s_{2W} \vdots s_{H1} s_{H2} \cdots s_{HW} Here s_{rc} represents the color of (r, c) \- `#` stands for black, and `.` stands for white.
import sys sys.setrecursionlimit(10**6) (H, W) = map(int, (input().split())) INF = 1000 mymap = list() for i in range(H): mymap.append(input().rstrip()) # print(mymap) costmap = [[INF for i in range(W)] for j in range(H)] # print(costmap) def make_costmap(i, j, prev_state, c): # print(i,j,prev_state,c) state = mymap[i][j] if prev_state == "." and state == "#": c += 1 if costmap[i][j] == INF or costmap[i][j] > c: costmap[i][j] = c else: return if i < H - 1: make_costmap(i + 1, j, state, c) if j < W - 1: make_costmap(i, j + 1, state, c) return make_costmap(0, 0, ".", 0) # for i in range(H): # print(mymap[i]) # for i in range(H): # print(costmap[i]) print(costmap[H - 1][W - 1])
Statement Consider a grid with H rows and W columns of squares. Let (r, c) denote the square at the r-th row from the top and the c-th column from the left. Each square is painted black or white. The grid is said to be _good_ if and only if the following condition is satisfied: * From (1, 1), we can reach (H, W) by moving one square **right or down** repeatedly, while always being on a white square. Note that (1, 1) and (H, W) must be white if the grid is good. Your task is to make the grid good by repeating the operation below. Find the minimum number of operations needed to complete the task. It can be proved that you can always complete the task in a finite number of operations. * Choose four integers r_0, c_0, r_1, c_1(1 \leq r_0 \leq r_1 \leq H, 1 \leq c_0 \leq c_1 \leq W). For each pair r, c (r_0 \leq r \leq r_1, c_0 \leq c \leq c_1), invert the color of (r, c) \- that is, from white to black and vice versa.
[{"input": "3 3\n .##\n .#.\n ##.", "output": "1\n \n\nDo the operation with (r_0, c_0, r_1, c_1) = (2, 2, 2, 2) to change just the\ncolor of (2, 2), and we are done.\n\n* * *"}, {"input": "2 2\n #.\n .#", "output": "2\n \n\n* * *"}, {"input": "4 4\n ..##\n #...\n ###.\n ###.", "output": "0\n \n\nNo operation may be needed.\n\n* * *"}, {"input": "5 5\n .#.#.\n #.#.#\n .#.#.\n #.#.#\n .#.#.", "output": "4"}]
Print the minimum number of operations needed. * * *
s974262270
Runtime Error
p02735
Input is given from Standard Input in the following format: H W s_{11} s_{12} \cdots s_{1W} s_{21} s_{22} \cdots s_{2W} \vdots s_{H1} s_{H2} \cdots s_{HW} Here s_{rc} represents the color of (r, c) \- `#` stands for black, and `.` stands for white.
H, W = map(int, input().split()) S = [input() for _ in range(W)] M = [] def dfs(m, n, history): history_ = history + S[m][n] if H - m > 1: dfs(m + 1, n, history_) if W - n > 1: dfs(m, n + 1, history_) if H - m == 1 and H - n == 1: count = 0 for h in history_: if h == "#": count += 1 M.append(count) return dfs(0, 0, "") print(min(M))
Statement Consider a grid with H rows and W columns of squares. Let (r, c) denote the square at the r-th row from the top and the c-th column from the left. Each square is painted black or white. The grid is said to be _good_ if and only if the following condition is satisfied: * From (1, 1), we can reach (H, W) by moving one square **right or down** repeatedly, while always being on a white square. Note that (1, 1) and (H, W) must be white if the grid is good. Your task is to make the grid good by repeating the operation below. Find the minimum number of operations needed to complete the task. It can be proved that you can always complete the task in a finite number of operations. * Choose four integers r_0, c_0, r_1, c_1(1 \leq r_0 \leq r_1 \leq H, 1 \leq c_0 \leq c_1 \leq W). For each pair r, c (r_0 \leq r \leq r_1, c_0 \leq c \leq c_1), invert the color of (r, c) \- that is, from white to black and vice versa.
[{"input": "3 3\n .##\n .#.\n ##.", "output": "1\n \n\nDo the operation with (r_0, c_0, r_1, c_1) = (2, 2, 2, 2) to change just the\ncolor of (2, 2), and we are done.\n\n* * *"}, {"input": "2 2\n #.\n .#", "output": "2\n \n\n* * *"}, {"input": "4 4\n ..##\n #...\n ###.\n ###.", "output": "0\n \n\nNo operation may be needed.\n\n* * *"}, {"input": "5 5\n .#.#.\n #.#.#\n .#.#.\n #.#.#\n .#.#.", "output": "4"}]
Print the minimum number of operations needed. * * *
s377724157
Runtime Error
p02735
Input is given from Standard Input in the following format: H W s_{11} s_{12} \cdots s_{1W} s_{21} s_{22} \cdots s_{2W} \vdots s_{H1} s_{H2} \cdots s_{HW} Here s_{rc} represents the color of (r, c) \- `#` stands for black, and `.` stands for white.
def checkpath(h, w, table, max_bomb): result = False x = 0 y = 0 bomb = max_bomb # x先行パターン while True: # # print("x:{} y:{} bomb:{}".format(x,y,bomb)) init = False if x == w and y == h: # 端についたらゴール result = True break if bomb > 0 and init == False and table[0][0] == "#": # 現在地が黒ならボムで bomb -= 1 init = True elif ( bomb > 0 and ((x == w and y == h - 1) or (x == w - 1 and y == h)) and table[w][h] == "#" ): # ゴールが黒ならボムで bomb -= 1 result = True break elif x < w and table[x + 1][y] == ".": # # print('右に進む') x += 1 elif y < h and table[x][y + 1] == ".": # # print(' 下に進む') y += 1 elif ( bomb > 0 and x < w - 1 and table[x + 1][y] == "#" and table[x + 2][y] == "." ): # # print(' 右にボムから右に行く') bomb -= 1 x += 2 elif ( bomb > 0 and x < w and y < h and table[x + 1][y] == "#" and table[x + 1][y + 1] == "." ): # # print(' 右にボムから下に行く') bomb -= 1 x += 1 y += 1 elif ( bomb > 0 and y < h and x < w and table[x][y + 1] == "#" and table[x + 1][y + 1] == "." ): # # print(' 下にボムから右に行く') bomb -= 1 y += 1 x += 1 elif ( bomb > 0 and y < h - 1 and table[x][y + 1] == "#" and table[x][y + 2] == "." ): # # print(' 下にボムから下に行く') bomb -= 1 y += 2 else: break if result: return result # y先行パターン while True: # # print("x:{} y:{}".format(x,y)) init = False if x == w and y == h: result = True break if bomb > 0 and init == False and table[0][0] == "#": # 現在地が黒ならボムで bomb -= 1 init = True elif ( bomb > 0 and ((x == w and y == h - 1) or (x == w - 1 and y == h)) and table[w][h] == "#" ): # ゴールが黒ならボムで bomb -= 1 result = True break elif y < h and table[x][y + 1] == ".": # # print(' 下に進む') y += 1 elif x < w and table[x + 1][y] == ".": # # print(' 右に進む') x += 1 elif ( bomb > 0 and x < w - 1 and table[x + 1][y] == "#" and table[x + 2][y] == "." ): # # print(' 右にボムから右に行く') bomb -= 1 x += 2 elif ( bomb > 0 and x < w and y < h and table[x + 1][y] == "#" and table[x + 1][y + 1] == "." ): # # print(' 右にボムから下に行く') bomb -= 1 x += 1 y += 1 elif ( bomb > 0 and y < h and x < w and table[x][y + 1] == "#" and table[x + 1][y + 1] == "." ): # # print(' 下にボムから右に行く') bomb -= 1 y += 1 x += 1 elif ( bomb > 0 and y < h - 1 and table[x][y + 1] == "#" and table[x][y + 2] == "." ): # # print(' 下にボムから下に行く') bomb -= 1 y += 2 else: break return result # メイン関数 # 入力からテーブル作成 hw = input("") h = int(hw.split(" ")[0]) w = int(hw.split(" ")[1]) table = [] for i in range(0, h): line = input("") r = [] for j in range(0, w): r.append(line[j]) table.append(r) for c in range(0, h * w): # # print("bomb:{}".format(c)) if checkpath(h - 1, w - 1, table, c): # # print('Success!!') print(c) break
Statement Consider a grid with H rows and W columns of squares. Let (r, c) denote the square at the r-th row from the top and the c-th column from the left. Each square is painted black or white. The grid is said to be _good_ if and only if the following condition is satisfied: * From (1, 1), we can reach (H, W) by moving one square **right or down** repeatedly, while always being on a white square. Note that (1, 1) and (H, W) must be white if the grid is good. Your task is to make the grid good by repeating the operation below. Find the minimum number of operations needed to complete the task. It can be proved that you can always complete the task in a finite number of operations. * Choose four integers r_0, c_0, r_1, c_1(1 \leq r_0 \leq r_1 \leq H, 1 \leq c_0 \leq c_1 \leq W). For each pair r, c (r_0 \leq r \leq r_1, c_0 \leq c \leq c_1), invert the color of (r, c) \- that is, from white to black and vice versa.
[{"input": "3 3\n .##\n .#.\n ##.", "output": "1\n \n\nDo the operation with (r_0, c_0, r_1, c_1) = (2, 2, 2, 2) to change just the\ncolor of (2, 2), and we are done.\n\n* * *"}, {"input": "2 2\n #.\n .#", "output": "2\n \n\n* * *"}, {"input": "4 4\n ..##\n #...\n ###.\n ###.", "output": "0\n \n\nNo operation may be needed.\n\n* * *"}, {"input": "5 5\n .#.#.\n #.#.#\n .#.#.\n #.#.#\n .#.#.", "output": "4"}]
Print the minimum number of operations needed. * * *
s283149578
Runtime Error
p02735
Input is given from Standard Input in the following format: H W s_{11} s_{12} \cdots s_{1W} s_{21} s_{22} \cdots s_{2W} \vdots s_{H1} s_{H2} \cdots s_{HW} Here s_{rc} represents the color of (r, c) \- `#` stands for black, and `.` stands for white.
N, A, B = map(int, input().split(" ")) distance = abs(B - A) res = 0 if distance % 2 == 0: res = distance / 2 else: a, b = min(A, B), max(A, B) ans = distance // 2 + min(a - 1, N - b) + 1
Statement Consider a grid with H rows and W columns of squares. Let (r, c) denote the square at the r-th row from the top and the c-th column from the left. Each square is painted black or white. The grid is said to be _good_ if and only if the following condition is satisfied: * From (1, 1), we can reach (H, W) by moving one square **right or down** repeatedly, while always being on a white square. Note that (1, 1) and (H, W) must be white if the grid is good. Your task is to make the grid good by repeating the operation below. Find the minimum number of operations needed to complete the task. It can be proved that you can always complete the task in a finite number of operations. * Choose four integers r_0, c_0, r_1, c_1(1 \leq r_0 \leq r_1 \leq H, 1 \leq c_0 \leq c_1 \leq W). For each pair r, c (r_0 \leq r \leq r_1, c_0 \leq c \leq c_1), invert the color of (r, c) \- that is, from white to black and vice versa.
[{"input": "3 3\n .##\n .#.\n ##.", "output": "1\n \n\nDo the operation with (r_0, c_0, r_1, c_1) = (2, 2, 2, 2) to change just the\ncolor of (2, 2), and we are done.\n\n* * *"}, {"input": "2 2\n #.\n .#", "output": "2\n \n\n* * *"}, {"input": "4 4\n ..##\n #...\n ###.\n ###.", "output": "0\n \n\nNo operation may be needed.\n\n* * *"}, {"input": "5 5\n .#.#.\n #.#.#\n .#.#.\n #.#.#\n .#.#.", "output": "4"}]
Print the minimum number of operations needed. * * *
s454059021
Accepted
p02735
Input is given from Standard Input in the following format: H W s_{11} s_{12} \cdots s_{1W} s_{21} s_{22} \cdots s_{2W} \vdots s_{H1} s_{H2} \cdots s_{HW} Here s_{rc} represents the color of (r, c) \- `#` stands for black, and `.` stands for white.
def main(): import sys input = sys.stdin.buffer.readline h, w = map(int, input().split()) t, *s, _ = input() if t == 46: c, f = 0, False else: c, f = 1, True p = [(c, f)] for t in s: g = t == 35 if g != f: c += 1 f = not f p += ((c, f),) d = p for _ in range(h - 1): t, *s, _ = input() c, f = d[0] g = t == 35 if g != f: c += 1 f = not f p = [(c, f)] for i, t in enumerate(s, 1): e, h = d[i] g = t == 35 if h != g: e += 1 h = not h if f != g: c += 1 f = not f if e < c: c, f = e, h p += ((c, f),) d = p print(d[-1][0] + 1 >> 1) main()
Statement Consider a grid with H rows and W columns of squares. Let (r, c) denote the square at the r-th row from the top and the c-th column from the left. Each square is painted black or white. The grid is said to be _good_ if and only if the following condition is satisfied: * From (1, 1), we can reach (H, W) by moving one square **right or down** repeatedly, while always being on a white square. Note that (1, 1) and (H, W) must be white if the grid is good. Your task is to make the grid good by repeating the operation below. Find the minimum number of operations needed to complete the task. It can be proved that you can always complete the task in a finite number of operations. * Choose four integers r_0, c_0, r_1, c_1(1 \leq r_0 \leq r_1 \leq H, 1 \leq c_0 \leq c_1 \leq W). For each pair r, c (r_0 \leq r \leq r_1, c_0 \leq c \leq c_1), invert the color of (r, c) \- that is, from white to black and vice versa.
[{"input": "3 3\n .##\n .#.\n ##.", "output": "1\n \n\nDo the operation with (r_0, c_0, r_1, c_1) = (2, 2, 2, 2) to change just the\ncolor of (2, 2), and we are done.\n\n* * *"}, {"input": "2 2\n #.\n .#", "output": "2\n \n\n* * *"}, {"input": "4 4\n ..##\n #...\n ###.\n ###.", "output": "0\n \n\nNo operation may be needed.\n\n* * *"}, {"input": "5 5\n .#.#.\n #.#.#\n .#.#.\n #.#.#\n .#.#.", "output": "4"}]
Print the minimum number of operations needed. * * *
s306753701
Wrong Answer
p02735
Input is given from Standard Input in the following format: H W s_{11} s_{12} \cdots s_{1W} s_{21} s_{22} \cdots s_{2W} \vdots s_{H1} s_{H2} \cdots s_{HW} Here s_{rc} represents the color of (r, c) \- `#` stands for black, and `.` stands for white.
print(0)
Statement Consider a grid with H rows and W columns of squares. Let (r, c) denote the square at the r-th row from the top and the c-th column from the left. Each square is painted black or white. The grid is said to be _good_ if and only if the following condition is satisfied: * From (1, 1), we can reach (H, W) by moving one square **right or down** repeatedly, while always being on a white square. Note that (1, 1) and (H, W) must be white if the grid is good. Your task is to make the grid good by repeating the operation below. Find the minimum number of operations needed to complete the task. It can be proved that you can always complete the task in a finite number of operations. * Choose four integers r_0, c_0, r_1, c_1(1 \leq r_0 \leq r_1 \leq H, 1 \leq c_0 \leq c_1 \leq W). For each pair r, c (r_0 \leq r \leq r_1, c_0 \leq c \leq c_1), invert the color of (r, c) \- that is, from white to black and vice versa.
[{"input": "3 3\n .##\n .#.\n ##.", "output": "1\n \n\nDo the operation with (r_0, c_0, r_1, c_1) = (2, 2, 2, 2) to change just the\ncolor of (2, 2), and we are done.\n\n* * *"}, {"input": "2 2\n #.\n .#", "output": "2\n \n\n* * *"}, {"input": "4 4\n ..##\n #...\n ###.\n ###.", "output": "0\n \n\nNo operation may be needed.\n\n* * *"}, {"input": "5 5\n .#.#.\n #.#.#\n .#.#.\n #.#.#\n .#.#.", "output": "4"}]
Print the minimum number of operations needed. * * *
s537915032
Wrong Answer
p02735
Input is given from Standard Input in the following format: H W s_{11} s_{12} \cdots s_{1W} s_{21} s_{22} \cdots s_{2W} \vdots s_{H1} s_{H2} \cdots s_{HW} Here s_{rc} represents the color of (r, c) \- `#` stands for black, and `.` stands for white.
h, w = map(int, input().split()) board = [list(input()) for i in range(h)] r = 0 c = 0 ans = 0 print(board[r][c])
Statement Consider a grid with H rows and W columns of squares. Let (r, c) denote the square at the r-th row from the top and the c-th column from the left. Each square is painted black or white. The grid is said to be _good_ if and only if the following condition is satisfied: * From (1, 1), we can reach (H, W) by moving one square **right or down** repeatedly, while always being on a white square. Note that (1, 1) and (H, W) must be white if the grid is good. Your task is to make the grid good by repeating the operation below. Find the minimum number of operations needed to complete the task. It can be proved that you can always complete the task in a finite number of operations. * Choose four integers r_0, c_0, r_1, c_1(1 \leq r_0 \leq r_1 \leq H, 1 \leq c_0 \leq c_1 \leq W). For each pair r, c (r_0 \leq r \leq r_1, c_0 \leq c \leq c_1), invert the color of (r, c) \- that is, from white to black and vice versa.
[{"input": "3 3\n .##\n .#.\n ##.", "output": "1\n \n\nDo the operation with (r_0, c_0, r_1, c_1) = (2, 2, 2, 2) to change just the\ncolor of (2, 2), and we are done.\n\n* * *"}, {"input": "2 2\n #.\n .#", "output": "2\n \n\n* * *"}, {"input": "4 4\n ..##\n #...\n ###.\n ###.", "output": "0\n \n\nNo operation may be needed.\n\n* * *"}, {"input": "5 5\n .#.#.\n #.#.#\n .#.#.\n #.#.#\n .#.#.", "output": "4"}]
Print the minimum number of operations needed. * * *
s079905812
Runtime Error
p02735
Input is given from Standard Input in the following format: H W s_{11} s_{12} \cdots s_{1W} s_{21} s_{22} \cdots s_{2W} \vdots s_{H1} s_{H2} \cdots s_{HW} Here s_{rc} represents the color of (r, c) \- `#` stands for black, and `.` stands for white.
# -*- utf-8 -*- tar_x, tar_y = map(int, input().split()) stage = [] tmp = list(input().split()) while not 0 == len(tmp): stage.append(tmp) tmp = list(input()) ans = 1000000000 tar_x, tar_y = (tar_x - 1, tar_y - 1) now_x, now_y = (0, 0) # serch cnt = 0 while now_x != tar_x or now_y != tar_y: if "#" == stage[now_x][now_y]: cnt += 1 # move next if tar_x == now_x: next_x = now_x else: next_x = now_x + 1 if tar_y == now_y: next_y = now_y else: next_y = now_y + 1 # setch x if "#" != stage[next_x][now_y] and tar_x != now_x: now_x = next_x # serch y elif "#" != stage[now_x][next_y] and tar_y != now_y: now_y = next_y # bose "#" else: if tar_x != now_x: now_x = next_x elif tar_x != now_x: now_y = next_y else: tmp_cnt_x = 0 tmp_cnt_y = 0 # x next_next_x = next_x + 1 if tar_x >= (next_x + 1) else None next_next_y = now_y + 1 if tar_y >= (now_y + 1) else None if not None is next_next_x: if "." == stage[next_next_x][now_y]: tmp_cnt_x += 1 if not None is next_next_y: if "." == stage[next_x][next_next_y]: tmp_cnt_x += 1 if not None is next_next_x and not None is next_next_y: if "." == stage[next_next_x][next_next_y]: tmp_cnt_x += 1 # y next_next_x = now_x + 1 if tar_x >= (now_x + 1) else None next_next_y = next_y + 1 if tar_y >= (next_y + 1) else None if not None is next_next_x: if "." == stage[next_next_x][next_y]: tmp_cnt_y += 1 if not None is next_next_y: if "." == stage[now_x][next_next_y]: tmp_cnt_y += 1 if not None is next_next_x and not None is next_next_y: if "." == stage[next_next_x][next_next_y]: tmp_cnt_y += 1 if tmp_cnt_x >= tmp_cnt_y: now_x = next_x else: now_y = next_y if "#" == stage[now_x][now_y]: cnt += 1 print(cnt)
Statement Consider a grid with H rows and W columns of squares. Let (r, c) denote the square at the r-th row from the top and the c-th column from the left. Each square is painted black or white. The grid is said to be _good_ if and only if the following condition is satisfied: * From (1, 1), we can reach (H, W) by moving one square **right or down** repeatedly, while always being on a white square. Note that (1, 1) and (H, W) must be white if the grid is good. Your task is to make the grid good by repeating the operation below. Find the minimum number of operations needed to complete the task. It can be proved that you can always complete the task in a finite number of operations. * Choose four integers r_0, c_0, r_1, c_1(1 \leq r_0 \leq r_1 \leq H, 1 \leq c_0 \leq c_1 \leq W). For each pair r, c (r_0 \leq r \leq r_1, c_0 \leq c \leq c_1), invert the color of (r, c) \- that is, from white to black and vice versa.
[{"input": "3 3\n .##\n .#.\n ##.", "output": "1\n \n\nDo the operation with (r_0, c_0, r_1, c_1) = (2, 2, 2, 2) to change just the\ncolor of (2, 2), and we are done.\n\n* * *"}, {"input": "2 2\n #.\n .#", "output": "2\n \n\n* * *"}, {"input": "4 4\n ..##\n #...\n ###.\n ###.", "output": "0\n \n\nNo operation may be needed.\n\n* * *"}, {"input": "5 5\n .#.#.\n #.#.#\n .#.#.\n #.#.#\n .#.#.", "output": "4"}]
Print the minimum number of operations needed. * * *
s406262363
Runtime Error
p02735
Input is given from Standard Input in the following format: H W s_{11} s_{12} \cdots s_{1W} s_{21} s_{22} \cdots s_{2W} \vdots s_{H1} s_{H2} \cdots s_{HW} Here s_{rc} represents the color of (r, c) \- `#` stands for black, and `.` stands for white.
import sys sys.setrecursionlimit(10**8) def maze(r, c, MAP, count, shaf, H, W): # print(r, c, count, shaf) if r == H - 1 and c == W - 1: if shaf == 1 and MAP[r][c] == "#": print(count) exit() if shaf == 0 and MAP[r][c] == ".": print(count) exit() if r == H or c == W: return if shaf == 0: if r != H - 1 and MAP[r + 1][c] == ".": maze(r + 1, c, MAP, count, shaf, H, W) elif c != W - 1 and MAP[r][c + 1] == ".": maze(r, c + 1, MAP, count, shaf, H, W) else: if r != H - 1: maze(r + 1, c, MAP, count + 1, 1, H, W) if c != W - 1: maze(r, c + 1, MAP, count + 1, 1, H, W) if shaf == 1: if r != H - 1 and MAP[r + 1][c] == "#": maze(r + 1, c, MAP, count, shaf, H, W) elif c != W - 1 and MAP[r][c + 1] == "#": maze(r, c + 1, MAP, count, shaf, H, W) else: if r != H - 1: maze(r + 1, c, MAP, count, 0, H, W) if c != W - 1: maze(r, c + 1, MAP, count, 0, H, W) def main(): H, W = list(map(int, input().split())) MAP = [[int() for x in range(H)] for xx in range(W)] for i in range(W): MAP[i] = input() count = 0 shaf = 0 if MAP[0][0] == "#": shaf = 1 count = 1 print(maze(0, 0, MAP, count, shaf, H, W)) main()
Statement Consider a grid with H rows and W columns of squares. Let (r, c) denote the square at the r-th row from the top and the c-th column from the left. Each square is painted black or white. The grid is said to be _good_ if and only if the following condition is satisfied: * From (1, 1), we can reach (H, W) by moving one square **right or down** repeatedly, while always being on a white square. Note that (1, 1) and (H, W) must be white if the grid is good. Your task is to make the grid good by repeating the operation below. Find the minimum number of operations needed to complete the task. It can be proved that you can always complete the task in a finite number of operations. * Choose four integers r_0, c_0, r_1, c_1(1 \leq r_0 \leq r_1 \leq H, 1 \leq c_0 \leq c_1 \leq W). For each pair r, c (r_0 \leq r \leq r_1, c_0 \leq c \leq c_1), invert the color of (r, c) \- that is, from white to black and vice versa.
[{"input": "3 3\n .##\n .#.\n ##.", "output": "1\n \n\nDo the operation with (r_0, c_0, r_1, c_1) = (2, 2, 2, 2) to change just the\ncolor of (2, 2), and we are done.\n\n* * *"}, {"input": "2 2\n #.\n .#", "output": "2\n \n\n* * *"}, {"input": "4 4\n ..##\n #...\n ###.\n ###.", "output": "0\n \n\nNo operation may be needed.\n\n* * *"}, {"input": "5 5\n .#.#.\n #.#.#\n .#.#.\n #.#.#\n .#.#.", "output": "4"}]
Print the sum of the weights the Minimum-Cost Arborescence.
s251442501
Wrong Answer
p02365
|V| |E| r s0 t0 w0 s1 t1 w1 : s|E|-1 t|E|-1 w|E|-1 , where |V| is the number of vertices and |E| is the number of edges in the graph. The graph vertices are named with the numbers 0, 1,..., |V|-1 respectively. r is the root of the Minimum-Cost Arborescence. si and ti represent source and target verticess of i-th directed edge. wi represents the weight of the i-th directed edge.
import heapq as pq n,E,r = map(int, input().split()) M = [[] for i in range(n)] for i in range(E): s,t,w = map(int, input().split()) M[s].append([t,w]) def prim(r): color = [0] * n d = [float("inf")] * n d[r] = 0 H = [] pq.heappush(H, [0, r]) while H: u2,u1 = pq.heappop(H) color[u1] = 1 if d[u1] < u2: continue for v1, v2 in M[u1]: if color[v1] == 1: continue if d[v1] > v2: d[v1] = v2 pq.heappush(H, [d[v1], v1]) return sum(d) print(prim(r))
Minimum-Cost Arborescence Find the sum of the weights of edges of the Minimum-Cost Arborescence with the root r for a given weighted directed graph G = (V, E).
[{"input": "4 6 0\n 0 1 3\n 0 2 2\n 2 0 1\n 2 3 1\n 3 0 1\n 3 1 5", "output": "6"}, {"input": "6 10 0\n 0 2 7\n 0 1 1\n 0 3 5\n 1 4 9\n 2 1 6\n 1 3 2\n 3 4 3\n 4 2 2\n 2 5 8\n 3 5 3", "output": "11"}]
Print the sum of the weights the Minimum-Cost Arborescence.
s217883813
Runtime Error
p02365
|V| |E| r s0 t0 w0 s1 t1 w1 : s|E|-1 t|E|-1 w|E|-1 , where |V| is the number of vertices and |E| is the number of edges in the graph. The graph vertices are named with the numbers 0, 1,..., |V|-1 respectively. r is the root of the Minimum-Cost Arborescence. si and ti represent source and target verticess of i-th directed edge. wi represents the weight of the i-th directed edge.
# Acceptance of input import sys file_input = sys.stdin v_num, e_num, r = map(int, file_input.readline().split()) G = [[] for i in range(v_num)] import heapq for line in file_input: s, t, w = map(int, line.split()) if t != r: heapq.heappush(G[t], [w, s, t]) # Edmonds' algorithm def find_cycle(incoming_edges, root): in_tree = [False] * v_num in_tree[root] = True for e in incoming_edges[:root] + incoming_edges[root + 1 :]: S = [] S.append(e[2]) while True: p = incoming_edges[S[-1]][1] if in_tree[p]: while S: in_tree[S.pop()] = True break elif p in S: return S[S.index(p) :] # return nodes in a cycle else: S.append(p) return None def contract_cycle(digraph, cycle_node): for edges in digraph: min_weight = edges[0][0] for e in edges: e[0] -= min_weight contracted_edges = [] for n in cycle_node: edge_set_in_cycle = digraph[n] heapq.heappop(edge_set_in_cycle) for e in edge_set_in_cycle: heapq.heappush(contracted_edges, e) for n in cycle_node: digraph[n] = contracted_edges def edmonds_branching(digraph, root, weight): min_incoming_edges = [None] * v_num for edges in digraph[:root] + digraph[root + 1 :]: min_edge = edges[0] min_incoming_edges[min_edge[2]] = min_edge weight += min_edge[0] C = find_cycle(min_incoming_edges, root) if not C: return weight else: contract_cycle(digraph, C) return edmonds_branching(digraph, root, weight) # output print(edmonds_branching(G, r, 0))
Minimum-Cost Arborescence Find the sum of the weights of edges of the Minimum-Cost Arborescence with the root r for a given weighted directed graph G = (V, E).
[{"input": "4 6 0\n 0 1 3\n 0 2 2\n 2 0 1\n 2 3 1\n 3 0 1\n 3 1 5", "output": "6"}, {"input": "6 10 0\n 0 2 7\n 0 1 1\n 0 3 5\n 1 4 9\n 2 1 6\n 1 3 2\n 3 4 3\n 4 2 2\n 2 5 8\n 3 5 3", "output": "11"}]
Print the sum of the weights the Minimum-Cost Arborescence.
s577994891
Accepted
p02365
|V| |E| r s0 t0 w0 s1 t1 w1 : s|E|-1 t|E|-1 w|E|-1 , where |V| is the number of vertices and |E| is the number of edges in the graph. The graph vertices are named with the numbers 0, 1,..., |V|-1 respectively. r is the root of the Minimum-Cost Arborescence. si and ti represent source and target verticess of i-th directed edge. wi represents the weight of the i-th directed edge.
# Edige Weighted Digraph from collections import namedtuple WeightedEdge = namedtuple("WeightedEdge", ("src", "dest", "weight")) class Digraph: def __init__(self, v): self.v = v self._edges = [[] for _ in range(v)] def add(self, edge): self._edges[edge.src].append(edge) def adj(self, v): return self._edges[v] def edges(self): for es in self._edges: for e in es: yield e def mca_chu_liu_edmonds(graph, s): def select_edges(): es = [None] * graph.v for v in range(graph.v): for e in graph.adj(v): w = e.dest if w == s: continue if es[w] is None or e.weight < es[w].weight: es[w] = e return es def find_cycle(es): vs = [0 for _ in range(graph.v)] for e in es: if e is None: continue vs[e.src] += 1 leaves = [v for v, c in enumerate(vs) if c == 0] while leaves: leaf, *leaves = leaves if es[leaf] is not None: w = es[leaf].src vs[w] -= 1 if vs[w] == 0: leaves.append(w) cycle = [] for v, c in enumerate(vs): if c > 0: cycle.append(v) u = es[v].src while u != v: cycle.append(u) u = es[u].src break return cycle def contract(es, vs): vvs = [] vv = 0 c = graph.v - len(vs) for v in range(graph.v): if v in vs: vvs.append(c) else: vvs.append(vv) vv += 1 g = Digraph(c + 1) for v in range(graph.v): for e in graph.adj(v): if e.src not in vs or e.dest not in vs: v = vvs[e.src] w = vvs[e.dest] weight = e.weight if e.dest in vs: weight -= es[e.dest].weight e = WeightedEdge(v, w, weight) g.add(e) return g, vvs[s] edges = select_edges() cycle = find_cycle(edges) if cycle: g, ss = contract(edges, cycle) return mca_chu_liu_edmonds(g, ss) + sum(edges[v].weight for v in cycle) else: return sum(e.weight for e in edges if e is not None) def run(): v, e, r = [int(i) for i in input().split()] graph = Digraph(v) for _ in range(e): s, t, w = [int(i) for i in input().split()] graph.add(WeightedEdge(s, t, w)) print(mca_chu_liu_edmonds(graph, r)) if __name__ == "__main__": run()
Minimum-Cost Arborescence Find the sum of the weights of edges of the Minimum-Cost Arborescence with the root r for a given weighted directed graph G = (V, E).
[{"input": "4 6 0\n 0 1 3\n 0 2 2\n 2 0 1\n 2 3 1\n 3 0 1\n 3 1 5", "output": "6"}, {"input": "6 10 0\n 0 2 7\n 0 1 1\n 0 3 5\n 1 4 9\n 2 1 6\n 1 3 2\n 3 4 3\n 4 2 2\n 2 5 8\n 3 5 3", "output": "11"}]
If there exists no unbalanced substring of s, print `-1 -1`. If there exists an unbalanced substring of s, let one such substring be s_a s_{a+1} ... s_{b} (1 ≦ a < b ≦ |s|), and print `a b`. If there exists more than one such substring, any of them will be accepted. * * *
s957253605
Runtime Error
p04032
The input is given from Standard Input in the following format: s
str = input() flg=0 for n in range(0,len(str)-2): if(str[n]==str[n+1]): print(n+1,n+2) flg =1 break elif (str[n]==str[n+2]): print(n+1,n+3) flg=1 break if flg =0: print(-1,-1)
Statement Given a string t, we will call it _unbalanced_ if and only if the length of t is at least 2, and more than half of the letters in t are the same. For example, both `voodoo` and `melee` are unbalanced, while neither `noon` nor `a` is. You are given a string s consisting of lowercase letters. Determine if there exists a (contiguous) substring of s that is unbalanced. If the answer is positive, show a position where such a substring occurs in s.
[{"input": "needed", "output": "2 5\n \n\nThe string s_2 s_3 s_4 s_5 = `eede` is unbalanced. There are also other\nunbalanced substrings. For example, the output `2 6` will also be accepted.\n\n* * *"}, {"input": "atcoder", "output": "-1 -1\n \n\nThe string `atcoder` contains no unbalanced substring."}]
If there exists no unbalanced substring of s, print `-1 -1`. If there exists an unbalanced substring of s, let one such substring be s_a s_{a+1} ... s_{b} (1 ≦ a < b ≦ |s|), and print `a b`. If there exists more than one such substring, any of them will be accepted. * * *
s440824171
Accepted
p04032
The input is given from Standard Input in the following format: s
import sys, collections as cl, bisect as bs sys.setrecursionlimit(100000) input = sys.stdin.readline mod = 10**9 + 7 Max = sys.maxsize def l(): # intのlist return list(map(int, input().split())) def m(): # 複数文字 return map(int, input().split()) def onem(): # Nとかの取得 return int(input()) def s(x): # 圧縮 a = [] if len(x) == 0: return [] aa = x[0] su = 1 for i in range(len(x) - 1): if aa != x[i + 1]: a.append([aa, su]) aa = x[i + 1] su = 1 else: su += 1 a.append([aa, su]) return a def jo(x): # listをスペースごとに分ける return " ".join(map(str, x)) def max2(x): # 他のときもどうように作成可能 return max(map(max, x)) def In(x, a): # aがリスト(sorted) k = bs.bisect_left(a, x) if k != len(a) and a[k] == x: return True else: return False def pow_k(x, n): ans = 1 while n: if n % 2: ans *= x x *= x n >>= 1 return ans """ def nibu(x,n,r): ll = 0 rr = r while True: mid = (ll+rr)//2 if rr == mid: return ll if (ここに評価入れる): rr = mid else: ll = mid+1 """ s = input()[:-1] a, b = -1, -1 for i in range(1, len(s)): if i >= 2: if s[i] == s[i - 1]: a = i b = i + 1 break if s[i] == s[i - 2]: a = i - 1 b = i + 1 break else: if s[i] == s[i - 1]: a = i b = i + 1 break print(a, b)
Statement Given a string t, we will call it _unbalanced_ if and only if the length of t is at least 2, and more than half of the letters in t are the same. For example, both `voodoo` and `melee` are unbalanced, while neither `noon` nor `a` is. You are given a string s consisting of lowercase letters. Determine if there exists a (contiguous) substring of s that is unbalanced. If the answer is positive, show a position where such a substring occurs in s.
[{"input": "needed", "output": "2 5\n \n\nThe string s_2 s_3 s_4 s_5 = `eede` is unbalanced. There are also other\nunbalanced substrings. For example, the output `2 6` will also be accepted.\n\n* * *"}, {"input": "atcoder", "output": "-1 -1\n \n\nThe string `atcoder` contains no unbalanced substring."}]
If there exists no unbalanced substring of s, print `-1 -1`. If there exists an unbalanced substring of s, let one such substring be s_a s_{a+1} ... s_{b} (1 ≦ a < b ≦ |s|), and print `a b`. If there exists more than one such substring, any of them will be accepted. * * *
s661734710
Accepted
p04032
The input is given from Standard Input in the following format: s
# -*- coding: utf-8 -*- ############# # Libraries # ############# import sys input = sys.stdin.readline import math # from math import gcd import bisect import heapq from collections import defaultdict from collections import deque from collections import Counter from functools import lru_cache ############# # Constants # ############# MOD = 10**9 + 7 INF = float("inf") AZ = "abcdefghijklmnopqrstuvwxyz" ############# # Functions # ############# ######INPUT###### def I(): return int(input().strip()) def S(): return input().strip() def IL(): return list(map(int, input().split())) def SL(): return list(map(str, input().split())) def ILs(n): return list(int(input()) for _ in range(n)) def SLs(n): return list(input().strip() for _ in range(n)) def ILL(n): return [list(map(int, input().split())) for _ in range(n)] def SLL(n): return [list(map(str, input().split())) for _ in range(n)] ######OUTPUT###### def P(arg): print(arg) return def Y(): print("Yes") return def N(): print("No") return def E(): exit() def PE(arg): print(arg) exit() def YE(): print("Yes") exit() def NE(): print("No") exit() #####Shorten##### def DD(arg): return defaultdict(arg) #####Inverse##### def inv(n): return pow(n, MOD - 2, MOD) ######Combination###### kaijo_memo = [] def kaijo(n): if len(kaijo_memo) > n: return kaijo_memo[n] if len(kaijo_memo) == 0: kaijo_memo.append(1) while len(kaijo_memo) <= n: kaijo_memo.append(kaijo_memo[-1] * len(kaijo_memo) % MOD) return kaijo_memo[n] gyaku_kaijo_memo = [] def gyaku_kaijo(n): if len(gyaku_kaijo_memo) > n: return gyaku_kaijo_memo[n] if len(gyaku_kaijo_memo) == 0: gyaku_kaijo_memo.append(1) while len(gyaku_kaijo_memo) <= n: gyaku_kaijo_memo.append( gyaku_kaijo_memo[-1] * pow(len(gyaku_kaijo_memo), MOD - 2, MOD) % MOD ) return gyaku_kaijo_memo[n] def nCr(n, r): if n == r: return 1 if n < r or r < 0: return 0 ret = 1 ret = ret * kaijo(n) % MOD ret = ret * gyaku_kaijo(r) % MOD ret = ret * gyaku_kaijo(n - r) % MOD return ret ######Factorization###### def factorization(n): arr = [] temp = n for i in range(2, int(-(-(n**0.5) // 1)) + 1): if temp % i == 0: cnt = 0 while temp % i == 0: cnt += 1 temp //= i arr.append([i, cnt]) if temp != 1: arr.append([temp, 1]) if arr == []: arr.append([n, 1]) return arr #####MakeDivisors###### def make_divisors(n): divisors = [] for i in range(1, int(n**0.5) + 1): if n % i == 0: divisors.append(i) if i != n // i: divisors.append(n // i) return divisors #####MakePrimes###### def make_primes(N): max = int(math.sqrt(N)) seachList = [i for i in range(2, N + 1)] primeNum = [] while seachList[0] <= max: primeNum.append(seachList[0]) tmp = seachList[0] seachList = [i for i in seachList if i % tmp != 0] primeNum.extend(seachList) return primeNum #####GCD##### def gcd(a, b): while b: a, b = b, a % b return a #####LCM##### def lcm(a, b): return a * b // gcd(a, b) #####BitCount##### def count_bit(n): count = 0 while n: n &= n - 1 count += 1 return count #####ChangeBase##### def base_10_to_n(X, n): if X // n: return base_10_to_n(X // n, n) + [X % n] return [X % n] def base_n_to_10(X, n): return sum(int(str(X)[-i - 1]) * n**i for i in range(len(str(X)))) def base_10_to_n_without_0(X, n): X -= 1 if X // n: return base_10_to_n_without_0(X // n, n) + [X % n] return [X % n] #####IntLog##### def int_log(n, a): count = 0 while n >= a: n //= a count += 1 return count ############# # Main Code # ############# S = S() N = len(S) for x in AZ: prev = -INF for i in range(N): if S[i] == x: if i - prev <= 2: print(prev + 1, i + 1) exit() prev = i print(-1, -1)
Statement Given a string t, we will call it _unbalanced_ if and only if the length of t is at least 2, and more than half of the letters in t are the same. For example, both `voodoo` and `melee` are unbalanced, while neither `noon` nor `a` is. You are given a string s consisting of lowercase letters. Determine if there exists a (contiguous) substring of s that is unbalanced. If the answer is positive, show a position where such a substring occurs in s.
[{"input": "needed", "output": "2 5\n \n\nThe string s_2 s_3 s_4 s_5 = `eede` is unbalanced. There are also other\nunbalanced substrings. For example, the output `2 6` will also be accepted.\n\n* * *"}, {"input": "atcoder", "output": "-1 -1\n \n\nThe string `atcoder` contains no unbalanced substring."}]
If there exists no unbalanced substring of s, print `-1 -1`. If there exists an unbalanced substring of s, let one such substring be s_a s_{a+1} ... s_{b} (1 ≦ a < b ≦ |s|), and print `a b`. If there exists more than one such substring, any of them will be accepted. * * *
s633679972
Runtime Error
p04032
The input is given from Standard Input in the following format: s
S = input() prvs = '' si = None for i, s in enumerate(S): if prvs == s: if si is None: si = i print(i,i+1) exit() else: if si is not None: print(si, i) prvs = s for i range(len(S)-2): if set(S[i:i+3])>=3: print(i+1, i+4) exit() print(-1, -1)
Statement Given a string t, we will call it _unbalanced_ if and only if the length of t is at least 2, and more than half of the letters in t are the same. For example, both `voodoo` and `melee` are unbalanced, while neither `noon` nor `a` is. You are given a string s consisting of lowercase letters. Determine if there exists a (contiguous) substring of s that is unbalanced. If the answer is positive, show a position where such a substring occurs in s.
[{"input": "needed", "output": "2 5\n \n\nThe string s_2 s_3 s_4 s_5 = `eede` is unbalanced. There are also other\nunbalanced substrings. For example, the output `2 6` will also be accepted.\n\n* * *"}, {"input": "atcoder", "output": "-1 -1\n \n\nThe string `atcoder` contains no unbalanced substring."}]
If there exists no unbalanced substring of s, print `-1 -1`. If there exists an unbalanced substring of s, let one such substring be s_a s_{a+1} ... s_{b} (1 ≦ a < b ≦ |s|), and print `a b`. If there exists more than one such substring, any of them will be accepted. * * *
s403943212
Runtime Error
p04032
The input is given from Standard Input in the following format: s
import sys l = [i for i in input()] dup_l = [i for i in set(l) if l.count(i) > 1] # len(l)//2] # print(dup_l) if len(dup_l) == 0: print("-1 -1") else: d = dict() for i in dup_l: d[i] = l.count(i) # print(d) dmax = max(d, key=d.get) # print(dmax) index = [] for i, s in enumerate(l, 1): if s == dmax: index.append(i) # print(index) okflag = 0 for i in range(len(index)): if i != len(index): if index[i + 1] - index[i] <= 2: print(index[i], index[i + 1]) okflag = 1 break if okflag == 0: print("-1 -1")
Statement Given a string t, we will call it _unbalanced_ if and only if the length of t is at least 2, and more than half of the letters in t are the same. For example, both `voodoo` and `melee` are unbalanced, while neither `noon` nor `a` is. You are given a string s consisting of lowercase letters. Determine if there exists a (contiguous) substring of s that is unbalanced. If the answer is positive, show a position where such a substring occurs in s.
[{"input": "needed", "output": "2 5\n \n\nThe string s_2 s_3 s_4 s_5 = `eede` is unbalanced. There are also other\nunbalanced substrings. For example, the output `2 6` will also be accepted.\n\n* * *"}, {"input": "atcoder", "output": "-1 -1\n \n\nThe string `atcoder` contains no unbalanced substring."}]
If there exists no unbalanced substring of s, print `-1 -1`. If there exists an unbalanced substring of s, let one such substring be s_a s_{a+1} ... s_{b} (1 ≦ a < b ≦ |s|), and print `a b`. If there exists more than one such substring, any of them will be accepted. * * *
s573317174
Runtime Error
p04032
The input is given from Standard Input in the following format: s
import sys def convert(num): out = "" if num == 0: out = "a" elif num == 1: out = "b" elif num == 2: out = "c" elif num == 3: out = "d" elif num == 4: out = "e" elif num == 5: out = "f" elif num == 6: out = "g" elif num == 7: out = "h" elif num == 8: out = "i" elif num == 9: out = "j" elif num == 10: out = "k" elif num == 11: out = "l" elif num == 12: out = "m" elif num == 13: out = "n" elif num == 14: out = "o" elif num == 15: out = "p" elif num == 16: out = "q" elif num == 17: out = "r" elif num == 18: out = "s" elif num == 19: out = "t" elif num == 20: out = "u" elif num == 21: out = "v" elif num == 22: out = "w" elif num == 23: out = "x" elif num == 24: out = "y" else: out = "z" return out s = input() L = [] L.append(s.count("a")) L.append(s.count("b")) L.append(s.count("c")) L.append(s.count("d")) L.append(s.count("e")) L.append(s.count("f")) L.append(s.count("g")) L.append(s.count("h")) L.append(s.count("i")) L.append(s.count("j")) L.append(s.count("k")) L.append(s.count("l")) L.append(s.count("m")) L.append(s.count("n")) L.append(s.count("o")) L.append(s.count("p")) L.append(s.count("q")) L.append(s.count("r")) L.append(s.count("s")) L.append(s.count("t")) L.append(s.count("u")) L.append(s.count("v")) L.append(s.count("w")) L.append(s.count("x")) L.append(s.count("y")) L.append(s.count("z")) flag = 0 maxlist = [] for i in range(26): if L[i] == max(L): maxlist.append(i) for j in range(len(maxlist)): for i in range(len(s)): if s[i] == convert(maxlist[j]): if s[i + 1] == convert(maxlist[j]): print("{0} {1}".format(i + 1, i + 2)) flag = 1 break if s[i + 2] == convert(maxlist[j]): print("{0} {1}".format(i + 1, i + 3)) flag = 1 break if flag == 0: print("{0} {1}".format(-1, -1))
Statement Given a string t, we will call it _unbalanced_ if and only if the length of t is at least 2, and more than half of the letters in t are the same. For example, both `voodoo` and `melee` are unbalanced, while neither `noon` nor `a` is. You are given a string s consisting of lowercase letters. Determine if there exists a (contiguous) substring of s that is unbalanced. If the answer is positive, show a position where such a substring occurs in s.
[{"input": "needed", "output": "2 5\n \n\nThe string s_2 s_3 s_4 s_5 = `eede` is unbalanced. There are also other\nunbalanced substrings. For example, the output `2 6` will also be accepted.\n\n* * *"}, {"input": "atcoder", "output": "-1 -1\n \n\nThe string `atcoder` contains no unbalanced substring."}]
If there exists no unbalanced substring of s, print `-1 -1`. If there exists an unbalanced substring of s, let one such substring be s_a s_{a+1} ... s_{b} (1 ≦ a < b ≦ |s|), and print `a b`. If there exists more than one such substring, any of them will be accepted. * * *
s468785558
Wrong Answer
p04032
The input is given from Standard Input in the following format: s
print(3, 5)
Statement Given a string t, we will call it _unbalanced_ if and only if the length of t is at least 2, and more than half of the letters in t are the same. For example, both `voodoo` and `melee` are unbalanced, while neither `noon` nor `a` is. You are given a string s consisting of lowercase letters. Determine if there exists a (contiguous) substring of s that is unbalanced. If the answer is positive, show a position where such a substring occurs in s.
[{"input": "needed", "output": "2 5\n \n\nThe string s_2 s_3 s_4 s_5 = `eede` is unbalanced. There are also other\nunbalanced substrings. For example, the output `2 6` will also be accepted.\n\n* * *"}, {"input": "atcoder", "output": "-1 -1\n \n\nThe string `atcoder` contains no unbalanced substring."}]
If there exists no unbalanced substring of s, print `-1 -1`. If there exists an unbalanced substring of s, let one such substring be s_a s_{a+1} ... s_{b} (1 ≦ a < b ≦ |s|), and print `a b`. If there exists more than one such substring, any of them will be accepted. * * *
s669364196
Wrong Answer
p04032
The input is given from Standard Input in the following format: s
# 申し訳ない s = input() for i in range(len(s)): for j in range(i + 1, len(s)): if s[i : j + 1].count("a") > len(s[i : j + 1]) / 2: print(str(i + 1) + " " + str(j + 1)) quit() if s[i : j + 1].count("b") > len(s[i : j + 1]) / 2: print(str(i + 1) + " " + str(j + 1)) quit() if s[i : j + 1].count("c") > len(s[i : j + 1]) / 2: print(str(i + 1) + " " + str(j + 1)) quit() if s[i : j + 1].count("d") > len(s[i : j + 1]) / 2: print(str(i + 1) + " " + str(j + 1)) quit() if s[i : j + 1].count("e") > len(s[i : j + 1]) / 2: print(str(i + 1) + " " + str(j + 1)) quit() if s[i : j + 1].count("f") > len(s[i : j + 1]) / 2: print(str(i + 1) + " " + str(j + 1)) quit() if s[i : j + 1].count("g") > len(s[i : j + 1]) / 2: print(str(i + 1) + " " + str(j + 1)) quit() if s[i : j + 1].count("h") > len(s[i : j + 1]) / 2: print(str(i + 1) + " " + str(j + 1)) quit() if s[i : j + 1].count("i") > len(s[i : j + 1]) / 2: print(str(i + 1) + " " + str(j + 1)) quit() if s[i : j + 1].count("j") > len(s[i : j + 1]) / 2: print(str(i + 1) + " " + str(j + 1)) quit() if s[i : j + 1].count("k") > len(s[i : j + 1]) / 2: print(str(i + 1) + " " + str(j + 1)) quit() if s[i : j + 1].count("l") > len(s[i : j + 1]) / 2: print(str(i + 1) + " " + str(j + 1)) quit() if s[i : j + 1].count("m") > len(s[i : j + 1]) / 2: print(str(i + 1) + " " + str(j + 1)) quit() if s[i : j + 1].count("n") > len(s[i : j + 1]) / 2: print(str(i + 1) + " " + str(j + 1)) quit() if s[i : j + 1].count("o") > len(s[i : j + 1]) / 2: print(str(i + 1) + " " + str(j + 1)) quit() if s[i : j + 1].count("p") > len(s[i : j + 1]) / 2: print(str(i + 1) + " " + str(j + 1)) quit() if s[i : j + 1].count("q") > len(s[i : j + 1]) / 2: print(str(i + 1) + " " + str(j + 1)) quit() if s[i : j + 1].count("r") > len(s[i : j + 1]) / 2: print(str(i + 1) + " " + str(j + 1)) quit() if s[i : j + 1].count("s") > len(s[i : j + 1]) / 2: print(str(i + 1) + " " + str(j + 1)) quit() if s[i : j + 1].count("t") > len(s[i : j + 1]) / 2: print(str(i + 1) + " " + str(j + 1)) quit() if s[i : j + 1].count("u") > len(s[i : j + 1]) / 2: print(str(i + 1) + " " + str(j + 1)) quit() if s[i : j + 1].count("v") > len(s[i : j + 1]) / 2: print(str(i + 1) + " " + str(j + 1)) quit() if s[i : j + 1].count("w") > len(s[i : j + 1]) / 2: print(str(i + 1) + " " + str(j + 1)) quit() if s[i : j + 1].count("x") > len(s[i : j + 1]) / 2: print(str(i + 1) + " " + str(j + 1)) quit() if s[i : j + 1].count("y") > len(s[i : j + 1]) / 2: print(str(i + 1) + " " + str(j + 1)) quit() if s[i : j + 1].count("z") > len(s[i : j + 1]) / 2: print(str(i + 1) + " " + str(j + 1)) quit() print("-1 - 1")
Statement Given a string t, we will call it _unbalanced_ if and only if the length of t is at least 2, and more than half of the letters in t are the same. For example, both `voodoo` and `melee` are unbalanced, while neither `noon` nor `a` is. You are given a string s consisting of lowercase letters. Determine if there exists a (contiguous) substring of s that is unbalanced. If the answer is positive, show a position where such a substring occurs in s.
[{"input": "needed", "output": "2 5\n \n\nThe string s_2 s_3 s_4 s_5 = `eede` is unbalanced. There are also other\nunbalanced substrings. For example, the output `2 6` will also be accepted.\n\n* * *"}, {"input": "atcoder", "output": "-1 -1\n \n\nThe string `atcoder` contains no unbalanced substring."}]
If there exists no unbalanced substring of s, print `-1 -1`. If there exists an unbalanced substring of s, let one such substring be s_a s_{a+1} ... s_{b} (1 ≦ a < b ≦ |s|), and print `a b`. If there exists more than one such substring, any of them will be accepted. * * *
s952227333
Wrong Answer
p04032
The input is given from Standard Input in the following format: s
# 文字列の読み取り input_str = input() max_str_len = len(input_str) # print(max_str_len) str_chars = {} # 文字と構成数の辞書を生成 for c in input_str: if c in str_chars: str_chars[c] += 1 else: str_chars[c] = 1 # print(str_chars) # 構成数が最も多い文字を取得 max_num = max(str_chars.values()) for k in str_chars.keys(): if str_chars[k] == max_num: max_char = k # print(max_char) # print(max_num) # 入力文字列から max_char_indexes = [i for i, x in enumerate(input_str) if x == max_char] # print(max_char_indexes) for count in range(len(max_char_indexes)): # for count2 in range(count + 1, len(max_char_indexes) - 1, 1): output_str = input_str[ max_char_indexes[count] : (max_char_indexes[len(max_char_indexes) - 1] + 1) ] output_str_char = output_str.count(max_char) if len(output_str) > len(input_str) / 2 and output_str_char > (len(output_str) / 2): print( "{} {}".format( max_char_indexes[count] + 1, max_char_indexes[len(max_char_indexes) - 1] + 1, ) ) break else: for count in range(1, len(max_char_indexes), 1): # for count2 in range(count + 1, len(max_char_indexes) - 1, 1): output_str = input_str[ max_char_indexes[count] : (max_char_indexes[len(max_char_indexes) - 1] + 1) ] output_str_char = output_str.count(max_char) if len(output_str) > len(input_str) / 2 and output_str_char > ( len(output_str) / 2 ): print( "{} {}".format( max_char_indexes[count] + 1, max_char_indexes[len(max_char_indexes) - 1] + 1, ) ) break print("-1 -1") # if (max_char_indexes[len(max_char_indexes)-1] - max_char_indexes[0]) >= len(input_str): #  input_str[max_char_indexes[0]:max_char_indexes[len(max_char_indexes)-1]] # print("{} {}".format(max_char_indexes[0] + 1, max_char_indexes[len(max_char_indexes)-1] + 1))
Statement Given a string t, we will call it _unbalanced_ if and only if the length of t is at least 2, and more than half of the letters in t are the same. For example, both `voodoo` and `melee` are unbalanced, while neither `noon` nor `a` is. You are given a string s consisting of lowercase letters. Determine if there exists a (contiguous) substring of s that is unbalanced. If the answer is positive, show a position where such a substring occurs in s.
[{"input": "needed", "output": "2 5\n \n\nThe string s_2 s_3 s_4 s_5 = `eede` is unbalanced. There are also other\nunbalanced substrings. For example, the output `2 6` will also be accepted.\n\n* * *"}, {"input": "atcoder", "output": "-1 -1\n \n\nThe string `atcoder` contains no unbalanced substring."}]
If there exists no unbalanced substring of s, print `-1 -1`. If there exists an unbalanced substring of s, let one such substring be s_a s_{a+1} ... s_{b} (1 ≦ a < b ≦ |s|), and print `a b`. If there exists more than one such substring, any of them will be accepted. * * *
s734333399
Wrong Answer
p04032
The input is given from Standard Input in the following format: s
s = str(input()) a = [] p = -1 q = -1 m = 0 n = 2 N = len(s) while ((p + 1) ** 2 + (q + 1) ** 2) == 0 & m != N: t = s[m:n] if n != N: n += 1 else: m += 1 n = m + 2 r = 0 for i in range(len(t)): d = list(t).count(t[i]) if r < d: r = d if r > (len(t)) / 2: p = m - 1 q = n - 2
Statement Given a string t, we will call it _unbalanced_ if and only if the length of t is at least 2, and more than half of the letters in t are the same. For example, both `voodoo` and `melee` are unbalanced, while neither `noon` nor `a` is. You are given a string s consisting of lowercase letters. Determine if there exists a (contiguous) substring of s that is unbalanced. If the answer is positive, show a position where such a substring occurs in s.
[{"input": "needed", "output": "2 5\n \n\nThe string s_2 s_3 s_4 s_5 = `eede` is unbalanced. There are also other\nunbalanced substrings. For example, the output `2 6` will also be accepted.\n\n* * *"}, {"input": "atcoder", "output": "-1 -1\n \n\nThe string `atcoder` contains no unbalanced substring."}]
If there exists no unbalanced substring of s, print `-1 -1`. If there exists an unbalanced substring of s, let one such substring be s_a s_{a+1} ... s_{b} (1 ≦ a < b ≦ |s|), and print `a b`. If there exists more than one such substring, any of them will be accepted. * * *
s931931770
Wrong Answer
p04032
The input is given from Standard Input in the following format: s
from sys import stdin, stdout import bisect import math def st(): return list(stdin.readline().strip()) def inp(): return int(stdin.readline()) def li(): return list(map(int, stdin.readline().split())) def mp(): return map(int, stdin.readline().split()) def pr(n): stdout.write(str(n) + "\n") def soe(limit): l = [1] * (limit + 1) prime = [] for i in range(2, limit + 1): if l[i]: for j in range(i * i, limit + 1, i): l[j] = 0 for i in range(2, limit + 1): if l[i]: prime.append(i) return prime def segsoe(low, high): limit = int(high**0.5) + 1 prime = soe(limit) n = high - low + 1 l = [0] * (n + 1) for i in range(len(prime)): lowlimit = (low // prime[i]) * prime[i] if lowlimit < low: lowlimit += prime[i] if lowlimit == prime[i]: lowlimit += prime[i] for j in range(lowlimit, high + 1, prime[i]): l[j - low] = 1 for i in range(low, high + 1): if not l[i - low]: if i != 1: print(i) def gcd(a, b): while b: a = a % b b, a = a, b return a def power(a, n): r = 1 while n: if n & 1: r = r * a a *= a n = n >> 1 return r def check(n, l): s = 0 for i in range(len(l)): s += (l[i] - n) * (l[i] - n) return s def solve(): s = input() c = 0 d = {} for i in range(len(s)): if s[i] in d: d[s[i]].append(i) else: d[s[i]] = [i] for i in d: l = d[i] a, b = l[0], l[-1] if b - a >= 1: if len(l) >= (b - a + 1) // 2: print(a + 1, b + 1) c = 1 break if c == 0: print(-1, -1) for _ in range(1): solve()
Statement Given a string t, we will call it _unbalanced_ if and only if the length of t is at least 2, and more than half of the letters in t are the same. For example, both `voodoo` and `melee` are unbalanced, while neither `noon` nor `a` is. You are given a string s consisting of lowercase letters. Determine if there exists a (contiguous) substring of s that is unbalanced. If the answer is positive, show a position where such a substring occurs in s.
[{"input": "needed", "output": "2 5\n \n\nThe string s_2 s_3 s_4 s_5 = `eede` is unbalanced. There are also other\nunbalanced substrings. For example, the output `2 6` will also be accepted.\n\n* * *"}, {"input": "atcoder", "output": "-1 -1\n \n\nThe string `atcoder` contains no unbalanced substring."}]
If there exists no unbalanced substring of s, print `-1 -1`. If there exists an unbalanced substring of s, let one such substring be s_a s_{a+1} ... s_{b} (1 ≦ a < b ≦ |s|), and print `a b`. If there exists more than one such substring, any of them will be accepted. * * *
s454894882
Runtime Error
p04032
The input is given from Standard Input in the following format: s
a = list(input()) b = [] for i in a: if a.count(i) >= len(a)/2: b = [j for j ,x in enumerate(a) if x == i] else: pass if not b: print(-1 1) else: print(b[0],b[1])
Statement Given a string t, we will call it _unbalanced_ if and only if the length of t is at least 2, and more than half of the letters in t are the same. For example, both `voodoo` and `melee` are unbalanced, while neither `noon` nor `a` is. You are given a string s consisting of lowercase letters. Determine if there exists a (contiguous) substring of s that is unbalanced. If the answer is positive, show a position where such a substring occurs in s.
[{"input": "needed", "output": "2 5\n \n\nThe string s_2 s_3 s_4 s_5 = `eede` is unbalanced. There are also other\nunbalanced substrings. For example, the output `2 6` will also be accepted.\n\n* * *"}, {"input": "atcoder", "output": "-1 -1\n \n\nThe string `atcoder` contains no unbalanced substring."}]
If there exists no unbalanced substring of s, print `-1 -1`. If there exists an unbalanced substring of s, let one such substring be s_a s_{a+1} ... s_{b} (1 ≦ a < b ≦ |s|), and print `a b`. If there exists more than one such substring, any of them will be accepted. * * *
s680413683
Wrong Answer
p04032
The input is given from Standard Input in the following format: s
s = list(input()) alpha = [[0 for i in range(2)] for j in range(26)] def conv(t): if t == "a": return 0 elif t == "b": return 1 elif t == "c": return 2 elif t == "d": return 3 elif t == "e": return 4 elif t == "f": return 5 elif t == "g": return 6 elif t == "h": return 7 elif t == "i": return 8 elif t == "j": return 9 elif t == "k": return 10 elif t == "l": return 11 elif t == "m": return 12 elif t == "n": return 13 elif t == "o": return 14 elif t == "p": return 15 elif t == "q": return 16 elif t == "r": return 17 elif t == "s": return 18 elif t == "t": return 19 elif t == "u": return 20 elif t == "v": return 21 elif t == "w": return 22 elif t == "x": return 23 elif t == "y": return 24 elif t == "z": return 25 index = 0 for i in s: # print(str(index)+i) if alpha[conv(i)][0] == 0: alpha[conv(i)][0] = 1 alpha[conv(i)][1] = index else: alpha[conv(i)][0] += 1 if index - alpha[conv(i)][1] + 1 < 2 * alpha[conv(i)][0]: print(alpha[conv(i)][1] + 1, index + 1) exit() else: alpha[conv(i)][1] = index index += 1 # print(alpha) print(-1, -1)
Statement Given a string t, we will call it _unbalanced_ if and only if the length of t is at least 2, and more than half of the letters in t are the same. For example, both `voodoo` and `melee` are unbalanced, while neither `noon` nor `a` is. You are given a string s consisting of lowercase letters. Determine if there exists a (contiguous) substring of s that is unbalanced. If the answer is positive, show a position where such a substring occurs in s.
[{"input": "needed", "output": "2 5\n \n\nThe string s_2 s_3 s_4 s_5 = `eede` is unbalanced. There are also other\nunbalanced substrings. For example, the output `2 6` will also be accepted.\n\n* * *"}, {"input": "atcoder", "output": "-1 -1\n \n\nThe string `atcoder` contains no unbalanced substring."}]
If there exists no unbalanced substring of s, print `-1 -1`. If there exists an unbalanced substring of s, let one such substring be s_a s_{a+1} ... s_{b} (1 ≦ a < b ≦ |s|), and print `a b`. If there exists more than one such substring, any of them will be accepted. * * *
s866884632
Runtime Error
p04032
The input is given from Standard Input in the following format: s
s = str(input()) a, b = 0, 0 for i in range(len(s)-1): if s[i] == s[i+1]: a, b = i+1, i+2 break if i != len(s)-1: elif s[i] == s[i+2]: a, b = i+1, i+3 break if a == 0: print(-1, -1) else: print(a, b)
Statement Given a string t, we will call it _unbalanced_ if and only if the length of t is at least 2, and more than half of the letters in t are the same. For example, both `voodoo` and `melee` are unbalanced, while neither `noon` nor `a` is. You are given a string s consisting of lowercase letters. Determine if there exists a (contiguous) substring of s that is unbalanced. If the answer is positive, show a position where such a substring occurs in s.
[{"input": "needed", "output": "2 5\n \n\nThe string s_2 s_3 s_4 s_5 = `eede` is unbalanced. There are also other\nunbalanced substrings. For example, the output `2 6` will also be accepted.\n\n* * *"}, {"input": "atcoder", "output": "-1 -1\n \n\nThe string `atcoder` contains no unbalanced substring."}]
If there exists no unbalanced substring of s, print `-1 -1`. If there exists an unbalanced substring of s, let one such substring be s_a s_{a+1} ... s_{b} (1 ≦ a < b ≦ |s|), and print `a b`. If there exists more than one such substring, any of them will be accepted. * * *
s680716071
Runtime Error
p04032
The input is given from Standard Input in the following format: s
def resolve(): S = list(input()) if len(S) == 2: print(-1, -1) for i in range(len(S)-3): if S[i] == S[i+1] or S[i+1] == S[i+2] or S[i+2] == S[i]): print(i+1, i+3) return print(-1, -1) if __name__ == '__main__': resolve()
Statement Given a string t, we will call it _unbalanced_ if and only if the length of t is at least 2, and more than half of the letters in t are the same. For example, both `voodoo` and `melee` are unbalanced, while neither `noon` nor `a` is. You are given a string s consisting of lowercase letters. Determine if there exists a (contiguous) substring of s that is unbalanced. If the answer is positive, show a position where such a substring occurs in s.
[{"input": "needed", "output": "2 5\n \n\nThe string s_2 s_3 s_4 s_5 = `eede` is unbalanced. There are also other\nunbalanced substrings. For example, the output `2 6` will also be accepted.\n\n* * *"}, {"input": "atcoder", "output": "-1 -1\n \n\nThe string `atcoder` contains no unbalanced substring."}]
If there exists no unbalanced substring of s, print `-1 -1`. If there exists an unbalanced substring of s, let one such substring be s_a s_{a+1} ... s_{b} (1 ≦ a < b ≦ |s|), and print `a b`. If there exists more than one such substring, any of them will be accepted. * * *
s606333958
Runtime Error
p04032
The input is given from Standard Input in the following format: s
S = input().strip() slen = len(S) s = S + '##' for i in range(slen): if s[i] == s[i+1]: print(i+1, i+2) exit() if s[i] == [i+2]: print(i+1, i+3) exit() print(-1, -1)
Statement Given a string t, we will call it _unbalanced_ if and only if the length of t is at least 2, and more than half of the letters in t are the same. For example, both `voodoo` and `melee` are unbalanced, while neither `noon` nor `a` is. You are given a string s consisting of lowercase letters. Determine if there exists a (contiguous) substring of s that is unbalanced. If the answer is positive, show a position where such a substring occurs in s.
[{"input": "needed", "output": "2 5\n \n\nThe string s_2 s_3 s_4 s_5 = `eede` is unbalanced. There are also other\nunbalanced substrings. For example, the output `2 6` will also be accepted.\n\n* * *"}, {"input": "atcoder", "output": "-1 -1\n \n\nThe string `atcoder` contains no unbalanced substring."}]
If there exists no unbalanced substring of s, print `-1 -1`. If there exists an unbalanced substring of s, let one such substring be s_a s_{a+1} ... s_{b} (1 ≦ a < b ≦ |s|), and print `a b`. If there exists more than one such substring, any of them will be accepted. * * *
s562241659
Runtime Error
p04032
The input is given from Standard Input in the following format: s
word = input() wset = set(word) ans = (-1, -1) for w in wset: if word.count(w) > len(word) / 2: p = word.index(w) + 1 ans = (p, int(len(word) / 2 + p) break print(ans[0], ans[1])
Statement Given a string t, we will call it _unbalanced_ if and only if the length of t is at least 2, and more than half of the letters in t are the same. For example, both `voodoo` and `melee` are unbalanced, while neither `noon` nor `a` is. You are given a string s consisting of lowercase letters. Determine if there exists a (contiguous) substring of s that is unbalanced. If the answer is positive, show a position where such a substring occurs in s.
[{"input": "needed", "output": "2 5\n \n\nThe string s_2 s_3 s_4 s_5 = `eede` is unbalanced. There are also other\nunbalanced substrings. For example, the output `2 6` will also be accepted.\n\n* * *"}, {"input": "atcoder", "output": "-1 -1\n \n\nThe string `atcoder` contains no unbalanced substring."}]
If there exists no unbalanced substring of s, print `-1 -1`. If there exists an unbalanced substring of s, let one such substring be s_a s_{a+1} ... s_{b} (1 ≦ a < b ≦ |s|), and print `a b`. If there exists more than one such substring, any of them will be accepted. * * *
s685079433
Accepted
p04032
The input is given from Standard Input in the following format: s
""" #kari1 = 'needed' #2 5 #kari1 = 'atcoder' #-1 -1 in1 = kari1 """ in1 = input() RC = "-1 -1" str1 = in1[0] str2 = in1[1] if str1 != str2: idx1 = 0 for idx1 in range(2, len(in1) - 2): if in1[idx1] == str1: RC = str(idx1 - 1) + " " + str(idx1 + 1) break elif in1[idx1] == str2: RC = str(idx1) + " " + str(idx1 + 1) break else: str1 = str2 str2 = in1[idx1] elif str1 == str2: RC = "1 2" print(RC)
Statement Given a string t, we will call it _unbalanced_ if and only if the length of t is at least 2, and more than half of the letters in t are the same. For example, both `voodoo` and `melee` are unbalanced, while neither `noon` nor `a` is. You are given a string s consisting of lowercase letters. Determine if there exists a (contiguous) substring of s that is unbalanced. If the answer is positive, show a position where such a substring occurs in s.
[{"input": "needed", "output": "2 5\n \n\nThe string s_2 s_3 s_4 s_5 = `eede` is unbalanced. There are also other\nunbalanced substrings. For example, the output `2 6` will also be accepted.\n\n* * *"}, {"input": "atcoder", "output": "-1 -1\n \n\nThe string `atcoder` contains no unbalanced substring."}]
If there exists no unbalanced substring of s, print `-1 -1`. If there exists an unbalanced substring of s, let one such substring be s_a s_{a+1} ... s_{b} (1 ≦ a < b ≦ |s|), and print `a b`. If there exists more than one such substring, any of them will be accepted. * * *
s007213086
Runtime Error
p04032
The input is given from Standard Input in the following format: s
#アンバランスな文字列からアンバランスでない文字列を取り除くと、 #アンバランスな文字列が残るはず。ということは、両側から文字を削り取ることで「どの部分列をとってもアンバランスな文字列」が存在するはず #すなわちそれは、両側に「ax」が存在しない文字列で、「axa」または「aa...aa」 #aaがある時点でアンバランス確定なので「axa」「aa」のどちらかを探せばよし import re s=input() alphabet="abcdefghijklmnopqrstuvwxyz" for i in alphabet: ba=s.find(i+i) if ba!=-1: print(str(ba+1)+str(ba+2)) break A=re.compile(i+"."+i) axa=A.search(s,0) if axa: ba=axa.start()) print(str(ba+1)+str(ba+3)) break
Statement Given a string t, we will call it _unbalanced_ if and only if the length of t is at least 2, and more than half of the letters in t are the same. For example, both `voodoo` and `melee` are unbalanced, while neither `noon` nor `a` is. You are given a string s consisting of lowercase letters. Determine if there exists a (contiguous) substring of s that is unbalanced. If the answer is positive, show a position where such a substring occurs in s.
[{"input": "needed", "output": "2 5\n \n\nThe string s_2 s_3 s_4 s_5 = `eede` is unbalanced. There are also other\nunbalanced substrings. For example, the output `2 6` will also be accepted.\n\n* * *"}, {"input": "atcoder", "output": "-1 -1\n \n\nThe string `atcoder` contains no unbalanced substring."}]
If there exists no unbalanced substring of s, print `-1 -1`. If there exists an unbalanced substring of s, let one such substring be s_a s_{a+1} ... s_{b} (1 ≦ a < b ≦ |s|), and print `a b`. If there exists more than one such substring, any of them will be accepted. * * *
s341331943
Runtime Error
p04032
The input is given from Standard Input in the following format: s
import numpy as np s = [ord(a)-ord('a') for a in input()] n = len(s) if n == 2: if s[0] == s[1]: print('1 2') else print('-1 -1') exit() cnt = np.array([0] * 26) cum = [cnt.copy()] for i, a in enumerate(s): cnt[a] += 1 cum.append(cnt.copy()) def is_check(cum, n): i = 3 d = 1 for j in range(n-i+1): for k in cum[j+i] - cum[j]: if k > d: return j+1, j+i return -1, -1 print(' '.join(map(str, is_check(cum, len(s)))))
Statement Given a string t, we will call it _unbalanced_ if and only if the length of t is at least 2, and more than half of the letters in t are the same. For example, both `voodoo` and `melee` are unbalanced, while neither `noon` nor `a` is. You are given a string s consisting of lowercase letters. Determine if there exists a (contiguous) substring of s that is unbalanced. If the answer is positive, show a position where such a substring occurs in s.
[{"input": "needed", "output": "2 5\n \n\nThe string s_2 s_3 s_4 s_5 = `eede` is unbalanced. There are also other\nunbalanced substrings. For example, the output `2 6` will also be accepted.\n\n* * *"}, {"input": "atcoder", "output": "-1 -1\n \n\nThe string `atcoder` contains no unbalanced substring."}]
If there exists no unbalanced substring of s, print `-1 -1`. If there exists an unbalanced substring of s, let one such substring be s_a s_{a+1} ... s_{b} (1 ≦ a < b ≦ |s|), and print `a b`. If there exists more than one such substring, any of them will be accepted. * * *
s097665236
Runtime Error
p04032
The input is given from Standard Input in the following format: s
s = input() checker = '' if len(s) <= 2: if s[0] == s[1]: print(1, 2) checker += '*' else: print(-1, -1) checker += '*' if checker == '' for a, b in zip(range(len(s)-1), range(1,len(s))): if s[a] == s[b]: print(a+1, b+1) checker += '*' break if checker == '': for a, c in zip(list(range(len(s)-2)), list(range(2, len(s)))): if s[a] == s[c]: print(a+1, c+1) chekcher += '*' break if checker == '': print(-1, -1)
Statement Given a string t, we will call it _unbalanced_ if and only if the length of t is at least 2, and more than half of the letters in t are the same. For example, both `voodoo` and `melee` are unbalanced, while neither `noon` nor `a` is. You are given a string s consisting of lowercase letters. Determine if there exists a (contiguous) substring of s that is unbalanced. If the answer is positive, show a position where such a substring occurs in s.
[{"input": "needed", "output": "2 5\n \n\nThe string s_2 s_3 s_4 s_5 = `eede` is unbalanced. There are also other\nunbalanced substrings. For example, the output `2 6` will also be accepted.\n\n* * *"}, {"input": "atcoder", "output": "-1 -1\n \n\nThe string `atcoder` contains no unbalanced substring."}]
If there exists no unbalanced substring of s, print `-1 -1`. If there exists an unbalanced substring of s, let one such substring be s_a s_{a+1} ... s_{b} (1 ≦ a < b ≦ |s|), and print `a b`. If there exists more than one such substring, any of them will be accepted. * * *
s682324524
Runtime Error
p04032
The input is given from Standard Input in the following format: s
s = str(input()) if len(s) == 2: if s[0] ==s[1]: start_ind =1 end_ind = 2 else: start_ind = -1 end_ind = -1 elif len(s)>2: start_ind = -1 end_ind = -1 for i in range(len(s)-2): par_str = s[i:i+3] if (par_str.count(par_str[0])>=2) | (par_str.count(par_str[1])>=2): start_ind = i + 1 end_ind = i + 3 break ans = str(start_ind) + ' ' + str(end_ind) print(ans)
Statement Given a string t, we will call it _unbalanced_ if and only if the length of t is at least 2, and more than half of the letters in t are the same. For example, both `voodoo` and `melee` are unbalanced, while neither `noon` nor `a` is. You are given a string s consisting of lowercase letters. Determine if there exists a (contiguous) substring of s that is unbalanced. If the answer is positive, show a position where such a substring occurs in s.
[{"input": "needed", "output": "2 5\n \n\nThe string s_2 s_3 s_4 s_5 = `eede` is unbalanced. There are also other\nunbalanced substrings. For example, the output `2 6` will also be accepted.\n\n* * *"}, {"input": "atcoder", "output": "-1 -1\n \n\nThe string `atcoder` contains no unbalanced substring."}]
If there exists no unbalanced substring of s, print `-1 -1`. If there exists an unbalanced substring of s, let one such substring be s_a s_{a+1} ... s_{b} (1 ≦ a < b ≦ |s|), and print `a b`. If there exists more than one such substring, any of them will be accepted. * * *
s831641911
Runtime Error
p04032
The input is given from Standard Input in the following format: s
a=input() t=-1 flag="False" for i in range(n-1): if a[i]==a[i+1]: flag="True1" t=i break if i!=n-2: if a[i]==a[i+2]: flag="True2" t=i break if flag=="False": print("{} {}".format(-1,-1)) elif flag=="True1": print("{} {}".format(t+1,t+2)) else flag=="True2": print("{} {}".format(t+1,t+2))
Statement Given a string t, we will call it _unbalanced_ if and only if the length of t is at least 2, and more than half of the letters in t are the same. For example, both `voodoo` and `melee` are unbalanced, while neither `noon` nor `a` is. You are given a string s consisting of lowercase letters. Determine if there exists a (contiguous) substring of s that is unbalanced. If the answer is positive, show a position where such a substring occurs in s.
[{"input": "needed", "output": "2 5\n \n\nThe string s_2 s_3 s_4 s_5 = `eede` is unbalanced. There are also other\nunbalanced substrings. For example, the output `2 6` will also be accepted.\n\n* * *"}, {"input": "atcoder", "output": "-1 -1\n \n\nThe string `atcoder` contains no unbalanced substring."}]
If there exists no unbalanced substring of s, print `-1 -1`. If there exists an unbalanced substring of s, let one such substring be s_a s_{a+1} ... s_{b} (1 ≦ a < b ≦ |s|), and print `a b`. If there exists more than one such substring, any of them will be accepted. * * *
s556246976
Runtime Error
p04032
The input is given from Standard Input in the following format: s
a=input() t=-1 flag="False" for i in range(n-1): if a[i]==a[i+1]: flag="True1" t=i break if i!=n-2 and a[i]==a[i+2]: flag="True2" t=i break if flag=="False": print("{} {}".format(-1,-1)) elif flag=="True1": print("{} {}".format(t+1,t+2)) else flag=="True2": print("{} {}".format(t+1,t+2))
Statement Given a string t, we will call it _unbalanced_ if and only if the length of t is at least 2, and more than half of the letters in t are the same. For example, both `voodoo` and `melee` are unbalanced, while neither `noon` nor `a` is. You are given a string s consisting of lowercase letters. Determine if there exists a (contiguous) substring of s that is unbalanced. If the answer is positive, show a position where such a substring occurs in s.
[{"input": "needed", "output": "2 5\n \n\nThe string s_2 s_3 s_4 s_5 = `eede` is unbalanced. There are also other\nunbalanced substrings. For example, the output `2 6` will also be accepted.\n\n* * *"}, {"input": "atcoder", "output": "-1 -1\n \n\nThe string `atcoder` contains no unbalanced substring."}]
If there exists no unbalanced substring of s, print `-1 -1`. If there exists an unbalanced substring of s, let one such substring be s_a s_{a+1} ... s_{b} (1 ≦ a < b ≦ |s|), and print `a b`. If there exists more than one such substring, any of them will be accepted. * * *
s186124511
Runtime Error
p04032
The input is given from Standard Input in the following format: s
import exit from sys s=input() l=len(s) for i in range(l-2): if s[i]==s[i+2]: print(str(i+1)+" "+str(i+3)) exit() if s[i]==s[i+1]: print(str(i+1)+" "+str(i+2)) exit() if s[l-2]==s[l-1]: print(str(l-1)+" "+str(l)) else: print("-1 -1")
Statement Given a string t, we will call it _unbalanced_ if and only if the length of t is at least 2, and more than half of the letters in t are the same. For example, both `voodoo` and `melee` are unbalanced, while neither `noon` nor `a` is. You are given a string s consisting of lowercase letters. Determine if there exists a (contiguous) substring of s that is unbalanced. If the answer is positive, show a position where such a substring occurs in s.
[{"input": "needed", "output": "2 5\n \n\nThe string s_2 s_3 s_4 s_5 = `eede` is unbalanced. There are also other\nunbalanced substrings. For example, the output `2 6` will also be accepted.\n\n* * *"}, {"input": "atcoder", "output": "-1 -1\n \n\nThe string `atcoder` contains no unbalanced substring."}]
If there exists no unbalanced substring of s, print `-1 -1`. If there exists an unbalanced substring of s, let one such substring be s_a s_{a+1} ... s_{b} (1 ≦ a < b ≦ |s|), and print `a b`. If there exists more than one such substring, any of them will be accepted. * * *
s006892442
Accepted
p04032
The input is given from Standard Input in the following format: s
#!/usr/bin/env python3 import sys # import math # from string import ascii_lowercase, ascii_upper_case, ascii_letters, digits, hexdigits # import re # re.compile(pattern) => ptn obj; p.search(s), p.match(s), p.finditer(s) => match obj; p.sub(after, s) # from operator import itemgetter # itemgetter(1), itemgetter('key') # from collections import deque # deque class. deque(L): dq.append(x), dq.appendleft(x), dq.pop(), dq.popleft(), dq.rotate() # from collections import defaultdict # subclass of dict. defaultdict(facroty) # from collections import Counter # subclass of dict. Counter(iter): c.elements(), c.most_common(n), c.subtract(iter) # from heapq import heapify, heappush, heappop # built-in list. heapify(L) changes list in-place to min-heap in O(n), heappush(heapL, x) and heappop(heapL) in O(lgn). # from heapq import nlargest, nsmallest # nlargest(n, iter[, key]) returns k-largest-list in O(n+klgn). # from itertools import count, cycle, repeat # count(start[,step]), cycle(iter), repeat(elm[,n]) # from itertools import groupby # [(k, list(g)) for k, g in groupby('000112')] returns [('0',['0','0','0']), ('1',['1','1']), ('2',['2'])] # from itertools import starmap # starmap(pow, [[2,5], [3,2]]) returns [32, 9] # from itertools import product, permutations # product(iter, repeat=n), permutations(iter[,r]) # from itertools import combinations, combinations_with_replacement # from itertools import accumulate # accumulate(iter[, f]) # from functools import reduce # reduce(f, iter[, init]) # from functools import lru_cache # @lrucache ...arguments of functions should be able to be keys of dict (e.g. list is not allowed) # from bisect import bisect_left, bisect_right # bisect_left(a, x, lo=0, hi=len(a)) returns i such that all(val<x for val in a[lo:i]) and all(val>-=x for val in a[i:hi]). # from copy import deepcopy # to copy multi-dimentional matrix without reference # from fractions import gcd # for Python 3.4 (previous contest @AtCoder) def main(): mod = 1000000007 # 10^9+7 inf = float("inf") # sys.float_info.max = 1.79...e+308 # inf = 2 ** 64 - 1 # (for fast JIT compile in PyPy) 1.84...e+19 sys.setrecursionlimit(10**6) # 1000 -> 1000000 def input(): return sys.stdin.readline().rstrip() def ii(): return int(input()) def mi(): return map(int, input().split()) def mi_0(): return map(lambda x: int(x) - 1, input().split()) def lmi(): return list(map(int, input().split())) def lmi_0(): return list(map(lambda x: int(x) - 1, input().split())) def li(): return list(input()) def calc_consective(s): n = len(s) for i in range(n - 1): if s[i] == s[i + 1]: return [i + 1, i + 2] # 1-index return None def calc_skip(s): n = len(s) for i in range(n - 2): if s[i] == s[i + 2]: return [i + 1, i + 3] # 1-index return None def calc_ans(s): ans = calc_consective(s) if ans: return ans ans = calc_skip(s) if ans: return ans return (-1, -1) s = input() res = calc_ans(s) print("{} {}".format(res[0], res[1])) if __name__ == "__main__": main()
Statement Given a string t, we will call it _unbalanced_ if and only if the length of t is at least 2, and more than half of the letters in t are the same. For example, both `voodoo` and `melee` are unbalanced, while neither `noon` nor `a` is. You are given a string s consisting of lowercase letters. Determine if there exists a (contiguous) substring of s that is unbalanced. If the answer is positive, show a position where such a substring occurs in s.
[{"input": "needed", "output": "2 5\n \n\nThe string s_2 s_3 s_4 s_5 = `eede` is unbalanced. There are also other\nunbalanced substrings. For example, the output `2 6` will also be accepted.\n\n* * *"}, {"input": "atcoder", "output": "-1 -1\n \n\nThe string `atcoder` contains no unbalanced substring."}]
For each query of the latter type, print the answer. * * *
s357028782
Accepted
p02559
Input is given from Standard Input in the following format: N Q a_0 a_1 ... a_{N - 1} \textrm{Query}_0 \textrm{Query}_1 : \textrm{Query}_{Q - 1}
import sys input = sys.stdin.readline def solve(): def makeBIT(numEle): numPow2 = 2 ** (numEle - 1).bit_length() data = [0] * (numPow2 + 1) return data, numPow2 def setInit(As): for iB, A in enumerate(As, 1): data[iB] = A for iB in range(1, numPow2): i = iB + (iB & -iB) data[i] += data[iB] def addValue(iA, A): iB = iA + 1 while iB <= numPow2: data[iB] += A iB += iB & -iB def getSum(iA): iB = iA + 1 ans = 0 while iB > 0: ans += data[iB] iB -= iB & -iB return ans def getRangeSum(iFr, iTo): return getSum(iTo) - getSum(iFr - 1) N, Q = map(int, input().split()) As = list(map(int, input().split())) data, numPow2 = makeBIT(N) setInit(As) anss = [] for _ in range(Q): t, i, j = map(int, input().split()) if t == 0: addValue(i, j) else: anss.append(getRangeSum(i, j - 1)) print("\n".join(map(str, anss))) solve()
Statement You are given an array a_0, a_1, ..., a_{N-1} of length N. Process Q queries of the following types. * `0 p x`: a_p \gets a_p + x * `1 l r`: Print \sum_{i = l}^{r - 1}{a_i}.
[{"input": "5 5\n 1 2 3 4 5\n 1 0 5\n 1 2 4\n 0 3 10\n 1 0 5\n 1 0 3", "output": "15\n 7\n 25\n 6"}]
For each query of the latter type, print the answer. * * *
s866370340
Accepted
p02559
Input is given from Standard Input in the following format: N Q a_0 a_1 ... a_{N - 1} \textrm{Query}_0 \textrm{Query}_1 : \textrm{Query}_{Q - 1}
def segfunc(x, y): return x + y class SegmentTree: def __init__(self, A, n, ide_ele): self.ide_ele = ide_ele self.num = 2 ** (n - 1).bit_length() self.seg = [self.ide_ele] * 2 * self.num # set_val for i in range(n): self.seg[i + self.num - 1] = A[i] # built for i in range(self.num - 2, -1, -1): self.seg[i] = segfunc(self.seg[2 * i + 1], self.seg[2 * i + 2]) def update(self, k, x): k += self.num - 1 self.seg[k] = x while k: k = (k - 1) // 2 self.seg[k] = segfunc(self.seg[k * 2 + 1], self.seg[k * 2 + 2]) def query(self, p, q): if q <= p: return self.ide_ele p += self.num - 1 q += self.num - 2 res = self.ide_ele while q - p > 1: if p & 1 == 0: res = segfunc(res, self.seg[p]) if q & 1 == 1: res = segfunc(res, self.seg[q]) q -= 1 p = p // 2 q = (q - 1) // 2 if p == q: res = segfunc(res, self.seg[p]) else: res = segfunc(segfunc(res, self.seg[p]), self.seg[q]) return res N, Q = list(map(int, input().split())) A = list(map(int, input().split())) ST = SegmentTree(A, N, 0) for i in range(Q): n, p, x = list(map(int, input().split())) if n == 1: print(ST.query(p, x)) else: A[p] += x ST.update(p, A[p])
Statement You are given an array a_0, a_1, ..., a_{N-1} of length N. Process Q queries of the following types. * `0 p x`: a_p \gets a_p + x * `1 l r`: Print \sum_{i = l}^{r - 1}{a_i}.
[{"input": "5 5\n 1 2 3 4 5\n 1 0 5\n 1 2 4\n 0 3 10\n 1 0 5\n 1 0 3", "output": "15\n 7\n 25\n 6"}]
For each query of the latter type, print the answer. * * *
s611008593
Accepted
p02559
Input is given from Standard Input in the following format: N Q a_0 a_1 ... a_{N - 1} \textrm{Query}_0 \textrm{Query}_1 : \textrm{Query}_{Q - 1}
#####segfunc###### def segfunc(x, y): return x + y def init(init_val): # set_val for i in range(n): seg[i + num - 1] = init_val[i] # built for i in range(num - 2, -1, -1): seg[i] = segfunc(seg[2 * i + 1], seg[2 * i + 2]) def update(k, x): k += num - 1 seg[k] = x while k + 1: k = (k - 1) // 2 seg[k] = segfunc(seg[k * 2 + 1], seg[k * 2 + 2]) def query(p, q): if q <= p: return ide_ele p += num - 1 q += num - 2 res = ide_ele while q - p > 1: if p & 1 == 0: res = segfunc(res, seg[p]) if q & 1 == 1: res = segfunc(res, seg[q]) q -= 1 p = p // 2 q = (q - 1) // 2 if p == q: res = segfunc(res, seg[p]) else: res = segfunc(segfunc(res, seg[p]), seg[q]) return res ide_ele = 0 n, q = map(int, input().split()) num = 2 ** (n - 1).bit_length() seg = [ide_ele] * 2 * num a = list(map(int, input().split())) init(a) ans = 0 for i in range(q): x, l, r = map(int, input().split()) if x == 0: update(l, seg[l + num - 1] + r) else: print(query(l, r))
Statement You are given an array a_0, a_1, ..., a_{N-1} of length N. Process Q queries of the following types. * `0 p x`: a_p \gets a_p + x * `1 l r`: Print \sum_{i = l}^{r - 1}{a_i}.
[{"input": "5 5\n 1 2 3 4 5\n 1 0 5\n 1 2 4\n 0 3 10\n 1 0 5\n 1 0 3", "output": "15\n 7\n 25\n 6"}]
For each query of the latter type, print the answer. * * *
s660332204
Accepted
p02559
Input is given from Standard Input in the following format: N Q a_0 a_1 ... a_{N - 1} \textrm{Query}_0 \textrm{Query}_1 : \textrm{Query}_{Q - 1}
#!/usr/bin python3 # -*- coding: utf-8 -*- # Segment Tree # 一点更新・範囲集約 # 1-indexed # update(i,x) :ai を x に変更する # add(i,x) :ai に x を加算する # query(l,r) :半開区間 [l,r) に対してモノイド al・…・ar−1 を返す # モノイドとは、集合と二項演算の組で、結合法則と単位元の存在するもの # ex. +, max, min # [ 1] a0 ・ a1 ・ a2 ・ a3 ・ a4 ・ a5 ・ a6 ・ a7 ->[0] # [ 2] a0 ・ a1 ・ a2 ・ a3 [ 3] a4 ・ a5 ・ a6・ a7 # [ 4] a0 ・ a1 [ 5] a2 ・ a3 [ 6] a4 ・ a5 [ 7] a6 ・ a7 # [ 8] a0 [ 9] a1 [10] a2 [11] a3 [12] a4 [13] a5 [14] a6 [15] a7 # [0001] # [0010] [0011] # [0100] [0101] [0110] [0111] # [1000][1001][1010][1011][1100][1101][1110][1111] # size = 8 元の配列数の2べき乗値 # 親のインデックス i//2 or i>>=1 bitで一個右シフト # 左側の子のインデックス 2*i # 右側の子のインデックス 2*i+1 # aiの値が代入されているインデックス i+size class SegmentTree: # 初期化処理 # f : SegmentTreeにのせるモノイド # idele : fに対する単位元 def __init__(self, size, f=lambda x, y: min(x, y), idele=float("inf")): self.size = 2 ** (size - 1).bit_length() # 簡単のため要素数nを2冪にする self.idele = idele # 単位元 self.f = f # モノイド self.dat = [self.idele] * (self.size * 2) # 要素を単位元で初期化 ## one point def update(self, i, x): i += self.size # 1番下の層におけるインデックス self.dat[i] = x while i > 0: # 層をのぼりながら値を更新 i >>= 1 # 1つ上の層のインデックス(完全二分木における親) # 下の層2つの演算結果の代入(完全二分木における子同士の演算) self.dat[i] = self.f(self.dat[i * 2], self.dat[i * 2 + 1]) ## one point def add(self, i, x): i += self.size # 1番下の層におけるインデックス self.dat[i] += x while i > 0: # 層をのぼりながら値を更新 indexが0になれば終了 i >>= 1 # 1つ上の層のインデックス(完全二分木における親) # 下の層2つの演算結果の代入(完全二分木における子同士の演算) self.dat[i] = self.f(self.dat[i * 2], self.dat[i * 2 + 1]) ## range def query(self, l, r): l += self.size # 1番下の層におけるインデックス r += self.size # 1番下の層におけるインデックス lres, rres = self.idele, self.idele # 左側の答えと右側の答えを初期化 while l < r: # lとrが重なるまで上記の判定を用いて加算を実行 # 左が子同士の右側(lが奇数)(lの末桁=1)ならば、dat[l]を加算 if l & 1: lres = self.f(lres, self.dat[l]) l += 1 # 右が子同士の右側(rが奇数)(rの末桁=1)ならば、dat[r-1]を加算 if r & 1: r -= 1 rres = self.f( self.dat[r], rres ) # モノイドでは可換律は保証されていないので演算の方向に注意 l >>= 1 r >>= 1 res = self.f(lres, rres) return res def init(self, a): for i, x in enumerate(a): # 1番下の層におけるインデックス self.dat[i + self.size] = x for i in range(self.size - 1, -1, -1): self.dat[i] = self.f(self.dat[i * 2], self.dat[i * 2 + 1]) n, q = map(int, input().split()) a = list(map(int, input().split())) sgt = SegmentTree(n, lambda x, y: x + y, 0) sgt.init(a) for _ in range(q): t, u, v = map(int, input().split()) if t == 0: sgt.add(u, v) else: print(sgt.query(u, v))
Statement You are given an array a_0, a_1, ..., a_{N-1} of length N. Process Q queries of the following types. * `0 p x`: a_p \gets a_p + x * `1 l r`: Print \sum_{i = l}^{r - 1}{a_i}.
[{"input": "5 5\n 1 2 3 4 5\n 1 0 5\n 1 2 4\n 0 3 10\n 1 0 5\n 1 0 3", "output": "15\n 7\n 25\n 6"}]
For each query of the latter type, print the answer. * * *
s815775526
Accepted
p02559
Input is given from Standard Input in the following format: N Q a_0 a_1 ... a_{N - 1} \textrm{Query}_0 \textrm{Query}_1 : \textrm{Query}_{Q - 1}
# Date [ 2020-09-08 00:04:04 ] # Problem [ b.py ] # Author Koki_tkg import sys # import math # import bisect # import numpy as np # from decimal import Decimal # from numba import njit, i8, u1, b1 #JIT compiler # from itertools import combinations, product # from collections import Counter, deque, defaultdict # sys.setrecursionlimit(10 ** 6) MOD = 10**9 + 7 INF = 10**9 PI = 3.14159265358979323846 def read_str(): return sys.stdin.readline().strip() def read_int(): return int(sys.stdin.readline().strip()) def read_ints(): return map(int, sys.stdin.readline().strip().split()) def read_ints2(x): return map(lambda num: int(num) - x, sys.stdin.readline().strip().split()) def read_str_list(): return list(sys.stdin.readline().strip().split()) def read_int_list(): return list(map(int, sys.stdin.readline().strip().split())) def GCD(a: int, b: int) -> int: return b if a % b == 0 else GCD(b, a % b) def LCM(a: int, b: int) -> int: return (a * b) // GCD(a, b) class BinaryIndexedTree: def __init__(self, n): """1-index""" self.size = n + 1 self.data = [0] * self.size self.element = [0] * self.size self.depth = 1 << n.bit_length() - 1 def build(self, array): for i, x in enumerate(array): self.add(i, x) def add(self, i, v): self.element[i] += v i += 1 # 1-index while i < self.size: self.data[i] += v i += i & -i def sum(self, i): ret = 0 i += 1 # 1-index while i > 0: ret += self.data[i] i -= i & -i return ret def query(self, l, r=None): """get sum [l, r)""" if r == None: return self.element[l] return self.sum(r) - self.sum(l - 1) def lower_bound(self, v): if v <= 0: return 0 k = self.depth i = 0 while k > 0: if i + k < self.size and self.data[i + k] < v: v -= self.data[i + k] i += k k >>= 1 return i + 1 def upper_bound(self, v): if v <= 0: return 0 k = self.depth i = 0 while k > 0: if i + k < self.size and self.data[i + k] <= v: v -= self.data[i + k] i += k k >>= 1 return i + 1 def Main(): n, q = read_ints() bit = BinaryIndexedTree(n) a = read_int_list() bit.build(a) for _ in range(q): t, l, r = read_ints() if t == 0: bit.add(l, r) else: print(bit.query(l, ~-r)) if __name__ == "__main__": Main()
Statement You are given an array a_0, a_1, ..., a_{N-1} of length N. Process Q queries of the following types. * `0 p x`: a_p \gets a_p + x * `1 l r`: Print \sum_{i = l}^{r - 1}{a_i}.
[{"input": "5 5\n 1 2 3 4 5\n 1 0 5\n 1 2 4\n 0 3 10\n 1 0 5\n 1 0 3", "output": "15\n 7\n 25\n 6"}]
If the objective is achievable, print the minimum necessary number of leaves to remove. Otherwise, print `-1` instead. * * *
s954345213
Runtime Error
p03718
Input is given from Standard Input in the following format: H W a_{11} ... a_{1W} : a_{H1} ... a_{HW}
code = """ # distutils: language=c++ # distutils: include_dirs=[/home/USERNAME/.local/lib/python3.8/site-packages/numpy/core/include, /opt/atcoder-stl] # cython: boundscheck=False # cython: wraparound=False from libcpp cimport bool from libcpp.vector cimport vector cdef extern from "<atcoder/maxflow>" namespace "atcoder": cdef cppclass mf_graph[Cap]: mf_graph(int n) int add_edge(int fr, int to, Cap cap) Cap flow(int s, int t) Cap flow(int s, int t, Cap flow_limit) vector[bool] min_cut(int s) cppclass edge: int frm 'from' int to Cap cap Cap flow edge(edge &e) edge get_edge(int i) vector[edge] edges() void change_edge(int i, Cap new_cap, Cap new_flow) cdef class MfGraph: cdef mf_graph[int] *_thisptr def __cinit__(self, int n): self._thisptr = new mf_graph[int](n) cpdef int add_edge(self, int fr, int to, int cap): return self._thisptr.add_edge(fr, to, cap) cpdef int flow(self, int s, int t): return self._thisptr.flow(s, t) cpdef int flow_with_limit(self, int s, int t, int flow_limit): return self._thisptr.flow(s, t, flow_limit) cpdef vector[bool] min_cut(self, int s): return self._thisptr.min_cut(s) cpdef vector[int] get_edge(self, int i): cdef mf_graph[int].edge *e = new mf_graph[int].edge(self._thisptr.get_edge(i)) cdef vector[int] *ret_e = new vector[int]() ret_e.push_back(e.frm) ret_e.push_back(e.to) ret_e.push_back(e.cap) ret_e.push_back(e.flow) return ret_e[0] cpdef vector[vector[int]] edges(self): cdef vector[mf_graph[int].edge] es = self._thisptr.edges() cdef vector[vector[int]] *ret_es = new vector[vector[int]](es.size()) for i in range(es.size()): ret_es.at(i).push_back(es.at(i).frm) ret_es.at(i).push_back(es.at(i).to) ret_es.at(i).push_back(es.at(i).cap) ret_es.at(i).push_back(es.at(i).flow) return ret_es[0] cpdef void change_edge(self, int i, int new_cap, int new_flow): self._thisptr.change_edge(i, new_cap, new_flow) """ import os, sys, getpass if sys.argv[-1] == "ONLINE_JUDGE": code = code.replace("USERNAME", getpass.getuser()) open("atcoder.pyx", "w").write(code) os.system("cythonize -i -3 -b atcoder.pyx") sys.exit(0) from atcoder import MfGraph H, W = list(map(int, input().split())) S = [input() for i in range(H)] mg = MfGraph(H + W + 2) s = H + W t = H + W + 1 BIG = 10**9 for i in range(H): for j in range(W): if S[i][j] != ".": mg.add_edge(i, H + j, 1) mg.add_edge(H + j, i, 1) if S[i][j] == "S": mg.add_edge(s, H + j, BIG) mg.add_edge(s, i, BIG) if S[i][j] == "T": mg.add_edge(H + j, t, BIG) mg.add_edge(i, t, BIG) ans = mg.flow(s, t) if ans >= BIG: print(-1) else: print(ans)
Statement There is a pond with a rectangular shape. The pond is divided into a grid with H rows and W columns of squares. We will denote the square at the i-th row from the top and j-th column from the left by (i,\ j). Some of the squares in the pond contains a lotus leaf floating on the water. On one of those leaves, S, there is a frog trying to get to another leaf T. The state of square (i,\ j) is given to you by a character a_{ij}, as follows: * `.` : A square without a leaf. * `o` : A square with a leaf floating on the water. * `S` : A square with the leaf S. * `T` : A square with the leaf T. The frog will repeatedly perform the following action to get to the leaf T: "jump to a leaf that is in the same row or the same column as the leaf where the frog is currently located." Snuke is trying to remove some of the leaves, other than S and T, so that the frog cannot get to the leaf T. Determine whether this objective is achievable. If it is achievable, find the minimum necessary number of leaves to remove.
[{"input": "3 3\n S.o\n .o.\n o.T", "output": "2\n \n\nRemove the upper-right and lower-left leaves.\n\n* * *"}, {"input": "3 4\n S...\n .oo.\n ...T", "output": "0\n \n\n* * *"}, {"input": "4 3\n .S.\n .o.\n .o.\n .T.", "output": "-1\n \n\n* * *"}, {"input": "10 10\n .o...o..o.\n ....o.....\n ....oo.oo.\n ..oooo..o.\n ....oo....\n ..o..o....\n o..o....So\n o....T....\n ....o.....\n ........oo", "output": "5"}]
If the objective is achievable, print the minimum necessary number of leaves to remove. Otherwise, print `-1` instead. * * *
s267596957
Wrong Answer
p03718
Input is given from Standard Input in the following format: H W a_{11} ... a_{1W} : a_{H1} ... a_{HW}
print(-1)
Statement There is a pond with a rectangular shape. The pond is divided into a grid with H rows and W columns of squares. We will denote the square at the i-th row from the top and j-th column from the left by (i,\ j). Some of the squares in the pond contains a lotus leaf floating on the water. On one of those leaves, S, there is a frog trying to get to another leaf T. The state of square (i,\ j) is given to you by a character a_{ij}, as follows: * `.` : A square without a leaf. * `o` : A square with a leaf floating on the water. * `S` : A square with the leaf S. * `T` : A square with the leaf T. The frog will repeatedly perform the following action to get to the leaf T: "jump to a leaf that is in the same row or the same column as the leaf where the frog is currently located." Snuke is trying to remove some of the leaves, other than S and T, so that the frog cannot get to the leaf T. Determine whether this objective is achievable. If it is achievable, find the minimum necessary number of leaves to remove.
[{"input": "3 3\n S.o\n .o.\n o.T", "output": "2\n \n\nRemove the upper-right and lower-left leaves.\n\n* * *"}, {"input": "3 4\n S...\n .oo.\n ...T", "output": "0\n \n\n* * *"}, {"input": "4 3\n .S.\n .o.\n .o.\n .T.", "output": "-1\n \n\n* * *"}, {"input": "10 10\n .o...o..o.\n ....o.....\n ....oo.oo.\n ..oooo..o.\n ....oo....\n ..o..o....\n o..o....So\n o....T....\n ....o.....\n ........oo", "output": "5"}]
If the objective is achievable, print the minimum necessary number of leaves to remove. Otherwise, print `-1` instead. * * *
s719826448
Accepted
p03718
Input is given from Standard Input in the following format: H W a_{11} ... a_{1W} : a_{H1} ... a_{HW}
#!usr/bin/env python3 from collections import defaultdict from collections import deque from heapq import heappush, heappop import sys import math import bisect import random def LI(): return list(map(int, sys.stdin.readline().split())) def I(): return int(sys.stdin.readline()) def LS(): return list(map(list, sys.stdin.readline().split())) def S(): return list(sys.stdin.readline())[:-1] def IR(n): l = [None for i in range(n)] for i in range(n): l[i] = I() return l def LIR(n): l = [None for i in range(n)] for i in range(n): l[i] = LI() return l def SR(n): l = [None for i in range(n)] for i in range(n): l[i] = S() return l def LSR(n): l = [None for i in range(n)] for i in range(n): l[i] = SR() return l mod = 1000000007 # A def A(): return # B def B(): return # C def C(): return # D def D(): return # E def E(): return # F def F(): def bfs(s, g, n): bfs_map = [-1 for i in range(n)] bfs_map[s] = 0 q = deque() q.append(s) fin = False while q: x = q.popleft() for y in range(n): if c[x][y] > 0 and bfs_map[y] < 0: bfs_map[y] = bfs_map[x] + 1 if y == g: fin = True break q.append(y) if fin: break if bfs_map[g] == -1: return [None, 0] path = [None for i in range(bfs_map[g] + 1)] m = float("inf") path[bfs_map[g]] = g y = g for i in range(bfs_map[g])[::-1]: for x in range(n + 1): if c[x][y] > 0 and bfs_map[x] == bfs_map[y] - 1: path[i] = x if c[x][y] < m: m = c[x][y] y = x break return [path, m] def ford_fulkerson(s, g, c, n): while 1: p, m = bfs(s, g, n) if not m: break for i in range(len(p) - 1): c[p[i]][p[i + 1]] -= m c[p[i + 1]][p[i]] += m return sum(c[g]) h, w = LI() a = SR(h) c = [[0 for i in range(h + w + 2)] for j in range(h + w + 2)] for y in range(h): for x in range(w): if a[y][x] == "S": c[0][y + 1] = float("inf") c[0][h + x + 1] = float("inf") if a[y][x] == "T": c[y + 1][h + w + 1] = float("inf") c[h + x + 1][h + w + 1] = float("inf") if a[y][x] == "o": c[y + 1][h + x + 1] = 1 c[h + x + 1][y + 1] = 1 ans = ford_fulkerson(0, h + w + 1, c, h + w + 2) if ans == float("inf"): print(-1) else: print(ans) # G def G(): return # H def H(): return # Solve if __name__ == "__main__": F()
Statement There is a pond with a rectangular shape. The pond is divided into a grid with H rows and W columns of squares. We will denote the square at the i-th row from the top and j-th column from the left by (i,\ j). Some of the squares in the pond contains a lotus leaf floating on the water. On one of those leaves, S, there is a frog trying to get to another leaf T. The state of square (i,\ j) is given to you by a character a_{ij}, as follows: * `.` : A square without a leaf. * `o` : A square with a leaf floating on the water. * `S` : A square with the leaf S. * `T` : A square with the leaf T. The frog will repeatedly perform the following action to get to the leaf T: "jump to a leaf that is in the same row or the same column as the leaf where the frog is currently located." Snuke is trying to remove some of the leaves, other than S and T, so that the frog cannot get to the leaf T. Determine whether this objective is achievable. If it is achievable, find the minimum necessary number of leaves to remove.
[{"input": "3 3\n S.o\n .o.\n o.T", "output": "2\n \n\nRemove the upper-right and lower-left leaves.\n\n* * *"}, {"input": "3 4\n S...\n .oo.\n ...T", "output": "0\n \n\n* * *"}, {"input": "4 3\n .S.\n .o.\n .o.\n .T.", "output": "-1\n \n\n* * *"}, {"input": "10 10\n .o...o..o.\n ....o.....\n ....oo.oo.\n ..oooo..o.\n ....oo....\n ..o..o....\n o..o....So\n o....T....\n ....o.....\n ........oo", "output": "5"}]
If the objective is achievable, print the minimum necessary number of leaves to remove. Otherwise, print `-1` instead. * * *
s551760097
Accepted
p03718
Input is given from Standard Input in the following format: H W a_{11} ... a_{1W} : a_{H1} ... a_{HW}
from networkx import * H, *S = open(0) H, W = map(int, H.split()) g = Graph() for i in range(m := H * W): g.add_weighted_edges_from( [[m * 2, h := i // W, I := m * 3], [m * 2, w := i % W + m, I]] * ((c := S[h][w - m]) == "S") + [[h, I, I], [w, I, I]] * (c == "T") + [[h, w, 1], [w, h, 1]] * (c > "T") ) print([-1, f := minimum_cut(g, m * 2, I, "weight")[0]][f < I])
Statement There is a pond with a rectangular shape. The pond is divided into a grid with H rows and W columns of squares. We will denote the square at the i-th row from the top and j-th column from the left by (i,\ j). Some of the squares in the pond contains a lotus leaf floating on the water. On one of those leaves, S, there is a frog trying to get to another leaf T. The state of square (i,\ j) is given to you by a character a_{ij}, as follows: * `.` : A square without a leaf. * `o` : A square with a leaf floating on the water. * `S` : A square with the leaf S. * `T` : A square with the leaf T. The frog will repeatedly perform the following action to get to the leaf T: "jump to a leaf that is in the same row or the same column as the leaf where the frog is currently located." Snuke is trying to remove some of the leaves, other than S and T, so that the frog cannot get to the leaf T. Determine whether this objective is achievable. If it is achievable, find the minimum necessary number of leaves to remove.
[{"input": "3 3\n S.o\n .o.\n o.T", "output": "2\n \n\nRemove the upper-right and lower-left leaves.\n\n* * *"}, {"input": "3 4\n S...\n .oo.\n ...T", "output": "0\n \n\n* * *"}, {"input": "4 3\n .S.\n .o.\n .o.\n .T.", "output": "-1\n \n\n* * *"}, {"input": "10 10\n .o...o..o.\n ....o.....\n ....oo.oo.\n ..oooo..o.\n ....oo....\n ..o..o....\n o..o....So\n o....T....\n ....o.....\n ........oo", "output": "5"}]
Print two integers with a space in between. First, print the minimum possible colorfulness of a tree T that can be constructed. Second, print the minimum number of leaves in a tree that achieves it. It can be shown that, under the constraints of this problem, the values that should be printed fit into 64-bit signed integers. * * *
s696315189
Runtime Error
p03348
Input is given from Standard Input in the following format: N a_1 b_1 : a_{N-1} b_{N-1}
N = int(input()) G = [[] for i in range(N)] E9 = [] for i in range(N - 1): a, b = map(int, input().split()) G[a - 1].append(b - 1) G[b - 1].append(a - 1) E9.append((a - 1, b - 1)) def encode(v, p): res = [] tmp = [] l = 0 P = [] def edfs(v, p): res = [0] cs = [] for w in G[v]: if w == p: continue cs.append(edfs(w, v)) cs.sort() for c in cs: res.extend(c) res.append(1) return res E = edfs(v, p) return E def calc(E): st = [] C = [0] P = [] L = len(E) l = 0 for i in range(L): if i and E[i - 1] < E[i]: l += 1 if E[i] == 0: st.append(i) P.append(None) else: j = st.pop() P.append(i) # P[i] = j P[j] = i C.append(l) return C, P INF = 10**9 def merge(e1, e2): l1 = len(e1) l2 = len(e2) dp = [[0] * (l1 + 1) for i in range(l2 + 1)] C1, P1 = calc(e1) C2, P2 = calc(e2) prev = {} memo = {} def dfs(x, y): if (x, y) in memo: return memo[x, y] if x == l1 and y == l2: return 0 res = INF p = None if x < l1 and y < l2 and e1[x] == e2[y]: r = dfs(x + 1, y + 1) + max(C1[x + 1] - C1[x], C2[y + 1] - C2[y]) if r < res: res = r p = (x + 1, y + 1) if x < l1 and e1[x] == 0: r = dfs(P1[x] + 1, y) + C1[P1[x] + 1] - C1[x] if r < res: res = r p = (P1[x] + 1, y) if y < l2 and e2[y] == 0: r = dfs(x, P2[y] + 1) + C2[P2[y] + 1] - C2[y] if r < res: res = r p = (x, P2[y] + 1) memo[x, y] = res prev[x, y] = p return res prev[0, 0] = (0, 0) r = dfs(0, 0) v = (0, 0) res = [] while v != (l1, l2): print(v) px, py = v x, y = v = prev[v] if px != x and py != y: res.append(e1[px]) elif px != x: res.extend(e1[px:x]) else: res.extend(e2[py:y]) print(res) return r, res from collections import deque def bfs(v, p=-1): que = deque([v]) dist = {v: 0, p: 0} prev = {} while que: u = que.popleft() d = dist[u] for w in G[u]: if w not in dist: dist[w] = d + 1 prev[w] = u que.append(w) w = u res = [] while w != v: res.append(w) w = prev[w] res.append(v) return u, res def solve(u, v): if bfs(u, v) > (L + 1) // 2 < bfs(v, u): return 10**9 E1 = encode(u, v) E2 = encode(v, u) # print(u, v, E1, E2) return merge(E1, E2)[0] * 2 def vsolve(v): if bfs(u) > (L + 1) // 2: return 10**9 E0 = encode(G[v][0], v) for w in G[v][1:]: E1 = encode(w, w) _, E0 = merge(E0, E1) C, P = calc(E0) # print(v, G[v][0], E0, C[-1], len(G[v])) return C[-1] * len(G[v]) v, _ = bfs(0) w, D = bfs(v) L = len(D) col = (L + 1) // 2 ans = 10**18 for a, b in E9: ans = min(ans, solve(a, b)) for v in range(N): ans = min(ans, vsolve(v)) print(col, ans)
Statement Coloring of the vertices of a tree G is called a _good coloring_ when, for every pair of two vertices u and v painted in the same color, picking u as the root and picking v as the root would result in isomorphic rooted trees. Also, the _colorfulness_ of G is defined as the minimum possible number of different colors used in a good coloring of G. You are given a tree with N vertices. The vertices are numbered 1 through N, and the i-th edge connects Vertex a_i and Vertex b_i. We will construct a new tree T by repeating the following operation on this tree some number of times: * Add a new vertex to the tree by connecting it to one of the vertices in the current tree with an edge. Find the minimum possible colorfulness of T. Additionally, print the minimum number of leaves (vertices with degree 1) in a tree T that achieves the minimum colorfulness.
[{"input": "5\n 1 2\n 2 3\n 3 4\n 3 5", "output": "2 4\n \n\nIf we connect a new vertex 6 to vertex 2, painting the vertices (1,4,5,6) red\nand painting the vertices (2,3) blue is a good coloring. Since painting all\nthe vertices in a single color is not a good coloring, we can see that the\ncolorfulness of this tree is 2. This is actually the optimal solution. There\nare four leaves, so we should print 2 and 4.\n\n* * *"}, {"input": "8\n 1 2\n 2 3\n 4 3\n 5 4\n 6 7\n 6 8\n 3 6", "output": "3 4\n \n\n* * *"}, {"input": "10\n 1 2\n 2 3\n 3 4\n 4 5\n 5 6\n 6 7\n 3 8\n 5 9\n 3 10", "output": "4 6\n \n\n* * *"}, {"input": "13\n 5 6\n 6 4\n 2 8\n 4 7\n 8 9\n 3 2\n 10 4\n 11 10\n 2 4\n 13 10\n 1 8\n 12 1", "output": "4 12"}]
Print two integers with a space in between. First, print the minimum possible colorfulness of a tree T that can be constructed. Second, print the minimum number of leaves in a tree that achieves it. It can be shown that, under the constraints of this problem, the values that should be printed fit into 64-bit signed integers. * * *
s129565310
Runtime Error
p03348
Input is given from Standard Input in the following format: N a_1 b_1 : a_{N-1} b_{N-1}
import math n = int(input()) lis = [] for i in range(n): lis.append(int(input())) if lis[0] != 0: print("-1") exit() cou = 0 print(lis, cou) for k in range(n - 1): if lis[n - (k + 1)] > lis[n - (k + 2)]: cou += math.ceil(lis[n - (k + 1)] / (lis[n - (k + 2)] + 1)) lis[n - (k + 1)] = 0 else: cou += lis[n - (k + 1)] lis[n - (k + 2)] -= lis[n - (k + 1)] - 1 lis[n - (k + 1)] = 0 print(lis, cou) print(cou)
Statement Coloring of the vertices of a tree G is called a _good coloring_ when, for every pair of two vertices u and v painted in the same color, picking u as the root and picking v as the root would result in isomorphic rooted trees. Also, the _colorfulness_ of G is defined as the minimum possible number of different colors used in a good coloring of G. You are given a tree with N vertices. The vertices are numbered 1 through N, and the i-th edge connects Vertex a_i and Vertex b_i. We will construct a new tree T by repeating the following operation on this tree some number of times: * Add a new vertex to the tree by connecting it to one of the vertices in the current tree with an edge. Find the minimum possible colorfulness of T. Additionally, print the minimum number of leaves (vertices with degree 1) in a tree T that achieves the minimum colorfulness.
[{"input": "5\n 1 2\n 2 3\n 3 4\n 3 5", "output": "2 4\n \n\nIf we connect a new vertex 6 to vertex 2, painting the vertices (1,4,5,6) red\nand painting the vertices (2,3) blue is a good coloring. Since painting all\nthe vertices in a single color is not a good coloring, we can see that the\ncolorfulness of this tree is 2. This is actually the optimal solution. There\nare four leaves, so we should print 2 and 4.\n\n* * *"}, {"input": "8\n 1 2\n 2 3\n 4 3\n 5 4\n 6 7\n 6 8\n 3 6", "output": "3 4\n \n\n* * *"}, {"input": "10\n 1 2\n 2 3\n 3 4\n 4 5\n 5 6\n 6 7\n 3 8\n 5 9\n 3 10", "output": "4 6\n \n\n* * *"}, {"input": "13\n 5 6\n 6 4\n 2 8\n 4 7\n 8 9\n 3 2\n 10 4\n 11 10\n 2 4\n 13 10\n 1 8\n 12 1", "output": "4 12"}]
Print the maximum possible sum of the digits (in base 10) of a positive integer not greater than N. * * *
s106222363
Accepted
p03427
Input is given from Standard Input in the following format: N
n = int(input()) m = n k = 0 while m > 0: k += 1 m = m // 10 if (n + 1) % (10 ** (k - 1)) == 0: print(n // (10 ** (k - 1)) + 9 * (k - 1)) else: print(n // (10 ** (k - 1)) - 1 + 9 * (k - 1))
Statement Find the maximum possible sum of the digits (in base 10) of a positive integer not greater than N.
[{"input": "100", "output": "18\n \n\nFor example, the sum of the digits in 99 is 18, which turns out to be the\nmaximum value.\n\n* * *"}, {"input": "9995", "output": "35\n \n\nFor example, the sum of the digits in 9989 is 35, which turns out to be the\nmaximum value.\n\n* * *"}, {"input": "3141592653589793", "output": "137"}]
Print the maximum possible sum of the digits (in base 10) of a positive integer not greater than N. * * *
s594621635
Accepted
p03427
Input is given from Standard Input in the following format: N
n = list(map(int, list(input()))) k = len(n) c = n[0] f = 1 for i in range(1, k): if n[i] != 9: f = 0 if f: print(sum(n)) else: print(c + 9 * (k - 1) - 1)
Statement Find the maximum possible sum of the digits (in base 10) of a positive integer not greater than N.
[{"input": "100", "output": "18\n \n\nFor example, the sum of the digits in 99 is 18, which turns out to be the\nmaximum value.\n\n* * *"}, {"input": "9995", "output": "35\n \n\nFor example, the sum of the digits in 9989 is 35, which turns out to be the\nmaximum value.\n\n* * *"}, {"input": "3141592653589793", "output": "137"}]
Print the maximum possible sum of the digits (in base 10) of a positive integer not greater than N. * * *
s357273112
Wrong Answer
p03427
Input is given from Standard Input in the following format: N
X = list(map(int, input())) sn = [] for i in range(len(X)): sn.append(sum(X[0 : i + 1])) ssn = [] for i in range(len(X)): ssn.append(sn[i] - 1 + 9 * (len(X) - 1 - i)) print(max(ssn))
Statement Find the maximum possible sum of the digits (in base 10) of a positive integer not greater than N.
[{"input": "100", "output": "18\n \n\nFor example, the sum of the digits in 99 is 18, which turns out to be the\nmaximum value.\n\n* * *"}, {"input": "9995", "output": "35\n \n\nFor example, the sum of the digits in 9989 is 35, which turns out to be the\nmaximum value.\n\n* * *"}, {"input": "3141592653589793", "output": "137"}]
Print the maximum possible sum of the digits (in base 10) of a positive integer not greater than N. * * *
s823700215
Accepted
p03427
Input is given from Standard Input in the following format: N
n = int(input()) n_str = str(n) num = len(n_str) hikaku = int(str(n_str[0]) + str(9) * (num - 1)) atai = int(int(n_str[0]) + int(9) * (num - 1)) if n >= hikaku: print(atai) else: print(atai - 1)
Statement Find the maximum possible sum of the digits (in base 10) of a positive integer not greater than N.
[{"input": "100", "output": "18\n \n\nFor example, the sum of the digits in 99 is 18, which turns out to be the\nmaximum value.\n\n* * *"}, {"input": "9995", "output": "35\n \n\nFor example, the sum of the digits in 9989 is 35, which turns out to be the\nmaximum value.\n\n* * *"}, {"input": "3141592653589793", "output": "137"}]
Print the maximum possible sum of the digits (in base 10) of a positive integer not greater than N. * * *
s472952595
Runtime Error
p03427
Input is given from Standard Input in the following format: N
-*- coding: utf-8 -*- N = input() if len(N) == 1: # 1桁の数字 print(N) elif all(map(lambda x: x == '9', N[1:])): # 下位が全部9の場合 print(sum(int(n) for n in N)) else: # 下位を全部9にする例 print(9 * (len(N) - 1) + int(N[0]) - 1)
Statement Find the maximum possible sum of the digits (in base 10) of a positive integer not greater than N.
[{"input": "100", "output": "18\n \n\nFor example, the sum of the digits in 99 is 18, which turns out to be the\nmaximum value.\n\n* * *"}, {"input": "9995", "output": "35\n \n\nFor example, the sum of the digits in 9989 is 35, which turns out to be the\nmaximum value.\n\n* * *"}, {"input": "3141592653589793", "output": "137"}]
Print the maximum possible sum of the digits (in base 10) of a positive integer not greater than N. * * *
s201094016
Accepted
p03427
Input is given from Standard Input in the following format: N
# print#!/usr/bin/env python3 # %% for atcoder uniittest use import sys input = lambda: sys.stdin.readline().rstrip() sys.setrecursionlimit(10**9) def pin(type=int): return map(type, input().split()) def tupin(t=int): return tuple(pin(t)) def lispin(t=int): return list(pin(t)) # %%code from collections import Counter def resolve(): N = list(input()) a = sum(map(int, N)) for n in range(1, len(N)): t = N[:n] + [9] * (len(N) - n) a = max(a, sum(map(int, t)) - 1) print(a) # %%submit! resolve()
Statement Find the maximum possible sum of the digits (in base 10) of a positive integer not greater than N.
[{"input": "100", "output": "18\n \n\nFor example, the sum of the digits in 99 is 18, which turns out to be the\nmaximum value.\n\n* * *"}, {"input": "9995", "output": "35\n \n\nFor example, the sum of the digits in 9989 is 35, which turns out to be the\nmaximum value.\n\n* * *"}, {"input": "3141592653589793", "output": "137"}]
Print the maximum possible sum of the digits (in base 10) of a positive integer not greater than N. * * *
s853411701
Accepted
p03427
Input is given from Standard Input in the following format: N
n = int(input()) s = str(n) len_s = len(s) dp = [[0] * (len_s + 1) for i in range(2)] dp[0][1] = int(s[0]) dp[1][1] = int(s[0]) - 1 for i in range(1, len_s): for num in range(int(s[i]) + 1): dp[0][i + 1] = max(dp[0][i + 1], dp[0][i] + num) for num in range(int(s[i])): dp[1][i + 1] = max(dp[1][i + 1], dp[0][i] + num) for num in range(10): dp[1][i + 1] = max(dp[1][i + 1], dp[1][i] + num) print(max(dp[0][len_s], dp[1][len_s]))
Statement Find the maximum possible sum of the digits (in base 10) of a positive integer not greater than N.
[{"input": "100", "output": "18\n \n\nFor example, the sum of the digits in 99 is 18, which turns out to be the\nmaximum value.\n\n* * *"}, {"input": "9995", "output": "35\n \n\nFor example, the sum of the digits in 9989 is 35, which turns out to be the\nmaximum value.\n\n* * *"}, {"input": "3141592653589793", "output": "137"}]
Print the maximum possible sum of the digits (in base 10) of a positive integer not greater than N. * * *
s235921079
Accepted
p03427
Input is given from Standard Input in the following format: N
# -*- coding: utf-8 -*- ############# # Libraries # ############# import sys input = sys.stdin.readline import math # from math import gcd import bisect from collections import defaultdict from collections import deque from collections import Counter from functools import lru_cache ############# # Constants # ############# MOD = 10**9 + 7 INF = float("inf") ############# # Functions # ############# ######INPUT###### def I(): return int(input().strip()) def S(): return input().strip() def IL(): return list(map(int, input().split())) def SL(): return list(map(str, input().split())) def ILs(n): return list(int(input()) for _ in range(n)) def SLs(n): return list(input().strip() for _ in range(n)) def ILL(n): return [list(map(int, input().split())) for _ in range(n)] def SLL(n): return [list(map(str, input().split())) for _ in range(n)] ######OUTPUT###### def P(arg): print(arg) return def Y(): print("Yes") return def N(): print("No") return def E(): exit() def PE(arg): print(arg) exit() def YE(): print("Yes") exit() def NE(): print("No") exit() #####Shorten##### def DD(arg): return defaultdict(arg) #####Inverse##### def inv(n): return pow(n, MOD - 2, MOD) ######Combination###### kaijo_memo = [] def kaijo(n): if len(kaijo_memo) > n: return kaijo_memo[n] if len(kaijo_memo) == 0: kaijo_memo.append(1) while len(kaijo_memo) <= n: kaijo_memo.append(kaijo_memo[-1] * len(kaijo_memo) % MOD) return kaijo_memo[n] gyaku_kaijo_memo = [] def gyaku_kaijo(n): if len(gyaku_kaijo_memo) > n: return gyaku_kaijo_memo[n] if len(gyaku_kaijo_memo) == 0: gyaku_kaijo_memo.append(1) while len(gyaku_kaijo_memo) <= n: gyaku_kaijo_memo.append( gyaku_kaijo_memo[-1] * pow(len(gyaku_kaijo_memo), MOD - 2, MOD) % MOD ) return gyaku_kaijo_memo[n] def nCr(n, r): if n == r: return 1 if n < r or r < 0: return 0 ret = 1 ret = ret * kaijo(n) % MOD ret = ret * gyaku_kaijo(r) % MOD ret = ret * gyaku_kaijo(n - r) % MOD return ret ######Factorization###### def factorization(n): arr = [] temp = n for i in range(2, int(-(-(n**0.5) // 1)) + 1): if temp % i == 0: cnt = 0 while temp % i == 0: cnt += 1 temp //= i arr.append([i, cnt]) if temp != 1: arr.append([temp, 1]) if arr == []: arr.append([n, 1]) return arr #####MakeDivisors###### def make_divisors(n): divisors = [] for i in range(1, int(n**0.5) + 1): if n % i == 0: divisors.append(i) if i != n // i: divisors.append(n // i) return divisors #####MakePrimes###### def make_primes(N): max = int(math.sqrt(N)) seachList = [i for i in range(2, N + 1)] primeNum = [] while seachList[0] <= max: primeNum.append(seachList[0]) tmp = seachList[0] seachList = [i for i in seachList if i % tmp != 0] primeNum.extend(seachList) return primeNum #####GCD##### def gcd(a, b): while b: a, b = b, a % b return a #####LCM##### def lcm(a, b): return a * b // gcd(a, b) #####BitCount##### def count_bit(n): count = 0 while n: n &= n - 1 count += 1 return count #####ChangeBase##### def base_10_to_n(X, n): if X // n: return base_10_to_n(X // n, n) + [X % n] return [X % n] def base_n_to_10(X, n): return sum(int(str(X)[-i - 1]) * n**i for i in range(len(str(X)))) #####IntLog##### def int_log(n, a): count = 0 while n >= a: n //= a count += 1 return count ############# # Main Code # ############# N = I() NN = N + 0 L = int_log(N, 10) if N == pow(10, L + 1) - 1: print(L * 9 + 9) exit() count_9 = 0 while (NN + 1) % 10 == 0: count_9 += 1 NN = int(str(NN)[:-1]) if count_9 == len(str(N)) - 1: print(sum(map(int, list(str(N))))) else: L = int_log(N, 10) print((count_9 + L) * 9 + (int(str(N)[0]) + 9) % 10)
Statement Find the maximum possible sum of the digits (in base 10) of a positive integer not greater than N.
[{"input": "100", "output": "18\n \n\nFor example, the sum of the digits in 99 is 18, which turns out to be the\nmaximum value.\n\n* * *"}, {"input": "9995", "output": "35\n \n\nFor example, the sum of the digits in 9989 is 35, which turns out to be the\nmaximum value.\n\n* * *"}, {"input": "3141592653589793", "output": "137"}]
Print the maximum possible sum of the digits (in base 10) of a positive integer not greater than N. * * *
s639731446
Accepted
p03427
Input is given from Standard Input in the following format: N
N = input() res = sum(map(int, N)) res = max(res, max(0, int(N[0]) - 1 + 9 * (len(N) - 1))) for i in range(1, len(N) - 1): if int(N[i]) > 0: t = 0 for j in range(i): t += int(N[j]) t += int(N[i]) - 1 + 9 * (len(N) - i - 1) res = max(res, t) print(res)
Statement Find the maximum possible sum of the digits (in base 10) of a positive integer not greater than N.
[{"input": "100", "output": "18\n \n\nFor example, the sum of the digits in 99 is 18, which turns out to be the\nmaximum value.\n\n* * *"}, {"input": "9995", "output": "35\n \n\nFor example, the sum of the digits in 9989 is 35, which turns out to be the\nmaximum value.\n\n* * *"}, {"input": "3141592653589793", "output": "137"}]
Print the maximum possible sum of the digits (in base 10) of a positive integer not greater than N. * * *
s538569607
Runtime Error
p03427
Input is given from Standard Input in the following format: N
from math import acos, hypot, pi class Point: def __init__(self, i, x, y): self.i = i self.x = int(x) self.y = int(y) class Line: def __init__(self, p1, p2): self.p1 = p1 self.p2 = p2 self.d2 = (p1.x - p2.x) ** 2 + (p1.y - p2.y) ** 2 if p1.x == p2.x: self.a = 1 self.b = 0 else: self.a = p2.y - p1.y self.b = p1.x - p2.x self.c = -p1.y * self.b - p1.x * self.a def dist(self, p): f = self.a * p.x + self.b * p.y + self.c if f == 0: d12 = (self.p1.x - p.x) ** 2 + (self.p1.y - p.y) ** 2 d22 = (self.p2.x - p.x) ** 2 + (self.p2.y - p.y) ** 2 if self.d2 < max(d12, d22): return None return 0 if f < 0: return -1 else: return 1 def kaku(self, other): x = self.a * other.a + self.b * other.b x /= hypot(self.a, self.b) * hypot(other.a, other.b) return pi - acos(x) def make_p(n, pp): pids = {p.i: [] for p in pp} for i in range(n): if len(pids[i]) == 2: continue p1 = pp[i] for j in pids: if i == j or len(pids[j]) == 2: continue p2 = pp[j] line = Line(p1, p2) ptype = {0: 0, 1: 0, -1: 0, None: 0} for k in pids: if k == i or k == j: continue ptype[line.dist(pp[k])] += 1 if ptype[None]: continue if ptype[1] == 0 or ptype[-1] == 0: pids[i].append(j) pids[j].append(i) return pids def main(): n = int(input()) if n == 2: print(0.5) print(0.5) return pp = [] for i in range(n): p = Point(i, *input().split()) pp.append(p) pids = make_p(n, pp) prob = [0.0] * n for i, nei in pids.items(): if len(nei) == 2: l1 = Line(pp[i], pp[nei[0]]) l2 = Line(pp[i], pp[nei[1]]) kaku = l1.kaku(l2) prob[i] += kaku / (2 * pi) for p in prob: print(p) if __name__ == "__main__": main()
Statement Find the maximum possible sum of the digits (in base 10) of a positive integer not greater than N.
[{"input": "100", "output": "18\n \n\nFor example, the sum of the digits in 99 is 18, which turns out to be the\nmaximum value.\n\n* * *"}, {"input": "9995", "output": "35\n \n\nFor example, the sum of the digits in 9989 is 35, which turns out to be the\nmaximum value.\n\n* * *"}, {"input": "3141592653589793", "output": "137"}]
Print the maximum possible sum of the digits (in base 10) of a positive integer not greater than N. * * *
s573558490
Runtime Error
p03427
Input is given from Standard Input in the following format: N
# -*- coding: utf-8 -*- import sys import math import os import itertools import string import heapq import _collections from collections import Counter from collections import defaultdict from functools import lru_cache import bisect import re import queue class Scanner: @staticmethod def int(): return int(sys.stdin.readline().rstrip()) @staticmethod def string(): return sys.stdin.readline().rstrip() @staticmethod def map_int(): return [int(x) for x in Scanner.string().split()] @staticmethod def string_list(n): return [input() for i in range(n)] @staticmethod def int_list_list(n): return [Scanner.map_int() for i in range(n)] @staticmethod def int_cols_list(n): return [int(input()) for i in range(n)] class Math: @staticmethod def gcd(a, b): if b == 0: return a return Math.gcd(b, a % b) @staticmethod def lcm(a, b): return (a * b) // Math.gcd(a, b) @staticmethod def roundUp(a, b): return -(-a // b) @staticmethod def toUpperMultiple(a, x): return Math.roundUp(a, x) * x @staticmethod def toLowerMultiple(a, x): return (a // x) * x @staticmethod def nearPow2(n): if n <= 0: return 0 if n & (n - 1) == 0: return n ret = 1 while n > 0: ret <<= 1 n >>= 1 return ret @staticmethod def sign(n): if n == 0: return 0 if n < 0: return -1 return 1 @staticmethod def isPrime(n): if n < 2: return False if n == 2: return True if n % 2 == 0: return False d = int(n**0.5) + 1 for i in range(3, d + 1, 2): if n % i == 0: return False return True class PriorityQueue: def __init__(self, l=[]): self.__q = l heapq.heapify(self.__q) return def push(self, n): heapq.heappush(self.__q, n) return def pop(self): return heapq.heappop(self.__q) MOD = int(1e09) + 7 INF = int(1e15) def calc(N): return sum(int(x) for x in str(N)) def main(): # sys.stdin = open("sample.txt") N = Scanner.int() ans = calc(N) ans = max(ans, calc(int(str(int(str(N)[0]) - 1) + "9" * (len(str(N)) - 1)))) ans = max(ans, calc(N - N % 10 - 1)) print(ans) return if __name__ == "__main__": main()
Statement Find the maximum possible sum of the digits (in base 10) of a positive integer not greater than N.
[{"input": "100", "output": "18\n \n\nFor example, the sum of the digits in 99 is 18, which turns out to be the\nmaximum value.\n\n* * *"}, {"input": "9995", "output": "35\n \n\nFor example, the sum of the digits in 9989 is 35, which turns out to be the\nmaximum value.\n\n* * *"}, {"input": "3141592653589793", "output": "137"}]
Print the maximum possible sum of the digits (in base 10) of a positive integer not greater than N. * * *
s760006627
Accepted
p03427
Input is given from Standard Input in the following format: N
s, *n = str(int(input()) + 1) print(int(s) + 9 * len(n) - 1)
Statement Find the maximum possible sum of the digits (in base 10) of a positive integer not greater than N.
[{"input": "100", "output": "18\n \n\nFor example, the sum of the digits in 99 is 18, which turns out to be the\nmaximum value.\n\n* * *"}, {"input": "9995", "output": "35\n \n\nFor example, the sum of the digits in 9989 is 35, which turns out to be the\nmaximum value.\n\n* * *"}, {"input": "3141592653589793", "output": "137"}]
Print the maximum possible sum of the digits (in base 10) of a positive integer not greater than N. * * *
s920246012
Accepted
p03427
Input is given from Standard Input in the following format: N
import math import fractions import bisect import collections import itertools import heapq import string import sys import copy from decimal import * from collections import deque sys.setrecursionlimit(10**7) MOD = 10**9 + 7 INF = float("inf") # 無限大 def gcd(a, b): return fractions.gcd(a, b) # 最大公約数 def lcm(a, b): return (a * b) // fractions.gcd(a, b) # 最小公倍数 def iin(): return int(sys.stdin.readline()) # 整数読み込み def ifn(): return float(sys.stdin.readline()) # 浮動小数点読み込み def isn(): return sys.stdin.readline().split() # 文字列読み込み def imn(): return map(int, sys.stdin.readline().split()) # 整数map取得 def imnn(): return map(lambda x: int(x) - 1, sys.stdin.readline().split()) # 整数-1map取得 def fmn(): return map(float, sys.stdin.readline().split()) # 浮動小数点map取得 def iln(): return list(map(int, sys.stdin.readline().split())) # 整数リスト取得 def iln_s(): return sorted(iln()) # 昇順の整数リスト取得 def iln_r(): return sorted(iln(), reverse=True) # 降順の整数リスト取得 def fln(): return list(map(float, sys.stdin.readline().split())) # 浮動小数点リスト取得 def join(l, s=""): return s.join(l) # リストを文字列に変換 def perm(l, n): return itertools.permutations(l, n) # 順列取得 def perm_count(n, r): return math.factorial(n) // math.factorial(n - r) # 順列の総数 def comb(l, n): return itertools.combinations(l, n) # 組み合わせ取得 def comb_count(n, r): return math.factorial(n) // ( math.factorial(n - r) * math.factorial(r) ) # 組み合わせの総数 def two_distance(a, b, c, d): return ((c - a) ** 2 + (d - b) ** 2) ** 0.5 # 2点間の距離 def m_add(a, b): return (a + b) % MOD def print_list(l): print(*l, sep="\n") def sieves_of_e(n): is_prime = [True] * (n + 1) is_prime[0] = False is_prime[1] = False for i in range(2, int(n**0.5) + 1): if not is_prime[i]: continue for j in range(i * 2, n + 1, i): is_prime[j] = False return is_prime N = str(iin()) sum_N = 0 for n in N: sum_N += int(n) ans = 0 if N[0] != 1: ans = int(N[0]) - 1 ans += (len(N) - 1) * 9 print(max(sum_N, ans))
Statement Find the maximum possible sum of the digits (in base 10) of a positive integer not greater than N.
[{"input": "100", "output": "18\n \n\nFor example, the sum of the digits in 99 is 18, which turns out to be the\nmaximum value.\n\n* * *"}, {"input": "9995", "output": "35\n \n\nFor example, the sum of the digits in 9989 is 35, which turns out to be the\nmaximum value.\n\n* * *"}, {"input": "3141592653589793", "output": "137"}]
Print the maximum possible sum of the digits (in base 10) of a positive integer not greater than N. * * *
s284836882
Wrong Answer
p03427
Input is given from Standard Input in the following format: N
# coding: utf-8 import re import math from collections import defaultdict from collections import deque import itertools from copy import deepcopy import random import time import os import queue import sys import datetime from functools import lru_cache # @lru_cache(maxsize=None) readline = sys.stdin.readline sys.setrecursionlimit(2000000) # import numpy as np alphabet = "abcdefghijklmnopqrstuvwxyz" mod = int(10**9 + 7) inf = int(10**20) def yn(b): if b: print("yes") else: print("no") def Yn(b): if b: print("Yes") else: print("No") def YN(b): if b: print("YES") else: print("NO") class union_find: def __init__(self, n): self.n = n self.P = [a for a in range(N)] self.rank = [0] * n def find(self, x): if x != self.P[x]: self.P[x] = self.find(self.P[x]) return self.P[x] def same(self, x, y): return self.find(x) == self.find(y) def link(self, x, y): if self.rank[x] < self.rank[y]: self.P[x] = y elif self.rank[y] < self.rank[x]: self.P[y] = x else: self.P[x] = y self.rank[y] += 1 def unite(self, x, y): self.link(self.find(x), self.find(y)) def size(self): S = set() for a in range(self.n): S.add(self.find(a)) return len(S) def is_pow(a, b): # aはbの累乗数か now = b while now < a: now *= b if now == a: return True else: return False def bin_(num, size): A = [0] * size for a in range(size): if (num >> (size - a - 1)) & 1 == 1: A[a] = 1 else: A[a] = 0 return A def get_facs(n, mod_=0): A = [1] * (n + 1) for a in range(2, len(A)): A[a] = A[a - 1] * a if mod_ > 0: A[a] %= mod_ return A def comb(n, r, mod, fac): if n - r < 0: return 0 return (fac[n] * pow(fac[n - r], mod - 2, mod) * pow(fac[r], mod - 2, mod)) % mod def next_comb(num, size): x = num & (-num) y = num + x z = num & (~y) z //= x z = z >> 1 num = y | z if num >= (1 << size): return False else: return num def get_primes(n, type="int"): if n == 0: if type == "int": return [] else: return [False] A = [True] * (n + 1) A[0] = False A[1] = False for a in range(2, n + 1): if A[a]: for b in range(a * 2, n + 1, a): A[b] = False if type == "bool": return A B = [] for a in range(n + 1): if A[a]: B.append(a) return B def is_prime(num): if num <= 1: return False i = 2 while i * i <= num: if num % i == 0: return False i += 1 return True def ifelse(a, b, c): if a: return b else: return c def join(A, c=""): n = len(A) A = list(map(str, A)) s = "" for a in range(n): s += A[a] if a < n - 1: s += c return s def factorize(n, type_="dict"): b = 2 list_ = [] while b * b <= n: while n % b == 0: n //= b list_.append(b) b += 1 if n > 1: list_.append(n) if type_ == "dict": dic = {} for a in list_: if a in dic: dic[a] += 1 else: dic[a] = 1 return dic elif type_ == "list": return list_ else: return None def floor_(n, x=1): return x * (n // x) def ceil_(n, x=1): return x * ((n + x - 1) // x) return ret def seifu(x): return x // abs(x) ###################################################################################################### def main(): n = input() ans = 0 for a in n: ans += int(a) ans = max((len(n) - 1) * 9, ans) print(ans) main()
Statement Find the maximum possible sum of the digits (in base 10) of a positive integer not greater than N.
[{"input": "100", "output": "18\n \n\nFor example, the sum of the digits in 99 is 18, which turns out to be the\nmaximum value.\n\n* * *"}, {"input": "9995", "output": "35\n \n\nFor example, the sum of the digits in 9989 is 35, which turns out to be the\nmaximum value.\n\n* * *"}, {"input": "3141592653589793", "output": "137"}]
Print the maximum possible sum of the digits (in base 10) of a positive integer not greater than N. * * *
s353331984
Accepted
p03427
Input is given from Standard Input in the following format: N
n = int(input()) num = [] k = n while k != 0: num.append(k % 10) k = k // 10 print(max(sum(num), num[-1] - 1 + 9 * (len(num) - 1)))
Statement Find the maximum possible sum of the digits (in base 10) of a positive integer not greater than N.
[{"input": "100", "output": "18\n \n\nFor example, the sum of the digits in 99 is 18, which turns out to be the\nmaximum value.\n\n* * *"}, {"input": "9995", "output": "35\n \n\nFor example, the sum of the digits in 9989 is 35, which turns out to be the\nmaximum value.\n\n* * *"}, {"input": "3141592653589793", "output": "137"}]
Print the maximum possible sum of the digits (in base 10) of a positive integer not greater than N. * * *
s790823702
Accepted
p03427
Input is given from Standard Input in the following format: N
#!/usr/bin/env python3 import sys, math, copy # import fractions, itertools # import numpy as np # import scipy HUGE = 2147483647 HUGEL = 9223372036854775807 ABC = "abcdefghijklmnopqrstuvwxyz" def main(): def digsum(s): su = 0 for c in s: su += int(c) return su def break_ith_dig(s, i1): assert 2 <= i1 <= dig if s[-i1] == "0": return s s = s[:-i1] + str(int(s[-i1]) - 1) + "9" * (i1 - 1) return s ns = input() dig = len(ns) ma = digsum(ns) for i in range(2, dig + 1): ns = break_ith_dig(ns, i) ma = max(ma, digsum(ns)) print(ma) main()
Statement Find the maximum possible sum of the digits (in base 10) of a positive integer not greater than N.
[{"input": "100", "output": "18\n \n\nFor example, the sum of the digits in 99 is 18, which turns out to be the\nmaximum value.\n\n* * *"}, {"input": "9995", "output": "35\n \n\nFor example, the sum of the digits in 9989 is 35, which turns out to be the\nmaximum value.\n\n* * *"}, {"input": "3141592653589793", "output": "137"}]
Print the maximum possible sum of the digits (in base 10) of a positive integer not greater than N. * * *
s713033284
Wrong Answer
p03427
Input is given from Standard Input in the following format: N
import sys ## io ## def IS(): return sys.stdin.readline().rstrip() def II(): return int(IS()) def MII(): return list(map(int, IS().split())) def MIIZ(): return list(map(lambda x: x - 1, MII())) ## dp ## def DD2(d1, d2, init=0): return [[init] * d2 for _ in range(d1)] def DD3(d1, d2, d3, init=0): return [DD2(d2, d3, init) for _ in range(d1)] ## math ## def to_bin(x: int) -> str: return format(x, "b") # rev => int(res, 2) def to_oct(x: int) -> str: return format(x, "o") # rev => int(res, 8) def to_hex(x: int) -> str: return format(x, "x") # rev => int(res, 16) MOD = 10**9 + 7 def divc(x, y) -> int: return -(-x // y) def divf(x, y) -> int: return x // y def gcd(x, y): while y: x, y = y, x % y return x def lcm(x, y): return x * y // gcd(x, y) def enumerate_divs(n): """Return a tuple list of divisor of n""" return [(i, n // i) for i in range(1, int(n**0.5) + 1) if n % i == 0] def get_primes(MAX_NUM=10**3): """Return a list of prime numbers n or less""" is_prime = [True] * (MAX_NUM + 1) is_prime[0] = is_prime[1] = False for i in range(2, int(MAX_NUM**0.5) + 1): if not is_prime[i]: continue for j in range(i * 2, MAX_NUM + 1, i): is_prime[j] = False return [i for i in range(MAX_NUM + 1) if is_prime[i]] ## libs ## from itertools import accumulate as acc from collections import deque, Counter from heapq import heapify, heappop, heappush from bisect import bisect_left # ======================================================# def main(): n = II() s = str(n) d = len(s) maxv = 0 for i in range(d): l = sum(int(si) for si in s[:i]) l += int(s[i]) - 1 l += 9 * (d - i - 1) maxv = max(maxv, l) print(maxv) if __name__ == "__main__": main()
Statement Find the maximum possible sum of the digits (in base 10) of a positive integer not greater than N.
[{"input": "100", "output": "18\n \n\nFor example, the sum of the digits in 99 is 18, which turns out to be the\nmaximum value.\n\n* * *"}, {"input": "9995", "output": "35\n \n\nFor example, the sum of the digits in 9989 is 35, which turns out to be the\nmaximum value.\n\n* * *"}, {"input": "3141592653589793", "output": "137"}]
Print the maximum possible sum of the digits (in base 10) of a positive integer not greater than N. * * *
s746167023
Runtime Error
p03427
Input is given from Standard Input in the following format: N
n = input() ans1=sum(int(i)for i in n) ans2=int(n[0])-1+9*(len(n)-1) print(max(ans1,ans2)
Statement Find the maximum possible sum of the digits (in base 10) of a positive integer not greater than N.
[{"input": "100", "output": "18\n \n\nFor example, the sum of the digits in 99 is 18, which turns out to be the\nmaximum value.\n\n* * *"}, {"input": "9995", "output": "35\n \n\nFor example, the sum of the digits in 9989 is 35, which turns out to be the\nmaximum value.\n\n* * *"}, {"input": "3141592653589793", "output": "137"}]
Print the maximum possible sum of the digits (in base 10) of a positive integer not greater than N. * * *
s329780851
Wrong Answer
p03427
Input is given from Standard Input in the following format: N
n = int(input()) d = len(str(n)) print(n // (10 ** (d - 1)) - 1 + 9 * (d - 1))
Statement Find the maximum possible sum of the digits (in base 10) of a positive integer not greater than N.
[{"input": "100", "output": "18\n \n\nFor example, the sum of the digits in 99 is 18, which turns out to be the\nmaximum value.\n\n* * *"}, {"input": "9995", "output": "35\n \n\nFor example, the sum of the digits in 9989 is 35, which turns out to be the\nmaximum value.\n\n* * *"}, {"input": "3141592653589793", "output": "137"}]
Print the maximum possible sum of the digits (in base 10) of a positive integer not greater than N. * * *
s525141570
Wrong Answer
p03427
Input is given from Standard Input in the following format: N
tes = input() a = [int(data) for data in tes] print(sum(a))
Statement Find the maximum possible sum of the digits (in base 10) of a positive integer not greater than N.
[{"input": "100", "output": "18\n \n\nFor example, the sum of the digits in 99 is 18, which turns out to be the\nmaximum value.\n\n* * *"}, {"input": "9995", "output": "35\n \n\nFor example, the sum of the digits in 9989 is 35, which turns out to be the\nmaximum value.\n\n* * *"}, {"input": "3141592653589793", "output": "137"}]
Print the maximum possible sum of the digits (in base 10) of a positive integer not greater than N. * * *
s676598714
Accepted
p03427
Input is given from Standard Input in the following format: N
# coding: utf-8 s = list(map(int, list(input()))) mx = sum(s) for i in range(len(s)): mx = max(sum(s[0 : i + 1]) - 1 + 9 * (len(s) - i - 1), mx) print(mx)
Statement Find the maximum possible sum of the digits (in base 10) of a positive integer not greater than N.
[{"input": "100", "output": "18\n \n\nFor example, the sum of the digits in 99 is 18, which turns out to be the\nmaximum value.\n\n* * *"}, {"input": "9995", "output": "35\n \n\nFor example, the sum of the digits in 9989 is 35, which turns out to be the\nmaximum value.\n\n* * *"}, {"input": "3141592653589793", "output": "137"}]
Print the maximum possible sum of the digits (in base 10) of a positive integer not greater than N. * * *
s926871466
Accepted
p03427
Input is given from Standard Input in the following format: N
x = input() l = len(x) if len(x) == 1: print(x) elif x[1:] == "9" * ~-l: print(int(x[0]) + 9 * ~-l) elif x[0] == "1": print(9 * ~-l) else: print(int(x[0]) - 1 + 9 * ~-l)
Statement Find the maximum possible sum of the digits (in base 10) of a positive integer not greater than N.
[{"input": "100", "output": "18\n \n\nFor example, the sum of the digits in 99 is 18, which turns out to be the\nmaximum value.\n\n* * *"}, {"input": "9995", "output": "35\n \n\nFor example, the sum of the digits in 9989 is 35, which turns out to be the\nmaximum value.\n\n* * *"}, {"input": "3141592653589793", "output": "137"}]
Print the maximum possible sum of the digits (in base 10) of a positive integer not greater than N. * * *
s518291148
Wrong Answer
p03427
Input is given from Standard Input in the following format: N
n = int(input()) c = len(str(n)) for i in range(1, 10): b = int(str(i) + "9" * (c - 1)) if int(str(i) + "9" * (c - 1)) >= n: print(9 * (c - 1) + (i - 1)) break
Statement Find the maximum possible sum of the digits (in base 10) of a positive integer not greater than N.
[{"input": "100", "output": "18\n \n\nFor example, the sum of the digits in 99 is 18, which turns out to be the\nmaximum value.\n\n* * *"}, {"input": "9995", "output": "35\n \n\nFor example, the sum of the digits in 9989 is 35, which turns out to be the\nmaximum value.\n\n* * *"}, {"input": "3141592653589793", "output": "137"}]
Print the maximum possible sum of the digits (in base 10) of a positive integer not greater than N. * * *
s405215059
Wrong Answer
p03427
Input is given from Standard Input in the following format: N
n = list(input()) x = [] for i in n: x.append(int(i)) out = int(n[0]) - 1 + (len(n) - 1) * 9 sample = [1] sample.extend([9] * (len(n) - 1)) if [9] * len(n) == x or sample == x or len(n) == 1: out = sum(x) print(out)
Statement Find the maximum possible sum of the digits (in base 10) of a positive integer not greater than N.
[{"input": "100", "output": "18\n \n\nFor example, the sum of the digits in 99 is 18, which turns out to be the\nmaximum value.\n\n* * *"}, {"input": "9995", "output": "35\n \n\nFor example, the sum of the digits in 9989 is 35, which turns out to be the\nmaximum value.\n\n* * *"}, {"input": "3141592653589793", "output": "137"}]
Print the maximum possible sum of the digits (in base 10) of a positive integer not greater than N. * * *
s389911903
Wrong Answer
p03427
Input is given from Standard Input in the following format: N
S = input() dp = [[0 for i in range(len(S))] for j in range(2)] dp[0][0] = int(S[0]) dp[1][0] = int(S[0]) - 1 for i in range(len(S) - 1): dp[0][i + 1] = dp[0][i] + int(S[i + 1]) dp[1][i + 1] = max(dp[0][i] + int(S[i + 1]) - 1, dp[1][i] + 9) print(dp[1][len(S) - 1])
Statement Find the maximum possible sum of the digits (in base 10) of a positive integer not greater than N.
[{"input": "100", "output": "18\n \n\nFor example, the sum of the digits in 99 is 18, which turns out to be the\nmaximum value.\n\n* * *"}, {"input": "9995", "output": "35\n \n\nFor example, the sum of the digits in 9989 is 35, which turns out to be the\nmaximum value.\n\n* * *"}, {"input": "3141592653589793", "output": "137"}]
Print the maximum possible sum of the digits (in base 10) of a positive integer not greater than N. * * *
s126322543
Wrong Answer
p03427
Input is given from Standard Input in the following format: N
s = input() n = int(s) l = len(s) isall9 = True for i in range(1, l): if s[i] != "9": isall9 = False if isall9: print(1 + 9 * (l - 1)) else: res = int(int(s[0]) - 1) + 9 * (l - 1) print(res)
Statement Find the maximum possible sum of the digits (in base 10) of a positive integer not greater than N.
[{"input": "100", "output": "18\n \n\nFor example, the sum of the digits in 99 is 18, which turns out to be the\nmaximum value.\n\n* * *"}, {"input": "9995", "output": "35\n \n\nFor example, the sum of the digits in 9989 is 35, which turns out to be the\nmaximum value.\n\n* * *"}, {"input": "3141592653589793", "output": "137"}]
Print the maximum possible sum of the digits (in base 10) of a positive integer not greater than N. * * *
s109178068
Wrong Answer
p03427
Input is given from Standard Input in the following format: N
N = input() a = [int(c) for c in N] naga = len(a) for i in range(naga): if a[i] < 9: a[i] -= 1 for j in range(i + 1, naga): a[j] = 9 break if a[naga - 1] != 9: a[naga - 2] -= 1 a[naga - 1] = 9 print(sum(a))
Statement Find the maximum possible sum of the digits (in base 10) of a positive integer not greater than N.
[{"input": "100", "output": "18\n \n\nFor example, the sum of the digits in 99 is 18, which turns out to be the\nmaximum value.\n\n* * *"}, {"input": "9995", "output": "35\n \n\nFor example, the sum of the digits in 9989 is 35, which turns out to be the\nmaximum value.\n\n* * *"}, {"input": "3141592653589793", "output": "137"}]
Print the maximum possible sum of the digits (in base 10) of a positive integer not greater than N. * * *
s505511300
Accepted
p03427
Input is given from Standard Input in the following format: N
# -*- coding: utf-8 -*- N = int(input()) def Sum(n): s = str(n) array = list(map(int, list(s))) return sum(array) a = [] a.append(Sum(N)) N_str = str(N) N_str = list(map(int, list(N_str))) "右端の数字を1下げたときの最大" N_str = str(N) N_str = list(map(int, list(N_str))) N_str[0] = N_str[0] - 1 for i in range(1, len(N_str)): N_str[i] = 9 a.append(sum(N_str)) print(max(a))
Statement Find the maximum possible sum of the digits (in base 10) of a positive integer not greater than N.
[{"input": "100", "output": "18\n \n\nFor example, the sum of the digits in 99 is 18, which turns out to be the\nmaximum value.\n\n* * *"}, {"input": "9995", "output": "35\n \n\nFor example, the sum of the digits in 9989 is 35, which turns out to be the\nmaximum value.\n\n* * *"}, {"input": "3141592653589793", "output": "137"}]
Print the maximum possible sum of the digits (in base 10) of a positive integer not greater than N. * * *
s748529196
Wrong Answer
p03427
Input is given from Standard Input in the following format: N
n = input().zfill(16) INF = 10**18 memo_ls = [[0 for i in range(2)] for j in range(17)] memo_ls[0][0] = 0 memo_ls[0][1] = -INF for i in range(1, 17): s = int(n[i - 1]) memo_ls[i][0] = memo_ls[i - 1][0] + s memo_ls[i][1] = memo_ls[i - 1][1] + 9 if s > 0: memo_ls[i][1] = max(memo_ls[i][1], memo_ls[i - 1][0] + s - 1) print(max(memo_ls[-1]))
Statement Find the maximum possible sum of the digits (in base 10) of a positive integer not greater than N.
[{"input": "100", "output": "18\n \n\nFor example, the sum of the digits in 99 is 18, which turns out to be the\nmaximum value.\n\n* * *"}, {"input": "9995", "output": "35\n \n\nFor example, the sum of the digits in 9989 is 35, which turns out to be the\nmaximum value.\n\n* * *"}, {"input": "3141592653589793", "output": "137"}]
Print the maximum possible sum of the digits (in base 10) of a positive integer not greater than N. * * *
s428581899
Wrong Answer
p03427
Input is given from Standard Input in the following format: N
a = list(input()) c = 0 for i in range(len(a)): b = "" d = 0 for j in range(len(a)): if i == j: b += str(max(int(a[i]) - 1, 0)) d += max(int(a[i]) - 1, 0) else: b += "9" d += 9 if int(b) <= int("".join(a)): c = max(c, d) print(c)
Statement Find the maximum possible sum of the digits (in base 10) of a positive integer not greater than N.
[{"input": "100", "output": "18\n \n\nFor example, the sum of the digits in 99 is 18, which turns out to be the\nmaximum value.\n\n* * *"}, {"input": "9995", "output": "35\n \n\nFor example, the sum of the digits in 9989 is 35, which turns out to be the\nmaximum value.\n\n* * *"}, {"input": "3141592653589793", "output": "137"}]
Print the maximum possible sum of the digits (in base 10) of a positive integer not greater than N. * * *
s321789307
Wrong Answer
p03427
Input is given from Standard Input in the following format: N
a = list(input()) if len(a) == 1: print(a) else: c = 0 for i in range(len(a)): b = "" d = 0 for j in range(len(a)): if i == j: b += str(max(int(a[i]) - 1, 0)) d += max(int(a[i]) - 1, 0) else: b += "9" d += 9 if int(b) <= int("".join(a)): c = max(c, d) print(c)
Statement Find the maximum possible sum of the digits (in base 10) of a positive integer not greater than N.
[{"input": "100", "output": "18\n \n\nFor example, the sum of the digits in 99 is 18, which turns out to be the\nmaximum value.\n\n* * *"}, {"input": "9995", "output": "35\n \n\nFor example, the sum of the digits in 9989 is 35, which turns out to be the\nmaximum value.\n\n* * *"}, {"input": "3141592653589793", "output": "137"}]
Print the maximum possible sum of the digits (in base 10) of a positive integer not greater than N. * * *
s673445082
Accepted
p03427
Input is given from Standard Input in the following format: N
a = input() x = 0 y = 0 for c in a: x += int(c) y += 9 y += int(a[0]) - 10 print(max(x, y))
Statement Find the maximum possible sum of the digits (in base 10) of a positive integer not greater than N.
[{"input": "100", "output": "18\n \n\nFor example, the sum of the digits in 99 is 18, which turns out to be the\nmaximum value.\n\n* * *"}, {"input": "9995", "output": "35\n \n\nFor example, the sum of the digits in 9989 is 35, which turns out to be the\nmaximum value.\n\n* * *"}, {"input": "3141592653589793", "output": "137"}]
Print the maximum possible sum of the digits (in base 10) of a positive integer not greater than N. * * *
s748883693
Accepted
p03427
Input is given from Standard Input in the following format: N
N = input() d = len(N) A = int(N[0]) - 1 + (d - 1) * 9 B = 0 for i in N: B += int(i) print(max(A, B))
Statement Find the maximum possible sum of the digits (in base 10) of a positive integer not greater than N.
[{"input": "100", "output": "18\n \n\nFor example, the sum of the digits in 99 is 18, which turns out to be the\nmaximum value.\n\n* * *"}, {"input": "9995", "output": "35\n \n\nFor example, the sum of the digits in 9989 is 35, which turns out to be the\nmaximum value.\n\n* * *"}, {"input": "3141592653589793", "output": "137"}]
Print the maximum possible sum of the digits (in base 10) of a positive integer not greater than N. * * *
s890023446
Accepted
p03427
Input is given from Standard Input in the following format: N
N = list(input()) N = [int(e) for e in N] v1 = sum(N) v2 = N[0] - 1 + 9 * (len(N) - 1) print(max(v1, v2))
Statement Find the maximum possible sum of the digits (in base 10) of a positive integer not greater than N.
[{"input": "100", "output": "18\n \n\nFor example, the sum of the digits in 99 is 18, which turns out to be the\nmaximum value.\n\n* * *"}, {"input": "9995", "output": "35\n \n\nFor example, the sum of the digits in 9989 is 35, which turns out to be the\nmaximum value.\n\n* * *"}, {"input": "3141592653589793", "output": "137"}]
Print the maximum possible sum of the digits (in base 10) of a positive integer not greater than N. * * *
s969291536
Accepted
p03427
Input is given from Standard Input in the following format: N
f, *n = str(int(input()) + 1) print(int(f) + 9 * len(n) - 1)
Statement Find the maximum possible sum of the digits (in base 10) of a positive integer not greater than N.
[{"input": "100", "output": "18\n \n\nFor example, the sum of the digits in 99 is 18, which turns out to be the\nmaximum value.\n\n* * *"}, {"input": "9995", "output": "35\n \n\nFor example, the sum of the digits in 9989 is 35, which turns out to be the\nmaximum value.\n\n* * *"}, {"input": "3141592653589793", "output": "137"}]
Print the maximum possible sum of the digits (in base 10) of a positive integer not greater than N. * * *
s582454822
Wrong Answer
p03427
Input is given from Standard Input in the following format: N
s = int(input()) if sum(map(int, str(s))) == 1: s -= 1 z = 10 ** (len(str(s)) - 1) y = (s + 1) // z * z - 1 print(sum(map(int, str(y))))
Statement Find the maximum possible sum of the digits (in base 10) of a positive integer not greater than N.
[{"input": "100", "output": "18\n \n\nFor example, the sum of the digits in 99 is 18, which turns out to be the\nmaximum value.\n\n* * *"}, {"input": "9995", "output": "35\n \n\nFor example, the sum of the digits in 9989 is 35, which turns out to be the\nmaximum value.\n\n* * *"}, {"input": "3141592653589793", "output": "137"}]
Print the maximum possible sum of the digits (in base 10) of a positive integer not greater than N. * * *
s241544045
Wrong Answer
p03427
Input is given from Standard Input in the following format: N
9999999999999999
Statement Find the maximum possible sum of the digits (in base 10) of a positive integer not greater than N.
[{"input": "100", "output": "18\n \n\nFor example, the sum of the digits in 99 is 18, which turns out to be the\nmaximum value.\n\n* * *"}, {"input": "9995", "output": "35\n \n\nFor example, the sum of the digits in 9989 is 35, which turns out to be the\nmaximum value.\n\n* * *"}, {"input": "3141592653589793", "output": "137"}]
Print the maximum possible sum of the digits (in base 10) of a positive integer not greater than N. * * *
s615221667
Wrong Answer
p03427
Input is given from Standard Input in the following format: N
3141592653589793
Statement Find the maximum possible sum of the digits (in base 10) of a positive integer not greater than N.
[{"input": "100", "output": "18\n \n\nFor example, the sum of the digits in 99 is 18, which turns out to be the\nmaximum value.\n\n* * *"}, {"input": "9995", "output": "35\n \n\nFor example, the sum of the digits in 9989 is 35, which turns out to be the\nmaximum value.\n\n* * *"}, {"input": "3141592653589793", "output": "137"}]
Print the maximum possible sum of the digits (in base 10) of a positive integer not greater than N. * * *
s209683147
Wrong Answer
p03427
Input is given from Standard Input in the following format: N
print(sum([int(i) for i in input()]))
Statement Find the maximum possible sum of the digits (in base 10) of a positive integer not greater than N.
[{"input": "100", "output": "18\n \n\nFor example, the sum of the digits in 99 is 18, which turns out to be the\nmaximum value.\n\n* * *"}, {"input": "9995", "output": "35\n \n\nFor example, the sum of the digits in 9989 is 35, which turns out to be the\nmaximum value.\n\n* * *"}, {"input": "3141592653589793", "output": "137"}]
Print the maximum possible sum of the digits (in base 10) of a positive integer not greater than N. * * *
s926094112
Runtime Error
p03427
Input is given from Standard Input in the following format: N
n = str(input().rstrip() + 1) ans = len(n) * 9 ans += int(n[0]) - 1 print(ans)
Statement Find the maximum possible sum of the digits (in base 10) of a positive integer not greater than N.
[{"input": "100", "output": "18\n \n\nFor example, the sum of the digits in 99 is 18, which turns out to be the\nmaximum value.\n\n* * *"}, {"input": "9995", "output": "35\n \n\nFor example, the sum of the digits in 9989 is 35, which turns out to be the\nmaximum value.\n\n* * *"}, {"input": "3141592653589793", "output": "137"}]
Print the minimum time required for all of the people to reach City 6, in minutes. * * *
s554539136
Accepted
p03077
Input is given from Standard Input in the following format: N A B C D E
N, *capas = map(int, open(0).read().split()) min_capa = min(capas) print((N + min_capa - 1) // min_capa + 4)
Statement In 2028 and after a continuous growth, AtCoder Inc. finally built an empire with six cities (City 1, 2, 3, 4, 5, 6)! There are five means of transport in this empire: * Train: travels from City 1 to 2 in one minute. A train can occupy at most A people. * Bus: travels from City 2 to 3 in one minute. A bus can occupy at most B people. * Taxi: travels from City 3 to 4 in one minute. A taxi can occupy at most C people. * Airplane: travels from City 4 to 5 in one minute. An airplane can occupy at most D people. * Ship: travels from City 5 to 6 in one minute. A ship can occupy at most E people. For each of them, one vehicle leaves the city at each integer time (time 0, 1, 2, ...). There is a group of N people at City 1, and they all want to go to City 6. At least how long does it take for all of them to reach there? You can ignore the time needed to transfer.
[{"input": "5\n 3\n 2\n 4\n 3\n 5", "output": "7\n \n\nOne possible way to travel is as follows. First, there are N = 5 people at\nCity 1, as shown in the following image:\n\n![ ](https://img.atcoder.jp/ghi/9c306138eddc8a2e08acfa5da19bdfe8.png)\n\nIn the first minute, three people travels from City 1 to City 2 by train. Note\nthat a train can only occupy at most three people.\n\n![ ](https://img.atcoder.jp/ghi/bd30b5ab37fc06951c9f5256bb974e4f.png)\n\nIn the second minute, the remaining two people travels from City 1 to City 2\nby train, and two of the three people who were already at City 2 travels to\nCity 3 by bus. Note that a bus can only occupy at most two people.\n\n![ ](https://img.atcoder.jp/ghi/50f2e49a770a30193fc53588ec8475b3.png)\n\nIn the third minute, two people travels from City 2 to City 3 by train, and\nanother two people travels from City 3 to City 4 by taxi.\n\n![ ](https://img.atcoder.jp/ghi/d6d80dc50abe58190905c8c5ea6ba345.png)\n\nFrom then on, if they continue traveling without stopping until they reach\nCity 6, all of them can reach there in seven minutes. \nThere is no way for them to reach City 6 in 6 minutes or less.\n\n* * *"}, {"input": "10\n 123\n 123\n 123\n 123\n 123", "output": "5\n \n\nAll kinds of vehicles can occupy N = 10 people at a time. Thus, if they\ncontinue traveling without stopping until they reach City 6, all of them can\nreach there in five minutes.\n\n* * *"}, {"input": "10000000007\n 2\n 3\n 5\n 7\n 11", "output": "5000000008\n \n\nNote that the input or output may not fit into a 32-bit integer type."}]
Print the minimum time required for all of the people to reach City 6, in minutes. * * *
s317290613
Runtime Error
p03077
Input is given from Standard Input in the following format: N A B C D E
# 2019/04/07 from numpy import array, zeros IN_RANGE = 5 # 入力受け取り N = int(input()) a_e = array([int(input()) for i in range(IN_RANGE)]) # どこに人がいるか a_e_num = zeros(IN_RANGE + 1) a_e_num[0] = N # 1分ずつの処理 minute = 0 while a_e_num[N] < N: minute += 1 move_index = (a_e_num[:N] - a_e) >= 0 move_num = a_e_num[:N].copy() move_num[move_index] = a_e[move_index] a_e_num[:N] = a_e_num[:N] - move_num a_e_num[1:] = a_e_num[1:] + move_num print(minute)
Statement In 2028 and after a continuous growth, AtCoder Inc. finally built an empire with six cities (City 1, 2, 3, 4, 5, 6)! There are five means of transport in this empire: * Train: travels from City 1 to 2 in one minute. A train can occupy at most A people. * Bus: travels from City 2 to 3 in one minute. A bus can occupy at most B people. * Taxi: travels from City 3 to 4 in one minute. A taxi can occupy at most C people. * Airplane: travels from City 4 to 5 in one minute. An airplane can occupy at most D people. * Ship: travels from City 5 to 6 in one minute. A ship can occupy at most E people. For each of them, one vehicle leaves the city at each integer time (time 0, 1, 2, ...). There is a group of N people at City 1, and they all want to go to City 6. At least how long does it take for all of them to reach there? You can ignore the time needed to transfer.
[{"input": "5\n 3\n 2\n 4\n 3\n 5", "output": "7\n \n\nOne possible way to travel is as follows. First, there are N = 5 people at\nCity 1, as shown in the following image:\n\n![ ](https://img.atcoder.jp/ghi/9c306138eddc8a2e08acfa5da19bdfe8.png)\n\nIn the first minute, three people travels from City 1 to City 2 by train. Note\nthat a train can only occupy at most three people.\n\n![ ](https://img.atcoder.jp/ghi/bd30b5ab37fc06951c9f5256bb974e4f.png)\n\nIn the second minute, the remaining two people travels from City 1 to City 2\nby train, and two of the three people who were already at City 2 travels to\nCity 3 by bus. Note that a bus can only occupy at most two people.\n\n![ ](https://img.atcoder.jp/ghi/50f2e49a770a30193fc53588ec8475b3.png)\n\nIn the third minute, two people travels from City 2 to City 3 by train, and\nanother two people travels from City 3 to City 4 by taxi.\n\n![ ](https://img.atcoder.jp/ghi/d6d80dc50abe58190905c8c5ea6ba345.png)\n\nFrom then on, if they continue traveling without stopping until they reach\nCity 6, all of them can reach there in seven minutes. \nThere is no way for them to reach City 6 in 6 minutes or less.\n\n* * *"}, {"input": "10\n 123\n 123\n 123\n 123\n 123", "output": "5\n \n\nAll kinds of vehicles can occupy N = 10 people at a time. Thus, if they\ncontinue traveling without stopping until they reach City 6, all of them can\nreach there in five minutes.\n\n* * *"}, {"input": "10000000007\n 2\n 3\n 5\n 7\n 11", "output": "5000000008\n \n\nNote that the input or output may not fit into a 32-bit integer type."}]
Print the minimum time required for all of the people to reach City 6, in minutes. * * *
s900681125
Accepted
p03077
Input is given from Standard Input in the following format: N A B C D E
n = int(input()) costs = [int(input()) for _ in range(5)] nums = [0] * 6 mc = min(costs) counts = -(-n // mc) print(counts + 4)
Statement In 2028 and after a continuous growth, AtCoder Inc. finally built an empire with six cities (City 1, 2, 3, 4, 5, 6)! There are five means of transport in this empire: * Train: travels from City 1 to 2 in one minute. A train can occupy at most A people. * Bus: travels from City 2 to 3 in one minute. A bus can occupy at most B people. * Taxi: travels from City 3 to 4 in one minute. A taxi can occupy at most C people. * Airplane: travels from City 4 to 5 in one minute. An airplane can occupy at most D people. * Ship: travels from City 5 to 6 in one minute. A ship can occupy at most E people. For each of them, one vehicle leaves the city at each integer time (time 0, 1, 2, ...). There is a group of N people at City 1, and they all want to go to City 6. At least how long does it take for all of them to reach there? You can ignore the time needed to transfer.
[{"input": "5\n 3\n 2\n 4\n 3\n 5", "output": "7\n \n\nOne possible way to travel is as follows. First, there are N = 5 people at\nCity 1, as shown in the following image:\n\n![ ](https://img.atcoder.jp/ghi/9c306138eddc8a2e08acfa5da19bdfe8.png)\n\nIn the first minute, three people travels from City 1 to City 2 by train. Note\nthat a train can only occupy at most three people.\n\n![ ](https://img.atcoder.jp/ghi/bd30b5ab37fc06951c9f5256bb974e4f.png)\n\nIn the second minute, the remaining two people travels from City 1 to City 2\nby train, and two of the three people who were already at City 2 travels to\nCity 3 by bus. Note that a bus can only occupy at most two people.\n\n![ ](https://img.atcoder.jp/ghi/50f2e49a770a30193fc53588ec8475b3.png)\n\nIn the third minute, two people travels from City 2 to City 3 by train, and\nanother two people travels from City 3 to City 4 by taxi.\n\n![ ](https://img.atcoder.jp/ghi/d6d80dc50abe58190905c8c5ea6ba345.png)\n\nFrom then on, if they continue traveling without stopping until they reach\nCity 6, all of them can reach there in seven minutes. \nThere is no way for them to reach City 6 in 6 minutes or less.\n\n* * *"}, {"input": "10\n 123\n 123\n 123\n 123\n 123", "output": "5\n \n\nAll kinds of vehicles can occupy N = 10 people at a time. Thus, if they\ncontinue traveling without stopping until they reach City 6, all of them can\nreach there in five minutes.\n\n* * *"}, {"input": "10000000007\n 2\n 3\n 5\n 7\n 11", "output": "5000000008\n \n\nNote that the input or output may not fit into a 32-bit integer type."}]
Print the minimum time required for all of the people to reach City 6, in minutes. * * *
s515226530
Accepted
p03077
Input is given from Standard Input in the following format: N A B C D E
n = [int(input()) for i in range(6)] print(5 + (n[0] - 1) // min(n[1:]))
Statement In 2028 and after a continuous growth, AtCoder Inc. finally built an empire with six cities (City 1, 2, 3, 4, 5, 6)! There are five means of transport in this empire: * Train: travels from City 1 to 2 in one minute. A train can occupy at most A people. * Bus: travels from City 2 to 3 in one minute. A bus can occupy at most B people. * Taxi: travels from City 3 to 4 in one minute. A taxi can occupy at most C people. * Airplane: travels from City 4 to 5 in one minute. An airplane can occupy at most D people. * Ship: travels from City 5 to 6 in one minute. A ship can occupy at most E people. For each of them, one vehicle leaves the city at each integer time (time 0, 1, 2, ...). There is a group of N people at City 1, and they all want to go to City 6. At least how long does it take for all of them to reach there? You can ignore the time needed to transfer.
[{"input": "5\n 3\n 2\n 4\n 3\n 5", "output": "7\n \n\nOne possible way to travel is as follows. First, there are N = 5 people at\nCity 1, as shown in the following image:\n\n![ ](https://img.atcoder.jp/ghi/9c306138eddc8a2e08acfa5da19bdfe8.png)\n\nIn the first minute, three people travels from City 1 to City 2 by train. Note\nthat a train can only occupy at most three people.\n\n![ ](https://img.atcoder.jp/ghi/bd30b5ab37fc06951c9f5256bb974e4f.png)\n\nIn the second minute, the remaining two people travels from City 1 to City 2\nby train, and two of the three people who were already at City 2 travels to\nCity 3 by bus. Note that a bus can only occupy at most two people.\n\n![ ](https://img.atcoder.jp/ghi/50f2e49a770a30193fc53588ec8475b3.png)\n\nIn the third minute, two people travels from City 2 to City 3 by train, and\nanother two people travels from City 3 to City 4 by taxi.\n\n![ ](https://img.atcoder.jp/ghi/d6d80dc50abe58190905c8c5ea6ba345.png)\n\nFrom then on, if they continue traveling without stopping until they reach\nCity 6, all of them can reach there in seven minutes. \nThere is no way for them to reach City 6 in 6 minutes or less.\n\n* * *"}, {"input": "10\n 123\n 123\n 123\n 123\n 123", "output": "5\n \n\nAll kinds of vehicles can occupy N = 10 people at a time. Thus, if they\ncontinue traveling without stopping until they reach City 6, all of them can\nreach there in five minutes.\n\n* * *"}, {"input": "10000000007\n 2\n 3\n 5\n 7\n 11", "output": "5000000008\n \n\nNote that the input or output may not fit into a 32-bit integer type."}]