結果
| 問題 |
No.297 カードの数式
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2016-06-20 03:06:43 |
| 言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 1,294 bytes |
| コンパイル時間 | 1,743 ms |
| コンパイル使用メモリ | 165,872 KB |
| 実行使用メモリ | 5,248 KB |
| 最終ジャッジ日時 | 2024-10-11 05:25:37 |
| 合計ジャッジ時間 | 2,366 ms |
|
ジャッジサーバーID (参考情報) |
judge3 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 16 WA * 7 |
コンパイルメッセージ
main.cpp: In function ‘int main()’:
main.cpp:25:14: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
25 | scanf(" %c", &c);
| ~~~~~^~~~~~~~~~~
ソースコード
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i,n) for(int (i)=0;(i)<(int)(n);++(i))
#define each(itr,c) for(__typeof(c.begin()) itr=c.begin(); itr!=c.end(); ++itr)
#define all(x) (x).begin(),(x).end()
#define mp make_pair
#define pb push_back
#define fi first
#define se second
int main()
{
int n;
cin >>n;
vector<int> num;
//plus,minus
int p=1,m=0;
rep(i,n)
{
char c;
scanf(" %c", &c);
if(c=='+') ++p;
else if(c=='-') ++m;
else num.pb(c-'0');
}
sort(all(num));
//作らなきゃいけない数字の個数
int a=p+m;
//今持っている数字カードの個数
int b=num.size();
//最終的に持つ数字のリスト
vector<ll> d;
//小さい方からa-1個取り出す
rep(i,a-1) d.pb(num[i]);
//大きい方から取り出してくっつける
ll add=0;
for(int i=b-1; i>=a-1; --i)
{
add=add*10+num[i];
}
d.pb(add);
//max,min
ll x=0, y=0;
//小さい方からm個をマイナス
rep(i,m) x-=d[i];
for(int i=m; i<p+m; ++i) x+=d[i];
//小さい方からp個をプラス
rep(i,p) y+=d[i];
for(int i=p; i<p+m; ++i) y-=d[i];
cout << x << " " << y << endl;
return 0;
}