結果

問題 No.505 カードの数式2
ユーザー htensaihtensai
提出日時 2019-12-26 11:53:14
言語 Java21
(openjdk 21)
結果
WA  
実行時間 -
コード長 997 bytes
コンパイル時間 2,273 ms
コンパイル使用メモリ 77,276 KB
実行使用メモリ 54,784 KB
最終ジャッジ日時 2024-04-14 09:23:24
合計ジャッジ時間 8,130 ms
ジャッジサーバーID
(参考情報)
judge4 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 139 ms
54,280 KB
testcase_01 AC 137 ms
53,912 KB
testcase_02 AC 136 ms
53,856 KB
testcase_03 AC 138 ms
53,976 KB
testcase_04 AC 137 ms
54,072 KB
testcase_05 AC 136 ms
54,248 KB
testcase_06 AC 137 ms
54,000 KB
testcase_07 AC 139 ms
54,164 KB
testcase_08 AC 136 ms
54,124 KB
testcase_09 AC 135 ms
54,096 KB
testcase_10 AC 135 ms
54,156 KB
testcase_11 WA -
testcase_12 AC 140 ms
54,276 KB
testcase_13 AC 139 ms
54,096 KB
testcase_14 AC 138 ms
54,380 KB
testcase_15 AC 141 ms
54,272 KB
testcase_16 AC 141 ms
54,276 KB
testcase_17 WA -
testcase_18 AC 140 ms
54,320 KB
testcase_19 AC 140 ms
53,996 KB
testcase_20 AC 140 ms
54,108 KB
testcase_21 AC 141 ms
54,304 KB
testcase_22 AC 139 ms
54,248 KB
testcase_23 AC 140 ms
54,200 KB
testcase_24 AC 141 ms
53,880 KB
testcase_25 AC 144 ms
54,092 KB
testcase_26 AC 138 ms
54,032 KB
testcase_27 AC 143 ms
54,264 KB
testcase_28 AC 143 ms
54,036 KB
testcase_29 WA -
testcase_30 AC 140 ms
54,784 KB
testcase_31 AC 141 ms
54,060 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);
            max = tmax;
            min = tmin;
        }
        System.out.println(max);
    }
}
0