結果

問題 No.505 カードの数式2
ユーザー tentententen
提出日時 2020-09-11 08:34:48
言語 Java21
(openjdk 21)
結果
WA  
実行時間 -
コード長 883 bytes
コンパイル時間 3,677 ms
コンパイル使用メモリ 72,140 KB
実行使用メモリ 57,192 KB
最終ジャッジ日時 2023-08-26 06:54:27
合計ジャッジ時間 9,602 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 121 ms
55,780 KB
testcase_01 AC 123 ms
56,140 KB
testcase_02 AC 125 ms
55,776 KB
testcase_03 AC 124 ms
56,004 KB
testcase_04 AC 121 ms
55,688 KB
testcase_05 AC 121 ms
55,520 KB
testcase_06 AC 122 ms
55,756 KB
testcase_07 AC 124 ms
56,244 KB
testcase_08 AC 123 ms
56,048 KB
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 AC 122 ms
55,540 KB
testcase_13 WA -
testcase_14 WA -
testcase_15 AC 120 ms
53,708 KB
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 AC 123 ms
55,880 KB
testcase_20 AC 124 ms
55,844 KB
testcase_21 AC 123 ms
56,152 KB
testcase_22 WA -
testcase_23 WA -
testcase_24 WA -
testcase_25 WA -
testcase_26 WA -
testcase_27 AC 122 ms
55,884 KB
testcase_28 WA -
testcase_29 WA -
testcase_30 WA -
testcase_31 WA -
権限があれば一括ダウンロードができます

ソースコード

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 = 0;
    	long min = 0;
    	for (int i = 0; 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);
    	    max = nextMax;
    	    min = nextMin;
    	}
    	System.out.println(max);
	}
}
0