message stringlengths 2 44.5k | message_type stringclasses 2
values | message_id int64 0 1 | conversation_id int64 276 109k | cluster float64 23 23 | __index_level_0__ int64 552 217k |
|---|---|---|---|---|---|
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Write a program which prints the central coordinate $(p_x, p_y)$ and the radius $r$ of a circumscribed circle of a triangle which is constructed by three points $(x_1, y_1)$, $(x_2, y_2)$ and $(x_3, y_3)$ on the plane surface.
Constraints
* $-100 \leq x_1, y_1, x_2, y_2, x_3, y_3 \leq 100$
* $ n \leq 20$
Input
Input consists of several datasets. In the first line, the number of datasets $n$ is given. Each dataset consists of:
$x_1$ $y_1$ $x_2$ $y_2$ $x_3$ $y_3$
in a line. All the input are real numbers.
Output
For each dataset, print $p_x$, $p_y$ and $r$ separated by a space in a line. Print the solution to three places of decimals. Round off the solution to three decimal places.
Example
Input
1
0.0 0.0 2.0 0.0 2.0 2.0
Output
1.000 1.000 1.414
Submitted Solution:
```
for _ in[0]*int(input()):
a,b,c,d,e,f=map(float,input().split())
x=((a*a+b*b)*(d-f)+(c*c+d*d)*(f-b)+(e*e+f*f)*(b-d))/2/(a*(d-f)+c*(f-b)+e*(b-d))
y=((a*a+b*b)*(c-e)+(c*c+d*d)*(e-a)+(e*e+f*f)*(a-c))/2/(b*(c-e)+d*(e-a)+f*(a-c))
print(f"{x:.3f} {y:.3f} {(x*x+y*y)**.5:.3f}")
``` | instruction | 0 | 45,296 | 23 | 90,592 |
No | output | 1 | 45,296 | 23 | 90,593 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Write a program which prints the central coordinate $(p_x, p_y)$ and the radius $r$ of a circumscribed circle of a triangle which is constructed by three points $(x_1, y_1)$, $(x_2, y_2)$ and $(x_3, y_3)$ on the plane surface.
Constraints
* $-100 \leq x_1, y_1, x_2, y_2, x_3, y_3 \leq 100$
* $ n \leq 20$
Input
Input consists of several datasets. In the first line, the number of datasets $n$ is given. Each dataset consists of:
$x_1$ $y_1$ $x_2$ $y_2$ $x_3$ $y_3$
in a line. All the input are real numbers.
Output
For each dataset, print $p_x$, $p_y$ and $r$ separated by a space in a line. Print the solution to three places of decimals. Round off the solution to three decimal places.
Example
Input
1
0.0 0.0 2.0 0.0 2.0 2.0
Output
1.000 1.000 1.414
Submitted Solution:
```
import sys
import math
n = int(sys.stdin.readline().rstrip())
for i in range(n):
x1,y1,x2,y2,x3,y3 = map(float, sys.stdin.readline().rstrip().split(' '))
p = ((y1-y3)*(y1**2-y2**2+x1**2-x2**2)-(y1-y2)*(y1**2-y3**2+x1**2-x3**2)) / (2*(y1-y3)*(x1-x2)-2*(y1-y2)*(x1-x3))
q = ((x1-x3)*(x1**2-x2**2+y1**2-y2**2)-(x1-x2)*(x1**2-x3**2+y1**2-y3**2)) / (2*(x1-x3)*(y1-y2)-2*(x1-x2)*(y1-y3))
r = math.sqrt((p-x1)**2 + (p-y1)**2)
print("{:0.3f} {:0.3f} {:0.3f}".format(round(p,3),round(q,3),round(r,3)))
``` | instruction | 0 | 45,297 | 23 | 90,594 |
No | output | 1 | 45,297 | 23 | 90,595 |
Provide a correct Python 3 solution for this coding contest problem.
Example
Input
4 4
1 2 3
1 3 3
2 3 3
2 4 3
Output
1 3 | instruction | 0 | 45,333 | 23 | 90,666 |
"Correct Solution:
```
N, M = map(int, input().split())
E0 = []
for i in range(M):
S, D, C = map(int, input().split())
E0.append((C, S-1, D-1))
E0.sort()
*parent, = range(N)
def root(x):
if x == parent[x]:
return x
y = parent[x] = root(parent[x])
return y
def unite(x, y):
px = root(x); py = root(y)
if px < py:
parent[py] = px
else:
parent[px] = py
cnt = 0; base = None
for i in range(M):
C, S, D = E0[i]
if root(S) != root(D):
unite(S, D)
cnt += 1
if cnt == N-1:
base = C
ES = {}; CM = {}
for i in range(M):
C, S, D = E0[i]
if C <= base:
ES.setdefault(C, set()).add((S, D))
CM[S, D] = C
def bridge(G, N):
result = set()
label = [None]*N
gen = 0
cost = [0]*N
def dfs(u, p):
nonlocal gen
res = 0
for v in G[u]:
if v == p:
continue
if label[v] is not None:
if label[v] < label[u]:
cost[v] += 1
res += 1
else:
label[v] = gen; gen += 1
r = dfs(v, u)
if r == 0:
result.add((u, v) if u < v else (v, u))
res += r
res -= cost[u]
return res
for v in range(N):
if not label[v]:
label[v] = gen; gen += 1
r = dfs(v, -1)
assert r == 0, r
return result
G = [[] for i in range(N)]
cnt = 0; ans = 0
for C in sorted(ES):
for S, D in ES[C]:
G[S].append(D)
G[D].append(S)
B = bridge(G, N)
cnt += len(B & ES[C])
ans += len(B & ES[C]) * C
print(cnt, ans)
``` | output | 1 | 45,333 | 23 | 90,667 |
Provide a correct Python 3 solution for this coding contest problem.
For given two sides of a triangle a and b and the angle C between them, calculate the following properties:
* S: Area of the triangle
* L: The length of the circumference of the triangle
* h: The height of the triangle with side a as a bottom edge
Input
The length of a, the length of b and the angle C are given in integers.
Output
Print S, L and h in a line respectively. The output should not contain an absolute error greater than 10-4.
Example
Input
4 3 90
Output
6.00000000
12.00000000
3.00000000 | instruction | 0 | 45,362 | 23 | 90,724 |
"Correct Solution:
```
import math
a, b, C = map(float, input().split())
S = a*b*math.sin(math.radians(C))/2
L = a + b + math.sqrt(a*a + b*b - 2*a*b*math.cos(math.radians(C)))
h = 2 * S / a
print(f"{S} {L} {h}")
``` | output | 1 | 45,362 | 23 | 90,725 |
Provide a correct Python 3 solution for this coding contest problem.
For given two sides of a triangle a and b and the angle C between them, calculate the following properties:
* S: Area of the triangle
* L: The length of the circumference of the triangle
* h: The height of the triangle with side a as a bottom edge
Input
The length of a, the length of b and the angle C are given in integers.
Output
Print S, L and h in a line respectively. The output should not contain an absolute error greater than 10-4.
Example
Input
4 3 90
Output
6.00000000
12.00000000
3.00000000 | instruction | 0 | 45,363 | 23 | 90,726 |
"Correct Solution:
```
import math
a, b, c = map(int, input().split())
S = 0.5*math.sin(math.radians(c))*a*b
L = (a**2+b**2-2*a*b*math.cos(math.radians(c)))**0.5 + a + b
h = 2*S/a
print(S,L,h)
``` | output | 1 | 45,363 | 23 | 90,727 |
Provide a correct Python 3 solution for this coding contest problem.
For given two sides of a triangle a and b and the angle C between them, calculate the following properties:
* S: Area of the triangle
* L: The length of the circumference of the triangle
* h: The height of the triangle with side a as a bottom edge
Input
The length of a, the length of b and the angle C are given in integers.
Output
Print S, L and h in a line respectively. The output should not contain an absolute error greater than 10-4.
Example
Input
4 3 90
Output
6.00000000
12.00000000
3.00000000 | instruction | 0 | 45,364 | 23 | 90,728 |
"Correct Solution:
```
import math
a,b,c=map(int,input().split())
rad=math.radians(c)
s=a*b*math.sin(rad)/2
print(s)
edge=math.sqrt(a**2 + b**2 - 2*a*b*math.cos(rad))
print(a+b+edge)
print(s*2/a)
``` | output | 1 | 45,364 | 23 | 90,729 |
Provide a correct Python 3 solution for this coding contest problem.
For given two sides of a triangle a and b and the angle C between them, calculate the following properties:
* S: Area of the triangle
* L: The length of the circumference of the triangle
* h: The height of the triangle with side a as a bottom edge
Input
The length of a, the length of b and the angle C are given in integers.
Output
Print S, L and h in a line respectively. The output should not contain an absolute error greater than 10-4.
Example
Input
4 3 90
Output
6.00000000
12.00000000
3.00000000 | instruction | 0 | 45,365 | 23 | 90,730 |
"Correct Solution:
```
import math as mp
a,b,C = map(int,input().split())
C = mp.radians(C)
print(0.5*a*b*mp.sin(C))
print(a+b+mp.sqrt(a**2+b**2-2*a*b*mp.cos(C)))
print(b*mp.sin(C))
``` | output | 1 | 45,365 | 23 | 90,731 |
Provide a correct Python 3 solution for this coding contest problem.
For given two sides of a triangle a and b and the angle C between them, calculate the following properties:
* S: Area of the triangle
* L: The length of the circumference of the triangle
* h: The height of the triangle with side a as a bottom edge
Input
The length of a, the length of b and the angle C are given in integers.
Output
Print S, L and h in a line respectively. The output should not contain an absolute error greater than 10-4.
Example
Input
4 3 90
Output
6.00000000
12.00000000
3.00000000 | instruction | 0 | 45,366 | 23 | 90,732 |
"Correct Solution:
```
import math
a, b, c = map(float, input().split())
c = c*math.pi/180
S = 0.5*a*b*math.sin(c)
d = (a**2 + b**2 - 2*b*a*math.cos(c))**0.5
L = a + b + d
h = b*math.sin(c)
print (S, L, h, end="\n")
``` | output | 1 | 45,366 | 23 | 90,733 |
Provide a correct Python 3 solution for this coding contest problem.
For given two sides of a triangle a and b and the angle C between them, calculate the following properties:
* S: Area of the triangle
* L: The length of the circumference of the triangle
* h: The height of the triangle with side a as a bottom edge
Input
The length of a, the length of b and the angle C are given in integers.
Output
Print S, L and h in a line respectively. The output should not contain an absolute error greater than 10-4.
Example
Input
4 3 90
Output
6.00000000
12.00000000
3.00000000 | instruction | 0 | 45,367 | 23 | 90,734 |
"Correct Solution:
```
import math
a, b, C = map(int, input().split())
S = a*b*math.sin(C*math.pi/180)/2
L = a+b+(a**2+b**2-2*a*b*math.cos(C*math.pi/180))**0.5
h = 2*S/a
print(S)
print(L)
print(h)
``` | output | 1 | 45,367 | 23 | 90,735 |
Provide a correct Python 3 solution for this coding contest problem.
For given two sides of a triangle a and b and the angle C between them, calculate the following properties:
* S: Area of the triangle
* L: The length of the circumference of the triangle
* h: The height of the triangle with side a as a bottom edge
Input
The length of a, the length of b and the angle C are given in integers.
Output
Print S, L and h in a line respectively. The output should not contain an absolute error greater than 10-4.
Example
Input
4 3 90
Output
6.00000000
12.00000000
3.00000000 | instruction | 0 | 45,368 | 23 | 90,736 |
"Correct Solution:
```
import math
A, B, R = map(int, input().split())
rad = math.radians(R)
S = A * B * math.sin(rad) / 2
C = math.sqrt(A**2 + B**2 - 2*A*B*math.cos(rad))
h = S / (0.5 *A)
print(S)
print(A+B+C)
print(h)
``` | output | 1 | 45,368 | 23 | 90,737 |
Provide a correct Python 3 solution for this coding contest problem.
For given two sides of a triangle a and b and the angle C between them, calculate the following properties:
* S: Area of the triangle
* L: The length of the circumference of the triangle
* h: The height of the triangle with side a as a bottom edge
Input
The length of a, the length of b and the angle C are given in integers.
Output
Print S, L and h in a line respectively. The output should not contain an absolute error greater than 10-4.
Example
Input
4 3 90
Output
6.00000000
12.00000000
3.00000000 | instruction | 0 | 45,369 | 23 | 90,738 |
"Correct Solution:
```
import math
a,b, A = map(float, input().split())
h = b*math.sin(math.radians(A))
S = a*h*0.5
L = a + b + math.sqrt(pow(a, 2) + pow(b, 2) - 2*a*b*math.cos(math.radians(A)))
print(S)
print(L)
print(h)
``` | output | 1 | 45,369 | 23 | 90,739 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
For given two sides of a triangle a and b and the angle C between them, calculate the following properties:
* S: Area of the triangle
* L: The length of the circumference of the triangle
* h: The height of the triangle with side a as a bottom edge
Input
The length of a, the length of b and the angle C are given in integers.
Output
Print S, L and h in a line respectively. The output should not contain an absolute error greater than 10-4.
Example
Input
4 3 90
Output
6.00000000
12.00000000
3.00000000
Submitted Solution:
```
import math
a,b,C=map(int,input().split())
c=(a**2+b**2-2*b*a*math.cos(math.radians(C)))**0.5
L=a+b+c
s=(a+b+c)/2
S=(s*(s-a)*(s-b)*(s-c))**0.5
h=2*S/a
print(S,L,h,sep='\n')
``` | instruction | 0 | 45,370 | 23 | 90,740 |
Yes | output | 1 | 45,370 | 23 | 90,741 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
For given two sides of a triangle a and b and the angle C between them, calculate the following properties:
* S: Area of the triangle
* L: The length of the circumference of the triangle
* h: The height of the triangle with side a as a bottom edge
Input
The length of a, the length of b and the angle C are given in integers.
Output
Print S, L and h in a line respectively. The output should not contain an absolute error greater than 10-4.
Example
Input
4 3 90
Output
6.00000000
12.00000000
3.00000000
Submitted Solution:
```
import math
a,b,C = map(int,input().split())
print(a*b*math.sin(math.radians(C))/2)
print(a+b+(a**2+b**2-2*a*b*math.cos(math.radians(C)))**(1/2))
print(b*math.sin(math.radians(C)))
``` | instruction | 0 | 45,371 | 23 | 90,742 |
Yes | output | 1 | 45,371 | 23 | 90,743 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
For given two sides of a triangle a and b and the angle C between them, calculate the following properties:
* S: Area of the triangle
* L: The length of the circumference of the triangle
* h: The height of the triangle with side a as a bottom edge
Input
The length of a, the length of b and the angle C are given in integers.
Output
Print S, L and h in a line respectively. The output should not contain an absolute error greater than 10-4.
Example
Input
4 3 90
Output
6.00000000
12.00000000
3.00000000
Submitted Solution:
```
import math
a,b,C=map(int,input().split())
c=math.sqrt(a*a + b*b - 2*a*b*math.cos(math.radians(C)))
s=(a+b+c)/2
S=math.sqrt(s*(s-a)*(s-b)*(s-c))
L=a+b+c
h=2*S/a
print(f"{S:.5f}\n{L:.5f}\n{h:.5f}")
``` | instruction | 0 | 45,372 | 23 | 90,744 |
Yes | output | 1 | 45,372 | 23 | 90,745 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
For given two sides of a triangle a and b and the angle C between them, calculate the following properties:
* S: Area of the triangle
* L: The length of the circumference of the triangle
* h: The height of the triangle with side a as a bottom edge
Input
The length of a, the length of b and the angle C are given in integers.
Output
Print S, L and h in a line respectively. The output should not contain an absolute error greater than 10-4.
Example
Input
4 3 90
Output
6.00000000
12.00000000
3.00000000
Submitted Solution:
```
import math as m
a,b,C = map(int,input().split())
r = m.radians(C)
print(f'{a*b*m.sin(r)/2:.5f}')
print(f'{a+b+m.sqrt(a**2+b**2-2*a*b*m.cos(r)):.5f}')
print(f'{b*m.sin(r):.5f}')
``` | instruction | 0 | 45,373 | 23 | 90,746 |
Yes | output | 1 | 45,373 | 23 | 90,747 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
For given two sides of a triangle a and b and the angle C between them, calculate the following properties:
* S: Area of the triangle
* L: The length of the circumference of the triangle
* h: The height of the triangle with side a as a bottom edge
Input
The length of a, the length of b and the angle C are given in integers.
Output
Print S, L and h in a line respectively. The output should not contain an absolute error greater than 10-4.
Example
Input
4 3 90
Output
6.00000000
12.00000000
3.00000000
Submitted Solution:
```
import math
a,b,c = map(float, raw_input().split())
cc = math.radians(c)
h = b * math.sin(cc)
S = a * h / 2
L = a + b + math.sqrt(h**2 + (a-b*math.cos(cc))**2)
print("{0:.5f}\n{1:.5f}\n{2:.5f}\n".format(S, L, h))
``` | instruction | 0 | 45,374 | 23 | 90,748 |
No | output | 1 | 45,374 | 23 | 90,749 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
For given two sides of a triangle a and b and the angle C between them, calculate the following properties:
* S: Area of the triangle
* L: The length of the circumference of the triangle
* h: The height of the triangle with side a as a bottom edge
Input
The length of a, the length of b and the angle C are given in integers.
Output
Print S, L and h in a line respectively. The output should not contain an absolute error greater than 10-4.
Example
Input
4 3 90
Output
6.00000000
12.00000000
3.00000000
Submitted Solution:
```
import math
class Triangle(object):
def __init__(self, a, b, C):
self.a = a
self.b = b
self.C = math.radians(C)
def getArea(self):
return((self.a * self.getHeight()) / 2)
def getPerimeter(self):
return(self.a + self.b + math.sqrt(self.a ** 2 + self.b ** 2))
def getHeight(self):
return(self.b * math.sin(self.C))
tri = Triangle(*[float(i) for i in input().split()])
print(tri.getArea())
print(tri.getPerimeter())
print(tri.getHeight())
``` | instruction | 0 | 45,375 | 23 | 90,750 |
No | output | 1 | 45,375 | 23 | 90,751 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
For given two sides of a triangle a and b and the angle C between them, calculate the following properties:
* S: Area of the triangle
* L: The length of the circumference of the triangle
* h: The height of the triangle with side a as a bottom edge
Input
The length of a, the length of b and the angle C are given in integers.
Output
Print S, L and h in a line respectively. The output should not contain an absolute error greater than 10-4.
Example
Input
4 3 90
Output
6.00000000
12.00000000
3.00000000
Submitted Solution:
```
import math
(a, b, C) = [int(i) for i in input().split()]
cs = math.radians(C)
c = math.sqrt(a ** 2 + b ** 2 - 2 * a * b * math.cos(cs))
h = b * math.sin(c)
S = a * h / 2
L = a + b + c
[print(format(i, '6f')) for i in [-S, L, -h]]
``` | instruction | 0 | 45,376 | 23 | 90,752 |
No | output | 1 | 45,376 | 23 | 90,753 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
For given two sides of a triangle a and b and the angle C between them, calculate the following properties:
* S: Area of the triangle
* L: The length of the circumference of the triangle
* h: The height of the triangle with side a as a bottom edge
Input
The length of a, the length of b and the angle C are given in integers.
Output
Print S, L and h in a line respectively. The output should not contain an absolute error greater than 10-4.
Example
Input
4 3 90
Output
6.00000000
12.00000000
3.00000000
Submitted Solution:
```
import math
a,b,c = map(int,input().split())
c=c/180*math.pi
print(0.5*a*b*math.sin(c),(a**2+b**2-2*a*b*math.cos(c))**0.5,b*math.sin(c))
``` | instruction | 0 | 45,377 | 23 | 90,754 |
No | output | 1 | 45,377 | 23 | 90,755 |
Provide tags and a correct Python 3 solution for this coding contest problem.
You are given n segments on a coordinate line; each endpoint of every segment has integer coordinates. Some segments can degenerate to points. Segments can intersect with each other, be nested in each other or even coincide.
Your task is the following: for every k ∈ [1..n], calculate the number of points with integer coordinates such that the number of segments that cover these points equals k. A segment with endpoints l_i and r_i covers point x if and only if l_i ≤ x ≤ r_i.
Input
The first line of the input contains one integer n (1 ≤ n ≤ 2 ⋅ 10^5) — the number of segments.
The next n lines contain segments. The i-th line contains a pair of integers l_i, r_i (0 ≤ l_i ≤ r_i ≤ 10^{18}) — the endpoints of the i-th segment.
Output
Print n space separated integers cnt_1, cnt_2, ..., cnt_n, where cnt_i is equal to the number of points such that the number of segments that cover these points equals to i.
Examples
Input
3
0 3
1 3
3 8
Output
6 2 1
Input
3
1 3
2 4
5 7
Output
5 2 0
Note
The picture describing the first example:
<image>
Points with coordinates [0, 4, 5, 6, 7, 8] are covered by one segment, points [1, 2] are covered by two segments and point [3] is covered by three segments.
The picture describing the second example:
<image>
Points [1, 4, 5, 6, 7] are covered by one segment, points [2, 3] are covered by two segments and there are no points covered by three segments. | instruction | 0 | 45,378 | 23 | 90,756 |
Tags: data structures, implementation, sortings
Correct Solution:
```
n=int(input())
l=[0 for i in range(n+1)]
lo=[]
lc=[]
for i in range(n):
x,y=map(int,input().strip().split())
lo.append(x)
lc.append(y)
lo.sort()
lc.sort()
i=1
j=0
count=1
st=lo[0]
ref=0
while(i<n and j<n):
if (lo[i]<=lc[j]):
if ref==0:
l[count]=l[count]+lo[i]-st
else:
l[count]=l[count]+lo[i]-st-1
ref=0
count=count+1
st=lo[i]
i=i+1
else:
if (ref==0):
l[count]=l[count]+lc[j]-st+1
else:
l[count]=l[count]+lc[j]-st
count=count-1
ref=1
st=lc[j]
j=j+1
while(j<n):
if (ref==0):
l[count]=l[count]+lc[j]-st+1
else:
l[count]=l[count]+lc[j]-st
count=count-1
ref=1
st=lc[j]
j=j+1
print (" ".join(map(str,l[1:])))
``` | output | 1 | 45,378 | 23 | 90,757 |
Provide tags and a correct Python 3 solution for this coding contest problem.
You are given n segments on a coordinate line; each endpoint of every segment has integer coordinates. Some segments can degenerate to points. Segments can intersect with each other, be nested in each other or even coincide.
Your task is the following: for every k ∈ [1..n], calculate the number of points with integer coordinates such that the number of segments that cover these points equals k. A segment with endpoints l_i and r_i covers point x if and only if l_i ≤ x ≤ r_i.
Input
The first line of the input contains one integer n (1 ≤ n ≤ 2 ⋅ 10^5) — the number of segments.
The next n lines contain segments. The i-th line contains a pair of integers l_i, r_i (0 ≤ l_i ≤ r_i ≤ 10^{18}) — the endpoints of the i-th segment.
Output
Print n space separated integers cnt_1, cnt_2, ..., cnt_n, where cnt_i is equal to the number of points such that the number of segments that cover these points equals to i.
Examples
Input
3
0 3
1 3
3 8
Output
6 2 1
Input
3
1 3
2 4
5 7
Output
5 2 0
Note
The picture describing the first example:
<image>
Points with coordinates [0, 4, 5, 6, 7, 8] are covered by one segment, points [1, 2] are covered by two segments and point [3] is covered by three segments.
The picture describing the second example:
<image>
Points [1, 4, 5, 6, 7] are covered by one segment, points [2, 3] are covered by two segments and there are no points covered by three segments. | instruction | 0 | 45,379 | 23 | 90,758 |
Tags: data structures, implementation, sortings
Correct Solution:
```
n = int(input())
pos = {}
for _ in range(n):
l, r = [int(x) for x in input().split()]
if l in pos: pos[l] += 1
else:pos[l] = 1
if r+1 in pos: pos[r+1] -= 1
else:pos[r+1] = -1
#pos[r+1] = pos.get(r+1, -1) - 1
a = sorted(pos.items(), key = lambda x : x[0])
res = [0] * n
s = 0
for i in range(len(a)):
if 1 <= s <= n:
res[s-1] += a[i][0] - a[i-1][0]
s += a[i][1]
print(*res)
``` | output | 1 | 45,379 | 23 | 90,759 |
Provide tags and a correct Python 3 solution for this coding contest problem.
You are given n segments on a coordinate line; each endpoint of every segment has integer coordinates. Some segments can degenerate to points. Segments can intersect with each other, be nested in each other or even coincide.
Your task is the following: for every k ∈ [1..n], calculate the number of points with integer coordinates such that the number of segments that cover these points equals k. A segment with endpoints l_i and r_i covers point x if and only if l_i ≤ x ≤ r_i.
Input
The first line of the input contains one integer n (1 ≤ n ≤ 2 ⋅ 10^5) — the number of segments.
The next n lines contain segments. The i-th line contains a pair of integers l_i, r_i (0 ≤ l_i ≤ r_i ≤ 10^{18}) — the endpoints of the i-th segment.
Output
Print n space separated integers cnt_1, cnt_2, ..., cnt_n, where cnt_i is equal to the number of points such that the number of segments that cover these points equals to i.
Examples
Input
3
0 3
1 3
3 8
Output
6 2 1
Input
3
1 3
2 4
5 7
Output
5 2 0
Note
The picture describing the first example:
<image>
Points with coordinates [0, 4, 5, 6, 7, 8] are covered by one segment, points [1, 2] are covered by two segments and point [3] is covered by three segments.
The picture describing the second example:
<image>
Points [1, 4, 5, 6, 7] are covered by one segment, points [2, 3] are covered by two segments and there are no points covered by three segments. | instruction | 0 | 45,380 | 23 | 90,760 |
Tags: data structures, implementation, sortings
Correct Solution:
```
def ii():
return int(input())
def mi():
return map(int, input().split())
def li():
return list(mi())
from collections import Counter
n = ii()
a1 = [tuple(mi()) for i in range(n)]
a = []
for l, r in a1:
a.append((l, 0))
a.append((r, 1))
c = Counter(a)
b = [(k[0], k[1], v) for k, v in c.items()]
b.sort()
ans = [0] * (n + 1)
p = -1
cnt = 0
for x, y, z in b:
if y == 0:
ans[cnt] += x - p - 1
cnt += z
ans[cnt] += 1
else:
if x != p:
ans[cnt] += x - p
cnt -= z
p = x
print(*ans[1:])
``` | output | 1 | 45,380 | 23 | 90,761 |
Provide tags and a correct Python 3 solution for this coding contest problem.
You are given n segments on a coordinate line; each endpoint of every segment has integer coordinates. Some segments can degenerate to points. Segments can intersect with each other, be nested in each other or even coincide.
Your task is the following: for every k ∈ [1..n], calculate the number of points with integer coordinates such that the number of segments that cover these points equals k. A segment with endpoints l_i and r_i covers point x if and only if l_i ≤ x ≤ r_i.
Input
The first line of the input contains one integer n (1 ≤ n ≤ 2 ⋅ 10^5) — the number of segments.
The next n lines contain segments. The i-th line contains a pair of integers l_i, r_i (0 ≤ l_i ≤ r_i ≤ 10^{18}) — the endpoints of the i-th segment.
Output
Print n space separated integers cnt_1, cnt_2, ..., cnt_n, where cnt_i is equal to the number of points such that the number of segments that cover these points equals to i.
Examples
Input
3
0 3
1 3
3 8
Output
6 2 1
Input
3
1 3
2 4
5 7
Output
5 2 0
Note
The picture describing the first example:
<image>
Points with coordinates [0, 4, 5, 6, 7, 8] are covered by one segment, points [1, 2] are covered by two segments and point [3] is covered by three segments.
The picture describing the second example:
<image>
Points [1, 4, 5, 6, 7] are covered by one segment, points [2, 3] are covered by two segments and there are no points covered by three segments. | instruction | 0 | 45,381 | 23 | 90,762 |
Tags: data structures, implementation, sortings
Correct Solution:
```
import sys
class main:
def __init__(self):
self.n=int(sys.stdin.readline())
self.line=dict()
for i in range(self.n):
a,b=(int(s) for s in sys.stdin.readline().rstrip().split(' '))
self.line[a]=self.line.get(a,0)+1
self.line[b+1]=self.line.get(b+1,0)-1
def calc(self):
self.result=dict()
sorted_keys = sorted(self.line.keys())
count=0
last=sorted_keys[0]
for k in sorted_keys:
self.result[count]=self.result.get(count,0)+k-last
count=count+self.line[k]
last=k
del self.result[0]
def out(self):
for k in range(1,self.n):
print(self.result.get(k,0),end=' ')
print(self.result.get(self.n, 0), end='')
def solve(self):
self.calc()
self.out()
if __name__ == '__main__':
m=main()
m.solve()
pass
``` | output | 1 | 45,381 | 23 | 90,763 |
Provide tags and a correct Python 3 solution for this coding contest problem.
You are given n segments on a coordinate line; each endpoint of every segment has integer coordinates. Some segments can degenerate to points. Segments can intersect with each other, be nested in each other or even coincide.
Your task is the following: for every k ∈ [1..n], calculate the number of points with integer coordinates such that the number of segments that cover these points equals k. A segment with endpoints l_i and r_i covers point x if and only if l_i ≤ x ≤ r_i.
Input
The first line of the input contains one integer n (1 ≤ n ≤ 2 ⋅ 10^5) — the number of segments.
The next n lines contain segments. The i-th line contains a pair of integers l_i, r_i (0 ≤ l_i ≤ r_i ≤ 10^{18}) — the endpoints of the i-th segment.
Output
Print n space separated integers cnt_1, cnt_2, ..., cnt_n, where cnt_i is equal to the number of points such that the number of segments that cover these points equals to i.
Examples
Input
3
0 3
1 3
3 8
Output
6 2 1
Input
3
1 3
2 4
5 7
Output
5 2 0
Note
The picture describing the first example:
<image>
Points with coordinates [0, 4, 5, 6, 7, 8] are covered by one segment, points [1, 2] are covered by two segments and point [3] is covered by three segments.
The picture describing the second example:
<image>
Points [1, 4, 5, 6, 7] are covered by one segment, points [2, 3] are covered by two segments and there are no points covered by three segments. | instruction | 0 | 45,382 | 23 | 90,764 |
Tags: data structures, implementation, sortings
Correct Solution:
```
N = int(input())
points = []
for i in range(N):
a, b = map(int, input().split())
points.append((a, 1))
points.append((b + 1, -1))
points = sorted(points, key = lambda x:x[0])
count = [0 for i in range(N + 1)]
overlapp = 0
prev = 0
for point in points:
count[overlapp] += point[0] - prev
overlapp += point[1]
prev = point[0]
print(" ".join(map(str, count[1:])))
``` | output | 1 | 45,382 | 23 | 90,765 |
Provide tags and a correct Python 3 solution for this coding contest problem.
You are given n segments on a coordinate line; each endpoint of every segment has integer coordinates. Some segments can degenerate to points. Segments can intersect with each other, be nested in each other or even coincide.
Your task is the following: for every k ∈ [1..n], calculate the number of points with integer coordinates such that the number of segments that cover these points equals k. A segment with endpoints l_i and r_i covers point x if and only if l_i ≤ x ≤ r_i.
Input
The first line of the input contains one integer n (1 ≤ n ≤ 2 ⋅ 10^5) — the number of segments.
The next n lines contain segments. The i-th line contains a pair of integers l_i, r_i (0 ≤ l_i ≤ r_i ≤ 10^{18}) — the endpoints of the i-th segment.
Output
Print n space separated integers cnt_1, cnt_2, ..., cnt_n, where cnt_i is equal to the number of points such that the number of segments that cover these points equals to i.
Examples
Input
3
0 3
1 3
3 8
Output
6 2 1
Input
3
1 3
2 4
5 7
Output
5 2 0
Note
The picture describing the first example:
<image>
Points with coordinates [0, 4, 5, 6, 7, 8] are covered by one segment, points [1, 2] are covered by two segments and point [3] is covered by three segments.
The picture describing the second example:
<image>
Points [1, 4, 5, 6, 7] are covered by one segment, points [2, 3] are covered by two segments and there are no points covered by three segments. | instruction | 0 | 45,383 | 23 | 90,766 |
Tags: data structures, implementation, sortings
Correct Solution:
```
l = int(input())
points = []
for i in range(l):
a, b = map(int, input().split())
points.append((a, 1))
points.append((b + 1, -1))
points = sorted(points, key = lambda x:x[0])
count = [0 for i in range(l + 1)]
overlap = 0
prev = 0
for point in points:
count[overlap] += point[0] - prev
overlap += point[1]
prev = point[0]
print(" ".join(map(str, count[1:])))
``` | output | 1 | 45,383 | 23 | 90,767 |
Provide tags and a correct Python 3 solution for this coding contest problem.
You are given n segments on a coordinate line; each endpoint of every segment has integer coordinates. Some segments can degenerate to points. Segments can intersect with each other, be nested in each other or even coincide.
Your task is the following: for every k ∈ [1..n], calculate the number of points with integer coordinates such that the number of segments that cover these points equals k. A segment with endpoints l_i and r_i covers point x if and only if l_i ≤ x ≤ r_i.
Input
The first line of the input contains one integer n (1 ≤ n ≤ 2 ⋅ 10^5) — the number of segments.
The next n lines contain segments. The i-th line contains a pair of integers l_i, r_i (0 ≤ l_i ≤ r_i ≤ 10^{18}) — the endpoints of the i-th segment.
Output
Print n space separated integers cnt_1, cnt_2, ..., cnt_n, where cnt_i is equal to the number of points such that the number of segments that cover these points equals to i.
Examples
Input
3
0 3
1 3
3 8
Output
6 2 1
Input
3
1 3
2 4
5 7
Output
5 2 0
Note
The picture describing the first example:
<image>
Points with coordinates [0, 4, 5, 6, 7, 8] are covered by one segment, points [1, 2] are covered by two segments and point [3] is covered by three segments.
The picture describing the second example:
<image>
Points [1, 4, 5, 6, 7] are covered by one segment, points [2, 3] are covered by two segments and there are no points covered by three segments. | instruction | 0 | 45,384 | 23 | 90,768 |
Tags: data structures, implementation, sortings
Correct Solution:
```
import sys
input = sys.stdin.readline
from collections import defaultdict
n = int(input())
l = []
for _ in range(n):
li, ri = map(int, input().split())
l.append((1, li))
l.append((-1, ri+1))
l.sort(key=lambda k: k[1])
ans = defaultdict(int)
cnt = 0
for i in range(len(l)-1):
cnt += l[i][0]
ans[cnt] += l[i+1][1]-l[i][1]
for i in range(1, n+1):
if i<n:
print(ans[i], end=' ')
else:
print(ans[i])
``` | output | 1 | 45,384 | 23 | 90,769 |
Provide tags and a correct Python 3 solution for this coding contest problem.
You are given n segments on a coordinate line; each endpoint of every segment has integer coordinates. Some segments can degenerate to points. Segments can intersect with each other, be nested in each other or even coincide.
Your task is the following: for every k ∈ [1..n], calculate the number of points with integer coordinates such that the number of segments that cover these points equals k. A segment with endpoints l_i and r_i covers point x if and only if l_i ≤ x ≤ r_i.
Input
The first line of the input contains one integer n (1 ≤ n ≤ 2 ⋅ 10^5) — the number of segments.
The next n lines contain segments. The i-th line contains a pair of integers l_i, r_i (0 ≤ l_i ≤ r_i ≤ 10^{18}) — the endpoints of the i-th segment.
Output
Print n space separated integers cnt_1, cnt_2, ..., cnt_n, where cnt_i is equal to the number of points such that the number of segments that cover these points equals to i.
Examples
Input
3
0 3
1 3
3 8
Output
6 2 1
Input
3
1 3
2 4
5 7
Output
5 2 0
Note
The picture describing the first example:
<image>
Points with coordinates [0, 4, 5, 6, 7, 8] are covered by one segment, points [1, 2] are covered by two segments and point [3] is covered by three segments.
The picture describing the second example:
<image>
Points [1, 4, 5, 6, 7] are covered by one segment, points [2, 3] are covered by two segments and there are no points covered by three segments. | instruction | 0 | 45,385 | 23 | 90,770 |
Tags: data structures, implementation, sortings
Correct Solution:
```
from collections import*
n=int(input())
d=defaultdict(int)
for _ in [0]*n:
l,r=map(int,input().split());d[l]+=1;d[r+1]-=1
s=p=0
f=[0]*(n+1)
for k in sorted(d):
f[s]+=k-p;s+=d[k];p=k
print(*f[1:])
r = 77
``` | output | 1 | 45,385 | 23 | 90,771 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
You are given n segments on a coordinate line; each endpoint of every segment has integer coordinates. Some segments can degenerate to points. Segments can intersect with each other, be nested in each other or even coincide.
Your task is the following: for every k ∈ [1..n], calculate the number of points with integer coordinates such that the number of segments that cover these points equals k. A segment with endpoints l_i and r_i covers point x if and only if l_i ≤ x ≤ r_i.
Input
The first line of the input contains one integer n (1 ≤ n ≤ 2 ⋅ 10^5) — the number of segments.
The next n lines contain segments. The i-th line contains a pair of integers l_i, r_i (0 ≤ l_i ≤ r_i ≤ 10^{18}) — the endpoints of the i-th segment.
Output
Print n space separated integers cnt_1, cnt_2, ..., cnt_n, where cnt_i is equal to the number of points such that the number of segments that cover these points equals to i.
Examples
Input
3
0 3
1 3
3 8
Output
6 2 1
Input
3
1 3
2 4
5 7
Output
5 2 0
Note
The picture describing the first example:
<image>
Points with coordinates [0, 4, 5, 6, 7, 8] are covered by one segment, points [1, 2] are covered by two segments and point [3] is covered by three segments.
The picture describing the second example:
<image>
Points [1, 4, 5, 6, 7] are covered by one segment, points [2, 3] are covered by two segments and there are no points covered by three segments.
Submitted Solution:
```
from collections import*
n=int(input())
d=defaultdict(int)
#rajatsingh
for _ in [0]*n:
l,r=map(int,input().split());d[l]+=1;d[r+1]-=1
s=p=0
f=[0]*(n+1)
for k in sorted(d):
f[s]+=k-p;s+=d[k];p=k
print(*f[1:])
``` | instruction | 0 | 45,386 | 23 | 90,772 |
Yes | output | 1 | 45,386 | 23 | 90,773 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
You are given n segments on a coordinate line; each endpoint of every segment has integer coordinates. Some segments can degenerate to points. Segments can intersect with each other, be nested in each other or even coincide.
Your task is the following: for every k ∈ [1..n], calculate the number of points with integer coordinates such that the number of segments that cover these points equals k. A segment with endpoints l_i and r_i covers point x if and only if l_i ≤ x ≤ r_i.
Input
The first line of the input contains one integer n (1 ≤ n ≤ 2 ⋅ 10^5) — the number of segments.
The next n lines contain segments. The i-th line contains a pair of integers l_i, r_i (0 ≤ l_i ≤ r_i ≤ 10^{18}) — the endpoints of the i-th segment.
Output
Print n space separated integers cnt_1, cnt_2, ..., cnt_n, where cnt_i is equal to the number of points such that the number of segments that cover these points equals to i.
Examples
Input
3
0 3
1 3
3 8
Output
6 2 1
Input
3
1 3
2 4
5 7
Output
5 2 0
Note
The picture describing the first example:
<image>
Points with coordinates [0, 4, 5, 6, 7, 8] are covered by one segment, points [1, 2] are covered by two segments and point [3] is covered by three segments.
The picture describing the second example:
<image>
Points [1, 4, 5, 6, 7] are covered by one segment, points [2, 3] are covered by two segments and there are no points covered by three segments.
Submitted Solution:
```
import sys
n = int(sys.stdin.readline())
start = dict()
end = dict()
for i in range(n):
b, c = (int(s) for s in sys.stdin.readline().rstrip().split(' '))
start[b] = start.setdefault(b, 0) + 1
start.setdefault(c, 0)
end[c] = end.setdefault(c, 0) + 1
end.setdefault(b, 0)
keys = sorted(start.keys())
k = 0
a = [0 for x in range(n+1)]
prev = -1
start_c = 0
end_c = 0
for key in keys:
if prev != -1 and key - prev > 1:
a[start_c - end_c] += key - prev - 1
start_c += start[key]
a[start_c - end_c] += 1
end_c += end[key]
prev = key
print(' '.join(str(x) for x in a[1:n+1]))
``` | instruction | 0 | 45,387 | 23 | 90,774 |
Yes | output | 1 | 45,387 | 23 | 90,775 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
You are given n segments on a coordinate line; each endpoint of every segment has integer coordinates. Some segments can degenerate to points. Segments can intersect with each other, be nested in each other or even coincide.
Your task is the following: for every k ∈ [1..n], calculate the number of points with integer coordinates such that the number of segments that cover these points equals k. A segment with endpoints l_i and r_i covers point x if and only if l_i ≤ x ≤ r_i.
Input
The first line of the input contains one integer n (1 ≤ n ≤ 2 ⋅ 10^5) — the number of segments.
The next n lines contain segments. The i-th line contains a pair of integers l_i, r_i (0 ≤ l_i ≤ r_i ≤ 10^{18}) — the endpoints of the i-th segment.
Output
Print n space separated integers cnt_1, cnt_2, ..., cnt_n, where cnt_i is equal to the number of points such that the number of segments that cover these points equals to i.
Examples
Input
3
0 3
1 3
3 8
Output
6 2 1
Input
3
1 3
2 4
5 7
Output
5 2 0
Note
The picture describing the first example:
<image>
Points with coordinates [0, 4, 5, 6, 7, 8] are covered by one segment, points [1, 2] are covered by two segments and point [3] is covered by three segments.
The picture describing the second example:
<image>
Points [1, 4, 5, 6, 7] are covered by one segment, points [2, 3] are covered by two segments and there are no points covered by three segments.
Submitted Solution:
```
n = int(input())
points = set()
starts = {}
ends = {}
for i in range(n):
a, b = map(int, input().split())
points.add(a)
points.add(b)
starts[a] = 1 + starts.get(a, 0)
ends[b] = 1 + ends.get(b, 0)
spoints = sorted(points)
dwd = {}
prev_point = spoints[0]
density = 0
for i, cur_point in enumerate(spoints):
interval_length = cur_point - prev_point - 1
if interval_length > 0:
dwd[density] = interval_length + dwd.get(density, 0)
starts_here = starts.get(cur_point, 0)
density += starts_here
dwd[density] = 1 + dwd.get(density, 0)
ends_here = ends.get(cur_point, 0)
density -= ends_here
prev_point = cur_point
for i in range(1, n + 1):
print(dwd.get(i, 0), end=' ')
``` | instruction | 0 | 45,388 | 23 | 90,776 |
Yes | output | 1 | 45,388 | 23 | 90,777 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
You are given n segments on a coordinate line; each endpoint of every segment has integer coordinates. Some segments can degenerate to points. Segments can intersect with each other, be nested in each other or even coincide.
Your task is the following: for every k ∈ [1..n], calculate the number of points with integer coordinates such that the number of segments that cover these points equals k. A segment with endpoints l_i and r_i covers point x if and only if l_i ≤ x ≤ r_i.
Input
The first line of the input contains one integer n (1 ≤ n ≤ 2 ⋅ 10^5) — the number of segments.
The next n lines contain segments. The i-th line contains a pair of integers l_i, r_i (0 ≤ l_i ≤ r_i ≤ 10^{18}) — the endpoints of the i-th segment.
Output
Print n space separated integers cnt_1, cnt_2, ..., cnt_n, where cnt_i is equal to the number of points such that the number of segments that cover these points equals to i.
Examples
Input
3
0 3
1 3
3 8
Output
6 2 1
Input
3
1 3
2 4
5 7
Output
5 2 0
Note
The picture describing the first example:
<image>
Points with coordinates [0, 4, 5, 6, 7, 8] are covered by one segment, points [1, 2] are covered by two segments and point [3] is covered by three segments.
The picture describing the second example:
<image>
Points [1, 4, 5, 6, 7] are covered by one segment, points [2, 3] are covered by two segments and there are no points covered by three segments.
Submitted Solution:
```
from sys import stdin
n = int(stdin.readline())
start = dict()
end = dict()
for i in range(n):
b, c = map(int, stdin.readline().strip().split())
start[b] = start.setdefault(b, 0) + 1
start.setdefault(c, 0)
end[c] = end.setdefault(c, 0) + 1
end.setdefault(b, 0)
keys = sorted(start.keys())
k = 0
a = [0 for x in range(n+1)]
prev = -1
start_c = 0
end_c = 0
for key in keys:
if prev != -1 and key - prev > 1:
a[start_c - end_c] += key - prev - 1
start_c += start[key]
a[start_c - end_c] += 1
end_c += end[key]
prev = key
print(' '.join(str(x) for x in a[1:n+1]))
``` | instruction | 0 | 45,389 | 23 | 90,778 |
Yes | output | 1 | 45,389 | 23 | 90,779 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
You are given n segments on a coordinate line; each endpoint of every segment has integer coordinates. Some segments can degenerate to points. Segments can intersect with each other, be nested in each other or even coincide.
Your task is the following: for every k ∈ [1..n], calculate the number of points with integer coordinates such that the number of segments that cover these points equals k. A segment with endpoints l_i and r_i covers point x if and only if l_i ≤ x ≤ r_i.
Input
The first line of the input contains one integer n (1 ≤ n ≤ 2 ⋅ 10^5) — the number of segments.
The next n lines contain segments. The i-th line contains a pair of integers l_i, r_i (0 ≤ l_i ≤ r_i ≤ 10^{18}) — the endpoints of the i-th segment.
Output
Print n space separated integers cnt_1, cnt_2, ..., cnt_n, where cnt_i is equal to the number of points such that the number of segments that cover these points equals to i.
Examples
Input
3
0 3
1 3
3 8
Output
6 2 1
Input
3
1 3
2 4
5 7
Output
5 2 0
Note
The picture describing the first example:
<image>
Points with coordinates [0, 4, 5, 6, 7, 8] are covered by one segment, points [1, 2] are covered by two segments and point [3] is covered by three segments.
The picture describing the second example:
<image>
Points [1, 4, 5, 6, 7] are covered by one segment, points [2, 3] are covered by two segments and there are no points covered by three segments.
Submitted Solution:
```
import collections
def main():
n = int(input())
mp = dict()
for i in range(n):
s, e = [int(x) for x in input().split()]
if s in mp:
mp[s] += 1
else:
mp[s] = 1
e = e+1
if e in mp:
mp[e] -= 1
else:
mp[e] = -1
mp = collections.OrderedDict(sorted(mp.items()))
ans = [0] * (n+1)
cnt = 0
prev = 0
print(mp.items())
for k, v in mp.items():
if cnt == 0:
prev = k
cnt = v
else:
ans[cnt] += k - prev
print( " ",cnt, ans[cnt])
prev = k
cnt += v
print(cnt, prev)
print(*ans[1:])
if __name__ == "__main__":
main()
``` | instruction | 0 | 45,390 | 23 | 90,780 |
No | output | 1 | 45,390 | 23 | 90,781 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
You are given n segments on a coordinate line; each endpoint of every segment has integer coordinates. Some segments can degenerate to points. Segments can intersect with each other, be nested in each other or even coincide.
Your task is the following: for every k ∈ [1..n], calculate the number of points with integer coordinates such that the number of segments that cover these points equals k. A segment with endpoints l_i and r_i covers point x if and only if l_i ≤ x ≤ r_i.
Input
The first line of the input contains one integer n (1 ≤ n ≤ 2 ⋅ 10^5) — the number of segments.
The next n lines contain segments. The i-th line contains a pair of integers l_i, r_i (0 ≤ l_i ≤ r_i ≤ 10^{18}) — the endpoints of the i-th segment.
Output
Print n space separated integers cnt_1, cnt_2, ..., cnt_n, where cnt_i is equal to the number of points such that the number of segments that cover these points equals to i.
Examples
Input
3
0 3
1 3
3 8
Output
6 2 1
Input
3
1 3
2 4
5 7
Output
5 2 0
Note
The picture describing the first example:
<image>
Points with coordinates [0, 4, 5, 6, 7, 8] are covered by one segment, points [1, 2] are covered by two segments and point [3] is covered by three segments.
The picture describing the second example:
<image>
Points [1, 4, 5, 6, 7] are covered by one segment, points [2, 3] are covered by two segments and there are no points covered by three segments.
Submitted Solution:
```
n = int(input())
a = []
b = []
for _ in range(n):
l, r = list(map(int, input().split()))
a.append([l, r])
b.append(l)
b.append(r + 1)
b = list(set(b))
c = [0 for _ in range(len(b) + 1)]
for seg in a:
lpos = b.index(seg[0])
rpos = b.index(seg[1] + 1)
c[lpos] += 1
c[rpos] -= 1
for i in range(1, len(b)):
c[i] += c[i - 1]
print(b)
print(c)
ans = [0 for _ in range(n + 1)]
for i in range(len(b) - 1):
ans[c[i]] += b[i + 1] - b[i]
print(*ans[1:])
``` | instruction | 0 | 45,391 | 23 | 90,782 |
No | output | 1 | 45,391 | 23 | 90,783 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
You are given n segments on a coordinate line; each endpoint of every segment has integer coordinates. Some segments can degenerate to points. Segments can intersect with each other, be nested in each other or even coincide.
Your task is the following: for every k ∈ [1..n], calculate the number of points with integer coordinates such that the number of segments that cover these points equals k. A segment with endpoints l_i and r_i covers point x if and only if l_i ≤ x ≤ r_i.
Input
The first line of the input contains one integer n (1 ≤ n ≤ 2 ⋅ 10^5) — the number of segments.
The next n lines contain segments. The i-th line contains a pair of integers l_i, r_i (0 ≤ l_i ≤ r_i ≤ 10^{18}) — the endpoints of the i-th segment.
Output
Print n space separated integers cnt_1, cnt_2, ..., cnt_n, where cnt_i is equal to the number of points such that the number of segments that cover these points equals to i.
Examples
Input
3
0 3
1 3
3 8
Output
6 2 1
Input
3
1 3
2 4
5 7
Output
5 2 0
Note
The picture describing the first example:
<image>
Points with coordinates [0, 4, 5, 6, 7, 8] are covered by one segment, points [1, 2] are covered by two segments and point [3] is covered by three segments.
The picture describing the second example:
<image>
Points [1, 4, 5, 6, 7] are covered by one segment, points [2, 3] are covered by two segments and there are no points covered by three segments.
Submitted Solution:
```
if __name__ == '__main__':
N=input()
N=int(N)
lines=[]
for i in range(N):
U,V=input().split()
U=int(U)
V=int(V)
if U <= V:
lines.append([U,V])
else:
lines.append([V,U])
lines=sorted(lines) #sorted initally by starting point and then ending point
#print(lines)
starting_point=-1 #previous line starting point,ending point
ending_point=-1
adding_num=0
answer=[0]*N
for i in range(len(lines)):
#print(lines[i])
sp=lines[i][0] #current line starting point, ending point
ep=lines[i][1]
if i is 0: #Initial line
starting_point=sp
ending_point=ep
adding_num+=1
answer[adding_num-1]+=ep-sp+1
#print(answer)
else:
if sp is starting_point: # Case 1: same starting point as last line
if ep > ending_point : # 1-1: much longer current line
answer[adding_num-1]-=ending_point-starting_point+1
adding_num+=1
answer[adding_num-1]+=ending_point-starting_point+1
adding_num=1
answer[adding_num-1]+=ep-sp+1-(ending_point-starting_point+1)
starting_point=sp
ending_point=ep
#print("1-1",answer)
else: #1-2: same line
answer[adding_num-1]-=ending_point-starting_point+1
adding_num+=1
answer[adding_num-1]+=ending_point-starting_point+1
starting_point=sp
ending_point=ep
#print("1-2",answer)
elif sp <=ending_point: #Case 2: Current line starting point is bigger than last one
if ep > ending_point : #2-1:partially overlapping
answer[adding_num-1]-=ending_point-sp+1
adding_num+=1
answer[adding_num-1]+=ending_point-sp+1
adding_num=1
answer[adding_num-1]+=ep-sp+1-(ending_point-sp+1)
starting_point=sp
ending_point=ep
#print("2-1",answer)
else: #2-2:same ending point, or completely overlapped
answer[adding_num-1]-=ep-sp+1
adding_num+=1
answer[adding_num-1]+=ep-sp+1
starting_point=sp
#print("2-2",answer)
else: #case3:no overlapping
adding_num=1
answer[adding_num-1]+=ep-sp+1
starting_point=sp
ending_point=ep
#print("3",answer)
print(' '.join(str(x) for x in answer))
``` | instruction | 0 | 45,392 | 23 | 90,784 |
No | output | 1 | 45,392 | 23 | 90,785 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
You are given n segments on a coordinate line; each endpoint of every segment has integer coordinates. Some segments can degenerate to points. Segments can intersect with each other, be nested in each other or even coincide.
Your task is the following: for every k ∈ [1..n], calculate the number of points with integer coordinates such that the number of segments that cover these points equals k. A segment with endpoints l_i and r_i covers point x if and only if l_i ≤ x ≤ r_i.
Input
The first line of the input contains one integer n (1 ≤ n ≤ 2 ⋅ 10^5) — the number of segments.
The next n lines contain segments. The i-th line contains a pair of integers l_i, r_i (0 ≤ l_i ≤ r_i ≤ 10^{18}) — the endpoints of the i-th segment.
Output
Print n space separated integers cnt_1, cnt_2, ..., cnt_n, where cnt_i is equal to the number of points such that the number of segments that cover these points equals to i.
Examples
Input
3
0 3
1 3
3 8
Output
6 2 1
Input
3
1 3
2 4
5 7
Output
5 2 0
Note
The picture describing the first example:
<image>
Points with coordinates [0, 4, 5, 6, 7, 8] are covered by one segment, points [1, 2] are covered by two segments and point [3] is covered by three segments.
The picture describing the second example:
<image>
Points [1, 4, 5, 6, 7] are covered by one segment, points [2, 3] are covered by two segments and there are no points covered by three segments.
Submitted Solution:
```
import collections
n = int(input())
m = []
for i in range(n):
a,b = map(int,input().split())
for j in range(a,b+1):
m.append(j)
#print(m)
ctr = collections.Counter(m)
#print(ctr)
count = []
l = set(m)
for i in range(len(l)):
count.append(0)
for i in l :
count[ctr[i] - 1] += 1
for i in range(len(count)):
if count[i] > 0:
print(count[i], end = " ")
``` | instruction | 0 | 45,393 | 23 | 90,786 |
No | output | 1 | 45,393 | 23 | 90,787 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
A set of points on a plane is called good, if for any two points at least one of the three conditions is true:
* those two points lie on same horizontal line;
* those two points lie on same vertical line;
* the rectangle, with corners in these two points, contains inside or on its borders at least one point of the set, other than these two. We mean here a rectangle with sides parallel to coordinates' axes, the so-called bounding box of the two points.
You are given a set consisting of n points on a plane. Find any good superset of the given set whose size would not exceed 2·105 points.
Input
The first line contains an integer n (1 ≤ n ≤ 104) — the number of points in the initial set. Next n lines describe the set's points. Each line contains two integers xi and yi ( - 109 ≤ xi, yi ≤ 109) — a corresponding point's coordinates. It is guaranteed that all the points are different.
Output
Print on the first line the number of points m (n ≤ m ≤ 2·105) in a good superset, print on next m lines the points. The absolute value of the points' coordinates should not exceed 109. Note that you should not minimize m, it is enough to find any good superset of the given set, whose size does not exceed 2·105.
All points in the superset should have integer coordinates.
Examples
Input
2
1 1
2 2
Output
3
1 1
2 2
1 2
Submitted Solution:
```
import sys
sys.setrecursionlimit(1000000)
s = set()
def f(l, r):
global spots
if l>=r:
return
mid = int((l+r)//2)
for i in range(r):
s.add((spots[mid][0] , spots[i][1]))
f(1, mid)
f(mid+1 , r)
n = int(input())
spots = []
for i in range(n):
spots.append(tuple(map(int , input().split())))
sorted(spots)
f(0,n)
print(len(s))
for i in s:
print(i[0],i[1])
``` | instruction | 0 | 45,909 | 23 | 91,818 |
No | output | 1 | 45,909 | 23 | 91,819 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
A set of points on a plane is called good, if for any two points at least one of the three conditions is true:
* those two points lie on same horizontal line;
* those two points lie on same vertical line;
* the rectangle, with corners in these two points, contains inside or on its borders at least one point of the set, other than these two. We mean here a rectangle with sides parallel to coordinates' axes, the so-called bounding box of the two points.
You are given a set consisting of n points on a plane. Find any good superset of the given set whose size would not exceed 2·105 points.
Input
The first line contains an integer n (1 ≤ n ≤ 104) — the number of points in the initial set. Next n lines describe the set's points. Each line contains two integers xi and yi ( - 109 ≤ xi, yi ≤ 109) — a corresponding point's coordinates. It is guaranteed that all the points are different.
Output
Print on the first line the number of points m (n ≤ m ≤ 2·105) in a good superset, print on next m lines the points. The absolute value of the points' coordinates should not exceed 109. Note that you should not minimize m, it is enough to find any good superset of the given set, whose size does not exceed 2·105.
All points in the superset should have integer coordinates.
Examples
Input
2
1 1
2 2
Output
3
1 1
2 2
1 2
Submitted Solution:
```
def merge_sort(s, e):
global points
if s == e-1:
ans.append((points[s][0], points[s][1] - 1))
return
if s == e-2:
try:
if points[s][0] != points[e - 1][0] and points[s][1] != points[e - 1][1]:
ans.append((points[s][0], points[e - 1][1]))
except Exception:
print(points)
return
m = (s + e) // 2
merge_sort(s, m + 1)
merge_sort(m + 1, e)
n = int(input())
points = []
for i in range(n):
coord = input().split()
points.append((int(coord[0]), int(coord[1])))
ans = points.copy()
points.sort(key=lambda point: point[1])
merge_sort(0, n)
print(len(ans))
for point in ans:
print(point[0], point[1])
``` | instruction | 0 | 45,910 | 23 | 91,820 |
No | output | 1 | 45,910 | 23 | 91,821 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
A set of points on a plane is called good, if for any two points at least one of the three conditions is true:
* those two points lie on same horizontal line;
* those two points lie on same vertical line;
* the rectangle, with corners in these two points, contains inside or on its borders at least one point of the set, other than these two. We mean here a rectangle with sides parallel to coordinates' axes, the so-called bounding box of the two points.
You are given a set consisting of n points on a plane. Find any good superset of the given set whose size would not exceed 2·105 points.
Input
The first line contains an integer n (1 ≤ n ≤ 104) — the number of points in the initial set. Next n lines describe the set's points. Each line contains two integers xi and yi ( - 109 ≤ xi, yi ≤ 109) — a corresponding point's coordinates. It is guaranteed that all the points are different.
Output
Print on the first line the number of points m (n ≤ m ≤ 2·105) in a good superset, print on next m lines the points. The absolute value of the points' coordinates should not exceed 109. Note that you should not minimize m, it is enough to find any good superset of the given set, whose size does not exceed 2·105.
All points in the superset should have integer coordinates.
Examples
Input
2
1 1
2 2
Output
3
1 1
2 2
1 2
Submitted Solution:
```
n = int(input())
l = [list(map(int,input().split())) for i in range(n)]
print((n+n**2)//2)
for i in range(n):
print(l[i][0],' ',l[i][1])
for i in range(n-1):
for j in range(i+1,n):
print(l[i][0],' ',l[j][1])
``` | instruction | 0 | 45,911 | 23 | 91,822 |
No | output | 1 | 45,911 | 23 | 91,823 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
A set of points on a plane is called good, if for any two points at least one of the three conditions is true:
* those two points lie on same horizontal line;
* those two points lie on same vertical line;
* the rectangle, with corners in these two points, contains inside or on its borders at least one point of the set, other than these two. We mean here a rectangle with sides parallel to coordinates' axes, the so-called bounding box of the two points.
You are given a set consisting of n points on a plane. Find any good superset of the given set whose size would not exceed 2·105 points.
Input
The first line contains an integer n (1 ≤ n ≤ 104) — the number of points in the initial set. Next n lines describe the set's points. Each line contains two integers xi and yi ( - 109 ≤ xi, yi ≤ 109) — a corresponding point's coordinates. It is guaranteed that all the points are different.
Output
Print on the first line the number of points m (n ≤ m ≤ 2·105) in a good superset, print on next m lines the points. The absolute value of the points' coordinates should not exceed 109. Note that you should not minimize m, it is enough to find any good superset of the given set, whose size does not exceed 2·105.
All points in the superset should have integer coordinates.
Examples
Input
2
1 1
2 2
Output
3
1 1
2 2
1 2
Submitted Solution:
```
n = int(input())
l = [list(map(int,input().split())) for i in range(n)]
for i in range(n-1):
for j in range(i+1,n):
if not(l[i][0]==l[j][0] or l[i][1]==l[j][1]):
l.append([l[i][0],l[j][1]])
print(len(l))
for i in l:
print(i[0],i[1])
``` | instruction | 0 | 45,912 | 23 | 91,824 |
No | output | 1 | 45,912 | 23 | 91,825 |
Provide a correct Python 3 solution for this coding contest problem.
There are a total of n x n squares, n rows vertically and n columns horizontally. Some squares are marked. Create a program that reads the marked state of each square and displays the length of the side of the largest square consisting of only the unmarked squares as an output.
For example, each dataset is given the following data:
Ten
... * .... **
..........
** .... ** ..
........ *.
.. * .......
..........
. * ........
..........
.... * .. ***
. * .... * ...
One line of input data represents the square of one line. Of the character strings in the input data,. (Period) indicates unmarked squares, and * (asterisk) indicates marked squares.
In the above example, the square indicated by 0 in the figure below is the largest.
... * .... **
..........
** .... ** ..
... 00000 *.
.. * 00000 ..
... 00000 ..
. * .00000 ..
... 00000 ..
.... * .. ***
. * .... * ...
Therefore, if you output 5, the answer will be correct.
If all the squares are marked, output 0.
Input
Multiple datasets are given in the above format. When n is 0, it is the last input. n is 1000 or less. The input data string does not contain any characters other than periods, asterisks, and line breaks. The number of datasets does not exceed 50.
Output
For each dataset, output the length (integer) of the side of the largest square on one line.
Example
Input
10
...*....**
..........
**....**..
........*.
..*.......
..........
.*........
..........
....*..***
.*....*...
10
****.*****
*..*.*....
****.*....
*....*....
*....*****
..........
****.*****
*..*...*..
****...*..
*..*...*..
0
Output
5
3 | instruction | 0 | 46,089 | 23 | 92,178 |
"Correct Solution:
```
import sys
while True:
N = int(sys.stdin.readline().rstrip())
if N == 0:
break;
max_value = 0
prev_row = [0] * (N+1)
for i in range(N):
row = sys.stdin.readline().rstrip()
curr_row = [0] * (N+1)
for x,d in enumerate(row,1):
if d == '.':
curr_row[x] = min(prev_row[x-1], prev_row[x], curr_row[x-1]) + 1
max_value = max(max(curr_row), max_value)
prev_row = curr_row
print(max_value)
``` | output | 1 | 46,089 | 23 | 92,179 |
Provide a correct Python 3 solution for this coding contest problem.
There are a total of n x n squares, n rows vertically and n columns horizontally. Some squares are marked. Create a program that reads the marked state of each square and displays the length of the side of the largest square consisting of only the unmarked squares as an output.
For example, each dataset is given the following data:
Ten
... * .... **
..........
** .... ** ..
........ *.
.. * .......
..........
. * ........
..........
.... * .. ***
. * .... * ...
One line of input data represents the square of one line. Of the character strings in the input data,. (Period) indicates unmarked squares, and * (asterisk) indicates marked squares.
In the above example, the square indicated by 0 in the figure below is the largest.
... * .... **
..........
** .... ** ..
... 00000 *.
.. * 00000 ..
... 00000 ..
. * .00000 ..
... 00000 ..
.... * .. ***
. * .... * ...
Therefore, if you output 5, the answer will be correct.
If all the squares are marked, output 0.
Input
Multiple datasets are given in the above format. When n is 0, it is the last input. n is 1000 or less. The input data string does not contain any characters other than periods, asterisks, and line breaks. The number of datasets does not exceed 50.
Output
For each dataset, output the length (integer) of the side of the largest square on one line.
Example
Input
10
...*....**
..........
**....**..
........*.
..*.......
..........
.*........
..........
....*..***
.*....*...
10
****.*****
*..*.*....
****.*....
*....*....
*....*****
..........
****.*****
*..*...*..
****...*..
*..*...*..
0
Output
5
3 | instruction | 0 | 46,090 | 23 | 92,180 |
"Correct Solution:
```
while True:
n = int(input())
if n == 0:
break
inp = []
for i in range(n):
inp.append(list(input()))
sq_max = [[0 for i in range(n + 1)] for j in range(n + 1)]
for y in range(n):
for x in range(n):
if inp[y][x] == ".":
sq_max[y + 1][x + 1] = min(sq_max[y][x + 1], sq_max[y + 1][x], sq_max[y][x]) + 1
else:
sq_max[y + 1][x + 1] = 0
ans = max(map(max, sq_max))
print(ans)
``` | output | 1 | 46,090 | 23 | 92,181 |
Provide a correct Python 3 solution for this coding contest problem.
There are a total of n x n squares, n rows vertically and n columns horizontally. Some squares are marked. Create a program that reads the marked state of each square and displays the length of the side of the largest square consisting of only the unmarked squares as an output.
For example, each dataset is given the following data:
Ten
... * .... **
..........
** .... ** ..
........ *.
.. * .......
..........
. * ........
..........
.... * .. ***
. * .... * ...
One line of input data represents the square of one line. Of the character strings in the input data,. (Period) indicates unmarked squares, and * (asterisk) indicates marked squares.
In the above example, the square indicated by 0 in the figure below is the largest.
... * .... **
..........
** .... ** ..
... 00000 *.
.. * 00000 ..
... 00000 ..
. * .00000 ..
... 00000 ..
.... * .. ***
. * .... * ...
Therefore, if you output 5, the answer will be correct.
If all the squares are marked, output 0.
Input
Multiple datasets are given in the above format. When n is 0, it is the last input. n is 1000 or less. The input data string does not contain any characters other than periods, asterisks, and line breaks. The number of datasets does not exceed 50.
Output
For each dataset, output the length (integer) of the side of the largest square on one line.
Example
Input
10
...*....**
..........
**....**..
........*.
..*.......
..........
.*........
..........
....*..***
.*....*...
10
****.*****
*..*.*....
****.*....
*....*....
*....*****
..........
****.*****
*..*...*..
****...*..
*..*...*..
0
Output
5
3 | instruction | 0 | 46,091 | 23 | 92,182 |
"Correct Solution:
```
# -*- coding: utf-8 -*-
"""
http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=0092
"""
import sys
def find_square0(data):
max_size = 0
lmap = [] # dp??¨???2?¬??????????
# '.'????????????0??????'*'????????????1????????????
for row in data:
temp = []
for c in row:
if c == '.':
temp.append(1)
else:
temp.append(0)
lmap.append(temp)
# ????±?????????????????????????????????£????????????????????£?????¢????¢??????§??????????????§????????????
for y in range(1, len(lmap)):
for x in range(1, len(lmap[0])):
if lmap[y][x] == 1:
lmap[y][x] = min(lmap[y-1][x-1], min(lmap[y-1][x], lmap[y][x-1])) + 1
if lmap[y][x] > max_size:
max_size = lmap[y][x]
return max_size
def find_square(data):
max_size = 0
lmap = []
for row in data:
temp = []
for c in row:
if c == '.':
temp.append(1)
else:
temp.append(0)
lmap.append(temp)
prev_row = lmap[0]
for curr_row in lmap[1:]:
for x in range(1, len(lmap[0])):
if curr_row[x] == 1:
if prev_row[x-1] != 0 and prev_row[x] != 0 and curr_row[x-1] != 0: # ???????????¶?????????
curr_row[x] = min(prev_row[x-1], min(prev_row[x], curr_row[x-1])) + 1
if curr_row[x] > max_size:
max_size = curr_row[x]
prev_row = curr_row
return max_size
def find_square2(data):
max_size = 0
lmap = [] # dp??¨???2?¬??????????
# '.'????????????0??????'*'????????????1????????????
for row in data:
temp = []
for c in row:
if c == '.':
temp.append(1)
else:
temp.append(0)
lmap.append(temp)
# ????±?????????????????????????????????£????????????????????£?????¢????¢??????§??????????????§????????????
# (?????¨???(curr_row)??¨???????????????(prev_row)????????¢????????????????????§?????????????????????)
prev_row = lmap[0]
for curr_row in lmap[1:]:
for x, t in enumerate(curr_row[1:], start=1):
if t == 1:
curr_row[x] = min(prev_row[x-1], min(prev_row[x], curr_row[x-1])) + 1
if curr_row[x] > max_size:
max_size = curr_row[x]
prev_row = curr_row
return max_size
def find_square3(data):
from array import array
max_size = 0
lmap = [array('I', [0]*len(data[0])) for _ in range(len(data))]
# '.'????????????0??????'*'????????????1????????????
for y, row in enumerate(data):
for x, c in enumerate(row):
if c == '.':
lmap[y][x] = 1
# ????±?????????????????????????????????£????????????????????£?????¢????¢??????§??????????????§????????????
# (?????¨???(curr_row)??¨???????????????(prev_row)????????¢????????????????????§?????????????????????)
prev_row = lmap[0]
for curr_row in lmap[1:]:
for x, t in enumerate(curr_row[1:], start=1):
if t == 1:
curr_row[x] = min(prev_row[x-1], min(prev_row[x], curr_row[x-1])) + 1
if curr_row[x] > max_size:
max_size = curr_row[x]
prev_row = curr_row
return max_size
def main(args):
while True:
n = int(input())
if n == 0:
break
data = [input() for _ in range(n)]
result = find_square3(data)
print(result)
if __name__ == '__main__':
main(sys.argv[1:])
``` | output | 1 | 46,091 | 23 | 92,183 |
Provide a correct Python 3 solution for this coding contest problem.
There are a total of n x n squares, n rows vertically and n columns horizontally. Some squares are marked. Create a program that reads the marked state of each square and displays the length of the side of the largest square consisting of only the unmarked squares as an output.
For example, each dataset is given the following data:
Ten
... * .... **
..........
** .... ** ..
........ *.
.. * .......
..........
. * ........
..........
.... * .. ***
. * .... * ...
One line of input data represents the square of one line. Of the character strings in the input data,. (Period) indicates unmarked squares, and * (asterisk) indicates marked squares.
In the above example, the square indicated by 0 in the figure below is the largest.
... * .... **
..........
** .... ** ..
... 00000 *.
.. * 00000 ..
... 00000 ..
. * .00000 ..
... 00000 ..
.... * .. ***
. * .... * ...
Therefore, if you output 5, the answer will be correct.
If all the squares are marked, output 0.
Input
Multiple datasets are given in the above format. When n is 0, it is the last input. n is 1000 or less. The input data string does not contain any characters other than periods, asterisks, and line breaks. The number of datasets does not exceed 50.
Output
For each dataset, output the length (integer) of the side of the largest square on one line.
Example
Input
10
...*....**
..........
**....**..
........*.
..*.......
..........
.*........
..........
....*..***
.*....*...
10
****.*****
*..*.*....
****.*....
*....*....
*....*****
..........
****.*****
*..*...*..
****...*..
*..*...*..
0
Output
5
3 | instruction | 0 | 46,092 | 23 | 92,184 |
"Correct Solution:
```
while True:
Sei = []
m_si = 0
n = int(input())
if n == 0:
break
for i in range(n):
sen = input()
Sei.append(list(sen))
DP = [[0] * n for i in range(n)]
for j in range(n):
if Sei[0][j] == ".":
DP[0][j] = 1
else:
DP[0][j] = 0
for k in range(n):
if Sei[k][0] == ".":
DP[k][0] = 1
else:
DP[k][0] = 0
for k in range(1,n):
for l in range(1,n):
if Sei[k][l] == ".":
DP[k][l] = min(DP[k - 1][l],DP[k][l - 1],DP[k -1][l - 1]) + 1
else:
DP[k][l] = 0
for i in range(n):
if max(DP[i]) > m_si:
m_si = max(DP[i])
print(m_si)
``` | output | 1 | 46,092 | 23 | 92,185 |
Provide a correct Python 3 solution for this coding contest problem.
There are a total of n x n squares, n rows vertically and n columns horizontally. Some squares are marked. Create a program that reads the marked state of each square and displays the length of the side of the largest square consisting of only the unmarked squares as an output.
For example, each dataset is given the following data:
Ten
... * .... **
..........
** .... ** ..
........ *.
.. * .......
..........
. * ........
..........
.... * .. ***
. * .... * ...
One line of input data represents the square of one line. Of the character strings in the input data,. (Period) indicates unmarked squares, and * (asterisk) indicates marked squares.
In the above example, the square indicated by 0 in the figure below is the largest.
... * .... **
..........
** .... ** ..
... 00000 *.
.. * 00000 ..
... 00000 ..
. * .00000 ..
... 00000 ..
.... * .. ***
. * .... * ...
Therefore, if you output 5, the answer will be correct.
If all the squares are marked, output 0.
Input
Multiple datasets are given in the above format. When n is 0, it is the last input. n is 1000 or less. The input data string does not contain any characters other than periods, asterisks, and line breaks. The number of datasets does not exceed 50.
Output
For each dataset, output the length (integer) of the side of the largest square on one line.
Example
Input
10
...*....**
..........
**....**..
........*.
..*.......
..........
.*........
..........
....*..***
.*....*...
10
****.*****
*..*.*....
****.*....
*....*....
*....*****
..........
****.*****
*..*...*..
****...*..
*..*...*..
0
Output
5
3 | instruction | 0 | 46,093 | 23 | 92,186 |
"Correct Solution:
```
# don't know good 参考:http://judge.u-aizu.ac.jp/onlinejudge/review.jsp?rid=2954794#1
table = [''] * 1002
dp = [[0] * 1002 for i in range(1002)]
while 1:
n = int(input())
if n == 0: break
for r in range(n): table[r] = input()
ans = 0
for r in range(n):
for c in range(n):
if table[r][c] == '*': dp[r][c] = 0
else :
t = dp[r-1][c-1]
if dp[r ][c-1] < t: t = dp[r ][c-1];
if dp[r-1][c ] < t: t = dp[r-1][c ];
t += 1
dp[r][c] = t
if t > ans: ans = t
print(ans)
``` | output | 1 | 46,093 | 23 | 92,187 |
Provide a correct Python 3 solution for this coding contest problem.
There are a total of n x n squares, n rows vertically and n columns horizontally. Some squares are marked. Create a program that reads the marked state of each square and displays the length of the side of the largest square consisting of only the unmarked squares as an output.
For example, each dataset is given the following data:
Ten
... * .... **
..........
** .... ** ..
........ *.
.. * .......
..........
. * ........
..........
.... * .. ***
. * .... * ...
One line of input data represents the square of one line. Of the character strings in the input data,. (Period) indicates unmarked squares, and * (asterisk) indicates marked squares.
In the above example, the square indicated by 0 in the figure below is the largest.
... * .... **
..........
** .... ** ..
... 00000 *.
.. * 00000 ..
... 00000 ..
. * .00000 ..
... 00000 ..
.... * .. ***
. * .... * ...
Therefore, if you output 5, the answer will be correct.
If all the squares are marked, output 0.
Input
Multiple datasets are given in the above format. When n is 0, it is the last input. n is 1000 or less. The input data string does not contain any characters other than periods, asterisks, and line breaks. The number of datasets does not exceed 50.
Output
For each dataset, output the length (integer) of the side of the largest square on one line.
Example
Input
10
...*....**
..........
**....**..
........*.
..*.......
..........
.*........
..........
....*..***
.*....*...
10
****.*****
*..*.*....
****.*....
*....*....
*....*****
..........
****.*****
*..*...*..
****...*..
*..*...*..
0
Output
5
3 | instruction | 0 | 46,094 | 23 | 92,188 |
"Correct Solution:
```
# -*- coding: utf-8 -*-
"""
http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=0092
"""
import sys
def find_square(data):
max_size = 0
lmap = []
for row in data:
temp = []
for c in row:
if c == '.':
temp.append(1)
else:
temp.append(0)
lmap.append(temp)
prev_row = lmap[0]
for curr_row in lmap[1:]:
for x in range(1, len(lmap[0])):
if curr_row[x] == 1:
if prev_row[x-1] != 0 and prev_row[x] != 0 and curr_row[x-1] != 0:
curr_row[x] = min(prev_row[x-1], min(prev_row[x], curr_row[x-1])) + 1
if curr_row[x] > max_size:
max_size = curr_row[x]
prev_row = curr_row
return max_size
def find_square2(data):
max_size = 0
lmap = []
for row in data:
temp = []
for c in row:
if c == '.':
temp.append(1)
else:
temp.append(0)
lmap.append(temp)
prev_row = lmap[0]
for curr_row in lmap[1:]:
for x, t in enumerate(curr_row[1:], start=1):
if t == 1:
curr_row[x] = min(prev_row[x-1], min(prev_row[x], curr_row[x-1])) + 1
if curr_row[x] > max_size:
max_size = curr_row[x]
prev_row = curr_row
return max_size
def main(args):
while True:
n = int(input())
if n == 0:
break
data = [input() for _ in range(n)]
result = find_square2(data)
print(result)
if __name__ == '__main__':
main(sys.argv[1:])
``` | output | 1 | 46,094 | 23 | 92,189 |
Provide a correct Python 3 solution for this coding contest problem.
There are a total of n x n squares, n rows vertically and n columns horizontally. Some squares are marked. Create a program that reads the marked state of each square and displays the length of the side of the largest square consisting of only the unmarked squares as an output.
For example, each dataset is given the following data:
Ten
... * .... **
..........
** .... ** ..
........ *.
.. * .......
..........
. * ........
..........
.... * .. ***
. * .... * ...
One line of input data represents the square of one line. Of the character strings in the input data,. (Period) indicates unmarked squares, and * (asterisk) indicates marked squares.
In the above example, the square indicated by 0 in the figure below is the largest.
... * .... **
..........
** .... ** ..
... 00000 *.
.. * 00000 ..
... 00000 ..
. * .00000 ..
... 00000 ..
.... * .. ***
. * .... * ...
Therefore, if you output 5, the answer will be correct.
If all the squares are marked, output 0.
Input
Multiple datasets are given in the above format. When n is 0, it is the last input. n is 1000 or less. The input data string does not contain any characters other than periods, asterisks, and line breaks. The number of datasets does not exceed 50.
Output
For each dataset, output the length (integer) of the side of the largest square on one line.
Example
Input
10
...*....**
..........
**....**..
........*.
..*.......
..........
.*........
..........
....*..***
.*....*...
10
****.*****
*..*.*....
****.*....
*....*....
*....*****
..........
****.*****
*..*...*..
****...*..
*..*...*..
0
Output
5
3 | instruction | 0 | 46,095 | 23 | 92,190 |
"Correct Solution:
```
# AOJ 0092 Square Searching
# Python3 2018.6.21 bal4u
cin = [[''] for r in range(1002)]
dp = [[0 for c in range(1002)] for r in range(1002)]
while 1:
n = int(input())
if n == 0: break
for r in range(n): cin[r] = input()
ans = 0
for r in range(n):
for c in range(n):
if cin[r][c] == '*': dp[r][c] = 0
else :
t = 1+min(dp[r-1][c-1], dp[r][c-1], dp[r-1][c])
dp[r][c] = t
if t > ans: ans = t
print(ans)
``` | output | 1 | 46,095 | 23 | 92,191 |
Provide a correct Python 3 solution for this coding contest problem.
There are a total of n x n squares, n rows vertically and n columns horizontally. Some squares are marked. Create a program that reads the marked state of each square and displays the length of the side of the largest square consisting of only the unmarked squares as an output.
For example, each dataset is given the following data:
Ten
... * .... **
..........
** .... ** ..
........ *.
.. * .......
..........
. * ........
..........
.... * .. ***
. * .... * ...
One line of input data represents the square of one line. Of the character strings in the input data,. (Period) indicates unmarked squares, and * (asterisk) indicates marked squares.
In the above example, the square indicated by 0 in the figure below is the largest.
... * .... **
..........
** .... ** ..
... 00000 *.
.. * 00000 ..
... 00000 ..
. * .00000 ..
... 00000 ..
.... * .. ***
. * .... * ...
Therefore, if you output 5, the answer will be correct.
If all the squares are marked, output 0.
Input
Multiple datasets are given in the above format. When n is 0, it is the last input. n is 1000 or less. The input data string does not contain any characters other than periods, asterisks, and line breaks. The number of datasets does not exceed 50.
Output
For each dataset, output the length (integer) of the side of the largest square on one line.
Example
Input
10
...*....**
..........
**....**..
........*.
..*.......
..........
.*........
..........
....*..***
.*....*...
10
****.*****
*..*.*....
****.*....
*....*....
*....*****
..........
****.*****
*..*...*..
****...*..
*..*...*..
0
Output
5
3 | instruction | 0 | 46,096 | 23 | 92,192 |
"Correct Solution:
```
# AOJ 0092 Square Searching
# Python3 2018.6.21 bal4u
cin = [['' for c in range(1002)] for r in range(1002)]
dp = [[0 for c in range(1002)] for r in range(1002)]
while 1:
n = int(input())
if n == 0: break
for r in range(n):
cin[r] = list(input())
ans = 0
for r in range(n):
for c in range(n):
if cin[r][c] == '*': dp[r][c] = 0
else :
t = dp[r-1][c-1]
if t > 0 and dp[r ][c-1] < t: t = dp[r ][c-1];
if t > 0 and dp[r-1][c ] < t: t = dp[r-1][c ];
t += 1
dp[r][c] = t
if t > ans: ans = t
print(ans)
``` | output | 1 | 46,096 | 23 | 92,193 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
There are a total of n x n squares, n rows vertically and n columns horizontally. Some squares are marked. Create a program that reads the marked state of each square and displays the length of the side of the largest square consisting of only the unmarked squares as an output.
For example, each dataset is given the following data:
Ten
... * .... **
..........
** .... ** ..
........ *.
.. * .......
..........
. * ........
..........
.... * .. ***
. * .... * ...
One line of input data represents the square of one line. Of the character strings in the input data,. (Period) indicates unmarked squares, and * (asterisk) indicates marked squares.
In the above example, the square indicated by 0 in the figure below is the largest.
... * .... **
..........
** .... ** ..
... 00000 *.
.. * 00000 ..
... 00000 ..
. * .00000 ..
... 00000 ..
.... * .. ***
. * .... * ...
Therefore, if you output 5, the answer will be correct.
If all the squares are marked, output 0.
Input
Multiple datasets are given in the above format. When n is 0, it is the last input. n is 1000 or less. The input data string does not contain any characters other than periods, asterisks, and line breaks. The number of datasets does not exceed 50.
Output
For each dataset, output the length (integer) of the side of the largest square on one line.
Example
Input
10
...*....**
..........
**....**..
........*.
..*.......
..........
.*........
..........
....*..***
.*....*...
10
****.*****
*..*.*....
****.*....
*....*....
*....*****
..........
****.*****
*..*...*..
****...*..
*..*...*..
0
Output
5
3
Submitted Solution:
```
# -*- coding: utf-8 -*-
"""
http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=0092
"""
import sys
def find_square2(data):
max_size = 0
dp = [[0]*len(data[0]) for _ in range(len(data))] # dp??¨???2?¬??????????
# '.'????????????1??????'*'????????????0????????????
for y, row in enumerate(data):
for x, c in enumerate(row):
if c == '.':
dp[y][x] = 1
max_size = 1
# ????±?????????????????????????????????£????????????????????£?????¢????¢??????§??????????????§????????????
# (?????¨???(curr_row)??¨???????????????(prev_row)????????¢????????????????????§?????????????????????)
prev_row = dp[0]
for curr_row in dp[1:]:
for x, t in enumerate(curr_row[1:], start=1):
if t == 1:
curr_row[x] = min(prev_row[x-1], prev_row[x], curr_row[x-1]) + 1
if curr_row[x] > max_size:
max_size = curr_row[x]
prev_row = curr_row
return max_size
def main(args):
while True:
n = int(input())
if n == 0:
break
data = [input() for _ in range(n)]
result = find_square2(data)
print(result)
if __name__ == '__main__':
main(sys.argv[1:])
``` | instruction | 0 | 46,097 | 23 | 92,194 |
Yes | output | 1 | 46,097 | 23 | 92,195 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
There are a total of n x n squares, n rows vertically and n columns horizontally. Some squares are marked. Create a program that reads the marked state of each square and displays the length of the side of the largest square consisting of only the unmarked squares as an output.
For example, each dataset is given the following data:
Ten
... * .... **
..........
** .... ** ..
........ *.
.. * .......
..........
. * ........
..........
.... * .. ***
. * .... * ...
One line of input data represents the square of one line. Of the character strings in the input data,. (Period) indicates unmarked squares, and * (asterisk) indicates marked squares.
In the above example, the square indicated by 0 in the figure below is the largest.
... * .... **
..........
** .... ** ..
... 00000 *.
.. * 00000 ..
... 00000 ..
. * .00000 ..
... 00000 ..
.... * .. ***
. * .... * ...
Therefore, if you output 5, the answer will be correct.
If all the squares are marked, output 0.
Input
Multiple datasets are given in the above format. When n is 0, it is the last input. n is 1000 or less. The input data string does not contain any characters other than periods, asterisks, and line breaks. The number of datasets does not exceed 50.
Output
For each dataset, output the length (integer) of the side of the largest square on one line.
Example
Input
10
...*....**
..........
**....**..
........*.
..*.......
..........
.*........
..........
....*..***
.*....*...
10
****.*****
*..*.*....
****.*....
*....*....
*....*****
..........
****.*****
*..*...*..
****...*..
*..*...*..
0
Output
5
3
Submitted Solution:
```
while True:
n = int(input())
if not n:
break
mp = []
for _ in range(n):
lst = list(input())
cum = []
acc = 0
for i in lst:
if i == ".":
acc += 1
else:
acc = 0
cum.append(acc)
mp.append(cum)
mp.append([-1] * n)
ans = 0
for i in range(n):
stack = []
for j in range(n + 1):
score = mp[j][i]
if not stack:
stack.append((score, j))
else:
last_score, last_ind = stack[-1][0], stack[-1][1]
if score > last_score:
stack.append((score, j))
elif score == last_score:
continue
else:
while stack != [] and stack[-1][0] >= score:
last_score, last_ind = stack.pop()
ans = max(ans, min(last_score, j - last_ind))
stack.append((score, last_ind))
print(ans)
``` | instruction | 0 | 46,098 | 23 | 92,196 |
Yes | output | 1 | 46,098 | 23 | 92,197 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
There are a total of n x n squares, n rows vertically and n columns horizontally. Some squares are marked. Create a program that reads the marked state of each square and displays the length of the side of the largest square consisting of only the unmarked squares as an output.
For example, each dataset is given the following data:
Ten
... * .... **
..........
** .... ** ..
........ *.
.. * .......
..........
. * ........
..........
.... * .. ***
. * .... * ...
One line of input data represents the square of one line. Of the character strings in the input data,. (Period) indicates unmarked squares, and * (asterisk) indicates marked squares.
In the above example, the square indicated by 0 in the figure below is the largest.
... * .... **
..........
** .... ** ..
... 00000 *.
.. * 00000 ..
... 00000 ..
. * .00000 ..
... 00000 ..
.... * .. ***
. * .... * ...
Therefore, if you output 5, the answer will be correct.
If all the squares are marked, output 0.
Input
Multiple datasets are given in the above format. When n is 0, it is the last input. n is 1000 or less. The input data string does not contain any characters other than periods, asterisks, and line breaks. The number of datasets does not exceed 50.
Output
For each dataset, output the length (integer) of the side of the largest square on one line.
Example
Input
10
...*....**
..........
**....**..
........*.
..*.......
..........
.*........
..........
....*..***
.*....*...
10
****.*****
*..*.*....
****.*....
*....*....
*....*****
..........
****.*****
*..*...*..
****...*..
*..*...*..
0
Output
5
3
Submitted Solution:
```
import sys
readline = sys.stdin.readline
write = sys.stdout.write
def solve():
N = int(readline())
if N == 0:
return False
f = ".*".index
MP = [list(map(f, readline().strip())) for i in range(N)]
D = [[0]*N for i in range(N)]
ds = [0]*N
for i in range(N):
MPi = MP[i]
Di = D[i]
for j in range(N):
if MPi[j]:
ds[j] = 0
else:
ds[j] += 1
Di[j] = ds[j]
ans = 0
def gen():
for i in range(N):
st = []
Di = D[i]
for j in range(N):
c = Di[j]
last = j
while st and st[-1][1] >= c:
k, d = st.pop()
yield min(d, j-k)
last = k
st.append((last, c))
while st:
k, d = st.pop()
yield min(d, N-k)
write("%d\n" % max(gen()))
return True
while solve():
...
``` | instruction | 0 | 46,099 | 23 | 92,198 |
Yes | output | 1 | 46,099 | 23 | 92,199 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.