結果
| 問題 |
No.297 カードの数式
|
| コンテスト | |
| ユーザー |
dnish
|
| 提出日時 | 2018-06-22 13:37:01 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
TLE
|
| 実行時間 | - |
| コード長 | 1,328 bytes |
| コンパイル時間 | 1,591 ms |
| コンパイル使用メモリ | 169,532 KB |
| 実行使用メモリ | 10,624 KB |
| 最終ジャッジ日時 | 2024-06-30 17:56:41 |
| 合計ジャッジ時間 | 4,128 ms |
|
ジャッジサーバーID (参考情報) |
judge5 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 1 TLE * 1 -- * 21 |
ソースコード
#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;
}
dnish