結果

問題 No.297 カードの数式
ユーザー imulanimulan
提出日時 2016-06-20 03:05:29
言語 C++11
(gcc 11.4.0)
結果
WA  
実行時間 -
コード長 1,289 bytes
コンパイル時間 1,180 ms
コンパイル使用メモリ 164,140 KB
実行使用メモリ 6,944 KB
最終ジャッジ日時 2024-04-19 13:03:41
合計ジャッジ時間 2,038 ms
ジャッジサーバーID
(参考情報)
judge5 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
6,812 KB
testcase_01 AC 1 ms
6,940 KB
testcase_02 AC 1 ms
6,940 KB
testcase_03 AC 1 ms
6,940 KB
testcase_04 WA -
testcase_05 AC 1 ms
6,940 KB
testcase_06 WA -
testcase_07 AC 2 ms
6,944 KB
testcase_08 AC 2 ms
6,944 KB
testcase_09 AC 2 ms
6,944 KB
testcase_10 AC 1 ms
6,940 KB
testcase_11 AC 1 ms
6,940 KB
testcase_12 AC 1 ms
6,940 KB
testcase_13 AC 1 ms
6,940 KB
testcase_14 AC 2 ms
6,940 KB
testcase_15 AC 1 ms
6,940 KB
testcase_16 AC 1 ms
6,940 KB
testcase_17 AC 1 ms
6,944 KB
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
testcase_22 AC 1 ms
6,940 KB
testcase_23 WA -
testcase_24 WA -
testcase_25 WA -
権限があれば一括ダウンロードができます
コンパイルメッセージ
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);
      |         ~~~~~^~~~~~~~~~~

ソースコード

diff #

#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<int> d;

    //小さい方からa-1個取り出す
    rep(i,a-1) d.pb(num[i]);
    //大きい方から取り出してくっつける
    int add=0;
    for(int i=b-1; i>=a-1; --i)
    {
        add=add*10+num[i];
    }
    d.pb(add);

    //max,min
    int 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];

    printf("%d %d\n",x,y);
    return 0;
}
0