結果

問題 No.297 カードの数式
ユーザー aaaaaaiuaaaaaaiu
提出日時 2019-08-25 01:55:18
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
TLE  
実行時間 -
コード長 1,017 bytes
コンパイル時間 2,299 ms
コンパイル使用メモリ 197,176 KB
実行使用メモリ 10,752 KB
最終ジャッジ日時 2024-04-22 16:09:24
合計ジャッジ時間 4,860 ms
ジャッジサーバーID
(参考情報)
judge4 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

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

int main() {
    int n;cin>>n;
    char a[n];
    for (int i=0;i<n;i++)
        cin>>a[i];
    sort(a,a+n);
    ll mn=1e18;
    ll mx=-1e18;
    do {
        if (!isdigit(a[0])||!isdigit(a[n-1]))
            continue;
        ll b=0;
        int i=0;
        while (i<n&&isdigit(a[i])) {
            b*=10;
            b+=a[i]-'0';
            i++;
        }
        bool invld=false;
        while (i<n) {
            int sign=1;
            if (a[i]=='-')
                sign=-1;
            i++;
            if (!isdigit(a[i])) {
                invld=true;
                break;
            }
            ll c=0;
            while (i<n&&isdigit(a[i])) {
                c*=10;
                c+=a[i]-'0';
                i++;
            }
            b+=c*sign;
        }
        if (invld)
            continue;
        mn=min(mn,b);
        mx=max(mx,b);
    } while (next_permutation(a,a+n));
    cout<<mx<<' '<<mn<<endl;
    return 0;
}
0