結果

問題 No.505 カードの数式2
ユーザー tentententen
提出日時 2021-11-02 11:01:16
言語 Java21
(openjdk 21)
結果
AC  
実行時間 51 ms / 2,000 ms
コード長 2,033 bytes
コンパイル時間 2,349 ms
コンパイル使用メモリ 77,284 KB
実行使用メモリ 37,160 KB
最終ジャッジ日時 2024-04-19 17:14:40
合計ジャッジ時間 5,031 ms
ジャッジサーバーID
(参考情報)
judge4 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 46 ms
36,692 KB
testcase_01 AC 46 ms
36,968 KB
testcase_02 AC 46 ms
37,160 KB
testcase_03 AC 48 ms
37,104 KB
testcase_04 AC 47 ms
36,936 KB
testcase_05 AC 46 ms
37,048 KB
testcase_06 AC 47 ms
36,452 KB
testcase_07 AC 46 ms
36,468 KB
testcase_08 AC 48 ms
36,468 KB
testcase_09 AC 47 ms
36,768 KB
testcase_10 AC 46 ms
36,748 KB
testcase_11 AC 48 ms
36,964 KB
testcase_12 AC 48 ms
37,012 KB
testcase_13 AC 49 ms
36,936 KB
testcase_14 AC 51 ms
36,620 KB
testcase_15 AC 50 ms
36,768 KB
testcase_16 AC 45 ms
36,976 KB
testcase_17 AC 47 ms
36,452 KB
testcase_18 AC 48 ms
36,676 KB
testcase_19 AC 50 ms
36,588 KB
testcase_20 AC 49 ms
36,692 KB
testcase_21 AC 47 ms
36,884 KB
testcase_22 AC 49 ms
36,864 KB
testcase_23 AC 48 ms
36,928 KB
testcase_24 AC 49 ms
36,856 KB
testcase_25 AC 47 ms
36,744 KB
testcase_26 AC 47 ms
36,860 KB
testcase_27 AC 51 ms
36,680 KB
testcase_28 AC 47 ms
36,972 KB
testcase_29 AC 49 ms
36,796 KB
testcase_30 AC 47 ms
36,588 KB
testcase_31 AC 47 ms
36,864 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.io.*;
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner();
        int n = sc.nextInt();
        long max = sc.nextInt();
        long min = max;
        for (int i = 1; i < n; i++) {
            long nextMax = Long.MIN_VALUE;
            long nextMin = Long.MAX_VALUE;
            int x = sc.nextInt();
            nextMax = Math.max(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);
            nextMin = Math.min(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);
    }
}
class Scanner {
    BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
    StringTokenizer st = new StringTokenizer("");
    
    public Scanner() throws Exception {
        
    }
    
    public int nextInt() throws Exception {
        return Integer.parseInt(next());
    }
    
    public long nextLong() throws Exception {
        return Long.parseLong(next());
    }
    
    public String nextLine() throws Exception {
        return br.readLine();
    }
    
    public String next() throws Exception {
        if (!st.hasMoreTokens()) {
            st = new StringTokenizer(br.readLine());
        }
        return st.nextToken();
    }
}
0