結果
| 問題 | No.297 カードの数式 | 
| コンテスト | |
| ユーザー |  sntea | 
| 提出日時 | 2015-11-09 20:26:04 | 
| 言語 | C++11(廃止可能性あり) (gcc 13.3.0) | 
| 結果 | 
                                AC
                                 
                             | 
| 実行時間 | 3 ms / 1,000 ms | 
| コード長 | 1,597 bytes | 
| コンパイル時間 | 2,344 ms | 
| コンパイル使用メモリ | 165,572 KB | 
| 実行使用メモリ | 5,248 KB | 
| 最終ジャッジ日時 | 2024-12-26 02:24:09 | 
| 合計ジャッジ時間 | 2,767 ms | 
| ジャッジサーバーID (参考情報) | judge1 / judge2 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| sample | AC * 3 | 
| other | AC * 23 | 
ソースコード
#include <bits/stdc++.h>
#include <cmath>
#include <climits>
#include <cstdio>
using namespace std;
#define endl '\n'
#define ALL(a)  (a).begin(),(a).end()
#define SZ(a) int((a).size())
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define RFOR(i,a,b) for (int i=(b)-1;i>=(a);i--)
#define REP(i,n)  FOR(i,0,n)
#define RREP(i,n) for (int i=(n)-1;i>=0;i--)
#define DEBUG(x) cout<<#x<<": "<<x<<endl
typedef pair<int,int> P;
typedef long long int LL;
typedef pair<LL,LL> LP;
#define int LL
signed main()
{
	ios::sync_with_stdio(false);
	cin.tie(0);
	int N;
	vector<char> c;
	cin >> N;
	int np = 0, nm = 0;
	vector<int> num;
	REP(i,N){
		char c;
		cin >> c;
		if(c == '+'){
			np++;
		}else if(c == '-'){
			nm++;
		}else{
			num.push_back(c-'0');
		}
	}
	int ans1 = 0, ans2 = 0;
	vector<int> num2;
	sort(ALL(num));
	//REP(i,SZ(num))	DEBUG(num[i]);
	int p = 0;
	REP(i,nm){
		num2.push_back(num[p]);
		p++; 
	}
	//DEBUG(nm);
	REP(i,np){
		num2.push_back(num[p]);
		p++;
	}
	int m = 0;
	RFOR(i,p,SZ(num)){
		m *= 10;
		m += num[i];
	}
	num2.push_back(m);
	p = 0;
	//REP(i,SZ(num2))	DEBUG(num2[i]);
	REP(i,nm){
		ans1 -= num2[p];
		//DEBUG(ans1);
		p++; 
	}
	REP(i,np){
		ans1 += num2[p];
		//DEBUG(ans1);
		p++;
	}
	//DEBUG(num[p]);
	ans1 += num2[p];
	p = 0;
	REP(i,np+1){
		ans2 += num2[p];
		p++;
	}
	REP(i,nm){
		ans2 -= num2[p];
		p++;
	}
	if(nm != 0) cout << ans1 << ' ' << ans2 << endl;
	else{
		int nn = np+1;
		int ans2 = 0;
		vector<int> v(nn,0);
		REP(i,SZ(num)){
			v[i%nn] *= 10;
			v[i%nn] += num[i];
		}
		REP(i,SZ(v)) ans2 += v[i];
		cout << ans1 << ' ' << ans2 << endl;
	}
	return 0;
}
            
            
            
        