結果

問題 No.297 カードの数式
ユーザー t8m8⛄️t8m8⛄️
提出日時 2016-01-25 18:18:52
言語 Java21
(openjdk 21)
結果
WA  
実行時間 -
コード長 1,391 bytes
コンパイル時間 4,050 ms
コンパイル使用メモリ 89,632 KB
実行使用メモリ 58,536 KB
最終ジャッジ日時 2023-10-21 14:58:53
合計ジャッジ時間 7,800 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 129 ms
58,024 KB
testcase_01 AC 122 ms
57,732 KB
testcase_02 AC 130 ms
58,120 KB
testcase_03 AC 128 ms
58,308 KB
testcase_04 AC 129 ms
58,308 KB
testcase_05 AC 131 ms
58,200 KB
testcase_06 WA -
testcase_07 AC 118 ms
57,780 KB
testcase_08 AC 128 ms
58,260 KB
testcase_09 AC 118 ms
57,604 KB
testcase_10 AC 130 ms
58,116 KB
testcase_11 AC 131 ms
58,208 KB
testcase_12 AC 119 ms
57,720 KB
testcase_13 AC 126 ms
57,724 KB
testcase_14 AC 116 ms
57,604 KB
testcase_15 AC 119 ms
57,864 KB
testcase_16 AC 120 ms
57,684 KB
testcase_17 AC 129 ms
58,208 KB
testcase_18 AC 118 ms
57,684 KB
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
testcase_22 AC 131 ms
58,336 KB
testcase_23 WA -
testcase_24 WA -
testcase_25 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.*;
import java.io.*;
import java.awt.geom.*;
import java.math.*;

public class No0294 {

	static final Scanner in = new Scanner(System.in);
	static final PrintWriter out = new PrintWriter(System.out,false);

	static void solve() {
		int n = in.nextInt();
		int cnt = 0;
		ArrayList<Integer> num = new ArrayList<>();
		for (int i=0; i<n; i++) {
			char c = in.next().charAt(0);
			if (c == '-') cnt++;
			if (c == '+' || c == '-') continue;
			num.add(c - '0');
		}
		Collections.sort(num);

		int size = num.size();
		int nn = n - size + 1;

		long x = 0, dig = 1;
		for (int i=nn-1; i<size; i++) {
			x += num.get(i)*dig;
			dig *= 10;
		}

		long max = 0;
		int tmp = cnt;
		for (int i=0; i<nn-1; i++) {
			if (cnt > 0) {
				max -= num.get(i);
				cnt--;
			} else {
				max += num.get(i);
			}
		}
		max += x;

		cnt = tmp;
		long min = 0;
		if (cnt > 0) {
			min -= x;
			cnt--;
		} else {
			min += x;
		}

		for (int i=nn-2; i>=0; i--) {
			if (cnt > 0) {
				min -= num.get(i);
				cnt--;
			} else {
				min += num.get(i);
			}
		}

		out.println(max + " " + min);
	}

	public static void main(String[] args) {
		long start = System.currentTimeMillis();

		solve();
		out.flush();

		long end = System.currentTimeMillis();
		//trace(end-start + "ms");
		in.close();
		out.close();
	}

	static void trace(Object... o) { System.out.println(Arrays.deepToString(o));}
}
0