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 increasing integers that can represent N as their sum. * * *
s453148062
Runtime Error
p03789
The input is given from Standard Input in the following format: N
def count(n): if n < 10: return n else: return count(n // 10) + n % 10 def check(k): return k >= count(9 * n + k) n = int(input()) l = 0 r = 555555 while r - l > 1: mid = (l + r) // 2 if check(mid): r = mid else: l = mid print((r + 8) // 9)
Statement We will call a non-negative integer _increasing_ if, for any two adjacent digits in its decimal representation, the digit to the right is greater than or equal to the digit to the left. For example, 1558, 11, 3 and 0 are all increasing; 10 and 20170312 are not. Snuke has an integer N. Find the minimum number of increasing integers that can represent N as their sum.
[{"input": "80", "output": "2\n \n\nOne possible representation is 80 = 77 + 3.\n\n* * *"}, {"input": "123456789", "output": "1\n \n\n123456789 in itself is increasing, and thus it can be represented as the sum\nof one increasing integer.\n\n* * *"}, {"input": "20170312", "output": "4\n \n\n* * *"}, {"input": "7204647845201772120166980358816078279571541735614841625060678056933503", "output": "31"}]
Print the final state of the grid in the same format as input (without the numbers of rows and columns); see the samples for clarity. * * *
s635163055
Runtime Error
p03273
Input is given from Standard Input in the following format: H W a_{1, 1}...a_{1, W} : a_{H, 1}...a_{H, W}
miss
Statement There is a grid of squares with H horizontal rows and W vertical columns. The square at the i-th row from the top and the j-th column from the left is represented as (i, j). Each square is black or white. The color of the square is given as an H-by-W matrix (a_{i, j}). If a_{i, j} is `.`, the square (i, j) is white; if a_{i, j} is `#`, the square (i, j) is black. Snuke is compressing this grid. He will do so by repeatedly performing the following operation while there is a row or column that consists only of white squares: * Operation: choose any one row or column that consists only of white squares, remove it and delete the space between the rows or columns. It can be shown that the final state of the grid is uniquely determined regardless of what row or column is chosen in each operation. Find the final state of the grid.
[{"input": "4 4\n ##.#\n ....\n ##.#\n .#.#", "output": "###\n ###\n .##\n \n\nThe second row and the third column in the original grid will be removed.\n\n* * *"}, {"input": "3 3\n #..\n .#.\n ..#", "output": "#..\n .#.\n ..#\n \n\nAs there is no row or column that consists only of white squares, no operation\nwill be performed.\n\n* * *"}, {"input": "4 5\n .....\n .....\n ..#..\n .....", "output": "#\n \n\n* * *"}, {"input": "7 6\n ......\n ....#.\n .#....\n ..#...\n ..#...\n ......\n .#..#.", "output": "..#\n #..\n .#.\n .#.\n #.#"}]
Print the final state of the grid in the same format as input (without the numbers of rows and columns); see the samples for clarity. * * *
s409662379
Runtime Error
p03273
Input is given from Standard Input in the following format: H W a_{1, 1}...a_{1, W} : a_{H, 1}...a_{H, W}
H,W = map(int,input().split()) mas = [list(input()) for i in range(H)] new_mas = [row for row in mas if "#" in row:] new_mas2 = [column for column in list(zip(*new_mas)) if "#" in column] for i in list(zip(*new_mas2)): for j in i: print(j,end="") print()
Statement There is a grid of squares with H horizontal rows and W vertical columns. The square at the i-th row from the top and the j-th column from the left is represented as (i, j). Each square is black or white. The color of the square is given as an H-by-W matrix (a_{i, j}). If a_{i, j} is `.`, the square (i, j) is white; if a_{i, j} is `#`, the square (i, j) is black. Snuke is compressing this grid. He will do so by repeatedly performing the following operation while there is a row or column that consists only of white squares: * Operation: choose any one row or column that consists only of white squares, remove it and delete the space between the rows or columns. It can be shown that the final state of the grid is uniquely determined regardless of what row or column is chosen in each operation. Find the final state of the grid.
[{"input": "4 4\n ##.#\n ....\n ##.#\n .#.#", "output": "###\n ###\n .##\n \n\nThe second row and the third column in the original grid will be removed.\n\n* * *"}, {"input": "3 3\n #..\n .#.\n ..#", "output": "#..\n .#.\n ..#\n \n\nAs there is no row or column that consists only of white squares, no operation\nwill be performed.\n\n* * *"}, {"input": "4 5\n .....\n .....\n ..#..\n .....", "output": "#\n \n\n* * *"}, {"input": "7 6\n ......\n ....#.\n .#....\n ..#...\n ..#...\n ......\n .#..#.", "output": "..#\n #..\n .#.\n .#.\n #.#"}]
Print the final state of the grid in the same format as input (without the numbers of rows and columns); see the samples for clarity. * * *
s905409764
Accepted
p03273
Input is given from Standard Input in the following format: H W a_{1, 1}...a_{1, W} : a_{H, 1}...a_{H, W}
from __future__ import print_function # import numpy as np # import numpypy as np import sys input = sys.stdin.readline def eprint(*args, **kwargs): print(*args, file=sys.stderr, **kwargs) return import math import string import fractions from fractions import Fraction from fractions import gcd def lcm(n, m): return int(n * m / gcd(n, m)) import re import array import copy import functools import operator import collections import itertools import bisect import heapq from heapq import heappush from heapq import heappop from heapq import heappushpop from heapq import heapify from heapq import heapreplace from queue import PriorityQueue as pq def reduce(p, q): common = fractions.gcd(p, q) return (p // common, q // common) # from itertools import accumulate # from collections import deque from operator import mul from functools import reduce def combinations_count(n, r): r = min(r, n - r) numer = reduce(mul, range(n, n - r, -1), 1) denom = reduce(mul, range(1, r + 1), 1) return numer // denom import random def main(): h, w = map(int, input().strip().split()) g = [input().strip() for _ in range(h)] gg = [col for col in zip(*g) if ("#" in col)] eprint("gg ", end=": \n") eprint(gg) for elem in gg: eprint(elem) gg = [row for row in zip(*gg) if ("#" in row)] eprint("gg ", end=": \n") eprint(gg) # for elem in gg: # eprint(elem) for S in gg: print("".join(S)) return if __name__ == "__main__": main() # trA = [list(col) for col in zip(*A)]
Statement There is a grid of squares with H horizontal rows and W vertical columns. The square at the i-th row from the top and the j-th column from the left is represented as (i, j). Each square is black or white. The color of the square is given as an H-by-W matrix (a_{i, j}). If a_{i, j} is `.`, the square (i, j) is white; if a_{i, j} is `#`, the square (i, j) is black. Snuke is compressing this grid. He will do so by repeatedly performing the following operation while there is a row or column that consists only of white squares: * Operation: choose any one row or column that consists only of white squares, remove it and delete the space between the rows or columns. It can be shown that the final state of the grid is uniquely determined regardless of what row or column is chosen in each operation. Find the final state of the grid.
[{"input": "4 4\n ##.#\n ....\n ##.#\n .#.#", "output": "###\n ###\n .##\n \n\nThe second row and the third column in the original grid will be removed.\n\n* * *"}, {"input": "3 3\n #..\n .#.\n ..#", "output": "#..\n .#.\n ..#\n \n\nAs there is no row or column that consists only of white squares, no operation\nwill be performed.\n\n* * *"}, {"input": "4 5\n .....\n .....\n ..#..\n .....", "output": "#\n \n\n* * *"}, {"input": "7 6\n ......\n ....#.\n .#....\n ..#...\n ..#...\n ......\n .#..#.", "output": "..#\n #..\n .#.\n .#.\n #.#"}]
Print the final state of the grid in the same format as input (without the numbers of rows and columns); see the samples for clarity. * * *
s528917878
Accepted
p03273
Input is given from Standard Input in the following format: H W a_{1, 1}...a_{1, W} : a_{H, 1}...a_{H, W}
import sys, os, math, bisect, itertools, collections, heapq, queue # from scipy.sparse.csgraph import csgraph_from_dense, floyd_warshall from decimal import Decimal from collections import defaultdict, deque sys.setrecursionlimit(10000000) ii = lambda: int(sys.stdin.buffer.readline().rstrip()) il = lambda: list(map(int, sys.stdin.buffer.readline().split())) fl = lambda: list(map(float, sys.stdin.buffer.readline().split())) iln = lambda n: [int(sys.stdin.buffer.readline().rstrip()) for _ in range(n)] iss = lambda: sys.stdin.buffer.readline().decode().rstrip() sl = lambda: list(map(str, sys.stdin.buffer.readline().decode().split())) isn = lambda n: [sys.stdin.buffer.readline().decode().rstrip() for _ in range(n)] lcm = lambda x, y: (x * y) // math.gcd(x, y) MOD = 10**9 + 7 MAX = float("inf") def main(): if os.getenv("LOCAL"): sys.stdin = open("input.txt", "r") H, W = il() HW = [sl() for _ in range(H)] h = [False] * H w = [False] * W for n in range(H): hw = HW[n] if "#" in hw[0]: h[n] = True for m in range(W): if hw[0][m] == "#": w[m] = True for n in range(H): if h[n]: str = "" for m in range(W): if w[m]: str += HW[n][0][m] print(str) if __name__ == "__main__": main()
Statement There is a grid of squares with H horizontal rows and W vertical columns. The square at the i-th row from the top and the j-th column from the left is represented as (i, j). Each square is black or white. The color of the square is given as an H-by-W matrix (a_{i, j}). If a_{i, j} is `.`, the square (i, j) is white; if a_{i, j} is `#`, the square (i, j) is black. Snuke is compressing this grid. He will do so by repeatedly performing the following operation while there is a row or column that consists only of white squares: * Operation: choose any one row or column that consists only of white squares, remove it and delete the space between the rows or columns. It can be shown that the final state of the grid is uniquely determined regardless of what row or column is chosen in each operation. Find the final state of the grid.
[{"input": "4 4\n ##.#\n ....\n ##.#\n .#.#", "output": "###\n ###\n .##\n \n\nThe second row and the third column in the original grid will be removed.\n\n* * *"}, {"input": "3 3\n #..\n .#.\n ..#", "output": "#..\n .#.\n ..#\n \n\nAs there is no row or column that consists only of white squares, no operation\nwill be performed.\n\n* * *"}, {"input": "4 5\n .....\n .....\n ..#..\n .....", "output": "#\n \n\n* * *"}, {"input": "7 6\n ......\n ....#.\n .#....\n ..#...\n ..#...\n ......\n .#..#.", "output": "..#\n #..\n .#.\n .#.\n #.#"}]
Print the final state of the grid in the same format as input (without the numbers of rows and columns); see the samples for clarity. * * *
s846183349
Accepted
p03273
Input is given from Standard Input in the following format: H W a_{1, 1}...a_{1, W} : a_{H, 1}...a_{H, W}
import sys import math import itertools import bisect from copy import copy from collections import deque, Counter from decimal import Decimal def s(): return input() def k(): return int(input()) def S(): return input().split() def I(): return map(int, input().split()) def X(): return list(input()) def L(): return list(input().split()) def l(): return list(map(int, input().split())) def lcm(a, b): return a * b // math.gcd(a, b) sys.setrecursionlimit(10**9) mod = 10**9 + 7 count = 0 ans = 0 inf = float("inf") h, w = I() board = [X() for _ in range(h)] num = [] nn = [] for i in range(h): if "#" not in board[i]: num.append(i) for i in num: a = i - count del board[a] count += 1 for i in range(w): nn.append(i) for j in range(len(board)): if board[j][i] == "#": nn.remove(i) break for i in range(len(board)): cnt = 0 for j in nn: b = j - cnt del board[i][b] cnt += 1 for i in range(len(board)): print("".join(board[i]))
Statement There is a grid of squares with H horizontal rows and W vertical columns. The square at the i-th row from the top and the j-th column from the left is represented as (i, j). Each square is black or white. The color of the square is given as an H-by-W matrix (a_{i, j}). If a_{i, j} is `.`, the square (i, j) is white; if a_{i, j} is `#`, the square (i, j) is black. Snuke is compressing this grid. He will do so by repeatedly performing the following operation while there is a row or column that consists only of white squares: * Operation: choose any one row or column that consists only of white squares, remove it and delete the space between the rows or columns. It can be shown that the final state of the grid is uniquely determined regardless of what row or column is chosen in each operation. Find the final state of the grid.
[{"input": "4 4\n ##.#\n ....\n ##.#\n .#.#", "output": "###\n ###\n .##\n \n\nThe second row and the third column in the original grid will be removed.\n\n* * *"}, {"input": "3 3\n #..\n .#.\n ..#", "output": "#..\n .#.\n ..#\n \n\nAs there is no row or column that consists only of white squares, no operation\nwill be performed.\n\n* * *"}, {"input": "4 5\n .....\n .....\n ..#..\n .....", "output": "#\n \n\n* * *"}, {"input": "7 6\n ......\n ....#.\n .#....\n ..#...\n ..#...\n ......\n .#..#.", "output": "..#\n #..\n .#.\n .#.\n #.#"}]
Print the final state of the grid in the same format as input (without the numbers of rows and columns); see the samples for clarity. * * *
s609087448
Runtime Error
p03273
Input is given from Standard Input in the following format: H W a_{1, 1}...a_{1, W} : a_{H, 1}...a_{H, W}
H, W = map(int, input().split()) grid = [list(str(input())) for _ in range(H)] def elim(grid): grid_after = [] for i in range(H): gset = list(set(grid[i])) # print(gset) # print(grid[i]) if gset[0] != ".": grid_after.append(grid[i]) return grid_after def transpose(grid_after): H1 = len(grid_after) W1 = len(grid_after[0][:]) gridT = [[""] * H1 for _ in range(W1)] for i in range(W1): for j in range(H1): gridT[i][j] = grid_after[j][i] return gridT grid_after = elim(grid) gridT1 = transpose(grid_after) # print(gridT1) grid_after2 = elim(gridT1) # print(grid_after2) gridT2 = transpose(grid_after2) # print(gridT2) for i in gridT2: print(*i, sep="")
Statement There is a grid of squares with H horizontal rows and W vertical columns. The square at the i-th row from the top and the j-th column from the left is represented as (i, j). Each square is black or white. The color of the square is given as an H-by-W matrix (a_{i, j}). If a_{i, j} is `.`, the square (i, j) is white; if a_{i, j} is `#`, the square (i, j) is black. Snuke is compressing this grid. He will do so by repeatedly performing the following operation while there is a row or column that consists only of white squares: * Operation: choose any one row or column that consists only of white squares, remove it and delete the space between the rows or columns. It can be shown that the final state of the grid is uniquely determined regardless of what row or column is chosen in each operation. Find the final state of the grid.
[{"input": "4 4\n ##.#\n ....\n ##.#\n .#.#", "output": "###\n ###\n .##\n \n\nThe second row and the third column in the original grid will be removed.\n\n* * *"}, {"input": "3 3\n #..\n .#.\n ..#", "output": "#..\n .#.\n ..#\n \n\nAs there is no row or column that consists only of white squares, no operation\nwill be performed.\n\n* * *"}, {"input": "4 5\n .....\n .....\n ..#..\n .....", "output": "#\n \n\n* * *"}, {"input": "7 6\n ......\n ....#.\n .#....\n ..#...\n ..#...\n ......\n .#..#.", "output": "..#\n #..\n .#.\n .#.\n #.#"}]
Print the final state of the grid in the same format as input (without the numbers of rows and columns); see the samples for clarity. * * *
s991747113
Accepted
p03273
Input is given from Standard Input in the following format: H W a_{1, 1}...a_{1, W} : a_{H, 1}...a_{H, W}
H, W = map(int, input().split()) grid = [input() for _ in range(H)] Hs = set() Ws = set() for h in range(H): for w in range(W): if grid[h][w] == "#": Hs.add(h) Ws.add(w) Hs = sorted(list(Hs)) Ws = sorted(list(Ws)) for h in Hs: for w in Ws: print(grid[h][w], end="") print()
Statement There is a grid of squares with H horizontal rows and W vertical columns. The square at the i-th row from the top and the j-th column from the left is represented as (i, j). Each square is black or white. The color of the square is given as an H-by-W matrix (a_{i, j}). If a_{i, j} is `.`, the square (i, j) is white; if a_{i, j} is `#`, the square (i, j) is black. Snuke is compressing this grid. He will do so by repeatedly performing the following operation while there is a row or column that consists only of white squares: * Operation: choose any one row or column that consists only of white squares, remove it and delete the space between the rows or columns. It can be shown that the final state of the grid is uniquely determined regardless of what row or column is chosen in each operation. Find the final state of the grid.
[{"input": "4 4\n ##.#\n ....\n ##.#\n .#.#", "output": "###\n ###\n .##\n \n\nThe second row and the third column in the original grid will be removed.\n\n* * *"}, {"input": "3 3\n #..\n .#.\n ..#", "output": "#..\n .#.\n ..#\n \n\nAs there is no row or column that consists only of white squares, no operation\nwill be performed.\n\n* * *"}, {"input": "4 5\n .....\n .....\n ..#..\n .....", "output": "#\n \n\n* * *"}, {"input": "7 6\n ......\n ....#.\n .#....\n ..#...\n ..#...\n ......\n .#..#.", "output": "..#\n #..\n .#.\n .#.\n #.#"}]
Print the final state of the grid in the same format as input (without the numbers of rows and columns); see the samples for clarity. * * *
s448021857
Accepted
p03273
Input is given from Standard Input in the following format: H W a_{1, 1}...a_{1, W} : a_{H, 1}...a_{H, W}
h, w, *a = open(0).read().split() for _ in range(2): a = [list(j) for j in zip(*[i for i in a if "#" in i])] print(*["".join(i) for i in a], sep="\n")
Statement There is a grid of squares with H horizontal rows and W vertical columns. The square at the i-th row from the top and the j-th column from the left is represented as (i, j). Each square is black or white. The color of the square is given as an H-by-W matrix (a_{i, j}). If a_{i, j} is `.`, the square (i, j) is white; if a_{i, j} is `#`, the square (i, j) is black. Snuke is compressing this grid. He will do so by repeatedly performing the following operation while there is a row or column that consists only of white squares: * Operation: choose any one row or column that consists only of white squares, remove it and delete the space between the rows or columns. It can be shown that the final state of the grid is uniquely determined regardless of what row or column is chosen in each operation. Find the final state of the grid.
[{"input": "4 4\n ##.#\n ....\n ##.#\n .#.#", "output": "###\n ###\n .##\n \n\nThe second row and the third column in the original grid will be removed.\n\n* * *"}, {"input": "3 3\n #..\n .#.\n ..#", "output": "#..\n .#.\n ..#\n \n\nAs there is no row or column that consists only of white squares, no operation\nwill be performed.\n\n* * *"}, {"input": "4 5\n .....\n .....\n ..#..\n .....", "output": "#\n \n\n* * *"}, {"input": "7 6\n ......\n ....#.\n .#....\n ..#...\n ..#...\n ......\n .#..#.", "output": "..#\n #..\n .#.\n .#.\n #.#"}]
Print the final state of the grid in the same format as input (without the numbers of rows and columns); see the samples for clarity. * * *
s680992121
Accepted
p03273
Input is given from Standard Input in the following format: H W a_{1, 1}...a_{1, W} : a_{H, 1}...a_{H, W}
H, W = map(int, input().split()) a = [None] * H b = [[1 for j in range(W)] for i in range(H)] delete = 1 for i in range(0, H): a[i] = input() for i in range(0, H): for j in range(0, W): if a[i][j] != ".": delete = 0 break if delete == 1: for j in range(0, W): b[i][j] = 0 else: delete = 1 for j in range(0, W): for i in range(0, H): if a[i][j] != ".": delete = 0 break if delete == 1: for i in range(0, H): b[i][j] = 0 else: delete = 1 new_line = 0 for i in range(0, H): for j in range(0, W): if b[i][j] == 1: print(a[i][j], end="") new_line = 1 if new_line == 1: print(" ") new_line = 0
Statement There is a grid of squares with H horizontal rows and W vertical columns. The square at the i-th row from the top and the j-th column from the left is represented as (i, j). Each square is black or white. The color of the square is given as an H-by-W matrix (a_{i, j}). If a_{i, j} is `.`, the square (i, j) is white; if a_{i, j} is `#`, the square (i, j) is black. Snuke is compressing this grid. He will do so by repeatedly performing the following operation while there is a row or column that consists only of white squares: * Operation: choose any one row or column that consists only of white squares, remove it and delete the space between the rows or columns. It can be shown that the final state of the grid is uniquely determined regardless of what row or column is chosen in each operation. Find the final state of the grid.
[{"input": "4 4\n ##.#\n ....\n ##.#\n .#.#", "output": "###\n ###\n .##\n \n\nThe second row and the third column in the original grid will be removed.\n\n* * *"}, {"input": "3 3\n #..\n .#.\n ..#", "output": "#..\n .#.\n ..#\n \n\nAs there is no row or column that consists only of white squares, no operation\nwill be performed.\n\n* * *"}, {"input": "4 5\n .....\n .....\n ..#..\n .....", "output": "#\n \n\n* * *"}, {"input": "7 6\n ......\n ....#.\n .#....\n ..#...\n ..#...\n ......\n .#..#.", "output": "..#\n #..\n .#.\n .#.\n #.#"}]
Print the final state of the grid in the same format as input (without the numbers of rows and columns); see the samples for clarity. * * *
s349998219
Wrong Answer
p03273
Input is given from Standard Input in the following format: H W a_{1, 1}...a_{1, W} : a_{H, 1}...a_{H, W}
i, j = map(int, input().split()) iCnt = 0 input_line = [] for iCnt in range(i): line = input() input_line.append(list(line)) for iCnt in reversed(range(i)): flg_white = True for jCnt in range(j): if input_line[iCnt][jCnt] != ".": flg_white = False if flg_white == True: del input_line[iCnt] for line in input_line: for dot in line: print(dot, end="") print()
Statement There is a grid of squares with H horizontal rows and W vertical columns. The square at the i-th row from the top and the j-th column from the left is represented as (i, j). Each square is black or white. The color of the square is given as an H-by-W matrix (a_{i, j}). If a_{i, j} is `.`, the square (i, j) is white; if a_{i, j} is `#`, the square (i, j) is black. Snuke is compressing this grid. He will do so by repeatedly performing the following operation while there is a row or column that consists only of white squares: * Operation: choose any one row or column that consists only of white squares, remove it and delete the space between the rows or columns. It can be shown that the final state of the grid is uniquely determined regardless of what row or column is chosen in each operation. Find the final state of the grid.
[{"input": "4 4\n ##.#\n ....\n ##.#\n .#.#", "output": "###\n ###\n .##\n \n\nThe second row and the third column in the original grid will be removed.\n\n* * *"}, {"input": "3 3\n #..\n .#.\n ..#", "output": "#..\n .#.\n ..#\n \n\nAs there is no row or column that consists only of white squares, no operation\nwill be performed.\n\n* * *"}, {"input": "4 5\n .....\n .....\n ..#..\n .....", "output": "#\n \n\n* * *"}, {"input": "7 6\n ......\n ....#.\n .#....\n ..#...\n ..#...\n ......\n .#..#.", "output": "..#\n #..\n .#.\n .#.\n #.#"}]
Print the final state of the grid in the same format as input (without the numbers of rows and columns); see the samples for clarity. * * *
s020069444
Accepted
p03273
Input is given from Standard Input in the following format: H W a_{1, 1}...a_{1, W} : a_{H, 1}...a_{H, W}
height, width = (int(x) for x in input().split()) matrix = [] for i in range(height): matrix.append(input()) row = [0] * width column = [0] * height for i in range(height): if "#" in matrix[i]: column[i] = 1 for j in range(width): if matrix[i][j] == "#": row[j] = 1 for i in range(height): if column[i] == 1: for j in range(width): if row[j] == 1: print(matrix[i][j], end="") print()
Statement There is a grid of squares with H horizontal rows and W vertical columns. The square at the i-th row from the top and the j-th column from the left is represented as (i, j). Each square is black or white. The color of the square is given as an H-by-W matrix (a_{i, j}). If a_{i, j} is `.`, the square (i, j) is white; if a_{i, j} is `#`, the square (i, j) is black. Snuke is compressing this grid. He will do so by repeatedly performing the following operation while there is a row or column that consists only of white squares: * Operation: choose any one row or column that consists only of white squares, remove it and delete the space between the rows or columns. It can be shown that the final state of the grid is uniquely determined regardless of what row or column is chosen in each operation. Find the final state of the grid.
[{"input": "4 4\n ##.#\n ....\n ##.#\n .#.#", "output": "###\n ###\n .##\n \n\nThe second row and the third column in the original grid will be removed.\n\n* * *"}, {"input": "3 3\n #..\n .#.\n ..#", "output": "#..\n .#.\n ..#\n \n\nAs there is no row or column that consists only of white squares, no operation\nwill be performed.\n\n* * *"}, {"input": "4 5\n .....\n .....\n ..#..\n .....", "output": "#\n \n\n* * *"}, {"input": "7 6\n ......\n ....#.\n .#....\n ..#...\n ..#...\n ......\n .#..#.", "output": "..#\n #..\n .#.\n .#.\n #.#"}]
Print the final state of the grid in the same format as input (without the numbers of rows and columns); see the samples for clarity. * * *
s163791819
Accepted
p03273
Input is given from Standard Input in the following format: H W a_{1, 1}...a_{1, W} : a_{H, 1}...a_{H, W}
# abc107_b.py # https://atcoder.jp/contests/abc107/tasks/abc107_b # B - Grid Compression / # ๅฎŸ่กŒๆ™‚้–“ๅˆถ้™: 2 sec / ใƒกใƒขใƒชๅˆถ้™: 1024 MB # ้…็‚น : 200็‚น # ๅ•้กŒๆ–‡ # ็ธฆ H่กŒใ€ๆจช W ๅˆ—ใฎใƒžใ‚น็›ฎใŒใ‚ใ‚Šใพใ™ใ€‚ ไธŠใ‹ใ‚‰ i ่กŒ็›ฎใ€ๅทฆใ‹ใ‚‰ j ๅˆ—็›ฎใฎใƒžใ‚นใ‚’ (i,j) ใจ่กจใ—ใพใ™ใ€‚ # ๅ„ใƒžใ‚นใฏ็™ฝใพใŸใฏ้ป’ใงใ™ใ€‚ ใƒžใ‚น็›ฎใฎ้…่‰ฒใฏใ€H ่กŒ W ๅˆ—ใฎ่กŒๅˆ— (ai,j) ใซใ‚ˆใฃใฆไธŽใˆใ‚‰ใ‚Œใพใ™ใ€‚ # ai,j ใŒ . ใชใ‚‰ใฐใƒžใ‚น (i,j) ใฏ็™ฝใงใ‚ใ‚Šใ€ai,j ใŒ # ใชใ‚‰ใฐใƒžใ‚น (i,j)ใฏ้ป’ใงใ™ใ€‚ # ใ™ใฌใ‘ๅ›ใฏใ“ใฎใƒžใ‚น็›ฎใ‚’ๅœง็ธฎใ—ใ‚ˆใ†ใจใ—ใฆใ„ใพใ™ใ€‚ ใใฎใŸใ‚ใซใ€็™ฝใ„ใƒžใ‚นใฎใฟใ‹ใ‚‰ใชใ‚‹่กŒใพใŸใฏๅˆ—ใŒๅญ˜ๅœจใ™ใ‚‹้–“ใ€ๆฌกใฎๆ“ไฝœใ‚’็นฐใ‚Š่ฟ”ใ—่กŒใ„ใพใ™ใ€‚ # ๆ“ไฝœ: ็™ฝใ„ใƒžใ‚นใฎใฟใ‹ใ‚‰ใชใ‚‹่กŒใพใŸใฏๅˆ—ใ‚’ใฒใจใคไปปๆ„ใซ้ธใณใ€ใใฎ่กŒใพใŸใฏๅˆ—ใ‚’ๅ–ใ‚Š้™คใ„ใฆ็ฉบ็™ฝใ‚’่ฉฐใ‚ใ‚‹ใ€‚ # ๅ„ๆ“ไฝœใงใฉใฎ่กŒใพใŸใฏๅˆ—ใ‚’้ธใถใ‹ใซใ‚ˆใ‚‰ใšใ€ๆœ€็ต‚็š„ใชใƒžใ‚น็›ฎใฏไธ€ๆ„ใซๅฎšใพใ‚‹ใ“ใจใŒ็คบใ›ใพใ™ใ€‚ ๆœ€็ต‚็š„ใชใƒžใ‚น็›ฎใ‚’ๆฑ‚ใ‚ใฆใใ ใ•ใ„ใ€‚ # ๅˆถ็ด„ # 1โ‰คH,Wโ‰ค100 # ai,jใฏ . ใพใŸใฏ # ใงใ‚ใ‚‹ใ€‚ # ใƒžใ‚น็›ฎๅ…จไฝ“ใงๅฐ‘ใชใใจใ‚‚ใฒใจใคใฏ้ป’ใ„ใƒžใ‚นใŒๅญ˜ๅœจใ™ใ‚‹ใ€‚ # ๅ…ฅๅŠ› # ๅ…ฅๅŠ›ใฏไปฅไธ‹ใฎๅฝขๅผใงๆจ™ๆบ–ๅ…ฅๅŠ›ใ‹ใ‚‰ไธŽใˆใ‚‰ใ‚Œใ‚‹ใ€‚ # H W # a1,1...a1,W # : # aH,1...aH,W # ๅ‡บๅŠ› # ๆœ€็ต‚็š„ใชใƒžใ‚น็›ฎใ‚’ใ€ๅ…ฅๅŠ›ใจๅŒๆง˜ใฎใƒ•ใ‚ฉใƒผใƒžใƒƒใƒˆใงๅ‡บๅŠ›ใ›ใ‚ˆใ€‚ ใŸใ ใ—ใ€่กŒๆ•ฐใŠใ‚ˆใณๅˆ—ๆ•ฐใฏ็œใใ“ใจใ€‚ ่ฉณใ—ใใฏใ‚ตใƒณใƒ—ใƒซใ‚’ๅ‚็…งใ›ใ‚ˆใ€‚ # ๅ…ฅๅŠ›ไพ‹ 1 # 4 4 # ##.# # .... # ##.# # .#.# # ๅ‡บๅŠ›ไพ‹ 1 # ### # ### # .## # ๅ…ƒใฎใƒžใ‚น็›ฎใซใŠใ‘ใ‚‹็ฌฌ 2่กŒใŠใ‚ˆใณ็ฌฌ 3ๅˆ—ใŒใใ‚Œใžใ‚Œๅ–ใ‚Š้™คใ‹ใ‚Œใพใ™ใ€‚ # ๅ…ฅๅŠ›ไพ‹ 2 # 3 3 # #.. # .#. # ..# # ๅ‡บๅŠ›ไพ‹ 2 # #.. # .#. # ..# # ็™ฝใ„ใƒžใ‚นใฎใฟใ‹ใ‚‰ใชใ‚‹่กŒใพใŸใฏๅˆ—ใŒๅญ˜ๅœจใ—ใชใ„ใฎใงใ€ๆ“ไฝœใฏ่กŒใ‚ใ‚Œใพใ›ใ‚“ใ€‚ # ๅ…ฅๅŠ›ไพ‹ 3 # 4 5 # ..... # ..... # ..#.. # ..... # ๅ‡บๅŠ›ไพ‹ 3 # # # ๅ…ฅๅŠ›ไพ‹ 4 # 7 6 # ...... # ....#. # .#.... # ..#... # ..#... # ...... # .#..#. # ๅ‡บๅŠ›ไพ‹ 4 # ..# # #.. # .#. # .#. # #.# def calculation(lines): N, W = list(map(int, lines[0].split())) masus = list() for i in range(N): line = lines[i + 1] if line != "." * W: masus.append(line) for w in range(W): flag = True for masu in masus: if masu[w] == "#": flag = False if flag: for i in range(len(masus)): masus[i] = masus[i][:w] + " " + masus[i][w + 1 :] for i in range(len(masus)): masus[i] = masus[i].replace(" ", "") return masus # ๅผ•ๆ•ฐใ‚’ๅ–ๅพ— def get_input_lines(): line = input() H, W = list(map(int, line.split())) lines = list() lines.append(line) for _ in range(H): lines.append(input()) return lines # ใƒ†ใ‚นใƒˆใƒ‡ใƒผใ‚ฟ def get_testdata(pattern): if pattern == 1: lines_input = ["4 4", "##.#", "....", "##.#", ".#.#"] lines_export = ["###", "###", ".##"] if pattern == 2: lines_input = ["3 3", "#..", ".#.", "..#"] lines_export = ["#..", ".#.", "..#"] if pattern == 3: lines_input = ["4 5", ".....", ".....", "..#..", "....."] lines_export = ["#"] if pattern == 4: lines_input = [ "7 6", "......", "....#.", ".#....", "..#...", "..#...", "......", ".#..#.", ] lines_export = ["..#", "#..", ".#.", ".#.", "#.#"] return lines_input, lines_export # ๅ‹•ไฝœใƒขใƒผใƒ‰ๅˆคๅˆฅ def get_mode(): import sys args = sys.argv if len(args) == 1: mode = 0 else: mode = int(args[1]) return mode # ไธปๅ‡ฆ็† def main(): mode = get_mode() if mode == 0: lines_input = get_input_lines() else: lines_input, lines_export = get_testdata(mode) lines_result = calculation(lines_input) for line_result in lines_result: print(line_result) # if mode > 0: # print(f'lines_input=[{lines_input}]') # print(f'lines_export=[{lines_export}]') # print(f'lines_result=[{lines_result}]') # if lines_result == lines_export: # print('OK') # else: # print('NG') # ่ตทๅ‹•ๅ‡ฆ็† if __name__ == "__main__": main()
Statement There is a grid of squares with H horizontal rows and W vertical columns. The square at the i-th row from the top and the j-th column from the left is represented as (i, j). Each square is black or white. The color of the square is given as an H-by-W matrix (a_{i, j}). If a_{i, j} is `.`, the square (i, j) is white; if a_{i, j} is `#`, the square (i, j) is black. Snuke is compressing this grid. He will do so by repeatedly performing the following operation while there is a row or column that consists only of white squares: * Operation: choose any one row or column that consists only of white squares, remove it and delete the space between the rows or columns. It can be shown that the final state of the grid is uniquely determined regardless of what row or column is chosen in each operation. Find the final state of the grid.
[{"input": "4 4\n ##.#\n ....\n ##.#\n .#.#", "output": "###\n ###\n .##\n \n\nThe second row and the third column in the original grid will be removed.\n\n* * *"}, {"input": "3 3\n #..\n .#.\n ..#", "output": "#..\n .#.\n ..#\n \n\nAs there is no row or column that consists only of white squares, no operation\nwill be performed.\n\n* * *"}, {"input": "4 5\n .....\n .....\n ..#..\n .....", "output": "#\n \n\n* * *"}, {"input": "7 6\n ......\n ....#.\n .#....\n ..#...\n ..#...\n ......\n .#..#.", "output": "..#\n #..\n .#.\n .#.\n #.#"}]
Print the final state of the grid in the same format as input (without the numbers of rows and columns); see the samples for clarity. * * *
s189631681
Runtime Error
p03273
Input is given from Standard Input in the following format: H W a_{1, 1}...a_{1, W} : a_{H, 1}...a_{H, W}
h, w = (int(i) for i in input().split()) list_a = [input() for s in range(0, w)] list_tmp = [] for i in range(0, w): for j in range(0, h): if list_a[i][j] == "#": list_tmp.append(list(list_a[i])) break # ่ปข็ฝฎ... https://note.nkmk.me/python-list-transpose/ใ€€ๅ‚็…ง list_tmp_t = [list(x) for x in zip(*list_tmp)] list_tmp2 = [] for i in range(0, h): for j in range(0, len(list_tmp_t[i])): if list_tmp_t[i][j] == "#": list_tmp2.append(list(list_tmp_t[i])) break # ่ปข็ฝฎ... https://note.nkmk.me/python-list-transpose/ใ€€ๅ‚็…ง list_ans = [list(x) for x in zip(*list_tmp2)] for i in range(0, len(list_ans)): print("".join(list_ans[i]))
Statement There is a grid of squares with H horizontal rows and W vertical columns. The square at the i-th row from the top and the j-th column from the left is represented as (i, j). Each square is black or white. The color of the square is given as an H-by-W matrix (a_{i, j}). If a_{i, j} is `.`, the square (i, j) is white; if a_{i, j} is `#`, the square (i, j) is black. Snuke is compressing this grid. He will do so by repeatedly performing the following operation while there is a row or column that consists only of white squares: * Operation: choose any one row or column that consists only of white squares, remove it and delete the space between the rows or columns. It can be shown that the final state of the grid is uniquely determined regardless of what row or column is chosen in each operation. Find the final state of the grid.
[{"input": "4 4\n ##.#\n ....\n ##.#\n .#.#", "output": "###\n ###\n .##\n \n\nThe second row and the third column in the original grid will be removed.\n\n* * *"}, {"input": "3 3\n #..\n .#.\n ..#", "output": "#..\n .#.\n ..#\n \n\nAs there is no row or column that consists only of white squares, no operation\nwill be performed.\n\n* * *"}, {"input": "4 5\n .....\n .....\n ..#..\n .....", "output": "#\n \n\n* * *"}, {"input": "7 6\n ......\n ....#.\n .#....\n ..#...\n ..#...\n ......\n .#..#.", "output": "..#\n #..\n .#.\n .#.\n #.#"}]
Print the final state of the grid in the same format as input (without the numbers of rows and columns); see the samples for clarity. * * *
s640347836
Runtime Error
p03273
Input is given from Standard Input in the following format: H W a_{1, 1}...a_{1, W} : a_{H, 1}...a_{H, W}
#ใ‚ใ‹ใ‚‰ใชใ„ใฎใงใ‚ฎใƒ–ใ‚ขใƒƒใƒ—ใ‚ณใƒ”ใƒš h,w=map(int,input().split()) a=[] #ๅ…ฅๅŠ›ใƒ‡ใƒผใ‚ฟใฎใƒชใ‚นใƒˆๅŒ– for i in range(h): x=input().split() a.append(x) h1=[] for i in range(H): if a[i]==['.']*w h1.append(i) w1=[] for i in range(w): flag=0 for j in range(h): if a[j][i]=='#': flag=1 break if flag==0: w.append(i) ans=[] for i in range(h): if i not in h1: r=[] for j in range(w): r.append(a[i][j]) ans.append(r) for i in range(lens(ans)): print(''.join(ans[i]))
Statement There is a grid of squares with H horizontal rows and W vertical columns. The square at the i-th row from the top and the j-th column from the left is represented as (i, j). Each square is black or white. The color of the square is given as an H-by-W matrix (a_{i, j}). If a_{i, j} is `.`, the square (i, j) is white; if a_{i, j} is `#`, the square (i, j) is black. Snuke is compressing this grid. He will do so by repeatedly performing the following operation while there is a row or column that consists only of white squares: * Operation: choose any one row or column that consists only of white squares, remove it and delete the space between the rows or columns. It can be shown that the final state of the grid is uniquely determined regardless of what row or column is chosen in each operation. Find the final state of the grid.
[{"input": "4 4\n ##.#\n ....\n ##.#\n .#.#", "output": "###\n ###\n .##\n \n\nThe second row and the third column in the original grid will be removed.\n\n* * *"}, {"input": "3 3\n #..\n .#.\n ..#", "output": "#..\n .#.\n ..#\n \n\nAs there is no row or column that consists only of white squares, no operation\nwill be performed.\n\n* * *"}, {"input": "4 5\n .....\n .....\n ..#..\n .....", "output": "#\n \n\n* * *"}, {"input": "7 6\n ......\n ....#.\n .#....\n ..#...\n ..#...\n ......\n .#..#.", "output": "..#\n #..\n .#.\n .#.\n #.#"}]
Print the final state of the grid in the same format as input (without the numbers of rows and columns); see the samples for clarity. * * *
s060889306
Runtime Error
p03273
Input is given from Standard Input in the following format: H W a_{1, 1}...a_{1, W} : a_{H, 1}...a_{H, W}
h, w = map(int, input().split()) l = [] ll = [[True for i in range(w)] for j in range(h)] for _ in range(h): s = input() cells = list(s) # print(cells) l.append(cells) # print(l) for h_i in range(h): flag = True for w_i in range(w): # print(l[h_i][w_i]) if l[h_i][w_i] == "#": flag = False break if flag: for w_i in range(w): ll[h_i][w_i] = False for w_i in range(w): flag = True for h_i in range(h): # print(l[h_i][w_i]) if l[h_i][w_i] == "#": flag = False break if flag: for h_i in range(h): ll[h_i][w_i] = False # print(ll) for i in range(h): lll = []a for j in range(w): # print(l[i][j]) if ll[i][j]: lll.append(l[i][j]) if len(lll) > 0: print(''.join(lll))
Statement There is a grid of squares with H horizontal rows and W vertical columns. The square at the i-th row from the top and the j-th column from the left is represented as (i, j). Each square is black or white. The color of the square is given as an H-by-W matrix (a_{i, j}). If a_{i, j} is `.`, the square (i, j) is white; if a_{i, j} is `#`, the square (i, j) is black. Snuke is compressing this grid. He will do so by repeatedly performing the following operation while there is a row or column that consists only of white squares: * Operation: choose any one row or column that consists only of white squares, remove it and delete the space between the rows or columns. It can be shown that the final state of the grid is uniquely determined regardless of what row or column is chosen in each operation. Find the final state of the grid.
[{"input": "4 4\n ##.#\n ....\n ##.#\n .#.#", "output": "###\n ###\n .##\n \n\nThe second row and the third column in the original grid will be removed.\n\n* * *"}, {"input": "3 3\n #..\n .#.\n ..#", "output": "#..\n .#.\n ..#\n \n\nAs there is no row or column that consists only of white squares, no operation\nwill be performed.\n\n* * *"}, {"input": "4 5\n .....\n .....\n ..#..\n .....", "output": "#\n \n\n* * *"}, {"input": "7 6\n ......\n ....#.\n .#....\n ..#...\n ..#...\n ......\n .#..#.", "output": "..#\n #..\n .#.\n .#.\n #.#"}]
Print the final state of the grid in the same format as input (without the numbers of rows and columns); see the samples for clarity. * * *
s754551556
Runtime Error
p03273
Input is given from Standard Input in the following format: H W a_{1, 1}...a_{1, W} : a_{H, 1}...a_{H, W}
h, w = map(int, input().split()) l = [] ll = [[True for i in range(w)] for j in range(h)] for _ in range(h): s = input() cells = list(s) # print(cells) l.append(cells) # print(l) for h_i in range(h): flag = True for w_i in range(w): # print(l[h_i][w_i]) if l[h_i][w_i] == "#": flag = False break if flag: for w_i in range(w): ll[h_i][w_i] = False for w_i in range(w): flag = True for h_i in range(h): # print(l[h_i][w_i]) if l[h_i][w_i] == "#": flag = False break if flag: for h_i in range(h): ll[h_i][w_i] = False # print(ll) for i in range(h): lll = []a for j in range(w): # print(l[i][j]) if ll[i][j]: lll.append(l[i][j]) if len(lll) > 0: print(''.join(lll))
Statement There is a grid of squares with H horizontal rows and W vertical columns. The square at the i-th row from the top and the j-th column from the left is represented as (i, j). Each square is black or white. The color of the square is given as an H-by-W matrix (a_{i, j}). If a_{i, j} is `.`, the square (i, j) is white; if a_{i, j} is `#`, the square (i, j) is black. Snuke is compressing this grid. He will do so by repeatedly performing the following operation while there is a row or column that consists only of white squares: * Operation: choose any one row or column that consists only of white squares, remove it and delete the space between the rows or columns. It can be shown that the final state of the grid is uniquely determined regardless of what row or column is chosen in each operation. Find the final state of the grid.
[{"input": "4 4\n ##.#\n ....\n ##.#\n .#.#", "output": "###\n ###\n .##\n \n\nThe second row and the third column in the original grid will be removed.\n\n* * *"}, {"input": "3 3\n #..\n .#.\n ..#", "output": "#..\n .#.\n ..#\n \n\nAs there is no row or column that consists only of white squares, no operation\nwill be performed.\n\n* * *"}, {"input": "4 5\n .....\n .....\n ..#..\n .....", "output": "#\n \n\n* * *"}, {"input": "7 6\n ......\n ....#.\n .#....\n ..#...\n ..#...\n ......\n .#..#.", "output": "..#\n #..\n .#.\n .#.\n #.#"}]
Print the final state of the grid in the same format as input (without the numbers of rows and columns); see the samples for clarity. * * *
s127211531
Accepted
p03273
Input is given from Standard Input in the following format: H W a_{1, 1}...a_{1, W} : a_{H, 1}...a_{H, W}
a, b = map(int, input().split()) e = [] f = [True] * b for i in range(a): c = list(input()) d = True for j in range(b): if c[j] == "#" and d: d = not d if c[j] == "#" and f[j]: f[j] = not f[j] if not d: e.append(c) for i in range(len(e)): g = "" for j in range(b): if not f[j]: g += e[i][j] print(g)
Statement There is a grid of squares with H horizontal rows and W vertical columns. The square at the i-th row from the top and the j-th column from the left is represented as (i, j). Each square is black or white. The color of the square is given as an H-by-W matrix (a_{i, j}). If a_{i, j} is `.`, the square (i, j) is white; if a_{i, j} is `#`, the square (i, j) is black. Snuke is compressing this grid. He will do so by repeatedly performing the following operation while there is a row or column that consists only of white squares: * Operation: choose any one row or column that consists only of white squares, remove it and delete the space between the rows or columns. It can be shown that the final state of the grid is uniquely determined regardless of what row or column is chosen in each operation. Find the final state of the grid.
[{"input": "4 4\n ##.#\n ....\n ##.#\n .#.#", "output": "###\n ###\n .##\n \n\nThe second row and the third column in the original grid will be removed.\n\n* * *"}, {"input": "3 3\n #..\n .#.\n ..#", "output": "#..\n .#.\n ..#\n \n\nAs there is no row or column that consists only of white squares, no operation\nwill be performed.\n\n* * *"}, {"input": "4 5\n .....\n .....\n ..#..\n .....", "output": "#\n \n\n* * *"}, {"input": "7 6\n ......\n ....#.\n .#....\n ..#...\n ..#...\n ......\n .#..#.", "output": "..#\n #..\n .#.\n .#.\n #.#"}]
Print the final state of the grid in the same format as input (without the numbers of rows and columns); see the samples for clarity. * * *
s395872638
Accepted
p03273
Input is given from Standard Input in the following format: H W a_{1, 1}...a_{1, W} : a_{H, 1}...a_{H, W}
f = lambda s: zip(*[t for t in s if "#" in t]) for r in f(f(open(0).readlines())): print(*r, sep="")
Statement There is a grid of squares with H horizontal rows and W vertical columns. The square at the i-th row from the top and the j-th column from the left is represented as (i, j). Each square is black or white. The color of the square is given as an H-by-W matrix (a_{i, j}). If a_{i, j} is `.`, the square (i, j) is white; if a_{i, j} is `#`, the square (i, j) is black. Snuke is compressing this grid. He will do so by repeatedly performing the following operation while there is a row or column that consists only of white squares: * Operation: choose any one row or column that consists only of white squares, remove it and delete the space between the rows or columns. It can be shown that the final state of the grid is uniquely determined regardless of what row or column is chosen in each operation. Find the final state of the grid.
[{"input": "4 4\n ##.#\n ....\n ##.#\n .#.#", "output": "###\n ###\n .##\n \n\nThe second row and the third column in the original grid will be removed.\n\n* * *"}, {"input": "3 3\n #..\n .#.\n ..#", "output": "#..\n .#.\n ..#\n \n\nAs there is no row or column that consists only of white squares, no operation\nwill be performed.\n\n* * *"}, {"input": "4 5\n .....\n .....\n ..#..\n .....", "output": "#\n \n\n* * *"}, {"input": "7 6\n ......\n ....#.\n .#....\n ..#...\n ..#...\n ......\n .#..#.", "output": "..#\n #..\n .#.\n .#.\n #.#"}]
Print the final state of the grid in the same format as input (without the numbers of rows and columns); see the samples for clarity. * * *
s069344784
Wrong Answer
p03273
Input is given from Standard Input in the following format: H W a_{1, 1}...a_{1, W} : a_{H, 1}...a_{H, W}
f = lambda s: zip(*[t for t in s if "#" in t]) for r in f(f(__import__("sys").stdin)): print(*r)
Statement There is a grid of squares with H horizontal rows and W vertical columns. The square at the i-th row from the top and the j-th column from the left is represented as (i, j). Each square is black or white. The color of the square is given as an H-by-W matrix (a_{i, j}). If a_{i, j} is `.`, the square (i, j) is white; if a_{i, j} is `#`, the square (i, j) is black. Snuke is compressing this grid. He will do so by repeatedly performing the following operation while there is a row or column that consists only of white squares: * Operation: choose any one row or column that consists only of white squares, remove it and delete the space between the rows or columns. It can be shown that the final state of the grid is uniquely determined regardless of what row or column is chosen in each operation. Find the final state of the grid.
[{"input": "4 4\n ##.#\n ....\n ##.#\n .#.#", "output": "###\n ###\n .##\n \n\nThe second row and the third column in the original grid will be removed.\n\n* * *"}, {"input": "3 3\n #..\n .#.\n ..#", "output": "#..\n .#.\n ..#\n \n\nAs there is no row or column that consists only of white squares, no operation\nwill be performed.\n\n* * *"}, {"input": "4 5\n .....\n .....\n ..#..\n .....", "output": "#\n \n\n* * *"}, {"input": "7 6\n ......\n ....#.\n .#....\n ..#...\n ..#...\n ......\n .#..#.", "output": "..#\n #..\n .#.\n .#.\n #.#"}]
Print the final state of the grid in the same format as input (without the numbers of rows and columns); see the samples for clarity. * * *
s826516264
Accepted
p03273
Input is given from Standard Input in the following format: H W a_{1, 1}...a_{1, W} : a_{H, 1}...a_{H, W}
a, b = list(map(int, input().split())) n = [list(str(input())) for _ in range(a)] y = [] for i, name in enumerate(n): if not all([j == "." for j in name]): y.append(name) nc = [] for _ in range(len(y[0])): nnc = [] for _ in range(len(y)): nnc.append("#") nc.append(nnc) for i, name in enumerate(y): for k, name2 in enumerate(name): nc[k][i] = name2 z = [] for i, name in enumerate(nc): if not all([j == "." for j in name]): z.append(name) nc = [] for _ in range(len(z[0])): nnc = [] for _ in range(len(z)): nnc.append("#") nc.append(nnc) for i, name in enumerate(z): for k, name2 in enumerate(name): nc[k][i] = name2 for i in nc: print("".join(i))
Statement There is a grid of squares with H horizontal rows and W vertical columns. The square at the i-th row from the top and the j-th column from the left is represented as (i, j). Each square is black or white. The color of the square is given as an H-by-W matrix (a_{i, j}). If a_{i, j} is `.`, the square (i, j) is white; if a_{i, j} is `#`, the square (i, j) is black. Snuke is compressing this grid. He will do so by repeatedly performing the following operation while there is a row or column that consists only of white squares: * Operation: choose any one row or column that consists only of white squares, remove it and delete the space between the rows or columns. It can be shown that the final state of the grid is uniquely determined regardless of what row or column is chosen in each operation. Find the final state of the grid.
[{"input": "4 4\n ##.#\n ....\n ##.#\n .#.#", "output": "###\n ###\n .##\n \n\nThe second row and the third column in the original grid will be removed.\n\n* * *"}, {"input": "3 3\n #..\n .#.\n ..#", "output": "#..\n .#.\n ..#\n \n\nAs there is no row or column that consists only of white squares, no operation\nwill be performed.\n\n* * *"}, {"input": "4 5\n .....\n .....\n ..#..\n .....", "output": "#\n \n\n* * *"}, {"input": "7 6\n ......\n ....#.\n .#....\n ..#...\n ..#...\n ......\n .#..#.", "output": "..#\n #..\n .#.\n .#.\n #.#"}]
Print the final state of the grid in the same format as input (without the numbers of rows and columns); see the samples for clarity. * * *
s750178243
Accepted
p03273
Input is given from Standard Input in the following format: H W a_{1, 1}...a_{1, W} : a_{H, 1}...a_{H, W}
############################################################################### from sys import stdout from bisect import bisect_left as binl from copy import copy, deepcopy mod = 1 def intin(): input_tuple = input().split() if len(input_tuple) <= 1: return int(input_tuple[0]) return tuple(map(int, input_tuple)) def intina(): return [int(i) for i in input().split()] def intinl(count): return [intin() for _ in range(count)] def modadd(x, y): global mod return (x + y) % mod def modmlt(x, y): global mod return (x * y) % mod def lcm(x, y): while y != 0: z = x % y x = y y = z return x def combination(x, y): assert x >= y if y > x // 2: y = x - y ret = 1 for i in range(0, y): j = x - i i = i + 1 ret = ret * j ret = ret // i return ret def get_divisors(x): retlist = [] for i in range(1, int(x**0.5) + 3): if x % i == 0: retlist.append(i) retlist.append(x // i) return retlist def get_factors(x): retlist = [] for i in range(2, int(x**0.5) + 3): while x % i == 0: retlist.append(i) x = x // i retlist.append(x) return retlist def make_linklist(xylist): linklist = {} for a, b in xylist: linklist.setdefault(a, []) linklist.setdefault(b, []) linklist[a].append(b) linklist[b].append(a) return linklist def calc_longest_distance(linklist, v=1): distance_list = {} distance_count = 0 distance = 0 vlist_previous = [] vlist = [v] nodecount = len(linklist) while distance_count < nodecount: vlist_next = [] for v in vlist: distance_list[v] = distance distance_count += 1 vlist_next.extend(linklist[v]) distance += 1 vlist_to_del = vlist_previous vlist_previous = vlist vlist = list(set(vlist_next) - set(vlist_to_del)) max_distance = -1 max_v = None for v, distance in distance_list.items(): if distance > max_distance: max_distance = distance max_v = v return (max_distance, max_v) def calc_tree_diameter(linklist, v=1): _, u = calc_longest_distance(linklist, v) distance, _ = calc_longest_distance(linklist, u) return distance ############################################################################### def main(): h, w = intin() alistlist = [] for i in range(h): alistlist.append(input()) new_alistlist = [] new_h = 0 for alist in alistlist: if alist != "." * w: new_alistlist.append(alist) new_h += 1 alistlist = new_alistlist h = new_h remove_wlist = [] for i in range(w): for j in range(h): if alistlist[j][i] == "#": break else: remove_wlist.append(i) new_alistlist = [] for alist in alistlist: new_alist = "" for i in range(w): if i not in remove_wlist: new_alist += alist[i] new_alistlist.append(new_alist) alistlist = new_alistlist for alist in alistlist: print(alist) if __name__ == "__main__": main()
Statement There is a grid of squares with H horizontal rows and W vertical columns. The square at the i-th row from the top and the j-th column from the left is represented as (i, j). Each square is black or white. The color of the square is given as an H-by-W matrix (a_{i, j}). If a_{i, j} is `.`, the square (i, j) is white; if a_{i, j} is `#`, the square (i, j) is black. Snuke is compressing this grid. He will do so by repeatedly performing the following operation while there is a row or column that consists only of white squares: * Operation: choose any one row or column that consists only of white squares, remove it and delete the space between the rows or columns. It can be shown that the final state of the grid is uniquely determined regardless of what row or column is chosen in each operation. Find the final state of the grid.
[{"input": "4 4\n ##.#\n ....\n ##.#\n .#.#", "output": "###\n ###\n .##\n \n\nThe second row and the third column in the original grid will be removed.\n\n* * *"}, {"input": "3 3\n #..\n .#.\n ..#", "output": "#..\n .#.\n ..#\n \n\nAs there is no row or column that consists only of white squares, no operation\nwill be performed.\n\n* * *"}, {"input": "4 5\n .....\n .....\n ..#..\n .....", "output": "#\n \n\n* * *"}, {"input": "7 6\n ......\n ....#.\n .#....\n ..#...\n ..#...\n ......\n .#..#.", "output": "..#\n #..\n .#.\n .#.\n #.#"}]
Print the final state of the grid in the same format as input (without the numbers of rows and columns); see the samples for clarity. * * *
s967215614
Runtime Error
p03273
Input is given from Standard Input in the following format: H W a_{1, 1}...a_{1, W} : a_{H, 1}...a_{H, W}
# -*- coding: utf-8 -*- """ Created on Wed Jul 18 00:01:41 2018 @author: Yuya """ n, m = map(int, input().split()) ans = [] c = 0 for i in range(n): tmp = list(input()) f = 1 for j in range(m): if tmp[j] == "#": f = -1 if f < 0: ans.append(tmp) c += 1 ans2 = [["0" for i in range(c)] for j in range(m)] for i in range(m): for j in range(c): ans2[i][j] = ans[j][i] d = m for i in range(m - 1, -1, -1): f = 1 for j in range(c): if ans2[i][j] == "#": f = -1 if f > 0: del ans2[i] d -= 1 ans3 = [["0" for i in range(c)] for j in range(d)] for i in range(d): for j in range(c): ans3[i][j] = ans2[j][i] for i in range(c): print("".join(ans3[i]))
Statement There is a grid of squares with H horizontal rows and W vertical columns. The square at the i-th row from the top and the j-th column from the left is represented as (i, j). Each square is black or white. The color of the square is given as an H-by-W matrix (a_{i, j}). If a_{i, j} is `.`, the square (i, j) is white; if a_{i, j} is `#`, the square (i, j) is black. Snuke is compressing this grid. He will do so by repeatedly performing the following operation while there is a row or column that consists only of white squares: * Operation: choose any one row or column that consists only of white squares, remove it and delete the space between the rows or columns. It can be shown that the final state of the grid is uniquely determined regardless of what row or column is chosen in each operation. Find the final state of the grid.
[{"input": "4 4\n ##.#\n ....\n ##.#\n .#.#", "output": "###\n ###\n .##\n \n\nThe second row and the third column in the original grid will be removed.\n\n* * *"}, {"input": "3 3\n #..\n .#.\n ..#", "output": "#..\n .#.\n ..#\n \n\nAs there is no row or column that consists only of white squares, no operation\nwill be performed.\n\n* * *"}, {"input": "4 5\n .....\n .....\n ..#..\n .....", "output": "#\n \n\n* * *"}, {"input": "7 6\n ......\n ....#.\n .#....\n ..#...\n ..#...\n ......\n .#..#.", "output": "..#\n #..\n .#.\n .#.\n #.#"}]
Print the final state of the grid in the same format as input (without the numbers of rows and columns); see the samples for clarity. * * *
s714670346
Runtime Error
p03273
Input is given from Standard Input in the following format: H W a_{1, 1}...a_{1, W} : a_{H, 1}...a_{H, W}
H,W = map(int,input().split()) li = [input() for i in range(H)] num_lists = [] for i in range(H): if "#" in li[i]: else : num_lists.append(i) for i in reversed(num_lists): li.pop(i) print(li)
Statement There is a grid of squares with H horizontal rows and W vertical columns. The square at the i-th row from the top and the j-th column from the left is represented as (i, j). Each square is black or white. The color of the square is given as an H-by-W matrix (a_{i, j}). If a_{i, j} is `.`, the square (i, j) is white; if a_{i, j} is `#`, the square (i, j) is black. Snuke is compressing this grid. He will do so by repeatedly performing the following operation while there is a row or column that consists only of white squares: * Operation: choose any one row or column that consists only of white squares, remove it and delete the space between the rows or columns. It can be shown that the final state of the grid is uniquely determined regardless of what row or column is chosen in each operation. Find the final state of the grid.
[{"input": "4 4\n ##.#\n ....\n ##.#\n .#.#", "output": "###\n ###\n .##\n \n\nThe second row and the third column in the original grid will be removed.\n\n* * *"}, {"input": "3 3\n #..\n .#.\n ..#", "output": "#..\n .#.\n ..#\n \n\nAs there is no row or column that consists only of white squares, no operation\nwill be performed.\n\n* * *"}, {"input": "4 5\n .....\n .....\n ..#..\n .....", "output": "#\n \n\n* * *"}, {"input": "7 6\n ......\n ....#.\n .#....\n ..#...\n ..#...\n ......\n .#..#.", "output": "..#\n #..\n .#.\n .#.\n #.#"}]
Print the final state of the grid in the same format as input (without the numbers of rows and columns); see the samples for clarity. * * *
s319975514
Runtime Error
p03273
Input is given from Standard Input in the following format: H W a_{1, 1}...a_{1, W} : a_{H, 1}...a_{H, W}
N = int(input()) ans = 0 for i in range(1, N + 1, 2): cnt = 0 for n in range(1, N + 1, 2): if n % i == 0: cnt += 1 if cnt == 8: ans += 1 print(ans)
Statement There is a grid of squares with H horizontal rows and W vertical columns. The square at the i-th row from the top and the j-th column from the left is represented as (i, j). Each square is black or white. The color of the square is given as an H-by-W matrix (a_{i, j}). If a_{i, j} is `.`, the square (i, j) is white; if a_{i, j} is `#`, the square (i, j) is black. Snuke is compressing this grid. He will do so by repeatedly performing the following operation while there is a row or column that consists only of white squares: * Operation: choose any one row or column that consists only of white squares, remove it and delete the space between the rows or columns. It can be shown that the final state of the grid is uniquely determined regardless of what row or column is chosen in each operation. Find the final state of the grid.
[{"input": "4 4\n ##.#\n ....\n ##.#\n .#.#", "output": "###\n ###\n .##\n \n\nThe second row and the third column in the original grid will be removed.\n\n* * *"}, {"input": "3 3\n #..\n .#.\n ..#", "output": "#..\n .#.\n ..#\n \n\nAs there is no row or column that consists only of white squares, no operation\nwill be performed.\n\n* * *"}, {"input": "4 5\n .....\n .....\n ..#..\n .....", "output": "#\n \n\n* * *"}, {"input": "7 6\n ......\n ....#.\n .#....\n ..#...\n ..#...\n ......\n .#..#.", "output": "..#\n #..\n .#.\n .#.\n #.#"}]
Print the final state of the grid in the same format as input (without the numbers of rows and columns); see the samples for clarity. * * *
s408170594
Runtime Error
p03273
Input is given from Standard Input in the following format: H W a_{1, 1}...a_{1, W} : a_{H, 1}...a_{H, W}
n = int(input()) if n < 105: print("0") else: if n < 135: print("1") else: if n < 165: print("2") else: if n < 189: print("3") else: print("4")
Statement There is a grid of squares with H horizontal rows and W vertical columns. The square at the i-th row from the top and the j-th column from the left is represented as (i, j). Each square is black or white. The color of the square is given as an H-by-W matrix (a_{i, j}). If a_{i, j} is `.`, the square (i, j) is white; if a_{i, j} is `#`, the square (i, j) is black. Snuke is compressing this grid. He will do so by repeatedly performing the following operation while there is a row or column that consists only of white squares: * Operation: choose any one row or column that consists only of white squares, remove it and delete the space between the rows or columns. It can be shown that the final state of the grid is uniquely determined regardless of what row or column is chosen in each operation. Find the final state of the grid.
[{"input": "4 4\n ##.#\n ....\n ##.#\n .#.#", "output": "###\n ###\n .##\n \n\nThe second row and the third column in the original grid will be removed.\n\n* * *"}, {"input": "3 3\n #..\n .#.\n ..#", "output": "#..\n .#.\n ..#\n \n\nAs there is no row or column that consists only of white squares, no operation\nwill be performed.\n\n* * *"}, {"input": "4 5\n .....\n .....\n ..#..\n .....", "output": "#\n \n\n* * *"}, {"input": "7 6\n ......\n ....#.\n .#....\n ..#...\n ..#...\n ......\n .#..#.", "output": "..#\n #..\n .#.\n .#.\n #.#"}]
Print the final state of the grid in the same format as input (without the numbers of rows and columns); see the samples for clarity. * * *
s382213084
Runtime Error
p03273
Input is given from Standard Input in the following format: H W a_{1, 1}...a_{1, W} : a_{H, 1}...a_{H, W}
H, W = map(int, input().split()) A = [input() for _ in range(N)] tmp = [] for a in zip(*A): if a.count("#") > 0: tmp.append("".join(a)) tmp2 = [] for t in zip(*tmp): if t.count("#") > 0: tmp2.append("".join(t)) print("\n".join(tmp2))
Statement There is a grid of squares with H horizontal rows and W vertical columns. The square at the i-th row from the top and the j-th column from the left is represented as (i, j). Each square is black or white. The color of the square is given as an H-by-W matrix (a_{i, j}). If a_{i, j} is `.`, the square (i, j) is white; if a_{i, j} is `#`, the square (i, j) is black. Snuke is compressing this grid. He will do so by repeatedly performing the following operation while there is a row or column that consists only of white squares: * Operation: choose any one row or column that consists only of white squares, remove it and delete the space between the rows or columns. It can be shown that the final state of the grid is uniquely determined regardless of what row or column is chosen in each operation. Find the final state of the grid.
[{"input": "4 4\n ##.#\n ....\n ##.#\n .#.#", "output": "###\n ###\n .##\n \n\nThe second row and the third column in the original grid will be removed.\n\n* * *"}, {"input": "3 3\n #..\n .#.\n ..#", "output": "#..\n .#.\n ..#\n \n\nAs there is no row or column that consists only of white squares, no operation\nwill be performed.\n\n* * *"}, {"input": "4 5\n .....\n .....\n ..#..\n .....", "output": "#\n \n\n* * *"}, {"input": "7 6\n ......\n ....#.\n .#....\n ..#...\n ..#...\n ......\n .#..#.", "output": "..#\n #..\n .#.\n .#.\n #.#"}]
Print the final state of the grid in the same format as input (without the numbers of rows and columns); see the samples for clarity. * * *
s138042170
Runtime Error
p03273
Input is given from Standard Input in the following format: H W a_{1, 1}...a_{1, W} : a_{H, 1}...a_{H, W}
import numpy as np h,w=map(int,input().split()) tmp=[] for i in range(h): a=list(input()) tmp.append(a) ans1=[] if(w!=1): for i in range(h): if(len(set(tmp[i]))==1): ans1.append(i) ans2=[] tmp=list(map(list,zip(*tmp))) if(h!=1) for i in range(w): if(len(set(tmp[i]))==1): ans2.append(i) # print(ans1,ans2) tmp=list(map(list,zip(*tmp))) tmp=np.delete(tmp,ans1,axis=0) tmp=np.delete(tmp,ans2,axis=1) for i in range(len(tmp)): for j in range(len(tmp[0])): print(tmp[i][j],end="") print()
Statement There is a grid of squares with H horizontal rows and W vertical columns. The square at the i-th row from the top and the j-th column from the left is represented as (i, j). Each square is black or white. The color of the square is given as an H-by-W matrix (a_{i, j}). If a_{i, j} is `.`, the square (i, j) is white; if a_{i, j} is `#`, the square (i, j) is black. Snuke is compressing this grid. He will do so by repeatedly performing the following operation while there is a row or column that consists only of white squares: * Operation: choose any one row or column that consists only of white squares, remove it and delete the space between the rows or columns. It can be shown that the final state of the grid is uniquely determined regardless of what row or column is chosen in each operation. Find the final state of the grid.
[{"input": "4 4\n ##.#\n ....\n ##.#\n .#.#", "output": "###\n ###\n .##\n \n\nThe second row and the third column in the original grid will be removed.\n\n* * *"}, {"input": "3 3\n #..\n .#.\n ..#", "output": "#..\n .#.\n ..#\n \n\nAs there is no row or column that consists only of white squares, no operation\nwill be performed.\n\n* * *"}, {"input": "4 5\n .....\n .....\n ..#..\n .....", "output": "#\n \n\n* * *"}, {"input": "7 6\n ......\n ....#.\n .#....\n ..#...\n ..#...\n ......\n .#..#.", "output": "..#\n #..\n .#.\n .#.\n #.#"}]
Print the final state of the grid in the same format as input (without the numbers of rows and columns); see the samples for clarity. * * *
s512361670
Runtime Error
p03273
Input is given from Standard Input in the following format: H W a_{1, 1}...a_{1, W} : a_{H, 1}...a_{H, W}
import numpy as np H, W = map(int, input().split()) a = np.array(shape=(H, W), dtype=bool) for i in range(H): a[i] = [s == "." for s in input().split()] y = [True] * H i in range(H): if all(a[i,:]): y[i] = False x = [True] * W for i in range(W): if all(a[:,i]): x[i] = False ans = [] for i in range(H): if not y[i]: continue s = "" for j in range(W): if not x[j]: continue s = "".join([s, "." if a[i,j] else "#"]) ans.append(s) print(*ans, sep="\n")
Statement There is a grid of squares with H horizontal rows and W vertical columns. The square at the i-th row from the top and the j-th column from the left is represented as (i, j). Each square is black or white. The color of the square is given as an H-by-W matrix (a_{i, j}). If a_{i, j} is `.`, the square (i, j) is white; if a_{i, j} is `#`, the square (i, j) is black. Snuke is compressing this grid. He will do so by repeatedly performing the following operation while there is a row or column that consists only of white squares: * Operation: choose any one row or column that consists only of white squares, remove it and delete the space between the rows or columns. It can be shown that the final state of the grid is uniquely determined regardless of what row or column is chosen in each operation. Find the final state of the grid.
[{"input": "4 4\n ##.#\n ....\n ##.#\n .#.#", "output": "###\n ###\n .##\n \n\nThe second row and the third column in the original grid will be removed.\n\n* * *"}, {"input": "3 3\n #..\n .#.\n ..#", "output": "#..\n .#.\n ..#\n \n\nAs there is no row or column that consists only of white squares, no operation\nwill be performed.\n\n* * *"}, {"input": "4 5\n .....\n .....\n ..#..\n .....", "output": "#\n \n\n* * *"}, {"input": "7 6\n ......\n ....#.\n .#....\n ..#...\n ..#...\n ......\n .#..#.", "output": "..#\n #..\n .#.\n .#.\n #.#"}]
Print the final state of the grid in the same format as input (without the numbers of rows and columns); see the samples for clarity. * * *
s567194633
Runtime Error
p03273
Input is given from Standard Input in the following format: H W a_{1, 1}...a_{1, W} : a_{H, 1}...a_{H, W}
numpy as np H, W = map(int, input().split()) a = np.zeros(shape=(H, W), dtype=bool) for i in range(H): a[i] = [s == "." for s in input().split()] y = [True] * H for i in range(H): if all(a[i,:]): y[i] = False x = [True] * W for i in range(W): if all(a[:,i]): x[i] = False ans = [] for i in range(H): if not y[i]: continue s = "" for j in range(W): if not x[j]: continue s = "".join([s, "." if a[i,j] else "#"]) ans.append(s) print(*ans, sep="\n")
Statement There is a grid of squares with H horizontal rows and W vertical columns. The square at the i-th row from the top and the j-th column from the left is represented as (i, j). Each square is black or white. The color of the square is given as an H-by-W matrix (a_{i, j}). If a_{i, j} is `.`, the square (i, j) is white; if a_{i, j} is `#`, the square (i, j) is black. Snuke is compressing this grid. He will do so by repeatedly performing the following operation while there is a row or column that consists only of white squares: * Operation: choose any one row or column that consists only of white squares, remove it and delete the space between the rows or columns. It can be shown that the final state of the grid is uniquely determined regardless of what row or column is chosen in each operation. Find the final state of the grid.
[{"input": "4 4\n ##.#\n ....\n ##.#\n .#.#", "output": "###\n ###\n .##\n \n\nThe second row and the third column in the original grid will be removed.\n\n* * *"}, {"input": "3 3\n #..\n .#.\n ..#", "output": "#..\n .#.\n ..#\n \n\nAs there is no row or column that consists only of white squares, no operation\nwill be performed.\n\n* * *"}, {"input": "4 5\n .....\n .....\n ..#..\n .....", "output": "#\n \n\n* * *"}, {"input": "7 6\n ......\n ....#.\n .#....\n ..#...\n ..#...\n ......\n .#..#.", "output": "..#\n #..\n .#.\n .#.\n #.#"}]
Print the final state of the grid in the same format as input (without the numbers of rows and columns); see the samples for clarity. * * *
s063772806
Runtime Error
p03273
Input is given from Standard Input in the following format: H W a_{1, 1}...a_{1, W} : a_{H, 1}...a_{H, W}
#include <bits/stdc++.h> using namespace std; typedef long long ll; #define rep(i, n) for(ll i=0; i < n; i++) #define FOR(i, m, n) for(ll i = m; i < n; i++) #define all(vec) vec.begin(), vec.end() #define tmax(x, y, z) max((x), max((y), (z))) #define tmin(x, y, z) min((x), min((y), (z))) ll MM = 1000000000; ll mod = MM + 7; ll MMM=9223372036854775807;//2^63 -1 ll GCD(ll x, ll y){ if(y == 0) return x; else return GCD(y, x % y);} ll LCM(ll x, ll y){ return x / GCD(x, y) * y;} template<class T> inline bool chmin(T& a, T b){ if(a > b){ a = b; return true;} return false;} template<class T> inline bool chmax(T& a, T b){ if(a < b){ a = b; return true;} return false;} const ll INF = 1LL << 60; //cout << fixed << setprecision(10); template<typename T> vector<T> make_v(size_t a,T b){return vector<T>(a,b);} template<typename... Ts> auto make_v(size_t a,Ts... ts){ return vector<decltype(make_v(ts...))>(a,make_v(ts...)); } int main(){ ll h, w; cin>>h>>w; vector<string> grid(h); set<ll> ver, hor; rep(i,h){ string s; cin>>s; grid[i] = s; rep(j,w){ if(s[j] == '#'){ ver.insert(i); hor.insert(j); } } } rep(i,h){ rep(j,w){ bool t = false; if(ver.count(i) && hor.count(j)){ cout<<grid[i][j]; t = true; } if(t && j == *rbegin(ver)) cout<<endl; } } }
Statement There is a grid of squares with H horizontal rows and W vertical columns. The square at the i-th row from the top and the j-th column from the left is represented as (i, j). Each square is black or white. The color of the square is given as an H-by-W matrix (a_{i, j}). If a_{i, j} is `.`, the square (i, j) is white; if a_{i, j} is `#`, the square (i, j) is black. Snuke is compressing this grid. He will do so by repeatedly performing the following operation while there is a row or column that consists only of white squares: * Operation: choose any one row or column that consists only of white squares, remove it and delete the space between the rows or columns. It can be shown that the final state of the grid is uniquely determined regardless of what row or column is chosen in each operation. Find the final state of the grid.
[{"input": "4 4\n ##.#\n ....\n ##.#\n .#.#", "output": "###\n ###\n .##\n \n\nThe second row and the third column in the original grid will be removed.\n\n* * *"}, {"input": "3 3\n #..\n .#.\n ..#", "output": "#..\n .#.\n ..#\n \n\nAs there is no row or column that consists only of white squares, no operation\nwill be performed.\n\n* * *"}, {"input": "4 5\n .....\n .....\n ..#..\n .....", "output": "#\n \n\n* * *"}, {"input": "7 6\n ......\n ....#.\n .#....\n ..#...\n ..#...\n ......\n .#..#.", "output": "..#\n #..\n .#.\n .#.\n #.#"}]
Print the final state of the grid in the same format as input (without the numbers of rows and columns); see the samples for clarity. * * *
s777390729
Runtime Error
p03273
Input is given from Standard Input in the following format: H W a_{1, 1}...a_{1, W} : a_{H, 1}...a_{H, W}
\import numpy as np h,w=map(int,input().split()) tmp=[] for i in range(h): a=list(input()) tmp.append(a) ans1=[] if(w!=1): for i in range(h): if(len(set(tmp[i]))==1 and tmp[i][0]!="#"): ans1.append(i) ans2=[] tmp=list(map(list,zip(*tmp))) if(h!=1): for i in range(w): if(len(set(tmp[i]))==1 and tmp[i][0]!="#"): ans2.append(i) # print(ans1,ans2) tmp=list(map(list,zip(*tmp))) tmp=np.delete(tmp,ans1,axis=0) tmp=np.delete(tmp,ans2,axis=1) for i in range(len(tmp)): for j in range(len(tmp[0])): print(tmp[i][j],end="") print()
Statement There is a grid of squares with H horizontal rows and W vertical columns. The square at the i-th row from the top and the j-th column from the left is represented as (i, j). Each square is black or white. The color of the square is given as an H-by-W matrix (a_{i, j}). If a_{i, j} is `.`, the square (i, j) is white; if a_{i, j} is `#`, the square (i, j) is black. Snuke is compressing this grid. He will do so by repeatedly performing the following operation while there is a row or column that consists only of white squares: * Operation: choose any one row or column that consists only of white squares, remove it and delete the space between the rows or columns. It can be shown that the final state of the grid is uniquely determined regardless of what row or column is chosen in each operation. Find the final state of the grid.
[{"input": "4 4\n ##.#\n ....\n ##.#\n .#.#", "output": "###\n ###\n .##\n \n\nThe second row and the third column in the original grid will be removed.\n\n* * *"}, {"input": "3 3\n #..\n .#.\n ..#", "output": "#..\n .#.\n ..#\n \n\nAs there is no row or column that consists only of white squares, no operation\nwill be performed.\n\n* * *"}, {"input": "4 5\n .....\n .....\n ..#..\n .....", "output": "#\n \n\n* * *"}, {"input": "7 6\n ......\n ....#.\n .#....\n ..#...\n ..#...\n ......\n .#..#.", "output": "..#\n #..\n .#.\n .#.\n #.#"}]
Print the final state of the grid in the same format as input (without the numbers of rows and columns); see the samples for clarity. * * *
s117245867
Runtime Error
p03273
Input is given from Standard Input in the following format: H W a_{1, 1}...a_{1, W} : a_{H, 1}...a_{H, W}
h, w = map(int, input().split()) a = [] for _ in range(h): l = input() if l != '.'*w: a.append(l) col = [] h = len(a) for i in range(w): if a[0][i] == '.': for j in range(1,h): if a[j][i] != '.': col.append(i) break else: col.append(i) for l in a: ll = '' for i in col: ll += l[i] print(ll) h, w = map(int, input().split()) a = [] for _ in range(h): l = input() if l != '.'*w: a.append(l) col = [] h = len(a) for i in range(w): if a[0][i] == '.': for j in range(1,h): if a[j][i] != '.': col.append(i) break else: col.append(i) for l in a: ll = '' for i in col: ll += l[i] print(ll)
Statement There is a grid of squares with H horizontal rows and W vertical columns. The square at the i-th row from the top and the j-th column from the left is represented as (i, j). Each square is black or white. The color of the square is given as an H-by-W matrix (a_{i, j}). If a_{i, j} is `.`, the square (i, j) is white; if a_{i, j} is `#`, the square (i, j) is black. Snuke is compressing this grid. He will do so by repeatedly performing the following operation while there is a row or column that consists only of white squares: * Operation: choose any one row or column that consists only of white squares, remove it and delete the space between the rows or columns. It can be shown that the final state of the grid is uniquely determined regardless of what row or column is chosen in each operation. Find the final state of the grid.
[{"input": "4 4\n ##.#\n ....\n ##.#\n .#.#", "output": "###\n ###\n .##\n \n\nThe second row and the third column in the original grid will be removed.\n\n* * *"}, {"input": "3 3\n #..\n .#.\n ..#", "output": "#..\n .#.\n ..#\n \n\nAs there is no row or column that consists only of white squares, no operation\nwill be performed.\n\n* * *"}, {"input": "4 5\n .....\n .....\n ..#..\n .....", "output": "#\n \n\n* * *"}, {"input": "7 6\n ......\n ....#.\n .#....\n ..#...\n ..#...\n ......\n .#..#.", "output": "..#\n #..\n .#.\n .#.\n #.#"}]
Print the final state of the grid in the same format as input (without the numbers of rows and columns); see the samples for clarity. * * *
s824391615
Runtime Error
p03273
Input is given from Standard Input in the following format: H W a_{1, 1}...a_{1, W} : a_{H, 1}...a_{H, W}
h,w = map(int,input().split()) a = [""]*h for i in range(h): a[i] = input() row = [False]*h column = [False]*w for i in range(h): for j in range(w): if a[i][j] = "#": row[i] = True column[j] = True for i in range(h): if row[i]: for j in range(w): if column[j]: print(a[i][j],end = "") print()
Statement There is a grid of squares with H horizontal rows and W vertical columns. The square at the i-th row from the top and the j-th column from the left is represented as (i, j). Each square is black or white. The color of the square is given as an H-by-W matrix (a_{i, j}). If a_{i, j} is `.`, the square (i, j) is white; if a_{i, j} is `#`, the square (i, j) is black. Snuke is compressing this grid. He will do so by repeatedly performing the following operation while there is a row or column that consists only of white squares: * Operation: choose any one row or column that consists only of white squares, remove it and delete the space between the rows or columns. It can be shown that the final state of the grid is uniquely determined regardless of what row or column is chosen in each operation. Find the final state of the grid.
[{"input": "4 4\n ##.#\n ....\n ##.#\n .#.#", "output": "###\n ###\n .##\n \n\nThe second row and the third column in the original grid will be removed.\n\n* * *"}, {"input": "3 3\n #..\n .#.\n ..#", "output": "#..\n .#.\n ..#\n \n\nAs there is no row or column that consists only of white squares, no operation\nwill be performed.\n\n* * *"}, {"input": "4 5\n .....\n .....\n ..#..\n .....", "output": "#\n \n\n* * *"}, {"input": "7 6\n ......\n ....#.\n .#....\n ..#...\n ..#...\n ......\n .#..#.", "output": "..#\n #..\n .#.\n .#.\n #.#"}]
Print the final state of the grid in the same format as input (without the numbers of rows and columns); see the samples for clarity. * * *
s411589552
Runtime Error
p03273
Input is given from Standard Input in the following format: H W a_{1, 1}...a_{1, W} : a_{H, 1}...a_{H, W}
h,w = map(int,input().split()) a = [""]*h for i in range(h): a[i] = input() row = [False]*h column = [False]*w for i in range(h): for j in range(w): if a[i][j] = "#": row[i] = True column[j] = True for i in range(h): if row[i]: for j in range(w): if column[j]: print("a[i][j]",end = "") print()
Statement There is a grid of squares with H horizontal rows and W vertical columns. The square at the i-th row from the top and the j-th column from the left is represented as (i, j). Each square is black or white. The color of the square is given as an H-by-W matrix (a_{i, j}). If a_{i, j} is `.`, the square (i, j) is white; if a_{i, j} is `#`, the square (i, j) is black. Snuke is compressing this grid. He will do so by repeatedly performing the following operation while there is a row or column that consists only of white squares: * Operation: choose any one row or column that consists only of white squares, remove it and delete the space between the rows or columns. It can be shown that the final state of the grid is uniquely determined regardless of what row or column is chosen in each operation. Find the final state of the grid.
[{"input": "4 4\n ##.#\n ....\n ##.#\n .#.#", "output": "###\n ###\n .##\n \n\nThe second row and the third column in the original grid will be removed.\n\n* * *"}, {"input": "3 3\n #..\n .#.\n ..#", "output": "#..\n .#.\n ..#\n \n\nAs there is no row or column that consists only of white squares, no operation\nwill be performed.\n\n* * *"}, {"input": "4 5\n .....\n .....\n ..#..\n .....", "output": "#\n \n\n* * *"}, {"input": "7 6\n ......\n ....#.\n .#....\n ..#...\n ..#...\n ......\n .#..#.", "output": "..#\n #..\n .#.\n .#.\n #.#"}]
Print the final state of the grid in the same format as input (without the numbers of rows and columns); see the samples for clarity. * * *
s240411432
Runtime Error
p03273
Input is given from Standard Input in the following format: H W a_{1, 1}...a_{1, W} : a_{H, 1}...a_{H, W}
h,w=map(int,input().split()) a=[[j for j in input()] for i in range(h)] for i in range(h): if a[i].count('.')==w: a[i]=[] while [] in a: a.remove([]) for i in range(w): c=0 for j in range(len(a)): if a[j][i]=='.': c+=1 if c==len(a): for j in range(len(a)): a[j][i]='!' for i in range(len(a)): while '!' in a[i]:a a[i].remove('!') for i in a: print(*i,sep='')
Statement There is a grid of squares with H horizontal rows and W vertical columns. The square at the i-th row from the top and the j-th column from the left is represented as (i, j). Each square is black or white. The color of the square is given as an H-by-W matrix (a_{i, j}). If a_{i, j} is `.`, the square (i, j) is white; if a_{i, j} is `#`, the square (i, j) is black. Snuke is compressing this grid. He will do so by repeatedly performing the following operation while there is a row or column that consists only of white squares: * Operation: choose any one row or column that consists only of white squares, remove it and delete the space between the rows or columns. It can be shown that the final state of the grid is uniquely determined regardless of what row or column is chosen in each operation. Find the final state of the grid.
[{"input": "4 4\n ##.#\n ....\n ##.#\n .#.#", "output": "###\n ###\n .##\n \n\nThe second row and the third column in the original grid will be removed.\n\n* * *"}, {"input": "3 3\n #..\n .#.\n ..#", "output": "#..\n .#.\n ..#\n \n\nAs there is no row or column that consists only of white squares, no operation\nwill be performed.\n\n* * *"}, {"input": "4 5\n .....\n .....\n ..#..\n .....", "output": "#\n \n\n* * *"}, {"input": "7 6\n ......\n ....#.\n .#....\n ..#...\n ..#...\n ......\n .#..#.", "output": "..#\n #..\n .#.\n .#.\n #.#"}]
Print the final state of the grid in the same format as input (without the numbers of rows and columns); see the samples for clarity. * * *
s379943848
Accepted
p03273
Input is given from Standard Input in the following format: H W a_{1, 1}...a_{1, W} : a_{H, 1}...a_{H, W}
h, w = map(int, input().split()) masulist = [list(input()) for a in range(h)] masulist2 = [b for b in masulist if b.count("#")] x = [b for b in list(zip(*masulist2)) if b.count("#")] y = list(zip(*x)) for a in y: print("".join(a))
Statement There is a grid of squares with H horizontal rows and W vertical columns. The square at the i-th row from the top and the j-th column from the left is represented as (i, j). Each square is black or white. The color of the square is given as an H-by-W matrix (a_{i, j}). If a_{i, j} is `.`, the square (i, j) is white; if a_{i, j} is `#`, the square (i, j) is black. Snuke is compressing this grid. He will do so by repeatedly performing the following operation while there is a row or column that consists only of white squares: * Operation: choose any one row or column that consists only of white squares, remove it and delete the space between the rows or columns. It can be shown that the final state of the grid is uniquely determined regardless of what row or column is chosen in each operation. Find the final state of the grid.
[{"input": "4 4\n ##.#\n ....\n ##.#\n .#.#", "output": "###\n ###\n .##\n \n\nThe second row and the third column in the original grid will be removed.\n\n* * *"}, {"input": "3 3\n #..\n .#.\n ..#", "output": "#..\n .#.\n ..#\n \n\nAs there is no row or column that consists only of white squares, no operation\nwill be performed.\n\n* * *"}, {"input": "4 5\n .....\n .....\n ..#..\n .....", "output": "#\n \n\n* * *"}, {"input": "7 6\n ......\n ....#.\n .#....\n ..#...\n ..#...\n ......\n .#..#.", "output": "..#\n #..\n .#.\n .#.\n #.#"}]
For each get operation, print the corresponding values in the order of insertions. For each dump operation, print the corresponding elements formed by a pair of the key and the value. For the dump operation, print the elements in ascending order of the keys, in case of a tie, in the order of insertions.
s388019466
Accepted
p02462
The input is given in the following format. $q$ $query_1$ $query_2$ : $query_q$ Each query $query_i$ is given by 0 $key$ $x$ or 1 $key$ or 2 $key$ or 3 $L$ $R$ where the first digits 0, 1, 2 and 3 represent insert, get, delete and dump operations.
# AOJ ITP2_8_D: Multi-Map # Python3 2018.6.24 bal4u from bisect import bisect_left, bisect_right, insort_left dict = {} keytbl = [] q = int(input()) for i in range(q): a = list(input().split()) ki = a[1] if a[0] == "0": if ki not in dict: dict[ki] = [] insort_left(keytbl, ki) dict[ki].append(int(a[2])) elif a[0] == "1": if ki in dict and dict[ki] != []: print(*dict[ki], sep="\n") elif a[0] == "2": if ki in dict: dict[ki] = [] else: L = bisect_left(keytbl, a[1]) R = bisect_right(keytbl, a[2], L) for j in range(L, R): for k in dict[keytbl[j]]: print(keytbl[j], k)
Multi-Map For a dictionary $M$ that stores elements formed by a pair of a string key and an integer value, perform a sequence of the following operations. Note that _multiple elements can have equivalent keys_. * insert($key$, $x$): Insert an element formed by a pair of $key$ and $x$ to $M$. * get($key$): Print all values with the specified $key$. * delete($key$): Delete all elements with the specified $key$. * dump($L$, $R$): Print all elements formed by a pair of the key and the value such that the key is greater than or equal to $L$ and less than or equal to $R$ in lexicographic order.
[{"input": "10\n 0 blue 6\n 0 red 1\n 0 blue 4\n 0 white 5\n 1 red\n 1 blue\n 2 red\n 1 black\n 1 red\n 3 w z", "output": "1\n 6\n 4\n white 5"}]
Print the maximum possible total joyfulness of the two contests. * * *
s645875160
Wrong Answer
p02874
Input is given from Standard Input in the following format: N L_1 R_1 L_2 R_2 \vdots L_N R_N
s = input() l = [0 for i in range(len(s) + 1)] if s[0] == "<": cnt = 1 for i in range(0, len(s)): if s[i] == "<": l[i + 1] = max(cnt, l[i + 1]) cnt += 1 else: break if s[-1] == ">": cnt = 1 for i in range(len(s) - 1, -1, -1): if s[i] == ">": l[i] = max(cnt, l[i]) cnt += 1 else: break for i in range(1, len(s)): if s[i - 1 : i + 1] == "><": # ๅทฆๅดๆคœ็ดข cnt = 1 for j in range(i - 1, -1, -1): if s[j] == ">": l[j] = max(cnt, l[j]) cnt += 1 else: break # ๅณๅดๆคœ็ดข cnt = 1 for j in range(i, len(s)): if s[j] == "<": l[j + 1] = max(cnt, l[j]) cnt += 1 else: break ans = sum(l) print(ans)
Statement 10^9 contestants, numbered 1 to 10^9, will compete in a competition. There will be two contests in this competition. The organizer prepared N problems, numbered 1 to N, to use in these contests. When Problem i is presented in a contest, it will be solved by all contestants from Contestant L_i to Contestant R_i (inclusive), and will not be solved by any other contestants. The organizer will use these N problems in the two contests. Each problem must be used in exactly one of the contests, and each contest must have at least one problem. The _joyfulness_ of each contest is the number of contestants who will solve all the problems in the contest. Find the maximum possible total joyfulness of the two contests.
[{"input": "4\n 4 7\n 1 4\n 5 8\n 2 5", "output": "6\n \n\nThe optimal choice is:\n\n * Use Problem 1 and 3 in the first contest. Contestant 5, 6, and 7 will solve both of them, so the joyfulness of this contest is 3.\n * Use Problem 2 and 4 in the second contest. Contestant 2, 3, and 4 will solve both of them, so the joyfulness of this contest is 3.\n * The total joyfulness of these two contests is 6. We cannot make the total joyfulness greater than 6.\n\n* * *"}, {"input": "4\n 1 20\n 2 19\n 3 18\n 4 17", "output": "34\n \n\n* * *"}, {"input": "10\n 457835016 996058008\n 456475528 529149798\n 455108441 512701454\n 455817105 523506955\n 457368248 814532746\n 455073228 459494089\n 456651538 774276744\n 457667152 974637457\n 457293701 800549465\n 456580262 636471526", "output": "540049931"}]
Print the maximum possible total joyfulness of the two contests. * * *
s941111074
Runtime Error
p02874
Input is given from Standard Input in the following format: N L_1 R_1 L_2 R_2 \vdots L_N R_N
from bisect import * from collections import * from fractions import gcd from math import factorial from itertools import * from heapq import * N=int(input()) LR=[list(map(int,input().split())) for i in range(N)] for i in range(N): LR[i][1]+=1 value=max([R-L for L,R in LR]) #LR=sorted(LR,key=lambda x:x[1]) LR=sorted(LR,key=lambda x:x[0]*10**9+x[1]) a=2*(10**9) minRlst=[a for i in range(N)] minRlst[-1]=LR[-1][1] maxLlst=[0 for i in range(N)] maxLlst[0]=LR[0][0] for i in range(N-2,-1,-1): minRlst[i]=min(minRlst[i+1],LR[i][1]) for i in range(1,N): maxLlst[i]=max(minRlst[i-1],LR[i][0]) L1,R1=LR[0] L2,R2=LR[-1][0],minRlst[1] maxR=from bisect import * from collections import * from fractions import gcd from math import factorial from itertools import * from heapq import * N=int(input()) LR=[list(map(int,input().split())) for i in range(N)] for i in range(N): LR[i][1]+=1 value=max([R-L for L,R in LR]) #LR=sorted(LR,key=lambda x:x[1]) LR=sorted(LR,key=lambda x:x[0]*10**9+x[1]) a=2*(10**9) minRlst=[a for i in range(N)] minRlst[-1]=LR[-1][1] maxLlst=[0 for i in range(N)] maxLlst[0]=LR[0][0] for i in range(N-2,-1,-1): minRlst[i]=min(minRlst[i+1],LR[i][1]) for i in range(1,N): maxLlst[i]=min(minRlst[i-1],LR[i][0]) L1,R1=LR[0] L2,R2=LR[-1][0],minRlst[1] minR=min([R for L,R in LR]) for i in range(0,N-1): L,R=LR[i] a=max(R-L,0) b=max(minR-LR[-1][0],0) value=max(value,a+b) L1=L R1=min(R1,R) R2=minRlst[i+1] a=max(R1-L1,0) b=max(R2-L2,0) value=max(value,a+b) print(value) ([R for L,R in LR]) for i in range(0,N-1): L,R=LR[i] a=max(R-L,0) b=max(maxR-LR[-1][0],0) value=max(value,a+b) L1=L R1=min(R1,R) R2=minRlst[i+1] a=max(R1-L1,0) b=max(R2-L2,0) value=max(value,a+b) print(value)
Statement 10^9 contestants, numbered 1 to 10^9, will compete in a competition. There will be two contests in this competition. The organizer prepared N problems, numbered 1 to N, to use in these contests. When Problem i is presented in a contest, it will be solved by all contestants from Contestant L_i to Contestant R_i (inclusive), and will not be solved by any other contestants. The organizer will use these N problems in the two contests. Each problem must be used in exactly one of the contests, and each contest must have at least one problem. The _joyfulness_ of each contest is the number of contestants who will solve all the problems in the contest. Find the maximum possible total joyfulness of the two contests.
[{"input": "4\n 4 7\n 1 4\n 5 8\n 2 5", "output": "6\n \n\nThe optimal choice is:\n\n * Use Problem 1 and 3 in the first contest. Contestant 5, 6, and 7 will solve both of them, so the joyfulness of this contest is 3.\n * Use Problem 2 and 4 in the second contest. Contestant 2, 3, and 4 will solve both of them, so the joyfulness of this contest is 3.\n * The total joyfulness of these two contests is 6. We cannot make the total joyfulness greater than 6.\n\n* * *"}, {"input": "4\n 1 20\n 2 19\n 3 18\n 4 17", "output": "34\n \n\n* * *"}, {"input": "10\n 457835016 996058008\n 456475528 529149798\n 455108441 512701454\n 455817105 523506955\n 457368248 814532746\n 455073228 459494089\n 456651538 774276744\n 457667152 974637457\n 457293701 800549465\n 456580262 636471526", "output": "540049931"}]
Print the maximum possible total joyfulness of the two contests. * * *
s742817057
Wrong Answer
p02874
Input is given from Standard Input in the following format: N L_1 R_1 L_2 R_2 \vdots L_N R_N
def main(): import sys input = sys.stdin.readline n = int(input()) dg = 10**10 lr = [] for _ in [0] * n: lll, rrr = map(int, input().split()) lr.append(lll * dg + rrr) lr.sort() # mirl[i],marl[i]:R0~Riใฎmin,max mirl = [10**10] * n marl = [0] * n for i, e in enumerate(lr): mirl[i] = min(mirl[i - 1], e % dg) marl[i] = max(marl[i - 1], e % dg) # mirr[i]:Ri~Rn-1ใฎmin mirr = [0] * n mirr[-1] = lr[-1] % dg for i in range(n - 2, -1, -1): mirr[i] = min(mirr[i + 1], lr[i] % dg) L1 = lr[-1] // dg res = (lr[0] % dg - lr[0] // dg + 1) + max(0, mirr[1] - L1 + 1) for k in range(n - 2, 0, -1): # print(res) L2 = lr[k] // dg R1 = mirr[k + 1] R2 = lr[k] % dg restMaxR = marl[k - 1] restMinR = mirl[k - 1] # print(L1,L2,R1,R2,restMaxR,restMinR) tmp = max(0, min(restMaxR, R1) - L1 + 1) + max(0, min(restMinR, R2) - L2 + 1) tmp = max( tmp, max(0, min(restMinR, R1) - L1 + 1) + max(0, min(restMaxR, R2) - L2 + 1) ) tmp = max(tmp, max(0, R1 - L1 + 1) + max(0, min(restMinR, R2) - L2 + 1)) tmp = max(tmp, max(0, min(restMinR, R1) - L1 + 1), max(0, R2 - L2 + 1)) res = max(res, tmp) print(res) if __name__ == "__main__": main()
Statement 10^9 contestants, numbered 1 to 10^9, will compete in a competition. There will be two contests in this competition. The organizer prepared N problems, numbered 1 to N, to use in these contests. When Problem i is presented in a contest, it will be solved by all contestants from Contestant L_i to Contestant R_i (inclusive), and will not be solved by any other contestants. The organizer will use these N problems in the two contests. Each problem must be used in exactly one of the contests, and each contest must have at least one problem. The _joyfulness_ of each contest is the number of contestants who will solve all the problems in the contest. Find the maximum possible total joyfulness of the two contests.
[{"input": "4\n 4 7\n 1 4\n 5 8\n 2 5", "output": "6\n \n\nThe optimal choice is:\n\n * Use Problem 1 and 3 in the first contest. Contestant 5, 6, and 7 will solve both of them, so the joyfulness of this contest is 3.\n * Use Problem 2 and 4 in the second contest. Contestant 2, 3, and 4 will solve both of them, so the joyfulness of this contest is 3.\n * The total joyfulness of these two contests is 6. We cannot make the total joyfulness greater than 6.\n\n* * *"}, {"input": "4\n 1 20\n 2 19\n 3 18\n 4 17", "output": "34\n \n\n* * *"}, {"input": "10\n 457835016 996058008\n 456475528 529149798\n 455108441 512701454\n 455817105 523506955\n 457368248 814532746\n 455073228 459494089\n 456651538 774276744\n 457667152 974637457\n 457293701 800549465\n 456580262 636471526", "output": "540049931"}]
Print the maximum possible total joyfulness of the two contests. * * *
s809805778
Wrong Answer
p02874
Input is given from Standard Input in the following format: N L_1 R_1 L_2 R_2 \vdots L_N R_N
# -*- coding: utf-8 -*- import bisect import heapq import math import random import sys from collections import Counter, defaultdict, deque from decimal import ROUND_CEILING, ROUND_HALF_UP, Decimal from functools import lru_cache, reduce from itertools import combinations, combinations_with_replacement, product, permutations from operator import add, mul, sub sys.setrecursionlimit(100000) input = sys.stdin.readline INF = 2**62 - 1 def read_int(): return int(input()) def read_int_n(): return list(map(int, input().split())) def read_float(): return float(input()) def read_float_n(): return list(map(float, input().split())) def read_str(): return input().strip() def read_str_n(): return list(map(str, input().split())) def error_print(*args): print(*args, file=sys.stderr) def mt(f): import time def wrap(*args, **kwargs): s = time.time() ret = f(*args, **kwargs) e = time.time() error_print(e - s, "sec") return ret return wrap @mt def slv(N, LR): LR.sort(key=lambda x: x[1], reverse=True) LR.sort(key=lambda x: x[0]) lc = [] l = 0 r = INF for i in range(N): l_, r_ = LR[i] l = max(l, l_) r = min(r, r_) lc.append(max(0, r - l + 1)) rc = [] l = 0 r = INF for i in range(N - 1, -1, -1): l_, r_ = LR[i] l = max(l, l_) r = min(r, r_) rc.append(max(0, r - l + 1)) ans = 0 for i in range(N - 1): ans = max(ans, lc[i] + rc[N - 1 - 1 - i]) return ans def main(): N = read_int() LR = [read_int_n() for _ in range(N)] print(slv(N, LR)) if __name__ == "__main__": main()
Statement 10^9 contestants, numbered 1 to 10^9, will compete in a competition. There will be two contests in this competition. The organizer prepared N problems, numbered 1 to N, to use in these contests. When Problem i is presented in a contest, it will be solved by all contestants from Contestant L_i to Contestant R_i (inclusive), and will not be solved by any other contestants. The organizer will use these N problems in the two contests. Each problem must be used in exactly one of the contests, and each contest must have at least one problem. The _joyfulness_ of each contest is the number of contestants who will solve all the problems in the contest. Find the maximum possible total joyfulness of the two contests.
[{"input": "4\n 4 7\n 1 4\n 5 8\n 2 5", "output": "6\n \n\nThe optimal choice is:\n\n * Use Problem 1 and 3 in the first contest. Contestant 5, 6, and 7 will solve both of them, so the joyfulness of this contest is 3.\n * Use Problem 2 and 4 in the second contest. Contestant 2, 3, and 4 will solve both of them, so the joyfulness of this contest is 3.\n * The total joyfulness of these two contests is 6. We cannot make the total joyfulness greater than 6.\n\n* * *"}, {"input": "4\n 1 20\n 2 19\n 3 18\n 4 17", "output": "34\n \n\n* * *"}, {"input": "10\n 457835016 996058008\n 456475528 529149798\n 455108441 512701454\n 455817105 523506955\n 457368248 814532746\n 455073228 459494089\n 456651538 774276744\n 457667152 974637457\n 457293701 800549465\n 456580262 636471526", "output": "540049931"}]
Print the maximum possible total joyfulness of the two contests. * * *
s495756419
Accepted
p02874
Input is given from Standard Input in the following format: N L_1 R_1 L_2 R_2 \vdots L_N R_N
import sys stdin = sys.stdin sys.setrecursionlimit(10**7) def li(): return map(int, stdin.readline().split()) def li_(): return map(lambda x: int(x) - 1, stdin.readline().split()) def lf(): return map(float, stdin.readline().split()) def ls(): return stdin.readline().split() def ns(): return stdin.readline().rstrip() def lc(): return list(ns()) def ni(): return int(stdin.readline()) def nf(): return float(stdin.readline()) from operator import itemgetter n = ni() lefts = [] rights = [] intervals = [] for _ in range(n): l, r = li() r += 1 lefts.append(l) rights.append(r) intervals.append((l, r)) maxleft = max(lefts) minright = min(rights) ans = 0 ## (1)ๆœ€้ซ˜ใฎๅทฆ็ซฏใจๆœ€ไฝŽใฎๅณ็ซฏใŒๅŒใ˜้›†ๅˆใซใ‚ใ‚‹ใจใ # 1ๅŒบ้–“ใฎใฟใ‚’้ธๆŠž longest = 0 for l, r in intervals: if l == maxleft or r == minright: continue else: longest = max(longest, r - l) ans = longest + max(0, minright - maxleft) ## (2)ๆœ€้ซ˜ใฎๅทฆ็ซฏใจๆœ€ไฝŽใฎๅณ็ซฏใŒๅˆฅใฎ้›†ๅˆใซใ‚ใ‚‹ใจใ intervals = sorted( sorted(intervals, key=itemgetter(1), reverse=True), key=itemgetter(0) ) s_maxleft = [intervals[0][0]] s_minright = [intervals[0][1]] t_maxleft = [intervals[-1][0]] t_minright = [intervals[-1][1]] for idx, (l, r) in enumerate(intervals): if idx == 0: continue s_maxleft.append(max(s_maxleft[-1], l)) s_minright.append(min(s_minright[-1], r)) for idx, (l, r) in enumerate(intervals[::-1]): if idx == 0: continue t_maxleft.append(max(s_maxleft[-1], l)) t_minright.append(min(t_minright[-1], r)) t_maxleft = t_maxleft[::-1] t_minright = t_minright[::-1] for i in range(n - 1): ans = max( ans, max(0, s_minright[i] - s_maxleft[i]) + max(0, t_minright[i + 1] - t_maxleft[i + 1]), ) print(ans)
Statement 10^9 contestants, numbered 1 to 10^9, will compete in a competition. There will be two contests in this competition. The organizer prepared N problems, numbered 1 to N, to use in these contests. When Problem i is presented in a contest, it will be solved by all contestants from Contestant L_i to Contestant R_i (inclusive), and will not be solved by any other contestants. The organizer will use these N problems in the two contests. Each problem must be used in exactly one of the contests, and each contest must have at least one problem. The _joyfulness_ of each contest is the number of contestants who will solve all the problems in the contest. Find the maximum possible total joyfulness of the two contests.
[{"input": "4\n 4 7\n 1 4\n 5 8\n 2 5", "output": "6\n \n\nThe optimal choice is:\n\n * Use Problem 1 and 3 in the first contest. Contestant 5, 6, and 7 will solve both of them, so the joyfulness of this contest is 3.\n * Use Problem 2 and 4 in the second contest. Contestant 2, 3, and 4 will solve both of them, so the joyfulness of this contest is 3.\n * The total joyfulness of these two contests is 6. We cannot make the total joyfulness greater than 6.\n\n* * *"}, {"input": "4\n 1 20\n 2 19\n 3 18\n 4 17", "output": "34\n \n\n* * *"}, {"input": "10\n 457835016 996058008\n 456475528 529149798\n 455108441 512701454\n 455817105 523506955\n 457368248 814532746\n 455073228 459494089\n 456651538 774276744\n 457667152 974637457\n 457293701 800549465\n 456580262 636471526", "output": "540049931"}]
Print the maximum possible total joyfulness of the two contests. * * *
s762371724
Wrong Answer
p02874
Input is given from Standard Input in the following format: N L_1 R_1 L_2 R_2 \vdots L_N R_N
N = int(input()) aL, aR = map(int, input().split()) bL, bR = map(int, input().split()) k = 2 while k < N: cL, cR = map(int, input().split()) X = min([aR, cR]) - max([aL, cL]) + bR - bL Y = min([bR, cR]) - max([bL, cL]) + aR - aL Z = min([aR, bR]) - max([aL, bL]) + cR - cL W = max([X, Y, Z]) if X == W: aR = min([aR, cR]) aL = max([aL, cL]) elif Y == W: bR = min([bR, cR]) bL = max([bL, cL]) else: aR = min([aR, bR]) aL = max([aL, bL]) bR = cR bL = cL k += 1 print(aR + bR - aL - bL + 2)
Statement 10^9 contestants, numbered 1 to 10^9, will compete in a competition. There will be two contests in this competition. The organizer prepared N problems, numbered 1 to N, to use in these contests. When Problem i is presented in a contest, it will be solved by all contestants from Contestant L_i to Contestant R_i (inclusive), and will not be solved by any other contestants. The organizer will use these N problems in the two contests. Each problem must be used in exactly one of the contests, and each contest must have at least one problem. The _joyfulness_ of each contest is the number of contestants who will solve all the problems in the contest. Find the maximum possible total joyfulness of the two contests.
[{"input": "4\n 4 7\n 1 4\n 5 8\n 2 5", "output": "6\n \n\nThe optimal choice is:\n\n * Use Problem 1 and 3 in the first contest. Contestant 5, 6, and 7 will solve both of them, so the joyfulness of this contest is 3.\n * Use Problem 2 and 4 in the second contest. Contestant 2, 3, and 4 will solve both of them, so the joyfulness of this contest is 3.\n * The total joyfulness of these two contests is 6. We cannot make the total joyfulness greater than 6.\n\n* * *"}, {"input": "4\n 1 20\n 2 19\n 3 18\n 4 17", "output": "34\n \n\n* * *"}, {"input": "10\n 457835016 996058008\n 456475528 529149798\n 455108441 512701454\n 455817105 523506955\n 457368248 814532746\n 455073228 459494089\n 456651538 774276744\n 457667152 974637457\n 457293701 800549465\n 456580262 636471526", "output": "540049931"}]
Print the maximum possible total joyfulness of the two contests. * * *
s210925072
Wrong Answer
p02874
Input is given from Standard Input in the following format: N L_1 R_1 L_2 R_2 \vdots L_N R_N
import sys def length(L1, L2, R1, R2): L = max(L1, L2) R = min(R1, R2) return R - L + 1 def leng(L, R): return R - L + 1 N = int(input()) L = [0] * N R = [0] * N Max = 0 Max_i = 0 for i in range(N): L[i], R[i] = map(int, input().split()) if Max < R[i] - L[i] + 1: Max = R[i] - L[i] + 1 Max_i = i Min = 10**9 Min_i = 0 for i in range(N): if Min > (min(R[Max_i], R[i]) - max(L[Max_i], L[i])): Min = min(R[Max_i], R[i]) - max(L[Max_i], L[i]) Min_i = i left = [L[Max_i], R[Max_i]] right = [L[Min_i], R[Min_i]] for i in range(N): if length(L[i], left[0], R[i], left[1]) + leng(right[0], right[1]) > leng( left[0], left[1] ) + length(L[i], right[0], R[i], right[1]): left[0] = max(left[0], L[i]) left[1] = min(left[1], R[i]) else: right[0] = max(right[0], L[i]) right[1] = min(right[1], R[i]) if Max > leng(left[0], left[1]) + leng(right[0], right[1]): print(Max) sys.exit() print(leng(left[0], left[1]) + leng(right[0], right[1]))
Statement 10^9 contestants, numbered 1 to 10^9, will compete in a competition. There will be two contests in this competition. The organizer prepared N problems, numbered 1 to N, to use in these contests. When Problem i is presented in a contest, it will be solved by all contestants from Contestant L_i to Contestant R_i (inclusive), and will not be solved by any other contestants. The organizer will use these N problems in the two contests. Each problem must be used in exactly one of the contests, and each contest must have at least one problem. The _joyfulness_ of each contest is the number of contestants who will solve all the problems in the contest. Find the maximum possible total joyfulness of the two contests.
[{"input": "4\n 4 7\n 1 4\n 5 8\n 2 5", "output": "6\n \n\nThe optimal choice is:\n\n * Use Problem 1 and 3 in the first contest. Contestant 5, 6, and 7 will solve both of them, so the joyfulness of this contest is 3.\n * Use Problem 2 and 4 in the second contest. Contestant 2, 3, and 4 will solve both of them, so the joyfulness of this contest is 3.\n * The total joyfulness of these two contests is 6. We cannot make the total joyfulness greater than 6.\n\n* * *"}, {"input": "4\n 1 20\n 2 19\n 3 18\n 4 17", "output": "34\n \n\n* * *"}, {"input": "10\n 457835016 996058008\n 456475528 529149798\n 455108441 512701454\n 455817105 523506955\n 457368248 814532746\n 455073228 459494089\n 456651538 774276744\n 457667152 974637457\n 457293701 800549465\n 456580262 636471526", "output": "540049931"}]
Print the maximum possible total joyfulness of the two contests. * * *
s890887466
Wrong Answer
p02874
Input is given from Standard Input in the following format: N L_1 R_1 L_2 R_2 \vdots L_N R_N
n = int(input()) p = [] max_p = 1001001001 max_i = 0 max_len = 0 for i in range(n): l, r = map(int, input().split()) p.append([l, r]) if max_p > l: max_p = l max_i = i max_len = r - l elif max_p == l: if r - l > max_len: max_i = i max_len = r - l min_p = 0 min_i = 0 for i in range(n): dif = min(p[max_i][0] - p[i][0], 0) + min(p[i][1] - p[max_i][1], 0) if dif < min_p: min_p = dif min_i = i g1 = [] g2 = [] max_l = p[max_i][0] max_r = p[max_i][1] min_l = p[min_i][0] min_r = p[min_i][1] g1.append(p[max_i]) g2.append(p[min_i]) for i in range(n): if i == max_i or i == min_i: continue if min(max_l - p[i][0], 0) + min(p[i][1] - max_r, 0) < min( min_l - p[i][0], 0 ) + min(p[i][1] - min_r, 0): g2.append(p[i]) else: g1.append(p[i]) g1_l = 0 g1_r = 1001001001 g2_l = 0 g2_r = 1001001001 for i in range(len(g1)): if g1[i][0] > g1_l: g1_l = g1[i][0] if g1[i][1] < g1_r: g1_r = g1[i][1] for i in range(len(g2)): if g2[i][0] > g2_l: g2_l = g2[i][0] if g2[i][1] < g2_r: g2_r = g2[i][1] s_g1 = max(g1_r - g1_l + 1, 0) s_g2 = max(g2_r - g2_l + 1, 0) ans = s_g1 + s_g2 print(ans)
Statement 10^9 contestants, numbered 1 to 10^9, will compete in a competition. There will be two contests in this competition. The organizer prepared N problems, numbered 1 to N, to use in these contests. When Problem i is presented in a contest, it will be solved by all contestants from Contestant L_i to Contestant R_i (inclusive), and will not be solved by any other contestants. The organizer will use these N problems in the two contests. Each problem must be used in exactly one of the contests, and each contest must have at least one problem. The _joyfulness_ of each contest is the number of contestants who will solve all the problems in the contest. Find the maximum possible total joyfulness of the two contests.
[{"input": "4\n 4 7\n 1 4\n 5 8\n 2 5", "output": "6\n \n\nThe optimal choice is:\n\n * Use Problem 1 and 3 in the first contest. Contestant 5, 6, and 7 will solve both of them, so the joyfulness of this contest is 3.\n * Use Problem 2 and 4 in the second contest. Contestant 2, 3, and 4 will solve both of them, so the joyfulness of this contest is 3.\n * The total joyfulness of these two contests is 6. We cannot make the total joyfulness greater than 6.\n\n* * *"}, {"input": "4\n 1 20\n 2 19\n 3 18\n 4 17", "output": "34\n \n\n* * *"}, {"input": "10\n 457835016 996058008\n 456475528 529149798\n 455108441 512701454\n 455817105 523506955\n 457368248 814532746\n 455073228 459494089\n 456651538 774276744\n 457667152 974637457\n 457293701 800549465\n 456580262 636471526", "output": "540049931"}]
Print the maximum possible total joyfulness of the two contests. * * *
s836095078
Wrong Answer
p02874
Input is given from Standard Input in the following format: N L_1 R_1 L_2 R_2 \vdots L_N R_N
# -*- coding: utf-8 -*- """ Created on Sat Jun 15 22:01:38 2019 @author: aozora """ N, *L = map(int, open(0).read().split()) inf = [] ls = [] rs = [] fl = 0 fr = float("inf") for i, x in enumerate(zip(*[iter(L)] * 2)): l, r = x ls.append((l, i)) rs.append((r, i)) inf.append((l, r)) ls.sort() rs.sort(reverse=True) m = 0 x = rs[-1][0] - ls[-1][0] used = [False] * N l1 = -1 l2 = -2 r1 = -1 r2 = -2 while True: while l1 >= -N: i = ls[l1][1] if not used[i]: break l1 -= 1 else: break while r1 >= -N: i = rs[r1][1] if not used[i]: break r1 -= 1 else: break while l2 >= -N: i = ls[l2][1] if (not used[i]) and l1 > l2: break l2 -= 1 else: break while r2 >= -N: i = rs[r2][1] if (not used[i]) and r1 > r2: break r2 -= 1 else: break x = rs[r1][0] - ls[l1][0] + 1 fa = m + x ll, i = ls[l1] lr = inf[i][1] a = max(ll, fl) b = min(lr, fr) lm = b - a + 1 lx = rs[r1][0] - ls[l2][0] + 1 la = lm + lx rr, j = rs[r1] rl = inf[j][0] p = max(rl, fl) q = min(rr, fr) rm = q - p + 1 rx = rs[r2][0] - ls[l1][0] + 1 ra = rm + rx if la > ra: if la > fa: fl = a fr = b m = lm used[i] = True l1 -= 1 else: break else: if ra > fa: fl = p fr = q m = rm used[j] = True r1 -= 1 else: break first = [0, float("inf")] second = [0, float("inf")] for i, flag in enumerate(used): if flag: first[0] = max(first[0], inf[i][0]) first[1] = min(first[1], inf[i][1]) else: second[0] = max(second[0], inf[i][0]) second[1] = min(second[1], inf[i][1]) if float("inf") in first or float("inf") in second: print(0) else: ans = first[1] - first[0] + 1 + second[1] - second[0] + 1 print(max(0, ans))
Statement 10^9 contestants, numbered 1 to 10^9, will compete in a competition. There will be two contests in this competition. The organizer prepared N problems, numbered 1 to N, to use in these contests. When Problem i is presented in a contest, it will be solved by all contestants from Contestant L_i to Contestant R_i (inclusive), and will not be solved by any other contestants. The organizer will use these N problems in the two contests. Each problem must be used in exactly one of the contests, and each contest must have at least one problem. The _joyfulness_ of each contest is the number of contestants who will solve all the problems in the contest. Find the maximum possible total joyfulness of the two contests.
[{"input": "4\n 4 7\n 1 4\n 5 8\n 2 5", "output": "6\n \n\nThe optimal choice is:\n\n * Use Problem 1 and 3 in the first contest. Contestant 5, 6, and 7 will solve both of them, so the joyfulness of this contest is 3.\n * Use Problem 2 and 4 in the second contest. Contestant 2, 3, and 4 will solve both of them, so the joyfulness of this contest is 3.\n * The total joyfulness of these two contests is 6. We cannot make the total joyfulness greater than 6.\n\n* * *"}, {"input": "4\n 1 20\n 2 19\n 3 18\n 4 17", "output": "34\n \n\n* * *"}, {"input": "10\n 457835016 996058008\n 456475528 529149798\n 455108441 512701454\n 455817105 523506955\n 457368248 814532746\n 455073228 459494089\n 456651538 774276744\n 457667152 974637457\n 457293701 800549465\n 456580262 636471526", "output": "540049931"}]
Print the maximum possible total joyfulness of the two contests. * * *
s520914646
Wrong Answer
p02874
Input is given from Standard Input in the following format: N L_1 R_1 L_2 R_2 \vdots L_N R_N
N = int(input()) LR = [list(map(int, input().split())) for _ in range(N)] def myeval(arg): if arg[0] != None: L_tmp, R_tmp = arg[0] score = max(0, R_tmp - L_tmp + 1) else: score = 0 if arg[1] != None: L_tmp, R_tmp = arg[1] score += max(0, R_tmp - L_tmp + 1) else: score += 0 return score ans = [None, None] for i, (Li, Ri) in enumerate(LR): # print("#", ans, myeval(ans)) # add left ans_l = list(ans) if ans_l[0] != None: L_tmp, R_tmp = ans_l[0] else: L_tmp, R_tmp = (0, 10**9 + 7) ans_l[0] = (max(L_tmp, Li), min(R_tmp, Ri)) # add right ans_r = list(ans) if ans_r[1] != None: L_tmp, R_tmp = ans_r[1] else: L_tmp, R_tmp = (0, 10**9 + 7) ans_r[1] = (max(L_tmp, Li), min(R_tmp, Ri)) # evaluate score score_l = myeval(ans_l) score_r = myeval(ans_r) # judge if score_l < score_r: ans = list(ans_r) else: ans = list(ans_l) print(myeval(ans))
Statement 10^9 contestants, numbered 1 to 10^9, will compete in a competition. There will be two contests in this competition. The organizer prepared N problems, numbered 1 to N, to use in these contests. When Problem i is presented in a contest, it will be solved by all contestants from Contestant L_i to Contestant R_i (inclusive), and will not be solved by any other contestants. The organizer will use these N problems in the two contests. Each problem must be used in exactly one of the contests, and each contest must have at least one problem. The _joyfulness_ of each contest is the number of contestants who will solve all the problems in the contest. Find the maximum possible total joyfulness of the two contests.
[{"input": "4\n 4 7\n 1 4\n 5 8\n 2 5", "output": "6\n \n\nThe optimal choice is:\n\n * Use Problem 1 and 3 in the first contest. Contestant 5, 6, and 7 will solve both of them, so the joyfulness of this contest is 3.\n * Use Problem 2 and 4 in the second contest. Contestant 2, 3, and 4 will solve both of them, so the joyfulness of this contest is 3.\n * The total joyfulness of these two contests is 6. We cannot make the total joyfulness greater than 6.\n\n* * *"}, {"input": "4\n 1 20\n 2 19\n 3 18\n 4 17", "output": "34\n \n\n* * *"}, {"input": "10\n 457835016 996058008\n 456475528 529149798\n 455108441 512701454\n 455817105 523506955\n 457368248 814532746\n 455073228 459494089\n 456651538 774276744\n 457667152 974637457\n 457293701 800549465\n 456580262 636471526", "output": "540049931"}]
Print the maximum possible total joyfulness of the two contests. * * *
s575176357
Wrong Answer
p02874
Input is given from Standard Input in the following format: N L_1 R_1 L_2 R_2 \vdots L_N R_N
import sys input = sys.stdin.readline ri = lambda: int(input()) rs = lambda: input().rstrip() ril = lambda: list(map(int, input().split())) rsl = lambda: input().rstrip().split() ris = lambda n: [ri() for _ in range(n)] rss = lambda n: [rs() for _ in range(n)] rils = lambda n: [ril() for _ in range(n)] rsls = lambda n: [rsl() for _ in range(n)] n = ri() ls = rils(n) res = max(r - l + 1 for l, r in ls) ls.sort(key=lambda x: x[1]) lmax0 = [ls[0][0]] rmin0 = [ls[0][1]] for i in range(1, n - 1): lmax0.append(max(lmax0[-1], ls[i][0])) rmin0.append(min(rmin0[-1], ls[i][1])) lmax1 = [ls[-1][0]] rmin1 = [ls[-1][1]] for i in range(1, n - 1): lmax1.append(max(lmax1[-1], ls[n - i - 1][0])) rmin1.append(min(rmin1[-1], ls[n - i - 1][1])) s0 = [max(0, r - l + 1) for l, r in zip(lmax0, rmin0)] s1 = [max(0, r - l + 1) for l, r in zip(lmax1, rmin1)] for x, y in zip(s0, reversed(s1)): res = max(res, x + y) ls.sort(key=lambda x: x[0]) lmax0 = [ls[0][0]] rmin0 = [ls[0][1]] for i in range(1, n - 1): lmax0.append(max(lmax0[-1], ls[i][0])) rmin0.append(min(rmin0[-1], ls[i][1])) lmax1 = [ls[-1][0]] rmin1 = [ls[-1][1]] for i in range(1, n - 1): lmax1.append(max(lmax1[-1], ls[n - i - 1][0])) rmin1.append(min(rmin1[-1], ls[n - i - 1][1])) s0 = [max(0, r - l + 1) for l, r in zip(lmax0, rmin0)] s1 = [max(0, r - l + 1) for l, r in zip(lmax1, rmin1)] for x, y in zip(s0, reversed(s1)): res = max(res, x + y) ls.sort(key=lambda x: -x[1]) lmax0 = [ls[0][0]] rmin0 = [ls[0][1]] for i in range(1, n - 1): lmax0.append(max(lmax0[-1], ls[i][0])) rmin0.append(min(rmin0[-1], ls[i][1])) lmax1 = [ls[-1][0]] rmin1 = [ls[-1][1]] for i in range(1, n - 1): lmax1.append(max(lmax1[-1], ls[n - i - 1][0])) rmin1.append(min(rmin1[-1], ls[n - i - 1][1])) s0 = [max(0, r - l + 1) for l, r in zip(lmax0, rmin0)] s1 = [max(0, r - l + 1) for l, r in zip(lmax1, rmin1)] for x, y in zip(s0, reversed(s1)): res = max(res, x + y) ls.sort(key=lambda x: -x[0]) lmax0 = [ls[0][0]] rmin0 = [ls[0][1]] for i in range(1, n - 1): lmax0.append(max(lmax0[-1], ls[i][0])) rmin0.append(min(rmin0[-1], ls[i][1])) lmax1 = [ls[-1][0]] rmin1 = [ls[-1][1]] for i in range(1, n - 1): lmax1.append(max(lmax1[-1], ls[n - i - 1][0])) rmin1.append(min(rmin1[-1], ls[n - i - 1][1])) s0 = [max(0, r - l + 1) for l, r in zip(lmax0, rmin0)] s1 = [max(0, r - l + 1) for l, r in zip(lmax1, rmin1)] for x, y in zip(s0, reversed(s1)): res = max(res, x + y) print(res)
Statement 10^9 contestants, numbered 1 to 10^9, will compete in a competition. There will be two contests in this competition. The organizer prepared N problems, numbered 1 to N, to use in these contests. When Problem i is presented in a contest, it will be solved by all contestants from Contestant L_i to Contestant R_i (inclusive), and will not be solved by any other contestants. The organizer will use these N problems in the two contests. Each problem must be used in exactly one of the contests, and each contest must have at least one problem. The _joyfulness_ of each contest is the number of contestants who will solve all the problems in the contest. Find the maximum possible total joyfulness of the two contests.
[{"input": "4\n 4 7\n 1 4\n 5 8\n 2 5", "output": "6\n \n\nThe optimal choice is:\n\n * Use Problem 1 and 3 in the first contest. Contestant 5, 6, and 7 will solve both of them, so the joyfulness of this contest is 3.\n * Use Problem 2 and 4 in the second contest. Contestant 2, 3, and 4 will solve both of them, so the joyfulness of this contest is 3.\n * The total joyfulness of these two contests is 6. We cannot make the total joyfulness greater than 6.\n\n* * *"}, {"input": "4\n 1 20\n 2 19\n 3 18\n 4 17", "output": "34\n \n\n* * *"}, {"input": "10\n 457835016 996058008\n 456475528 529149798\n 455108441 512701454\n 455817105 523506955\n 457368248 814532746\n 455073228 459494089\n 456651538 774276744\n 457667152 974637457\n 457293701 800549465\n 456580262 636471526", "output": "540049931"}]
Print the maximum possible total joyfulness of the two contests. * * *
s813396392
Wrong Answer
p02874
Input is given from Standard Input in the following format: N L_1 R_1 L_2 R_2 \vdots L_N R_N
n = int(input()) lis = [list(map(int, input().split())) for i in range(n)] lis.sort(key=lambda x: x[1], reverse=True) lis.sort(key=lambda x: x[0]) left = lis.pop(0) lis.sort(key=lambda x: x[1], reverse=True) right = lis.pop(0) for i in range(n - 2): now_left = left[1] - left[0] + 1 now_right = right[1] - right[0] + 1 will_left = max(0, min(left[1], lis[i][1]) - max(left[0], lis[i][0]) + 1) will_right = max(0, min(right[1], lis[i][1]) - max(right[0], lis[i][0]) + 1) lost_left = now_left - will_left lost_right = now_right - will_right if lost_left > lost_right: right[1] = min(right[1], lis[i][1]) right[0] = max(right[0], lis[i][0]) else: left[0] = max(left[0], lis[i][0]) left[1] = min(left[1], lis[i][1]) print(max(0, left[1] - left[0] + 1) + max(0, right[1] - right[0] + 1))
Statement 10^9 contestants, numbered 1 to 10^9, will compete in a competition. There will be two contests in this competition. The organizer prepared N problems, numbered 1 to N, to use in these contests. When Problem i is presented in a contest, it will be solved by all contestants from Contestant L_i to Contestant R_i (inclusive), and will not be solved by any other contestants. The organizer will use these N problems in the two contests. Each problem must be used in exactly one of the contests, and each contest must have at least one problem. The _joyfulness_ of each contest is the number of contestants who will solve all the problems in the contest. Find the maximum possible total joyfulness of the two contests.
[{"input": "4\n 4 7\n 1 4\n 5 8\n 2 5", "output": "6\n \n\nThe optimal choice is:\n\n * Use Problem 1 and 3 in the first contest. Contestant 5, 6, and 7 will solve both of them, so the joyfulness of this contest is 3.\n * Use Problem 2 and 4 in the second contest. Contestant 2, 3, and 4 will solve both of them, so the joyfulness of this contest is 3.\n * The total joyfulness of these two contests is 6. We cannot make the total joyfulness greater than 6.\n\n* * *"}, {"input": "4\n 1 20\n 2 19\n 3 18\n 4 17", "output": "34\n \n\n* * *"}, {"input": "10\n 457835016 996058008\n 456475528 529149798\n 455108441 512701454\n 455817105 523506955\n 457368248 814532746\n 455073228 459494089\n 456651538 774276744\n 457667152 974637457\n 457293701 800549465\n 456580262 636471526", "output": "540049931"}]
Print how many sequences satisfy the conditions, modulo 10^9+7. * * *
s766226663
Runtime Error
p03766
Input is given from Standard Input in the following format: n
import numpy as np n = int(input()) if n == 1: print(1) else: res_v = np.zeros(n + 1, dtype="int64") res_v_cumsum = np.zeros(n + 1, dtype="int64") res_v[0] = 0 res_v[1] = 1 res_v[2] = 1 res_v_cumsum[0] = 0 res_v_cumsum[1] = 1 res_v_cumsum[2] = 2 M = 1000000007 for k in range(3, n): res_v[k] = (1 + res_v_cumsum[k - 1] - res_v[k - 2]) % M res_v_cumsum[k] = (res_v_cumsum[k - 1] + res_v[k]) % M print( ( ((res_v_cumsum[n - 2] * (((n - 1) * (n - 1)) % M)) % M) + ((res_v_cumsum[n - 1] * (n - 1)) % M) + n + (n - 1) * (n - 1) % M ) % M )
Statement How many infinite sequences a_1, a_2, ... consisting of {{1, ... ,n}} satisfy the following conditions? * The n-th and subsequent elements are all equal. That is, if n \leq i,j, a_i = a_j. * For every integer i, the a_i elements immediately following the i-th element are all equal. That is, if i < j < k\leq i+a_i, a_j = a_k. Find the count modulo 10^9+7.
[{"input": "2", "output": "4\n \n\nThe four sequences that satisfy the conditions are:\n\n * 1, 1, 1, ...\n * 1, 2, 2, ...\n * 2, 1, 1, ...\n * 2, 2, 2, ...\n\n* * *"}, {"input": "654321", "output": "968545283"}]
Print how many sequences satisfy the conditions, modulo 10^9+7. * * *
s289278549
Runtime Error
p03766
Input is given from Standard Input in the following format: n
import sys readline = sys.stdin.readline MOD = 10**9 + 7 N = int(readline()) dp1 = [0] * (N + 1) Dp1 = [0] * (N + 1) dp2 = [0] * (N + 1) Dp2 = [0] * (N + 1) dp1[0] = 1 Dp1[0] = 1 dp2[0] = N - 1 Dp2[0] = N - 1 dp1[1] = N - 1 dp2[1] = (N - 1) ** 2 dp1[2] = N - 1 dp2[2] = (N - 1) ** 2 Dp1[1] = Dp1[0] + dp1[1] Dp2[1] = Dp2[0] + dp2[1] Dp1[2] = Dp1[1] + dp1[2] Dp2[2] = Dp2[1] + dp2[2] for i in range(3, N + 1): dp1[i] = (dp1[i - 1] + Dp1[i - 3] - 1) % MOD dp2[i] = (dp2[i - 1] + Dp2[i - 3]) % MOD Dp1[i] = (Dp1[i - 1] + dp1[i]) % MOD Dp2[i] = (Dp2[i - 1] + dp2[i]) % MOD print((Dp1[N - 1] + Dp2[N - 1]) % MOD)
Statement How many infinite sequences a_1, a_2, ... consisting of {{1, ... ,n}} satisfy the following conditions? * The n-th and subsequent elements are all equal. That is, if n \leq i,j, a_i = a_j. * For every integer i, the a_i elements immediately following the i-th element are all equal. That is, if i < j < k\leq i+a_i, a_j = a_k. Find the count modulo 10^9+7.
[{"input": "2", "output": "4\n \n\nThe four sequences that satisfy the conditions are:\n\n * 1, 1, 1, ...\n * 1, 2, 2, ...\n * 2, 1, 1, ...\n * 2, 2, 2, ...\n\n* * *"}, {"input": "654321", "output": "968545283"}]
Print how many sequences satisfy the conditions, modulo 10^9+7. * * *
s536254117
Runtime Error
p03766
Input is given from Standard Input in the following format: n
MOD = 10**9 + 7 n = int(input()) dp = [0 for _ in range(n + 1)] dp[0], dp[1], dp[2] = 1, 1, 1 cum = [0 for _ in range(n + 1)] cum[0], cum[1], cum[2] = 1, 2, 3 for i in range(3, n + 1): dp[i] = (dp[i - 1] + cum[i - 3]) % MOD cum[i] = (cum[i - 1] + dp[i]) % MOD ans = cum[n - 2] * (n - 1) * (n - 1) + dp[n - 1] * (n - 1) + cum[n - 2] * (n - 1) + 1 print(ans % MOD)
Statement How many infinite sequences a_1, a_2, ... consisting of {{1, ... ,n}} satisfy the following conditions? * The n-th and subsequent elements are all equal. That is, if n \leq i,j, a_i = a_j. * For every integer i, the a_i elements immediately following the i-th element are all equal. That is, if i < j < k\leq i+a_i, a_j = a_k. Find the count modulo 10^9+7.
[{"input": "2", "output": "4\n \n\nThe four sequences that satisfy the conditions are:\n\n * 1, 1, 1, ...\n * 1, 2, 2, ...\n * 2, 1, 1, ...\n * 2, 2, 2, ...\n\n* * *"}, {"input": "654321", "output": "968545283"}]
Print how many sequences satisfy the conditions, modulo 10^9+7. * * *
s132073990
Runtime Error
p03766
Input is given from Standard Input in the following format: n
n = int(input()) mod = 10**9 + 7 dp = [0] * (n + 1) S = [0] * (n + 1) dp[0] = 1 dp[1] = 1 dp[2] = 1 S[0] = 1 for i in range(n): if i + 1 >= 3: dp[i + 1] = 2 * dp[i] - dp[i - 1] + dp[i - 2] dp[i + 1] %= mod S[i + 1] = S[i] + (n - 1) * dp[i] S[i + 1] %= mod ans = S[n] for i in range(1, n): ans += ((n - 1) ** 2) * dp[i - 1] ans %= mod print(ans) # print(S) # print(dp)
Statement How many infinite sequences a_1, a_2, ... consisting of {{1, ... ,n}} satisfy the following conditions? * The n-th and subsequent elements are all equal. That is, if n \leq i,j, a_i = a_j. * For every integer i, the a_i elements immediately following the i-th element are all equal. That is, if i < j < k\leq i+a_i, a_j = a_k. Find the count modulo 10^9+7.
[{"input": "2", "output": "4\n \n\nThe four sequences that satisfy the conditions are:\n\n * 1, 1, 1, ...\n * 1, 2, 2, ...\n * 2, 1, 1, ...\n * 2, 2, 2, ...\n\n* * *"}, {"input": "654321", "output": "968545283"}]
Print how many sequences satisfy the conditions, modulo 10^9+7. * * *
s583215265
Runtime Error
p03766
Input is given from Standard Input in the following format: n
#!/usr/bin/env python3 # -*- coding: utf-8 -*- from random import * def readln(): _res = list(map(int, str(input()).split(" "))) return _res p = 1000000000 + 7 n = readln()[0] f = [0 for i in range(0, n + 1)] f[1] = n f[2] = n * n s = f[:] s[2] = f[1] + f[2] for i in range(3, n + 1): f[i] = f[i - 1] + (n - 1) * (n - 1) f[i] = f[i] + s[i - 3] + (n - i + 2) f[i] = f[i] % p s[i] = s[i - 1] + f[i] s[i] = s[i] % p print(f[n])
Statement How many infinite sequences a_1, a_2, ... consisting of {{1, ... ,n}} satisfy the following conditions? * The n-th and subsequent elements are all equal. That is, if n \leq i,j, a_i = a_j. * For every integer i, the a_i elements immediately following the i-th element are all equal. That is, if i < j < k\leq i+a_i, a_j = a_k. Find the count modulo 10^9+7.
[{"input": "2", "output": "4\n \n\nThe four sequences that satisfy the conditions are:\n\n * 1, 1, 1, ...\n * 1, 2, 2, ...\n * 2, 1, 1, ...\n * 2, 2, 2, ...\n\n* * *"}, {"input": "654321", "output": "968545283"}]
Print how many sequences satisfy the conditions, modulo 10^9+7. * * *
s241458769
Accepted
p03766
Input is given from Standard Input in the following format: n
n = int(input()) a, b, c, p = 1, 1, n, n - 1 for i in range(n - 1): p += a - 1 a, b, c = b, c, ((n - 1) ** 2 + p + c) % (10**9 + 7) print(c)
Statement How many infinite sequences a_1, a_2, ... consisting of {{1, ... ,n}} satisfy the following conditions? * The n-th and subsequent elements are all equal. That is, if n \leq i,j, a_i = a_j. * For every integer i, the a_i elements immediately following the i-th element are all equal. That is, if i < j < k\leq i+a_i, a_j = a_k. Find the count modulo 10^9+7.
[{"input": "2", "output": "4\n \n\nThe four sequences that satisfy the conditions are:\n\n * 1, 1, 1, ...\n * 1, 2, 2, ...\n * 2, 1, 1, ...\n * 2, 2, 2, ...\n\n* * *"}, {"input": "654321", "output": "968545283"}]
In the first line, print the number that would be kept by Takahashi eventually; in the second line, print the number that would be kept by Aoki eventually. Those numbers should be represented in binary and printed as strings consisting of `0` and `1` that begin with `1`. * * *
s136219885
Runtime Error
p03336
Input is given from Standard Input in the following format: N M K S T
# Meet n, m, k = input().split() n = int(n) m = int(m) k = int(k) def bitwise_and(a, b): temp = [0 for i in range(32)] for i in range(32): if a[i] == 0 or b[i] == 0: temp[i] = 0 else: temp[i] = 1 return temp def bitwise_sum(a, b): temp = [0 for i in range(32)] carry = 0 for i in range(31, -1, -1): if a[i] + b[i] + carry == 2: temp[i] = 0 carry = 1 elif a[i] + b[i] + carry == 3: temp[i] = 1 carry = 1 elif a[i] + b[i] + carry == 1: temp[i] = 1 carry = 0 elif a[i] + b[i] + carry == 0: temp[i] = 0 carry = 0 return temp s = list(input()) t = list(input()) a = [0 for i in range(32)] b = [0 for i in range(32)] for i in range(n): a[31 - i] = int(s[n - 1 - i]) for i in range(m): b[31 - i] = int(t[m - 1 - i]) # print(a) # print(b) for i in range(k): temp = bitwise_and(a, b) a = bitwise_sum(a, temp) b = bitwise_sum(b, temp) # print(a) # print(b) s_a = "" s_b = "" flag = 0 for i in a: if i == 1: flag = 1 if flag: s_a += str(i) flag = 0 for i in b: if i == 1: flag = 1 if flag: s_b += str(i) # print(a) # print(b) print(s_a) print(s_b)
Statement Takahashi and Aoki love calculating things, so they will play with numbers now. First, they came up with one positive integer each. Takahashi came up with X, and Aoki came up with Y. Then, they will enjoy themselves by repeating the following operation K times: * Compute the bitwise AND of the number currently kept by Takahashi and the number currently kept by Aoki. Let Z be the result. * Then, add Z to both of the numbers kept by Takahashi and Aoki. However, it turns out that even for the two math maniacs this is just too much work. Could you find the number that would be kept by Takahashi and the one that would be kept by Aoki eventually? Note that input and output are done in binary. Especially, X and Y are given as strings S and T of length N and M consisting of `0` and `1`, respectively, whose initial characters are guaranteed to be `1`.
[{"input": "2 3 3\n 11\n 101", "output": "10000\n 10010\n \n\nThe values of X and Y after each operation are as follows:\n\n * After the first operation: (X,Y)=(4,6).\n * After the second operation: (X,Y)=(8,10).\n * After the third operation: (X,Y)=(16,18).\n\n* * *"}, {"input": "5 8 3\n 10101\n 10101001", "output": "100000\n 10110100\n \n\n* * *"}, {"input": "10 10 10\n 1100110011\n 1011001101", "output": "10000100000010001000\n 10000100000000100010"}]
In the first line, print the number that would be kept by Takahashi eventually; in the second line, print the number that would be kept by Aoki eventually. Those numbers should be represented in binary and printed as strings consisting of `0` and `1` that begin with `1`. * * *
s123065480
Wrong Answer
p03336
Input is given from Standard Input in the following format: N M K S T
n, m, k = map(int, input().split()) s = int(input()) t = int(input()) def bitwise(n, m): c = 0 i = 0 while n >= 1 and m >= 1: an = n % (10**1) am = m % (10**1) if an == 1 and am == 1: c += 10**i n = (n - an) / 10 m = (m - am) / 10 i += 1 return c def two_ten(n): z = 0 c = 0 while n >= 1: if n % 10 == 1: z += 2**c n -= 1 n /= 10 c += 1 return z def ten_two(n): z = 0 c = 0 while n >= 1: if n % 2 == 1: z += 10**c n -= 1 n /= 2 c += 1 return z while k > 0: z = bitwise(s, t) s10 = two_ten(s) + two_ten(z) t10 = two_ten(t) + two_ten(z) s = ten_two(s10) t = ten_two(t10) k -= 1 print(s) print(t)
Statement Takahashi and Aoki love calculating things, so they will play with numbers now. First, they came up with one positive integer each. Takahashi came up with X, and Aoki came up with Y. Then, they will enjoy themselves by repeating the following operation K times: * Compute the bitwise AND of the number currently kept by Takahashi and the number currently kept by Aoki. Let Z be the result. * Then, add Z to both of the numbers kept by Takahashi and Aoki. However, it turns out that even for the two math maniacs this is just too much work. Could you find the number that would be kept by Takahashi and the one that would be kept by Aoki eventually? Note that input and output are done in binary. Especially, X and Y are given as strings S and T of length N and M consisting of `0` and `1`, respectively, whose initial characters are guaranteed to be `1`.
[{"input": "2 3 3\n 11\n 101", "output": "10000\n 10010\n \n\nThe values of X and Y after each operation are as follows:\n\n * After the first operation: (X,Y)=(4,6).\n * After the second operation: (X,Y)=(8,10).\n * After the third operation: (X,Y)=(16,18).\n\n* * *"}, {"input": "5 8 3\n 10101\n 10101001", "output": "100000\n 10110100\n \n\n* * *"}, {"input": "10 10 10\n 1100110011\n 1011001101", "output": "10000100000010001000\n 10000100000000100010"}]
Print the number of possible pairs that he may have had. * * *
s523120939
Runtime Error
p03418
Input is given from Standard Input in the following format: N K
#include <iostream> #include <string> #include <sstream> #include <vector> #include <iomanip> #include <iterator> #include <algorithm> #include <functional> #include <typeinfo> #include <utility> #include <tuple> #include <queue> #include <deque> using namespace std; #define repr(i, a, b) for (int i = (int)(a); i < (int)(b); i++) #define rep(i, n) repr(i, 0, n) #define reprrev(i, a, b) for (int i = (int)(b) - 1; i >= (int)(a); i--) #define reprev(i, n) reprrev(i, 0, n) #define mp(a, b) make_pair(a, b) #define all(vec) (vec).begin(), (vec).end() #define yn(formula) (formula) ? (cout << "Yes" << endl) : (cout << "No" << endl) #define YN(formula) (formula) ? (cout << "YES" << endl) : (cout << "NO" << endl) #define MIN(a, b) ((a) < (b)) ? (a) : (b) typedef long long ll; typedef pair<int, int> pii; typedef pair<ll, ll> pll; typedef vector<int> vi; typedef vector<ll> vll; typedef vector<bool> vb; typedef vector<char> vc; typedef vector<string> vs; typedef vector<pii> vp; typedef vector<pll> vpl; typedef vector<vi> vvi; typedef vector<vll> vvl; typedef vector<vb> vvb; typedef vector<vc> vvc; typedef vector<vs> vvs; typedef vector<vp> vvp; typedef vector<vpl> vvpl; constexpr double PI = 3.14159265358979323846; constexpr ll INF = 1 << 29; constexpr ll MOD = (ll)1e9 + 7; constexpr double EPS = 1e-7; constexpr int dy[4] = { 0, 1, 0, -1 }; constexpr int dx[4] = { 1, 0, -1, 0 }; struct edge { ll to; ll cost; }; /*<ใ“ใ“ใ‹ใ‚‰>***********************************************************/ int main() { int N, K; cin >> N >> K; int ans = 0; repr(i, 1, N + 1) { ans += N / i * max(0, i - K); ans += max(0, N % i - K + 1); } cout << ans << endl; return 0; }
Statement Takahashi had a pair of two positive integers not exceeding N, (a,b), which he has forgotten. He remembers that the remainder of a divided by b was greater than or equal to K. Find the number of possible pairs that he may have had.
[{"input": "5 2", "output": "7\n \n\nThere are seven possible pairs: (2,3),(5,3),(2,4),(3,4),(2,5),(3,5) and (4,5).\n\n* * *"}, {"input": "10 0", "output": "100\n \n\n* * *"}, {"input": "31415 9265", "output": "287927211"}]
Print the number of possible pairs that he may have had. * * *
s263512463
Runtime Error
p03418
Input is given from Standard Input in the following format: N K
N, K = map(int, input().split()) cnt = 0 for b in range(K+1, N+1): if N % b == 0: cnt += (b-K)*(N//b) + max((N - (N //b) * b) - K , 0) else cnt += (b - K) * (N // b) + max((N - (N // b) * b) - K+1, 0) print(cnt)
Statement Takahashi had a pair of two positive integers not exceeding N, (a,b), which he has forgotten. He remembers that the remainder of a divided by b was greater than or equal to K. Find the number of possible pairs that he may have had.
[{"input": "5 2", "output": "7\n \n\nThere are seven possible pairs: (2,3),(5,3),(2,4),(3,4),(2,5),(3,5) and (4,5).\n\n* * *"}, {"input": "10 0", "output": "100\n \n\n* * *"}, {"input": "31415 9265", "output": "287927211"}]
Print the number of possible pairs that he may have had. * * *
s299114931
Runtime Error
p03418
Input is given from Standard Input in the following format: N K
n,k = map(int,input().split()) if k == 0: print(n**2) else: total = 0 for i in range(k+1,n+1): d,m = divmod(n,i) if (i-k) > 0: total += d*(i-k) if (m-k+1) > 0: total += m-k+1 print(total)
Statement Takahashi had a pair of two positive integers not exceeding N, (a,b), which he has forgotten. He remembers that the remainder of a divided by b was greater than or equal to K. Find the number of possible pairs that he may have had.
[{"input": "5 2", "output": "7\n \n\nThere are seven possible pairs: (2,3),(5,3),(2,4),(3,4),(2,5),(3,5) and (4,5).\n\n* * *"}, {"input": "10 0", "output": "100\n \n\n* * *"}, {"input": "31415 9265", "output": "287927211"}]
Print the number of possible pairs that he may have had. * * *
s107631058
Runtime Error
p03418
Input is given from Standard Input in the following format: N K
n, k = list(map(int, input().split())) ans = 0 if k = 0: ans = n * n else: for b in range(k + 1, n + 1): ans += n // b * (b - k) ans += max(0, (n - (n // b * b)) - k + 1) print(ans)
Statement Takahashi had a pair of two positive integers not exceeding N, (a,b), which he has forgotten. He remembers that the remainder of a divided by b was greater than or equal to K. Find the number of possible pairs that he may have had.
[{"input": "5 2", "output": "7\n \n\nThere are seven possible pairs: (2,3),(5,3),(2,4),(3,4),(2,5),(3,5) and (4,5).\n\n* * *"}, {"input": "10 0", "output": "100\n \n\n* * *"}, {"input": "31415 9265", "output": "287927211"}]
Print the number of possible pairs that he may have had. * * *
s845530368
Runtime Error
p03418
Input is given from Standard Input in the following format: N K
n, k = map(int, input().split()) ans = 0 # N = pb + r for b in range(k+1,n+1): p = n//b r = n%b ans += p * max(0,b-k) + max(0, r-k+1) if k==0: ans -= n print(
Statement Takahashi had a pair of two positive integers not exceeding N, (a,b), which he has forgotten. He remembers that the remainder of a divided by b was greater than or equal to K. Find the number of possible pairs that he may have had.
[{"input": "5 2", "output": "7\n \n\nThere are seven possible pairs: (2,3),(5,3),(2,4),(3,4),(2,5),(3,5) and (4,5).\n\n* * *"}, {"input": "10 0", "output": "100\n \n\n* * *"}, {"input": "31415 9265", "output": "287927211"}]
Print the number of possible pairs that he may have had. * * *
s029293009
Runtime Error
p03418
Input is given from Standard Input in the following format: N K
n, k = map(int, input().split()) if k == 0: print(n**2) exit() ans = 0 for b in range(k+1, n+1): p = n//b r = n%b ans += p*(b-k)-1 ans += max(0, r-k+1) print(ans)
Statement Takahashi had a pair of two positive integers not exceeding N, (a,b), which he has forgotten. He remembers that the remainder of a divided by b was greater than or equal to K. Find the number of possible pairs that he may have had.
[{"input": "5 2", "output": "7\n \n\nThere are seven possible pairs: (2,3),(5,3),(2,4),(3,4),(2,5),(3,5) and (4,5).\n\n* * *"}, {"input": "10 0", "output": "100\n \n\n* * *"}, {"input": "31415 9265", "output": "287927211"}]
Print the number of possible pairs that he may have had. * * *
s198195979
Accepted
p03418
Input is given from Standard Input in the following format: N K
import sys import heapq import re from itertools import permutations from bisect import bisect_left, bisect_right from collections import Counter, deque from fractions import gcd from math import factorial, sqrt, ceil from functools import lru_cache, reduce INF = 1 << 60 MOD = 1000000007 sys.setrecursionlimit(10**7) # UnionFind class UnionFind: def __init__(self, n): self.n = n self.parents = [-1] * n def find(self, x): if self.parents[x] < 0: return x else: self.parents[x] = self.find(self.parents[x]) return self.parents[x] def union(self, x, y): x = self.find(x) y = self.find(y) if x == y: return if self.parents[x] > self.parents[y]: x, y = y, x self.parents[x] += self.parents[y] self.parents[y] = x def size(self, x): return -self.parents[self.find(x)] def same(self, x, y): return self.find(x) == self.find(y) def members(self, x): root = self.find(x) return [i for i in range(self.n) if self.find(i) == root] def roots(self): return [i for i, x in enumerate(self.parents) if x < 0] def group_count(self): return len(self.roots()) def all_group_members(self): return {r: self.members(r) for r in self.roots()} def __str__(self): return "\n".join("{}: {}".format(r, self.members(r)) for r in self.roots()) def is_prime(n): if n == 1: return False for i in range(2, int(n**0.5) + 1): if n % i == 0: return False return True # ใƒฏใƒผใ‚ทใƒฃใƒซใƒ•ใƒญใ‚คใƒ‰ (ไปปๆ„ใฎ2้ ‚็‚นใฎๅฏพใซๅฏพใ—ใฆๆœ€็Ÿญ็ตŒ่ทฏใ‚’ๆฑ‚ใ‚ใ‚‹) # ่จˆ็ฎ—้‡n^3 (nใฏ้ ‚็‚นใฎๆ•ฐ) def warshall_floyd(d, n): # d[i][j]: iใ‹ใ‚‰jใธใฎๆœ€็Ÿญ่ท้›ข for k in range(n): for i in range(n): for j in range(n): d[i][j] = min(d[i][j], d[i][k] + d[k][j]) return d # ใƒ€ใ‚คใ‚ฏใ‚นใƒˆใƒฉ def dijkstra_heap(s, edge, n): # ๅง‹็‚นsใ‹ใ‚‰ๅ„้ ‚็‚นใธใฎๆœ€็Ÿญ่ท้›ข d = [10**20] * n used = [True] * n # True:ๆœช็ขบๅฎš d[s] = 0 used[s] = False edgelist = [] for a, b in edge[s]: heapq.heappush(edgelist, a * (10**6) + b) while len(edgelist): minedge = heapq.heappop(edgelist) # ใพใ ไฝฟใ‚ใ‚Œใฆใชใ„้ ‚็‚นใฎไธญใ‹ใ‚‰ๆœ€ๅฐใฎ่ท้›ขใฎใ‚‚ใฎใ‚’ๆŽขใ™ if not used[minedge % (10**6)]: continue v = minedge % (10**6) d[v] = minedge // (10**6) used[v] = False for e in edge[v]: if used[e[1]]: heapq.heappush(edgelist, (e[0] + d[v]) * (10**6) + e[1]) return d # ็ด ๅ› ๆ•ฐๅˆ†่งฃ 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 # 2ๆ•ฐใฎๆœ€ๅฐๅ…ฌๅ€ๆ•ฐ def lcm(x, y): return (x * y) // gcd(x, y) # ใƒชใ‚นใƒˆใฎ่ฆ็ด ใฎๆœ€ๅฐๅ…ฌๅ€ๆ•ฐ def lcm_list(numbers): return reduce(lcm, numbers, 1) # ใƒชใ‚นใƒˆใฎ่ฆ็ด ใฎๆœ€ๅคงๅ…ฌ็ด„ๆ•ฐ def gcd_list(numbers): return reduce(gcd, numbers) # ็ด ๆ•ฐๅˆคๅฎš # limitไปฅไธ‹ใฎ็ด ๆ•ฐใ‚’ๅˆ—ๆŒ™ def eratosthenes(limit): A = [i for i in range(2, limit + 1)] P = [] while True: prime = min(A) if prime > sqrt(limit): break P.append(prime) i = 0 while i < len(A): if A[i] % prime == 0: A.pop(i) continue i += 1 for a in A: P.append(a) return P # ๅŒใ˜ใ‚‚ใฎใ‚’ๅซใ‚€้ †ๅˆ— def permutation_with_duplicates(L): if L == []: return [[]] else: ret = [] # set๏ผˆ้›†ๅˆ๏ผ‰ๅž‹ใง้‡่ค‡ใ‚’ๅ‰Š้™คใ€ใ‚ฝใƒผใƒˆ S = sorted(set(L)) for i in S: data = L[:] data.remove(i) for j in permutation_with_duplicates(data): ret.append([i] + j) return ret # ใ“ใ“ใ‹ใ‚‰ๆ›ธใๅง‹ใ‚ใ‚‹ n, k = map(int, input().split()) if k == 0: print(n**2) else: ans = 0 for b in range(k + 1, n + 1): ans += n // b * (b - k) ans += max(n % b - (k - 1), 0) print(ans)
Statement Takahashi had a pair of two positive integers not exceeding N, (a,b), which he has forgotten. He remembers that the remainder of a divided by b was greater than or equal to K. Find the number of possible pairs that he may have had.
[{"input": "5 2", "output": "7\n \n\nThere are seven possible pairs: (2,3),(5,3),(2,4),(3,4),(2,5),(3,5) and (4,5).\n\n* * *"}, {"input": "10 0", "output": "100\n \n\n* * *"}, {"input": "31415 9265", "output": "287927211"}]
Print the number of possible pairs that he may have had. * * *
s203318607
Wrong Answer
p03418
Input is given from Standard Input in the following format: N K
# -*- coding: utf-8 -*- ############# # Libraries # ############# import sys input = sys.stdin.readline import math # from math import gcd import bisect from collections import defaultdict from collections import deque from functools import lru_cache ############# # Constants # ############# MOD = 10**9 + 7 INF = float("inf") ############# # Functions # ############# ######INPUT###### def I(): return int(input().strip()) def S(): return input().strip() def IL(): return list(map(int, input().split())) def SL(): return list(map(str, input().split())) def ILs(n): return list(int(input()) for _ in range(n)) def SLs(n): return list(input().strip() for _ in range(n)) def ILL(n): return [list(map(int, input().split())) for _ in range(n)] def SLL(n): return [list(map(str, input().split())) for _ in range(n)] ######OUTPUT###### def P(arg): print(arg) return def Y(): print("Yes") return def N(): print("No") return def E(): exit() def PE(arg): print(arg) exit() def YE(): print("Yes") exit() def NE(): print("No") exit() #####Shorten##### def DD(arg): return defaultdict(arg) #####Inverse##### def inv(n): return pow(n, MOD - 2, MOD) ######Combination###### kaijo_memo = [] def kaijo(n): if len(kaijo_memo) > n: return kaijo_memo[n] if len(kaijo_memo) == 0: kaijo_memo.append(1) while len(kaijo_memo) <= n: kaijo_memo.append(kaijo_memo[-1] * len(kaijo_memo) % MOD) return kaijo_memo[n] gyaku_kaijo_memo = [] def gyaku_kaijo(n): if len(gyaku_kaijo_memo) > n: return gyaku_kaijo_memo[n] if len(gyaku_kaijo_memo) == 0: gyaku_kaijo_memo.append(1) while len(gyaku_kaijo_memo) <= n: gyaku_kaijo_memo.append( gyaku_kaijo_memo[-1] * pow(len(gyaku_kaijo_memo), MOD - 2, MOD) % MOD ) return gyaku_kaijo_memo[n] def nCr(n, r): if n == r: return 1 if n < r or r < 0: return 0 ret = 1 ret = ret * kaijo(n) % MOD ret = ret * gyaku_kaijo(r) % MOD ret = ret * gyaku_kaijo(n - r) % MOD return ret ######Factorization###### def factorization(n): arr = [] temp = n for i in range(2, int(-(-(n**0.5) // 1)) + 1): if temp % i == 0: cnt = 0 while temp % i == 0: cnt += 1 temp //= i arr.append([i, cnt]) if temp != 1: arr.append([temp, 1]) if arr == []: arr.append([n, 1]) return arr #####MakeDivisors###### def make_divisors(n): divisors = [] for i in range(1, int(n**0.5) + 1): if n % i == 0: divisors.append(i) if i != n // i: divisors.append(n // i) return divisors #####GCD##### def gcd(a, b): while b: a, b = b, a % b return a #####LCM##### def lcm(a, b): return a * b // gcd(a, b) #####BitCount##### def count_bit(n): count = 0 while n: n &= n - 1 count += 1 return count #####ChangeBase##### def base_10_to_n(X, n): if X // n: return base_10_to_n(X // n, n) + [X % n] return [X % n] def base_n_to_10(X, n): return sum(int(str(X)[-i - 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, K = IL() ans = 0 for i in range(K + 1, N + 1): ans += (N // i) * (i - K) + max(((N % i) - K + 1), 0) print(ans)
Statement Takahashi had a pair of two positive integers not exceeding N, (a,b), which he has forgotten. He remembers that the remainder of a divided by b was greater than or equal to K. Find the number of possible pairs that he may have had.
[{"input": "5 2", "output": "7\n \n\nThere are seven possible pairs: (2,3),(5,3),(2,4),(3,4),(2,5),(3,5) and (4,5).\n\n* * *"}, {"input": "10 0", "output": "100\n \n\n* * *"}, {"input": "31415 9265", "output": "287927211"}]
Print the number of possible pairs that he may have had. * * *
s257098865
Runtime Error
p03418
Input is given from Standard Input in the following format: N K
data = input() data = data.split(" ") n = int(data[0]) k = int(data[1]) sum = 0 for b in range(1, n+1): sum += (n//b*max(0,b-k)+max(0,n%b-k+1)) if k == 0: sum-=n print(sum)
Statement Takahashi had a pair of two positive integers not exceeding N, (a,b), which he has forgotten. He remembers that the remainder of a divided by b was greater than or equal to K. Find the number of possible pairs that he may have had.
[{"input": "5 2", "output": "7\n \n\nThere are seven possible pairs: (2,3),(5,3),(2,4),(3,4),(2,5),(3,5) and (4,5).\n\n* * *"}, {"input": "10 0", "output": "100\n \n\n* * *"}, {"input": "31415 9265", "output": "287927211"}]
Print the number of possible pairs that he may have had. * * *
s351665794
Runtime Error
p03418
Input is given from Standard Input in the following format: N K
n,k=map(int,input().split()) if k==0: print(n**2) exit() c=0 for b in range(1:n+1): c+=max(b-k,0)*(n//b) c+=max(n%b-k+1,0) print(c)
Statement Takahashi had a pair of two positive integers not exceeding N, (a,b), which he has forgotten. He remembers that the remainder of a divided by b was greater than or equal to K. Find the number of possible pairs that he may have had.
[{"input": "5 2", "output": "7\n \n\nThere are seven possible pairs: (2,3),(5,3),(2,4),(3,4),(2,5),(3,5) and (4,5).\n\n* * *"}, {"input": "10 0", "output": "100\n \n\n* * *"}, {"input": "31415 9265", "output": "287927211"}]
Print the answer. * * *
s521627797
Accepted
p03048
Input is given from Standard Input in the following format: R G B N
#!/usr/bin/env python import os import sys from io import BytesIO, IOBase from typing import List class Solution: def numSubarrayProductLessThanK(self, nums: List[int], k: int) -> int: left = 0 ans, prod = 0, 1 lenght = 0 for num in nums: if prod * num >= k: prod *= num lenght += 1 while prod >= k: prod //= nums[left] left += 1 lenght -= 1 ans += lenght else: prod *= num lenght += 1 ans += lenght # print(ans) return ans def main() -> None: r, g, b, n = map(int, input().split()) cnt = 0 for i in range(0, n + 1, r): for j in range(0, n + 1, g): k = n - i - j if k % b != 0: continue # k //= b if i + j + k == n and k >= 0: cnt += 1 # print(i, j, k ) print(cnt) # region fastio BUFSIZE = 8192 class FastIO(IOBase): newlines = 0 def __init__(self, file): self._fd = file.fileno() self.buffer = BytesIO() self.writable = "x" in file.mode or "r" not in file.mode self.write = self.buffer.write if self.writable else None def read(self): while True: b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE)) if not b: break ptr = self.buffer.tell() self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr) self.newlines = 0 return self.buffer.read() def readline(self, **kwargs): while self.newlines == 0: b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE)) self.newlines = b.count(b"\n") + (not b) ptr = self.buffer.tell() self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr) self.newlines -= 1 return self.buffer.readline() def flush(self): if self.writable: os.write(self._fd, self.buffer.getvalue()) self.buffer.truncate(0), self.buffer.seek(0) class IOWrapper(IOBase): def __init__(self, file): self.buffer = FastIO(file) self.flush = self.buffer.flush self.writable = self.buffer.writable self.write = lambda s: self.buffer.write(s.encode("ascii")) self.read = lambda: self.buffer.read().decode("ascii") self.readline = lambda: self.buffer.readline().decode("ascii") sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout) input = lambda: sys.stdin.readline().rstrip("\r\n") # endregion if __name__ == "__main__": main()
Statement Snuke has come to a store that sells boxes containing balls. The store sells the following three kinds of boxes: * Red boxes, each containing R red balls * Green boxes, each containing G green balls * Blue boxes, each containing B blue balls Snuke wants to get a total of exactly N balls by buying r red boxes, g green boxes and b blue boxes. How many triples of non-negative integers (r,g,b) achieve this?
[{"input": "1 2 3 4", "output": "4\n \n\nFour triples achieve the objective, as follows:\n\n * (4,0,0)\n * (2,1,0)\n * (1,0,1)\n * (0,2,0)\n\n* * *"}, {"input": "13 1 4 3000", "output": "87058"}]
Print the answer. * * *
s810389155
Wrong Answer
p03048
Input is given from Standard Input in the following format: R G B N
x = input() xx = x.split() R = int(xx[0]) G = int(xx[1]) B = int(xx[2]) N = int(xx[3]) b = 0 for r in (1, R + 1): for g in (1, G + 1): for b in (1, B + 1): if r + g + b == N: b += 1 print(b)
Statement Snuke has come to a store that sells boxes containing balls. The store sells the following three kinds of boxes: * Red boxes, each containing R red balls * Green boxes, each containing G green balls * Blue boxes, each containing B blue balls Snuke wants to get a total of exactly N balls by buying r red boxes, g green boxes and b blue boxes. How many triples of non-negative integers (r,g,b) achieve this?
[{"input": "1 2 3 4", "output": "4\n \n\nFour triples achieve the objective, as follows:\n\n * (4,0,0)\n * (2,1,0)\n * (1,0,1)\n * (0,2,0)\n\n* * *"}, {"input": "13 1 4 3000", "output": "87058"}]
Print the answer. * * *
s295088992
Accepted
p03048
Input is given from Standard Input in the following format: R G B N
r, g, b, n = map(int, input().split()) if r >= g and g >= b: pass elif r >= b and b >= g: temp = g g = b b = temp else: temp = r r = g g = temp if (r == 1 and g == 1) or (r == 1 and b == 1) or (g == 1 and b == 1): rg = [i + 1 for i in range(n + 1)] elif ( (r == 1 and g == 2) or (r == 1 and b == 2) or (g == 1 and b == 2) or (r == 2 and g == 1) or (r == 2 and b == 1) or (g == 2 and b == 1) ): rg = [1 + i // 2 for i in range(n + 1)] else: rg = [0 for _ in range(n + 1)] ri = 0 while ri <= n: gi = 0 while gi <= n - ri: rg[ri + gi] += 1 gi += g ri += r bi = 0 result = 0 while bi <= n: total = rg[n - bi] result += total bi += b print(result)
Statement Snuke has come to a store that sells boxes containing balls. The store sells the following three kinds of boxes: * Red boxes, each containing R red balls * Green boxes, each containing G green balls * Blue boxes, each containing B blue balls Snuke wants to get a total of exactly N balls by buying r red boxes, g green boxes and b blue boxes. How many triples of non-negative integers (r,g,b) achieve this?
[{"input": "1 2 3 4", "output": "4\n \n\nFour triples achieve the objective, as follows:\n\n * (4,0,0)\n * (2,1,0)\n * (1,0,1)\n * (0,2,0)\n\n* * *"}, {"input": "13 1 4 3000", "output": "87058"}]
Print the answer. * * *
s756998908
Runtime Error
p03048
Input is given from Standard Input in the following format: R G B N
N = int(input()) AB_number = 0 ab_cnt = 0 a_cnt = 0 b_cnt = 0 for _ in range(N): s_i = input() AB_number += s_i.count("AB") if s_i[0] == "B" and s_i[-1] == "A": ab_cnt += 1 elif s_i[-1] == "A": a_cnt += 1 elif s_i[0] == "B": b_cnt += 1 if ab_cnt == 0: print(AB_number + min(a_cnt, b_cnt)) print(AB_number + min(a_cnt, b_cnt) - 1) elif a_cnt != b_cnt: print(AB_number + (ab_cnt - 1) + 1 + min(a_cnt, b_cnt)) else: print(AB_number + (ab_cnt - 1) + min(a_cnt, b_cnt))
Statement Snuke has come to a store that sells boxes containing balls. The store sells the following three kinds of boxes: * Red boxes, each containing R red balls * Green boxes, each containing G green balls * Blue boxes, each containing B blue balls Snuke wants to get a total of exactly N balls by buying r red boxes, g green boxes and b blue boxes. How many triples of non-negative integers (r,g,b) achieve this?
[{"input": "1 2 3 4", "output": "4\n \n\nFour triples achieve the objective, as follows:\n\n * (4,0,0)\n * (2,1,0)\n * (1,0,1)\n * (0,2,0)\n\n* * *"}, {"input": "13 1 4 3000", "output": "87058"}]
Print the answer. * * *
s625090817
Runtime Error
p03048
Input is given from Standard Input in the following format: R G B N
n = int(input()) s = [input() for i in range(n)] ans = 0 A = 0 B = 0 BA = 0 for i in s: ans += i.count("AB") if i[0:1] != "B" and i[-1:] == "A": A += 1 elif i[0:1] == "B" and i[-1:] != "A": B += 1 elif i[0:1] == "B" and i[-1:] == "A": BA += 1 # print(ans) # print(A,B,BA) while 1: if BA == 0 or A == B: break if A >= B: B += 1 else: A += 1 BA -= 1 # print(A,B,BA) if A == 0 and B == 0: BA -= 1 print(ans + min(A, B) + BA)
Statement Snuke has come to a store that sells boxes containing balls. The store sells the following three kinds of boxes: * Red boxes, each containing R red balls * Green boxes, each containing G green balls * Blue boxes, each containing B blue balls Snuke wants to get a total of exactly N balls by buying r red boxes, g green boxes and b blue boxes. How many triples of non-negative integers (r,g,b) achieve this?
[{"input": "1 2 3 4", "output": "4\n \n\nFour triples achieve the objective, as follows:\n\n * (4,0,0)\n * (2,1,0)\n * (1,0,1)\n * (0,2,0)\n\n* * *"}, {"input": "13 1 4 3000", "output": "87058"}]
Print the answer. * * *
s571282126
Wrong Answer
p03048
Input is given from Standard Input in the following format: R G B N
def a(R, G, B, N): b = 0 for r in (1, R + 1): for g in (1, G + 1): for b in (1, B + 1): if r + g + b == N: b += 1 return b
Statement Snuke has come to a store that sells boxes containing balls. The store sells the following three kinds of boxes: * Red boxes, each containing R red balls * Green boxes, each containing G green balls * Blue boxes, each containing B blue balls Snuke wants to get a total of exactly N balls by buying r red boxes, g green boxes and b blue boxes. How many triples of non-negative integers (r,g,b) achieve this?
[{"input": "1 2 3 4", "output": "4\n \n\nFour triples achieve the objective, as follows:\n\n * (4,0,0)\n * (2,1,0)\n * (1,0,1)\n * (0,2,0)\n\n* * *"}, {"input": "13 1 4 3000", "output": "87058"}]
Print the answer. * * *
s337015391
Accepted
p03048
Input is given from Standard Input in the following format: R G B N
r, g, b, n = [int(i) for i in input().split()] total = 0 rm = n // r for rn in range(rm + 1): gm = (n - rn * r) // g for gn in range(gm + 1): bd = n - r * rn - g * gn if bd % b == 0: total += 1 print(total)
Statement Snuke has come to a store that sells boxes containing balls. The store sells the following three kinds of boxes: * Red boxes, each containing R red balls * Green boxes, each containing G green balls * Blue boxes, each containing B blue balls Snuke wants to get a total of exactly N balls by buying r red boxes, g green boxes and b blue boxes. How many triples of non-negative integers (r,g,b) achieve this?
[{"input": "1 2 3 4", "output": "4\n \n\nFour triples achieve the objective, as follows:\n\n * (4,0,0)\n * (2,1,0)\n * (1,0,1)\n * (0,2,0)\n\n* * *"}, {"input": "13 1 4 3000", "output": "87058"}]
Print the answer. * * *
s769620912
Accepted
p03048
Input is given from Standard Input in the following format: R G B N
# -*- coding: utf-8 -*- # input # a = int(input()) # a = input() a, b, c, d = map(int, input().split()) # a, b, c = input().split() o = 0 for i in range((d // a) + 1): for j in range(((d - a * i) // b) + 1): if (d - a * i - b * j) % c == 0: o += 1 # output print(o)
Statement Snuke has come to a store that sells boxes containing balls. The store sells the following three kinds of boxes: * Red boxes, each containing R red balls * Green boxes, each containing G green balls * Blue boxes, each containing B blue balls Snuke wants to get a total of exactly N balls by buying r red boxes, g green boxes and b blue boxes. How many triples of non-negative integers (r,g,b) achieve this?
[{"input": "1 2 3 4", "output": "4\n \n\nFour triples achieve the objective, as follows:\n\n * (4,0,0)\n * (2,1,0)\n * (1,0,1)\n * (0,2,0)\n\n* * *"}, {"input": "13 1 4 3000", "output": "87058"}]
Print the answer. * * *
s861633940
Accepted
p03048
Input is given from Standard Input in the following format: R G B N
def li(): return list(map(int, input().split())) def combination2(a, b, n): # print('call 2: ', a, b, n) com2 = 0 a_quot = n // a + 1 for j in range(a_quot): com2 = com2 + combination1(b, n - j * a) return com2 def combination1(a, n): # print('call 1: ', a, n) if n % a == 0: return 1 else: return 0 [r, g, b, n] = li() r_quot = n // r + 1 com_num = 0 for i in range(r_quot): com_num = com_num + combination2(g, b, n - i * r) print(com_num)
Statement Snuke has come to a store that sells boxes containing balls. The store sells the following three kinds of boxes: * Red boxes, each containing R red balls * Green boxes, each containing G green balls * Blue boxes, each containing B blue balls Snuke wants to get a total of exactly N balls by buying r red boxes, g green boxes and b blue boxes. How many triples of non-negative integers (r,g,b) achieve this?
[{"input": "1 2 3 4", "output": "4\n \n\nFour triples achieve the objective, as follows:\n\n * (4,0,0)\n * (2,1,0)\n * (1,0,1)\n * (0,2,0)\n\n* * *"}, {"input": "13 1 4 3000", "output": "87058"}]
Print the answer as an integer. * * *
s105875154
Wrong Answer
p02659
Input is given from Standard Input in the following format: A B
N = list(map(float, input().split())) print(int(N[0] * N[1]))
Statement Compute A \times B, truncate its fractional part, and print the result as an integer.
[{"input": "198 1.10", "output": "217\n \n\nWe have 198 \\times 1.10 = 217.8. After truncating the fractional part, we have\nthe answer: 217.\n\n* * *"}, {"input": "1 0.01", "output": "0\n \n\n* * *"}, {"input": "1000000000000000 9.99", "output": "9990000000000000"}]
Print the answer as an integer. * * *
s691622921
Wrong Answer
p02659
Input is given from Standard Input in the following format: A B
A, B = 999990000000010, 9.90 B_ = int(B * 100) C = str(A * B_) D = C[:-2] E = C[-2:] D, E if E == "00": print(D) else: print(D + "." + E)
Statement Compute A \times B, truncate its fractional part, and print the result as an integer.
[{"input": "198 1.10", "output": "217\n \n\nWe have 198 \\times 1.10 = 217.8. After truncating the fractional part, we have\nthe answer: 217.\n\n* * *"}, {"input": "1 0.01", "output": "0\n \n\n* * *"}, {"input": "1000000000000000 9.99", "output": "9990000000000000"}]
Print the answer as an integer. * * *
s515255031
Wrong Answer
p02659
Input is given from Standard Input in the following format: A B
lst = [i for i in input().split()] x = int(lst[0]) y = float(lst[1]) y *= 1000 # y = int(y) z = x * y z //= 1000 print(z)
Statement Compute A \times B, truncate its fractional part, and print the result as an integer.
[{"input": "198 1.10", "output": "217\n \n\nWe have 198 \\times 1.10 = 217.8. After truncating the fractional part, we have\nthe answer: 217.\n\n* * *"}, {"input": "1 0.01", "output": "0\n \n\n* * *"}, {"input": "1000000000000000 9.99", "output": "9990000000000000"}]
Print the answer as an integer. * * *
s309422371
Runtime Error
p02659
Input is given from Standard Input in the following format: A B
A, B = input().split() for x in (A, B): if float(x) == int(float(x)): x = int(x) else: x = float(x) def dicimal2int(d): d = str(d) if "." not in d: return int(d), 0 if d[:2] == "0.": for i in range(2, len(d)): if d[i] != "0": break n_move = len(d) - 2 return int(d[i:]), n_move idx = d.index(".") n_move = len(d) - idx - 1 return int(d[:idx] + d[idx + 1 :]), n_move C1, n1 = dicimal2int(A) C2, n2 = dicimal2int(B) D = C1 * C2 n = n1 + n2 if n == 0: print(D) exit() def int2dicimal(N, n_move): if n_move == 0: return N N = str(N) for i in range(len(N)): if N[-i - 1] != "0": break n_zero = i if n_zero > n_move: return int(N[:-n_move]) if n_zero > 0: N = N[:-n_zero] n_move -= n_zero if len(N) - 1 >= n_move: return float(N[:-n_move] + "." + N[-n_move:]) return float("0." + "0" * (n_move - len(N)) + N) print(int(int2dicimal(D, n)))
Statement Compute A \times B, truncate its fractional part, and print the result as an integer.
[{"input": "198 1.10", "output": "217\n \n\nWe have 198 \\times 1.10 = 217.8. After truncating the fractional part, we have\nthe answer: 217.\n\n* * *"}, {"input": "1 0.01", "output": "0\n \n\n* * *"}, {"input": "1000000000000000 9.99", "output": "9990000000000000"}]
Print the answer as an integer. * * *
s963317428
Wrong Answer
p02659
Input is given from Standard Input in the following format: A B
z = [] x, y = map(float, input().split()) a = (x * (y * 100)) / 100 b = str(a) head, sep, tail = b.partition(".") print(int(head))
Statement Compute A \times B, truncate its fractional part, and print the result as an integer.
[{"input": "198 1.10", "output": "217\n \n\nWe have 198 \\times 1.10 = 217.8. After truncating the fractional part, we have\nthe answer: 217.\n\n* * *"}, {"input": "1 0.01", "output": "0\n \n\n* * *"}, {"input": "1000000000000000 9.99", "output": "9990000000000000"}]
Print the answer as an integer. * * *
s897115046
Wrong Answer
p02659
Input is given from Standard Input in the following format: A B
import math S = input().split() buf = -2 for n, i in enumerate(S): if i == "0": buf = 0 if buf != 0: for n, i in enumerate(S): if n == 0: buf = float(i) else: buf = buf * float(i) buf = math.floor(buf * 10) / 10 buf = math.floor(buf) print(buf)
Statement Compute A \times B, truncate its fractional part, and print the result as an integer.
[{"input": "198 1.10", "output": "217\n \n\nWe have 198 \\times 1.10 = 217.8. After truncating the fractional part, we have\nthe answer: 217.\n\n* * *"}, {"input": "1 0.01", "output": "0\n \n\n* * *"}, {"input": "1000000000000000 9.99", "output": "9990000000000000"}]
Print the answer as an integer. * * *
s154684362
Wrong Answer
p02659
Input is given from Standard Input in the following format: A B
m = input("") list = m.split(" ") if len(list) == 2: s1 = list[0].split(".") s2 = list[1].split(".") if len(s2) != 1: if ( len(s1) == 1 and len(s2[1]) == 2 and eval(list[0]) >= 0 and eval(list[0]) <= 10**15 and eval(list[1]) >= 0 and eval(list[1]) < 10 ): num = eval(list[0]) * eval(list[1]) print(int(num))
Statement Compute A \times B, truncate its fractional part, and print the result as an integer.
[{"input": "198 1.10", "output": "217\n \n\nWe have 198 \\times 1.10 = 217.8. After truncating the fractional part, we have\nthe answer: 217.\n\n* * *"}, {"input": "1 0.01", "output": "0\n \n\n* * *"}, {"input": "1000000000000000 9.99", "output": "9990000000000000"}]
Print the answer as an integer. * * *
s390193542
Wrong Answer
p02659
Input is given from Standard Input in the following format: A B
strA, strB = input().split() A, B = int(strA), float(strB) print(int(A * (B * 100) / 100))
Statement Compute A \times B, truncate its fractional part, and print the result as an integer.
[{"input": "198 1.10", "output": "217\n \n\nWe have 198 \\times 1.10 = 217.8. After truncating the fractional part, we have\nthe answer: 217.\n\n* * *"}, {"input": "1 0.01", "output": "0\n \n\n* * *"}, {"input": "1000000000000000 9.99", "output": "9990000000000000"}]
Print the answer as an integer. * * *
s344160018
Wrong Answer
p02659
Input is given from Standard Input in the following format: A B
x, y = map(str, input().split()) x = int(x) y = float(y) y = int(y * 100) prod = x * y prod = prod / 100.0 ans = int(prod) print(ans)
Statement Compute A \times B, truncate its fractional part, and print the result as an integer.
[{"input": "198 1.10", "output": "217\n \n\nWe have 198 \\times 1.10 = 217.8. After truncating the fractional part, we have\nthe answer: 217.\n\n* * *"}, {"input": "1 0.01", "output": "0\n \n\n* * *"}, {"input": "1000000000000000 9.99", "output": "9990000000000000"}]
Print the answer as an integer. * * *
s491136898
Runtime Error
p02659
Input is given from Standard Input in the following format: A B
L = map(int, input().split()) prod = int(L[0] * L[1]) print(prod)
Statement Compute A \times B, truncate its fractional part, and print the result as an integer.
[{"input": "198 1.10", "output": "217\n \n\nWe have 198 \\times 1.10 = 217.8. After truncating the fractional part, we have\nthe answer: 217.\n\n* * *"}, {"input": "1 0.01", "output": "0\n \n\n* * *"}, {"input": "1000000000000000 9.99", "output": "9990000000000000"}]
Print the answer as an integer. * * *
s596645539
Wrong Answer
p02659
Input is given from Standard Input in the following format: A B
t = [x for x in input().split()] a = int(t[0]) b = float(t[1]) print(int(b * a))
Statement Compute A \times B, truncate its fractional part, and print the result as an integer.
[{"input": "198 1.10", "output": "217\n \n\nWe have 198 \\times 1.10 = 217.8. After truncating the fractional part, we have\nthe answer: 217.\n\n* * *"}, {"input": "1 0.01", "output": "0\n \n\n* * *"}, {"input": "1000000000000000 9.99", "output": "9990000000000000"}]
Print the answer as an integer. * * *
s655977761
Accepted
p02659
Input is given from Standard Input in the following format: A B
print(int((s := input())[:-4]) * int(s[-4] + s[-2:]) // 100)
Statement Compute A \times B, truncate its fractional part, and print the result as an integer.
[{"input": "198 1.10", "output": "217\n \n\nWe have 198 \\times 1.10 = 217.8. After truncating the fractional part, we have\nthe answer: 217.\n\n* * *"}, {"input": "1 0.01", "output": "0\n \n\n* * *"}, {"input": "1000000000000000 9.99", "output": "9990000000000000"}]
Print the answer as an integer. * * *
s939385451
Wrong Answer
p02659
Input is given from Standard Input in the following format: A B
val = eval(input().replace(" ", "*")) print(str(val).split(".")[0])
Statement Compute A \times B, truncate its fractional part, and print the result as an integer.
[{"input": "198 1.10", "output": "217\n \n\nWe have 198 \\times 1.10 = 217.8. After truncating the fractional part, we have\nthe answer: 217.\n\n* * *"}, {"input": "1 0.01", "output": "0\n \n\n* * *"}, {"input": "1000000000000000 9.99", "output": "9990000000000000"}]
Print the answer as an integer. * * *
s667943926
Accepted
p02659
Input is given from Standard Input in the following format: A B
a, b = map(float, input().split()) aa = int(a) % 10000000 a = int(a) // 10000000 c = round(b * int(a) * 100) cc = round(b * int(aa) * 100) cc /= 100 cc = int(cc) print(c * 100000 + cc)
Statement Compute A \times B, truncate its fractional part, and print the result as an integer.
[{"input": "198 1.10", "output": "217\n \n\nWe have 198 \\times 1.10 = 217.8. After truncating the fractional part, we have\nthe answer: 217.\n\n* * *"}, {"input": "1 0.01", "output": "0\n \n\n* * *"}, {"input": "1000000000000000 9.99", "output": "9990000000000000"}]
Print the answer as an integer. * * *
s775727083
Accepted
p02659
Input is given from Standard Input in the following format: A B
A, B = input().split() A = A[::-1] B = str(B[0] + B[2] + B[3])[::-1] ans = [0] * 20 for i in range(len(B)): for j in range(i, len(A) + i): ans[j] += int(A[j - i]) * int(B[i]) for i in range(19): ans[i + 1] += ans[i] // 10 ans[i] = ans[i] % 10 ans = ans[2:] ans = "".join([str(a) for a in ans])[::-1] print(int(ans))
Statement Compute A \times B, truncate its fractional part, and print the result as an integer.
[{"input": "198 1.10", "output": "217\n \n\nWe have 198 \\times 1.10 = 217.8. After truncating the fractional part, we have\nthe answer: 217.\n\n* * *"}, {"input": "1 0.01", "output": "0\n \n\n* * *"}, {"input": "1000000000000000 9.99", "output": "9990000000000000"}]
Print the answer as an integer. * * *
s392674655
Wrong Answer
p02659
Input is given from Standard Input in the following format: A B
arg = input().split() print(int(float(arg[1]) * int(arg[0])))
Statement Compute A \times B, truncate its fractional part, and print the result as an integer.
[{"input": "198 1.10", "output": "217\n \n\nWe have 198 \\times 1.10 = 217.8. After truncating the fractional part, we have\nthe answer: 217.\n\n* * *"}, {"input": "1 0.01", "output": "0\n \n\n* * *"}, {"input": "1000000000000000 9.99", "output": "9990000000000000"}]
Print the answer as an integer. * * *
s552038287
Accepted
p02659
Input is given from Standard Input in the following format: A B
ab=input().split() a=int(ab[0]) b=int(ab[1][0]+ab[1][2]+ab[1][3]) s=a*b print(s//100)
Statement Compute A \times B, truncate its fractional part, and print the result as an integer.
[{"input": "198 1.10", "output": "217\n \n\nWe have 198 \\times 1.10 = 217.8. After truncating the fractional part, we have\nthe answer: 217.\n\n* * *"}, {"input": "1 0.01", "output": "0\n \n\n* * *"}, {"input": "1000000000000000 9.99", "output": "9990000000000000"}]
Print the answer as an integer. * * *
s930094314
Wrong Answer
p02659
Input is given from Standard Input in the following format: A B
def solve(a, b): if b == 0 or a == "0": return 0 alist = list(reversed(a)) count = 0 k = 0 res = [] for s in alist: tmp = int(s) if count < 2: k += tmp * b * 10 ** (count) else: k += tmp * b * 100 k = int(k) res.append(str(k % 10)) k = k // 10 count += 1 k = int(k) while k > 0: res.append(str(k % 10)) k = k // 10 res.reverse() ans = "".join(res) if ans == "": return 0 return ans if __name__ == "__main__": s = input().split() a = s[0] b = float(s[1]) print(solve(a, b))
Statement Compute A \times B, truncate its fractional part, and print the result as an integer.
[{"input": "198 1.10", "output": "217\n \n\nWe have 198 \\times 1.10 = 217.8. After truncating the fractional part, we have\nthe answer: 217.\n\n* * *"}, {"input": "1 0.01", "output": "0\n \n\n* * *"}, {"input": "1000000000000000 9.99", "output": "9990000000000000"}]
Print the answer as an integer. * * *
s180498449
Accepted
p02659
Input is given from Standard Input in the following format: A B
m, n = input().split() print(int(m) * int(n[0] + n[2::]) // 100)
Statement Compute A \times B, truncate its fractional part, and print the result as an integer.
[{"input": "198 1.10", "output": "217\n \n\nWe have 198 \\times 1.10 = 217.8. After truncating the fractional part, we have\nthe answer: 217.\n\n* * *"}, {"input": "1 0.01", "output": "0\n \n\n* * *"}, {"input": "1000000000000000 9.99", "output": "9990000000000000"}]
Print the answer as an integer. * * *
s083795859
Wrong Answer
p02659
Input is given from Standard Input in the following format: A B
c,d=input().split() a,b=int(c),float(d) e=a*b print(int(e))
Statement Compute A \times B, truncate its fractional part, and print the result as an integer.
[{"input": "198 1.10", "output": "217\n \n\nWe have 198 \\times 1.10 = 217.8. After truncating the fractional part, we have\nthe answer: 217.\n\n* * *"}, {"input": "1 0.01", "output": "0\n \n\n* * *"}, {"input": "1000000000000000 9.99", "output": "9990000000000000"}]
Print the answer as an integer. * * *
s474351683
Accepted
p02659
Input is given from Standard Input in the following format: A B
inputs = input().split(" ") decimal = inputs[1].split(".") product = int(inputs[0]) * (int(decimal[0] + decimal[1])) print(product // 100)
Statement Compute A \times B, truncate its fractional part, and print the result as an integer.
[{"input": "198 1.10", "output": "217\n \n\nWe have 198 \\times 1.10 = 217.8. After truncating the fractional part, we have\nthe answer: 217.\n\n* * *"}, {"input": "1 0.01", "output": "0\n \n\n* * *"}, {"input": "1000000000000000 9.99", "output": "9990000000000000"}]
Print the answer as an integer. * * *
s726826657
Wrong Answer
p02659
Input is given from Standard Input in the following format: A B
s = list(map(float, input().split())) print(int(s[0] * s[1]))
Statement Compute A \times B, truncate its fractional part, and print the result as an integer.
[{"input": "198 1.10", "output": "217\n \n\nWe have 198 \\times 1.10 = 217.8. After truncating the fractional part, we have\nthe answer: 217.\n\n* * *"}, {"input": "1 0.01", "output": "0\n \n\n* * *"}, {"input": "1000000000000000 9.99", "output": "9990000000000000"}]
Print the answer as an integer. * * *
s425572749
Wrong Answer
p02659
Input is given from Standard Input in the following format: A B
inputs = list(input().split()) A = int(inputs[0]) B = float(inputs[1]) + 0.05 B = B * 100 Ans = A * B / 100 print(int(Ans))
Statement Compute A \times B, truncate its fractional part, and print the result as an integer.
[{"input": "198 1.10", "output": "217\n \n\nWe have 198 \\times 1.10 = 217.8. After truncating the fractional part, we have\nthe answer: 217.\n\n* * *"}, {"input": "1 0.01", "output": "0\n \n\n* * *"}, {"input": "1000000000000000 9.99", "output": "9990000000000000"}]