結果

問題 No.297 カードの数式
ユーザー tkzw_21tkzw_21
提出日時 2015-11-06 22:54:37
言語 C++11
(gcc 11.4.0)
結果
WA  
実行時間 -
コード長 847 bytes
コンパイル時間 2,409 ms
コンパイル使用メモリ 160,168 KB
実行使用メモリ 4,352 KB
最終ジャッジ日時 2023-10-11 14:47:14
合計ジャッジ時間 3,550 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;

int main(void){
	int n;
	cin >> n;
	vector<int> a;
	vector<char> c;
	for(int i=0;i<n;i++){
		char cc;
		cin >> cc;
		if(cc == '+' || cc== '-'){
			c.push_back(cc);
		}else{
			a.push_back(cc-'0');
		}
	}

	int m = c.size();
	sort(a.begin(),a.end(),greater<int>());
	sort(c.begin(),c.end());
	long long ma = 0;
	string s;
	for(int i=0;i<a.size()-m;i++){
		s += '0'+a[i];
	}
	ma = stol(s);
	long long mm = ma;

	for(int i=0;i<m;i++){
		if(c[i] == '+')
			ma += a[a.size()-m+i];
		else
			ma -= a[a.size()-m+i];
	}

	long long mi = 0;
	vector<long long>vec;
	sort(a.begin(),a.end());
	for(int i=0;i<m;i++)vec.push_back(a[i]);
	vec.push_back(mm);
	mi = vec[0];
	for(int i=1;i<vec.size();i++){
		if(c[i-1] == '+')
			mi += vec[i];
		else
			mi -= vec[i];
	}
	cout << ma << " " << mi << endl;

	return 0;
}
0