結果

問題 No.297 カードの数式
ユーザー snteasntea
提出日時 2015-11-09 20:26:04
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 2 ms / 1,000 ms
コード長 1,597 bytes
コンパイル時間 1,399 ms
コンパイル使用メモリ 152,100 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-08-26 22:49:57
合計ジャッジ時間 2,176 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#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;
}
0