結果

問題 No.297 カードの数式
ユーザー ぴろずぴろず
提出日時 2015-11-06 22:50:54
言語 Java21
(openjdk 21)
結果
WA  
実行時間 -
コード長 1,161 bytes
コンパイル時間 2,495 ms
コンパイル使用メモリ 82,704 KB
実行使用メモリ 57,048 KB
最終ジャッジ日時 2023-10-11 14:45:55
合計ジャッジ時間 7,844 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 150 ms
56,680 KB
testcase_01 AC 150 ms
56,452 KB
testcase_02 AC 150 ms
56,724 KB
testcase_03 AC 157 ms
56,640 KB
testcase_04 AC 152 ms
56,700 KB
testcase_05 AC 153 ms
56,872 KB
testcase_06 WA -
testcase_07 AC 154 ms
56,728 KB
testcase_08 AC 152 ms
56,788 KB
testcase_09 AC 152 ms
56,712 KB
testcase_10 AC 154 ms
56,632 KB
testcase_11 AC 156 ms
56,912 KB
testcase_12 AC 150 ms
56,436 KB
testcase_13 AC 151 ms
56,776 KB
testcase_14 AC 150 ms
56,668 KB
testcase_15 AC 154 ms
56,708 KB
testcase_16 AC 151 ms
56,816 KB
testcase_17 AC 151 ms
56,668 KB
testcase_18 AC 150 ms
56,636 KB
testcase_19 AC 151 ms
56,892 KB
testcase_20 AC 151 ms
56,556 KB
testcase_21 WA -
testcase_22 AC 151 ms
56,456 KB
testcase_23 AC 150 ms
56,612 KB
testcase_24 AC 158 ms
57,048 KB
testcase_25 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

package no297;

import java.util.ArrayList;
import java.util.Collections;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		ArrayList<Integer> d = new ArrayList<>();
		int plus = 0;
		int minus = 0;
		for(int i=0;i<n;i++) {
			char c = sc.next().charAt(0);
			if (Character.isDigit(c)) {
				d.add(c - '0');
			}else if(c == '+') {
				plus++;
			}else{
				minus++;
			}
		}
		Collections.sort(d);
		long max = 0;

		long big = 0;
		for(int i=0;i<n-(plus+minus)*2;i++) {
			big = (big * 10) + d.get(d.size()-1-i);
		}

		max += big;
		for(int i=0;i<minus;i++) {
			max -= d.get(i);
		}
		for(int i=minus;i<minus+plus;i++) {
			max += d.get(i);
		}

		long min = 0;
		if (minus == 0) {
			int i=0;
			while(i < d.size()) {
				min *= 10;
				for(int j=0;j<plus+1;j++) {
					min += d.get(i);
					i++;
					if (i >= d.size()) {
						break;
					}
				}
			}
		}else{
			min = -big;
			for(int i=0;i<plus+1;i++) {
				min += d.get(i);
			}
			for(int i=plus+1;i<minus+plus;i++) {
				min -= d.get(i);
			}
		}

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

}
0