Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

C . Rectangle Merging time limit per test: 1 second memory limit per test: 2 5 6 megabytes input: standard input output: standard output You

C. Rectangle Merging
time limit per test: 1 second
memory limit per test: 256 megabytes
input: standard input
output: standard output
You are given a rectangles. In the first second, only the first rectangle of size ax by is considered. Then, on the i-th second, a rectangle of size ax by is attached to one of the sides of the current rectangle without overlapping, so that their union remains a rectangle.
For this, the current rectangle and the rectangle of size a, x by must be attached to each other by an equal side. The rectangle could be rotated by 90% and attached to any side of the current rectangle if it had an equal side to it
Based on the information about the sizes of all a rectangles, determine if they can all be merged in such order, and if yes, what possible rectangles could result in the end.
Input
The first line of input contains a single number the number of rectangles (1 n 105)
In the i-th of the following lines, two integers a, and by are given, separated by a space the sizes of the i-th rectangle (1 a, b <1012). Note that the sizes of the rectangles may not fit into a 32-bit Integer type int
Output
In the first line, output a single integer k the number of possible size variations of the final rectangle. If it is not possible

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

More Books

Students also viewed these Databases questions

Question

What are some ways to infl uence an informal team?

Answered: 1 week ago

Question

How do Data Types perform data validation?

Answered: 1 week ago

Question

How does Referential Integrity work?

Answered: 1 week ago