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 |
|---|---|---|---|---|---|---|---|
Replace the first four characters in S with `2018` and print it.
* * * | s857621070 | Runtime Error | p03469 | Input is given from Standard Input in the following format:
S | h = [int(s) for s in input().split()]
N = h[0]
Y = h[1]
def otoshidama(a,b):
ok_flag = 0
money = 0
for i in range(N+1):
for j in range(N+1-i):
money = 10000*i + 5000*j + 1000*(N-i-j)
if money == Y:
print(i,j,N-i-j)
ok_flag = 1
return
money = 0
if ok_flag == 0:
print(-1 -1 -1)
otoshidama(N,Y) | Statement
On some day in January 2018, Takaki is writing a document. The document has a
column where the current date is written in `yyyy/mm/dd` format. For example,
January 23, 2018 should be written as `2018/01/23`.
After finishing the document, she noticed that she had mistakenly wrote `2017`
at the beginning of the date column. Write a program that, when the string
that Takaki wrote in the date column, S, is given as input, modifies the first
four characters in S to `2018` and prints it. | [{"input": "2017/01/07", "output": "2018/01/07\n \n\n* * *"}, {"input": "2017/01/31", "output": "2018/01/31"}] |
Replace the first four characters in S with `2018` and print it.
* * * | s059300347 | Runtime Error | p03469 | Input is given from Standard Input in the following format:
S | s = input()
ans = ""
for i in range(len(s)):
if (i == 3) ans += "8"
else ans += s[i]
print (ans) | Statement
On some day in January 2018, Takaki is writing a document. The document has a
column where the current date is written in `yyyy/mm/dd` format. For example,
January 23, 2018 should be written as `2018/01/23`.
After finishing the document, she noticed that she had mistakenly wrote `2017`
at the beginning of the date column. Write a program that, when the string
that Takaki wrote in the date column, S, is given as input, modifies the first
four characters in S to `2018` and prints it. | [{"input": "2017/01/07", "output": "2018/01/07\n \n\n* * *"}, {"input": "2017/01/31", "output": "2018/01/31"}] |
Replace the first four characters in S with `2018` and print it.
* * * | s072034211 | Runtime Error | p03469 | Input is given from Standard Input in the following format:
S | A = int(input())
B = int(input())
C = int(input())
D = int(input())
ans = min(A, B) + min(C, D)
print(ans)
| Statement
On some day in January 2018, Takaki is writing a document. The document has a
column where the current date is written in `yyyy/mm/dd` format. For example,
January 23, 2018 should be written as `2018/01/23`.
After finishing the document, she noticed that she had mistakenly wrote `2017`
at the beginning of the date column. Write a program that, when the string
that Takaki wrote in the date column, S, is given as input, modifies the first
four characters in S to `2018` and prints it. | [{"input": "2017/01/07", "output": "2018/01/07\n \n\n* * *"}, {"input": "2017/01/31", "output": "2018/01/31"}] |
Replace the first four characters in S with `2018` and print it.
* * * | s189446410 | Runtime Error | p03469 | Input is given from Standard Input in the following format:
S | n = int(input())
li = []
for i in range(n):
num = int(input())
if num not in li:
li.append(num)
print(len(li))
| Statement
On some day in January 2018, Takaki is writing a document. The document has a
column where the current date is written in `yyyy/mm/dd` format. For example,
January 23, 2018 should be written as `2018/01/23`.
After finishing the document, she noticed that she had mistakenly wrote `2017`
at the beginning of the date column. Write a program that, when the string
that Takaki wrote in the date column, S, is given as input, modifies the first
four characters in S to `2018` and prints it. | [{"input": "2017/01/07", "output": "2018/01/07\n \n\n* * *"}, {"input": "2017/01/31", "output": "2018/01/31"}] |
Replace the first four characters in S with `2018` and print it.
* * * | s370800386 | Accepted | p03469 | Input is given from Standard Input in the following format:
S | print("".join([c if i != 3 else "8" for i, c in enumerate(input())]))
| Statement
On some day in January 2018, Takaki is writing a document. The document has a
column where the current date is written in `yyyy/mm/dd` format. For example,
January 23, 2018 should be written as `2018/01/23`.
After finishing the document, she noticed that she had mistakenly wrote `2017`
at the beginning of the date column. Write a program that, when the string
that Takaki wrote in the date column, S, is given as input, modifies the first
four characters in S to `2018` and prints it. | [{"input": "2017/01/07", "output": "2018/01/07\n \n\n* * *"}, {"input": "2017/01/31", "output": "2018/01/31"}] |
Replace the first four characters in S with `2018` and print it.
* * * | s267393495 | Accepted | p03469 | Input is given from Standard Input in the following format:
S | a = input().split("/")
a[0] = "2018"
print("/".join(a))
| Statement
On some day in January 2018, Takaki is writing a document. The document has a
column where the current date is written in `yyyy/mm/dd` format. For example,
January 23, 2018 should be written as `2018/01/23`.
After finishing the document, she noticed that she had mistakenly wrote `2017`
at the beginning of the date column. Write a program that, when the string
that Takaki wrote in the date column, S, is given as input, modifies the first
four characters in S to `2018` and prints it. | [{"input": "2017/01/07", "output": "2018/01/07\n \n\n* * *"}, {"input": "2017/01/31", "output": "2018/01/31"}] |
Replace the first four characters in S with `2018` and print it.
* * * | s590768387 | Accepted | p03469 | Input is given from Standard Input in the following format:
S | st = list(input())
st[3] = "8"
print("".join(st))
| Statement
On some day in January 2018, Takaki is writing a document. The document has a
column where the current date is written in `yyyy/mm/dd` format. For example,
January 23, 2018 should be written as `2018/01/23`.
After finishing the document, she noticed that she had mistakenly wrote `2017`
at the beginning of the date column. Write a program that, when the string
that Takaki wrote in the date column, S, is given as input, modifies the first
four characters in S to `2018` and prints it. | [{"input": "2017/01/07", "output": "2018/01/07\n \n\n* * *"}, {"input": "2017/01/31", "output": "2018/01/31"}] |
Replace the first four characters in S with `2018` and print it.
* * * | s351556243 | Accepted | p03469 | Input is given from Standard Input in the following format:
S | val = input()
print(val.replace("2017", "2018"))
| Statement
On some day in January 2018, Takaki is writing a document. The document has a
column where the current date is written in `yyyy/mm/dd` format. For example,
January 23, 2018 should be written as `2018/01/23`.
After finishing the document, she noticed that she had mistakenly wrote `2017`
at the beginning of the date column. Write a program that, when the string
that Takaki wrote in the date column, S, is given as input, modifies the first
four characters in S to `2018` and prints it. | [{"input": "2017/01/07", "output": "2018/01/07\n \n\n* * *"}, {"input": "2017/01/31", "output": "2018/01/31"}] |
Replace the first four characters in S with `2018` and print it.
* * * | s632669435 | Runtime Error | p03469 | Input is given from Standard Input in the following format:
S | print(len(set([int(input()), for _ in range(int(input()))])))
| Statement
On some day in January 2018, Takaki is writing a document. The document has a
column where the current date is written in `yyyy/mm/dd` format. For example,
January 23, 2018 should be written as `2018/01/23`.
After finishing the document, she noticed that she had mistakenly wrote `2017`
at the beginning of the date column. Write a program that, when the string
that Takaki wrote in the date column, S, is given as input, modifies the first
four characters in S to `2018` and prints it. | [{"input": "2017/01/07", "output": "2018/01/07\n \n\n* * *"}, {"input": "2017/01/31", "output": "2018/01/31"}] |
Replace the first four characters in S with `2018` and print it.
* * * | s866903659 | Runtime Error | p03469 | Input is given from Standard Input in the following format:
S | print(len(set(input() for i in range(int(input())))))
| Statement
On some day in January 2018, Takaki is writing a document. The document has a
column where the current date is written in `yyyy/mm/dd` format. For example,
January 23, 2018 should be written as `2018/01/23`.
After finishing the document, she noticed that she had mistakenly wrote `2017`
at the beginning of the date column. Write a program that, when the string
that Takaki wrote in the date column, S, is given as input, modifies the first
four characters in S to `2018` and prints it. | [{"input": "2017/01/07", "output": "2018/01/07\n \n\n* * *"}, {"input": "2017/01/31", "output": "2018/01/31"}] |
Replace the first four characters in S with `2018` and print it.
* * * | s005355912 | Runtime Error | p03469 | Input is given from Standard Input in the following format:
S | print(''.join((lambda s:s[3]='8')(list(input())))) | Statement
On some day in January 2018, Takaki is writing a document. The document has a
column where the current date is written in `yyyy/mm/dd` format. For example,
January 23, 2018 should be written as `2018/01/23`.
After finishing the document, she noticed that she had mistakenly wrote `2017`
at the beginning of the date column. Write a program that, when the string
that Takaki wrote in the date column, S, is given as input, modifies the first
four characters in S to `2018` and prints it. | [{"input": "2017/01/07", "output": "2018/01/07\n \n\n* * *"}, {"input": "2017/01/31", "output": "2018/01/31"}] |
Replace the first four characters in S with `2018` and print it.
* * * | s757488233 | Wrong Answer | p03469 | Input is given from Standard Input in the following format:
S | y, m, d = map(int, input().split("/"))
print("2018/01/" + str(d))
| Statement
On some day in January 2018, Takaki is writing a document. The document has a
column where the current date is written in `yyyy/mm/dd` format. For example,
January 23, 2018 should be written as `2018/01/23`.
After finishing the document, she noticed that she had mistakenly wrote `2017`
at the beginning of the date column. Write a program that, when the string
that Takaki wrote in the date column, S, is given as input, modifies the first
four characters in S to `2018` and prints it. | [{"input": "2017/01/07", "output": "2018/01/07\n \n\n* * *"}, {"input": "2017/01/31", "output": "2018/01/31"}] |
Print an integer representing the minimum possible total price of fruits.
* * * | s929986420 | Wrong Answer | p02628 | Input is given from Standard Input in the following format:
N K
p_1 p_2 \ldots p_N | x = input()
arr = [int(j) for j in x.split()]
y = input()
main = [int(i) for i in y.split()]
main = sorted(main)
sum = 0
r = 0
while r < arr[1]:
sum += main[r]
r += 1
print(main)
| Statement
A shop sells N kinds of fruits, Fruit 1, \ldots, N, at prices of p_1, \ldots,
p_N yen per item, respectively. (Yen is the currency of Japan.)
Here, we will choose K kinds of fruits and buy one of each chosen kind. Find
the minimum possible total price of those fruits. | [{"input": "5 3\n 50 100 80 120 80", "output": "210\n \n\nThis shop sells Fruit 1, 2, 3, 4, and 5 for 50 yen, 100 yen, 80 yen, 120 yen,\nand 80 yen, respectively.\n\nThe minimum total price for three kinds of fruits is 50 + 80 + 80 = 210 yen\nwhen choosing Fruit 1, 3, and 5.\n\n* * *"}, {"input": "1 1\n 1000", "output": "1000"}] |
Print an integer representing the minimum possible total price of fruits.
* * * | s114706228 | Accepted | p02628 | Input is given from Standard Input in the following format:
N K
p_1 p_2 \ldots p_N | n, k = [int(x) for x in input().split()]
arr = sorted([int(x) for x in input().split()])
print(sum(arr[:k]))
| Statement
A shop sells N kinds of fruits, Fruit 1, \ldots, N, at prices of p_1, \ldots,
p_N yen per item, respectively. (Yen is the currency of Japan.)
Here, we will choose K kinds of fruits and buy one of each chosen kind. Find
the minimum possible total price of those fruits. | [{"input": "5 3\n 50 100 80 120 80", "output": "210\n \n\nThis shop sells Fruit 1, 2, 3, 4, and 5 for 50 yen, 100 yen, 80 yen, 120 yen,\nand 80 yen, respectively.\n\nThe minimum total price for three kinds of fruits is 50 + 80 + 80 = 210 yen\nwhen choosing Fruit 1, 3, and 5.\n\n* * *"}, {"input": "1 1\n 1000", "output": "1000"}] |
Print an integer representing the minimum possible total price of fruits.
* * * | s387981185 | Accepted | p02628 | Input is given from Standard Input in the following format:
N K
p_1 p_2 \ldots p_N | N, K = [int(a) for a in input().split()]
P = [int(a) for a in input().split()]
for i in range(len(P) - 1):
for j in reversed(range(i, len(P) - 1)):
if P[j] > P[j + 1]:
P[j], P[j + 1] = P[j + 1], P[j]
print(sum(P[:K]))
| Statement
A shop sells N kinds of fruits, Fruit 1, \ldots, N, at prices of p_1, \ldots,
p_N yen per item, respectively. (Yen is the currency of Japan.)
Here, we will choose K kinds of fruits and buy one of each chosen kind. Find
the minimum possible total price of those fruits. | [{"input": "5 3\n 50 100 80 120 80", "output": "210\n \n\nThis shop sells Fruit 1, 2, 3, 4, and 5 for 50 yen, 100 yen, 80 yen, 120 yen,\nand 80 yen, respectively.\n\nThe minimum total price for three kinds of fruits is 50 + 80 + 80 = 210 yen\nwhen choosing Fruit 1, 3, and 5.\n\n* * *"}, {"input": "1 1\n 1000", "output": "1000"}] |
Print an integer representing the minimum possible total price of fruits.
* * * | s146257312 | Wrong Answer | p02628 | Input is given from Standard Input in the following format:
N K
p_1 p_2 \ldots p_N | A = list(input().split(" "))
B = list(input().split(" "))
C = sorted(B)
D = []
M = 0
for i in range(int(A[1])):
D.append(int(C[i]))
for j in range(len(D)):
M = D[j] + M
print(M)
| Statement
A shop sells N kinds of fruits, Fruit 1, \ldots, N, at prices of p_1, \ldots,
p_N yen per item, respectively. (Yen is the currency of Japan.)
Here, we will choose K kinds of fruits and buy one of each chosen kind. Find
the minimum possible total price of those fruits. | [{"input": "5 3\n 50 100 80 120 80", "output": "210\n \n\nThis shop sells Fruit 1, 2, 3, 4, and 5 for 50 yen, 100 yen, 80 yen, 120 yen,\nand 80 yen, respectively.\n\nThe minimum total price for three kinds of fruits is 50 + 80 + 80 = 210 yen\nwhen choosing Fruit 1, 3, and 5.\n\n* * *"}, {"input": "1 1\n 1000", "output": "1000"}] |
Print an integer representing the minimum possible total price of fruits.
* * * | s923559273 | Runtime Error | p02628 | Input is given from Standard Input in the following format:
N K
p_1 p_2 \ldots p_N | N, M = map(int, input().splilt())
L = list(map(int, input().splilt()))
print(sum(sorted(L)[:M]))
| Statement
A shop sells N kinds of fruits, Fruit 1, \ldots, N, at prices of p_1, \ldots,
p_N yen per item, respectively. (Yen is the currency of Japan.)
Here, we will choose K kinds of fruits and buy one of each chosen kind. Find
the minimum possible total price of those fruits. | [{"input": "5 3\n 50 100 80 120 80", "output": "210\n \n\nThis shop sells Fruit 1, 2, 3, 4, and 5 for 50 yen, 100 yen, 80 yen, 120 yen,\nand 80 yen, respectively.\n\nThe minimum total price for three kinds of fruits is 50 + 80 + 80 = 210 yen\nwhen choosing Fruit 1, 3, and 5.\n\n* * *"}, {"input": "1 1\n 1000", "output": "1000"}] |
Print an integer representing the minimum possible total price of fruits.
* * * | s476870107 | Runtime Error | p02628 | Input is given from Standard Input in the following format:
N K
p_1 p_2 \ldots p_N | N, K = tuple(map(int, input.split(" ")))
cont = list(map(int, input.split(" ")))
print(sum(cont[:K]))
| Statement
A shop sells N kinds of fruits, Fruit 1, \ldots, N, at prices of p_1, \ldots,
p_N yen per item, respectively. (Yen is the currency of Japan.)
Here, we will choose K kinds of fruits and buy one of each chosen kind. Find
the minimum possible total price of those fruits. | [{"input": "5 3\n 50 100 80 120 80", "output": "210\n \n\nThis shop sells Fruit 1, 2, 3, 4, and 5 for 50 yen, 100 yen, 80 yen, 120 yen,\nand 80 yen, respectively.\n\nThe minimum total price for three kinds of fruits is 50 + 80 + 80 = 210 yen\nwhen choosing Fruit 1, 3, and 5.\n\n* * *"}, {"input": "1 1\n 1000", "output": "1000"}] |
Print an integer representing the minimum possible total price of fruits.
* * * | s149886609 | Runtime Error | p02628 | Input is given from Standard Input in the following format:
N K
p_1 p_2 \ldots p_N | a = input()
l = a.split(" ")
n = int(l[0])
k = int(l[1])
f = input()
fruits = int(f.split(" "))
for d in range(0, len(fruits)):
fruits[d] = int(fruits[d])
ans = 0
b = 0
while b < k:
g = max(fruits)
ans += g
fruits.remove(g)
b += 1
print(ans)
| Statement
A shop sells N kinds of fruits, Fruit 1, \ldots, N, at prices of p_1, \ldots,
p_N yen per item, respectively. (Yen is the currency of Japan.)
Here, we will choose K kinds of fruits and buy one of each chosen kind. Find
the minimum possible total price of those fruits. | [{"input": "5 3\n 50 100 80 120 80", "output": "210\n \n\nThis shop sells Fruit 1, 2, 3, 4, and 5 for 50 yen, 100 yen, 80 yen, 120 yen,\nand 80 yen, respectively.\n\nThe minimum total price for three kinds of fruits is 50 + 80 + 80 = 210 yen\nwhen choosing Fruit 1, 3, and 5.\n\n* * *"}, {"input": "1 1\n 1000", "output": "1000"}] |
Print an integer representing the minimum possible total price of fruits.
* * * | s692099947 | Accepted | p02628 | Input is given from Standard Input in the following format:
N K
p_1 p_2 \ldots p_N | _, k = list(map(int, input().split()))
print(sum(sorted(list(map(int, input().split())))[0:k]))
| Statement
A shop sells N kinds of fruits, Fruit 1, \ldots, N, at prices of p_1, \ldots,
p_N yen per item, respectively. (Yen is the currency of Japan.)
Here, we will choose K kinds of fruits and buy one of each chosen kind. Find
the minimum possible total price of those fruits. | [{"input": "5 3\n 50 100 80 120 80", "output": "210\n \n\nThis shop sells Fruit 1, 2, 3, 4, and 5 for 50 yen, 100 yen, 80 yen, 120 yen,\nand 80 yen, respectively.\n\nThe minimum total price for three kinds of fruits is 50 + 80 + 80 = 210 yen\nwhen choosing Fruit 1, 3, and 5.\n\n* * *"}, {"input": "1 1\n 1000", "output": "1000"}] |
Print an integer representing the minimum possible total price of fruits.
* * * | s548522553 | Runtime Error | p02628 | Input is given from Standard Input in the following format:
N K
p_1 p_2 \ldots p_N | N,K = map(int,input().split())
list = map(int,input().split())
MIN = list[0]
SUM = 0
for j in range(1,K):
for i in list:
if MIN > list[i]:
MIN = list[i]
list.delete(MIN)
SUM += MIN
MIN = list[0]
print(SUM) | Statement
A shop sells N kinds of fruits, Fruit 1, \ldots, N, at prices of p_1, \ldots,
p_N yen per item, respectively. (Yen is the currency of Japan.)
Here, we will choose K kinds of fruits and buy one of each chosen kind. Find
the minimum possible total price of those fruits. | [{"input": "5 3\n 50 100 80 120 80", "output": "210\n \n\nThis shop sells Fruit 1, 2, 3, 4, and 5 for 50 yen, 100 yen, 80 yen, 120 yen,\nand 80 yen, respectively.\n\nThe minimum total price for three kinds of fruits is 50 + 80 + 80 = 210 yen\nwhen choosing Fruit 1, 3, and 5.\n\n* * *"}, {"input": "1 1\n 1000", "output": "1000"}] |
Print an integer representing the minimum possible total price of fruits.
* * * | s342151234 | Runtime Error | p02628 | Input is given from Standard Input in the following format:
N K
p_1 p_2 \ldots p_N | a = input()
print(sum(list(map(int, input().split()))[: int(a[2])]))
| Statement
A shop sells N kinds of fruits, Fruit 1, \ldots, N, at prices of p_1, \ldots,
p_N yen per item, respectively. (Yen is the currency of Japan.)
Here, we will choose K kinds of fruits and buy one of each chosen kind. Find
the minimum possible total price of those fruits. | [{"input": "5 3\n 50 100 80 120 80", "output": "210\n \n\nThis shop sells Fruit 1, 2, 3, 4, and 5 for 50 yen, 100 yen, 80 yen, 120 yen,\nand 80 yen, respectively.\n\nThe minimum total price for three kinds of fruits is 50 + 80 + 80 = 210 yen\nwhen choosing Fruit 1, 3, and 5.\n\n* * *"}, {"input": "1 1\n 1000", "output": "1000"}] |
Print an integer representing the minimum possible total price of fruits.
* * * | s302779837 | Runtime Error | p02628 | Input is given from Standard Input in the following format:
N K
p_1 p_2 \ldots p_N | A, B = map(int, input().split())
C = list(map(int, input().split()))
C.sort()
D = C[0] + C[1] + C[2]
print(D)
| Statement
A shop sells N kinds of fruits, Fruit 1, \ldots, N, at prices of p_1, \ldots,
p_N yen per item, respectively. (Yen is the currency of Japan.)
Here, we will choose K kinds of fruits and buy one of each chosen kind. Find
the minimum possible total price of those fruits. | [{"input": "5 3\n 50 100 80 120 80", "output": "210\n \n\nThis shop sells Fruit 1, 2, 3, 4, and 5 for 50 yen, 100 yen, 80 yen, 120 yen,\nand 80 yen, respectively.\n\nThe minimum total price for three kinds of fruits is 50 + 80 + 80 = 210 yen\nwhen choosing Fruit 1, 3, and 5.\n\n* * *"}, {"input": "1 1\n 1000", "output": "1000"}] |
Print an integer representing the minimum possible total price of fruits.
* * * | s024945790 | Accepted | p02628 | Input is given from Standard Input in the following format:
N K
p_1 p_2 \ldots p_N | import sys
sys.setrecursionlimit(10**9)
# input = sys.stdin.readline ####
def int1(x):
return int(x) - 1
def II():
return int(input())
def MI():
return map(int, input().split())
def MI1():
return map(int1, input().split())
def LI():
return list(map(int, input().split()))
def LI1():
return list(map(int1, input().split()))
def LLI(rows_number):
return [LI() for _ in range(rows_number)]
def MS():
return input().split()
def LS():
return list(input())
def LLS(rows_number):
return [LS() for _ in range(rows_number)]
def printlist(lst, k=" "):
print(k.join(list(map(str, lst))))
INF = float("inf")
# from math import ceil, floor, log2
# from collections import deque
# from itertools import combinations as comb, combinations_with_replacement as comb_w, accumulate, product, permutations
# from heapq import heapify, heappop, heappush
# import numpy as np
# from numpy import cumsum # accumulate
def solve():
N, K = MI()
P = LI()
P.sort()
print(sum(P[:K]))
if __name__ == "__main__":
solve()
| Statement
A shop sells N kinds of fruits, Fruit 1, \ldots, N, at prices of p_1, \ldots,
p_N yen per item, respectively. (Yen is the currency of Japan.)
Here, we will choose K kinds of fruits and buy one of each chosen kind. Find
the minimum possible total price of those fruits. | [{"input": "5 3\n 50 100 80 120 80", "output": "210\n \n\nThis shop sells Fruit 1, 2, 3, 4, and 5 for 50 yen, 100 yen, 80 yen, 120 yen,\nand 80 yen, respectively.\n\nThe minimum total price for three kinds of fruits is 50 + 80 + 80 = 210 yen\nwhen choosing Fruit 1, 3, and 5.\n\n* * *"}, {"input": "1 1\n 1000", "output": "1000"}] |
Print an integer representing the minimum possible total price of fruits.
* * * | s870530802 | Accepted | p02628 | Input is given from Standard Input in the following format:
N K
p_1 p_2 \ldots p_N | s = input().split()
intN = int(s[0])
intK = int(s[1])
inList = list(map(int, input().split()))
# print(inList)
inList.sort()
# print(inList)
idx = 0
intCnt = 0
for wInt in inList:
if idx < intK:
intCnt += wInt
# print(wInt)
# print(intCnt)
idx += 1
print(intCnt)
| Statement
A shop sells N kinds of fruits, Fruit 1, \ldots, N, at prices of p_1, \ldots,
p_N yen per item, respectively. (Yen is the currency of Japan.)
Here, we will choose K kinds of fruits and buy one of each chosen kind. Find
the minimum possible total price of those fruits. | [{"input": "5 3\n 50 100 80 120 80", "output": "210\n \n\nThis shop sells Fruit 1, 2, 3, 4, and 5 for 50 yen, 100 yen, 80 yen, 120 yen,\nand 80 yen, respectively.\n\nThe minimum total price for three kinds of fruits is 50 + 80 + 80 = 210 yen\nwhen choosing Fruit 1, 3, and 5.\n\n* * *"}, {"input": "1 1\n 1000", "output": "1000"}] |
Print an integer representing the minimum possible total price of fruits.
* * * | s885930157 | Accepted | p02628 | Input is given from Standard Input in the following format:
N K
p_1 p_2 \ldots p_N | a, b = input().split(" ")
lst = list(map(int, input().split(" ")))
lst_s = sorted(lst)
res = lst_s[0 : int(b)]
print(sum(res))
| Statement
A shop sells N kinds of fruits, Fruit 1, \ldots, N, at prices of p_1, \ldots,
p_N yen per item, respectively. (Yen is the currency of Japan.)
Here, we will choose K kinds of fruits and buy one of each chosen kind. Find
the minimum possible total price of those fruits. | [{"input": "5 3\n 50 100 80 120 80", "output": "210\n \n\nThis shop sells Fruit 1, 2, 3, 4, and 5 for 50 yen, 100 yen, 80 yen, 120 yen,\nand 80 yen, respectively.\n\nThe minimum total price for three kinds of fruits is 50 + 80 + 80 = 210 yen\nwhen choosing Fruit 1, 3, and 5.\n\n* * *"}, {"input": "1 1\n 1000", "output": "1000"}] |
Print an integer representing the minimum possible total price of fruits.
* * * | s145556517 | Accepted | p02628 | Input is given from Standard Input in the following format:
N K
p_1 p_2 \ldots p_N | n, amount = map(int, input().split())
flist = list(map(int, input().split()))
print(sum(sorted(flist)[:amount]))
| Statement
A shop sells N kinds of fruits, Fruit 1, \ldots, N, at prices of p_1, \ldots,
p_N yen per item, respectively. (Yen is the currency of Japan.)
Here, we will choose K kinds of fruits and buy one of each chosen kind. Find
the minimum possible total price of those fruits. | [{"input": "5 3\n 50 100 80 120 80", "output": "210\n \n\nThis shop sells Fruit 1, 2, 3, 4, and 5 for 50 yen, 100 yen, 80 yen, 120 yen,\nand 80 yen, respectively.\n\nThe minimum total price for three kinds of fruits is 50 + 80 + 80 = 210 yen\nwhen choosing Fruit 1, 3, and 5.\n\n* * *"}, {"input": "1 1\n 1000", "output": "1000"}] |
Print an integer representing the minimum possible total price of fruits.
* * * | s276341135 | Wrong Answer | p02628 | Input is given from Standard Input in the following format:
N K
p_1 p_2 \ldots p_N | n, k = map(int, input().split())
| Statement
A shop sells N kinds of fruits, Fruit 1, \ldots, N, at prices of p_1, \ldots,
p_N yen per item, respectively. (Yen is the currency of Japan.)
Here, we will choose K kinds of fruits and buy one of each chosen kind. Find
the minimum possible total price of those fruits. | [{"input": "5 3\n 50 100 80 120 80", "output": "210\n \n\nThis shop sells Fruit 1, 2, 3, 4, and 5 for 50 yen, 100 yen, 80 yen, 120 yen,\nand 80 yen, respectively.\n\nThe minimum total price for three kinds of fruits is 50 + 80 + 80 = 210 yen\nwhen choosing Fruit 1, 3, and 5.\n\n* * *"}, {"input": "1 1\n 1000", "output": "1000"}] |
Print the sum of f(i, j) modulo (10^9+7).
* * * | s020336944 | Accepted | p02782 | Input is given from Standard Input in the following format:
r_1 c_1 r_2 c_2 | class ModComb:
def __init__(self, MAX, mod=10**9 + 7):
fac = [1, 1]
finv = [1, 1]
inv = [0, 1]
for i in range(2, MAX):
fac.append(fac[i - 1] * i % mod)
inv.append(mod - inv[mod % i] * (mod // i) % mod)
finv.append(finv[i - 1] * inv[i] % mod)
self.fac, self.finv, self.mod = fac, finv, mod
def nCk(self, n, k):
if n < k or n < 0 or k < 0:
return 0
fac, finv, mod = self.fac, self.finv, self.mod
return fac[n] * (finv[k] * finv[n - k] % mod) % mod
mod = 10**9 + 7
r1, c1, r2, c2 = map(int, input().split())
mc = ModComb(r2 + c2 + 10)
def f(i, j):
return mc.nCk(i + j, i)
print((f(r2 + 1, c2 + 1) - f(r2 + 1, c1) - f(r1, c2 + 1) + f(r1, c1)) % mod)
| Statement
Snuke is standing on a two-dimensional plane. In one operation, he can move by
1 in the positive x-direction, or move by 1 in the positive y-direction.
Let us define a function f(r, c) as follows:
* f(r,c) := (The number of paths from the point (0, 0) to the point (r, c) that Snuke can trace by repeating the operation above)
Given are integers r_1, r_2, c_1, and c_2. Find the sum of f(i, j) over all
pair of integers (i, j) such that r_1 ≤ i ≤ r_2 and c_1 ≤ j ≤ c_2, and compute
this value modulo (10^9+7). | [{"input": "1 1 2 2", "output": "14\n \n\nFor example, there are two paths from the point (0, 0) to the point (1, 1):\n(0,0) \u2192 (0,1) \u2192 (1,1) and (0,0) \u2192 (1,0) \u2192 (1,1), so f(1,1)=2.\n\nSimilarly, f(1,2)=3, f(2,1)=3, and f(2,2)=6. Thus, the sum is 14.\n\n* * *"}, {"input": "314 159 2653 589", "output": "602215194"}] |
Print the sum of f(i, j) modulo (10^9+7).
* * * | s293819118 | Accepted | p02782 | Input is given from Standard Input in the following format:
r_1 c_1 r_2 c_2 | class Combination:
"""
SIZEが10^6程度以下の二項係数を何回も呼び出したいときに使う
使い方:
comb = Combination(SIZE, MOD)
comb(10, 3) => 120
"""
def __init__(self, N, MOD=10**9 + 7):
self.MOD = MOD
self.fact, self.inv = self._make_factorial_list(N)
def __call__(self, n, k):
if k < 0 or k > n:
return 0
res = self.fact[n] * self.inv[k] % self.MOD
res = res * self.inv[n - k] % self.MOD
return res
def _make_factorial_list(self, N):
fact = [1] * (N + 1)
inv = [1] * (N + 1)
MOD = self.MOD
for i in range(1, N + 1):
fact[i] = (fact[i - 1] * i) % MOD
inv[N] = pow(fact[N], MOD - 2, MOD)
for i in range(N, 0, -1):
inv[i - 1] = (inv[i] * i) % MOD
return fact, inv
if __name__ == "__main__":
r1, c1, r2, c2 = map(int, input().split())
mod = 10**9 + 7
comb = Combination(2 * 10**6 + 10, mod)
def f(r, c):
return comb(r + c + 2, r + 1)
CD = (f(r2, c2) - f(r2, c1 - 1) + mod) % mod
C = (f(r1 - 1, c2) - f(r1 - 1, c1 - 1) + mod) % mod
ans = (CD - C + mod) % mod
print(ans)
| Statement
Snuke is standing on a two-dimensional plane. In one operation, he can move by
1 in the positive x-direction, or move by 1 in the positive y-direction.
Let us define a function f(r, c) as follows:
* f(r,c) := (The number of paths from the point (0, 0) to the point (r, c) that Snuke can trace by repeating the operation above)
Given are integers r_1, r_2, c_1, and c_2. Find the sum of f(i, j) over all
pair of integers (i, j) such that r_1 ≤ i ≤ r_2 and c_1 ≤ j ≤ c_2, and compute
this value modulo (10^9+7). | [{"input": "1 1 2 2", "output": "14\n \n\nFor example, there are two paths from the point (0, 0) to the point (1, 1):\n(0,0) \u2192 (0,1) \u2192 (1,1) and (0,0) \u2192 (1,0) \u2192 (1,1), so f(1,1)=2.\n\nSimilarly, f(1,2)=3, f(2,1)=3, and f(2,2)=6. Thus, the sum is 14.\n\n* * *"}, {"input": "314 159 2653 589", "output": "602215194"}] |
Print the sum of f(i, j) modulo (10^9+7).
* * * | s961282826 | Runtime Error | p02782 | Input is given from Standard Input in the following format:
r_1 c_1 r_2 c_2 | # -*- coding: utf-8 -*-
import sys
# sys.setrecursionlimit(10**6)
# buff_readline = sys.stdin.buffer.readline
buff_readline = sys.stdin.readline
readline = sys.stdin.readline
INF = 2**62 - 1
def read_int():
return int(buff_readline())
def read_int_n():
return list(map(int, buff_readline().split()))
def read_float():
return float(buff_readline())
def read_float_n():
return list(map(float, buff_readline().split()))
def read_str():
return readline().strip()
def read_str_n():
return readline().strip().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
class Combination:
def __init__(self, n, mod):
g1 = [1, 1]
g2 = [1, 1]
inverse = [0, 1]
for i in range(2, n + 1):
g1.append((g1[-1] * i) % mod)
inverse.append((-inverse[mod % i] * (mod // i)) % mod)
g2.append((g2[-1] * inverse[-1]) % mod)
self.MOD = mod
self.N = n
self.g1 = g1
self.g2 = g2
self.inverse = inverse
def __call__(self, n, r):
if r < 0 or r > n:
return 0
r = min(r, n - r)
return self.g1[n] * self.g2[r] * self.g2[n - r] % self.MOD
class Mod:
def __init__(self, m):
self.m = m
def add(self, a, b):
return (a + b) % self.m
def sub(self, a, b):
return (a - b) % self.m
def mul(self, a, b):
return ((a % self.m) * (b % self.m)) % self.m
def div(self, a, b):
return self.mul(a, pow(b, self.m - 2, self.m))
def pow(self, a, b):
return pow(a, b, self.m)
@mt
def slv(R1, C1, R2, C2):
C = Combination(2 * 10**6, 10**9 + 7)
M = Mod(10**9 + 7)
ans = 0
for r in range(R1, R2 + 1):
a = C(C2 + r + 1, r + 1)
b = C(C1 - 1 + r + 1, r + 1)
ans = M.add(ans, M.sub(a, b))
return ans
def main():
R1, C1, R2, C2 = read_int_n()
print(slv(R1, C1, R2, C2))
if __name__ == "__main__":
main()
| Statement
Snuke is standing on a two-dimensional plane. In one operation, he can move by
1 in the positive x-direction, or move by 1 in the positive y-direction.
Let us define a function f(r, c) as follows:
* f(r,c) := (The number of paths from the point (0, 0) to the point (r, c) that Snuke can trace by repeating the operation above)
Given are integers r_1, r_2, c_1, and c_2. Find the sum of f(i, j) over all
pair of integers (i, j) such that r_1 ≤ i ≤ r_2 and c_1 ≤ j ≤ c_2, and compute
this value modulo (10^9+7). | [{"input": "1 1 2 2", "output": "14\n \n\nFor example, there are two paths from the point (0, 0) to the point (1, 1):\n(0,0) \u2192 (0,1) \u2192 (1,1) and (0,0) \u2192 (1,0) \u2192 (1,1), so f(1,1)=2.\n\nSimilarly, f(1,2)=3, f(2,1)=3, and f(2,2)=6. Thus, the sum is 14.\n\n* * *"}, {"input": "314 159 2653 589", "output": "602215194"}] |
Print the sum of f(i, j) modulo (10^9+7).
* * * | s568340496 | Runtime Error | p02782 | Input is given from Standard Input in the following format:
r_1 c_1 r_2 c_2 | import math
r_1, c_1, r_2, c_2 = input().split()
r_1 = int(r_1)
r_2 = int(r_2)
c_1 = int(c_1)
c_2 = int(c_2)
count = 0
def total(r, c):
return math.factorial(r + c) / (math.factorial(r) * math.factorial(c))
count += total(r_1, c_1)
count += total(r_1, c_2)
count += total(r_2, c_1)
count += total(r_2, c_2)
if count < (pow(10, 9) + 7):
print(int(count))
else:
print(int(count % (pow(10, 9) + 7)))
| Statement
Snuke is standing on a two-dimensional plane. In one operation, he can move by
1 in the positive x-direction, or move by 1 in the positive y-direction.
Let us define a function f(r, c) as follows:
* f(r,c) := (The number of paths from the point (0, 0) to the point (r, c) that Snuke can trace by repeating the operation above)
Given are integers r_1, r_2, c_1, and c_2. Find the sum of f(i, j) over all
pair of integers (i, j) such that r_1 ≤ i ≤ r_2 and c_1 ≤ j ≤ c_2, and compute
this value modulo (10^9+7). | [{"input": "1 1 2 2", "output": "14\n \n\nFor example, there are two paths from the point (0, 0) to the point (1, 1):\n(0,0) \u2192 (0,1) \u2192 (1,1) and (0,0) \u2192 (1,0) \u2192 (1,1), so f(1,1)=2.\n\nSimilarly, f(1,2)=3, f(2,1)=3, and f(2,2)=6. Thus, the sum is 14.\n\n* * *"}, {"input": "314 159 2653 589", "output": "602215194"}] |
Print the eventual hardness of the last stone remaining.
* * * | s655299137 | Wrong Answer | p03890 | The input is given from Standard Input in the following format:
N
A_1
A_2
:
A_{2^N} | N = int(input())
A = [int(input()) for _ in range(N)]
while len(A) > 1:
B = []
i = 0
while i < len(A):
if A[i] == A[i + 1]:
B.append(A[i])
else:
B.append(abs(A[i] - A[i + 1]))
i += 2
A = B
print(A[0])
| Statement
_Kode Festival_ is an anual contest where the hardest stone in the world is
determined. (Kode is a Japanese word for "hardness".)
This year, 2^N stones participated. The hardness of the i-th stone is A_i.
In the contest, stones are thrown at each other in a knockout tournament.
When two stones with hardness X and Y are thrown at each other, the following
will happen:
* When X > Y: The stone with hardness Y will be destroyed and eliminated. The hardness of the stone with hardness X will become X-Y.
* When X = Y: One of the stones will be destroyed and eliminated. The hardness of the other stone will remain the same.
* When X < Y: The stone with hardness X will be destroyed and eliminated. The hardness of the stone with hardness Y will become Y-X.
The 2^N stones will fight in a knockout tournament as follows:
1. The following pairs will fight: (the 1-st stone versus the 2-nd stone), (the 3-rd stone versus the 4-th stone), ...
2. The following pairs will fight: (the winner of (1-st versus 2-nd) versus the winner of (3-rd versus 4-th)), (the winner of (5-th versus 6-th) versus the winner of (7-th versus 8-th)), ...
3. And so forth, until there is only one stone remaining.
Determine the eventual hardness of the last stone remaining. | [{"input": "2\n 1\n 3\n 10\n 19", "output": "7\n \n\n* * *"}, {"input": "3\n 1\n 3\n 2\n 4\n 6\n 8\n 100\n 104", "output": "2"}] |
Print the eventual hardness of the last stone remaining.
* * * | s172600134 | Wrong Answer | p03890 | The input is given from Standard Input in the following format:
N
A_1
A_2
:
A_{2^N} | 3
1
3
2
4
6
8
100
104
| Statement
_Kode Festival_ is an anual contest where the hardest stone in the world is
determined. (Kode is a Japanese word for "hardness".)
This year, 2^N stones participated. The hardness of the i-th stone is A_i.
In the contest, stones are thrown at each other in a knockout tournament.
When two stones with hardness X and Y are thrown at each other, the following
will happen:
* When X > Y: The stone with hardness Y will be destroyed and eliminated. The hardness of the stone with hardness X will become X-Y.
* When X = Y: One of the stones will be destroyed and eliminated. The hardness of the other stone will remain the same.
* When X < Y: The stone with hardness X will be destroyed and eliminated. The hardness of the stone with hardness Y will become Y-X.
The 2^N stones will fight in a knockout tournament as follows:
1. The following pairs will fight: (the 1-st stone versus the 2-nd stone), (the 3-rd stone versus the 4-th stone), ...
2. The following pairs will fight: (the winner of (1-st versus 2-nd) versus the winner of (3-rd versus 4-th)), (the winner of (5-th versus 6-th) versus the winner of (7-th versus 8-th)), ...
3. And so forth, until there is only one stone remaining.
Determine the eventual hardness of the last stone remaining. | [{"input": "2\n 1\n 3\n 10\n 19", "output": "7\n \n\n* * *"}, {"input": "3\n 1\n 3\n 2\n 4\n 6\n 8\n 100\n 104", "output": "2"}] |
Print the minimal cost in a line. | s347886514 | Accepted | p02278 | In the first line, an integer $n$ is given. In the second line, $n$ integers
$w_i (i = 0, 1, 2, ... n-1)$ separated by space characters are given. | import bisect
def sorted_index(A):
# Aをソートした後のindexのリスト
A_ = sorted(A)
B = []
for a in A:
idx = bisect.bisect_left(A_, a)
B.append(idx)
return B
def cyclic_factorize(A):
# Aを巡回置換分解する
B = sorted_index(A)
checked = [False] * len(A)
cycle_lst = []
for i, a in enumerate(A):
if checked[i]:
continue
now = i
checked[now] = True
cycle = [a]
next = B[now]
while not checked[next]:
now = next
next = B[now]
cycle.append(A[now])
checked[now] = True
cycle_lst.append(cycle)
return cycle_lst
N = int(input())
(*W,) = map(int, input().split())
cycle_lst = cyclic_factorize(W)
ans = 0
global_min = min(W)
for cycle in cycle_lst:
l = len(cycle)
s = sum(cycle)
local_min = min(cycle)
ans += s + min((l - 2) * local_min, local_min + (l + 1) * global_min)
print(ans)
| Minimum Cost Sort
You are given $n$ integers $w_i (i = 0, 1, ..., n-1)$ to be sorted in
ascending order. You can swap two integers $w_i$ and $w_j$. Each swap
operation has a cost, which is the sum of the two integers $w_i + w_j$. You
can perform the operations any number of times.
Write a program which reports the minimal total cost to sort the given
integers. | [{"input": "5\n 1 5 3 4 2", "output": "7"}, {"input": "4\n 4 3 2 1", "output": "10"}] |
Print the minimal cost in a line. | s761750463 | Wrong Answer | p02278 | In the first line, an integer $n$ is given. In the second line, $n$ integers
$w_i (i = 0, 1, 2, ... n-1)$ separated by space characters are given. | def partition(A, l, r):
p = A[r]
j = l - 1
for i in range(l, r):
if A[i] <= p:
j += 1
A[j], A[i] = A[i], A[j]
j += 1
A[j], A[r] = A[r], A[j]
return j
def quick_sort(A, l, r):
if l < r:
p = partition(A, l, r)
quick_sort(A, l, p - 1)
quick_sort(A, p + 1, r)
def minimum_cost_sort(A):
cost = 0
B = A[:]
quick_sort(A, 0, len(A) - 1)
for i in range(len(A) // 2):
if A[i] != B[i]:
cost += A[i] + B[i]
return cost
N = int(input())
A = list(map(int, input().split()))
print(minimum_cost_sort(A))
| Minimum Cost Sort
You are given $n$ integers $w_i (i = 0, 1, ..., n-1)$ to be sorted in
ascending order. You can swap two integers $w_i$ and $w_j$. Each swap
operation has a cost, which is the sum of the two integers $w_i + w_j$. You
can perform the operations any number of times.
Write a program which reports the minimal total cost to sort the given
integers. | [{"input": "5\n 1 5 3 4 2", "output": "7"}, {"input": "4\n 4 3 2 1", "output": "10"}] |
Print the minimal cost in a line. | s109169997 | Wrong Answer | p02278 | In the first line, an integer $n$ is given. In the second line, $n$ integers
$w_i (i = 0, 1, 2, ... n-1)$ separated by space characters are given. | n = int(input())
array = [int(i) for i in input().split()]
temp = array.copy()
array.sort()
w = 0
for i in range(n):
for j in range(n):
if i != j and temp[i] == array[j]:
array[i], array[j] = array[j], array[i]
w += array[i]
w += array[j]
print(w)
| Minimum Cost Sort
You are given $n$ integers $w_i (i = 0, 1, ..., n-1)$ to be sorted in
ascending order. You can swap two integers $w_i$ and $w_j$. Each swap
operation has a cost, which is the sum of the two integers $w_i + w_j$. You
can perform the operations any number of times.
Write a program which reports the minimal total cost to sort the given
integers. | [{"input": "5\n 1 5 3 4 2", "output": "7"}, {"input": "4\n 4 3 2 1", "output": "10"}] |
Print the minimal cost in a line. | s896590563 | Accepted | p02278 | In the first line, an integer $n$ is given. In the second line, $n$ integers
$w_i (i = 0, 1, 2, ... n-1)$ separated by space characters are given. | import functools
def find_all_rings(items):
"items: (??°???, ?????????????????????????????????)"
l = len(items)
check_list = [False] * l
rings = []
i = 0
while i < l:
if check_list[i] == False:
ring = []
first = items[i]
ring.append(first)
check_list[i] = True
item_index = first[1]
item = items[item_index]
while item[0] != first[0]:
ring.append(item)
check_list[item_index] = True
item_index = item[1]
item = items[item_index]
rings.append(ring)
i += 1
return rings
def compute_ring_cost(min_all, ring):
l = len(ring)
if l <= 1:
return 0
w = [item[0] for item in ring]
min_ring = min(w)
sum_ring = sum(w)
if (l + 1) * min_all < (l - 3) * min_ring:
return sum_ring + min_ring + (l + 1) * min_all
else:
return sum_ring + (l - 2) * min_ring
n = int(input())
ns = list(map(int, input().split()))
items = []
sorted_items = []
for i in range(n):
item = (ns[i], i)
items.append(item)
sorted_items.append(item)
sorted_items.sort(key=lambda x: x[0])
for i in range(n):
item = sorted_items[i]
items_index = item[1]
items[items_index] = (item[0], i)
rings = find_all_rings(items)
compute_ring_cost1 = functools.partial(compute_ring_cost, min(ns))
print(sum(map(compute_ring_cost1, rings)))
| Minimum Cost Sort
You are given $n$ integers $w_i (i = 0, 1, ..., n-1)$ to be sorted in
ascending order. You can swap two integers $w_i$ and $w_j$. Each swap
operation has a cost, which is the sum of the two integers $w_i + w_j$. You
can perform the operations any number of times.
Write a program which reports the minimal total cost to sort the given
integers. | [{"input": "5\n 1 5 3 4 2", "output": "7"}, {"input": "4\n 4 3 2 1", "output": "10"}] |
Print the answer.
* * * | s761012271 | Accepted | p02556 | Input is given from Standard Input in the following format:
N
x_1 y_1
x_2 y_2
:
x_N y_N | n = int(input())
p_mn = m_mn = 10**9 * 2
p_mx = m_mx = -p_mn
for i in range(n):
x, y = map(int, input().split())
p = x + y
m = x - y
p_mx = max(p_mx, p)
p_mn = min(p_mn, p)
m_mx = max(m_mx, m)
m_mn = min(m_mn, m)
print(max(p_mx - p_mn, m_mx - m_mn))
| Statement
There are N points on the 2D plane, i-th of which is located on (x_i, y_i).
There can be multiple points that share the same coordinate. What is the
maximum possible Manhattan distance between two distinct points?
Here, the _Manhattan distance_ between two points (x_i, y_i) and (x_j, y_j) is
defined by |x_i-x_j| + |y_i-y_j|. | [{"input": "3\n 1 1\n 2 4\n 3 2", "output": "4\n \n\nThe Manhattan distance between the first point and the second point is\n|1-2|+|1-4|=4, which is maximum possible.\n\n* * *"}, {"input": "2\n 1 1\n 1 1", "output": "0"}] |
Print the answer.
* * * | s262996638 | Wrong Answer | p02556 | Input is given from Standard Input in the following format:
N
x_1 y_1
x_2 y_2
:
x_N y_N | N = int(input())
x1, y1 = map(int, input().split())
centre = [x1, y1]
left_bottom = [x1, y1]
left_bottom_dist = 0
left_top = [x1, y1]
left_top_dist = 0
right_bottom = [x1, y1]
right_bottom_dist = 0
right_top = [x1, y1]
right_top_dist = 0
for i in range(N - 1):
xi, yi = map(int, input().split())
if xi <= x1 and yi <= y1:
if x1 - xi + y1 - yi >= left_bottom_dist:
left_bottom = [xi, yi]
left_bottom_dist = x1 - xi + y1 - yi
if xi <= x1 and yi >= y1:
if x1 - xi + yi - y1 >= left_top_dist:
left_top = [xi, yi]
left_top_dist = x1 - xi + yi - y1
if xi >= x1 and yi <= y1:
if xi - x1 + y1 - yi >= right_bottom_dist:
right_bottom = [xi, yi]
right_bottom_dist = xi - x1 + y1 - yi
if xi >= x1 and yi >= y1:
if xi - x1 + yi - y1 >= right_top_dist:
right_top = [xi, yi]
right_top_dist = xi - x1 + yi - y1
D1 = abs(right_top[0] - left_bottom[0]) + abs(right_top[1] - left_bottom[1])
D2 = abs(right_bottom[0] - left_top[0]) + abs(right_bottom[1] - left_top[1])
D3 = abs(left_top[0] - left_bottom[0]) + abs(left_top[1] - left_bottom[1])
D4 = abs(right_top[0] - right_bottom[0]) + abs(right_top[1] - right_bottom[1])
D5 = abs(left_top[0] - right_top[0]) + abs(left_top[1] - right_top[1])
D6 = abs(left_bottom[0] - right_bottom[0]) + abs(left_bottom[1] - right_bottom[1])
print(max(D1, D2, D3, D4, D5, D6))
| Statement
There are N points on the 2D plane, i-th of which is located on (x_i, y_i).
There can be multiple points that share the same coordinate. What is the
maximum possible Manhattan distance between two distinct points?
Here, the _Manhattan distance_ between two points (x_i, y_i) and (x_j, y_j) is
defined by |x_i-x_j| + |y_i-y_j|. | [{"input": "3\n 1 1\n 2 4\n 3 2", "output": "4\n \n\nThe Manhattan distance between the first point and the second point is\n|1-2|+|1-4|=4, which is maximum possible.\n\n* * *"}, {"input": "2\n 1 1\n 1 1", "output": "0"}] |
Print the answer.
* * * | s084305398 | Accepted | p02556 | Input is given from Standard Input in the following format:
N
x_1 y_1
x_2 y_2
:
x_N y_N | l = [list(map(int, input().split())) for _ in range(int(input()))]
f = sorted([x + y for x, y in l])
g = sorted([x - y for x, y in l])
print(max(f[-1] - f[0], g[-1] - g[0]))
| Statement
There are N points on the 2D plane, i-th of which is located on (x_i, y_i).
There can be multiple points that share the same coordinate. What is the
maximum possible Manhattan distance between two distinct points?
Here, the _Manhattan distance_ between two points (x_i, y_i) and (x_j, y_j) is
defined by |x_i-x_j| + |y_i-y_j|. | [{"input": "3\n 1 1\n 2 4\n 3 2", "output": "4\n \n\nThe Manhattan distance between the first point and the second point is\n|1-2|+|1-4|=4, which is maximum possible.\n\n* * *"}, {"input": "2\n 1 1\n 1 1", "output": "0"}] |
Print the answer.
* * * | s704821786 | Wrong Answer | p02556 | Input is given from Standard Input in the following format:
N
x_1 y_1
x_2 y_2
:
x_N y_N | n = input()
n = int(n)
p = []
for i in range(n):
x, y = map(int, input().split(" "))
p.append([x, y])
maXP = max(p, key=lambda x: x[0])
miXP = min(p, key=lambda x: x[0])
maYP = max(p, key=lambda x: x[1])
miYP = min(p, key=lambda x: x[1])
mp = [maXP, miXP, maYP, miYP]
md = -1
for i in range(3):
for j in range(i + 1, 4):
x1, y1 = mp[i]
x2, y2 = mp[j]
md = abs(x1 - x2) + abs(y1 - y2)
md = int(md)
print(md)
| Statement
There are N points on the 2D plane, i-th of which is located on (x_i, y_i).
There can be multiple points that share the same coordinate. What is the
maximum possible Manhattan distance between two distinct points?
Here, the _Manhattan distance_ between two points (x_i, y_i) and (x_j, y_j) is
defined by |x_i-x_j| + |y_i-y_j|. | [{"input": "3\n 1 1\n 2 4\n 3 2", "output": "4\n \n\nThe Manhattan distance between the first point and the second point is\n|1-2|+|1-4|=4, which is maximum possible.\n\n* * *"}, {"input": "2\n 1 1\n 1 1", "output": "0"}] |
Print the answer.
* * * | s083923043 | Wrong Answer | p02556 | Input is given from Standard Input in the following format:
N
x_1 y_1
x_2 y_2
:
x_N y_N | n = int(input())
a_list = [list(map(int, input().split())) for i in range(n)]
A = []
for i in range(n):
A.append(a_list[i][0] ** 2 + a_list[i][1] ** 2)
X = A.index(max(A))
X = int(X)
Y = A.index(min(A))
Y = int(Y)
print(abs(a_list[X][0] - a_list[Y][0]) + abs(a_list[X][1] - a_list[Y][1]))
| Statement
There are N points on the 2D plane, i-th of which is located on (x_i, y_i).
There can be multiple points that share the same coordinate. What is the
maximum possible Manhattan distance between two distinct points?
Here, the _Manhattan distance_ between two points (x_i, y_i) and (x_j, y_j) is
defined by |x_i-x_j| + |y_i-y_j|. | [{"input": "3\n 1 1\n 2 4\n 3 2", "output": "4\n \n\nThe Manhattan distance between the first point and the second point is\n|1-2|+|1-4|=4, which is maximum possible.\n\n* * *"}, {"input": "2\n 1 1\n 1 1", "output": "0"}] |
Print the answer.
* * * | s898816023 | Accepted | p02556 | Input is given from Standard Input in the following format:
N
x_1 y_1
x_2 y_2
:
x_N y_N | import sys
sys.setrecursionlimit(10**9)
# input = sys.stdin.readline ####
def int1(x):
return int(x) - 1
def II():
return int(input())
def MI():
return map(int, input().split())
def MI1():
return map(int1, input().split())
def LI():
return list(map(int, input().split()))
def LI1():
return list(map(int1, input().split()))
def LLI(rows_number):
return [LI() for _ in range(rows_number)]
def MS():
return input().split()
def LS():
return list(input())
def LLS(rows_number):
return [LS() for _ in range(rows_number)]
def printlist(lst, k=" "):
print(k.join(list(map(str, lst))))
INF = float("inf")
# from math import ceil, floor, log2
# from collections import deque, defaultdict
# from itertools import combinations as comb, combinations_with_replacement as comb_w, accumulate, product, permutations
# from heapq import heapify, heappop, heappush
# import numpy as np # cumsum
# from bisect import bisect_left, bisect_right
def solve():
N = II()
Z = []
for i in range(N):
x, y = MI()
Z.append((x - y, x + y))
# print(Z)
minx = miny = INF
maxx = maxy = -INF
for z in Z:
minx = min(minx, z[0])
maxx = max(maxx, z[0])
miny = min(miny, z[1])
maxy = max(maxy, z[1])
print(max(maxx - minx, maxy - miny))
if __name__ == "__main__":
solve()
| Statement
There are N points on the 2D plane, i-th of which is located on (x_i, y_i).
There can be multiple points that share the same coordinate. What is the
maximum possible Manhattan distance between two distinct points?
Here, the _Manhattan distance_ between two points (x_i, y_i) and (x_j, y_j) is
defined by |x_i-x_j| + |y_i-y_j|. | [{"input": "3\n 1 1\n 2 4\n 3 2", "output": "4\n \n\nThe Manhattan distance between the first point and the second point is\n|1-2|+|1-4|=4, which is maximum possible.\n\n* * *"}, {"input": "2\n 1 1\n 1 1", "output": "0"}] |
Print the answer.
* * * | s491528466 | Wrong Answer | p02556 | Input is given from Standard Input in the following format:
N
x_1 y_1
x_2 y_2
:
x_N y_N | n = int(input())
x = []
y = []
for _ in range(n):
x_k, y_k = map(int, input().split())
x.append(x_k)
y.append(y_k)
x_max, x_min, y_max, y_min = x[0], x[0], y[0], y[0]
for i in range(n):
if x[i] > x_max:
x_max = x[i]
if x[i] < x_min:
x_min = x[i]
if y[i] > y_max:
y_max = y[i]
if y[i] < y_min:
y_min = y[i]
# print( x_max, x_min, y_max, y_min )
right, top, left, bottom = [], [], [], []
for i in range(n):
if x[i] == x_max:
right.append(y[i])
if y[i] == y_max:
top.append(x[i])
if x[i] == x_min:
left.append(y[i])
if y[i] == y_min:
bottom.append(x[i])
ver = [(0, 0) for _ in range(8)]
ver[0] = (x_max, max(right))
ver[1] = (max(top), y_max)
ver[2] = (min(top), y_max)
ver[3] = (x_min, max(left))
ver[4] = (x_min, min(left))
ver[5] = (y_min, min(bottom))
ver[6] = (y_min, max(bottom))
ver[7] = (x_max, min(right))
max_length = 0
for i in range(8):
for j in range(8):
length = abs(ver[i][0] - ver[j][0]) + abs(ver[i][1] - ver[j][1])
if length > max_length:
max_length = length
# print( ver[ i ], ver[ j ], length )
# print( ver )
print(max_length)
| Statement
There are N points on the 2D plane, i-th of which is located on (x_i, y_i).
There can be multiple points that share the same coordinate. What is the
maximum possible Manhattan distance between two distinct points?
Here, the _Manhattan distance_ between two points (x_i, y_i) and (x_j, y_j) is
defined by |x_i-x_j| + |y_i-y_j|. | [{"input": "3\n 1 1\n 2 4\n 3 2", "output": "4\n \n\nThe Manhattan distance between the first point and the second point is\n|1-2|+|1-4|=4, which is maximum possible.\n\n* * *"}, {"input": "2\n 1 1\n 1 1", "output": "0"}] |
Print the answer.
* * * | s020532603 | Wrong Answer | p02556 | Input is given from Standard Input in the following format:
N
x_1 y_1
x_2 y_2
:
x_N y_N | n = int(input())
ab = [list(map(int, input().split())) for _ in range(n)]
edge = [0] * 8
tate = 0
yoko = 0
summ = 10**10
sumn = 0
for i in range(n):
x = ab[i][0]
y = ab[i][1]
if x + y <= summ:
edge[0] = x
edge[1] = y
summ = x + y
if x + y >= sumn:
edge[2] = x
edge[3] = y
sumn = x + y
if x - y <= tate:
edge[4] = x
edge[5] = y
tate = x - y
if y - x <= yoko:
edge[6] = x
edge[7] = y
yoko = y - x
a = abs(edge[0] - edge[2]) + abs(edge[1] - edge[3])
b = abs(edge[0] - edge[4]) + abs(edge[1] - edge[5])
c = abs(edge[0] - edge[6]) + abs(edge[1] - edge[7])
d = abs(edge[2] - edge[4]) + abs(edge[3] - edge[5])
e = abs(edge[2] - edge[6]) + abs(edge[3] - edge[7])
f = abs(edge[4] - edge[6]) + abs(edge[5] - edge[7])
print(max(a, b, c, d, e, f))
| Statement
There are N points on the 2D plane, i-th of which is located on (x_i, y_i).
There can be multiple points that share the same coordinate. What is the
maximum possible Manhattan distance between two distinct points?
Here, the _Manhattan distance_ between two points (x_i, y_i) and (x_j, y_j) is
defined by |x_i-x_j| + |y_i-y_j|. | [{"input": "3\n 1 1\n 2 4\n 3 2", "output": "4\n \n\nThe Manhattan distance between the first point and the second point is\n|1-2|+|1-4|=4, which is maximum possible.\n\n* * *"}, {"input": "2\n 1 1\n 1 1", "output": "0"}] |
Print the answer.
* * * | s604205601 | Wrong Answer | p02556 | Input is given from Standard Input in the following format:
N
x_1 y_1
x_2 y_2
:
x_N y_N | N = int(input())
P = [tuple(map(int, input().split())) for _ in [0] * N]
xM, yM, xm, ym = 0, 0, 10**9 + 7, 10**9 + 7
xM_list, xm_list, yM_list, ym_list = [], [], [], []
for i in range(N):
if xM < P[i][0]:
xM = P[i][0]
xM_list = [P[i]]
elif xM == P[i][0]:
xM_list.append(P[i])
if xm > P[i][0]:
xm = P[i][0]
xm_list = [P[i]]
elif xm == P[i][0]:
xm_list.append(P[i])
if yM < P[i][1]:
yM = P[i][1]
yM_list = [P[i]]
elif yM == P[i][1]:
yM_list.append(P[i])
if ym > P[i][1]:
ym = P[i][1]
ym_list = [P[i]]
elif ym == P[i][1]:
ym_list.append(P[i])
xm_list.sort(lambda x: x[1])
xM_list.sort(lambda x: x[1])
ym_list.sort(lambda x: x[0])
yM_list.sort(lambda x: x[0])
goodP = []
if len(xm_list) > 1:
goodP.append(xm_list[-1])
goodP.append(xm_list[0])
else:
goodP.append(xm_list[0])
if len(xM_list) > 1:
goodP.append(xM_list[-1])
goodP.append(xM_list[0])
else:
goodP.append(xM_list[0])
if len(ym_list) > 1:
goodP.append(ym_list[-1])
goodP.append(ym_list[0])
else:
goodP.append(ym_list[0])
if len(yM_list) > 1:
goodP.append(yM_list[-1])
goodP.append(yM_list[0])
else:
goodP.append(yM_list[0])
res = []
for i in range(len(goodP)):
for j in range(len(goodP)):
if not i < j:
continue
res.append(abs(goodP[i][0] - goodP[j][0]) + abs(goodP[i][1] - goodP[j][1]))
print(max(res))
| Statement
There are N points on the 2D plane, i-th of which is located on (x_i, y_i).
There can be multiple points that share the same coordinate. What is the
maximum possible Manhattan distance between two distinct points?
Here, the _Manhattan distance_ between two points (x_i, y_i) and (x_j, y_j) is
defined by |x_i-x_j| + |y_i-y_j|. | [{"input": "3\n 1 1\n 2 4\n 3 2", "output": "4\n \n\nThe Manhattan distance between the first point and the second point is\n|1-2|+|1-4|=4, which is maximum possible.\n\n* * *"}, {"input": "2\n 1 1\n 1 1", "output": "0"}] |
Print the answer.
* * * | s429495336 | Wrong Answer | p02556 | Input is given from Standard Input in the following format:
N
x_1 y_1
x_2 y_2
:
x_N y_N | input = input()
| Statement
There are N points on the 2D plane, i-th of which is located on (x_i, y_i).
There can be multiple points that share the same coordinate. What is the
maximum possible Manhattan distance between two distinct points?
Here, the _Manhattan distance_ between two points (x_i, y_i) and (x_j, y_j) is
defined by |x_i-x_j| + |y_i-y_j|. | [{"input": "3\n 1 1\n 2 4\n 3 2", "output": "4\n \n\nThe Manhattan distance between the first point and the second point is\n|1-2|+|1-4|=4, which is maximum possible.\n\n* * *"}, {"input": "2\n 1 1\n 1 1", "output": "0"}] |
Print the answer.
* * * | s709064250 | Accepted | p02556 | Input is given from Standard Input in the following format:
N
x_1 y_1
x_2 y_2
:
x_N y_N | n = int(input())
a0 = 10**10
b0 = 10**10
c0 = 10**10
d0 = 10**10
a1 = -(10**10)
b1 = -(10**10)
c1 = -(10**10)
d1 = -(10**10)
for i in range(n):
x, y = map(int, input().split())
a = x + y
if a0 > a:
a0 = a
if a1 < a:
a1 = a
b = x - y
if b0 > b:
b0 = b
if b1 < b:
b1 = b
c = -x + y
if c0 > c:
c0 = c
if c1 < c:
c1 = c
d = -x - y
if d0 > d:
d0 = d
if d1 < d:
d1 = d
print(max(a1 - a0, b1 - b0, c1 - c0, d1 - d0))
| Statement
There are N points on the 2D plane, i-th of which is located on (x_i, y_i).
There can be multiple points that share the same coordinate. What is the
maximum possible Manhattan distance between two distinct points?
Here, the _Manhattan distance_ between two points (x_i, y_i) and (x_j, y_j) is
defined by |x_i-x_j| + |y_i-y_j|. | [{"input": "3\n 1 1\n 2 4\n 3 2", "output": "4\n \n\nThe Manhattan distance between the first point and the second point is\n|1-2|+|1-4|=4, which is maximum possible.\n\n* * *"}, {"input": "2\n 1 1\n 1 1", "output": "0"}] |
Print the answer.
* * * | s492059520 | Accepted | p02556 | Input is given from Standard Input in the following format:
N
x_1 y_1
x_2 y_2
:
x_N y_N | n = int(input())
maxda = -10**18
minda = 10**18
maxdb = -10**18
mindb = 10**18
for i in range(n):
x,y = map(int,input().split())
maxda = max(maxda, x-y)
minda = min(minda, x-y)
maxdb = max(maxdb, x+y)
mindb = min(mindb, y+x)
print(max(maxda-minda, maxdb-mindb)) | Statement
There are N points on the 2D plane, i-th of which is located on (x_i, y_i).
There can be multiple points that share the same coordinate. What is the
maximum possible Manhattan distance between two distinct points?
Here, the _Manhattan distance_ between two points (x_i, y_i) and (x_j, y_j) is
defined by |x_i-x_j| + |y_i-y_j|. | [{"input": "3\n 1 1\n 2 4\n 3 2", "output": "4\n \n\nThe Manhattan distance between the first point and the second point is\n|1-2|+|1-4|=4, which is maximum possible.\n\n* * *"}, {"input": "2\n 1 1\n 1 1", "output": "0"}] |
Print the answer.
* * * | s003212312 | Runtime Error | p02556 | Input is given from Standard Input in the following format:
N
x_1 y_1
x_2 y_2
:
x_N y_N | n = int(input())
l1 = []
l2 = []
for i in range(n):
a, b = map(int, input().split())
if a == b:
l1.append(a + b)
l2.append(a + b)
elif a > b:
l1.append(a + b)
else:
l2.append(a + b)
l1.sort()
l2.sort()
a, b, c, d = l1[0], l1[-1], l2[0], l2[-1]
print(abs(max(a - c, a - d, b - c, b - d, key=abs)))
| Statement
There are N points on the 2D plane, i-th of which is located on (x_i, y_i).
There can be multiple points that share the same coordinate. What is the
maximum possible Manhattan distance between two distinct points?
Here, the _Manhattan distance_ between two points (x_i, y_i) and (x_j, y_j) is
defined by |x_i-x_j| + |y_i-y_j|. | [{"input": "3\n 1 1\n 2 4\n 3 2", "output": "4\n \n\nThe Manhattan distance between the first point and the second point is\n|1-2|+|1-4|=4, which is maximum possible.\n\n* * *"}, {"input": "2\n 1 1\n 1 1", "output": "0"}] |
Print the answer.
* * * | s738078948 | Wrong Answer | p02556 | Input is given from Standard Input in the following format:
N
x_1 y_1
x_2 y_2
:
x_N y_N | from sys import stdin
input = stdin.readline
xmin1, xmax1 = None, None
ymin1, ymax1 = None, None
xmin2, xmax2 = None, None
ymin2, ymax2 = None, None
for _ in range(int(input())):
x, y = map(int, input().split())
if xmin1 == None:
xmin1 = xmax1 = ymin1 = ymax1 = (x, y)
xmin2 = xmax2 = ymin2 = ymax2 = (x, y)
else:
if xmin1[0] > x:
xmin1 = x, y
xmin2 = x, y
elif xmin1[0] == x:
if xmin1[1] < y:
xmin1 = x, y
if xmin2[1] > y:
xmin2 = x, y
if xmax1[0] < x:
xmax1 = x, y
xmax2 = x, y
elif xmax1[0] == x:
if xmax1[1] < y:
xmax1 = x, y
if xmax2[1] > y:
xmax2 = x, y
if ymin1[1] > y:
ymin1 = x, y
ymin2 = x, y
elif ymin1[1] == y:
if ymin1[0] > x:
ymin1 = x, y
if ymin2[0] < x:
ymin2 = x, y
if ymax1[1] < y:
ymax1 = x, y
ymax2 = x, y
elif ymax1[1] == y:
if ymax1[0] > x:
ymax1 = x, y
if ymax2[0] < x:
ymax2 = x, y
arr = [xmin1, xmin2, xmax1, xmax2, ymin1, ymin2, ymax1, ymax2]
man = 0
for i, j in arr:
for i1, j1 in arr:
man = max(man, abs(i - i1) + abs(j - j1))
print(man)
| Statement
There are N points on the 2D plane, i-th of which is located on (x_i, y_i).
There can be multiple points that share the same coordinate. What is the
maximum possible Manhattan distance between two distinct points?
Here, the _Manhattan distance_ between two points (x_i, y_i) and (x_j, y_j) is
defined by |x_i-x_j| + |y_i-y_j|. | [{"input": "3\n 1 1\n 2 4\n 3 2", "output": "4\n \n\nThe Manhattan distance between the first point and the second point is\n|1-2|+|1-4|=4, which is maximum possible.\n\n* * *"}, {"input": "2\n 1 1\n 1 1", "output": "0"}] |
Print the answer.
* * * | s592568511 | Accepted | p02556 | Input is given from Standard Input in the following format:
N
x_1 y_1
x_2 y_2
:
x_N y_N | #!/usr/bin/env python3
(n,), *d = [[*map(int, o.split())] for o in open(0)]
M = [[x - y for x, y in d], [x + y for x, y in d]]
print(max(max(M[d]) - min(M[d]) for d in [0, 1]))
| Statement
There are N points on the 2D plane, i-th of which is located on (x_i, y_i).
There can be multiple points that share the same coordinate. What is the
maximum possible Manhattan distance between two distinct points?
Here, the _Manhattan distance_ between two points (x_i, y_i) and (x_j, y_j) is
defined by |x_i-x_j| + |y_i-y_j|. | [{"input": "3\n 1 1\n 2 4\n 3 2", "output": "4\n \n\nThe Manhattan distance between the first point and the second point is\n|1-2|+|1-4|=4, which is maximum possible.\n\n* * *"}, {"input": "2\n 1 1\n 1 1", "output": "0"}] |
Print the answer.
* * * | s813045160 | Accepted | p02556 | Input is given from Standard Input in the following format:
N
x_1 y_1
x_2 y_2
:
x_N y_N | # from collections import deque,defaultdict
printn = lambda x: print(x, end="")
inn = lambda: int(input())
inl = lambda: list(map(int, input().split()))
inm = lambda: map(int, input().split())
ins = lambda: input().strip()
DBG = True # and False
BIG = 10**18
R = 10**9 + 7
# R = 998244353
def ddprint(x):
if DBG:
print(x)
n = inn()
x = []
y = []
for i in range(n):
xx, yy = inm()
x.append(xx)
y.append(yy)
dif = [x[i] - y[i] for i in range(n)]
sum = [x[i] + y[i] for i in range(n)]
print(max(max(dif) - min(dif), max(sum) - min(sum)))
| Statement
There are N points on the 2D plane, i-th of which is located on (x_i, y_i).
There can be multiple points that share the same coordinate. What is the
maximum possible Manhattan distance between two distinct points?
Here, the _Manhattan distance_ between two points (x_i, y_i) and (x_j, y_j) is
defined by |x_i-x_j| + |y_i-y_j|. | [{"input": "3\n 1 1\n 2 4\n 3 2", "output": "4\n \n\nThe Manhattan distance between the first point and the second point is\n|1-2|+|1-4|=4, which is maximum possible.\n\n* * *"}, {"input": "2\n 1 1\n 1 1", "output": "0"}] |
Print the answer.
* * * | s652511192 | Wrong Answer | p02556 | Input is given from Standard Input in the following format:
N
x_1 y_1
x_2 y_2
:
x_N y_N | import sys
input = sys.stdin.readline
def main(args):
n = int(input())
minx = float("inf")
maxx = 0
miny = float("inf")
maxy = 0
place = []
for i in range(n):
x, y = map(int, input().split())
minx = min(minx, x)
maxx = max(maxx, x)
miny = min(miny, y)
maxy = max(maxy, y)
place.append((x, y))
Minx = []
Maxx = []
Miny = []
Maxy = []
for x, y in place:
if x == minx:
Minx.append((x, y))
elif x == maxx:
Maxx.append((x, y))
if y == miny:
Miny.append((x, y))
elif y == maxy:
Maxy.append((x, y))
if not Maxx:
print(maxy - miny)
exit()
if not Maxy:
print(maxx - minx)
exit()
ans = 0
for i in range(len(Maxx)):
xi, yi = Maxx[i]
for j in range(len(Minx)):
xj, yj = Minx[j]
tmp = abs(xi - xj) + abs(yi - yj)
ans = max(tmp, ans)
for i in range(len(Maxx)):
xi, yi = Maxx[i]
for j in range(len(Miny)):
xj, yj = Miny[j]
tmp = abs(xi - xj) + abs(yi - yj)
ans = max(tmp, ans)
for i in range(len(Maxy)):
xi, yi = Maxy[i]
for j in range(len(Miny)):
xj, yj = Miny[j]
tmp = abs(xi - xj) + abs(yi - yj)
ans = max(ans, tmp)
for i in range(len(Maxy)):
xi, yi = Maxy[i]
for j in range(len(Minx)):
xj, yj = Minx[j]
tmp = abs(xi - xj) + abs(yi - yj)
ans = max(ans, tmp)
for i in range(len(Maxx)):
xi, yi = Maxx[i]
for j in range(len(Maxy)):
xj, yj = Maxy[j]
tmp = abs(xi - xj) + abs(yi - yj)
ans = max(tmp, ans)
for i in range(len(Minx)):
xi, yi = Minx[i]
for j in range(len(Miny)):
xj, yj = Miny[j]
tmp = abs(xi - xj) + abs(yi - yj)
ans = max(tmp, ans)
print(ans)
if __name__ == "__main__":
main(sys.argv[1:])
| Statement
There are N points on the 2D plane, i-th of which is located on (x_i, y_i).
There can be multiple points that share the same coordinate. What is the
maximum possible Manhattan distance between two distinct points?
Here, the _Manhattan distance_ between two points (x_i, y_i) and (x_j, y_j) is
defined by |x_i-x_j| + |y_i-y_j|. | [{"input": "3\n 1 1\n 2 4\n 3 2", "output": "4\n \n\nThe Manhattan distance between the first point and the second point is\n|1-2|+|1-4|=4, which is maximum possible.\n\n* * *"}, {"input": "2\n 1 1\n 1 1", "output": "0"}] |
Print the answer.
* * * | s143423860 | Accepted | p02556 | Input is given from Standard Input in the following format:
N
x_1 y_1
x_2 y_2
:
x_N y_N | sumi = []
diff = []
t = int(input())
for _ in range(t):
z = list(map(int, input().split()))
sumi.append(z[0] + z[1])
diff.append(z[0] - z[1])
print(max(max(diff) - min(diff), max(sumi) - min(sumi)))
| Statement
There are N points on the 2D plane, i-th of which is located on (x_i, y_i).
There can be multiple points that share the same coordinate. What is the
maximum possible Manhattan distance between two distinct points?
Here, the _Manhattan distance_ between two points (x_i, y_i) and (x_j, y_j) is
defined by |x_i-x_j| + |y_i-y_j|. | [{"input": "3\n 1 1\n 2 4\n 3 2", "output": "4\n \n\nThe Manhattan distance between the first point and the second point is\n|1-2|+|1-4|=4, which is maximum possible.\n\n* * *"}, {"input": "2\n 1 1\n 1 1", "output": "0"}] |
Print the answer.
* * * | s291265289 | Accepted | p02556 | Input is given from Standard Input in the following format:
N
x_1 y_1
x_2 y_2
:
x_N y_N | #https://naoyat.hatenablog.jp/entry/k-dimension-manhattan-distance
N=int(input())
kouho=[(10**10)*(-1)]*4#xmax,ymax,xmin,ymin
kouho[2]=10**10
kouho[3]=10**10
ans=0
for i in range(N):
x,y=map(int,input().split())
newx=x-y
newy=x+y
if newx>kouho[0]:
kouho[0]=newx
if newx<kouho[2]:
kouho[2]=newx
if newy>kouho[1]:
kouho[1]=newy
if newy<kouho[3]:
kouho[3]=newy
ans=max(kouho[0]-kouho[2],kouho[1]-kouho[3])
print(ans) | Statement
There are N points on the 2D plane, i-th of which is located on (x_i, y_i).
There can be multiple points that share the same coordinate. What is the
maximum possible Manhattan distance between two distinct points?
Here, the _Manhattan distance_ between two points (x_i, y_i) and (x_j, y_j) is
defined by |x_i-x_j| + |y_i-y_j|. | [{"input": "3\n 1 1\n 2 4\n 3 2", "output": "4\n \n\nThe Manhattan distance between the first point and the second point is\n|1-2|+|1-4|=4, which is maximum possible.\n\n* * *"}, {"input": "2\n 1 1\n 1 1", "output": "0"}] |
Print the answer.
* * * | s893515239 | Wrong Answer | p02556 | Input is given from Standard Input in the following format:
N
x_1 y_1
x_2 y_2
:
x_N y_N | N = int(input())
x, y = map(int,input().split())
min_x = x
max_x = x
min_y = y
max_y = y
L = x ** 2 + y ** 2
min_L = L
max_L = L
for i in range(N-1):
x, y = map(int, input().split())
L = x ** 2 + y ** 2
if min_L > L:
min_x = x
min_y = y
min_L = L
elif max_L < L:
max_x = x
max_y = y
max_L = L
ans = max_x - min_x + max_y - min_y
print(ans) | Statement
There are N points on the 2D plane, i-th of which is located on (x_i, y_i).
There can be multiple points that share the same coordinate. What is the
maximum possible Manhattan distance between two distinct points?
Here, the _Manhattan distance_ between two points (x_i, y_i) and (x_j, y_j) is
defined by |x_i-x_j| + |y_i-y_j|. | [{"input": "3\n 1 1\n 2 4\n 3 2", "output": "4\n \n\nThe Manhattan distance between the first point and the second point is\n|1-2|+|1-4|=4, which is maximum possible.\n\n* * *"}, {"input": "2\n 1 1\n 1 1", "output": "0"}] |
Print the answer.
* * * | s051009876 | Wrong Answer | p02556 | Input is given from Standard Input in the following format:
N
x_1 y_1
x_2 y_2
:
x_N y_N | n = int(input())
maxsum = -float("inf")
minsum = float("inf")
maxdif = -float("inf")
mindif = float("inf")
for i in range(n):
x, y = map(int, input().split())
trysum = x + y
trydif = x - y
if trysum >= maxsum:
maxsum = trysum
if trysum <= minsum:
minsum = trysum
if trydif >= maxdif:
maxdif = trydif
if trydif <= minsum:
mindif = trydif
print(max(maxsum - minsum, maxdif - mindif))
| Statement
There are N points on the 2D plane, i-th of which is located on (x_i, y_i).
There can be multiple points that share the same coordinate. What is the
maximum possible Manhattan distance between two distinct points?
Here, the _Manhattan distance_ between two points (x_i, y_i) and (x_j, y_j) is
defined by |x_i-x_j| + |y_i-y_j|. | [{"input": "3\n 1 1\n 2 4\n 3 2", "output": "4\n \n\nThe Manhattan distance between the first point and the second point is\n|1-2|+|1-4|=4, which is maximum possible.\n\n* * *"}, {"input": "2\n 1 1\n 1 1", "output": "0"}] |
Print the answer.
* * * | s759001938 | Accepted | p02556 | Input is given from Standard Input in the following format:
N
x_1 y_1
x_2 y_2
:
x_N y_N | num = int(input())
sumList = [0] * num
minusList = [0] * num
for id in range(num):
x, y = map(int, input().split())
sumList[id - 1] = x + y
minusList[id - 1] = x - y
sumMax = max(sumList) - min(sumList)
minusMax = max(minusList) - min(minusList)
print(max(sumMax, minusMax))
| Statement
There are N points on the 2D plane, i-th of which is located on (x_i, y_i).
There can be multiple points that share the same coordinate. What is the
maximum possible Manhattan distance between two distinct points?
Here, the _Manhattan distance_ between two points (x_i, y_i) and (x_j, y_j) is
defined by |x_i-x_j| + |y_i-y_j|. | [{"input": "3\n 1 1\n 2 4\n 3 2", "output": "4\n \n\nThe Manhattan distance between the first point and the second point is\n|1-2|+|1-4|=4, which is maximum possible.\n\n* * *"}, {"input": "2\n 1 1\n 1 1", "output": "0"}] |
Print the answer.
* * * | s906827534 | Wrong Answer | p02556 | Input is given from Standard Input in the following format:
N
x_1 y_1
x_2 y_2
:
x_N y_N | n = int(input())
a = 0
b = 10**9
c = 0
d = 10**9
aint = 0
bint = 0
cint = 0
dint = 0
g = []
for i in range(n):
x, y = map(int, input().split())
if x > a:
a = x
aint = i
if x < b:
b = x
bint = i
if y > c:
c = y
cint = i
if y < d:
d = y
dint = i
g.append([x, y])
r = [aint, bint, cint, dint]
ans = [0]
def man(a, b):
return abs(g[a][0] - g[b][0]) + abs(g[a][1] - g[b][1])
for i in r:
for j in r:
if i == j:
continue
ans.append(man(i, j))
print(max(ans))
| Statement
There are N points on the 2D plane, i-th of which is located on (x_i, y_i).
There can be multiple points that share the same coordinate. What is the
maximum possible Manhattan distance between two distinct points?
Here, the _Manhattan distance_ between two points (x_i, y_i) and (x_j, y_j) is
defined by |x_i-x_j| + |y_i-y_j|. | [{"input": "3\n 1 1\n 2 4\n 3 2", "output": "4\n \n\nThe Manhattan distance between the first point and the second point is\n|1-2|+|1-4|=4, which is maximum possible.\n\n* * *"}, {"input": "2\n 1 1\n 1 1", "output": "0"}] |
Print the answer.
* * * | s455917741 | Wrong Answer | p02556 | Input is given from Standard Input in the following format:
N
x_1 y_1
x_2 y_2
:
x_N y_N | N = int(input())
xy = []
for _ in range(N):
x, y = map(int, input().split())
xy.append((x, y))
x0, y0 = xy[0]
x_max, x_min, y_max, y_min, t_max, t_min = x0, x0, y0, y0, x0 + y0, x0 + y0
cand = [xy[0] for _ in range(6)]
for x, y in xy[1:]:
if x > x_max:
x_max = x
cand[0] = (x, y)
if x < x_min:
x_min = x
cand[1] = (x, y)
if y > y_max:
y_max = y
cand[2] = (x, y)
if y < y_min:
y_min = y
cand[3] = (x, y)
if x + y > t_max:
t_max = x + y
cand[4] = (x, y)
if x + y < t_min:
t_min = x + y
cand[5] = (x, y)
ans = 0
for i in range(5):
x1, y1 = cand[i]
for j in range(6):
x2, y2 = cand[j]
ans = max(ans, abs(x1 - x2) + abs(y1 - y2))
print(ans)
| Statement
There are N points on the 2D plane, i-th of which is located on (x_i, y_i).
There can be multiple points that share the same coordinate. What is the
maximum possible Manhattan distance between two distinct points?
Here, the _Manhattan distance_ between two points (x_i, y_i) and (x_j, y_j) is
defined by |x_i-x_j| + |y_i-y_j|. | [{"input": "3\n 1 1\n 2 4\n 3 2", "output": "4\n \n\nThe Manhattan distance between the first point and the second point is\n|1-2|+|1-4|=4, which is maximum possible.\n\n* * *"}, {"input": "2\n 1 1\n 1 1", "output": "0"}] |
Print the answer.
* * * | s660403966 | Accepted | p02556 | Input is given from Standard Input in the following format:
N
x_1 y_1
x_2 y_2
:
x_N y_N | n=int(input())
xbox=[]
ybox=[]
for i in range(n):
x,y = map(int,input().split())
xbox.append(x)
ybox.append(y)
xmax=max(xbox)
xmin = min(xbox)
ymax=max(ybox)
ymin=min(ybox)
box1=[]
box2=[]
box3=[]
box4=[]
for i in range(n):
box1.append(xmax+ymax-xbox[i]-ybox[i])
box2.append(-xmin + ymax + xbox[i] - ybox[i])
box3.append(xmax - ymax - xbox[i] + ybox[i])
box4.append(-xmax - ymax + xbox[i] + ybox[i])
print(max([max(box1)-min(box1),max(box2)-min(box2),max(box3)-min(box3),max(box4)-min(box4)]))
| Statement
There are N points on the 2D plane, i-th of which is located on (x_i, y_i).
There can be multiple points that share the same coordinate. What is the
maximum possible Manhattan distance between two distinct points?
Here, the _Manhattan distance_ between two points (x_i, y_i) and (x_j, y_j) is
defined by |x_i-x_j| + |y_i-y_j|. | [{"input": "3\n 1 1\n 2 4\n 3 2", "output": "4\n \n\nThe Manhattan distance between the first point and the second point is\n|1-2|+|1-4|=4, which is maximum possible.\n\n* * *"}, {"input": "2\n 1 1\n 1 1", "output": "0"}] |
Print the answer.
* * * | s353876394 | Accepted | p02556 | Input is given from Standard Input in the following format:
N
x_1 y_1
x_2 y_2
:
x_N y_N | n = int(input())
arr1 = []
arr2 = []
for i in range(n):
h, m = list(map(int, input().split()))
arr1.append(h)
arr2.append(m)
l1, l2, l3, l4 = [], [], [], []
for i in range(len(arr1)):
l1 += [arr1[i] + arr2[i]]
l2 += [arr1[i] - arr2[i]]
l3 += [-arr1[i] + arr2[i]]
l4 += [-arr1[i] - arr2[i]]
res = []
res += [max(l1) - min(l1)]
res += [max(l2) - min(l2)]
res += [max(l3) - min(l3)]
res += [max(l4) - min(l4)]
print(max(res))
| Statement
There are N points on the 2D plane, i-th of which is located on (x_i, y_i).
There can be multiple points that share the same coordinate. What is the
maximum possible Manhattan distance between two distinct points?
Here, the _Manhattan distance_ between two points (x_i, y_i) and (x_j, y_j) is
defined by |x_i-x_j| + |y_i-y_j|. | [{"input": "3\n 1 1\n 2 4\n 3 2", "output": "4\n \n\nThe Manhattan distance between the first point and the second point is\n|1-2|+|1-4|=4, which is maximum possible.\n\n* * *"}, {"input": "2\n 1 1\n 1 1", "output": "0"}] |
Print the answer.
* * * | s541570051 | Wrong Answer | p02556 | Input is given from Standard Input in the following format:
N
x_1 y_1
x_2 y_2
:
x_N y_N | n = int(input())
str_list = [list(input().split()) for _ in range(n)]
count = 0
u = 0
for n in str_list:
if count == 0:
m = n
count += 1
continue
if abs(int(n[0]) - int(m[0])) + abs(int(n[1]) - int(m[1])) > u:
u = abs(int(n[0]) - int(m[0])) + abs(int(n[1]) - int(m[1]))
m = n
count += 1
print(u)
| Statement
There are N points on the 2D plane, i-th of which is located on (x_i, y_i).
There can be multiple points that share the same coordinate. What is the
maximum possible Manhattan distance between two distinct points?
Here, the _Manhattan distance_ between two points (x_i, y_i) and (x_j, y_j) is
defined by |x_i-x_j| + |y_i-y_j|. | [{"input": "3\n 1 1\n 2 4\n 3 2", "output": "4\n \n\nThe Manhattan distance between the first point and the second point is\n|1-2|+|1-4|=4, which is maximum possible.\n\n* * *"}, {"input": "2\n 1 1\n 1 1", "output": "0"}] |
Print the answer.
* * * | s185189461 | Wrong Answer | p02556 | Input is given from Standard Input in the following format:
N
x_1 y_1
x_2 y_2
:
x_N y_N | N = int(input())
tmp1 = []
tmp2 = []
tmp3 = []
tmp4 = []
for i in range(N):
x, y = map(int, input().split())
if x >= 0 and y >= 0:
tmp1.append([x, y, abs(x) + abs(y)])
if x >= 0 and y <= 0:
tmp2.append([x, y, abs(x) + abs(y)])
if x <= 0 and y <= 0:
tmp3.append([x, y, abs(x) + abs(y)])
if x <= 0 and y >= 0:
tmp4.append([x, y, abs(x) + abs(y)])
ans = 0
if len(tmp1) > 0:
tmp = []
for i in range(len(tmp1)):
tmp.append(tmp1[i][2])
ans = max(ans, max(tmp) - min(tmp))
if len(tmp2) > 0:
tmp = []
for i in range(len(tmp2)):
tmp.append(tmp2[i][2])
ans = max(ans, max(tmp) - min(tmp))
if len(tmp3) > 0:
tmp = []
for i in range(len(tmp3)):
tmp.append(tmp1[i][2])
ans = max(ans, max(tmp) - min(tmp))
if len(tmp4) > 0:
tmp = []
for i in range(len(tmp4)):
tmp.append(tmp1[i][2])
ans = max(ans, max(tmp) - min(tmp))
print(ans)
| Statement
There are N points on the 2D plane, i-th of which is located on (x_i, y_i).
There can be multiple points that share the same coordinate. What is the
maximum possible Manhattan distance between two distinct points?
Here, the _Manhattan distance_ between two points (x_i, y_i) and (x_j, y_j) is
defined by |x_i-x_j| + |y_i-y_j|. | [{"input": "3\n 1 1\n 2 4\n 3 2", "output": "4\n \n\nThe Manhattan distance between the first point and the second point is\n|1-2|+|1-4|=4, which is maximum possible.\n\n* * *"}, {"input": "2\n 1 1\n 1 1", "output": "0"}] |
Print the answer.
* * * | s670628905 | Wrong Answer | p02556 | Input is given from Standard Input in the following format:
N
x_1 y_1
x_2 y_2
:
x_N y_N | a = []
for t in range(int(input())):
x, y = [int(_) for _ in input().split()]
a.append([x, y])
a.sort()
print(abs(a[-1][0] - a[0][0]) + abs(a[-1][1] - a[0][1]))
| Statement
There are N points on the 2D plane, i-th of which is located on (x_i, y_i).
There can be multiple points that share the same coordinate. What is the
maximum possible Manhattan distance between two distinct points?
Here, the _Manhattan distance_ between two points (x_i, y_i) and (x_j, y_j) is
defined by |x_i-x_j| + |y_i-y_j|. | [{"input": "3\n 1 1\n 2 4\n 3 2", "output": "4\n \n\nThe Manhattan distance between the first point and the second point is\n|1-2|+|1-4|=4, which is maximum possible.\n\n* * *"}, {"input": "2\n 1 1\n 1 1", "output": "0"}] |
Print the answer.
* * * | s677470950 | Accepted | p02556 | Input is given from Standard Input in the following format:
N
x_1 y_1
x_2 y_2
:
x_N y_N | N = int(input())
L = [list(map(int, input().split())) for _ in range(N)]
L_1 = [l[0] + l[1] for l in L]
L_2 = [(10**9 + 1 - l[0]) + l[1] for l in L]
L_3 = [(10**9 + 1 - l[1]) + l[0] for l in L]
L_4 = [(10**9 + 1 - l[0]) + (10**9 + 1 - l[1]) for l in L]
L_1.sort()
a = L_1[-1] - L_1[0]
L_2.sort()
b = L_2[-1] - L_2[0]
L_3.sort()
c = L_3[-1] - L_3[0]
L_4.sort()
d = L_4[-1] - L_4[0]
print(max(a, b, c, d))
| Statement
There are N points on the 2D plane, i-th of which is located on (x_i, y_i).
There can be multiple points that share the same coordinate. What is the
maximum possible Manhattan distance between two distinct points?
Here, the _Manhattan distance_ between two points (x_i, y_i) and (x_j, y_j) is
defined by |x_i-x_j| + |y_i-y_j|. | [{"input": "3\n 1 1\n 2 4\n 3 2", "output": "4\n \n\nThe Manhattan distance between the first point and the second point is\n|1-2|+|1-4|=4, which is maximum possible.\n\n* * *"}, {"input": "2\n 1 1\n 1 1", "output": "0"}] |
Print the answer.
* * * | s929407113 | Wrong Answer | p02556 | Input is given from Standard Input in the following format:
N
x_1 y_1
x_2 y_2
:
x_N y_N | n = int(input())
# n = 2*10**5
min_x = float("inf")
max_x = -float("inf")
min_y = float("inf")
max_y = -float("inf")
min_x_pos = []
max_x_pos = []
min_y_pos = []
max_y_pos = []
for i in range(n):
x, y = map(int, input().split())
# x, y = (10**9 , 10**9)
if x < min_x:
min_x = x
min_x_pos = [(x, y)]
elif x == min_x:
min_x_pos.append((x, y))
if y < min_y:
min_y = y
min_y_pos = [(x, y)]
elif y == min_y:
min_y_pos.append((x, y))
if x > max_x:
max_x = x
max_x_pos = [(x, y)]
elif x == max_x:
max_x_pos.append((x, y))
if y > max_y:
max_y = y
max_y_pos = [(x, y)]
elif y == max_y:
max_y_pos.append((x, y))
def calc_dist(pos1, pos2):
return abs(pos1[0] - pos2[0]) + abs(pos1[1] - pos2[1])
min_x_of_max_y = max(min_x_pos, key=lambda pos: pos[1])
min_x_of_min_y = min(min_x_pos, key=lambda pos: pos[1])
min_y_of_max_x = max(min_y_pos, key=lambda pos: pos[0])
min_y_of_min_x = min(min_y_pos, key=lambda pos: pos[0])
max_x_of_max_y = max(max_x_pos, key=lambda pos: pos[1])
max_x_of_min_y = min(max_x_pos, key=lambda pos: pos[1])
max_y_of_max_x = max(max_y_pos, key=lambda pos: pos[0])
max_y_of_min_x = min(max_y_pos, key=lambda pos: pos[0])
candidate_pos = [
min_x_of_max_y,
min_y_of_max_x,
min_y_of_min_x,
min_y_of_max_x,
max_x_of_min_y,
max_x_of_max_y,
max_y_of_min_x,
max_y_of_max_x,
]
answer = 0
for i in range(len(candidate_pos)):
for j in range(len(candidate_pos)):
dis = calc_dist(candidate_pos[i], candidate_pos[j])
answer = max(answer, dis)
print(answer)
| Statement
There are N points on the 2D plane, i-th of which is located on (x_i, y_i).
There can be multiple points that share the same coordinate. What is the
maximum possible Manhattan distance between two distinct points?
Here, the _Manhattan distance_ between two points (x_i, y_i) and (x_j, y_j) is
defined by |x_i-x_j| + |y_i-y_j|. | [{"input": "3\n 1 1\n 2 4\n 3 2", "output": "4\n \n\nThe Manhattan distance between the first point and the second point is\n|1-2|+|1-4|=4, which is maximum possible.\n\n* * *"}, {"input": "2\n 1 1\n 1 1", "output": "0"}] |
Print the answer.
* * * | s885330035 | Wrong Answer | p02556 | Input is given from Standard Input in the following format:
N
x_1 y_1
x_2 y_2
:
x_N y_N | def main():
N = int(input())
p = []
for i in range(N):
x, y = [int(a) for a in input().split(" ")]
p.append({"x" : x, "y" : y})
aveX = 0
aveY = 0
for i in range(N):
aveX += p[i]["x"]
aveY += p[i]["y"]
aveX /= N
aveY /= N
for i in range(N):
p[i]["d"] = abs(aveX - p[i]["x"]) + abs(aveY - p[i]["y"])
p.sort(key=lambda z: z["d"])
D = []
P = [p[-1]]
k = 1
while k < min([len(P), 100]) and abs(p[-k-1]["d"] - P[0]["d"]) < 1:
P.append(p[-k-1])
k += 1
for i in range(N - 1):
for j in range(len(P)):
D.append(abs(P[j]["x"] - p[i]["x"]) + abs(P[j]["y"] - p[i]["y"]))
print(max(D))
main() | Statement
There are N points on the 2D plane, i-th of which is located on (x_i, y_i).
There can be multiple points that share the same coordinate. What is the
maximum possible Manhattan distance between two distinct points?
Here, the _Manhattan distance_ between two points (x_i, y_i) and (x_j, y_j) is
defined by |x_i-x_j| + |y_i-y_j|. | [{"input": "3\n 1 1\n 2 4\n 3 2", "output": "4\n \n\nThe Manhattan distance between the first point and the second point is\n|1-2|+|1-4|=4, which is maximum possible.\n\n* * *"}, {"input": "2\n 1 1\n 1 1", "output": "0"}] |
Print the answer.
* * * | s121027745 | Wrong Answer | p02556 | Input is given from Standard Input in the following format:
N
x_1 y_1
x_2 y_2
:
x_N y_N | n = int(input())
a = [list(map(int, input().split())) for i in range(n)]
X = sorted(a, key=lambda x: x[0])
Y = sorted(a, key=lambda x: x[1])
dis = [0] * 6
dis[0] = abs(X[0][0] - X[n - 1][0]) + abs(X[0][1] - X[n - 1][1])
dis[1] = abs(X[0][0] - Y[n - 1][0]) + abs(X[0][1] - Y[n - 1][1])
dis[2] = abs(X[0][0] - Y[0][0]) + abs(X[0][1] - Y[0][1])
dis[3] = abs(X[n - 1][0] - Y[n - 1][0]) + abs(X[n - 1][1] - Y[n - 1][1])
dis[4] = abs(X[n - 1][0] - Y[0][0]) + abs(X[n - 1][1] - Y[0][1])
dis[5] = abs(Y[n - 1][0] - Y[0][0]) + abs(Y[n - 1][1] - Y[0][1])
print(max(dis))
| Statement
There are N points on the 2D plane, i-th of which is located on (x_i, y_i).
There can be multiple points that share the same coordinate. What is the
maximum possible Manhattan distance between two distinct points?
Here, the _Manhattan distance_ between two points (x_i, y_i) and (x_j, y_j) is
defined by |x_i-x_j| + |y_i-y_j|. | [{"input": "3\n 1 1\n 2 4\n 3 2", "output": "4\n \n\nThe Manhattan distance between the first point and the second point is\n|1-2|+|1-4|=4, which is maximum possible.\n\n* * *"}, {"input": "2\n 1 1\n 1 1", "output": "0"}] |
Print the answer.
* * * | s864747663 | Wrong Answer | p02556 | Input is given from Standard Input in the following format:
N
x_1 y_1
x_2 y_2
:
x_N y_N | n = int(input())
l = [list(map(int, input().split())) for i in range(n)]
x = list(sorted(l, key=lambda x: x[0]))
y = list(sorted(l, key=lambda x: x[1]))
ax = abs(x[0][0] - x[-1][0]) + abs(x[0][1] - x[-1][1])
ay = abs(y[0][0] - y[-1][0]) + abs(y[0][1] - y[-1][1])
print(max(ax, ay))
| Statement
There are N points on the 2D plane, i-th of which is located on (x_i, y_i).
There can be multiple points that share the same coordinate. What is the
maximum possible Manhattan distance between two distinct points?
Here, the _Manhattan distance_ between two points (x_i, y_i) and (x_j, y_j) is
defined by |x_i-x_j| + |y_i-y_j|. | [{"input": "3\n 1 1\n 2 4\n 3 2", "output": "4\n \n\nThe Manhattan distance between the first point and the second point is\n|1-2|+|1-4|=4, which is maximum possible.\n\n* * *"}, {"input": "2\n 1 1\n 1 1", "output": "0"}] |
Print the answer.
* * * | s584507141 | Wrong Answer | p02556 | Input is given from Standard Input in the following format:
N
x_1 y_1
x_2 y_2
:
x_N y_N | N = int(input())
x = []
y = []
"""
minX = 1100000000
minX_id = -1
maxX = 0
maxX_id = -1
minY = 1100000000
minY_id = -1
maxY = 0
maxY_id = -1
"""
for _ in range(N):
X, Y = map(int, input().split())
x.append(X)
y.append(Y)
minX = min(x)
maxX = max(x)
minY = min(y)
maxY = max(y)
minX_id = [i for i, v in enumerate(x) if v == minX]
maxX_id = [i for i, v in enumerate(x) if v == maxX]
minY_id = [i for i, v in enumerate(y) if v == minY]
maxY_id = [i for i, v in enumerate(y) if v == maxY]
"""
print(minX_id)
print(maxX_id)
print(minY_id)
print(maxY_id)
"""
cand = 0
for idx in minX_id:
for IDX in maxX_id:
cand = max(cand, maxX - minX + abs(y[IDX] - y[idx]))
for idy in minY_id:
for IDY in maxY_id:
cand = max(cand, abs(x[IDY] - x[idy]) + maxY - minY)
print(cand)
| Statement
There are N points on the 2D plane, i-th of which is located on (x_i, y_i).
There can be multiple points that share the same coordinate. What is the
maximum possible Manhattan distance between two distinct points?
Here, the _Manhattan distance_ between two points (x_i, y_i) and (x_j, y_j) is
defined by |x_i-x_j| + |y_i-y_j|. | [{"input": "3\n 1 1\n 2 4\n 3 2", "output": "4\n \n\nThe Manhattan distance between the first point and the second point is\n|1-2|+|1-4|=4, which is maximum possible.\n\n* * *"}, {"input": "2\n 1 1\n 1 1", "output": "0"}] |
Print the answer.
* * * | s474894627 | Wrong Answer | p02556 | Input is given from Standard Input in the following format:
N
x_1 y_1
x_2 y_2
:
x_N y_N | n = int(input())
l = []
for num in range(n):
l += [list(map(int,input().split()))]
maxn = -1
maxx = -1
maxy = -1
miny = 2*10**10
minx = 2*10**10
for num in range(n):
if maxx < l[num][0]:
maxx = l[num][0]
if maxy < l[num][1]:
maxy = l[num][1]
if minx > l[num][0]:
minx = l[num][0]
if miny > l[num][1]:
miny = l[num][1]
for num in range(n):
if maxx == l[num][0] or maxy == l[num][1] or minx == l[num][0] or miny == l[num][1]:
for j in range(n):
if (num != j):
if abs(l[num][0]-l[j][0])+abs(l[num][1]-l[j][1]) > maxn:
maxn = abs(l[num][0]-l[j][0])+abs(l[num][1]-l[j][1])
print(maxn) | Statement
There are N points on the 2D plane, i-th of which is located on (x_i, y_i).
There can be multiple points that share the same coordinate. What is the
maximum possible Manhattan distance between two distinct points?
Here, the _Manhattan distance_ between two points (x_i, y_i) and (x_j, y_j) is
defined by |x_i-x_j| + |y_i-y_j|. | [{"input": "3\n 1 1\n 2 4\n 3 2", "output": "4\n \n\nThe Manhattan distance between the first point and the second point is\n|1-2|+|1-4|=4, which is maximum possible.\n\n* * *"}, {"input": "2\n 1 1\n 1 1", "output": "0"}] |
Print the answer.
* * * | s017936568 | Runtime Error | p02556 | Input is given from Standard Input in the following format:
N
x_1 y_1
x_2 y_2
:
x_N y_N | #!python3
import sys
iim = lambda: map(int, sys.stdin.readline().rstrip().split())
def resolve():
it = map(int, sys.stdin.read().split())
N = next(it)
if N == 2:
raise 1
D = 16
x1 = y1 = 10**9 + 1
x2 = y2 = 0
vis = set()
for xy in zip(it, it):
if xy in vis:
continue
vis.add(xy)
x, y = xy
x1 = min(x1, x)
x2 = max(x2, x)
y1 = min(y1, y)
y2 = max(y2, y)
dd = max(1, (x2 - x1) // D, (y2 - y1) // D)
dx = (x2 - x1 + 1) // dd + 1
dy = (y2 - y1 + 1) // dd + 1
d = [[[] for j in range(dx)] for i in range(dy)]
md = [[] for i in range(dx + dy - 1)]
for i in range(dx * dy):
ay1, ax1 = divmod(i, dx)
md[0].append((ax1, ay1, ax1, ay1))
for j in range(i + 1, dx * dy):
ay2, ax2 = divmod(j, dx)
md[abs(ax1 - ax2) + abs(ay1 - ay2)].append((ax1, ay1, ax2, ay2))
for xy in vis:
x, y = xy
ix = (x - x1) // dd
iy = (y - y1) // dd
d[iy][ix].append(xy)
ans = 0
cnt = 1
for md1 in reversed(md):
for x1, y1, x2, y2 in md1:
if len(d[y2][x2]) == 0:
continue
for xx1, yy1 in d[y1][x1]:
for xx2, yy2 in d[y2][x2]:
val = abs(xx1 - xx2) + abs(yy1 - yy2)
ans = max(ans, val)
if ans:
if cnt:
cnt -= 1
else:
break
print(ans)
if __name__ == "__main__":
resolve()
| Statement
There are N points on the 2D plane, i-th of which is located on (x_i, y_i).
There can be multiple points that share the same coordinate. What is the
maximum possible Manhattan distance between two distinct points?
Here, the _Manhattan distance_ between two points (x_i, y_i) and (x_j, y_j) is
defined by |x_i-x_j| + |y_i-y_j|. | [{"input": "3\n 1 1\n 2 4\n 3 2", "output": "4\n \n\nThe Manhattan distance between the first point and the second point is\n|1-2|+|1-4|=4, which is maximum possible.\n\n* * *"}, {"input": "2\n 1 1\n 1 1", "output": "0"}] |
Print the answer.
* * * | s288100837 | Wrong Answer | p02556 | Input is given from Standard Input in the following format:
N
x_1 y_1
x_2 y_2
:
x_N y_N | N = int(input())
numbers = []
for _ in range(N):
x, y = map(int, input().split())
numbers.append([x, y])
saishou = [numbers[0][0], numbers[0][1]]
saidai = [numbers[0][0], numbers[0][1]]
min_dis = numbers[0][0] + numbers[0][1]
max_dis = numbers[0][0] + numbers[0][1]
for num in numbers:
if num[0] ** 2 + num[1] < min_dis:
min_dis = num[0] + num[1]
saishou = [num[0], num[1]]
if num[0] + num[1] > max_dis:
max_dis = num[0] + num[1]
saidai = [num[0], num[1]]
ans1 = saidai[0] - saishou[0] + saidai[1] - saishou[1]
sort_numbers = sorted(numbers)
max_x = sort_numbers[-1][0]
for n in range(N):
numbers[n] = [numbers[n][0] - max_x, numbers[n][1]]
saishou = [numbers[0][0], numbers[0][1]]
saidai = [numbers[0][0], numbers[0][1]]
min_dis = abs(numbers[0][0]) + abs(numbers[0][1])
max_dis = abs(numbers[0][0]) + abs(numbers[0][1])
for num in numbers:
if abs(num[0]) + num[1] < min_dis:
min_dis = abs(num[0]) + num[1]
saishou = [num[0], num[1]]
if abs(num[0]) + num[1] > max_dis:
max_dis = abs(num[0]) + num[1]
saidai = [num[0], num[1]]
ans2 = abs(saidai[0] - saishou[0]) + abs(saidai[1] - saishou[1])
print(max(ans1, ans2))
| Statement
There are N points on the 2D plane, i-th of which is located on (x_i, y_i).
There can be multiple points that share the same coordinate. What is the
maximum possible Manhattan distance between two distinct points?
Here, the _Manhattan distance_ between two points (x_i, y_i) and (x_j, y_j) is
defined by |x_i-x_j| + |y_i-y_j|. | [{"input": "3\n 1 1\n 2 4\n 3 2", "output": "4\n \n\nThe Manhattan distance between the first point and the second point is\n|1-2|+|1-4|=4, which is maximum possible.\n\n* * *"}, {"input": "2\n 1 1\n 1 1", "output": "0"}] |
If we can make X equal to A by repeating the operation, print the minimum
number of operations required. If we cannot, print -1.
* * * | s924523265 | Runtime Error | p03347 | Input is given from Standard Input in the following format:
N
A_1
:
A_N | N = int(input())
start = int(input())
flag = 0
if start != 0:
flag = 1
t = 0
for i in range(N-1):
k = int(input())
if k == start:
t += start
elif k == start + 1:
t += 1
start = k
elif k == 0:
start = 0
elif k > start + 1:
t = -1
break
else:
t += k
start = k
if flag ==1:
t = -1
print(t) | Statement
There is a sequence X of length N, where every element is initially 0. Let X_i
denote the i-th element of X.
You are given a sequence A of length N. The i-th element of A is A_i.
Determine if we can make X equal to A by repeating the operation below. If we
can, find the minimum number of operations required.
* Choose an integer i such that 1\leq i\leq N-1. Replace the value of X_{i+1} with the value of X_i plus 1. | [{"input": "4\n 0\n 1\n 1\n 2", "output": "3\n \n\nWe can make X equal to A as follows:\n\n * Choose i=2. X becomes (0,0,1,0).\n * Choose i=1. X becomes (0,1,1,0).\n * Choose i=3. X becomes (0,1,1,2).\n\n* * *"}, {"input": "3\n 1\n 2\n 1", "output": "-1\n \n\n* * *"}, {"input": "9\n 0\n 1\n 1\n 0\n 1\n 2\n 2\n 1\n 2", "output": "8"}] |
If we can make X equal to A by repeating the operation, print the minimum
number of operations required. If we cannot, print -1.
* * * | s832493992 | Runtime Error | p03347 | Input is given from Standard Input in the following format:
N
A_1
:
A_N | #include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#define fi first
#define se second
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define srep(i,s,t) for (int i = s; i < t; ++i)
#define rng(a) a.begin(),a.end()
#define rrng(a) a.rbegin(),a.rend()
#define maxs(x,y) (x = max(x,y))
#define mins(x,y) (x = min(x,y))
#define limit(x,l,r) max(l,min(x,r))
#define lims(x,l,r) (x = max(l,min(x,r)))
#define isin(x,l,r) ((l) <= (x) && (x) < (r))
#define pb push_back
#define eb emplace_back
#define sz(x) (int)(x).size()
#define pcnt __builtin_popcountll
#define uni(x) x.erase(unique(rng(x)),x.end())
#define show(x) cout<<#x<<" = "<<x<<endl;
#define PQ(T) priority_queue<T,v(T),greater<T> >
#define bn(x) ((1<<x)-1)
#define dup(x,y) (((x)+(y)-1)/(y))
#define newline puts("")
#define v(T) vector<T>
#define vv(T) v(v(T))
using namespace std;
typedef long long int ll;
typedef unsigned uint;
typedef unsigned long long ull;
typedef pair<int,int> P;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<P> vp;
int main() {
int n;
cin >> n;
vl a(n);
rep(i,n)cin >> a[i];
if(a[0] != 0){
cout<<-1<<endl;
return 0;
}
ll ans = 0;
srep(i,1,n){
if(a[i-1]==0 || a[i]<=1){
//show("s1");
ans+=a[i];
}
else if(a[i] <=a[i-1]){
//show("s2");
ans+=1;
}else{
//show("s3");
ans+=max(1LL,a[i]-a[i-1]);
}
// a[i]=max(1LL,a[i]-a[i-1]);
// if(a[i-1] != 0 && a[i]>=a[i-1])ans-=1;
}
cout<<ans<<endl;
return 0;
}
| Statement
There is a sequence X of length N, where every element is initially 0. Let X_i
denote the i-th element of X.
You are given a sequence A of length N. The i-th element of A is A_i.
Determine if we can make X equal to A by repeating the operation below. If we
can, find the minimum number of operations required.
* Choose an integer i such that 1\leq i\leq N-1. Replace the value of X_{i+1} with the value of X_i plus 1. | [{"input": "4\n 0\n 1\n 1\n 2", "output": "3\n \n\nWe can make X equal to A as follows:\n\n * Choose i=2. X becomes (0,0,1,0).\n * Choose i=1. X becomes (0,1,1,0).\n * Choose i=3. X becomes (0,1,1,2).\n\n* * *"}, {"input": "3\n 1\n 2\n 1", "output": "-1\n \n\n* * *"}, {"input": "9\n 0\n 1\n 1\n 0\n 1\n 2\n 2\n 1\n 2", "output": "8"}] |
If we can make X equal to A by repeating the operation, print the minimum
number of operations required. If we cannot, print -1.
* * * | s781879423 | Accepted | p03347 | Input is given from Standard Input in the following format:
N
A_1
:
A_N | # -*- coding: utf-8 -*-
#############
# Libraries #
#############
import sys
input = sys.stdin.readline
import math
# from math import gcd
import bisect
import heapq
from collections import defaultdict
from collections import deque
from collections import Counter
from functools import lru_cache
#############
# Constants #
#############
MOD = 10**9 + 7
INF = float("inf")
AZ = "abcdefghijklmnopqrstuvwxyz"
#############
# Functions #
#############
######INPUT######
def I():
return int(input().strip())
def S():
return input().strip()
def IL():
return list(map(int, input().split()))
def SL():
return list(map(str, input().split()))
def ILs(n):
return list(int(input()) for _ in range(n))
def SLs(n):
return list(input().strip() for _ in range(n))
def ILL(n):
return [list(map(int, input().split())) for _ in range(n)]
def SLL(n):
return [list(map(str, input().split())) for _ in range(n)]
######OUTPUT######
def P(arg):
print(arg)
return
def Y():
print("Yes")
return
def N():
print("No")
return
def E():
exit()
def PE(arg):
print(arg)
exit()
def YE():
print("Yes")
exit()
def NE():
print("No")
exit()
#####Shorten#####
def DD(arg):
return defaultdict(arg)
#####Inverse#####
def inv(n):
return pow(n, MOD - 2, MOD)
######Combination######
kaijo_memo = []
def kaijo(n):
if len(kaijo_memo) > n:
return kaijo_memo[n]
if len(kaijo_memo) == 0:
kaijo_memo.append(1)
while len(kaijo_memo) <= n:
kaijo_memo.append(kaijo_memo[-1] * len(kaijo_memo) % MOD)
return kaijo_memo[n]
gyaku_kaijo_memo = []
def gyaku_kaijo(n):
if len(gyaku_kaijo_memo) > n:
return gyaku_kaijo_memo[n]
if len(gyaku_kaijo_memo) == 0:
gyaku_kaijo_memo.append(1)
while len(gyaku_kaijo_memo) <= n:
gyaku_kaijo_memo.append(
gyaku_kaijo_memo[-1] * pow(len(gyaku_kaijo_memo), MOD - 2, MOD) % MOD
)
return gyaku_kaijo_memo[n]
def nCr(n, r):
if n == r:
return 1
if n < r or r < 0:
return 0
ret = 1
ret = ret * kaijo(n) % MOD
ret = ret * gyaku_kaijo(r) % MOD
ret = ret * gyaku_kaijo(n - r) % MOD
return ret
######Factorization######
def factorization(n):
arr = []
temp = n
for i in range(2, int(-(-(n**0.5) // 1)) + 1):
if temp % i == 0:
cnt = 0
while temp % i == 0:
cnt += 1
temp //= i
arr.append([i, cnt])
if temp != 1:
arr.append([temp, 1])
if arr == []:
arr.append([n, 1])
return arr
#####MakeDivisors######
def make_divisors(n):
divisors = []
for i in range(1, int(n**0.5) + 1):
if n % i == 0:
divisors.append(i)
if i != n // i:
divisors.append(n // i)
return divisors
#####MakePrimes######
def make_primes(N):
max = int(math.sqrt(N))
seachList = [i for i in range(2, N + 1)]
primeNum = []
while seachList[0] <= max:
primeNum.append(seachList[0])
tmp = seachList[0]
seachList = [i for i in seachList if i % tmp != 0]
primeNum.extend(seachList)
return primeNum
#####GCD#####
def gcd(a, b):
while b:
a, b = b, a % b
return a
#####LCM#####
def lcm(a, b):
return a * b // gcd(a, b)
#####BitCount#####
def count_bit(n):
count = 0
while n:
n &= n - 1
count += 1
return count
#####ChangeBase#####
def base_10_to_n(X, n):
if X // n:
return base_10_to_n(X // n, n) + [X % n]
return [X % n]
def base_n_to_10(X, n):
return sum(int(str(X)[-i - 1]) * n**i for i in range(len(str(X))))
def base_10_to_n_without_0(X, n):
X -= 1
if X // n:
return base_10_to_n_without_0(X // n, n) + [X % n]
return [X % n]
#####IntLog#####
def int_log(n, a):
count = 0
while n >= a:
n //= a
count += 1
return count
#############
# Main Code #
#############
N = I()
A = ILs(N)
ans = 0
req = 0
for i in range(N)[::-1]:
if A[i] > i or A[i] < req:
print(-1)
exit()
if A[i] > req:
req = A[i]
ans += req
req = max(0, req - 1)
print(ans)
| Statement
There is a sequence X of length N, where every element is initially 0. Let X_i
denote the i-th element of X.
You are given a sequence A of length N. The i-th element of A is A_i.
Determine if we can make X equal to A by repeating the operation below. If we
can, find the minimum number of operations required.
* Choose an integer i such that 1\leq i\leq N-1. Replace the value of X_{i+1} with the value of X_i plus 1. | [{"input": "4\n 0\n 1\n 1\n 2", "output": "3\n \n\nWe can make X equal to A as follows:\n\n * Choose i=2. X becomes (0,0,1,0).\n * Choose i=1. X becomes (0,1,1,0).\n * Choose i=3. X becomes (0,1,1,2).\n\n* * *"}, {"input": "3\n 1\n 2\n 1", "output": "-1\n \n\n* * *"}, {"input": "9\n 0\n 1\n 1\n 0\n 1\n 2\n 2\n 1\n 2", "output": "8"}] |
If we can make X equal to A by repeating the operation, print the minimum
number of operations required. If we cannot, print -1.
* * * | s974390920 | Wrong Answer | p03347 | Input is given from Standard Input in the following format:
N
A_1
:
A_N | c = g = p = e = 0
for i in range(int(input())):
if not e:
if (a := int(input())) > i:
e = 1
else:
if i != 0:
(g, c, p) = (g + 1, c + 1, a) if a == p + 1 else (g + a, 0, a)
print(-1 if e else g)
| Statement
There is a sequence X of length N, where every element is initially 0. Let X_i
denote the i-th element of X.
You are given a sequence A of length N. The i-th element of A is A_i.
Determine if we can make X equal to A by repeating the operation below. If we
can, find the minimum number of operations required.
* Choose an integer i such that 1\leq i\leq N-1. Replace the value of X_{i+1} with the value of X_i plus 1. | [{"input": "4\n 0\n 1\n 1\n 2", "output": "3\n \n\nWe can make X equal to A as follows:\n\n * Choose i=2. X becomes (0,0,1,0).\n * Choose i=1. X becomes (0,1,1,0).\n * Choose i=3. X becomes (0,1,1,2).\n\n* * *"}, {"input": "3\n 1\n 2\n 1", "output": "-1\n \n\n* * *"}, {"input": "9\n 0\n 1\n 1\n 0\n 1\n 2\n 2\n 1\n 2", "output": "8"}] |
Print the minimum radius of a circle such that all the N points are inside or
on it.
Your output will be considered correct if the absolute or relative error from
our answer is at most 10^{-6}.
* * * | s565846164 | Wrong Answer | p02805 | Input is given from Standard Input in the following format:
N
x_1 y_1
:
x_N y_N | import sys
import numpy as np
sr = lambda: sys.stdin.readline().rstrip()
ir = lambda: int(sr())
lr = lambda: list(map(int, sr().split()))
N = ir()
XY = np.array([lr() for _ in range(N)])
X = XY[:, 0]
Y = XY[:, 1]
# 円の中心
cen_X = (X.max() + X.min()) / 2
cen_Y = (Y.max() + Y.min()) / 2
# 2分探索
def check(R):
bool = True
for x, y in XY:
if (cen_X - x) ** 2 + (cen_Y - y) ** 2 > R**2:
bool = False
return bool
left = 0 # NG
right = 1000 # OK
while right > left + 0.0000000001:
mid = (left + right) / 2
if check(mid):
right = mid
else:
left = mid
print(right)
# 18
| Statement
Given are N points (x_i, y_i) in a two-dimensional plane.
Find the minimum radius of a circle such that all the points are inside or on
it. | [{"input": "2\n 0 0\n 1 0", "output": "0.500000000000000000\n \n\nBoth points are contained in the circle centered at (0.5,0) with a radius of\n0.5.\n\n* * *"}, {"input": "3\n 0 0\n 0 1\n 1 0", "output": "0.707106781186497524\n \n\n* * *"}, {"input": "10\n 10 9\n 5 9\n 2 0\n 0 0\n 2 7\n 3 3\n 2 5\n 10 0\n 3 7\n 1 9", "output": "6.726812023536805158\n \n\nIf the absolute or relative error from our answer is at most 10^{-6}, the\noutput will be considered correct."}] |
Print the minimum radius of a circle such that all the N points are inside or
on it.
Your output will be considered correct if the absolute or relative error from
our answer is at most 10^{-6}.
* * * | s581512240 | Wrong Answer | p02805 | Input is given from Standard Input in the following format:
N
x_1 y_1
:
x_N y_N | import sys
input = sys.stdin.readline
def dist(x1, x2, y1, y2):
return (y1 - y2) * (y1 - y2) + (x1 - x2) * (x1 - x2)
def farthest(x, y):
ret = 0
point = (-1, -1)
for u, v in X:
d = dist(x, u, y, v)
if d > ret:
ret = d
point = u, v
return ret, point
N = int(input())
X = []
for _ in [0] * N:
x, y = map(int, input().split())
X.append((x, y))
x = (max(x for x, y in X) - min(x for x, y in X)) / 2
y = (max(y for x, y in X) - min(y for x, y in X)) / 2
step = 0.5
o = 1
eps = 10**-15
while o > eps:
_, (u, v) = farthest(x, y)
x += (u - x) * step
y += (v - y) * step
step *= 0.99
o = abs(u - x + x - y) * step
ans, _ = farthest(x, y)
ans **= 0.5
print(ans)
| Statement
Given are N points (x_i, y_i) in a two-dimensional plane.
Find the minimum radius of a circle such that all the points are inside or on
it. | [{"input": "2\n 0 0\n 1 0", "output": "0.500000000000000000\n \n\nBoth points are contained in the circle centered at (0.5,0) with a radius of\n0.5.\n\n* * *"}, {"input": "3\n 0 0\n 0 1\n 1 0", "output": "0.707106781186497524\n \n\n* * *"}, {"input": "10\n 10 9\n 5 9\n 2 0\n 0 0\n 2 7\n 3 3\n 2 5\n 10 0\n 3 7\n 1 9", "output": "6.726812023536805158\n \n\nIf the absolute or relative error from our answer is at most 10^{-6}, the\noutput will be considered correct."}] |
Print the minimum radius of a circle such that all the N points are inside or
on it.
Your output will be considered correct if the absolute or relative error from
our answer is at most 10^{-6}.
* * * | s478944814 | Runtime Error | p02805 | Input is given from Standard Input in the following format:
N
x_1 y_1
:
x_N y_N | import math
cx = 0
cy = 0
r = 0
x1 = 0
y1 = 0
x2 = 0
y2 = 0
x3 = 0
y3 = 0
c = 0
for i in range(int(input())):
x, y = map(int, input().split())
l = math.sqrt((x - cx) ** 2 + (y - cy) ** 2)
print(x, y, l)
if c == 0:
x1 = x
y1 = x
cx = x
cy = y
c += 1
if l > r:
if c == 1:
x2 = x
y2 = y
cx = (x1 + x2) / 2
cy = (y1 + y2) / 2
r = math.sqrt((cx - x1) ** 2 + (cy - y1) ** 2)
c += 1
elif c == 2:
x3 = x
y3 = y
d = 2 * ((y1 - y3) * (x1 - x2) - (y1 - y2) * (x1 - x3))
cx = (
(y1 - y3) * (y1**2 - y2**2 + x1**2 - x2**2)
- (y1 - y2) * (y1**2 - y3**2 + x1**2 - x3**2)
) / d
cy = (
(x1 - x3) * (x1**2 - x2**2 + y1**2 - y2**2)
- (x1 - x2) * (x1**2 - x3**2 + y1**2 - y3**2)
) / -d
r = math.sqrt((cx - x1) ** 2 + (cy - y1) ** 2)
print(r)
c += 1
elif c == 3:
l1 = math.sqrt((x - x1) ** 2 + (y - y1) ** 2)
l2 = math.sqrt((x - x2) ** 2 + (y - y2) ** 2)
l3 = math.sqrt((x - x3) ** 2 + (y - y3) ** 2)
if min([l1, l2, l3]) == l1:
x1 = x
y1 = y
if min([l1, l2, l3]) == l2:
x2 = x
y2 = y
if min([l1, l2, l3]) == l3:
x3 = x
y3 = y
d = 2 * ((y1 - y3) * (x1 - x2) - (y1 - y2) * (x1 - x3))
cx = (
(y1 - y3) * (y1**2 - y2**2 + x1**2 - x2**2)
- (y1 - y2) * (y1**2 - y3**2 + x1**2 - x3**2)
) / d
cy = (
(x1 - x3) * (x1**2 - x2**2 + y1**2 - y2**2)
- (x1 - x2) * (x1**2 - x3**2 + y1**2 - y3**2)
) / -d
r = math.sqrt((cx - x1) ** 2 + (cy - y1) ** 2)
print(r)
| Statement
Given are N points (x_i, y_i) in a two-dimensional plane.
Find the minimum radius of a circle such that all the points are inside or on
it. | [{"input": "2\n 0 0\n 1 0", "output": "0.500000000000000000\n \n\nBoth points are contained in the circle centered at (0.5,0) with a radius of\n0.5.\n\n* * *"}, {"input": "3\n 0 0\n 0 1\n 1 0", "output": "0.707106781186497524\n \n\n* * *"}, {"input": "10\n 10 9\n 5 9\n 2 0\n 0 0\n 2 7\n 3 3\n 2 5\n 10 0\n 3 7\n 1 9", "output": "6.726812023536805158\n \n\nIf the absolute or relative error from our answer is at most 10^{-6}, the\noutput will be considered correct."}] |
Print the minimum radius of a circle such that all the N points are inside or
on it.
Your output will be considered correct if the absolute or relative error from
our answer is at most 10^{-6}.
* * * | s866547241 | Wrong Answer | p02805 | Input is given from Standard Input in the following format:
N
x_1 y_1
:
x_N y_N | m = map(int, open(0).read().split()[1:])
(*z,) = zip(m, m)
M = 0
for x, y in z:
for i, j in z:
M = max(M, (x - i) ** 2 + (y - j) ** 2)
print(M**0.5 / 2)
| Statement
Given are N points (x_i, y_i) in a two-dimensional plane.
Find the minimum radius of a circle such that all the points are inside or on
it. | [{"input": "2\n 0 0\n 1 0", "output": "0.500000000000000000\n \n\nBoth points are contained in the circle centered at (0.5,0) with a radius of\n0.5.\n\n* * *"}, {"input": "3\n 0 0\n 0 1\n 1 0", "output": "0.707106781186497524\n \n\n* * *"}, {"input": "10\n 10 9\n 5 9\n 2 0\n 0 0\n 2 7\n 3 3\n 2 5\n 10 0\n 3 7\n 1 9", "output": "6.726812023536805158\n \n\nIf the absolute or relative error from our answer is at most 10^{-6}, the\noutput will be considered correct."}] |
Print the minimum radius of a circle such that all the N points are inside or
on it.
Your output will be considered correct if the absolute or relative error from
our answer is at most 10^{-6}.
* * * | s081790525 | Runtime Error | p02805 | Input is given from Standard Input in the following format:
N
x_1 y_1
:
x_N y_N | import sys
from math import hypot
readline = sys.stdin.readline
N = int(readline())
Points = [tuple(map(int, readline().split())) for _ in range(N)]
inf = 10**9 + 7
EPS = 1e-8
ans = inf
for i in range(N):
for j in range(i):
a = Points[i][0]
b = Points[i][1]
c = Points[j][0]
d = Points[j][1]
px, py = (a + c) / 2, (b + d) / 2
R = hypot(a - px, b - py)
if all(hypot(px - xi, py - yi) <= R + EPS for xi, yi in Points):
ans = min(ans, R)
for i in range(N):
for j in range(i):
for k in range(j):
a = Points[i][0]
b = Points[i][1]
c = Points[j][0]
d = Points[j][1]
e = Points[k][0]
f = Points[k][1]
ea = hypot(c - e, d - f)
eb = hypot(a - e, b - f)
ec = hypot(a - c, b - d)
cA = (ec**2 + eb**2 - ea**2) / (2 * ec * eb)
cB = (ec**2 - eb**2 + ea**2) / (2 * ec * ea)
cC = (-(ec**2) + eb**2 + ea**2) / (2 * ea * eb)
sA = (1 - cA**2) ** 0.5
sB = (1 - cB**2) ** 0.5
sC = (1 - cC**2) ** 0.5
s2A = 2 * sA * cA
s2B = 2 * sB * cB
s2C = 2 * sC * cC
if max(s2A, s2B, s2C) < EPS:
continue
else:
px = (a * s2A + c * s2B + e * s2C) / (s2A + s2B + s2C)
py = (b * s2A + d * s2B + f * s2C) / (s2A + s2B + s2C)
R = hypot(px - a, py - b)
if all(hypot(px - xi, py - yi) <= R + EPS for xi, yi in Points):
ans = min(ans, R)
print(ans)
| Statement
Given are N points (x_i, y_i) in a two-dimensional plane.
Find the minimum radius of a circle such that all the points are inside or on
it. | [{"input": "2\n 0 0\n 1 0", "output": "0.500000000000000000\n \n\nBoth points are contained in the circle centered at (0.5,0) with a radius of\n0.5.\n\n* * *"}, {"input": "3\n 0 0\n 0 1\n 1 0", "output": "0.707106781186497524\n \n\n* * *"}, {"input": "10\n 10 9\n 5 9\n 2 0\n 0 0\n 2 7\n 3 3\n 2 5\n 10 0\n 3 7\n 1 9", "output": "6.726812023536805158\n \n\nIf the absolute or relative error from our answer is at most 10^{-6}, the\noutput will be considered correct."}] |
Print the minimum radius of a circle such that all the N points are inside or
on it.
Your output will be considered correct if the absolute or relative error from
our answer is at most 10^{-6}.
* * * | s858861587 | Accepted | p02805 | Input is given from Standard Input in the following format:
N
x_1 y_1
:
x_N y_N | def want(x, y):
ret = 0
for i in xy:
ret = max(ret, ((i[0] - x) ** 2 + (i[1] - y) ** 2) ** 0.5)
return ret
def want2(x):
ly = miny
ry = maxy
while ry - ly > 10 ** (-7) and ry - ly > (ry / (10**6)):
m1 = (ly * 2 + ry) / 3
m2 = (ly + ry * 2) / 3
rm1 = want(x, m1)
rm2 = want(x, m2)
if rm1 > rm2:
ly = m1
else:
ry = m2
ansy = (ly + ry) / 2
return want(x, ansy)
N = int(input())
xy = []
minx = float("inf")
maxx = float("-inf")
miny = float("inf")
maxy = float("-inf")
for i in range(N):
x, y = map(int, input().split())
xy.append([x, y])
minx = min(minx, x)
miny = min(miny, y)
maxx = max(maxx, x)
maxy = max(maxy, y)
lx = minx
rx = maxx
while rx - lx > 10 ** (-7) and rx - lx > (rx / (10**6)):
m1 = (lx * 2 + rx) / 3
m2 = (lx + rx * 2) / 3
rm1 = want2(m1)
rm2 = want2(m2)
if rm1 > rm2:
lx = m1
else:
rx = m2
print((rm1 + rm2) / 2)
| Statement
Given are N points (x_i, y_i) in a two-dimensional plane.
Find the minimum radius of a circle such that all the points are inside or on
it. | [{"input": "2\n 0 0\n 1 0", "output": "0.500000000000000000\n \n\nBoth points are contained in the circle centered at (0.5,0) with a radius of\n0.5.\n\n* * *"}, {"input": "3\n 0 0\n 0 1\n 1 0", "output": "0.707106781186497524\n \n\n* * *"}, {"input": "10\n 10 9\n 5 9\n 2 0\n 0 0\n 2 7\n 3 3\n 2 5\n 10 0\n 3 7\n 1 9", "output": "6.726812023536805158\n \n\nIf the absolute or relative error from our answer is at most 10^{-6}, the\noutput will be considered correct."}] |
Print the minimum radius of a circle such that all the N points are inside or
on it.
Your output will be considered correct if the absolute or relative error from
our answer is at most 10^{-6}.
* * * | s557116982 | Accepted | p02805 | Input is given from Standard Input in the following format:
N
x_1 y_1
:
x_N y_N | # coding: utf-8
# Your code here!
import sys
sys.setrecursionlimit(10**6)
readline = sys.stdin.readline
read = sys.stdin.read
# h,w = [int(i) for i in readline().split()]
# n,*d = [int(i) for i in read().split()]
n = int(input())
xy = [[int(i) for i in readline().split()] for _ in range(n)]
def get_max_dist_and_index(a, b):
d = [(a - x) ** 2 + (b - y) ** 2 for x, y in xy]
m = 0
idx = 0
for i, di in enumerate(d):
if m < di:
idx = i
m = di
return m, idx
x0 = y0 = 0
r = 100.0
ratio = 0.99
ans = 10000000
for _ in range(100000):
m, i = get_max_dist_and_index(x0, y0)
# print(m,i,x0,y0,r)
m **= 0.5
ans = min(ans, m)
dx, dy = (xy[i][0] - x0), (xy[i][1] - y0)
x0 += r * dx / m
y0 += r * dy / m
r *= ratio
print(ans)
| Statement
Given are N points (x_i, y_i) in a two-dimensional plane.
Find the minimum radius of a circle such that all the points are inside or on
it. | [{"input": "2\n 0 0\n 1 0", "output": "0.500000000000000000\n \n\nBoth points are contained in the circle centered at (0.5,0) with a radius of\n0.5.\n\n* * *"}, {"input": "3\n 0 0\n 0 1\n 1 0", "output": "0.707106781186497524\n \n\n* * *"}, {"input": "10\n 10 9\n 5 9\n 2 0\n 0 0\n 2 7\n 3 3\n 2 5\n 10 0\n 3 7\n 1 9", "output": "6.726812023536805158\n \n\nIf the absolute or relative error from our answer is at most 10^{-6}, the\noutput will be considered correct."}] |
Print the minimum radius of a circle such that all the N points are inside or
on it.
Your output will be considered correct if the absolute or relative error from
our answer is at most 10^{-6}.
* * * | s964521141 | Accepted | p02805 | Input is given from Standard Input in the following format:
N
x_1 y_1
:
x_N y_N | def dist(a, b):
return ((a[0] - b[0]) ** 2 + (a[1] - b[1]) ** 2) ** 0.5
n = int(input())
data = []
for i in range(n):
x, y = map(float, input().split())
data.append((x, y))
now = (500.0, 500.0)
move = 1
for i in range(200000):
max_dist = 0
max_dist_point = -1
for j in range(len(data)):
d = dist(now, data[j])
if d > max_dist:
max_dist = d
max_dist_point = j
target = data[max_dist_point]
now = (now[0] + (target[0] - now[0]) * move, now[1] + (target[1] - now[1]) * move)
move *= 0.999
max_dist = 0
for j in range(len(data)):
d = dist(now, data[j])
if d > max_dist:
max_dist = d
print(max_dist)
| Statement
Given are N points (x_i, y_i) in a two-dimensional plane.
Find the minimum radius of a circle such that all the points are inside or on
it. | [{"input": "2\n 0 0\n 1 0", "output": "0.500000000000000000\n \n\nBoth points are contained in the circle centered at (0.5,0) with a radius of\n0.5.\n\n* * *"}, {"input": "3\n 0 0\n 0 1\n 1 0", "output": "0.707106781186497524\n \n\n* * *"}, {"input": "10\n 10 9\n 5 9\n 2 0\n 0 0\n 2 7\n 3 3\n 2 5\n 10 0\n 3 7\n 1 9", "output": "6.726812023536805158\n \n\nIf the absolute or relative error from our answer is at most 10^{-6}, the\noutput will be considered correct."}] |
Print the minimum radius of a circle such that all the N points are inside or
on it.
Your output will be considered correct if the absolute or relative error from
our answer is at most 10^{-6}.
* * * | s453332424 | Accepted | p02805 | Input is given from Standard Input in the following format:
N
x_1 y_1
:
x_N y_N | class Triangle:
def __init__(self, A, B, C):
# 3点の座標
self.A = A
self.B = B
self.C = C
Ax, Ay = A
Bx, By = B
Cx, Cy = C
a = ((Bx - Cx) ** 2 + (By - Cy) ** 2) ** 0.5
b = ((Cx - Ax) ** 2 + (Cy - Ay) ** 2) ** 0.5
c = ((Ax - Bx) ** 2 + (Ay - By) ** 2) ** 0.5
# 3辺の長さ
self.a = a
self.b = b
self.c = c
# 外心の座標
s = a**2 * (b**2 + c**2 - a**2)
t = b**2 * (c**2 + a**2 - b**2)
u = c**2 * (a**2 + b**2 - c**2)
Ux = (s * Ax + t * Bx + u * Cx) / (s + t + u)
Uy = (s * Ay + t * By + u * Cy) / (s + t + u)
self.U = (Ux, Uy)
# 重心の座標
self.G = ((Ax + Bx + Cx) / 3, (Ay + By + Cy) / 3)
class Circle:
# 中心p、半径rの円
def __init__(self, p, r):
self.p = p
self.r = r
def contain(self, q):
# 点qを含むか判定
px, py = self.p
qx, qy = q
return (px - qx) ** 2 + (py - qy) ** 2 <= self.r**2 + 10 ** (-7)
def distance(a, b):
ax, ay = a
bx, by = b
return ((ax - bx) ** 2 + (ay - by) ** 2) ** 0.5
def enclose(P):
n = len(P)
if n == 2:
ax, ay = P[0]
bx, by = P[1]
p = ((ax + bx) / 2, (ay + by) / 2)
r = distance(P[0], p)
return Circle(p, r)
if n == 3:
circle = enclose([P[0], P[1]])
if circle.contain(P[2]):
return circle
circle = enclose([P[1], P[2]])
if circle.contain(P[0]):
return circle
circle = enclose([P[2], P[0]])
if circle.contain(P[1]):
return circle
triangle = Triangle(P[0], P[1], P[2])
u = triangle.U
r = distance(u, P[0])
return Circle(u, r)
for i in range(n - 2):
for j in range(i + 1, n - 1):
for k in range(j + 1, n):
circle = enclose([P[i], P[j], P[k]])
if all([circle.contain(q) for q in P]):
return circle
n = int(input())
P = []
for i in range(n):
x, y = map(int, input().split())
P.append((x, y))
circle = enclose(P)
print(circle.r)
| Statement
Given are N points (x_i, y_i) in a two-dimensional plane.
Find the minimum radius of a circle such that all the points are inside or on
it. | [{"input": "2\n 0 0\n 1 0", "output": "0.500000000000000000\n \n\nBoth points are contained in the circle centered at (0.5,0) with a radius of\n0.5.\n\n* * *"}, {"input": "3\n 0 0\n 0 1\n 1 0", "output": "0.707106781186497524\n \n\n* * *"}, {"input": "10\n 10 9\n 5 9\n 2 0\n 0 0\n 2 7\n 3 3\n 2 5\n 10 0\n 3 7\n 1 9", "output": "6.726812023536805158\n \n\nIf the absolute or relative error from our answer is at most 10^{-6}, the\noutput will be considered correct."}] |
Print the minimum radius of a circle such that all the N points are inside or
on it.
Your output will be considered correct if the absolute or relative error from
our answer is at most 10^{-6}.
* * * | s325596453 | Accepted | p02805 | Input is given from Standard Input in the following format:
N
x_1 y_1
:
x_N y_N | N = int(input())
XY = [complex(*map(int, input().split())) for _ in range(N)]
ans = 10**18
def calc(center):
return max(abs(center - x) for x in XY)
for A in XY:
for B in XY:
center = (A + B) / 2
ans = min(ans, calc(center))
for C in XY:
a, b, c = abs(B - C), abs(C - A), abs(A - B)
S = 0
T = complex(0, 0)
for (x, y, z), u in zip([(a, b, c), (b, c, a), (c, b, a)], (A, B, C)):
O = x**2 * (y**2 + z**2 - x**2)
S += O
T += O * u
if S == 0:
continue
ans = min(ans, calc(T / S))
print(ans)
| Statement
Given are N points (x_i, y_i) in a two-dimensional plane.
Find the minimum radius of a circle such that all the points are inside or on
it. | [{"input": "2\n 0 0\n 1 0", "output": "0.500000000000000000\n \n\nBoth points are contained in the circle centered at (0.5,0) with a radius of\n0.5.\n\n* * *"}, {"input": "3\n 0 0\n 0 1\n 1 0", "output": "0.707106781186497524\n \n\n* * *"}, {"input": "10\n 10 9\n 5 9\n 2 0\n 0 0\n 2 7\n 3 3\n 2 5\n 10 0\n 3 7\n 1 9", "output": "6.726812023536805158\n \n\nIf the absolute or relative error from our answer is at most 10^{-6}, the\noutput will be considered correct."}] |
Print the minimum radius of a circle such that all the N points are inside or
on it.
Your output will be considered correct if the absolute or relative error from
our answer is at most 10^{-6}.
* * * | s459516558 | Wrong Answer | p02805 | Input is given from Standard Input in the following format:
N
x_1 y_1
:
x_N y_N | N = int(input())
XY = [list(map(int, input().split())) for i in range(N)]
from itertools import combinations
a = 9999
def f(X, Y, R2, a):
if not any([(X - x) ** 2 + (Y - y) ** 2 > R2 for x, y in XY]):
a = min(a, R2**0.5)
return a
for (x1, y1), (x2, y2), (x3, y3) in combinations(XY, 3):
e1 = (x2 - x3) ** 2 + (y2 - y3) ** 2
e2 = (x3 - x1) ** 2 + (y3 - y1) ** 2
e3 = (x1 - x2) ** 2 + (y1 - y2) ** 2
p = e1 * (e2 + e3 - e1)
q = e2 * (e3 + e1 - e2)
r = e3 * (e1 + e2 - e3)
if p + q + r == 0:
continue
X = (p * x1 + q * x2 * r * x3) / (p + q + r)
Y = (p * y1 + q * y2 + r * y3) / (p + q + r)
R2 = (X - x1) ** 2 + (Y - y1) ** 2 + 10e-15
a = f(X, Y, R2, a)
for (x1, y1), (x2, y2) in combinations(XY, 2):
X = (x1 + x2) / 2
Y = (y1 + y2) / 2
R2 = (X - x1) ** 2 + (Y - y1) ** 2 + 10e-15
a = f(X, Y, R2, a)
print(a)
| Statement
Given are N points (x_i, y_i) in a two-dimensional plane.
Find the minimum radius of a circle such that all the points are inside or on
it. | [{"input": "2\n 0 0\n 1 0", "output": "0.500000000000000000\n \n\nBoth points are contained in the circle centered at (0.5,0) with a radius of\n0.5.\n\n* * *"}, {"input": "3\n 0 0\n 0 1\n 1 0", "output": "0.707106781186497524\n \n\n* * *"}, {"input": "10\n 10 9\n 5 9\n 2 0\n 0 0\n 2 7\n 3 3\n 2 5\n 10 0\n 3 7\n 1 9", "output": "6.726812023536805158\n \n\nIf the absolute or relative error from our answer is at most 10^{-6}, the\noutput will be considered correct."}] |
Print the number of ways to paint the squares to satisfy all the conditions,
modulo 10^9+7.
* * * | s469337312 | Accepted | p03717 | Input is given from Standard Input in the following format:
N M
l_1 r_1 x_1
l_2 r_2 x_2
:
l_M r_M x_M | MOD = 10**9 + 7
N, M = map(int, input().split())
S = [[N + 1] * (N + 1) for i in [0, 1, 2]]
T = [[0] * (N + 1) for i in [0, 1, 2]]
C = [0] * (N + 1)
for i in range(M):
l, r, x = map(int, input().split())
if r - l < x - 1:
print(0)
exit(0)
S[x - 1][r] = min(S[x - 1][r], l)
T[x - 1][r] = max(T[x - 1][r], l)
C[r] = 1
S0, S1, S2 = S
T0, T1, T2 = T
ok = 1
for i in range(N + 1):
if not T2[i] < S1[i] or not T1[i] < S0[i]:
ok = 0
break
if not ok:
print(0)
exit(0)
RM = [N + 1] * (N + 1)
GM = [N + 1] * (N + 1)
for i in range(N - 1, -1, -1):
RM[i] = min(RM[i + 1], S1[i + 1])
GM[i] = min(GM[i + 1], S0[i + 1])
X = {(0, 0): 3}
D = [0] * (N + 1)
D[0] = 6
B = [{} for i in range(N + 1)]
B[0][0] = 3
bb = 0
for b in range(1, N):
t2 = T2[b + 1]
s1 = S1[b + 1]
t1 = T1[b + 1]
s0 = S0[b + 1]
rm = RM[b]
gm = GM[b]
if t1 <= b < gm:
F = B[b]
for z in range(t2, min(rm, b)):
v = D[z] % MOD
if v:
F[z] = v
D[z] += v
D[b] += v
if C[b + 1]:
for g in range(bb, min(t1, b)):
for r, v in B[g].items():
D[r] -= v
D[g] -= v
B[g] = None
bb = max(t1, bb)
for g in range(bb, b):
for r, v in B[g].items():
if not t2 <= r < s1:
D[r] -= v
D[g] -= v
B[g] = {r: v for r, v in B[g].items() if t2 <= r < s1}
ans = 0
for b in range(bb, N + 1):
if B[b]:
ans += sum(B[b].values())
print(ans % MOD)
| Statement
There are N squares arranged in a row. The squares are numbered 1, 2, ..., N,
from left to right.
Snuke is painting each square in red, green or blue. According to his
aesthetic sense, the following M conditions must all be satisfied. The i-th
condition is:
* There are exactly x_i different colors among squares l_i, l_i + 1, ..., r_i.
In how many ways can the squares be painted to satisfy all the conditions?
Find the count modulo 10^9+7. | [{"input": "3 1\n 1 3 3", "output": "6\n \n\nThe six ways are:\n\n * RGB\n * RBG\n * GRB\n * GBR\n * BRG\n * BGR\n\nwhere R, G and B correspond to red, green and blue squares, respectively.\n\n* * *"}, {"input": "4 2\n 1 3 1\n 2 4 2", "output": "6\n \n\nThe six ways are:\n\n * RRRG\n * RRRB\n * GGGR\n * GGGB\n * BBBR\n * BBBG\n\n* * *"}, {"input": "1 3\n 1 1 1\n 1 1 2\n 1 1 3", "output": "0\n \n\nThere are zero ways.\n\n* * *"}, {"input": "8 10\n 2 6 2\n 5 5 1\n 3 5 2\n 4 7 3\n 4 4 1\n 2 3 1\n 7 7 1\n 1 5 2\n 1 7 3\n 3 4 2", "output": "108"}] |
Print the number of ways to paint the squares to satisfy all the conditions,
modulo 10^9+7.
* * * | s150938220 | Wrong Answer | p03717 | Input is given from Standard Input in the following format:
N M
l_1 r_1 x_1
l_2 r_2 x_2
:
l_M r_M x_M | import sys
from collections import defaultdict
sys.setrecursionlimit(10**6)
int1 = lambda x: int(x) - 1
p2D = lambda x: print(*x, sep="\n")
def MI():
return map(int, sys.stdin.readline().split())
def LI():
return list(map(int, sys.stdin.readline().split()))
def LLI(rows_number):
return [LI() for _ in range(rows_number)]
# 一番後ろの色を(赤に)固定した上で、もらうDPに書き換え
def main():
md = 10**9 + 7
n, m = MI()
rtol = defaultdict(list)
for _ in range(m):
l, r, x = MI()
rtol[r].append([l, x])
dp = [[0] * (n + 1) for _ in range(n + 1)]
dp[0][0] = 1
for k in range(1, n + 1):
for i in range(k - 1):
dp[i][k - 1] = dp[k - 1][i] = sum(dp[i][: k - 1])
for l, x in rtol[k]:
if x == 1:
for i in range(l, k):
for j in range(k):
dp[i][j] = dp[j][i] = 0
if x == 2:
for i in range(l, k):
for j in range(i + 1, k):
dp[i][j] = dp[j][i] = 0
for i in range(l):
for j in range(i + 1):
dp[i][j] = dp[j][i] = 0
if x == 3:
for i in range(l):
for j in range(k):
dp[i][j] = dp[j][i] = 0
# p2D(dp)
print(sum(sum(dr) for dr in dp) * 3)
main()
| Statement
There are N squares arranged in a row. The squares are numbered 1, 2, ..., N,
from left to right.
Snuke is painting each square in red, green or blue. According to his
aesthetic sense, the following M conditions must all be satisfied. The i-th
condition is:
* There are exactly x_i different colors among squares l_i, l_i + 1, ..., r_i.
In how many ways can the squares be painted to satisfy all the conditions?
Find the count modulo 10^9+7. | [{"input": "3 1\n 1 3 3", "output": "6\n \n\nThe six ways are:\n\n * RGB\n * RBG\n * GRB\n * GBR\n * BRG\n * BGR\n\nwhere R, G and B correspond to red, green and blue squares, respectively.\n\n* * *"}, {"input": "4 2\n 1 3 1\n 2 4 2", "output": "6\n \n\nThe six ways are:\n\n * RRRG\n * RRRB\n * GGGR\n * GGGB\n * BBBR\n * BBBG\n\n* * *"}, {"input": "1 3\n 1 1 1\n 1 1 2\n 1 1 3", "output": "0\n \n\nThere are zero ways.\n\n* * *"}, {"input": "8 10\n 2 6 2\n 5 5 1\n 3 5 2\n 4 7 3\n 4 4 1\n 2 3 1\n 7 7 1\n 1 5 2\n 1 7 3\n 3 4 2", "output": "108"}] |
Print the number of ways to paint the squares to satisfy all the conditions,
modulo 10^9+7.
* * * | s280533582 | Runtime Error | p03717 | Input is given from Standard Input in the following format:
N M
l_1 r_1 x_1
l_2 r_2 x_2
:
l_M r_M x_M | from itertools import permutations
n,m = map(int,input().split())
lrx = [list(map(int,input().split())) for i in range(m)]
lrx.sort(key = lambda x:x[1])
mod = 10**9+7
dp = [[[0 for i in range(n+1)] for j in range(n+1)] for k in range(n+1)]
dp[0][0][0] = 1
for l,r,t in lrx:
if t != 1:
for g in range(l):
for b in range(max(1,g)):
dp[r][g][b] = -1
if t != 2:
for g in range(l,r):
for b in range(l):
dp[r][g][b] = -1
if t != 3:
for g in range(l,r):
for b in range(l,g):
dp[r][g][b] = -1
for r in range(n):
for g in range(r):
for b in range(max(1,g)):
v = dp[r][g][b]
if v == -1:
continue
if dp[r+1][g][b] >= 0:
dp[r+1][g][b] += v
dp[r+1][g][b] %= mod
if dp[r+1][r][b] >= 0:
dp[r+1][r][b] += v
dp[r+1[r][b] %= mod
if dp[r+1][g][b] >= 0:
dp[r+1][g][b] += v
dp[r+1][g][b] %= mod
ans = 0
for i in range(n):
for j in range(max(1,i)):
if dp[n][i][j] >= 0:
ans += dp[n][i][j]
ans %= mod
print(ans*6%mod)
| Statement
There are N squares arranged in a row. The squares are numbered 1, 2, ..., N,
from left to right.
Snuke is painting each square in red, green or blue. According to his
aesthetic sense, the following M conditions must all be satisfied. The i-th
condition is:
* There are exactly x_i different colors among squares l_i, l_i + 1, ..., r_i.
In how many ways can the squares be painted to satisfy all the conditions?
Find the count modulo 10^9+7. | [{"input": "3 1\n 1 3 3", "output": "6\n \n\nThe six ways are:\n\n * RGB\n * RBG\n * GRB\n * GBR\n * BRG\n * BGR\n\nwhere R, G and B correspond to red, green and blue squares, respectively.\n\n* * *"}, {"input": "4 2\n 1 3 1\n 2 4 2", "output": "6\n \n\nThe six ways are:\n\n * RRRG\n * RRRB\n * GGGR\n * GGGB\n * BBBR\n * BBBG\n\n* * *"}, {"input": "1 3\n 1 1 1\n 1 1 2\n 1 1 3", "output": "0\n \n\nThere are zero ways.\n\n* * *"}, {"input": "8 10\n 2 6 2\n 5 5 1\n 3 5 2\n 4 7 3\n 4 4 1\n 2 3 1\n 7 7 1\n 1 5 2\n 1 7 3\n 3 4 2", "output": "108"}] |
Print the number of ways to paint the squares to satisfy all the conditions,
modulo 10^9+7.
* * * | s208618728 | Runtime Error | p03717 | Input is given from Standard Input in the following format:
N M
l_1 r_1 x_1
l_2 r_2 x_2
:
l_M r_M x_M | from itertools import permutations
n,m = map(int,input().split())
lrx = [list(map(int,input().split())) for i in range(m)]
lrx.sort(key = lambda x:x[1])
mod = 10**9+7
dp = [[[0 for i in range(n+1)] for j in range(n+1)] for k in range(n+1)]
dp[0][0][0] = 1
for l,r,t in lrx:
if t != 1:
for g in range(l):
for b in range(max(1,g)):
for x,y,z in permutations((r,g,b)):
dp[x][y][z] = -1
if t != 2:
for g in range(l,r):
for b in range(l):
for x,y,z in permutations((r,g,b)):
dp[x][y][z] = -1
if t != 3:
for g in range(l,r):
for b in range(l,g):
for x,y,z in permutations((r,g,b)):
dp[x][y][z] = -1
for r in range(n):
for g in range(r):
for b in range(max(1,g)):
v = dp[r][g][b]
if v == -1:
continue
if dp[mx+1][g][b] >= 0:
dp[mx+1][g][b] += v
dp[mx+1][g][b] %= mod
if dp[r][mx+1][b] >= 0:
dp[r][mx+1][b] += v
dp[r][mx+1][b] %= mod
if dp[r][g][mx+1] >= 0:
dp[r][g][mx+1] += v
dp[r][g][mx+1] %= mod
ans = 0
for i in range(n):
for j in range(max(1,i)):
for x,y,z in permutations((n,i,j)):
if dp[x][y][z] >= 0:
ans += dp[x][y][z]
ans %= mod
print(ans*6%mod)
""" | Statement
There are N squares arranged in a row. The squares are numbered 1, 2, ..., N,
from left to right.
Snuke is painting each square in red, green or blue. According to his
aesthetic sense, the following M conditions must all be satisfied. The i-th
condition is:
* There are exactly x_i different colors among squares l_i, l_i + 1, ..., r_i.
In how many ways can the squares be painted to satisfy all the conditions?
Find the count modulo 10^9+7. | [{"input": "3 1\n 1 3 3", "output": "6\n \n\nThe six ways are:\n\n * RGB\n * RBG\n * GRB\n * GBR\n * BRG\n * BGR\n\nwhere R, G and B correspond to red, green and blue squares, respectively.\n\n* * *"}, {"input": "4 2\n 1 3 1\n 2 4 2", "output": "6\n \n\nThe six ways are:\n\n * RRRG\n * RRRB\n * GGGR\n * GGGB\n * BBBR\n * BBBG\n\n* * *"}, {"input": "1 3\n 1 1 1\n 1 1 2\n 1 1 3", "output": "0\n \n\nThere are zero ways.\n\n* * *"}, {"input": "8 10\n 2 6 2\n 5 5 1\n 3 5 2\n 4 7 3\n 4 4 1\n 2 3 1\n 7 7 1\n 1 5 2\n 1 7 3\n 3 4 2", "output": "108"}] |
Print the number of ways to paint the squares to satisfy all the conditions,
modulo 10^9+7.
* * * | s876281868 | Runtime Error | p03717 | Input is given from Standard Input in the following format:
N M
l_1 r_1 x_1
l_2 r_2 x_2
:
l_M r_M x_M | #include <bits/stdc++.h>
#define REP(i,a,b) for(int i=(a);i<(b);i++)
#define RREP(i,a,b) for(int i=(a);i>=(b);i--)
#define pq priority_queue
#define P pair<int,int>
#define P2 pair<int,P>
#define P3 pair<int,P2>
typedef long long ll; typedef long double ld;
using namespace std;
const int INF=1e9, MOD=1e9+7, around[]={0,1,1,-1,-1,0,-1,1,0,0};
const ll LINF=1e18;
const ld PI=abs(acos(-1));
int n,m,a,b,c;
ll dp[310][310][310]; //最右のindex
vector<P> vec[310];
bool ch(int i,int j,int k){
int r=max(i,max(j,k));
for(auto s:vec[r]){
if(((s.first<i)+(s.first<j)+(s.first<k))!=s.second) return 0;
}
return 1;
}
int main(){
cin >> n >> m;
REP(i,0,m) cin >> a >> b >> c,vec[b].push_back(P(a-1,c));
dp[0][0][0]=1;
REP(i,0,n){
REP(j,0,n){
REP(k,0,n){
int ma=max(i,max(j,k));
if(ch(i,j,ma+1)) (dp[i][j][ma+1]+=dp[i][j][k])%=MOD;
if(ch(i,ma+1,k)) (dp[i][ma+1][k]+=dp[i][j][k])%=MOD;
if(ch(ma+1,j,k)) (dp[ma+1][j][k]+=dp[i][j][k])%=MOD;
}
}
}
ll s=0;
REP(i,0,n+1){
REP(j,0,n+1){
s+=dp[n][i][j];
s+=dp[i][n][j];
s+=dp[i][j][n];
}
}
cout << s%MOD << endl;
return 0;
}
| Statement
There are N squares arranged in a row. The squares are numbered 1, 2, ..., N,
from left to right.
Snuke is painting each square in red, green or blue. According to his
aesthetic sense, the following M conditions must all be satisfied. The i-th
condition is:
* There are exactly x_i different colors among squares l_i, l_i + 1, ..., r_i.
In how many ways can the squares be painted to satisfy all the conditions?
Find the count modulo 10^9+7. | [{"input": "3 1\n 1 3 3", "output": "6\n \n\nThe six ways are:\n\n * RGB\n * RBG\n * GRB\n * GBR\n * BRG\n * BGR\n\nwhere R, G and B correspond to red, green and blue squares, respectively.\n\n* * *"}, {"input": "4 2\n 1 3 1\n 2 4 2", "output": "6\n \n\nThe six ways are:\n\n * RRRG\n * RRRB\n * GGGR\n * GGGB\n * BBBR\n * BBBG\n\n* * *"}, {"input": "1 3\n 1 1 1\n 1 1 2\n 1 1 3", "output": "0\n \n\nThere are zero ways.\n\n* * *"}, {"input": "8 10\n 2 6 2\n 5 5 1\n 3 5 2\n 4 7 3\n 4 4 1\n 2 3 1\n 7 7 1\n 1 5 2\n 1 7 3\n 3 4 2", "output": "108"}] |
Print the minimum possible number of different characters contained in the
strings.
* * * | s813334617 | Runtime Error | p03202 | Input is given from Standard Input in the following format:
N
A_1 A_2 ... A_N | N = int(input())
A = [int(_) for _ in input().split() if int(_) < 19 else 18]
N = len(A)
for _ in range(3):
flag = True
B = [A[0]]
for i in range(N - 1):
if A[i] >= A[i + 1]:
B += [A[i + 1]]
else:
flag = False
A = B
N = len(A)
if flag:
break
if N == 1:
print(1)
exit()
def is_possible(K):
dp = [0] * 19
for i in range(N - 1):
if B[i] >= B[i + 1]:
dp = dp[: B[i + 1]] + [0] * (19 - B[i + 1])
flag = True
for j in range(B[i + 1] - 1, -1, -1):
if dp[j] < K - 1:
dp[j] += 1
flag = False
break
else:
dp[j] = 0
if flag:
return False
return True
def bis(x, y):
if y == x + 1:
return y
elif is_possible((x + y) // 2):
return bis(x, (x + y) // 2)
else:
return bis((x + y) // 2, y)
print(bis(0, N))
| Statement
There are N strings arranged in a row. It is known that, for any two adjacent
strings, the string to the left is lexicographically smaller than the string
to the right. That is, S_1<S_2<...<S_N holds lexicographically, where S_i is
the i-th string from the left.
At least how many different characters are contained in S_1,S_2,...,S_N, if
the length of S_i is known to be A_i? | [{"input": "3\n 3 2 1", "output": "2\n \n\nThe number of different characters contained in S_1,S_2,...,S_N would be 3\nwhen, for example, S_1=`abc`, S_2=`bb` and S_3=`c`.\n\nHowever, if we choose the strings properly, the number of different characters\ncan be 2.\n\n* * *"}, {"input": "5\n 2 3 2 1 2", "output": "2"}] |
Print the minimum possible number of different characters contained in the
strings.
* * * | s357900828 | Runtime Error | p03202 | Input is given from Standard Input in the following format:
N
A_1 A_2 ... A_N | N=int(input())
alist=list(map(int,input().split()))
def bsearch(X):
amap={}
for i in range(1,N):
if alist[i-1]>=alist[i]:
if alist[i] in amap:
amap[alist[i]]+=1
else:
amap[alist[i]=1
if amap[alist[i]]>=X:
return False
for key in list(amap.keys()):
if key>alist[i]:
del amap[key]
#print(amap)
return True
l,r=1,N
while(True):
mid=(l+r)//2
#print(l,r,mid)
if bsearch(mid):
if mid==1 or not bsearch(mid-1):
break
else:
r=mid-1
else:
l=mid+1
print(mid) | Statement
There are N strings arranged in a row. It is known that, for any two adjacent
strings, the string to the left is lexicographically smaller than the string
to the right. That is, S_1<S_2<...<S_N holds lexicographically, where S_i is
the i-th string from the left.
At least how many different characters are contained in S_1,S_2,...,S_N, if
the length of S_i is known to be A_i? | [{"input": "3\n 3 2 1", "output": "2\n \n\nThe number of different characters contained in S_1,S_2,...,S_N would be 3\nwhen, for example, S_1=`abc`, S_2=`bb` and S_3=`c`.\n\nHowever, if we choose the strings properly, the number of different characters\ncan be 2.\n\n* * *"}, {"input": "5\n 2 3 2 1 2", "output": "2"}] |
Print the minimum possible number of different characters contained in the
strings.
* * * | s987766612 | Wrong Answer | p03202 | Input is given from Standard Input in the following format:
N
A_1 A_2 ... A_N | import os
import sys
if os.getenv("LOCAL"):
sys.stdin = open("_in.txt", "r")
sys.setrecursionlimit(10**9)
INF = float("inf")
IINF = 10**18
MOD = 10**9 + 7
# MOD = 998244353
N = int(sys.stdin.buffer.readline())
A = list(map(int, sys.stdin.buffer.readline().split()))
# (長さ、文字種)
stack = [(0, 0)]
ans = 0
for a in A:
popped = False
while a < stack[-1][0]:
stack.pop()
popped = True
l, c = stack[-1]
if a > l:
stack.append((a, 2 if popped else 1))
elif a == l:
stack[-1] = l, c + 1
else:
assert False
ans = max(ans, stack[-1][1])
while stack:
_, c = stack.pop()
ans = max(ans, c)
print(ans)
| Statement
There are N strings arranged in a row. It is known that, for any two adjacent
strings, the string to the left is lexicographically smaller than the string
to the right. That is, S_1<S_2<...<S_N holds lexicographically, where S_i is
the i-th string from the left.
At least how many different characters are contained in S_1,S_2,...,S_N, if
the length of S_i is known to be A_i? | [{"input": "3\n 3 2 1", "output": "2\n \n\nThe number of different characters contained in S_1,S_2,...,S_N would be 3\nwhen, for example, S_1=`abc`, S_2=`bb` and S_3=`c`.\n\nHowever, if we choose the strings properly, the number of different characters\ncan be 2.\n\n* * *"}, {"input": "5\n 2 3 2 1 2", "output": "2"}] |
Print the minimum possible number of different characters contained in the
strings.
* * * | s325671651 | Wrong Answer | p03202 | Input is given from Standard Input in the following format:
N
A_1 A_2 ... A_N | N = int(input())
A = [int(i) for i in input().split()]
print(2)
| Statement
There are N strings arranged in a row. It is known that, for any two adjacent
strings, the string to the left is lexicographically smaller than the string
to the right. That is, S_1<S_2<...<S_N holds lexicographically, where S_i is
the i-th string from the left.
At least how many different characters are contained in S_1,S_2,...,S_N, if
the length of S_i is known to be A_i? | [{"input": "3\n 3 2 1", "output": "2\n \n\nThe number of different characters contained in S_1,S_2,...,S_N would be 3\nwhen, for example, S_1=`abc`, S_2=`bb` and S_3=`c`.\n\nHowever, if we choose the strings properly, the number of different characters\ncan be 2.\n\n* * *"}, {"input": "5\n 2 3 2 1 2", "output": "2"}] |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.