結果
| 問題 | No.505 カードの数式2 | 
| コンテスト | |
| ユーザー |  tenten | 
| 提出日時 | 2020-09-11 08:38:50 | 
| 言語 | Java (openjdk 23) | 
| 結果 | 
                                AC
                                 
                             | 
| 実行時間 | 156 ms / 2,000 ms | 
| コード長 | 1,134 bytes | 
| コンパイル時間 | 3,820 ms | 
| コンパイル使用メモリ | 77,072 KB | 
| 実行使用メモリ | 41,536 KB | 
| 最終ジャッジ日時 | 2024-12-24 22:22:28 | 
| 合計ジャッジ時間 | 9,180 ms | 
| ジャッジサーバーID (参考情報) | judge1 / judge5 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| sample | AC * 3 | 
| other | AC * 29 | 
ソースコード
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);
    	    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);
	}
}
            
            
            
        