結果
| 問題 |
No.297 カードの数式
|
| コンテスト | |
| ユーザー |
sugim48
|
| 提出日時 | 2015-11-06 23:14:22 |
| 言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 1,389 bytes |
| コンパイル時間 | 765 ms |
| コンパイル使用メモリ | 89,360 KB |
| 実行使用メモリ | 6,948 KB |
| 最終ジャッジ日時 | 2024-09-13 13:46:16 |
| 合計ジャッジ時間 | 1,612 ms |
|
ジャッジサーバーID (参考情報) |
judge2 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 15 WA * 8 |
ソースコード
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());
}
int x = 0;
reverse(a.begin(), a.end());
while (!a.empty()) {
x = x * 10 + a[0];
a.erase(a.begin());
}
return ans - x;
}
else {
int ans = 0;
reverse(a.begin(), a.end());
while (plus--) {
ans += a[0];
a.erase(a.begin());
}
ll x = 0;
while (!a.empty()) {
x = x * 10 + a[a.size() - 1];
a.erase(a.begin());
}
return ans + x;
}
}
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;
}
sugim48