結果

問題 No.505 カードの数式2
ユーザー tentententen
提出日時 2020-09-11 08:35:48
言語 Java21
(openjdk 21)
結果
WA  
実行時間 -
コード長 896 bytes
コンパイル時間 1,906 ms
コンパイル使用メモリ 71,876 KB
実行使用メモリ 56,556 KB
最終ジャッジ日時 2023-08-26 06:55:35
合計ジャッジ時間 6,974 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 110 ms
56,240 KB
testcase_01 AC 106 ms
56,028 KB
testcase_02 AC 108 ms
56,028 KB
testcase_03 AC 109 ms
56,160 KB
testcase_04 AC 109 ms
55,976 KB
testcase_05 AC 110 ms
55,888 KB
testcase_06 AC 107 ms
56,076 KB
testcase_07 AC 114 ms
56,112 KB
testcase_08 AC 108 ms
55,988 KB
testcase_09 AC 110 ms
56,348 KB
testcase_10 AC 108 ms
55,900 KB
testcase_11 WA -
testcase_12 AC 113 ms
55,844 KB
testcase_13 AC 112 ms
56,036 KB
testcase_14 AC 107 ms
56,172 KB
testcase_15 AC 113 ms
56,112 KB
testcase_16 AC 121 ms
56,416 KB
testcase_17 WA -
testcase_18 AC 118 ms
55,984 KB
testcase_19 AC 118 ms
56,360 KB
testcase_20 AC 111 ms
55,900 KB
testcase_21 AC 109 ms
56,364 KB
testcase_22 AC 110 ms
56,052 KB
testcase_23 AC 110 ms
56,004 KB
testcase_24 AC 114 ms
56,092 KB
testcase_25 AC 112 ms
55,556 KB
testcase_26 AC 111 ms
55,856 KB
testcase_27 AC 112 ms
56,168 KB
testcase_28 AC 111 ms
56,380 KB
testcase_29 WA -
testcase_30 AC 109 ms
55,776 KB
testcase_31 AC 105 ms
55,996 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);
    	    max = nextMax;
    	    min = nextMin;
    	}
    	System.out.println(max);
	}
}
0