結果

問題 No.297 カードの数式
ユーザー dnishdnish
提出日時 2018-06-22 13:37:01
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
TLE  
実行時間 -
コード長 1,328 bytes
コンパイル時間 1,439 ms
コンパイル使用メモリ 167,128 KB
実行使用メモリ 8,760 KB
最終ジャッジ日時 2023-09-13 07:55:47
合計ジャッジ時間 4,207 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
7,536 KB
testcase_01 AC 1 ms
4,376 KB
testcase_02 AC 1 ms
4,376 KB
testcase_03 AC 1 ms
4,380 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"
#define REP(i,n,N) for(int i=(n); i<(N); i++)
#define RREP(i,n,N) for(ll i=(N-1); i>=n; i--)
#define CK(n,a,b) ((a)<=(n)&&(n)<(b))
#define ALL(v) (v).begin(),(v).end()
#define p(s) cout<<(s)<<endl
#define p2(a,b) cout<<(a)<<" "<<(b)<<endl
#define v2(T) vector<vector<T>>
typedef long long ll;
using namespace std;
const ll inf = 1e18+7;


int main() {
    int N;
    cin>>N;
    char c[16];
    ll mx=0,mn=inf;
    REP(i,0,N){
        cin>>c[i];
    }
    sort(c,c+N);
    do{
        if(!isdigit(c[N-1])) continue;
        bool pren=true;
        bool ok=true;
        char en = '+';
        ll sum=0;
        ll tmp=0;
        REP(i,0,N){
            if(isdigit(c[i])){
                pren=false;
                tmp*=10;
                tmp+=c[i]-'0';
            }else{
                if(pren) {
                    ok=false;
                    break;
                }else{
                    if(en=='+') sum+=tmp;
                    else sum-=tmp;
                    tmp=0;
                    en = c[i];
                    pren =true;
                }
            }

        }
        if(ok){
            if(en=='+') sum+=tmp;
            else sum-=tmp;
            mx=max(mx,sum);
            mn=min(mn,sum);
        }
    }while(next_permutation(c,c+N));
    p2(mx,mn);
    return 0;
}
0