結果

問題 No.193 筒の数式
ユーザー tentententen
提出日時 2020-10-06 08:49:20
言語 Java21
(openjdk 21)
結果
AC  
実行時間 109 ms / 1,000 ms
コード長 1,498 bytes
コンパイル時間 4,150 ms
コンパイル使用メモリ 73,580 KB
実行使用メモリ 57,704 KB
最終ジャッジ日時 2023-09-27 06:23:16
合計ジャッジ時間 8,225 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 106 ms
55,884 KB
testcase_01 AC 102 ms
55,372 KB
testcase_02 AC 103 ms
55,592 KB
testcase_03 AC 107 ms
55,696 KB
testcase_04 AC 105 ms
55,632 KB
testcase_05 AC 107 ms
55,928 KB
testcase_06 AC 108 ms
55,644 KB
testcase_07 AC 108 ms
55,740 KB
testcase_08 AC 106 ms
55,452 KB
testcase_09 AC 106 ms
55,420 KB
testcase_10 AC 102 ms
55,416 KB
testcase_11 AC 106 ms
55,772 KB
testcase_12 AC 104 ms
55,792 KB
testcase_13 AC 109 ms
55,756 KB
testcase_14 AC 104 ms
55,700 KB
testcase_15 AC 106 ms
57,704 KB
testcase_16 AC 103 ms
55,648 KB
testcase_17 AC 105 ms
55,632 KB
testcase_18 AC 101 ms
55,356 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        char[] arr = sc.next().toCharArray();
        int length = arr.length;
        int max = Integer.MIN_VALUE;
        for (int i = 0; i < length; i++) {
            if (arr[i] == '+' || arr[i] == '-' || arr[(i - 1 + length) % length] == '+' || arr[(i - 1 + length) % length] == '-') {
                continue;
            }
            int sum = 0;
            boolean isPlus = true;
            int tmp = 0;
            for (int j = 0; j < length; j++) {
                if (arr[(i + j) % length] == '+') {
                    if (isPlus) {
                        sum += tmp;
                    } else {
                        sum -= tmp;
                    }
                    isPlus = true;
                    tmp = 0;
                } else if (arr[(i + j) % length] == '-') {
                     if (isPlus) {
                        sum += tmp;
                    } else {
                        sum -= tmp;
                    }
                    isPlus = false;
                    tmp = 0;
                } else {
                    tmp *= 10;
                    tmp += arr[(i + j) % length] - '0';
                }
            }
            if (isPlus) {
                sum += tmp;
            } else {
                sum -= tmp;
            }
            max = Math.max(max, sum);
        }
        System.out.println(max);
    }
}
0