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.
This is an interactive problem
You are given a grid nΓ n, where n is odd. Rows are enumerated from 1 to n from up to down, columns are enumerated from 1 to n from left to right. Cell, standing on the intersection of row x and column y, is denoted by (x, y).
Every cell contains 0 or 1. It is known that the top-left cell contains 1, and the bottom-right cell contains 0.
We want to know numbers in all cells of the grid. To do so we can ask the following questions:
"? x_1 y_1 x_2 y_2", where 1 β€ x_1 β€ x_2 β€ n, 1 β€ y_1 β€ y_2 β€ n, and x_1 + y_1 + 2 β€ x_2 + y_2. In other words, we output two different cells (x_1, y_1), (x_2, y_2) of the grid such that we can get from the first to the second by moving only to the right and down, and they aren't adjacent.
As a response to such question you will be told if there exists a path between (x_1, y_1) and (x_2, y_2), going only to the right or down, numbers in cells of which form a palindrome.
For example, paths, shown in green, are palindromic, so answer for "? 1 1 2 3" and "? 1 2 3 3" would be that there exists such path. However, there is no palindromic path between (1, 1) and (3, 1).
<image>
Determine all cells of the grid by asking not more than n^2 questions. It can be shown that the answer always exists.
Input
The first line contains odd integer (3 β€ n < 50) β the side of the grid.
Interaction
You begin the interaction by reading n.
To ask a question about cells (x_1, y_1), (x_2, y_2), in a separate line output "? x_1 y_1 x_2 y_2".
Numbers in the query have to satisfy 1 β€ x_1 β€ x_2 β€ n, 1 β€ y_1 β€ y_2 β€ n, and x_1 + y_1 + 2 β€ x_2 + y_2. Don't forget to 'flush', to get the answer.
In response, you will receive 1, if there exists a path going from (x_1, y_1) to (x_2, y_2) only to the right or down, numbers in cells of which form a palindrome, and 0 otherwise.
In case your query is invalid or you asked more than n^2 queries, program will print -1 and will finish interaction. You will receive Wrong answer verdict. Make sure to exit immediately to avoid getting other verdicts.
When you determine numbers in all cells, output "!".
Then output n lines, the i-th of which is a string of length n, corresponding to numbers in the i-th row of the grid.
After printing a query do not forget to output end of line and flush the output. Otherwise, you will get Idleness limit exceeded. To do this, use:
* fflush(stdout) or cout.flush() in C++;
* System.out.flush() in Java;
* flush(output) in Pascal;
* stdout.flush() in Python;
* see documentation for other languages.
Hack Format
To hack, use the following format.
The first line should contain a single odd integer n (side of your grid).
The i-th of n following lines should contain a string of length n corresponding to the i-th row of the grid. Top left element of the grid has to be equal to 1, bottom right has to be equal to 0.
Example
Input
3
0
1
0
1
1
1
1
Output
? 1 1 1 3
? 1 1 2 3
? 2 1 2 3
? 3 1 3 3
? 2 2 3 3
? 1 2 3 2
? 1 2 3 3
!
100
001
000
Submitted Solution:
```
from sys import stdout
from itertools import product
n = int(input())
grid = [[-1] * n for _ in range(n)]
grid[0][0] = 1
grid[n-1][n-1] = 0
def print_grid():
for i in range(n):
print(''.join(map(str,grid[i])))
def query(i, j, k, l):
print("? %d %d %d %d" % (i+1, j+1, k+1, l+1))
stdout.flush()
return int(input()) == 1
def derive_value(i, j, k, l):
if grid[k][l] != -1:
return
if i < k or j < l:
q = query(i, j, k, l)
else:
q = query(k, l, i, j)
if q:
grid[k][l] = grid[i][j]
else:
grid[k][l] = 1 - grid[i][j]
for i in range(0, n-2, 2):
derive_value(i, 0, i+2, 0)
for i,j in product(range(0, n, 2), range(0, n-2, 2)):
derive_value(i,j,i,j+2)
for i,j in product(range(0, n-2, 2),range(0, n-2, 2)):
derive_value(i,j,i+1,j+1)
for i in range(0,n-2, 2):
if grid[i+2][i+2] == 0:
if query(i,j,i+1,j+2):
grid[i+1][j+2] = 1
l = i+1
m = j+2
elif grid[i+2][j] != grid[i+1][j+1]:
grid[i+1][j+2] = 0
l = i+1
m = j+2
else:
if query(i, j+1, i+2, j+2):
grid[i][j + 1] = 0
l = i
m = j + 1
elif grid[i+1][j+1] == 1:
grid[i + 1][j + 2] = 0
l = i + 1
m = j + 2
else:
grid[i][j + 1] = 1
l = i
m = j + 1
for j in range(m-2, -1, -2):
derive_value(l, j+2, l, j)
for j in range(m, n-2, 2):
derive_value(l, j, l, j+2)
for i in range(l-2, -1, -2):
derive_value(i+2, m%2, i, m%2)
for i in range(l, n-2, 2):
derive_value(i, m%2, i+2, m%2)
derive_value(l%2,m%2, l%2+1, m%2 + 1)
if l%2 == 1:
derive_value(l%2+1,m%2+1,l%2-1,m%2+1)
else:
derive_value(l%2+1,m%2+1,l%2+1,m%2-1)
for j in range(1,n-3,2):
derive_value(0,j,0,j+2)
for j in range(0,n-2,2):
derive_value(1,j,1,j+2)
for i,j in product(range(0,n-2),range(0,n)):
derive_value(i,j,i+2,j)
print('!')
print_grid()
``` | instruction | 0 | 22,109 | 23 | 44,218 |
No | output | 1 | 22,109 | 23 | 44,219 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Drazil created a following problem about putting 1 Γ 2 tiles into an n Γ m grid:
"There is a grid with some cells that are empty and some cells that are occupied. You should use 1 Γ 2 tiles to cover all empty cells and no two tiles should cover each other. And you should print a solution about how to do it."
But Drazil doesn't like to write special checking program for this task. His friend, Varda advised him: "how about asking contestant only to print the solution when it exists and it is unique? Otherwise contestant may print 'Not unique' ".
Drazil found that the constraints for this task may be much larger than for the original task!
Can you solve this new problem?
Note that you should print 'Not unique' either when there exists no solution or when there exists several different solutions for the original task.
Input
The first line contains two integers n and m (1 β€ n, m β€ 2000).
The following n lines describe the grid rows. Character '.' denotes an empty cell, and the character '*' denotes a cell that is occupied.
Output
If there is no solution or the solution is not unique, you should print the string "Not unique".
Otherwise you should print how to cover all empty cells with 1 Γ 2 tiles. Use characters "<>" to denote horizontal tiles and characters "^v" to denote vertical tiles. Refer to the sample test for the output format example.
Examples
Input
3 3
...
.*.
...
Output
Not unique
Input
4 4
..**
*...
*.**
....
Output
<>**
*^<>
*v**
<><>
Input
2 4
*..*
....
Output
*<>*
<><>
Input
1 1
.
Output
Not unique
Input
1 1
*
Output
*
Note
In the first case, there are indeed two solutions:
<>^
^*v
v<>
and
^<>
v*^
<>v
so the answer is "Not unique".
Submitted Solution:
```
pass
pass
pass
pass
pass
pass
pass
pass
pass
pass
pass
pass
pass
pass
pass
pass
pass
print('Not unique')
``` | instruction | 0 | 22,472 | 23 | 44,944 |
No | output | 1 | 22,472 | 23 | 44,945 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Drazil created a following problem about putting 1 Γ 2 tiles into an n Γ m grid:
"There is a grid with some cells that are empty and some cells that are occupied. You should use 1 Γ 2 tiles to cover all empty cells and no two tiles should cover each other. And you should print a solution about how to do it."
But Drazil doesn't like to write special checking program for this task. His friend, Varda advised him: "how about asking contestant only to print the solution when it exists and it is unique? Otherwise contestant may print 'Not unique' ".
Drazil found that the constraints for this task may be much larger than for the original task!
Can you solve this new problem?
Note that you should print 'Not unique' either when there exists no solution or when there exists several different solutions for the original task.
Input
The first line contains two integers n and m (1 β€ n, m β€ 2000).
The following n lines describe the grid rows. Character '.' denotes an empty cell, and the character '*' denotes a cell that is occupied.
Output
If there is no solution or the solution is not unique, you should print the string "Not unique".
Otherwise you should print how to cover all empty cells with 1 Γ 2 tiles. Use characters "<>" to denote horizontal tiles and characters "^v" to denote vertical tiles. Refer to the sample test for the output format example.
Examples
Input
3 3
...
.*.
...
Output
Not unique
Input
4 4
..**
*...
*.**
....
Output
<>**
*^<>
*v**
<><>
Input
2 4
*..*
....
Output
*<>*
<><>
Input
1 1
.
Output
Not unique
Input
1 1
*
Output
*
Note
In the first case, there are indeed two solutions:
<>^
^*v
v<>
and
^<>
v*^
<>v
so the answer is "Not unique".
Submitted Solution:
```
from sys import stdin, gettrace, stdout
# if not gettrace():
# def input():
# return next(stdin)[:-1]
LEFT = ord('<')
RIGHT = ord('>')
TOP = ord('^')
BOTTOM = ord('v')
def input():
return stdin.buffer.readline()
EMPTY = ord('.')
def main():
n,m = map(int, input().split())
grid = bytearray(n*(m+1))
stdin.buffer.readinto(grid)
to_process = []
ecount = 0
adj = [[0]*m for _ in range(n)]
def is_empty(i,j):
return i >= 0 and j >= 0 and i < n and j < m and grid[i*(m+1) + j] == EMPTY
def set_grid(i,j, data):
grid[i*(m+1) + j] = data
def set_adj(i, j):
if is_empty(i,j):
adj[i][j] = 0
count = 0
if is_empty(i - 1, j):
adj[i][j] |= 1
count+=1
if is_empty(i + 1, j):
adj[i][j] |= 2
count += 1
if is_empty(i,j - 1):
adj[i][j] |= 4
count += 1
if is_empty(i, j + 1):
adj[i][j] |= 8
count += 1
if not count:
print("Not unique")
return False
if count == 1:
to_process.append((i, j))
return True
for i in range(n):
for j in range(m):
if not set_adj(i, j):
return
if is_empty(i, j):
ecount+=1
while to_process:
i,j = to_process.pop()
if not is_empty(i,j):
continue
if adj[i][j] == 1:
set_grid(i,j,BOTTOM)
set_grid(i-1,j,TOP)
ecount -= 2
if not set_adj(i-1,j-1):
return
if not set_adj(i-1, j+1):
return
if not set_adj(i-2,j):
return
elif adj[i][j] == 2 :
set_grid(i,j,TOP)
set_grid(i+1,j,BOTTOM)
ecount -= 2
if not set_adj(i+1,j-1):
return
if not set_adj(i+1, j+1):
return
if not set_adj(i+2,j):
return
elif adj[i][j] == 4:
set_grid(i,j,RIGHT)
set_grid(i,j-1,LEFT)
ecount -= 2
if not set_adj(i-1,j-1):
return
if not set_adj(i+1, j-1):
return
if not set_adj(i,j-2):
return
else:
set_grid(i,j,LEFT)
set_grid(i,j + 1,RIGHT)
ecount -= 2
if not set_adj(i - 1, j + 1):
return
if not set_adj(i + 1, j + 1):
return
if not set_adj(i, j + 2):
return
if ecount != 0:
print("Not unique")
return
else:
stdout.buffer.write(grid)
if __name__ == "__main__":
main()
``` | instruction | 0 | 22,473 | 23 | 44,946 |
No | output | 1 | 22,473 | 23 | 44,947 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Drazil created a following problem about putting 1 Γ 2 tiles into an n Γ m grid:
"There is a grid with some cells that are empty and some cells that are occupied. You should use 1 Γ 2 tiles to cover all empty cells and no two tiles should cover each other. And you should print a solution about how to do it."
But Drazil doesn't like to write special checking program for this task. His friend, Varda advised him: "how about asking contestant only to print the solution when it exists and it is unique? Otherwise contestant may print 'Not unique' ".
Drazil found that the constraints for this task may be much larger than for the original task!
Can you solve this new problem?
Note that you should print 'Not unique' either when there exists no solution or when there exists several different solutions for the original task.
Input
The first line contains two integers n and m (1 β€ n, m β€ 2000).
The following n lines describe the grid rows. Character '.' denotes an empty cell, and the character '*' denotes a cell that is occupied.
Output
If there is no solution or the solution is not unique, you should print the string "Not unique".
Otherwise you should print how to cover all empty cells with 1 Γ 2 tiles. Use characters "<>" to denote horizontal tiles and characters "^v" to denote vertical tiles. Refer to the sample test for the output format example.
Examples
Input
3 3
...
.*.
...
Output
Not unique
Input
4 4
..**
*...
*.**
....
Output
<>**
*^<>
*v**
<><>
Input
2 4
*..*
....
Output
*<>*
<><>
Input
1 1
.
Output
Not unique
Input
1 1
*
Output
*
Note
In the first case, there are indeed two solutions:
<>^
^*v
v<>
and
^<>
v*^
<>v
so the answer is "Not unique".
Submitted Solution:
```
from collections import deque
import sys
dx=[1,-1,0,0]
dy=[0,0,1,-1]
def main():
n,m=map(int,input().split())
matrix=[]
answer=[]
degree=[]
for i in range(n):
l=list(input().replace(" ",""))
matrix.append(l)
answer.append(l)
c=[0]*m
degree.append(c)
Solve(n,m,matrix,answer,degree)
# matrix =[[for j in (input().split())] for i in range(n)]
def IsValid(x,y,n,m):
return x>=0 and x<n and y>=0 and y<m
def Solve(n,m,matrix,answer,degree):
q=deque()
for i in range(n):
for j in range(m):
if matrix[i][j]=='.':
for k in range(4):
nx=i+dx[k]
ny=j+dy[k]
if IsValid(nx,ny,n,m) and matrix[nx][ny]=='.':
degree[i][j]+=1
for i in range(n):
for j in range(m):
if degree[i][j]==1 :
q.append((i,j))
while len(q)!=0:
v=q.popleft()
x=v[0]
y=v[1]
for k in range(4):
nx=x+dx[k]
ny=y+dy[k]
if IsValid(nx,ny,n,m) and matrix[nx][ny]=='.':
if k==0:
answer[x][y]='^'
answer[nx][ny]='v'
if k==1:
answer[x][y]='v'
answer[nx][ny]='^'
if k==2:
answer[x][y]='<'
answer[nx][ny]='>'
if k==3:
answer[x][y]='>'
answer[nx][ny]='<'
degree[x][y]=degree[nx][ny]=0
for p in range(4):
nnx=nx+dx[p]
nny=ny+dy[p]
if IsValid(nnx,nny,n,m) and matrix[nnx][nny]=='.':
degree[nnx][nny]-=1
if degree[nnx][nny]==1:
q.append((nnx,nny))
for i in range(n):
for j in range(m):
if answer[i][j]=='.':
print("Not unique")
return
a=""
for i in range(n):
for j in range(m):
a +=str(answer[i][j]+" ")
print(a)
a=""
main()
``` | instruction | 0 | 22,474 | 23 | 44,948 |
No | output | 1 | 22,474 | 23 | 44,949 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Drazil created a following problem about putting 1 Γ 2 tiles into an n Γ m grid:
"There is a grid with some cells that are empty and some cells that are occupied. You should use 1 Γ 2 tiles to cover all empty cells and no two tiles should cover each other. And you should print a solution about how to do it."
But Drazil doesn't like to write special checking program for this task. His friend, Varda advised him: "how about asking contestant only to print the solution when it exists and it is unique? Otherwise contestant may print 'Not unique' ".
Drazil found that the constraints for this task may be much larger than for the original task!
Can you solve this new problem?
Note that you should print 'Not unique' either when there exists no solution or when there exists several different solutions for the original task.
Input
The first line contains two integers n and m (1 β€ n, m β€ 2000).
The following n lines describe the grid rows. Character '.' denotes an empty cell, and the character '*' denotes a cell that is occupied.
Output
If there is no solution or the solution is not unique, you should print the string "Not unique".
Otherwise you should print how to cover all empty cells with 1 Γ 2 tiles. Use characters "<>" to denote horizontal tiles and characters "^v" to denote vertical tiles. Refer to the sample test for the output format example.
Examples
Input
3 3
...
.*.
...
Output
Not unique
Input
4 4
..**
*...
*.**
....
Output
<>**
*^<>
*v**
<><>
Input
2 4
*..*
....
Output
*<>*
<><>
Input
1 1
.
Output
Not unique
Input
1 1
*
Output
*
Note
In the first case, there are indeed two solutions:
<>^
^*v
v<>
and
^<>
v*^
<>v
so the answer is "Not unique".
Submitted Solution:
```
n, m = [int(i) for i in input().split()]
grid = [[j for j in input()] for i in range(n)]
def get_degree(grid, i, j):
n, m = len(grid), len(grid[0])
degree = 0
if i - 1 >= 0 and grid[i - 1][j] == ".": degree += 1
if i + 1 < n and grid[i + 1][j] == ".": degree += 1
if j - 1 >= 0 and grid[i][j - 1] == ".": degree += 1
if j + 1 < m and grid[i][j + 1] == ".": degree += 1
return degree
def get_empty_neighbors(grid, i, j):
n, m = len(grid), len(grid[0])
neighbors = []
if i - 1 >= 0 and grid[i - 1][j] == ".":
neighbors.append((i - 1, j))
if i + 1 < n and grid[i + 1][j] == ".":
neighbors.append((i + 1, j))
if j - 1 >= 0 and grid[i][j - 1] == ".":
neighbors.append((i, j - 1))
if j + 1 < m and grid[i][j + 1] == ".":
neighbors.append((i, j + 1))
return neighbors
vertices = []
for i in range(n):
for j in range(m):
if grid[i][j] == "." and get_degree(grid, i, j) == 1:
vertices.append((i, j))
while vertices:
i, j = vertices.pop()
if i - 1 >= 0 and grid[i - 1][j] == ".":
grid[i - 1][j], grid[i][j] = "<", ">"
for nbr in get_empty_neighbors(i - 1, j):
if get_degree(grid, nbr[0], nbr[1]) == 1:
vertices.append(nbr)
if i + 1 < n and grid[i + 1][j] == ".":
grid[i + 1][j], grid[i][j] = ">", "<"
for nbr in get_empty_neighbors(i + 1, j):
if get_degree(grid, nbr[0], nbr[1]) == 1:
vertices.append(nbr)
if j - 1 >= 0 and grid[i][j - 1] == ".":
grid[i][j - 1], grid[i][j] = "^", "v"
for nbr in get_empty_neighbors(i, j - 1):
if get_degree(grid, nbr[0], nbr[1]) == 1:
vertices.append(nbr)
if j + 1 < m and grid[i][j + 1] == ".":
grid[i][j + 1], grid[i][j] = "v", "^"
for nbr in get_empty_neighbors(i, j + 1):
if get_degree(grid, nbr[0], nbr[1]) == 1:
vertices.append(nbr)
printgrid = True
for i in range(n):
for j in range(m):
if grid[i][j] == ".":
print("Not unique")
printgrid = False
if printgrid:
for i in range(n):
for j in range(m):
print(grid[i][j], end="")
print()
``` | instruction | 0 | 22,475 | 23 | 44,950 |
No | output | 1 | 22,475 | 23 | 44,951 |
Provide a correct Python 3 solution for this coding contest problem.
There is a rectangle in a coordinate plane. The coordinates of the four vertices are (0,0), (W,0), (W,H), and (0,H). You are given a point (x,y) which is within the rectangle or on its border. We will draw a straight line passing through (x,y) to cut the rectangle into two parts. Find the maximum possible area of the part whose area is not larger than that of the other. Additionally, determine if there are multiple ways to cut the rectangle and achieve that maximum.
Constraints
* 1 \leq W,H \leq 10^9
* 0\leq x\leq W
* 0\leq y\leq H
* All values in input are integers.
Input
Input is given from Standard Input in the following format:
W H x y
Output
Print the maximum possible area of the part whose area is not larger than that of the other, followed by `1` if there are multiple ways to cut the rectangle and achieve that maximum, and `0` otherwise.
The area printed will be judged correct when its absolute or relative error is at most 10^{-9}.
Examples
Input
2 3 1 2
Output
3.000000 0
Input
2 2 1 1
Output
2.000000 1 | instruction | 0 | 22,650 | 23 | 45,300 |
"Correct Solution:
```
w,h,x,y=map(int,input().split())
print(w*h/2.0,1 if 2*x==w and 2*y==h else 0)
``` | output | 1 | 22,650 | 23 | 45,301 |
Provide a correct Python 3 solution for this coding contest problem.
There is a rectangle in a coordinate plane. The coordinates of the four vertices are (0,0), (W,0), (W,H), and (0,H). You are given a point (x,y) which is within the rectangle or on its border. We will draw a straight line passing through (x,y) to cut the rectangle into two parts. Find the maximum possible area of the part whose area is not larger than that of the other. Additionally, determine if there are multiple ways to cut the rectangle and achieve that maximum.
Constraints
* 1 \leq W,H \leq 10^9
* 0\leq x\leq W
* 0\leq y\leq H
* All values in input are integers.
Input
Input is given from Standard Input in the following format:
W H x y
Output
Print the maximum possible area of the part whose area is not larger than that of the other, followed by `1` if there are multiple ways to cut the rectangle and achieve that maximum, and `0` otherwise.
The area printed will be judged correct when its absolute or relative error is at most 10^{-9}.
Examples
Input
2 3 1 2
Output
3.000000 0
Input
2 2 1 1
Output
2.000000 1 | instruction | 0 | 22,651 | 23 | 45,302 |
"Correct Solution:
```
w,h,x,y=map(int,input().split())
if w/2==x and h/2==y:k=1
else:k=0
print(w*h/2,k)
``` | output | 1 | 22,651 | 23 | 45,303 |
Provide a correct Python 3 solution for this coding contest problem.
There is a rectangle in a coordinate plane. The coordinates of the four vertices are (0,0), (W,0), (W,H), and (0,H). You are given a point (x,y) which is within the rectangle or on its border. We will draw a straight line passing through (x,y) to cut the rectangle into two parts. Find the maximum possible area of the part whose area is not larger than that of the other. Additionally, determine if there are multiple ways to cut the rectangle and achieve that maximum.
Constraints
* 1 \leq W,H \leq 10^9
* 0\leq x\leq W
* 0\leq y\leq H
* All values in input are integers.
Input
Input is given from Standard Input in the following format:
W H x y
Output
Print the maximum possible area of the part whose area is not larger than that of the other, followed by `1` if there are multiple ways to cut the rectangle and achieve that maximum, and `0` otherwise.
The area printed will be judged correct when its absolute or relative error is at most 10^{-9}.
Examples
Input
2 3 1 2
Output
3.000000 0
Input
2 2 1 1
Output
2.000000 1 | instruction | 0 | 22,652 | 23 | 45,304 |
"Correct Solution:
```
W,H,x,y=map(float,input().split())
num=0
if W==x*2 and H==y*2:
num=1
print(W*H/2,num)
``` | output | 1 | 22,652 | 23 | 45,305 |
Provide a correct Python 3 solution for this coding contest problem.
There is a rectangle in a coordinate plane. The coordinates of the four vertices are (0,0), (W,0), (W,H), and (0,H). You are given a point (x,y) which is within the rectangle or on its border. We will draw a straight line passing through (x,y) to cut the rectangle into two parts. Find the maximum possible area of the part whose area is not larger than that of the other. Additionally, determine if there are multiple ways to cut the rectangle and achieve that maximum.
Constraints
* 1 \leq W,H \leq 10^9
* 0\leq x\leq W
* 0\leq y\leq H
* All values in input are integers.
Input
Input is given from Standard Input in the following format:
W H x y
Output
Print the maximum possible area of the part whose area is not larger than that of the other, followed by `1` if there are multiple ways to cut the rectangle and achieve that maximum, and `0` otherwise.
The area printed will be judged correct when its absolute or relative error is at most 10^{-9}.
Examples
Input
2 3 1 2
Output
3.000000 0
Input
2 2 1 1
Output
2.000000 1 | instruction | 0 | 22,653 | 23 | 45,306 |
"Correct Solution:
```
W,H,x,y=map(int,open(0).read().split())
print(W*H/2,int(x==W/2 and y==H/2))
``` | output | 1 | 22,653 | 23 | 45,307 |
Provide a correct Python 3 solution for this coding contest problem.
There is a rectangle in a coordinate plane. The coordinates of the four vertices are (0,0), (W,0), (W,H), and (0,H). You are given a point (x,y) which is within the rectangle or on its border. We will draw a straight line passing through (x,y) to cut the rectangle into two parts. Find the maximum possible area of the part whose area is not larger than that of the other. Additionally, determine if there are multiple ways to cut the rectangle and achieve that maximum.
Constraints
* 1 \leq W,H \leq 10^9
* 0\leq x\leq W
* 0\leq y\leq H
* All values in input are integers.
Input
Input is given from Standard Input in the following format:
W H x y
Output
Print the maximum possible area of the part whose area is not larger than that of the other, followed by `1` if there are multiple ways to cut the rectangle and achieve that maximum, and `0` otherwise.
The area printed will be judged correct when its absolute or relative error is at most 10^{-9}.
Examples
Input
2 3 1 2
Output
3.000000 0
Input
2 2 1 1
Output
2.000000 1 | instruction | 0 | 22,654 | 23 | 45,308 |
"Correct Solution:
```
w, h, x, y = map(int, input().split())
print(w*h/2., int(w/2.==x and h/2.==y) )
``` | output | 1 | 22,654 | 23 | 45,309 |
Provide a correct Python 3 solution for this coding contest problem.
There is a rectangle in a coordinate plane. The coordinates of the four vertices are (0,0), (W,0), (W,H), and (0,H). You are given a point (x,y) which is within the rectangle or on its border. We will draw a straight line passing through (x,y) to cut the rectangle into two parts. Find the maximum possible area of the part whose area is not larger than that of the other. Additionally, determine if there are multiple ways to cut the rectangle and achieve that maximum.
Constraints
* 1 \leq W,H \leq 10^9
* 0\leq x\leq W
* 0\leq y\leq H
* All values in input are integers.
Input
Input is given from Standard Input in the following format:
W H x y
Output
Print the maximum possible area of the part whose area is not larger than that of the other, followed by `1` if there are multiple ways to cut the rectangle and achieve that maximum, and `0` otherwise.
The area printed will be judged correct when its absolute or relative error is at most 10^{-9}.
Examples
Input
2 3 1 2
Output
3.000000 0
Input
2 2 1 1
Output
2.000000 1 | instruction | 0 | 22,655 | 23 | 45,310 |
"Correct Solution:
```
w,h,x,y=map(int,input().split());print(w*h/2,(x==w/2)*(y==h/2))
``` | output | 1 | 22,655 | 23 | 45,311 |
Provide a correct Python 3 solution for this coding contest problem.
There is a rectangle in a coordinate plane. The coordinates of the four vertices are (0,0), (W,0), (W,H), and (0,H). You are given a point (x,y) which is within the rectangle or on its border. We will draw a straight line passing through (x,y) to cut the rectangle into two parts. Find the maximum possible area of the part whose area is not larger than that of the other. Additionally, determine if there are multiple ways to cut the rectangle and achieve that maximum.
Constraints
* 1 \leq W,H \leq 10^9
* 0\leq x\leq W
* 0\leq y\leq H
* All values in input are integers.
Input
Input is given from Standard Input in the following format:
W H x y
Output
Print the maximum possible area of the part whose area is not larger than that of the other, followed by `1` if there are multiple ways to cut the rectangle and achieve that maximum, and `0` otherwise.
The area printed will be judged correct when its absolute or relative error is at most 10^{-9}.
Examples
Input
2 3 1 2
Output
3.000000 0
Input
2 2 1 1
Output
2.000000 1 | instruction | 0 | 22,656 | 23 | 45,312 |
"Correct Solution:
```
n, m, x, y = map(int, input().split())
print(n * m / 2, int(x == n / 2 and y == m / 2))
``` | output | 1 | 22,656 | 23 | 45,313 |
Provide a correct Python 3 solution for this coding contest problem.
There is a rectangle in a coordinate plane. The coordinates of the four vertices are (0,0), (W,0), (W,H), and (0,H). You are given a point (x,y) which is within the rectangle or on its border. We will draw a straight line passing through (x,y) to cut the rectangle into two parts. Find the maximum possible area of the part whose area is not larger than that of the other. Additionally, determine if there are multiple ways to cut the rectangle and achieve that maximum.
Constraints
* 1 \leq W,H \leq 10^9
* 0\leq x\leq W
* 0\leq y\leq H
* All values in input are integers.
Input
Input is given from Standard Input in the following format:
W H x y
Output
Print the maximum possible area of the part whose area is not larger than that of the other, followed by `1` if there are multiple ways to cut the rectangle and achieve that maximum, and `0` otherwise.
The area printed will be judged correct when its absolute or relative error is at most 10^{-9}.
Examples
Input
2 3 1 2
Output
3.000000 0
Input
2 2 1 1
Output
2.000000 1 | instruction | 0 | 22,657 | 23 | 45,314 |
"Correct Solution:
```
W,H,x,y=map(int,input().split())
print(W*H/2,1) if W==2*x and H==2*y else print(W*H/2,0)
``` | output | 1 | 22,657 | 23 | 45,315 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
There is a rectangle in a coordinate plane. The coordinates of the four vertices are (0,0), (W,0), (W,H), and (0,H). You are given a point (x,y) which is within the rectangle or on its border. We will draw a straight line passing through (x,y) to cut the rectangle into two parts. Find the maximum possible area of the part whose area is not larger than that of the other. Additionally, determine if there are multiple ways to cut the rectangle and achieve that maximum.
Constraints
* 1 \leq W,H \leq 10^9
* 0\leq x\leq W
* 0\leq y\leq H
* All values in input are integers.
Input
Input is given from Standard Input in the following format:
W H x y
Output
Print the maximum possible area of the part whose area is not larger than that of the other, followed by `1` if there are multiple ways to cut the rectangle and achieve that maximum, and `0` otherwise.
The area printed will be judged correct when its absolute or relative error is at most 10^{-9}.
Examples
Input
2 3 1 2
Output
3.000000 0
Input
2 2 1 1
Output
2.000000 1
Submitted Solution:
```
W,H,x,y = map(int,input().split())
f = int(W==2*x and H==2*y)
print(W*H/2,f)
``` | instruction | 0 | 22,658 | 23 | 45,316 |
Yes | output | 1 | 22,658 | 23 | 45,317 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
There is a rectangle in a coordinate plane. The coordinates of the four vertices are (0,0), (W,0), (W,H), and (0,H). You are given a point (x,y) which is within the rectangle or on its border. We will draw a straight line passing through (x,y) to cut the rectangle into two parts. Find the maximum possible area of the part whose area is not larger than that of the other. Additionally, determine if there are multiple ways to cut the rectangle and achieve that maximum.
Constraints
* 1 \leq W,H \leq 10^9
* 0\leq x\leq W
* 0\leq y\leq H
* All values in input are integers.
Input
Input is given from Standard Input in the following format:
W H x y
Output
Print the maximum possible area of the part whose area is not larger than that of the other, followed by `1` if there are multiple ways to cut the rectangle and achieve that maximum, and `0` otherwise.
The area printed will be judged correct when its absolute or relative error is at most 10^{-9}.
Examples
Input
2 3 1 2
Output
3.000000 0
Input
2 2 1 1
Output
2.000000 1
Submitted Solution:
```
W,H,x,y = map(int,input().split())
print(H*W/2, int(W/2 == x and H/2 == y))
``` | instruction | 0 | 22,659 | 23 | 45,318 |
Yes | output | 1 | 22,659 | 23 | 45,319 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
There is a rectangle in a coordinate plane. The coordinates of the four vertices are (0,0), (W,0), (W,H), and (0,H). You are given a point (x,y) which is within the rectangle or on its border. We will draw a straight line passing through (x,y) to cut the rectangle into two parts. Find the maximum possible area of the part whose area is not larger than that of the other. Additionally, determine if there are multiple ways to cut the rectangle and achieve that maximum.
Constraints
* 1 \leq W,H \leq 10^9
* 0\leq x\leq W
* 0\leq y\leq H
* All values in input are integers.
Input
Input is given from Standard Input in the following format:
W H x y
Output
Print the maximum possible area of the part whose area is not larger than that of the other, followed by `1` if there are multiple ways to cut the rectangle and achieve that maximum, and `0` otherwise.
The area printed will be judged correct when its absolute or relative error is at most 10^{-9}.
Examples
Input
2 3 1 2
Output
3.000000 0
Input
2 2 1 1
Output
2.000000 1
Submitted Solution:
```
W,H,x,y = map(int,input().split())
i = int(W-x==x and H-y==y)
print(W*H/2,i)
``` | instruction | 0 | 22,660 | 23 | 45,320 |
Yes | output | 1 | 22,660 | 23 | 45,321 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
There is a rectangle in a coordinate plane. The coordinates of the four vertices are (0,0), (W,0), (W,H), and (0,H). You are given a point (x,y) which is within the rectangle or on its border. We will draw a straight line passing through (x,y) to cut the rectangle into two parts. Find the maximum possible area of the part whose area is not larger than that of the other. Additionally, determine if there are multiple ways to cut the rectangle and achieve that maximum.
Constraints
* 1 \leq W,H \leq 10^9
* 0\leq x\leq W
* 0\leq y\leq H
* All values in input are integers.
Input
Input is given from Standard Input in the following format:
W H x y
Output
Print the maximum possible area of the part whose area is not larger than that of the other, followed by `1` if there are multiple ways to cut the rectangle and achieve that maximum, and `0` otherwise.
The area printed will be judged correct when its absolute or relative error is at most 10^{-9}.
Examples
Input
2 3 1 2
Output
3.000000 0
Input
2 2 1 1
Output
2.000000 1
Submitted Solution:
```
w,h,x,y=map(int,input().split())
if 2*x==w and 2*y==h:
a=1
else:
a=0
print(w*h/2,a)
``` | instruction | 0 | 22,661 | 23 | 45,322 |
Yes | output | 1 | 22,661 | 23 | 45,323 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
There is a rectangle in a coordinate plane. The coordinates of the four vertices are (0,0), (W,0), (W,H), and (0,H). You are given a point (x,y) which is within the rectangle or on its border. We will draw a straight line passing through (x,y) to cut the rectangle into two parts. Find the maximum possible area of the part whose area is not larger than that of the other. Additionally, determine if there are multiple ways to cut the rectangle and achieve that maximum.
Constraints
* 1 \leq W,H \leq 10^9
* 0\leq x\leq W
* 0\leq y\leq H
* All values in input are integers.
Input
Input is given from Standard Input in the following format:
W H x y
Output
Print the maximum possible area of the part whose area is not larger than that of the other, followed by `1` if there are multiple ways to cut the rectangle and achieve that maximum, and `0` otherwise.
The area printed will be judged correct when its absolute or relative error is at most 10^{-9}.
Examples
Input
2 3 1 2
Output
3.000000 0
Input
2 2 1 1
Output
2.000000 1
Submitted Solution:
```
W, H, x, y = map(int, input().split())
if (
(W // 2 == x and H // 2 == y)
or (W == x and H == y)
or (W == x and H == 0)
or (W == 0 and H == 0)
or (W == 0 and H == y)
):
print(W * H / 2, 1)
else:
print(W * H / 2, 0)
``` | instruction | 0 | 22,662 | 23 | 45,324 |
No | output | 1 | 22,662 | 23 | 45,325 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
There is a rectangle in a coordinate plane. The coordinates of the four vertices are (0,0), (W,0), (W,H), and (0,H). You are given a point (x,y) which is within the rectangle or on its border. We will draw a straight line passing through (x,y) to cut the rectangle into two parts. Find the maximum possible area of the part whose area is not larger than that of the other. Additionally, determine if there are multiple ways to cut the rectangle and achieve that maximum.
Constraints
* 1 \leq W,H \leq 10^9
* 0\leq x\leq W
* 0\leq y\leq H
* All values in input are integers.
Input
Input is given from Standard Input in the following format:
W H x y
Output
Print the maximum possible area of the part whose area is not larger than that of the other, followed by `1` if there are multiple ways to cut the rectangle and achieve that maximum, and `0` otherwise.
The area printed will be judged correct when its absolute or relative error is at most 10^{-9}.
Examples
Input
2 3 1 2
Output
3.000000 0
Input
2 2 1 1
Output
2.000000 1
Submitted Solution:
```
w,h,x,y=map(int,input().split())
area=w*h
if x!=0:
if (y/x)*w>=h:
ax=(h/y)*x
if ((y-h)/x)*w+h>=0:
ayy=((y-h)/x)*w+h
axx=((x-w)*w)/y+w
if y!=h:
ay=((y-h)/(w-x))*w+h
lst=[min(area-((w-axx)*h)/2,((w-axx)*h)/2),min(area-((h-ayy)*w)/2,((h-ayy)*w)/2),min(area-h*x,h*x),min(area-w*y,w*y),min(area-(ax*h)/2,(ax*h)/2),min(area-(ay*w)/2,(ay*w)/2)]
ans=max(lst)
if lst.count(ans)==1:
f=0
else:
f=1
else:
lst=[min(area-((w-axx)*h)/2,((w-axx)*h)/2),min(area-h*x,h*x),min(area-(ax*h)/2,(ax*h)/2)]
ans=max(lst)
if lst.count(ans)==1:
f=0
else:
f=1
else:
axx=(h*x)/(h-y)
ayy=(w*y)/(w-y)
ay=((y-h)/(w-x))*w+h
lst=[min(area-(w*ayy)/2,(w*ayy)/2),min(area-(axx*h)/2,(axx*h)/2),min(area-h*x,h*x),min(area-w*y,w*y),min(area-(ax*h)/2,(ax*h)/2),min(area-(ay*w)/2,(ay*w)/2)]
ans=max(lst)
if lst.count(ans)==1:
f=0
else:
f=1
else:
ay=(w*y)/x
if ((y-h)/x)*w+h>=0:
axx=((x-w)*w)/y+w
ayy=((y-h)/x)*w+h
if x!=w:
ax=((w-x)/(y-h))*h+w
lst=[min(area-((w-axx)*h)/2,((w-axx)*h)/2),min(area-((h-ayy)*w)/2,((h-ayy)*w)/2),min(area-h*x,h*x),min(area-w*y,w*y),min(area-(ay*w)/2,(ay*w)/2),min(area-((w-ax)*h)/2,((w-ax)*h)/2)]
ans=max(lst)
if lst.count(ans)==1:
f=0
else:
f=1
else:
lst=[min(area-((h-ayy)*w)/2,((h-ayy)*w)/2),min(area-w*y,w*y),min(area-(ay*w)/2,(ay*w)/2)]
ans=max(lst)
if lst.count(ans)==1:
f=0
else:
f=1
else:
axx=(h*x)/(h-y)
ayy=(w*y)/(w-y)
ax=((w-x)/(y-h))*h+w
lst=[min(area-(w*ayy)/2,(w*ayy)/2),min(area-(axx*h)/2),min(area-(axx*h)/2,(axx*h)/2),min(area-h*x,h*x),min(area-w*y,w*y),min(area-(ay*w)/2,(ay*w)/2),min(area-((w-ax)*h)/2,((w-ax)*h)/2)]
ans=max(lst)
if lst.count(ans)==1:
f=0
else:
f=1
else:
lst=[min(area-w*y,w*y),min(((h-y)*w)/2,area-((h-y)*w)/2),min(area-(y*w)/2,(y*w)/2)]
ans=max(lst)
if lst.count(ans)==1:
f=0
else:
f=1
print(ans,f)
``` | instruction | 0 | 22,663 | 23 | 45,326 |
No | output | 1 | 22,663 | 23 | 45,327 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
There is a rectangle in a coordinate plane. The coordinates of the four vertices are (0,0), (W,0), (W,H), and (0,H). You are given a point (x,y) which is within the rectangle or on its border. We will draw a straight line passing through (x,y) to cut the rectangle into two parts. Find the maximum possible area of the part whose area is not larger than that of the other. Additionally, determine if there are multiple ways to cut the rectangle and achieve that maximum.
Constraints
* 1 \leq W,H \leq 10^9
* 0\leq x\leq W
* 0\leq y\leq H
* All values in input are integers.
Input
Input is given from Standard Input in the following format:
W H x y
Output
Print the maximum possible area of the part whose area is not larger than that of the other, followed by `1` if there are multiple ways to cut the rectangle and achieve that maximum, and `0` otherwise.
The area printed will be judged correct when its absolute or relative error is at most 10^{-9}.
Examples
Input
2 3 1 2
Output
3.000000 0
Input
2 2 1 1
Output
2.000000 1
Submitted Solution:
```
W,H,x,y=map(int,input().split())
area=0
K=0
L=0
if abs(H//2-y)>abs(W//2-x):
area=H*(min(x,W-x))
K=x
L=W
else:
area=W*min(y,H-y)
K=y
L=H
ans=0
if W/2==x and H/2==y:
ans=1
else:
ans=0
print(area,ans)
``` | instruction | 0 | 22,664 | 23 | 45,328 |
No | output | 1 | 22,664 | 23 | 45,329 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
There is a rectangle in a coordinate plane. The coordinates of the four vertices are (0,0), (W,0), (W,H), and (0,H). You are given a point (x,y) which is within the rectangle or on its border. We will draw a straight line passing through (x,y) to cut the rectangle into two parts. Find the maximum possible area of the part whose area is not larger than that of the other. Additionally, determine if there are multiple ways to cut the rectangle and achieve that maximum.
Constraints
* 1 \leq W,H \leq 10^9
* 0\leq x\leq W
* 0\leq y\leq H
* All values in input are integers.
Input
Input is given from Standard Input in the following format:
W H x y
Output
Print the maximum possible area of the part whose area is not larger than that of the other, followed by `1` if there are multiple ways to cut the rectangle and achieve that maximum, and `0` otherwise.
The area printed will be judged correct when its absolute or relative error is at most 10^{-9}.
Examples
Input
2 3 1 2
Output
3.000000 0
Input
2 2 1 1
Output
2.000000 1
Submitted Solution:
```
W, H, x, y = list(map(int,input().rstrip().split()))
if x == W//2 and y == H//2:
print(W*H//2, 1)
else:
print(W*H//2, 0)
``` | instruction | 0 | 22,665 | 23 | 45,330 |
No | output | 1 | 22,665 | 23 | 45,331 |
Provide a correct Python 3 solution for this coding contest problem.
Find places where a R Γ C pattern is found within a H Γ W region. Print top-left coordinates (i, j) of sub-regions where the pattern found. The top-left and bottom-right coordinates of the region is (0, 0) and (H-1, W-1) respectively.
Constraints
* 1 β€ H, W β€ 1000
* 1 β€ R, C β€ 1000
* The input consists of alphabetical characters and digits
Input
In the first line, two integers H and W are given. In the following H lines, i-th lines of the region are given.
In the next line, two integers R and C are given. In the following R lines, i-th lines of the pattern are given.
Example
Input
4 5
00010
00101
00010
00100
3 2
10
01
10
Output
0 3
1 2 | instruction | 0 | 22,811 | 23 | 45,622 |
"Correct Solution:
```
from functools import lru_cache
class MatrixRKSearch:
shift = 40
size = 33554393
def __init__(self, m1, m2):
self.haystack = self._encode(m1)
self.needle = self._encode(m2)
def find(self):
i1, j1 = len(self.haystack), len(self.haystack[0])
i2, j2 = len(self.needle), len(self.needle[0])
if i1 < i2 or j1 < j2:
return
hs1 = [self._hash(s, j2) for s in self.haystack]
hs2 = [self._hash(s, j2) for s in self.needle]
dm = self.shift**(j2-1) % self.size
for j in range(j1-j2+1):
for i in range(i1-i2+1):
if hs1[i:i+i2] == hs2:
yield (i, j)
if j+j2 < j1:
for i in range(i1):
hs1[i] = self._shift(hs1[i], self.haystack[i][j+j2],
self.haystack[i][j], dm)
@lru_cache(maxsize=1000)
def _shift(self, h, add, remove, dm):
return ((h - remove*dm) * self.shift + add) % self.size
def _hash(self, s, length):
h = 0
for i in range(length):
h = (h * self.shift + s[i]) % self.size
return h
def _encode(cls, m):
basea = ord('a')
based = ord('0')
es = []
for s in m:
bs = []
for c in s:
if c.isdigit():
bs.append(ord(c) - based + 27)
else:
bs.append(ord(c) - basea)
es.append(bs)
return es
def run():
h, w = [int(x) for x in input().split()]
m = []
for _ in range(h):
m.append(input())
r, c = [int(x) for x in input().split()]
pt = []
for _ in range(r):
pt.append(input())
sch = MatrixRKSearch(m, pt)
result = []
for i, j in sch.find():
result.append((i, j))
result.sort()
for i, j in result:
print(i, j)
if __name__ == '__main__':
run()
``` | output | 1 | 22,811 | 23 | 45,623 |
Provide a correct Python 3 solution for this coding contest problem.
Find places where a R Γ C pattern is found within a H Γ W region. Print top-left coordinates (i, j) of sub-regions where the pattern found. The top-left and bottom-right coordinates of the region is (0, 0) and (H-1, W-1) respectively.
Constraints
* 1 β€ H, W β€ 1000
* 1 β€ R, C β€ 1000
* The input consists of alphabetical characters and digits
Input
In the first line, two integers H and W are given. In the following H lines, i-th lines of the region are given.
In the next line, two integers R and C are given. In the following R lines, i-th lines of the pattern are given.
Example
Input
4 5
00010
00101
00010
00100
3 2
10
01
10
Output
0 3
1 2 | instruction | 0 | 22,812 | 23 | 45,624 |
"Correct Solution:
```
from typing import List
def calc_hash(tab: List[List[int]], row_num: int, col_num: int) -> None:
global hash_table, R, C, baes1, base2, mask
tmp_table = [[0] * col_num for _ in range(row_num)]
diff_row, diff_col = row_num - R, col_num - C
bit_mask = 1
for _ in range(C):
bit_mask = (bit_mask * base1) & mask
for r in range(row_num):
hash_v = 0
for c in range(C):
hash_v = hash_v * base1 + tab[r][c]
for dc in range(diff_col):
tmp_table[r][dc] = hash_v
hash_v = (hash_v * base1 - bit_mask * tab[r][dc] + tab[r][dc + C]) & mask
tmp_table[r][diff_col] = hash_v
bit_mask = 1
for _ in range(R):
bit_mask = (bit_mask * base2) & mask
for c in range(diff_col + 1):
hash_v = 0
for r in range(R):
hash_v = hash_v * base2 + tmp_table[r][c]
for dr in range(diff_row):
hash_table[dr][c] = hash_v
hash_v = (hash_v * base2 - bit_mask * tmp_table[dr][c]
+ tmp_table[dr + R][c]) & mask
hash_table[diff_row][c] = hash_v
if __name__ == "__main__":
base1 = 1009 # The first prime number over 1000.
base2 = 1013 # The second prime number over 1000.
mask = (1 << 32) - 1 # Mask.
H, W = map(lambda x: int(x), input().split())
region = [[0] * W for _ in range(H)]
for row in range(H):
region[row] = [ord(s) for s in input()]
R, C = map(lambda x: int(x), input().split())
pattern = [[0] * C for _ in range(R)]
for row in range(R):
pattern[row] = [ord(s) for s in input()]
if H >= R and W >= C:
hash_table = [[0] * W for _ in range(H)]
calc_hash(pattern, R, C) # Calc the target hash and save it into hash_table[0][0]
key = hash_table[0][0] & mask
calc_hash(region, H, W)
for r in range(H - R + 1):
for c in range(W - C + 1):
if key == hash_table[r][c] & mask:
print(f"{r} {c}")
``` | output | 1 | 22,812 | 23 | 45,625 |
Provide a correct Python 3 solution for this coding contest problem.
Find places where a R Γ C pattern is found within a H Γ W region. Print top-left coordinates (i, j) of sub-regions where the pattern found. The top-left and bottom-right coordinates of the region is (0, 0) and (H-1, W-1) respectively.
Constraints
* 1 β€ H, W β€ 1000
* 1 β€ R, C β€ 1000
* The input consists of alphabetical characters and digits
Input
In the first line, two integers H and W are given. In the following H lines, i-th lines of the region are given.
In the next line, two integers R and C are given. In the following R lines, i-th lines of the pattern are given.
Example
Input
4 5
00010
00101
00010
00100
3 2
10
01
10
Output
0 3
1 2 | instruction | 0 | 22,813 | 23 | 45,626 |
"Correct Solution:
```
base1 = 1009
base2 = 1013
mask = (1 << 32) - 1
def calc_hash(f, r, c):
global ph, pw, h
tmp = [[0] * c for _ in range(r)]
dr, dc = r - ph, c - pw
t1 = 1
for _ in range(pw):
t1 = (t1 * base1) & mask
for i in range(r):
e = 0
for j in range(pw):
e = e * base1 + f[i][j]
for j in range(dc):
tmp[i][j] = e
e = (e * base1 - t1 * f[i][j] + f[i][j + pw]) & mask
tmp[i][dc] = e
t2 = 1
for _ in range(ph):
t2 = (t2 * base2) & mask
for j in range(dc + 1):
e = 0
for i in range(ph):
e = e * base2 + tmp[i][j]
for i in range(dr):
h[i][j] = e
e = (e * base2 - t2 * tmp[i][j] + tmp[i + ph][j]) & mask
h[dr][j] = e
th, tw = map(int, input().split())
t = tuple(tuple(ord(c) for c in input()) for _ in range(th))
ph, pw = map(int, input().split())
p = tuple(tuple(ord(c) for c in input()) for _ in range(ph))
ans = []
if th >= ph and tw >= pw:
h = [[0] * tw for _ in range(th)]
calc_hash(p, ph, pw)
key = h[0][0] & mask
calc_hash(t, th, tw)
for i in range(th - ph + 1):
for j in range(tw - pw + 1):
if h[i][j] & mask == key:
ans.append(f"{i} {j}")
if ans:
print("\n".join(a for a in ans))
``` | output | 1 | 22,813 | 23 | 45,627 |
Provide a correct Python 3 solution for this coding contest problem.
Find places where a R Γ C pattern is found within a H Γ W region. Print top-left coordinates (i, j) of sub-regions where the pattern found. The top-left and bottom-right coordinates of the region is (0, 0) and (H-1, W-1) respectively.
Constraints
* 1 β€ H, W β€ 1000
* 1 β€ R, C β€ 1000
* The input consists of alphabetical characters and digits
Input
In the first line, two integers H and W are given. In the following H lines, i-th lines of the region are given.
In the next line, two integers R and C are given. In the following R lines, i-th lines of the pattern are given.
Example
Input
4 5
00010
00101
00010
00100
3 2
10
01
10
Output
0 3
1 2 | instruction | 0 | 22,814 | 23 | 45,628 |
"Correct Solution:
```
import sys
readline = sys.stdin.readline
write = sys.stdout.write
mod = 10**9 + 9; p = 13; q = 19
p_table = q_table = None
def prepare(L):
global p_table, q_table
p_table = [1]*(L+1); q_table = [1]*(L+1)
for i in range(L):
p_table[i+1] = p_table[i] * p % mod
q_table[i+1] = q_table[i] * q % mod
def rolling_hash(S, W, H):
D = [[0]*(W+1) for i in range(H+1)]
for i in range(H):
su = 0
dp = D[i]
di = D[i+1]
si = S[i]
for j in range(W):
v = si[j] # v = ord(si[j]) if si[j] is str
su = (su*p + v) % mod
di[j+1] = (su + dp[j+1]*q) % mod
return D
def get(S, x0, y0, x1, y1):
P = p_table[x1 - x0]; Q = q_table[y1 - y0]
return (S[y1][x1] - S[y1][x0] * P - S[y0][x1] * Q + S[y0][x0] * (P * Q) % mod) % mod
def solve():
prepare(1001)
H, W = map(int, readline().split())
M = [list(map(ord, readline().strip())) for i in range(H)]
R, C = map(int, readline().split())
M0 = [list(map(ord, readline().strip())) for i in range(R)]
rh = rolling_hash(M, W, H)
rh0 = rolling_hash(M0, C, R)
v = rh0[-1][-1]
for i in range(H-R+1):
for j in range(W-C+1):
if v == get(rh, j, i, j+C, i+R):
write("%d %d\n" % (i, j))
solve()
``` | output | 1 | 22,814 | 23 | 45,629 |
Provide a correct Python 3 solution for this coding contest problem.
Find places where a R Γ C pattern is found within a H Γ W region. Print top-left coordinates (i, j) of sub-regions where the pattern found. The top-left and bottom-right coordinates of the region is (0, 0) and (H-1, W-1) respectively.
Constraints
* 1 β€ H, W β€ 1000
* 1 β€ R, C β€ 1000
* The input consists of alphabetical characters and digits
Input
In the first line, two integers H and W are given. In the following H lines, i-th lines of the region are given.
In the next line, two integers R and C are given. In the following R lines, i-th lines of the pattern are given.
Example
Input
4 5
00010
00101
00010
00100
3 2
10
01
10
Output
0 3
1 2 | instruction | 0 | 22,815 | 23 | 45,630 |
"Correct Solution:
```
base1 = 1009
base2 = 1013
mask = (1 << 32) - 1
def calc_hash(f, r, c):
global ph, pw, h
tmp = [[0] * c for _ in range(r)]
dr, dc = r - ph, c - pw
t1 = 1
for _ in range(pw):
t1 = (t1 * base1) & mask
for i in range(r):
e = 0
for j in range(pw):
e = e * base1 + f[i][j]
for j in range(dc):
tmp[i][j] = e
e = (e * base1 - t1 * f[i][j] + f[i][j + pw]) & mask
tmp[i][dc] = e
t2 = 1
for _ in range(ph):
t2 = (t2 * base2) & mask
for j in range(dc + 1):
e = 0
for i in range(ph):
e = e * base2 + tmp[i][j]
for i in range(dr):
h[i][j] = e
e = (e * base2 - t2 * tmp[i][j] + tmp[i + ph][j]) & mask
h[dr][j] = e
th, tw = map(int, input().split())
t = [[ord(c) for c in input().strip()] for _ in range(th)]
ph, pw = map(int, input().split())
p = [[ord(c) for c in input().strip()] for _ in range(ph)]
if th >= ph and tw >= pw:
h = [[0] * tw for _ in range(th)]
calc_hash(p, ph, pw)
key = h[0][0] & mask
calc_hash(t, th, tw)
for i in range(th - ph + 1):
for j in range(tw - pw + 1):
if h[i][j] & mask == key:
print(i, j)
``` | output | 1 | 22,815 | 23 | 45,631 |
Provide a correct Python 3 solution for this coding contest problem.
Find places where a R Γ C pattern is found within a H Γ W region. Print top-left coordinates (i, j) of sub-regions where the pattern found. The top-left and bottom-right coordinates of the region is (0, 0) and (H-1, W-1) respectively.
Constraints
* 1 β€ H, W β€ 1000
* 1 β€ R, C β€ 1000
* The input consists of alphabetical characters and digits
Input
In the first line, two integers H and W are given. In the following H lines, i-th lines of the region are given.
In the next line, two integers R and C are given. In the following R lines, i-th lines of the pattern are given.
Example
Input
4 5
00010
00101
00010
00100
3 2
10
01
10
Output
0 3
1 2 | instruction | 0 | 22,816 | 23 | 45,632 |
"Correct Solution:
```
base1 = 127
base2 = 1009
mask = (1 << 32) - 1
def calc_hash(f, r, c):
global ph, pw, h
tmp = [[0] * c for _ in range(r)]
dr, dc = r - ph, c - pw
t1 = 1
for _ in range(pw):
t1 = (t1 * base1) & mask
for i in range(r):
e = 0
for j in range(pw):
e = e * base1 + f[i][j]
for j in range(dc):
tmp[i][j] = e
e = (e * base1 - t1 * f[i][j] + f[i][j + pw]) & mask
tmp[i][dc] = e
t2 = 1
for _ in range(ph):
t2 = (t2 * base2) & mask
for j in range(dc + 1):
e = 0
for i in range(ph):
e = e * base2 + tmp[i][j]
for i in range(dr):
h[i][j] = e
e = (e * base2 - t2 * tmp[i][j] + tmp[i + ph][j]) & mask
h[dr][j] = e
th, tw = map(int, input().split())
t = [[ord(c) for c in input().strip()] for _ in range(th)]
ph, pw = map(int, input().split())
p = [[ord(c) for c in input().strip()] for _ in range(ph)]
if th >= ph and tw >= pw:
h = [[0] * tw for _ in range(th)]
calc_hash(p, ph, pw)
key = h[0][0] & mask
calc_hash(t, th, tw)
for i in range(th - ph + 1):
for j in range(tw - pw + 1):
if h[i][j] & mask == key:
print(i, j)
``` | output | 1 | 22,816 | 23 | 45,633 |
Provide a correct Python 3 solution for this coding contest problem.
Find places where a R Γ C pattern is found within a H Γ W region. Print top-left coordinates (i, j) of sub-regions where the pattern found. The top-left and bottom-right coordinates of the region is (0, 0) and (H-1, W-1) respectively.
Constraints
* 1 β€ H, W β€ 1000
* 1 β€ R, C β€ 1000
* The input consists of alphabetical characters and digits
Input
In the first line, two integers H and W are given. In the following H lines, i-th lines of the region are given.
In the next line, two integers R and C are given. In the following R lines, i-th lines of the pattern are given.
Example
Input
4 5
00010
00101
00010
00100
3 2
10
01
10
Output
0 3
1 2 | instruction | 0 | 22,817 | 23 | 45,634 |
"Correct Solution:
```
from functools import lru_cache
class MatrixRKSearch:
shift = 40
size = 33554393
def __init__(self, m1, m2):
self.haystack = self._encode(m1)
self.needle = self._encode(m2)
def find(self):
i1, j1 = len(self.haystack), len(self.haystack[0])
i2, j2 = len(self.needle), len(self.needle[0])
if i1 < i2 or j1 < j2:
return
hs1 = [self._hash(s, j2) for s in self.haystack]
hs2 = [self._hash(s, j2) for s in self.needle]
dm = self.shift**(j2-1) % self.size
for j in range(j1-j2+1):
for i in range(i1-i2+1):
if hs1[i:i+i2] == hs2:
yield (i, j)
if j+j2 < j1:
for i in range(i1):
hs1[i] = self._shift(hs1[i], self.haystack[i][j+j2],
self.haystack[i][j], dm)
def _shift(self, h, add, remove, dm):
return ((h - remove*dm) * self.shift + add) % self.size
def _hash(self, s, length):
h = 0
for i in range(length):
h = (h * self.shift + s[i]) % self.size
return h
def _encode(cls, m):
basea = ord('a')
based = ord('0')
es = []
for s in m:
bs = []
for c in s:
if c.isdigit():
bs.append(ord(c) - based + 27)
else:
bs.append(ord(c) - basea)
es.append(bs)
return es
def search(matrix, pattern):
"""Search matrix for pattern
"""
def _check(y, x):
for m in range(py):
for n in range(px):
if matrix[y+m][x+n] != pattern[m][n]:
return False
return True
mx = len(matrix[0])
my = len(matrix)
px = len(pattern[0])
py = len(pattern)
for i in range(my-py+1):
for j in range(mx-px+1):
if _check(i, j):
yield (i, j)
def run():
h, w = [int(x) for x in input().split()]
m = []
for _ in range(h):
m.append(input())
r, c = [int(x) for x in input().split()]
pt = []
for _ in range(r):
pt.append(input())
sch = MatrixRKSearch(m, pt)
result = []
for i, j in sch.find():
result.append((i, j))
result.sort()
for i, j in result:
print(i, j)
if __name__ == '__main__':
run()
``` | output | 1 | 22,817 | 23 | 45,635 |
Provide a correct Python 3 solution for this coding contest problem.
Find places where a R Γ C pattern is found within a H Γ W region. Print top-left coordinates (i, j) of sub-regions where the pattern found. The top-left and bottom-right coordinates of the region is (0, 0) and (H-1, W-1) respectively.
Constraints
* 1 β€ H, W β€ 1000
* 1 β€ R, C β€ 1000
* The input consists of alphabetical characters and digits
Input
In the first line, two integers H and W are given. In the following H lines, i-th lines of the region are given.
In the next line, two integers R and C are given. In the following R lines, i-th lines of the pattern are given.
Example
Input
4 5
00010
00101
00010
00100
3 2
10
01
10
Output
0 3
1 2 | instruction | 0 | 22,818 | 23 | 45,636 |
"Correct Solution:
```
base1 = 1009
base2 = 1013
mask = (1 << 32) - 1
def calculate_hash(f, r, c):
global ph, pw, h
tmp = [[0 for _ in range(c)] for _ in range(r)]
dr, dc = r - ph, c - pw
t1 = 1
for _ in range(pw):
t1 = (t1 * base1) & mask
for i in range(r):
e = 0
for j in range(pw):
e = e * base1 + f[i][j]
for j in range(dc):
tmp[i][j] = e
e = (e * base1 - t1 * f[i][j] + f[i][j + pw]) & mask
tmp[i][dc] = e
t2 = 1
for _ in range(ph):
t2 = (t2 * base2) & mask
for j in range(dc + 1):
e = 0
for i in range(ph):
e = e * base2 + tmp[i][j]
for i in range(dr):
h[i][j] = e
e = (e * base2 - t2 * tmp[i][j] + tmp[i + ph][j]) & mask
h[dr][j] = e
th, tw = map(int, input().split())
t = [[ord(x) for x in input().strip()] for _ in range(th)]
ph, pw = map(int, input().split())
p = [[ord(x) for x in input().strip()] for _ in range(ph)]
if th >= ph and tw >= pw:
h = [[0 for _ in range(tw)] for _ in range(th)]
calculate_hash(p, ph, pw)
key = h[0][0] & mask
calculate_hash(t, th, tw)
for i in range(th - ph + 1):
for j in range(tw - pw + 1):
if h[i][j] & mask == key:
print(i, j)
``` | output | 1 | 22,818 | 23 | 45,637 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Find places where a R Γ C pattern is found within a H Γ W region. Print top-left coordinates (i, j) of sub-regions where the pattern found. The top-left and bottom-right coordinates of the region is (0, 0) and (H-1, W-1) respectively.
Constraints
* 1 β€ H, W β€ 1000
* 1 β€ R, C β€ 1000
* The input consists of alphabetical characters and digits
Input
In the first line, two integers H and W are given. In the following H lines, i-th lines of the region are given.
In the next line, two integers R and C are given. In the following R lines, i-th lines of the pattern are given.
Example
Input
4 5
00010
00101
00010
00100
3 2
10
01
10
Output
0 3
1 2
Submitted Solution:
```
base1 = 1009
base2 = 1013
mask = (1 << 32) - 1
def calc_hash(f, r, c):
global ph, pw, h
tmp = [[0] * c for _ in range(r)]
dr, dc = r - ph, c - pw
t1 = 1
for _ in range(pw):
t1 = (t1 * base1) & mask
for i in range(r):
e = 0
for j in range(pw):
e = e * base1 + f[i][j]
for j in range(dc):
tmp[i][j] = e
e = (e * base1 - t1 * f[i][j] + f[i][j + pw]) & mask
tmp[i][dc] = e
t2 = 1
for _ in range(ph):
t2 = (t2 * base2) & mask
for j in range(dc + 1):
e = 0
for i in range(ph):
e = e * base2 + tmp[i][j]
for i in range(dr):
h[i][j] = e
e = (e * base2 - t2 * tmp[i][j] + tmp[i + ph][j]) & mask
h[dr][j] = e
th, tw = map(int, input().split())
t = tuple(tuple(ord(c) for c in input()) for _ in range(th))
ph, pw = map(int, input().split())
p = tuple(tuple(ord(c) for c in input()) for _ in range(ph))
if th >= ph and tw >= pw:
h = [[0] * tw for _ in range(th)]
calc_hash(p, ph, pw)
key = h[0][0] & mask
calc_hash(t, th, tw)
for i in range(th - ph + 1):
for j in range(tw - pw + 1):
if h[i][j] & mask == key:
print(i, j)
``` | instruction | 0 | 22,819 | 23 | 45,638 |
Yes | output | 1 | 22,819 | 23 | 45,639 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Find places where a R Γ C pattern is found within a H Γ W region. Print top-left coordinates (i, j) of sub-regions where the pattern found. The top-left and bottom-right coordinates of the region is (0, 0) and (H-1, W-1) respectively.
Constraints
* 1 β€ H, W β€ 1000
* 1 β€ R, C β€ 1000
* The input consists of alphabetical characters and digits
Input
In the first line, two integers H and W are given. In the following H lines, i-th lines of the region are given.
In the next line, two integers R and C are given. In the following R lines, i-th lines of the pattern are given.
Example
Input
4 5
00010
00101
00010
00100
3 2
10
01
10
Output
0 3
1 2
Submitted Solution:
```
from collections import deque
import re
import sys
sys.setrecursionlimit(100000)
class AC:
def __init__(self,num,parent,char):
self.num = num
self.parent = parent
self.char = char
self.d = {}
self.failure = None
def insert(self,string,num):
if not string[0] in self.d:
self.d[string[0]] = AC(num,self,string[0])
num+=1
if not string[1:] == "":
return self.d[string[0]].insert(string[1:],num)
else:
return num
def setFailure(self):
tmp = self.parent.failure
while(True):
if self.char in tmp.d:
self.failure = tmp.d[self.char]
break
else:
if tmp.num == 0:
self.failure = tmp
break
else:
tmp = tmp.failure
def setFailureRoot(self):
self.failure = self
def setFailureFirstLayer(self):
self.failure = self.parent
def transition(self,string):
if string == "":
return []
elif string[0] in self.d:
tmp = self.d[string[0]]
num = "{0:09d}".format(tmp.num)
return [num]+tmp.transition(string[1:])
else:
if self.num == 0:
num = "{0:09d}".format(self.num)
return [num]+self.transition(string[1:])
else:
return self.failure.transition(string)
H,W = [int(i) for i in input().split()]
A = [input() for _ in range(H)]
R,C = [int(i) for i in input().split()]
B = [input() for _ in range(R)]
root = AC(0,None,"")
root.setFailureRoot()
num=1
for i in B:
num = root.insert(i,num)
d = deque()
for i in root.d.values():
i.setFailureFirstLayer()
for j in i.d.values():
d.appendleft(j)
while(len(d)>0):
tmp = d.pop()
tmp.setFailure()
for i in tmp.d.values():
d.appendleft(i)
trans = ["" for i in range(W)]
for i in A:
tmp = root.transition(i)
for j,k in enumerate(tmp):
trans[j] = trans[j]+k+"#"
ans=""
for i in B:
ans = ans+root.transition(i)[-1]+"#"
ansd = deque()
for i,j in enumerate(trans):
obj = re.search(ans,j)
c = 0
while(obj):
s = obj.start()
if (i-C+1)<0:
print(i)
ansd.append(((c+s)//10,i-C+1))
obj = re.search(ans,j[c+s+10:])
c += s+10
for i in sorted(ansd):
print(i[0],i[1])
``` | instruction | 0 | 22,820 | 23 | 45,640 |
Yes | output | 1 | 22,820 | 23 | 45,641 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Find places where a R Γ C pattern is found within a H Γ W region. Print top-left coordinates (i, j) of sub-regions where the pattern found. The top-left and bottom-right coordinates of the region is (0, 0) and (H-1, W-1) respectively.
Constraints
* 1 β€ H, W β€ 1000
* 1 β€ R, C β€ 1000
* The input consists of alphabetical characters and digits
Input
In the first line, two integers H and W are given. In the following H lines, i-th lines of the region are given.
In the next line, two integers R and C are given. In the following R lines, i-th lines of the pattern are given.
Example
Input
4 5
00010
00101
00010
00100
3 2
10
01
10
Output
0 3
1 2
Submitted Solution:
```
base1 = 1009
base2 = 1013
mask = (1 << 32) - 1
def calc_hash(f, r, c):
global ph, pw, h
tmp = [[0] * c for _ in range(r)]
dr, dc = r - ph, c - pw
# t1 = 1
t1 = (base1 ** pw) & mask
# for _ in range(pw):
# t1 = (t1 * base1) & mask
for i in range(r):
e = 0
for j in range(pw):
e = e * base1 + f[i][j]
for j in range(dc):
tmp[i][j] = e
e = (e * base1 - t1 * f[i][j] + f[i][j + pw]) & mask
tmp[i][dc] = e
t2 = 1
for _ in range(ph):
t2 = (t2 * base2) & mask
for j in range(dc + 1):
e = 0
for i in range(ph):
e = e * base2 + tmp[i][j]
for i in range(dr):
h[i][j] = e
e = (e * base2 - t2 * tmp[i][j] + tmp[i + ph][j]) & mask
h[dr][j] = e
th, tw = map(int, input().split())
t = tuple(tuple(ord(c) for c in input()) for _ in range(th))
ph, pw = map(int, input().split())
p = tuple(tuple(ord(c) for c in input()) for _ in range(ph))
ans = []
if th >= ph and tw >= pw:
h = [[0] * tw for _ in range(th)]
calc_hash(p, ph, pw)
key = h[0][0] & mask
calc_hash(t, th, tw)
for i in range(th - ph + 1):
for j in range(tw - pw + 1):
if h[i][j] & mask == key:
ans.append(f"{i} {j}")
if ans:
print("\n".join(a for a in ans))
``` | instruction | 0 | 22,821 | 23 | 45,642 |
Yes | output | 1 | 22,821 | 23 | 45,643 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Find places where a R Γ C pattern is found within a H Γ W region. Print top-left coordinates (i, j) of sub-regions where the pattern found. The top-left and bottom-right coordinates of the region is (0, 0) and (H-1, W-1) respectively.
Constraints
* 1 β€ H, W β€ 1000
* 1 β€ R, C β€ 1000
* The input consists of alphabetical characters and digits
Input
In the first line, two integers H and W are given. In the following H lines, i-th lines of the region are given.
In the next line, two integers R and C are given. In the following R lines, i-th lines of the pattern are given.
Example
Input
4 5
00010
00101
00010
00100
3 2
10
01
10
Output
0 3
1 2
Submitted Solution:
```
#coding:utf-8
def make_KMP_table(pattern): # ????´’????????????????§???°???????±????????????????????????????
l = len(pattern)
table = [0]*l
count = 0
j = 0
for i in range(1,l):
if pattern[i] == pattern[j]:
table[i] = count
count += 1
j += 1
else:
table[i] = count
count = 0
j = 0
return table
def bfs(pattern,buff,x,y):
count = 0
for j in range(1,R):
for i in range(C):
if pattern[j][i] != buff[y+j][i + x]:
count = 1
break
if count == 1:
break
else:
print(y,x)
def KMP_search(pattern,buff):
bl = W
pl = C
table = make_KMP_table(pattern[0])
for y in range(H-R + 1):
buffplace = 0
j = 0
while buffplace < bl:
if pattern[0][j] != buff[y][buffplace]:
if j == 0:
buffplace += 1
else:
j = table[j]
elif pattern[0][j] == buff[y][buffplace]:
buffplace += 1
j += 1
if j == pl:
x = buffplace - j
bfs(pattern,buff,x,y)
buffplace -= j - 1
j = 0
H,W = map(int,input().split())
buff = [0]*H
for i in range(H):
buff[i] = input()
R,C = map(int,input().split())
pattern = [0] * R
for i in range(R):
pattern[i] = input()
KMP_search(pattern, buff)
``` | instruction | 0 | 22,822 | 23 | 45,644 |
No | output | 1 | 22,822 | 23 | 45,645 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Find places where a R Γ C pattern is found within a H Γ W region. Print top-left coordinates (i, j) of sub-regions where the pattern found. The top-left and bottom-right coordinates of the region is (0, 0) and (H-1, W-1) respectively.
Constraints
* 1 β€ H, W β€ 1000
* 1 β€ R, C β€ 1000
* The input consists of alphabetical characters and digits
Input
In the first line, two integers H and W are given. In the following H lines, i-th lines of the region are given.
In the next line, two integers R and C are given. In the following R lines, i-th lines of the pattern are given.
Example
Input
4 5
00010
00101
00010
00100
3 2
10
01
10
Output
0 3
1 2
Submitted Solution:
```
#coding:utf-8
def make_KMP_table(pattern): # ????´’????????????????§???°???????±????????????????????????????
l = len(pattern)
table = [0]*l
count = 0
j = 0
for i in range(1,l):
if pattern[i] == pattern[j]:
table[i] = count
count += 1
j += 1
else:
table[i] = 0
count = 0
j = 0
return table
def bfs(pattern,buff,x,y):
count = 0
for j in range(1,R):
for i in range(C):
if pattern[j][i] != buff[y+j][i + x]:
count = 1
break
if count == 1:
break
else:
print(y,x)
def KMP_search(pattern,buff):
bl = W
pl = C
table = make_KMP_table(pattern[0])
for y in range(H-R + 1):
buffplace = 0
j = 0
while buffplace < bl:
if pattern[0][j] != buff[y][buffplace]:
if j == 0:
buffplace += 1
else:
j = table[j]
elif pattern[0][j] == buff[y][buffplace]:
buffplace += 1
j += 1
if j == pl:
x = buffplace - j
bfs(pattern,buff,x,y)
buffplace -= j - 1
j = 0
H,W = map(int,input().split())
buff = [0]*H
for i in range(H):
buff[i] = input()
R,C = map(int,input().split())
pattern = [0] * R
for i in range(R):
pattern[i] = input()
KMP_search(pattern, buff)
``` | instruction | 0 | 22,823 | 23 | 45,646 |
No | output | 1 | 22,823 | 23 | 45,647 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Find places where a R Γ C pattern is found within a H Γ W region. Print top-left coordinates (i, j) of sub-regions where the pattern found. The top-left and bottom-right coordinates of the region is (0, 0) and (H-1, W-1) respectively.
Constraints
* 1 β€ H, W β€ 1000
* 1 β€ R, C β€ 1000
* The input consists of alphabetical characters and digits
Input
In the first line, two integers H and W are given. In the following H lines, i-th lines of the region are given.
In the next line, two integers R and C are given. In the following R lines, i-th lines of the pattern are given.
Example
Input
4 5
00010
00101
00010
00100
3 2
10
01
10
Output
0 3
1 2
Submitted Solution:
```
def rabin_karp(T, P, d):
n = len(T)
m = len(P)
if n < m:
return
h = 1
p = 0
t0 = 0
for _ in range(m - 1):
h *= d
for i in range(m):
p = d * p + P[i]
t0 = d * t0 + T[i]
# print("h = ", h)
# print("p = ", p)
for s in range(n - m + 1):
# print("t0 = ", t0)
if p == t0:
print(s)
if s < n - m:
# print(" ", t0 - T[s] * h)
# print(" ", d)
# print(" ", T[s + m])
t0 = d * (t0 - T[s] * h) + T[s + m]
d = 1009
t = list(map(ord, input()))
p = list(map(ord, input()))
rabin_karp(t, p, d)
``` | instruction | 0 | 22,824 | 23 | 45,648 |
No | output | 1 | 22,824 | 23 | 45,649 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Find places where a R Γ C pattern is found within a H Γ W region. Print top-left coordinates (i, j) of sub-regions where the pattern found. The top-left and bottom-right coordinates of the region is (0, 0) and (H-1, W-1) respectively.
Constraints
* 1 β€ H, W β€ 1000
* 1 β€ R, C β€ 1000
* The input consists of alphabetical characters and digits
Input
In the first line, two integers H and W are given. In the following H lines, i-th lines of the region are given.
In the next line, two integers R and C are given. In the following R lines, i-th lines of the pattern are given.
Example
Input
4 5
00010
00101
00010
00100
3 2
10
01
10
Output
0 3
1 2
Submitted Solution:
```
import re
h, w = map(int, input().split())
f = ""
for i in range(h):
f += input()
r, c = map(int, input().split())
p = input()
for i in range(r - 1):
line = input()
p += "."*(w - c) + line
for i in range(len(f) - len(p) + 1):
tmp = f[i:i + len(p)]
if re.match(p, tmp) and (i%w <= w - c or i//w == h - r):
print(i//w, i%w)
``` | instruction | 0 | 22,825 | 23 | 45,650 |
No | output | 1 | 22,825 | 23 | 45,651 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
To make a paper airplane, one has to use a rectangular piece of paper. From a sheet of standard size you can make s airplanes.
A group of k people decided to make n airplanes each. They are going to buy several packs of paper, each of them containing p sheets, and then distribute the sheets between the people. Each person should have enough sheets to make n airplanes. How many packs should they buy?
Input
The only line contains four integers k, n, s, p (1 β€ k, n, s, p β€ 10^4) β the number of people, the number of airplanes each should make, the number of airplanes that can be made using one sheet and the number of sheets in one pack, respectively.
Output
Print a single integer β the minimum number of packs they should buy.
Examples
Input
5 3 2 3
Output
4
Input
5 3 100 1
Output
5
Note
In the first sample they have to buy 4 packs of paper: there will be 12 sheets in total, and giving 2 sheets to each person is enough to suit everyone's needs.
In the second sample they have to buy a pack for each person as they can't share sheets.
Submitted Solution:
```
k, n, s, p = map(int, input().split())
l = 0
r = 10 ** 9
while (r - l != 1):
m = (l + r) // 2
if ((p * m // k) * s >= n):
r = m
else:
l = m
print(r)
``` | instruction | 0 | 23,534 | 23 | 47,068 |
Yes | output | 1 | 23,534 | 23 | 47,069 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
To make a paper airplane, one has to use a rectangular piece of paper. From a sheet of standard size you can make s airplanes.
A group of k people decided to make n airplanes each. They are going to buy several packs of paper, each of them containing p sheets, and then distribute the sheets between the people. Each person should have enough sheets to make n airplanes. How many packs should they buy?
Input
The only line contains four integers k, n, s, p (1 β€ k, n, s, p β€ 10^4) β the number of people, the number of airplanes each should make, the number of airplanes that can be made using one sheet and the number of sheets in one pack, respectively.
Output
Print a single integer β the minimum number of packs they should buy.
Examples
Input
5 3 2 3
Output
4
Input
5 3 100 1
Output
5
Note
In the first sample they have to buy 4 packs of paper: there will be 12 sheets in total, and giving 2 sheets to each person is enough to suit everyone's needs.
In the second sample they have to buy a pack for each person as they can't share sheets.
Submitted Solution:
```
from math import ceil
k, n, s, p = [int(i) for i in input().split()]
sheets_needed = int(ceil(n / s)) * k
print(int(ceil(sheets_needed / p)))
``` | instruction | 0 | 23,535 | 23 | 47,070 |
Yes | output | 1 | 23,535 | 23 | 47,071 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
To make a paper airplane, one has to use a rectangular piece of paper. From a sheet of standard size you can make s airplanes.
A group of k people decided to make n airplanes each. They are going to buy several packs of paper, each of them containing p sheets, and then distribute the sheets between the people. Each person should have enough sheets to make n airplanes. How many packs should they buy?
Input
The only line contains four integers k, n, s, p (1 β€ k, n, s, p β€ 10^4) β the number of people, the number of airplanes each should make, the number of airplanes that can be made using one sheet and the number of sheets in one pack, respectively.
Output
Print a single integer β the minimum number of packs they should buy.
Examples
Input
5 3 2 3
Output
4
Input
5 3 100 1
Output
5
Note
In the first sample they have to buy 4 packs of paper: there will be 12 sheets in total, and giving 2 sheets to each person is enough to suit everyone's needs.
In the second sample they have to buy a pack for each person as they can't share sheets.
Submitted Solution:
```
def main():
k, n, s, p = map(int, input().split())
sheets = (n + s - 1) // s
packs = (sheets * k + p - 1) // p
print(packs)
main()
``` | instruction | 0 | 23,536 | 23 | 47,072 |
Yes | output | 1 | 23,536 | 23 | 47,073 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
To make a paper airplane, one has to use a rectangular piece of paper. From a sheet of standard size you can make s airplanes.
A group of k people decided to make n airplanes each. They are going to buy several packs of paper, each of them containing p sheets, and then distribute the sheets between the people. Each person should have enough sheets to make n airplanes. How many packs should they buy?
Input
The only line contains four integers k, n, s, p (1 β€ k, n, s, p β€ 10^4) β the number of people, the number of airplanes each should make, the number of airplanes that can be made using one sheet and the number of sheets in one pack, respectively.
Output
Print a single integer β the minimum number of packs they should buy.
Examples
Input
5 3 2 3
Output
4
Input
5 3 100 1
Output
5
Note
In the first sample they have to buy 4 packs of paper: there will be 12 sheets in total, and giving 2 sheets to each person is enough to suit everyone's needs.
In the second sample they have to buy a pack for each person as they can't share sheets.
Submitted Solution:
```
from math import ceil
k, n, s, p = map(int, input().split())
lo = 1
hi = 1000000000000
cm = int(ceil(n / s))
while lo <= hi:
ans = (lo + hi) // 2
if (ans * p) // k >= cm and ((ans - 1) * p) // k < cm:
print(ans)
exit(0)
elif (ans * p) // k >= cm:
hi = ans - 1
else:
lo = ans + 1
``` | instruction | 0 | 23,537 | 23 | 47,074 |
Yes | output | 1 | 23,537 | 23 | 47,075 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
To make a paper airplane, one has to use a rectangular piece of paper. From a sheet of standard size you can make s airplanes.
A group of k people decided to make n airplanes each. They are going to buy several packs of paper, each of them containing p sheets, and then distribute the sheets between the people. Each person should have enough sheets to make n airplanes. How many packs should they buy?
Input
The only line contains four integers k, n, s, p (1 β€ k, n, s, p β€ 10^4) β the number of people, the number of airplanes each should make, the number of airplanes that can be made using one sheet and the number of sheets in one pack, respectively.
Output
Print a single integer β the minimum number of packs they should buy.
Examples
Input
5 3 2 3
Output
4
Input
5 3 100 1
Output
5
Note
In the first sample they have to buy 4 packs of paper: there will be 12 sheets in total, and giving 2 sheets to each person is enough to suit everyone's needs.
In the second sample they have to buy a pack for each person as they can't share sheets.
Submitted Solution:
```
[k,n,s,p]=map(int,input().split())
x=n//s
if x==0:
x=1
if n&s>0:
x=x+1
y=(x*k)//p
if (x*k)%p>0:
y=y+1
print(y)
``` | instruction | 0 | 23,538 | 23 | 47,076 |
No | output | 1 | 23,538 | 23 | 47,077 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
To make a paper airplane, one has to use a rectangular piece of paper. From a sheet of standard size you can make s airplanes.
A group of k people decided to make n airplanes each. They are going to buy several packs of paper, each of them containing p sheets, and then distribute the sheets between the people. Each person should have enough sheets to make n airplanes. How many packs should they buy?
Input
The only line contains four integers k, n, s, p (1 β€ k, n, s, p β€ 10^4) β the number of people, the number of airplanes each should make, the number of airplanes that can be made using one sheet and the number of sheets in one pack, respectively.
Output
Print a single integer β the minimum number of packs they should buy.
Examples
Input
5 3 2 3
Output
4
Input
5 3 100 1
Output
5
Note
In the first sample they have to buy 4 packs of paper: there will be 12 sheets in total, and giving 2 sheets to each person is enough to suit everyone's needs.
In the second sample they have to buy a pack for each person as they can't share sheets.
Submitted Solution:
```
k,n,s,p = map(int,input().split())
print(((n//s)*k)//p)
``` | instruction | 0 | 23,539 | 23 | 47,078 |
No | output | 1 | 23,539 | 23 | 47,079 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
To make a paper airplane, one has to use a rectangular piece of paper. From a sheet of standard size you can make s airplanes.
A group of k people decided to make n airplanes each. They are going to buy several packs of paper, each of them containing p sheets, and then distribute the sheets between the people. Each person should have enough sheets to make n airplanes. How many packs should they buy?
Input
The only line contains four integers k, n, s, p (1 β€ k, n, s, p β€ 10^4) β the number of people, the number of airplanes each should make, the number of airplanes that can be made using one sheet and the number of sheets in one pack, respectively.
Output
Print a single integer β the minimum number of packs they should buy.
Examples
Input
5 3 2 3
Output
4
Input
5 3 100 1
Output
5
Note
In the first sample they have to buy 4 packs of paper: there will be 12 sheets in total, and giving 2 sheets to each person is enough to suit everyone's needs.
In the second sample they have to buy a pack for each person as they can't share sheets.
Submitted Solution:
```
import math
k,n,s,p=map(int,input().split())
if p==1:
print(k)
else:
a=math.ceil(n/s)
print(math.ceil((k*a)/p))
``` | instruction | 0 | 23,540 | 23 | 47,080 |
No | output | 1 | 23,540 | 23 | 47,081 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
To make a paper airplane, one has to use a rectangular piece of paper. From a sheet of standard size you can make s airplanes.
A group of k people decided to make n airplanes each. They are going to buy several packs of paper, each of them containing p sheets, and then distribute the sheets between the people. Each person should have enough sheets to make n airplanes. How many packs should they buy?
Input
The only line contains four integers k, n, s, p (1 β€ k, n, s, p β€ 10^4) β the number of people, the number of airplanes each should make, the number of airplanes that can be made using one sheet and the number of sheets in one pack, respectively.
Output
Print a single integer β the minimum number of packs they should buy.
Examples
Input
5 3 2 3
Output
4
Input
5 3 100 1
Output
5
Note
In the first sample they have to buy 4 packs of paper: there will be 12 sheets in total, and giving 2 sheets to each person is enough to suit everyone's needs.
In the second sample they have to buy a pack for each person as they can't share sheets.
Submitted Solution:
```
k, n, s, p = map(int,input().split())
print(((n+s-1)//s*k+p-1)/p)
``` | instruction | 0 | 23,541 | 23 | 47,082 |
No | output | 1 | 23,541 | 23 | 47,083 |
Provide a correct Python 3 solution for this coding contest problem.
Takahashi has N sticks that are distinguishable from each other. The length of the i-th stick is L_i.
He is going to form a triangle using three of these sticks. Let a, b, and c be the lengths of the three sticks used. Here, all of the following conditions must be satisfied:
* a < b + c
* b < c + a
* c < a + b
How many different triangles can be formed? Two triangles are considered different when there is a stick used in only one of them.
Constraints
* All values in input are integers.
* 3 \leq N \leq 2 \times 10^3
* 1 \leq L_i \leq 10^3
Input
Input is given from Standard Input in the following format:
N
L_1 L_2 ... L_N
Constraints
Print the number of different triangles that can be formed.
Constraints
Print the number of different triangles that can be formed.
Input
Input is given from Standard Input in the following format:
N
L_1 L_2 ... L_N
Examples
Input
4
3 4 2 1
Output
1
Input
3
1 1000 1
Output
0
Input
7
218 786 704 233 645 728 389
Output
23 | instruction | 0 | 23,590 | 23 | 47,180 |
"Correct Solution:
```
import bisect
n=int(input())
l=sorted(list(map(int,input().split())))
ans=0
for i in range(n):
for j in range(i+1,n):
temp=l[i]+l[j]
ans+=(bisect.bisect_left(l,temp)-j-1)
print(ans)
``` | output | 1 | 23,590 | 23 | 47,181 |
Provide a correct Python 3 solution for this coding contest problem.
Takahashi has N sticks that are distinguishable from each other. The length of the i-th stick is L_i.
He is going to form a triangle using three of these sticks. Let a, b, and c be the lengths of the three sticks used. Here, all of the following conditions must be satisfied:
* a < b + c
* b < c + a
* c < a + b
How many different triangles can be formed? Two triangles are considered different when there is a stick used in only one of them.
Constraints
* All values in input are integers.
* 3 \leq N \leq 2 \times 10^3
* 1 \leq L_i \leq 10^3
Input
Input is given from Standard Input in the following format:
N
L_1 L_2 ... L_N
Constraints
Print the number of different triangles that can be formed.
Constraints
Print the number of different triangles that can be formed.
Input
Input is given from Standard Input in the following format:
N
L_1 L_2 ... L_N
Examples
Input
4
3 4 2 1
Output
1
Input
3
1 1000 1
Output
0
Input
7
218 786 704 233 645 728 389
Output
23 | instruction | 0 | 23,591 | 23 | 47,182 |
"Correct Solution:
```
import bisect
n=int(input())
lis=list(map(int, input().split()))
lis.sort()
out=0
for i in range(n):
for j in range(1+i,n):
out+=bisect.bisect_left(lis,lis[i]+lis[j])-j-1
print(out)
``` | output | 1 | 23,591 | 23 | 47,183 |
Provide a correct Python 3 solution for this coding contest problem.
Takahashi has N sticks that are distinguishable from each other. The length of the i-th stick is L_i.
He is going to form a triangle using three of these sticks. Let a, b, and c be the lengths of the three sticks used. Here, all of the following conditions must be satisfied:
* a < b + c
* b < c + a
* c < a + b
How many different triangles can be formed? Two triangles are considered different when there is a stick used in only one of them.
Constraints
* All values in input are integers.
* 3 \leq N \leq 2 \times 10^3
* 1 \leq L_i \leq 10^3
Input
Input is given from Standard Input in the following format:
N
L_1 L_2 ... L_N
Constraints
Print the number of different triangles that can be formed.
Constraints
Print the number of different triangles that can be formed.
Input
Input is given from Standard Input in the following format:
N
L_1 L_2 ... L_N
Examples
Input
4
3 4 2 1
Output
1
Input
3
1 1000 1
Output
0
Input
7
218 786 704 233 645 728 389
Output
23 | instruction | 0 | 23,592 | 23 | 47,184 |
"Correct Solution:
```
import bisect
N =int(input())
L = sorted(list(map(int,input().split())))
cnt = 0
for i in range(N):
for j in range(i+1,N):
cnt += bisect.bisect_left(L,L[i]+L[j]) - (j+1)
print(cnt)
``` | output | 1 | 23,592 | 23 | 47,185 |
Provide a correct Python 3 solution for this coding contest problem.
Takahashi has N sticks that are distinguishable from each other. The length of the i-th stick is L_i.
He is going to form a triangle using three of these sticks. Let a, b, and c be the lengths of the three sticks used. Here, all of the following conditions must be satisfied:
* a < b + c
* b < c + a
* c < a + b
How many different triangles can be formed? Two triangles are considered different when there is a stick used in only one of them.
Constraints
* All values in input are integers.
* 3 \leq N \leq 2 \times 10^3
* 1 \leq L_i \leq 10^3
Input
Input is given from Standard Input in the following format:
N
L_1 L_2 ... L_N
Constraints
Print the number of different triangles that can be formed.
Constraints
Print the number of different triangles that can be formed.
Input
Input is given from Standard Input in the following format:
N
L_1 L_2 ... L_N
Examples
Input
4
3 4 2 1
Output
1
Input
3
1 1000 1
Output
0
Input
7
218 786 704 233 645 728 389
Output
23 | instruction | 0 | 23,593 | 23 | 47,186 |
"Correct Solution:
```
import bisect
n=int(input())
l=sorted(map(int,input().split()))
ans=0
for i in range(n):
for j in range(i+1,n):
idx=bisect.bisect_left(l,l[i]+l[j])
ans+=max(0,idx-j-1)
print(ans)
``` | output | 1 | 23,593 | 23 | 47,187 |
Provide a correct Python 3 solution for this coding contest problem.
Takahashi has N sticks that are distinguishable from each other. The length of the i-th stick is L_i.
He is going to form a triangle using three of these sticks. Let a, b, and c be the lengths of the three sticks used. Here, all of the following conditions must be satisfied:
* a < b + c
* b < c + a
* c < a + b
How many different triangles can be formed? Two triangles are considered different when there is a stick used in only one of them.
Constraints
* All values in input are integers.
* 3 \leq N \leq 2 \times 10^3
* 1 \leq L_i \leq 10^3
Input
Input is given from Standard Input in the following format:
N
L_1 L_2 ... L_N
Constraints
Print the number of different triangles that can be formed.
Constraints
Print the number of different triangles that can be formed.
Input
Input is given from Standard Input in the following format:
N
L_1 L_2 ... L_N
Examples
Input
4
3 4 2 1
Output
1
Input
3
1 1000 1
Output
0
Input
7
218 786 704 233 645 728 389
Output
23 | instruction | 0 | 23,594 | 23 | 47,188 |
"Correct Solution:
```
n = int(input())
a = sorted([int(x) for x in input().split()])
ret = 0
for i in range(n-1, 0, -1):
l = 0
r = i-1
while l<r:
if a[l]+a[r]>a[i]:
ret += r - l
r -= 1
else:
l += 1
print(ret)
``` | output | 1 | 23,594 | 23 | 47,189 |
Provide a correct Python 3 solution for this coding contest problem.
Takahashi has N sticks that are distinguishable from each other. The length of the i-th stick is L_i.
He is going to form a triangle using three of these sticks. Let a, b, and c be the lengths of the three sticks used. Here, all of the following conditions must be satisfied:
* a < b + c
* b < c + a
* c < a + b
How many different triangles can be formed? Two triangles are considered different when there is a stick used in only one of them.
Constraints
* All values in input are integers.
* 3 \leq N \leq 2 \times 10^3
* 1 \leq L_i \leq 10^3
Input
Input is given from Standard Input in the following format:
N
L_1 L_2 ... L_N
Constraints
Print the number of different triangles that can be formed.
Constraints
Print the number of different triangles that can be formed.
Input
Input is given from Standard Input in the following format:
N
L_1 L_2 ... L_N
Examples
Input
4
3 4 2 1
Output
1
Input
3
1 1000 1
Output
0
Input
7
218 786 704 233 645 728 389
Output
23 | instruction | 0 | 23,595 | 23 | 47,190 |
"Correct Solution:
```
import bisect
n=int(input())
l=list(map(int,input().split()))
l.sort()
ct=0
for i in range(n):
for j in range(i+1,n):
ct+=bisect.bisect_left(l,l[i]+l[j])-j-1
print(ct)
``` | output | 1 | 23,595 | 23 | 47,191 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.