結果
| 問題 |
No.297 カードの数式
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2019-08-25 01:55:18 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
TLE
|
| 実行時間 | - |
| コード長 | 1,017 bytes |
| コンパイル時間 | 2,557 ms |
| コンパイル使用メモリ | 194,760 KB |
| 最終ジャッジ日時 | 2025-01-07 14:54:09 |
|
ジャッジサーバーID (参考情報) |
judge3 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 18 TLE * 5 |
ソースコード
#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;
}