report VI VI EN
Register | Login
  • HOME
  • PROBLEMSET
  • ROADMAP
  • COMPETITION
  • TOPIC
  • RANKING
  • GUIDE
  • MASHUP
  • ABOUT
  • CONTACT
  • Problem
  • Submit
  • Results
Bad Apple!! - FlandreOJ: Flandre Online Judge

Bad Apple!!

Time limit: 1000 ms
Memory limit: 256 MB
**Rule 86: If it exists, it can run Bad Apple!** For the Gensokyo's light festival, Reimu prepared a $n \times n$ table of lanterns (a square of $n$ rows and $n$ columns) to play Bad Apple! As we know, a video consists of many frames. The current frame is $A$ and the next frame is $B$. In one second, Reimu can flip the state of an entire row or an entire column of lanterns. Normally, transforming two frames shouldn't take longer than a split second, but we can wait. Calculate the smallest time, in seconds, needed for Reimu to transform frame $A$ into frame $B$, or determine if it would take forever. ### Input - The first line contains an integer $n$. - The next $n$ lines each contain a binary string of length $n$, representing frame $A$, where `1` means the lantern is on and `0` means it's off. - The following $n$ lines each contain a binary string of length $n$, representing frame $B$, with the same meaning. ### Output - Print the minimum time, in seconds, required to transform $A$ into $B$. If time would end before Reimu could do so, print `-1`. ### Constraints - $1 \le n \le 500$. ### Example Input: ``` 3 010 001 110 111 100 000 ``` Output: ``` -1 ```
contest
Wooden sticks
MARISA
Supermarket
That yellow girl not in Mesmerizer
# Announcement
Sweet-colored master path
Trick-OR-Treat
Minecraft was her sweets?
Flowless wells
MST Miko Reimu
Cirno's beloved candies
Subterranean Iridescence
String division
Hotspot
Dictionary
Matching numbers
Arrange flowers
Stolen precious thing
Path counting
Rescue Reisen
Bad Apple!!
Internet provider
Christmas decoration
Chemical reaction
Tree path
Spider web
Topic
Graph
Rating 1800
Solution (1) Solution