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

Envío 6237

Problema 0xe2 - Detectar overflow al sumar dos enteros de 64 bits

  • Autor: rpedrazacoello
  • Fecha: 2022-05-26 23:45:16 UTC (Hace más de 2 años)
Caso # Resultado Tiempo Memoria
#1
Error en tiempo de ejecución (NZEC)
Exited with error status 1
Exception in thread "main" java.util.InputMismatchException: For input string: "9223372036854775808"
	at java.base/java.util.Scanner.nextLong(Scanner.java:2379)
	at java.base/java.util.Scanner.nextLong(Scanner.java:2328)
	at Main.main(Main.java:7)
0.135 s 14 KBi
#2
Error en tiempo de ejecución (NZEC)
Exited with error status 1
Exception in thread "main" java.util.InputMismatchException: For input string: "9223372036854775808"
	at java.base/java.util.Scanner.nextLong(Scanner.java:2379)
	at java.base/java.util.Scanner.nextLong(Scanner.java:2328)
	at Main.main(Main.java:6)
0.096 s 16 KBi
#3
Error en tiempo de ejecución (NZEC)
Exited with error status 1
Exception in thread "main" java.util.InputMismatchException: For input string: "18446744073709551615"
	at java.base/java.util.Scanner.nextLong(Scanner.java:2379)
	at java.base/java.util.Scanner.nextLong(Scanner.java:2328)
	at Main.main(Main.java:7)
0.1 s 16 KBi
#4
Error en tiempo de ejecución (NZEC)
Exited with error status 1
Exception in thread "main" java.util.InputMismatchException: For input string: "18446744073709551615"
	at java.base/java.util.Scanner.nextLong(Scanner.java:2379)
	at java.base/java.util.Scanner.nextLong(Scanner.java:2328)
	at Main.main(Main.java:6)
0.166 s 13 KBi
#5
Error en tiempo de ejecución (NZEC)
Exited with error status 1
Exception in thread "main" java.util.InputMismatchException: For input string: "18446744073709551615"
	at java.base/java.util.Scanner.nextLong(Scanner.java:2379)
	at java.base/java.util.Scanner.nextLong(Scanner.java:2328)
	at Main.main(Main.java:7)
0.083 s 16 KBi
#6
Error en tiempo de ejecución (NZEC)
Exited with error status 1
Exception in thread "main" java.util.InputMismatchException: For input string: "18446744073709551615"
	at java.base/java.util.Scanner.nextLong(Scanner.java:2379)
	at java.base/java.util.Scanner.nextLong(Scanner.java:2328)
	at Main.main(Main.java:6)
0.081 s 16 KBi
#7
Error en tiempo de ejecución (NZEC)
Exited with error status 1
Exception in thread "main" java.util.InputMismatchException: For input string: "18446744073709551614"
	at java.base/java.util.Scanner.nextLong(Scanner.java:2379)
	at java.base/java.util.Scanner.nextLong(Scanner.java:2328)
	at Main.main(Main.java:7)
0.1 s 17 KBi
#8
Error en tiempo de ejecución (NZEC)
Exited with error status 1
Exception in thread "main" java.util.InputMismatchException: For input string: "18446744073709551614"
	at java.base/java.util.Scanner.nextLong(Scanner.java:2379)
	at java.base/java.util.Scanner.nextLong(Scanner.java:2328)
	at Main.main(Main.java:6)
0.096 s 16 KBi
#9
Error en tiempo de ejecución (NZEC)
Exited with error status 1
Exception in thread "main" java.util.InputMismatchException: For input string: "18446744073709551613"
	at java.base/java.util.Scanner.nextLong(Scanner.java:2379)
	at java.base/java.util.Scanner.nextLong(Scanner.java:2328)
	at Main.main(Main.java:7)
0.088 s 16 KBi
#10
Error en tiempo de ejecución (NZEC)
Exited with error status 1
Exception in thread "main" java.util.InputMismatchException: For input string: "18446744073709551613"
	at java.base/java.util.Scanner.nextLong(Scanner.java:2379)
	at java.base/java.util.Scanner.nextLong(Scanner.java:2328)
	at Main.main(Main.java:6)
0.096 s 16 KBi
#11
Error en tiempo de ejecución (NZEC)
Exited with error status 1
Exception in thread "main" java.util.InputMismatchException: For input string: "18446744073709551611"
	at java.base/java.util.Scanner.nextLong(Scanner.java:2379)
	at java.base/java.util.Scanner.nextLong(Scanner.java:2328)
	at Main.main(Main.java:7)
0.08 s 16 KBi
#12
Error en tiempo de ejecución (NZEC)
Exited with error status 1
Exception in thread "main" java.util.InputMismatchException: For input string: "18446744073709551611"
	at java.base/java.util.Scanner.nextLong(Scanner.java:2379)
	at java.base/java.util.Scanner.nextLong(Scanner.java:2328)
	at Main.main(Main.java:6)
0.094 s 16 KBi
#13
Error en tiempo de ejecución (NZEC)
Exited with error status 1
Exception in thread "main" java.util.InputMismatchException: For input string: "18446744073709551615"
	at java.base/java.util.Scanner.nextLong(Scanner.java:2379)
	at java.base/java.util.Scanner.nextLong(Scanner.java:2328)
	at Main.main(Main.java:6)
0.079 s 16 KBi
#14
Incorrecto
0.142 s 14 KBi
#15
Incorrecto
0.114 s 18 KBi
#16
Incorrecto
0.083 s 16 KBi
#17
Correcto
0.091 s 16 KBi
#18
Correcto
0.092 s 16 KBi
#19
Correcto
0.09 s 16 KBi
#20
Correcto
0.086 s 16 KBi
#21
Correcto
0.163 s 14 KBi
#22
Correcto
0.1 s 16 KBi
#23
Correcto
0.084 s 16 KBi
#24
Error en tiempo de ejecución (NZEC)
Exited with error status 1
Exception in thread "main" java.util.InputMismatchException: For input string: "14279135640914575112"
	at java.base/java.util.Scanner.nextLong(Scanner.java:2379)
	at java.base/java.util.Scanner.nextLong(Scanner.java:2328)
	at Main.main(Main.java:6)
0.087 s 16 KBi
#25
Error en tiempo de ejecución (NZEC)
Exited with error status 1
Exception in thread "main" java.util.InputMismatchException: For input string: "18064753869300860172"
	at java.base/java.util.Scanner.nextLong(Scanner.java:2379)
	at java.base/java.util.Scanner.nextLong(Scanner.java:2328)
	at Main.main(Main.java:6)
0.096 s 16 KBi
#26
Error en tiempo de ejecución (NZEC)
Exited with error status 1
Exception in thread "main" java.util.InputMismatchException: For input string: "11872121203545330973"
	at java.base/java.util.Scanner.nextLong(Scanner.java:2379)
	at java.base/java.util.Scanner.nextLong(Scanner.java:2328)
	at Main.main(Main.java:6)
0.094 s 16 KBi
#27
Error en tiempo de ejecución (NZEC)
Exited with error status 1
Exception in thread "main" java.util.InputMismatchException: For input string: "13317888925631790680"
	at java.base/java.util.Scanner.nextLong(Scanner.java:2379)
	at java.base/java.util.Scanner.nextLong(Scanner.java:2328)
	at Main.main(Main.java:6)
0.083 s 16 KBi
#28
Error en tiempo de ejecución (NZEC)
Exited with error status 1
Exception in thread "main" java.util.InputMismatchException: For input string: "16336507483253313818"
	at java.base/java.util.Scanner.nextLong(Scanner.java:2379)
	at java.base/java.util.Scanner.nextLong(Scanner.java:2328)
	at Main.main(Main.java:6)
0.088 s 16 KBi
#29
Error en tiempo de ejecución (NZEC)
Exited with error status 1
Exception in thread "main" java.util.InputMismatchException: For input string: "13039027971530996040"
	at java.base/java.util.Scanner.nextLong(Scanner.java:2379)
	at java.base/java.util.Scanner.nextLong(Scanner.java:2328)
	at Main.main(Main.java:6)
0.09 s 16 KBi
Puntos totales: 25 / 100

Código

import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        long x  = scanner.nextLong();
        long y = scanner.nextLong();

        long l1 = 2^63;
        long l2 = 2^63 - 1;

        long maxNumber = l1 +l2;
        maxNumber = maxNumber - x;

        if(maxNumber>y){
            System.out.println("Overflow");
        } else {
            System.out.println("Safe");
        }
    }
}