結果
| 問題 |
No.297 カードの数式
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2021-01-15 19:30:57 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 1,291 bytes |
| コンパイル時間 | 2,104 ms |
| コンパイル使用メモリ | 198,888 KB |
| 最終ジャッジ日時 | 2025-01-17 18:23:02 |
|
ジャッジサーバーID (参考情報) |
judge5 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 17 WA * 6 |
ソースコード
#include <bits/stdc++.h>
using namespace std;
// max
long long f(vector<int> a, int x, int y) {
sort(a.begin(), a.end());
int pos = 0;
long long ret = 0;
for (int i = 0; i < y; i++)
ret -= a[pos++];
for (int i = 0; i < x; i++)
ret += a[pos++];
long long base = 1;
while (pos < a.size()) {
base *= 10;
ret += base * a[pos++];
}
return ret;
}
long long p10(int x) {
long long ret = 1;
for (int i = 0; i < x; i++)
ret *= 10;
return ret;
}
// min
long long g(vector<int> a, int x, int y) {
sort(a.begin(), a.end());
int pos = 0;
long long ret = 0;
if (y == 0) {
for (int i = 0; i < a.size(); i++) {
ret += a[i] * p10(i / x);
}
return ret;
}
for (int i = 0; i < x; i++)
ret += a[pos++];
for (int i = 0; i < y; i++)
ret -= a[pos++];
long long base = 1;
while (pos < a.size()) {
base *= 10;
ret -= base * a[pos++];
}
return ret;
}
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
int n;
cin >> n;
int x = 1, y = 0;
vector<int> a;
for (int i = 0; i < n; i++) {
char c;
cin >> c;
if (isdigit(c))
a.push_back(c - '0');
else if (c == '+')
++x;
else
++y;
}
cout << f(a, x, y) << " " << g(a, x, y) << endl;
return 0;
}