0% found this document useful (0 votes)
299 views8 pages

Volume of Scrapped Cube Material

Chandan's son dropped a N x N x N cube made of smaller cubes into a tank of Coke, getting it dirty, so he scrapped off the smaller cubes that had Coke on any of their six faces to calculate the volume of material removed; the document provides sample input and output showing for a 1x1x1 cube with Coke on all sides, 1 unit is removed. Help is requested to calculate the volume of scrapped material for different sized cubes given their side length N.

Uploaded by

Nitesh Sahni
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
299 views8 pages

Volume of Scrapped Cube Material

Chandan's son dropped a N x N x N cube made of smaller cubes into a tank of Coke, getting it dirty, so he scrapped off the smaller cubes that had Coke on any of their six faces to calculate the volume of material removed; the document provides sample input and output showing for a 1x1x1 cube with Coke on all sides, 1 unit is removed. Help is requested to calculate the volume of scrapped material for different sized cubes given their side length N.

Uploaded by

Nitesh Sahni
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd

Chandan gave his son a cube with side N.

The N X N X N cube is made up of small 1 X 1 X 1


cubes.
Chandan's son is extremely notorious just like him. So he dropped the cube inside a tank filled
with Coke. The cube got totally immersed in that tank. His son was somehow able to take out the
cube from the tank. But sooner his son realized that the cube had gone all dirty because of the
coke. Since Chandan did not like dirty stuffs so his son decided to scrap off all the smaller cubes
that got dirty in the process. A cube that had coke on any one of its six faces was considered to
be dirty and scrapped off. After completing this cumbersome part his son decided to calculate
volume of the scrapped off material. Since Chandan's son is weak in maths he is unable to do it
alone.
Help him in calculating the required volume.
Input:
The first line contains T denoting the number of test cases. Then T lines follow each line
contains N that is the side of cube.
Output:
For each case output the required volume.
Constraints:

1 T 100

1 N 109

Note:
There is no hole or space between 2 smaller cubes.

Sample Input
(Plaintext Link)
2
1
3
Sample Output
(Plaintext Link)
1
26
Explanation
For the first test case : There is only 1 small cube in a 1 x 1 x 1 cube. This cube gets coke on all of
its 6 faces so it needs to be scrapped off. Volume of material that gets scrapped is 1 x 1 x 1 = 1.

Once upon a time, the Earth was a flat rectangular landmass. And there was no life. It was then
that the sky lit up with meteorites falling from out of space. Wherever they fell on the planet, a
river was born, which flowed in all 4 directions (North, East, West, South), till the waters reached
the edge of the Earth and simply fell off into space.
Now, these rivers criss-crossed and divided the one huge landmass (Pangaea) into many smaller
landmasses. Now the lifeless (there was no life, remember?), want to know the number of
landmasses on the planet after all the meteorites have fallen. They also want to know the area of
the smallest and largest landmass. Can you help the lifeless in this question?

Input:
First line contains T which is the number of test cases.
First line of every test case contains 3 integers N, M, Q where N and M are coordinates of the
bottom right corner of the planet and Q is the number of meteorites.
The next Q lines contains the coordinates X, Y where each of the meteorites fell.

Output:
For each test case, output a line containing 3 integers indicating the number of regions, the
minimum area and the maximum area.

Constraints:

1 T 10

2 N, M 105

0 Q 105

1XN

1YM

0 sum of Q over all test cases 105

Scoring:

2 N, M 10, 0 Q 10 : (30 pts)

2 N, M 1000, 0 Q 1000 : (30 pts)

Original Constraints : (40 pts)

Note:

The Earth can be assumed to be a rectangle with top left point as (1,1) and bottom right
point (N,M).

More than one meteorite may have landed at some point.

The rivers may be assumed to be flowing in very thin straight lines parallel to the edges
of the planet.

Sample Input
(Plaintext Link)
1
5 5 2
2 3
4 4
Sample Output
(Plaintext Link)
9 1 4
Explanation
Refer to image below showing all the regions with individual areas.

Problem
Editorial
My Submissions
Shil has an array of N elements A1 , A2, ... ,AN . He also has an integer K. He wants to find out
value of Square Sum for every i from 1 to N-K+1.
The value of Square Sum for certain i is defined as 1 j K (j2 Ai+j-1).
Input:
First line of input consists of two integers N and K. Next line consists of N integers A1 , A2, ... ,AN.
Output:
Output N-K+1 integers where ith integer corresponds to Square Sum of i. Print Square Sum
modulus 109+7.

Constraints:

1 K N 106

1 Ai 109

Sample Input
(Plaintext Link)
6 3
6 9 10 10 4 6
Sample Output
(Plaintext Link)
132 139 86 80

Problem
Editorial
My Submissions
Dilku was thinking about the first time he met his girl... It was indeed a walk to remember. The
romantic weather and her silly talks. He was completely mesmarized. Those were the days!..
Today is his girl's birthday and he wants to make it special for her. He wants to again take her on
a "special walk" that they would remember for the lifetime.
The city in which Dilku lives is represented as an unweighted directed graph with N nodes and M
edges. A "special walk" in the graph starting at node u is a simple path that begins and ends at
the same node u.

Formally, A special walk is path u , a1 , a2 , a3 ,..., ai ,.... , u where ai are distinct and not equal to
u for all i.
Now since Dilku is really nervous about taking his girl out, he needs your help. For every node in
the given graph, tell whether it is possible for Dilku to take his girl on a "special walk" starting at
that node.
Input:
First line of a two space separated integers denoting N and M, the number of nodes and number
of directed edges in the corresponding graph.
Following M lines contain two space separated integers u v denoting a directed edge in the
graph from vertex numbered u to vertex numbered v.
Output:
Print N space separated integers, where ith integer can be either 1 or 0 depicting whether it is
possible to go on a special walk starting at node i or not.
Constraints:

1 N 105

1 M 2 105

1 u, v N

Sample Input
(Plaintext Link)
5 5
1 2
2 3
3 4
4 5
4 2
Sample Output
(Plaintext Link)
0 1 1 1 0
Explanation
In the given graph , there is just one directed cycle : 2-->3-->4-->2. Hence, for all nodes on this
cycle, the answer is yes and for others the answer is no.

Problem
Editorial
My Submissions
Kevin thinks that array A is beautiful if

It contains N positive integers.

It doesn't contain any bad numbers.

There doesn't exist any number x and tuple (y1, y2, ..., yK) such that Ax = Ay1 Ay2 ...
AyK (yi < x).

Kevin knows M bad numbers Bi. Kevin also knows that 1 isn't a bad number. Now he wants to
find lexicographically smallest beautiful array.
Input format:
The first line of the input contains three numbers N, K, M. The next line contains M integers - B i.
Output format:
Output N integers - lexicographically smallest beautiful array.
Constraints:

2 N, K 2 104

0 M 2 104

0 Bi 109

N, M, K 100 in test data worth 20% of all points

M = 0 in test data worth 20% of all points

Sample Input
(Plaintext Link)
7 2 3
4 7 47
Sample Output
(Plaintext Link)
1 2 3 5 8 11 12

Common questions

Powered by AI

The 'Square Sum' for an array segment of length K in Shil’s problem is calculated using the formula ∑ (j^2 * Ai+j-1), where j ranges from 1 to K. This calculation is repeated for each starting index i from 1 to N-K+1. The result for each segment is taken modulo 10^9+7 to handle large numbers as specified by constraints .

Considering the constraints is crucial in the graph problem to efficiently identify potential 'special walks'. With a high number of nodes (up to 105) and edges (up to 2*105), an algorithm should preferably be linear or near-linear in complexity to handle these inputs within a reasonable timeframe. Constraints guide the development of efficient searching techniques, like using DFS to detect cycles in the graph or employing strongly connected components identification algorithms effectively. Ignoring constraints could lead to inefficient solutions that exceed computational limits .

When a cube of side N is immersed in Coke, any smaller cube with any face exposed to the Coke is considered dirty. The exposed cubes are all the cubes on the surface of the larger cube. The volume of scrapped material, therefore, is calculated by removing the volume of the inner cube from the volume of the entire cube. The volume of the N x N x N cube is N^3 and the volume of the inner cube (not exposed) is (N-2)^3 (since it excludes a layer around the edge). Thus, the volume of scrapped material is N^3 - (N-2)^3 for N > 2. For N = 2, all cubes are dirty, so the scrapped material is 8 cubes. For N = 1, it is 1 cube .

Meteorite impacts on a flat Earth surface create rivers that flow in four cardinal directions (North, East, South, West) from the point of impact until water reaches the edge of the Earth, dividing the Earth into distinct landmasses. Each impact point serves as a junction that divides existing regions into smaller sections. The overall number of landmasses is determined by how these rivers intersect and form boundaries around land sections. A meteoric strike might affect existing regions depending on their locations and previous river formations, leading to a net increase or mere reshaping of landmasses .

The challenge in arranging a 'beautiful array' lexicographically involves honoring both the absence of 'bad numbers' and maintaining a product condition where no element x equals a product of a selection of previous elements. This dual requirement adds complexity as it narrows down the set of valid numbers for array construction and forces additional checks for each candidate number, rapidly increasing computational efforts with the addition of constraints like non-zero 'bad numbers'. Additionally, lexicographical arrangements necessitate sorting considerations, further challenging computational efficiency .

A 'special walk' in an unweighted directed graph is possible if there exists a directed cycle that can start and end at the same node. Therefore, for a node to support a 'special walk', it must be part of a directed cycle. This involves checking each node whether it is part of a strongly connected component where a cycle exists. In the given sample, nodes 2, 3, and 4 support special walks because they form a cycle (2-->3-->4-->2).

The size N of the initial cube significantly impacts the extent of scrapped material. For very small N, such as N=1 or N=2, the entire cube or most of it gets scrapped because all or nearly all smaller cubes are exposed to Coke. As N increases, only the surface cubes (sides exposed to Coke) are scrapped, which is governed by the difference N^3 - (N-2)^3. For a large N, the proportion of scrapped material decreases as the internal cubes exponentially increase, greatly lowering the scrapped volume proportion relative to the whole cube .

An efficient approach to solve this geospatial division problem involves using a graph-based depiction of the grid, treating meteorite impact points as nodes with omnidirectional edges symbolizing rivers. A flood-fill algorithm or a union-find data structure can efficiently identify and mark regions created by these divisions. These methods handle large N x M grids dynamically, quickly visualizing connected components broken by river lines. This approach effectively decomposes the grid into landmasses, iterating through impact coordinates to determine areas and count divisions .

In Kevin's array task, excluding bad numbers is crucial to meeting the problem's condition that no number in the array is a product of a subset of other array elements. Bad numbers, often those like small primes or highly composite numbers, could disrupt forming this 'product-free' condition. This exclusion dramatically reduces the solution space, necessitating creative combinatorial thinking to find the lexicographically smallest array, ensuring both conditions are satisfied without any element causatively related to others by multiplication .

To determine if a node can be included in a cycle within a directed graph, conduct a Depth First Search (DFS) or use algorithms for detecting strongly connected components (SCCs). If a node is part of a non-trivial SCC, it means there is a cycle involving that node. This is significant for special walk problems as it establishes whether a closed path (u to u) can incorporate a node, fulfilling the conditions for a special walk. It ensures computational resources are focused on nodes capable of practical cyclical traversal .

You might also like