結果
| 問題 | No.505 カードの数式2 |
| コンテスト | |
| ユーザー |
tenten
|
| 提出日時 | 2020-09-11 08:38:50 |
| 言語 | Java (openjdk 25.0.2) |
| 結果 |
AC
|
| 実行時間 | 55 ms / 2,000 ms |
| コード長 | 1,134 bytes |
| 記録 | |
| コンパイル時間 | 1,653 ms |
| コンパイル使用メモリ | 82,292 KB |
| 実行使用メモリ | 42,064 KB |
| 最終ジャッジ日時 | 2026-05-30 16:44:02 |
| 合計ジャッジ時間 | 4,644 ms |
|
ジャッジサーバーID (参考情報) |
judge1_0 / judge2_0 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| 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);
}
}
tenten