結果

問題 No.505 カードの数式2
ユーザー yagi2yagi2
提出日時 2017-04-21 22:44:07
言語 Java21
(openjdk 21)
結果
WA  
実行時間 -
コード長 1,035 bytes
コンパイル時間 4,441 ms
コンパイル使用メモリ 75,384 KB
実行使用メモリ 57,708 KB
最終ジャッジ日時 2023-09-27 11:28:13
合計ジャッジ時間 6,661 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 110 ms
55,704 KB
testcase_01 AC 108 ms
55,672 KB
testcase_02 AC 107 ms
56,068 KB
testcase_03 AC 105 ms
56,128 KB
testcase_04 AC 107 ms
55,944 KB
testcase_05 AC 109 ms
55,824 KB
testcase_06 AC 107 ms
56,380 KB
testcase_07 AC 110 ms
56,396 KB
testcase_08 AC 102 ms
55,888 KB
testcase_09 WA -
testcase_10 AC 110 ms
55,676 KB
testcase_11 WA -
testcase_12 AC 110 ms
55,628 KB
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 AC 102 ms
55,920 KB
testcase_21 AC 108 ms
56,220 KB
testcase_22 WA -
testcase_23 WA -
testcase_24 WA -
testcase_25 WA -
testcase_26 WA -
testcase_27 WA -
testcase_28 WA -
testcase_29 WA -
testcase_30 WA -
testcase_31 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

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);
    }
}
0