結果

問題 No.505 カードの数式2
ユーザー htensaihtensai
提出日時 2019-12-26 11:58:53
言語 Java21
(openjdk 21)
結果
AC  
実行時間 141 ms / 2,000 ms
コード長 1,229 bytes
コンパイル時間 2,280 ms
コンパイル使用メモリ 77,392 KB
実行使用メモリ 54,348 KB
最終ジャッジ日時 2024-04-14 09:35:14
合計ジャッジ時間 7,980 ms
ジャッジサーバーID
(参考情報)
judge2 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 139 ms
54,104 KB
testcase_01 AC 138 ms
54,140 KB
testcase_02 AC 140 ms
54,120 KB
testcase_03 AC 137 ms
54,096 KB
testcase_04 AC 137 ms
54,348 KB
testcase_05 AC 138 ms
53,920 KB
testcase_06 AC 139 ms
54,144 KB
testcase_07 AC 136 ms
54,276 KB
testcase_08 AC 138 ms
54,096 KB
testcase_09 AC 136 ms
54,316 KB
testcase_10 AC 136 ms
54,152 KB
testcase_11 AC 132 ms
54,300 KB
testcase_12 AC 141 ms
54,028 KB
testcase_13 AC 135 ms
54,120 KB
testcase_14 AC 128 ms
52,820 KB
testcase_15 AC 135 ms
54,284 KB
testcase_16 AC 134 ms
53,880 KB
testcase_17 AC 139 ms
53,952 KB
testcase_18 AC 140 ms
54,172 KB
testcase_19 AC 139 ms
54,312 KB
testcase_20 AC 134 ms
54,120 KB
testcase_21 AC 135 ms
54,192 KB
testcase_22 AC 130 ms
54,124 KB
testcase_23 AC 135 ms
54,304 KB
testcase_24 AC 136 ms
53,876 KB
testcase_25 AC 134 ms
54,260 KB
testcase_26 AC 135 ms
54,276 KB
testcase_27 AC 134 ms
54,124 KB
testcase_28 AC 137 ms
54,104 KB
testcase_29 AC 139 ms
54,220 KB
testcase_30 AC 135 ms
54,120 KB
testcase_31 AC 137 ms
54,296 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 tmax = Long.MIN_VALUE;
            long tmin = Long.MAX_VALUE;
            long x = sc.nextInt();
            tmax = Math.max(tmax, max + x);
            tmax = Math.max(tmax, max - x);
            tmax = Math.max(tmax, max * x);
            tmin = Math.min(tmin, max + x);
            tmin = Math.min(tmin, max - x);
            tmin = Math.min(tmin, max * x);
            tmax = Math.max(tmax, min + x);
            tmax = Math.max(tmax, min - x);
            tmax = Math.max(tmax, min * x);
            tmin = Math.min(tmin, min + x);
            tmin = Math.min(tmin, min - x);
            tmin = Math.min(tmin, min * x);
            if (x != 0) {
                tmax = Math.max(tmax, max / x);
                tmin = Math.min(tmin, max / x);
                tmax = Math.max(tmax, min / x);
                tmin = Math.min(tmin, min / x);
            }
            max = tmax;
            min = tmin;
        }
        System.out.println(max);
    }
}
0