結果
問題 |
No.505 カードの数式2
|
ユーザー |
|
提出日時 | 2017-04-21 22:44:07 |
言語 | Java (openjdk 23) |
結果 |
WA
|
実行時間 | - |
コード長 | 1,035 bytes |
コンパイル時間 | 3,695 ms |
コンパイル使用メモリ | 77,860 KB |
実行使用メモリ | 55,956 KB |
最終ジャッジ日時 | 2024-07-20 05:34:09 |
合計ジャッジ時間 | 8,367 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 10 WA * 19 |
ソースコード
import java.util.ArrayList; import java.util.List; import java.util.Scanner; public class Main { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int N = Integer.parseInt(sc.next()); List<Integer> cards = new ArrayList<>(); for (int i = 0; i < N; i++) { cards.add(Integer.parseInt(sc.next())); } int sum = cards.get(0); if (cards.get(0) < 0 && cards.get(1) >= 0) sum = -sum; for (int i = 1; i < N; i++) { if (cards.get(i) < 0) { if (sum < 0) { sum *= cards.get(i); continue; } else { sum -= cards.get(i); continue; } } if (cards.get(i) == 1) { sum += cards.get(i); continue; } if (cards.get(i) > 0) { sum *= cards.get(i); } } System.out.println(sum); } }