結果
問題 | No.297 カードの数式 |
ユーザー | nanophoto12 |
提出日時 | 2015-11-23 14:59:00 |
言語 | Java21 (openjdk 21) |
結果 |
WA
|
実行時間 | - |
コード長 | 1,637 bytes |
コンパイル時間 | 2,361 ms |
コンパイル使用メモリ | 77,900 KB |
実行使用メモリ | 58,980 KB |
最終ジャッジ日時 | 2023-10-11 18:22:46 |
合計ジャッジ時間 | 7,797 ms |
ジャッジサーバーID (参考情報) |
judge13 / judge11 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 156 ms
54,492 KB |
testcase_01 | AC | 158 ms
56,432 KB |
testcase_02 | AC | 157 ms
56,884 KB |
testcase_03 | AC | 157 ms
56,692 KB |
testcase_04 | AC | 162 ms
56,748 KB |
testcase_05 | AC | 159 ms
57,004 KB |
testcase_06 | WA | - |
testcase_07 | AC | 162 ms
56,764 KB |
testcase_08 | AC | 162 ms
56,788 KB |
testcase_09 | AC | 160 ms
56,640 KB |
testcase_10 | WA | - |
testcase_11 | WA | - |
testcase_12 | AC | 161 ms
56,904 KB |
testcase_13 | WA | - |
testcase_14 | AC | 160 ms
56,960 KB |
testcase_15 | WA | - |
testcase_16 | WA | - |
testcase_17 | WA | - |
testcase_18 | AC | 159 ms
56,708 KB |
testcase_19 | WA | - |
testcase_20 | WA | - |
testcase_21 | WA | - |
testcase_22 | WA | - |
testcase_23 | WA | - |
testcase_24 | WA | - |
testcase_25 | WA | - |
ソースコード
package com.company; import java.util.*; public class Main { private static long RemoveLargest(List<Integer> list, int operatorCount) { long value = 0L; int size = list.size(); for(int i = 0; i < size - operatorCount;i++) { value *=10L; value += list.get(0); list.remove(0); } return value; } public static void main(String[] args) { Scanner scanner = new Scanner(System.in); int n = scanner.nextInt(); List<Integer> list = new ArrayList<Integer>(0); Integer plusCount = 0; Integer minusCount = 0; for(int i = 0; i < n;i++) { String token = scanner.next(); if(token.equals("+")) { plusCount++; continue; } if(token.equals("-")) { minusCount++; continue; } int value = Integer.parseInt(token); list.add(value); } Collections.sort(list); Collections.reverse(list); Long largest = RemoveLargest(list, plusCount+minusCount); Long maxValue = largest; for(int i = 0; i < plusCount;i++) { maxValue += list.get(i); } for(int i = plusCount;i < plusCount + minusCount;i++) { maxValue -= list.get(i); } Long minValue = maxValue; if(minusCount > 0) { minValue = -maxValue; } System.out.println(maxValue.toString() + " " + minValue.toString()); } }