█████████ ████ ███░░░░░███ ░░███ ███ ░░░ ██████ ███████ ██████ ██████ ░███ ███░░███ ███░░███ ███░░███ ███░░███ ░███ ░███ ░███░███ ░███ ░███████ ░███ ░███ ░░███ ███░███ ░███░███ ░███ ░███░░░ ░███ ░███ ░░█████████ ░░██████ ░░████████░░██████ ░░██████ ░░░░░░░░░ ░░░░░░ ░░░░░░░░ ░░░░░░ ░░░░░░

Envío 6890

Problema 0x4f - Rectángulo de máxima área dentro de un histograma pequeño

  • Autor: Aaron Zuñiga
  • Fecha: 2023-02-25 07:07:22 UTC (Hace alrededor de 1 año)
Caso # Resultado Tiempo Memoria
#1
Incorrecto
                      Note: Main.java uses unchecked or unsafe operations.
Note: Recompile with -Xlint:unchecked for details.

                    
0.119 s 13 KBi
#2
Incorrecto
                      Note: Main.java uses unchecked or unsafe operations.
Note: Recompile with -Xlint:unchecked for details.

                    
0.064 s 16 KBi
#3
Incorrecto
                      Note: Main.java uses unchecked or unsafe operations.
Note: Recompile with -Xlint:unchecked for details.

                    
0.118 s 13 KBi
#4
Incorrecto
                      Note: Main.java uses unchecked or unsafe operations.
Note: Recompile with -Xlint:unchecked for details.

                    
0.072 s 15 KBi
#5
Incorrecto
                      Note: Main.java uses unchecked or unsafe operations.
Note: Recompile with -Xlint:unchecked for details.

                    
0.075 s 16 KBi
#6
Incorrecto
                      Note: Main.java uses unchecked or unsafe operations.
Note: Recompile with -Xlint:unchecked for details.

                    
0.117 s 13 KBi
#7
Incorrecto
                      Note: Main.java uses unchecked or unsafe operations.
Note: Recompile with -Xlint:unchecked for details.

                    
0.075 s 16 KBi
#8
Incorrecto
                      Note: Main.java uses unchecked or unsafe operations.
Note: Recompile with -Xlint:unchecked for details.

                    
0.063 s 16 KBi
#9
Incorrecto
                      Note: Main.java uses unchecked or unsafe operations.
Note: Recompile with -Xlint:unchecked for details.

                    
0.096 s 13 KBi
#10
Incorrecto
                      Note: Main.java uses unchecked or unsafe operations.
Note: Recompile with -Xlint:unchecked for details.

                    
0.076 s 17 KBi
#11
Incorrecto
                      Note: Main.java uses unchecked or unsafe operations.
Note: Recompile with -Xlint:unchecked for details.

                    
0.077 s 16 KBi
#12
Incorrecto
                      Note: Main.java uses unchecked or unsafe operations.
Note: Recompile with -Xlint:unchecked for details.

                    
0.12 s 13 KBi
#13
Incorrecto
                      Note: Main.java uses unchecked or unsafe operations.
Note: Recompile with -Xlint:unchecked for details.

                    
0.114 s 13 KBi
#14
Incorrecto
                      Note: Main.java uses unchecked or unsafe operations.
Note: Recompile with -Xlint:unchecked for details.

                    
0.15 s 15 KBi
#15
Incorrecto
                      Note: Main.java uses unchecked or unsafe operations.
Note: Recompile with -Xlint:unchecked for details.

                    
0.131 s 13 KBi
#16
Incorrecto
                      Note: Main.java uses unchecked or unsafe operations.
Note: Recompile with -Xlint:unchecked for details.

                    
0.085 s 16 KBi
#17
Incorrecto
                      Note: Main.java uses unchecked or unsafe operations.
Note: Recompile with -Xlint:unchecked for details.

                    
0.087 s 16 KBi
#18
Incorrecto
                      Note: Main.java uses unchecked or unsafe operations.
Note: Recompile with -Xlint:unchecked for details.

                    
0.14 s 14 KBi
#19
Incorrecto
                      Note: Main.java uses unchecked or unsafe operations.
Note: Recompile with -Xlint:unchecked for details.

                    
0.133 s 14 KBi
Puntos totales: 0 / 100

Código

import java.util.Scanner;
import java.util.Stack;
class Main
{
    public static void main(String[] args){
        
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int a[] = new int[n+1];
        Stack stack = new Stack();
        int area = 0;
        int mayor = Integer.MIN_VALUE;
        
        for(int i = 0; i < n; i++){
            a[i] = sc.nextInt();
        }
        
        stack.push(0);
        for(int i = 1; i < a.length; i++){
            if(i == a.length - 1){
                a[i] = 0;
            }
            if(a[i] > a[i-1]){
                stack.push(i);
            }else{
                while(!stack.isEmpty()){
                    System.out.print(stack);
                    int x = (int)stack.peek();
                    if(a[x] <= a[i]){
                        stack.push(i);
                        break;
                    }
                    stack.pop();    
                    if(stack.isEmpty()){
                        area = a[x] * i;
                        if(area > mayor){
                            mayor = area;
                        }
                        stack.push(i);
                        break;
                    }else{
                        area = a[x] * (i - (int)stack.peek() - 1);       
                    }
                    if(area > mayor){
                        mayor = area;
                    }
                }
            }
        }
        System.out.println(mayor);
    }
}