結果

問題 No.297 カードの数式
ユーザー otsnskotsnsk
提出日時 2015-11-27 16:32:29
言語 C++11
(gcc 11.4.0)
結果
CE  
(最新)
AC  
(最初)
実行時間 -
コード長 1,586 bytes
コンパイル時間 466 ms
コンパイル使用メモリ 69,616 KB
最終ジャッジ日時 2024-04-27 02:16:05
合計ジャッジ時間 861 ms
ジャッジサーバーID
(参考情報)
judge5 / judge2
このコードへのチャレンジ
(要ログイン)
コンパイルエラー時のメッセージ・ソースコードは、提出者また管理者しか表示できないようにしております。(リジャッジ後のコンパイルエラーは公開されます)
ただし、clay言語の場合は開発者のデバッグのため、公開されます。

コンパイルメッセージ
main.cpp: In function ‘int main()’:
main.cpp:67:16: error: ‘accumulate’ was not declared in this scope
   67 |         amin = accumulate(n.begin(), n.begin()+plus+1, 0);
      |                ^~~~~~~~~~

ソースコード

diff #

#include <iostream>
#include <iomanip>
#include <vector>
#include <algorithm>
#include <cmath>

#define FORR(i,b,e) for(int i=(b);i<(int)(e);++i)
#define FOR(i,e) FORR(i,0,e)
#define ALL(c) begin(c), end(c)
#define sortuniq(v) sort(v.begin(), v.end()), v.erase(unique(v.begin(),v.end()),v.end())
#define dump(var) cerr << #var ": " << var << "\n"
#define dumpc(con) for(auto& e: con) cerr << e << " "; cerr<<"\n"

typedef long long ll;
typedef unsigned long long ull;

const double EPS = 1e-6;
const int d4[] = {0, -1, 0, 1, 0};

using namespace std;


int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);

    int N;
    cin >> N;
    vector<int> n;
    int plus = 0, minus = 0;
    FOR(i, N) {
        char c;
        cin >> c;
        if (c == '+') plus++;
        else if (c == '-') minus++;
        else {
            n.push_back(c - '0');
        }
    }
    sort(ALL(n));

    ll amax = 0, amin = n[0];
    FOR(i, plus) {
        amax += n[minus+i];
        amin += n[i+1];
    }
    FOR(i, minus) {
        amax -= n[i];
        if (i) amin -= n[plus+i];
    }
    ll nx = 0, d = 1;
    FORR(i, plus+minus, n.size()) {
        nx += n[i] * d;
        d *= 10;
    }
    amax += nx;
    amin -= nx;

    if (minus == 0) {
        int k = plus+1, d = 1;
        while (k < n.size()) {
            for (int i = 0; i < plus+1 && k + i < n.size(); i++) {
                n[i] = n[i] * 10 + n[k+i];
            }
            k += plus+1;
        }
        amin = accumulate(n.begin(), n.begin()+plus+1, 0);
    }

    cout << amax << ' ' << amin << endl;
    
    return 0;
}
0