結果

問題 No.81 すべて足すだけの簡単なお仕事です。
ユーザー BantakoBantako
提出日時 2018-12-28 19:51:46
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 2 ms / 5,000 ms
コード長 1,481 bytes
コンパイル時間 1,453 ms
コンパイル使用メモリ 166,580 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-09-29 22:45:46
合計ジャッジ時間 2,665 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 1 ms
4,384 KB
testcase_02 AC 1 ms
4,376 KB
testcase_03 AC 1 ms
4,376 KB
testcase_04 AC 2 ms
4,380 KB
testcase_05 AC 1 ms
4,380 KB
testcase_06 AC 1 ms
4,380 KB
testcase_07 AC 1 ms
4,376 KB
testcase_08 AC 1 ms
4,380 KB
testcase_09 AC 1 ms
4,376 KB
testcase_10 AC 1 ms
4,380 KB
testcase_11 AC 2 ms
4,380 KB
testcase_12 AC 1 ms
4,380 KB
testcase_13 AC 1 ms
4,376 KB
testcase_14 AC 1 ms
4,376 KB
testcase_15 AC 2 ms
4,380 KB
testcase_16 AC 1 ms
4,376 KB
testcase_17 AC 1 ms
4,380 KB
testcase_18 AC 1 ms
4,380 KB
testcase_19 AC 1 ms
4,376 KB
testcase_20 AC 2 ms
4,380 KB
testcase_21 AC 2 ms
4,380 KB
testcase_22 AC 2 ms
4,376 KB
testcase_23 AC 2 ms
4,376 KB
testcase_24 AC 1 ms
4,376 KB
testcase_25 AC 1 ms
4,376 KB
testcase_26 AC 1 ms
4,376 KB
testcase_27 AC 2 ms
4,376 KB
testcase_28 AC 1 ms
4,380 KB
testcase_29 AC 1 ms
4,376 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp:14:1: 警告: ISO C++ では型の無い ‘main’ の宣言を禁止しています [-Wreturn-type]
   14 | main(){
      | ^~~~

ソースコード

diff #

#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=int(a);i<int(b);++i)
using namespace std;
typedef long long ll;
int INF = (1LL << 30) - 1;
ll MOD = 1e10;
int charsearch(string s,char c){
    //文字cが文字列sに含まれるかどうか
    rep(i, 0, s.length()){
        if(s[i] == c)return i;
    }
    return -1;
}
main(){
    int sign = 1;
    ll num[2] = {};
    int N;
    cin >> N;
    rep(i,0,N){
        string s;
        cin >> s;
        int ind = charsearch(s,'.');
        ll a,b;
        if(ind != -1){
            //cout << s.substr(0,ind) << endl;
            //cout << s.substr(ind+1) << endl;
            a = stoll(s.substr(0,ind));
            b = stoll(s.substr(ind+1) + string(10 - (s.size() - ind - 1), '0') );
            //cout << a << " " << b << endl;  
        }else{
            a = stoll(s);
            b = 0;
        }
        int sign2 = s[0] == '-' ? -1 : 1;
        a = abs(a);
        if(sign == sign2){
            num[1] += b;
            num[0] += a + (num[1] / MOD);
            num[1] %= MOD;
        }else{
            if(num[0] < a || num[0] == a && num[1] < b){
                swap(num[0], a);
                swap(num[1], b);
                sign = sign2;
            }
            num[1] -= b;
            if(num[1] < 0){
                num[0]--;
                num[1] += MOD;
            }
            num[0] -= a;
        }        
    }
    cout << (sign == -1 ? "-" : "");
    printf("%lld.%010lld\n", num[0], num[1]);
}
0