結果

問題 No.505 カードの数式2
ユーザー tentententen
提出日時 2020-09-11 08:38:50
言語 Java21
(openjdk 21)
結果
AC  
実行時間 115 ms / 2,000 ms
コード長 1,134 bytes
コンパイル時間 3,589 ms
コンパイル使用メモリ 73,576 KB
実行使用メモリ 56,540 KB
最終ジャッジ日時 2023-08-26 07:03:37
合計ジャッジ時間 7,321 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 115 ms
55,868 KB
testcase_01 AC 111 ms
55,884 KB
testcase_02 AC 110 ms
55,704 KB
testcase_03 AC 113 ms
55,640 KB
testcase_04 AC 113 ms
55,844 KB
testcase_05 AC 112 ms
55,904 KB
testcase_06 AC 109 ms
55,804 KB
testcase_07 AC 110 ms
56,096 KB
testcase_08 AC 114 ms
55,772 KB
testcase_09 AC 111 ms
55,996 KB
testcase_10 AC 108 ms
56,044 KB
testcase_11 AC 109 ms
56,060 KB
testcase_12 AC 109 ms
55,620 KB
testcase_13 AC 111 ms
55,756 KB
testcase_14 AC 108 ms
55,864 KB
testcase_15 AC 109 ms
55,888 KB
testcase_16 AC 109 ms
55,868 KB
testcase_17 AC 109 ms
55,888 KB
testcase_18 AC 108 ms
55,600 KB
testcase_19 AC 110 ms
56,004 KB
testcase_20 AC 111 ms
55,812 KB
testcase_21 AC 113 ms
55,616 KB
testcase_22 AC 110 ms
55,976 KB
testcase_23 AC 111 ms
55,556 KB
testcase_24 AC 111 ms
55,776 KB
testcase_25 AC 111 ms
56,348 KB
testcase_26 AC 111 ms
55,612 KB
testcase_27 AC 112 ms
55,716 KB
testcase_28 AC 109 ms
55,860 KB
testcase_29 AC 114 ms
56,540 KB
testcase_30 AC 110 ms
55,884 KB
testcase_31 AC 113 ms
55,804 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.*;

public class Main {
	public static void main (String[] args) {
    	Scanner sc = new Scanner(System.in);
    	int n = sc.nextInt();
    	long max = sc.nextInt();
    	long min = max;
    	for (int i = 1; i < n; i++) {
    	    long x = sc.nextInt();
    	    long nextMax = max + x;
    	    nextMax = Math.max(nextMax, max - x);
    	    nextMax = Math.max(nextMax, max * x);
    	    nextMax = Math.max(nextMax, min + x);
    	    nextMax = Math.max(nextMax, min - x);
    	    nextMax = Math.max(nextMax, min * x);
    	    long nextMin = max + x;
    	    nextMin = Math.min(nextMin, max - x);
    	    nextMin = Math.min(nextMin, max * x);
    	    nextMin = Math.min(nextMin, min + x);
    	    nextMin = Math.min(nextMin, min - x);
    	    nextMin = Math.min(nextMin, min * x);
    	    if (x != 0) {
        	    nextMax = Math.max(nextMax, max / x);
        	    nextMax = Math.max(nextMax, min / x);
        	    nextMin = Math.min(nextMin, max / x);
        	    nextMin = Math.min(nextMin, min / x);
    	    }
    	    max = nextMax;
    	    min = nextMin;
    	}
    	System.out.println(max);
	}
}
0