結果
問題 |
No.297 カードの数式
|
ユーザー |
![]() |
提出日時 | 2015-11-06 23:15:35 |
言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 1,378 bytes |
コンパイル時間 | 772 ms |
コンパイル使用メモリ | 90,252 KB |
実行使用メモリ | 6,948 KB |
最終ジャッジ日時 | 2024-09-13 13:48:19 |
合計ジャッジ時間 | 1,605 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 1 WA * 2 |
other | AC * 4 WA * 19 |
ソースコード
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) { minus--; int ans = 0; while (plus--) { ans += a[0]; a.erase(a.begin()); } while (minus--) { 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; } 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; }