結果
問題 | No.297 カードの数式 |
ユーザー | spacia |
提出日時 | 2015-12-14 22:49:04 |
言語 | Java21 (openjdk 21) |
結果 |
RE
|
実行時間 | - |
コード長 | 1,728 bytes |
コンパイル時間 | 2,231 ms |
コンパイル使用メモリ | 74,964 KB |
実行使用メモリ | 55,952 KB |
最終ジャッジ日時 | 2023-10-13 16:47:00 |
合計ジャッジ時間 | 5,893 ms |
ジャッジサーバーID (参考情報) |
judge11 / judge12 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 93 ms
52,532 KB |
testcase_01 | AC | 94 ms
52,512 KB |
testcase_02 | AC | 93 ms
53,608 KB |
testcase_03 | AC | 94 ms
53,308 KB |
testcase_04 | RE | - |
testcase_05 | AC | 95 ms
52,800 KB |
testcase_06 | WA | - |
testcase_07 | AC | 94 ms
53,592 KB |
testcase_08 | AC | 106 ms
52,896 KB |
testcase_09 | AC | 95 ms
52,812 KB |
testcase_10 | AC | 96 ms
52,548 KB |
testcase_11 | AC | 94 ms
52,660 KB |
testcase_12 | AC | 93 ms
52,968 KB |
testcase_13 | AC | 95 ms
52,672 KB |
testcase_14 | AC | 103 ms
52,548 KB |
testcase_15 | AC | 95 ms
52,300 KB |
testcase_16 | AC | 95 ms
52,248 KB |
testcase_17 | AC | 103 ms
53,228 KB |
testcase_18 | RE | - |
testcase_19 | WA | - |
testcase_20 | WA | - |
testcase_21 | RE | - |
testcase_22 | AC | 95 ms
52,520 KB |
testcase_23 | WA | - |
testcase_24 | WA | - |
testcase_25 | RE | - |
ソースコード
import java.io.*; import java.util.*; class Main { public static int getMin (int[] nums , int addCnt , int subCnt) { int ret = nums[0] , concatCnt = 0 , len = nums.length; Arrays.sort(nums); int ai = 0, si = 0; for (int i = 1; i < len; i++) { if (addCnt + subCnt > 1 && addCnt > 0) { ret += nums[i]; addCnt--; } else if (addCnt + subCnt > 1 && subCnt > 0) { ret -= nums[i]; subCnt--; } else { String str = ""; for (int j = i; j < len; j++) { str = (nums[j] + "") + str; } ret = addCnt > 0 ? ret + Integer.parseInt(str) : ret - Integer.parseInt(str); break; } } return ret; } public static int getMax (int[] nums , int addCnt , int subCnt) { int ret = 0 , concatCnt = 0 , len = nums.length; Arrays.sort(nums); int ai = 0, si = 0; for (int i = len - 1; i >= 0; i--) { if (len - concatCnt++ > addCnt + subCnt) { ret = ret * 10 + nums[i]; continue; } else if (ai++ < addCnt) { ret += nums[i]; } else if (si < subCnt) { ret -= nums[i]; } } return ret; } public static void main (String[] args) throws IOException { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); int addCnt = 0, subCnt = 0; int n = Integer.parseInt(br.readLine()); String[] str = br.readLine().split(" "); for (int i = 0; i < n; i++) { if (str[i].equals("+")) { addCnt++; } else if (str[i].equals("-")) { subCnt++; } } int[] nums = new int[n - (addCnt + subCnt)]; int j = 0; for (String s : str) { if (!s.equals("+") && !s.equals("-")) { nums[j++] = Integer.parseInt(s); } } System.out.println(getMax(nums , addCnt , subCnt) + " " + getMin(nums , addCnt , subCnt)); } }