結果

問題 No.297 カードの数式
ユーザー t98slidert98slider
提出日時 2022-12-23 18:23:51
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 2 ms / 1,000 ms
コード長 1,149 bytes
コンパイル時間 1,902 ms
コンパイル使用メモリ 176,616 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-08-11 11:53:52
合計ジャッジ時間 3,068 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

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

int main(){
  int n, p = 0, m = 0;
  cin >> n;
  vector<char> c(n);
  string s;
  for(auto &&v:c){
    cin >> v;
    if(v >= '0' && v <= '9')s += v;
    else{
      p += (v == '+');
      m += (v == '-');
    }
  }
  sort(s.begin(), s.end());
  vector<string> ans1(p + m + 1), ans2(p + m + 1);
  for(int i = 0; i < s.size(); i++){
    ans1[max(p + m - i, 0)] += s[i];
  }
  if(m >= 1){
    for(int i = 0; i < s.size(); i++){
      ans2[min(p + m, i)] += s[i];
    }
  }else{
    for(int i = 0; i < s.size(); i++){
      ans2[i % (p + m + 1)] += s[i];
    }
  }
  sort(ans1[0].rbegin(), ans1[0].rend());
  sort(ans2[0].begin(), ans2[0].end());
  ll v1 = stoll(ans1[0]), v2 = stoll(ans2[0]);
  for(int i = 1; i <= p; i++){
    sort(ans1[i].rbegin(), ans1[i].rend());
    sort(ans2[i].begin(), ans2[i].end());
    v1 += stoll(ans1[i]);
    v2 += stoll(ans2[i]);
  }
  for(int i = p + 1; i <= p + m; i++){
    sort(ans1[i].begin(), ans1[i].end());
    sort(ans2[i].rbegin(), ans2[i].rend());
    v1 -= stoll(ans1[i]);
    v2 -= stoll(ans2[i]);
  }
  cout << v1 << " " << v2 << '\n';
}
0