結果
| 問題 |
No.505 カードの数式2
|
| コンテスト | |
| ユーザー |
tenten
|
| 提出日時 | 2020-09-11 08:34:48 |
| 言語 | Java (openjdk 23) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 883 bytes |
| コンパイル時間 | 2,455 ms |
| コンパイル使用メモリ | 74,568 KB |
| 実行使用メモリ | 41,776 KB |
| 最終ジャッジ日時 | 2024-12-24 22:07:07 |
| 合計ジャッジ時間 | 8,910 ms |
|
ジャッジサーバーID (参考情報) |
judge5 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 12 WA * 17 |
ソースコード
import java.util.*;
public class Main {
public static void main (String[] args) {
Scanner sc = new Scanner(System.in);
int n = sc.nextInt();
long max = 0;
long min = 0;
for (int i = 0; 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);
max = nextMax;
min = nextMin;
}
System.out.println(max);
}
}
tenten