結果

問題 No.505 カードの数式2
ユーザー uafr_csuafr_cs
提出日時 2017-10-30 18:02:09
言語 Java21
(openjdk 21)
結果
WA  
実行時間 -
コード長 1,183 bytes
コンパイル時間 2,672 ms
コンパイル使用メモリ 73,944 KB
実行使用メモリ 56,260 KB
最終ジャッジ日時 2023-08-14 13:14:56
合計ジャッジ時間 7,578 ms
ジャッジサーバーID
(参考情報)
judge14 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 114 ms
39,492 KB
testcase_01 AC 116 ms
39,064 KB
testcase_02 AC 119 ms
39,568 KB
testcase_03 AC 117 ms
39,312 KB
testcase_04 AC 116 ms
39,556 KB
testcase_05 AC 114 ms
39,312 KB
testcase_06 AC 115 ms
39,052 KB
testcase_07 AC 115 ms
39,680 KB
testcase_08 AC 116 ms
39,228 KB
testcase_09 AC 117 ms
39,120 KB
testcase_10 AC 114 ms
39,868 KB
testcase_11 WA -
testcase_12 AC 114 ms
39,700 KB
testcase_13 AC 115 ms
39,512 KB
testcase_14 AC 115 ms
39,904 KB
testcase_15 AC 115 ms
39,588 KB
testcase_16 AC 116 ms
39,300 KB
testcase_17 WA -
testcase_18 AC 115 ms
39,100 KB
testcase_19 AC 116 ms
39,292 KB
testcase_20 AC 123 ms
39,400 KB
testcase_21 AC 115 ms
39,304 KB
testcase_22 AC 118 ms
39,288 KB
testcase_23 AC 118 ms
39,132 KB
testcase_24 AC 118 ms
39,216 KB
testcase_25 AC 117 ms
39,760 KB
testcase_26 AC 119 ms
39,136 KB
testcase_27 AC 119 ms
39,944 KB
testcase_28 AC 116 ms
39,476 KB
testcase_29 WA -
testcase_30 AC 117 ms
40,000 KB
testcase_31 AC 121 ms
39,784 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.Arrays;
import java.util.LinkedList;
import java.util.Scanner;

public class Main {
	
	public static long MOD = 1000000007;
	
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		
		final int N = sc.nextInt();
		long[] as = new long[N];
		for(int i = 0; i < N; i++){ as[i] = sc.nextLong(); }
		
		long min = as[0], max = as[0];
		for(int i = 1; i < N; i++){
			long curr_min = min + as[i];
			long curr_max = max + as[i];
			
			// +
			{
				curr_min = Math.min(curr_min, min + as[i]);
				curr_min = Math.min(curr_min, max + as[i]);
				curr_max = Math.max(curr_max, min + as[i]);
				curr_max = Math.max(curr_max, max + as[i]);
			}
			// -
			{
				curr_min = Math.min(curr_min, min - as[i]);
				curr_min = Math.min(curr_min, max - as[i]);
				curr_max = Math.max(curr_max, min - as[i]);
				curr_max = Math.max(curr_max, max - as[i]);
			}
			// *
			{
				curr_min = Math.min(curr_min, min * as[i]);
				curr_min = Math.min(curr_min, max * as[i]);
				curr_max = Math.max(curr_max, min * as[i]);
				curr_max = Math.max(curr_max, max * as[i]);
			}
			
			min = curr_min;
			max = curr_max;
		}
		
		System.out.println(max);
	}
}
0