結果

問題 No.297 カードの数式
ユーザー nmnmnmnmnmnmnmnmnmnmnmnmnmnm
提出日時 2015-11-06 22:51:20
言語 C++11
(gcc 11.4.0)
結果
TLE  
実行時間 -
コード長 1,810 bytes
コンパイル時間 1,671 ms
コンパイル使用メモリ 94,392 KB
実行使用メモリ 7,588 KB
最終ジャッジ日時 2023-10-11 14:45:45
合計ジャッジ時間 4,291 ms
ジャッジサーバーID
(参考情報)
judge15 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,348 KB
testcase_01 AC 2 ms
4,352 KB
testcase_02 AC 2 ms
4,348 KB
testcase_03 AC 1 ms
4,348 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 <algorithm>
#include <cfloat>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <functional>
#include <iostream>
#include <map>
#include <memory>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>

using namespace std;

#define sz size()
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define all(c) (c).begin(), (c).end()
#define rep(i,a,b) for(int i=(a);i<(b);++i)
#define clr(a, b) memset((a), (b) ,sizeof(a))

#define MOD 1000000007

int main(){
  int n;
  cin>>n;
  vector<int> v;
  int minus = 0;
  int plus = 1;
  rep(i,0,n){
    string s;
    cin>>s;
    if(s=="-")minus++;
    else if(s=="+")plus++;
    else{
      v.pb(s[0]-'0');
    }
  }
  vector<int> vp;
  rep(i,0,plus){
    vp.pb(1);
  }
  rep(i,0,minus){
    vp.pb(-1);
  }
  sort(all(v));
  long long mn = 1000000000000LL;
  long long mx = -1000000000000LL;
  do{
    vector<int> vv;
    rep(i,0,v.sz){
      vv.pb(0);
    }
    rep(i,0,vp.sz-1){
      vv.pb(1);
    }
    do{
      vector<int> vvv;
      int a = -1;
      int index = 0;
      rep(i,0,vv.sz){
        if(vv[i] == 0){
          if(a==-1){
            a = v[index];
            index++;
          }
          else{
            a = a*10+v[index];
            index++;
          }
        }
        else{
          if(a!=-1)vvv.pb(a);
          a = -1;
        }
      }
      if(a!=-1)vvv.pb(a);
      if(vvv.sz==vp.sz){
        long long ans = 0;
        rep(i,0,vp.sz){
          ans += vp[i]*vvv[i];
        }
        mx = max(mx,ans);
        mn = min(mn,ans);
      }
    }while(next_permutation(all(vv)));
  }while(next_permutation(all(v)));
  cout << mx << " " << mn << endl;
  return 0;
}
0