The time complexity has to be as less as possible (nlogn or n at best, no n^2). Apply divide and conquer algorithm in the problem. Make sure ALL test cases return expected outputs by providing output screenshots. Hint: Use bisection method / binarySearch Output Format The output contains one line with a single integer: the minimum instability you can achieve modulo 10^9 + 7. Sample Input 0 2 1 1 2 3 4 3 Sample Output 0 30 Sample Input 1 2 2 2 1 4 2 1 5 1 Sample Output 1 40 Sample Input 2 2 5 6 4 6 7 0 1 3 2 0 6 1 6 2 2 Sample Output 2 214 The actual code import java.io.*; import java.util.*; public class Solution {     public static final long MOD = 1000000007L;     public static void main(String[] args) throws Exception {         BufferedReader br = new BufferedReader(             new InputStreamReader(System.in)         );         String[] parts = br.readLine().trim().split(" ");         int l = Integer.parseInt(parts[0]);         int w = Integer.parseInt(parts[1]);         int d = Integer.parseInt(parts[2]);         int[] length_costs = new int[l];         int[] width_costs = new int[w];         int[] depth_costs = new int[d];         for(int i = 0; i < l; i++) {             length_costs[i] = Integer.parseInt(br.readLine().trim());         }         for(int i = 0; i < w; i++) {             width_costs[i] = Integer.parseInt(br.readLine().trim());         }         for(int i = 0; i < d; i++) {             depth_costs[i] = Integer.parseInt(br.readLine().trim());         }                  System.out.println(solve(l,w,d,length_costs,width_costs,depth_costs));     }     /*     This function solves a test case.     Parameters:     l            : int   - # of length cutting points of quatrum cluster     w            : int   - # of width cutting points of quatrum cluster     d            : int   - # of depth cutting points of quatrum cluster     length_costs : int[] - list of length cutting point instability factors     width_costs  : int[] - list of width cutting point instability factors     depth_costs  : int[] - list of depth cutting point instability factors     Returns:     An integer indicating the smallest attainable instability after cutting the      cluster down to 1 x 1 x 1 cubes     */     public static long solve(int l, int w, int d, int[] length_costs,                               int[] width_costs, int[] depth_costs) {         // TODO     }

Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
icon
Related questions
Question

Information is present in the screenshot and below. Based on that need help in solving the code for this problem in java. The time complexity has to be as less as possible (nlogn or n at best, no n^2). Apply divide and conquer algorithm in the problem. Make sure ALL test cases return expected outputs by providing output screenshots.

Hint: Use bisection method / binarySearch

Output Format
The output contains one line with a single integer: the minimum instability you can achieve modulo 10^9 + 7.

Sample Input 0
2 1 1
2
3
4
3

Sample Output 0
30

Sample Input 1
2 2 2
1
4
2
1
5
1

Sample Output 1
40

Sample Input 2
2 5 6
4
6
7
0
1
3
2
0
6
1
6
2
2

Sample Output 2
214

The actual code

import java.io.*;
import java.util.*;

public class Solution {
    public static final long MOD = 1000000007L;
    public static void main(String[] args) throws Exception {
        BufferedReader br = new BufferedReader(
            new InputStreamReader(System.in)
        );
        String[] parts = br.readLine().trim().split(" ");
        int l = Integer.parseInt(parts[0]);
        int w = Integer.parseInt(parts[1]);
        int d = Integer.parseInt(parts[2]);
        int[] length_costs = new int[l];
        int[] width_costs = new int[w];
        int[] depth_costs = new int[d];

        for(int i = 0; i < l; i++) {
            length_costs[i] = Integer.parseInt(br.readLine().trim());
        }
        for(int i = 0; i < w; i++) {
            width_costs[i] = Integer.parseInt(br.readLine().trim());
        }
        for(int i = 0; i < d; i++) {
            depth_costs[i] = Integer.parseInt(br.readLine().trim());
        }
        
        System.out.println(solve(l,w,d,length_costs,width_costs,depth_costs));
    }

    /*
    This function solves a test case.

    Parameters:
    l            : int   - # of length cutting points of quatrum cluster
    w            : int   - # of width cutting points of quatrum cluster
    d            : int   - # of depth cutting points of quatrum cluster
    length_costs : int[] - list of length cutting point instability factors
    width_costs  : int[] - list of width cutting point instability factors
    depth_costs  : int[] - list of depth cutting point instability factors

    Returns:
    An integer indicating the smallest attainable instability after cutting the 
    cluster down to 1 x 1 x 1 cubes
    */
    public static long solve(int l, int w, int d, int[] length_costs, 
                             int[] width_costs, int[] depth_costs) {
        // TODO
    }
}

If we make the first cut along the first length cutting point, the instability increases by 1 multiplied by the
number of section being cut through. Since this is our first cut, the only section is the entire cluster itself. After
the cut, there are now two sections, lengthwise.
If we make another cut along the length, this is still only cutting through one segment since this cut will be
parallel to the previous cut, and thus will also only cut through one section of the cluster. However, consider if
we cut through the first width cutting point. Since this cut is orthogonal to the initial cut, we are now cutting
through 2 sections of the cluster. Thus, our instability increases by 1 x 2, where 1 is the instability factor of
the first width cutting point, and 2 is the number of sections we are cutting through.
At this point, using one of the length cutting points will cut through 2 sections, since we already cut through
one of the width cutting points. Likewise, using a width cutting point will cut through 2 sections since we
already cut through one of the length cutting points. Consider, however, if we cut using the first depth cutting
point. This now passes through 4 sections, since the cross section was cut into two sections lengthwise, and
two sections widthwise, yielding a total of 4 sections.
You want to cut this entire cube into L W D cubes of size 1 x 1 x 1. Find the minimum instability index
attainable. Since this number can be very large, print it modulo 10⁹ + 7.
Input Format
Input begins with a line containing three space-separated integers: L – 1, W – 1, and D – 1, indicating the
number of length, width, and depth cutting points of the quatrum cluster respectively.
L – 1 lines follow, the ith of which contains №₁,¿, the instability factor of the ith length cutting point.
W - 1 lines follow, the ith of which contains I2,;, the instability factor of the ith width cutting point.
D - 1 lines follow, the ith of which contains I3,;, the instability factor of the ith depth cutting point.
Constraints
1 ≤ L, W, D ≤ 100001
0≤ 11., 12., 13.i < 10⁹
1,2,
Transcribed Image Text:If we make the first cut along the first length cutting point, the instability increases by 1 multiplied by the number of section being cut through. Since this is our first cut, the only section is the entire cluster itself. After the cut, there are now two sections, lengthwise. If we make another cut along the length, this is still only cutting through one segment since this cut will be parallel to the previous cut, and thus will also only cut through one section of the cluster. However, consider if we cut through the first width cutting point. Since this cut is orthogonal to the initial cut, we are now cutting through 2 sections of the cluster. Thus, our instability increases by 1 x 2, where 1 is the instability factor of the first width cutting point, and 2 is the number of sections we are cutting through. At this point, using one of the length cutting points will cut through 2 sections, since we already cut through one of the width cutting points. Likewise, using a width cutting point will cut through 2 sections since we already cut through one of the length cutting points. Consider, however, if we cut using the first depth cutting point. This now passes through 4 sections, since the cross section was cut into two sections lengthwise, and two sections widthwise, yielding a total of 4 sections. You want to cut this entire cube into L W D cubes of size 1 x 1 x 1. Find the minimum instability index attainable. Since this number can be very large, print it modulo 10⁹ + 7. Input Format Input begins with a line containing three space-separated integers: L – 1, W – 1, and D – 1, indicating the number of length, width, and depth cutting points of the quatrum cluster respectively. L – 1 lines follow, the ith of which contains №₁,¿, the instability factor of the ith length cutting point. W - 1 lines follow, the ith of which contains I2,;, the instability factor of the ith width cutting point. D - 1 lines follow, the ith of which contains I3,;, the instability factor of the ith depth cutting point. Constraints 1 ≤ L, W, D ≤ 100001 0≤ 11., 12., 13.i < 10⁹ 1,2,
Algo-Man and his students, belonging to the Class of '25, while studying algorithms and complexity,
accidentally stumbled upon a polynomial time algorithm to one of the illustrious NP-Complete problems. This
caused a Quatro Tunnel to appear in their classroom and Algo-Man and his class were sucked into the Quatro
Realm. This is a realm where only excellence exists, and if you are deemed inferior by the fabric of existence in
this realm, it wilt halt your ontological inertia and you will cease to exist.
Seeking to escape this realm of excellence, Algo-Man and his students are now hatching up a plan to escape
back into their reality. They are able to find the remains of a time and space travelling machine known as the
TARDIS (Time And Relative Dimension In Space) and are seeking to repair it to get back to their world.
One of the components in need of repair is the energy core of the TARDIS. Algo-Man has determined that one
of the cracked quatrum clusters nearby can be broken down and fed to the TARDIS' energy core.
A quatrum cluster is a rectangular prism in dimensions L × W × D. Additionally, due to their inherent
perfection, quatrum clusters always have integral dimensions. The TARDIS only accepts 1 × 1 × 1 cubes.
Algo-Man has determined that the optimal cutting points of the quatrum clusters is at the integer markers.
Using the spare equipment in the TARDIS, Algo-Man has identified the instability factor of each of the cutting
points.
When cutting across the length of the cluster, there are L – 1 cutting points. The ith of these has an
instability factor of I1,i.
When cutting across the width of the cluster, there are W - 1 cutting points. The ith of these has an
instability factor of I2,i.
When cutting across the depth of the cluster, there are D - 1 cutting points. The ith of these has an
instability factor of I3,i.
When cutting through one of the designated cutting points, this increases the instability of the cluster. The
instability increases by the instability factor multiplied by the sections of the cluster being cut through.
Take for example a 4 × 4 × 4 cluster. The instability factors of the length cutting points is 1, 2, 3. The
instability factors of the width cutting points is 1, 3, 5. The instability factors of the depth cutting points is
4, 1, 2.
Transcribed Image Text:Algo-Man and his students, belonging to the Class of '25, while studying algorithms and complexity, accidentally stumbled upon a polynomial time algorithm to one of the illustrious NP-Complete problems. This caused a Quatro Tunnel to appear in their classroom and Algo-Man and his class were sucked into the Quatro Realm. This is a realm where only excellence exists, and if you are deemed inferior by the fabric of existence in this realm, it wilt halt your ontological inertia and you will cease to exist. Seeking to escape this realm of excellence, Algo-Man and his students are now hatching up a plan to escape back into their reality. They are able to find the remains of a time and space travelling machine known as the TARDIS (Time And Relative Dimension In Space) and are seeking to repair it to get back to their world. One of the components in need of repair is the energy core of the TARDIS. Algo-Man has determined that one of the cracked quatrum clusters nearby can be broken down and fed to the TARDIS' energy core. A quatrum cluster is a rectangular prism in dimensions L × W × D. Additionally, due to their inherent perfection, quatrum clusters always have integral dimensions. The TARDIS only accepts 1 × 1 × 1 cubes. Algo-Man has determined that the optimal cutting points of the quatrum clusters is at the integer markers. Using the spare equipment in the TARDIS, Algo-Man has identified the instability factor of each of the cutting points. When cutting across the length of the cluster, there are L – 1 cutting points. The ith of these has an instability factor of I1,i. When cutting across the width of the cluster, there are W - 1 cutting points. The ith of these has an instability factor of I2,i. When cutting across the depth of the cluster, there are D - 1 cutting points. The ith of these has an instability factor of I3,i. When cutting through one of the designated cutting points, this increases the instability of the cluster. The instability increases by the instability factor multiplied by the sections of the cluster being cut through. Take for example a 4 × 4 × 4 cluster. The instability factors of the length cutting points is 1, 2, 3. The instability factors of the width cutting points is 1, 3, 5. The instability factors of the depth cutting points is 4, 1, 2.
Expert Solution
steps

Step by step

Solved in 3 steps

Blurred answer
Knowledge Booster
Problems on numbers
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
Recommended textbooks for you
Database System Concepts
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education