結果
問題 | No.193 筒の数式 |
ユーザー | Grenache |
提出日時 | 2016-02-14 19:32:47 |
言語 | Java21 (openjdk 21) |
結果 |
AC
|
実行時間 | 137 ms / 1,000 ms |
コード長 | 992 bytes |
コンパイル時間 | 5,402 ms |
コンパイル使用メモリ | 79,928 KB |
実行使用メモリ | 57,728 KB |
最終ジャッジ日時 | 2023-10-22 05:18:01 |
合計ジャッジ時間 | 7,145 ms |
ジャッジサーバーID (参考情報) |
judge9 / judge14 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 128 ms
57,420 KB |
testcase_01 | AC | 130 ms
57,448 KB |
testcase_02 | AC | 135 ms
57,544 KB |
testcase_03 | AC | 137 ms
57,720 KB |
testcase_04 | AC | 135 ms
57,404 KB |
testcase_05 | AC | 134 ms
57,496 KB |
testcase_06 | AC | 131 ms
57,512 KB |
testcase_07 | AC | 127 ms
57,464 KB |
testcase_08 | AC | 129 ms
57,204 KB |
testcase_09 | AC | 133 ms
57,724 KB |
testcase_10 | AC | 127 ms
57,364 KB |
testcase_11 | AC | 118 ms
56,248 KB |
testcase_12 | AC | 127 ms
57,304 KB |
testcase_13 | AC | 127 ms
57,540 KB |
testcase_14 | AC | 129 ms
57,728 KB |
testcase_15 | AC | 129 ms
57,464 KB |
testcase_16 | AC | 128 ms
57,204 KB |
testcase_17 | AC | 129 ms
57,540 KB |
testcase_18 | AC | 127 ms
57,252 KB |
ソースコード
import java.util.Scanner; public class Main_yukicoder193 { public static void main(String[] args) { Scanner sc = new Scanner(System.in); String s = sc.next(); int n = s.length(); s = s + s; int max = Integer.MIN_VALUE; for (int i = 0; i < n; i++) { max = Math.max(max, calc(s.substring(i, i + n))); } System.out.println(max); sc.close(); } private static int calc(String str) { int n = str.length(); if (str.charAt(0) == '+' || str.charAt(0) == '-') { return Integer.MIN_VALUE; } if (str.charAt(n - 1) == '+' || str.charAt(n - 1) == '-') { return Integer.MIN_VALUE; } int i; int j = 0; int ret = 0; for (i = 0; i < str.length(); i++) { char c = str.charAt(i); if (c == '+' || c == '-') { int tmp = Integer.parseInt(str.substring(j, i)); ret += tmp; j = i; } } int tmp = Integer.parseInt(str.substring(j, i)); ret += tmp; return ret; } }