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