結果

問題 No.297 カードの数式
ユーザー sugim48sugim48
提出日時 2015-11-06 23:14:22
言語 C++11
(gcc 11.4.0)
結果
WA  
実行時間 -
コード長 1,389 bytes
コンパイル時間 691 ms
コンパイル使用メモリ 82,044 KB
実行使用メモリ 4,480 KB
最終ジャッジ日時 2023-10-11 14:53:53
合計ジャッジ時間 1,785 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,352 KB
testcase_01 AC 1 ms
4,348 KB
testcase_02 AC 1 ms
4,348 KB
testcase_03 AC 1 ms
4,348 KB
testcase_04 WA -
testcase_05 AC 2 ms
4,352 KB
testcase_06 WA -
testcase_07 AC 1 ms
4,348 KB
testcase_08 AC 2 ms
4,348 KB
testcase_09 AC 2 ms
4,352 KB
testcase_10 AC 1 ms
4,352 KB
testcase_11 AC 2 ms
4,348 KB
testcase_12 AC 2 ms
4,348 KB
testcase_13 AC 2 ms
4,348 KB
testcase_14 AC 2 ms
4,352 KB
testcase_15 AC 1 ms
4,348 KB
testcase_16 AC 1 ms
4,352 KB
testcase_17 AC 2 ms
4,348 KB
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
testcase_22 AC 1 ms
4,352 KB
testcase_23 AC 1 ms
4,352 KB
testcase_24 WA -
testcase_25 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

using namespace std;
#include <algorithm>
#include <iostream>
#include <random>
#include <string>
#include <fstream>
#include <vector>
#include <climits>

typedef long long ll;
ll INF = LLONG_MAX;

int ma(vector<int> a, int plus, int minus) {
	int ans = 0;
	while (minus--) {
		ans -= a[0];
		a.erase(a.begin());
	}
	while (plus--) {
		ans += a[0];
		a.erase(a.begin());
	}
	ll x = 0;
	reverse(a.begin(), a.end());
	while (!a.empty()) {
		x = x * 10 + a[0];
		a.erase(a.begin());
	}
	return ans + x;
}

int mi(vector<int> a, int plus, int minus) {
	if (minus) {
		plus++;
		minus--;
		int ans = 0;
		while (plus--) {
			ans += a[0];
			a.erase(a.begin());
		}
		while (minus--) {
			ans -= a[0];
			a.erase(a.begin());
		}
		int x = 0;
		reverse(a.begin(), a.end());
		while (!a.empty()) {
			x = x * 10 + a[0];
			a.erase(a.begin());
		}
		return ans - x;
	}
	else {
		int ans = 0;
		reverse(a.begin(), a.end());
		while (plus--) {
			ans += a[0];
			a.erase(a.begin());
		}
		ll x = 0;
		while (!a.empty()) {
			x = x * 10 + a[a.size() - 1];
			a.erase(a.begin());
		}
		return ans + x;
	}
}

int main() {
	int N; cin >> N;
	vector<int> a;
	int plus = 0, minus = 0;
	while (N--) {
		string c; cin >> c;
		if (c == "+") plus++;
		else if (c == "-") minus++;
		else a.push_back(c[0] - '0');
	}
	sort(a.begin(), a.end());
	cout << ma(a, plus, minus) << ' ' << mi(a, plus, minus) << endl;
}
0