QOJ.ac

QOJ

Time Limit: 1 s Memory Limit: 1024 MB Total points: 100

#3002. Busy Board

統計

Problem Description

Remember the busy boards for toddlers that have an array of holes into which to hammer pegs of various shapes? There’s a new, electronic version. The board consists of a $\text{2D}$ grid of pegs. Each peg on the board can be either $\text{up}$ or $\text{down}$, but not both simultaneously. You can pick any peg that is currently up, and “hammer” it down. This will push that peg down, and also raise all of the other pegs in its row, and its column, regardless of their current state. You cannot “hammer” a peg that is down (well, maybe you can, but it will have no effect). Those poor kids will never get all the pegs down at one time!

This example shows what happens when the top right peg is “hammered.” ($\circ = \text{up}$, $\bullet = \text{down}$)

A substitute teacher wants to challenge her class. She uses the “Teacher Mode” to set up the board in a particular configuration, and then asks her students to see if they can get the board to a second configuration by hammering some (perhaps none) of the pegs.

That may be too tough of a problem for toddlers, but maybe you can handle it.

Input

Each test case will begin with a line with two space-separated integers $r$ and $c$ ($1 \leq r, c \leq 1,000$), which are the dimensions of the board.

Each of the next $r$ lines will have exactly $c$ characters, consisting only of capital ‘$\texttt{O}$’ (representing a peg that is up), capital ‘$\texttt{X}$’ (representing a peg that is down), and no spaces or other characters. This is the starting configuration.

Following this, each of the next $r$ lines will have exactly $c$ characters, consisting only of capital ‘$\texttt{O}$’(representing a peg that is up), capital ‘$\texttt{X}$’ (representing a peg that is down), and no spaces or other characters. This is the target configuration

Output

Output a single integer, $1$ if it is possible to reach the target configuration from the starting configuration, and $0$ if it is impossible.

Samples

Sample Input 1

4 2
XO
OX
XO
OX
OX
OO
XO
OO

Sample Output 1

1

Sample Input 2

2 4
XXXX
XXXX
XOOO
OOOO

Sample Output 2

0
About Issues

We understand that our problem archive is not perfect. If you find any issues with the problem, including the statement, scoring configuration, time/memory limits, test cases, etc.

You may use this form to submit an issue regarding the problem. A problem moderator will review your issue and proceed it properly.

STOP! Before you submit an issue, please READ the following guidelines:

  1. This is not a place to publish a discussion, editorial, or requests to debug your code. Your issue will only be visible by you and problem moderators. Other users will not be able to view or reply your issues.
  2. Do not submit duplicated issues. If you have already submitted one, please wait for an moderator to review it. Submitting multiple issues will not speed up the review process and might cause your account to be banned.
  3. Issues must be filed in English or Chinese only.
  4. Be sure your issue is related to this problem. If you need to submit an issue regarding another problem, contest, category, etc., you should submit it to the corresponding page.

Active Issues 0

No issues in this category.

Closed/Resolved Issues 0

No issues in this category.