結果

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

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,348 KB
testcase_01 WA -
testcase_02 WA -
testcase_03 AC 2 ms
4,348 KB
testcase_04 WA -
testcase_05 AC 2 ms
4,348 KB
testcase_06 AC 1 ms
4,476 KB
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 AC 1 ms
4,348 KB
testcase_20 AC 1 ms
4,352 KB
testcase_21 WA -
testcase_22 WA -
testcase_23 AC 1 ms
4,348 KB
testcase_24 AC 2 ms
4,348 KB
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());
		}
		ll x = 0;
		reverse(a.begin(), a.end());
		while (!a.empty()) {
			x = x * 10 + a[0];
			a.erase(a.begin());
		}
		return 114514;
		return ans - x;
	}
	else {
		int n = plus + 1;
		vector<ll> b(n);
		for (int i = 0; i < a.size(); i++)
			b[i % n] = b[i % n] * 10 + a[i];
		ll sum = 0;
		for (int k = 0; k < n; k++)
			sum += b[k];
		return sum;
	}
}

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