結果

問題 No.297 カードの数式
ユーザー matsukin1111matsukin1111
提出日時 2019-04-24 13:32:32
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,713 bytes
コンパイル時間 1,020 ms
コンパイル使用メモリ 101,956 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-04-25 08:24:40
合計ジャッジ時間 2,048 ms
ジャッジサーバーID
(参考情報)
judge5 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include<iostream>
#include<cstdio>
#include<cstring>
#include <cstdlib>  
#include <cmath>   
#include<cctype>
#include<string>
#include<set>
#include<iomanip>
#include <map>
#include<algorithm>
#include <functional>
#include<vector>
#include<climits>
#include<stack>
#include<queue>
#include <deque>
#include <climits>
#include <typeinfo>
#include <utility> 
#define all(x) (x).begin(),(x).end()
#define rep(i,m,n) for(int i = m;i < n;++i)
#define pb push_back
#define fore(i,a) for(auto &i:a)
#define rrep(i,m,n) for(int i = m;i >= n;--i)
#define INF INT_MAX/2
using namespace std;
using ll = long long;
using R = double;
using Data = pair<ll, vector<int>>;
const ll MOD = 1e9 + 7;
const ll inf = 1LL << 50;
struct edge { ll from; ll to; ll cost; };

int main() {
	int n;
	cin >> n;

	vector<char>s(n);
	vector<int>num;
	rep(i, 0, n)cin >> s[i];


	int cnt = 0;
	int cntpl = 0;
	int cntmi = 0;
	rep(i, 0, n) {
		if (s[i] == '+' || s[i] == '-') {
			if (s[i] == '+')cntpl++;
			else cntmi++;
			cnt++;
		}
		else {
			num.pb(s[i]-'0');
		}
	}
	sort(all(num));
	reverse(all(num));

	int mx = 0;
	int dgt = 1;
	//max
	for (int i = num.size() - cnt-1; i >= 0; i--) {
		mx += dgt * num[i];
		dgt *= 10;
	}
	for (int i = 0; i <= cntpl - 1; i++) {
		mx += num[num.size()-cnt+i];
	}
	for (int i = 0; i <= cntmi - 1; i++) {
		mx -= num[num.size()-1-i];
	}



	int mi = 0;
	dgt = 1;
	//min
	if (cntmi > 0) {
		for (int i = num.size() - cnt - 1; i >= 0; i--) {
			mi -= dgt * num[i];
			dgt *= 10;
		}
		for (int i = 0; i <= cntmi - 2; i++) {
			mi -= num[num.size() - cnt + i];
		}
		for (int i = 0; i <= cntpl; i++) {
			mi += num[num.size() - 1 - i];
		}
	}
	else {

	}
	cout << mx << " " << mi << endl;

	return 0;
}
0