結果

問題 No.81 すべて足すだけの簡単なお仕事です。
ユーザー heabiheabi
提出日時 2021-02-07 16:22:45
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 2 ms / 5,000 ms
コード長 3,939 bytes
コンパイル時間 1,690 ms
コンパイル使用メモリ 172,048 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-09-29 22:58:29
合計ジャッジ時間 2,978 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 1 ms
4,384 KB
testcase_03 AC 1 ms
4,380 KB
testcase_04 AC 1 ms
4,376 KB
testcase_05 AC 1 ms
4,380 KB
testcase_06 AC 1 ms
4,376 KB
testcase_07 AC 1 ms
4,380 KB
testcase_08 AC 2 ms
4,380 KB
testcase_09 AC 2 ms
4,376 KB
testcase_10 AC 2 ms
4,380 KB
testcase_11 AC 2 ms
4,376 KB
testcase_12 AC 2 ms
4,380 KB
testcase_13 AC 1 ms
4,376 KB
testcase_14 AC 2 ms
4,376 KB
testcase_15 AC 1 ms
4,376 KB
testcase_16 AC 1 ms
4,376 KB
testcase_17 AC 1 ms
4,376 KB
testcase_18 AC 2 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,376 KB
testcase_22 AC 1 ms
4,380 KB
testcase_23 AC 2 ms
4,376 KB
testcase_24 AC 1 ms
4,376 KB
testcase_25 AC 1 ms
4,380 KB
testcase_26 AC 2 ms
4,380 KB
testcase_27 AC 2 ms
4,380 KB
testcase_28 AC 1 ms
4,376 KB
testcase_29 AC 2 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;

#define all(v) v.begin(), v.end()
#define ll long long
#define rep(i, n) for (ll i = 0; i < n; ++i)
#define rep_up(i, a, b) for (ll i = a; i < b; ++i)
#define rep_down(i, a, b) for (ll i = a; i > b; --i)

#define P pair<ll, ll>
#define Graph vector<vector<ll>>
#define fi first
#define se second

#define vvvvll vector<vector<vector<vector<ll>>>>
#define vvvll vector<vector<vector<ll>>>
#define vvll vector<vector<ll>>
#define vll vector<ll>

#define vvvvdo vector<vector<vector<vector<double>>>>
#define vvvdo vector<vector<vector<double>>>
#define vvdo vector<vector<double>>
#define vdo vector<double>

#define pqll priority_queue<ll>
#define pqllg priority_queue<ll, vector<ll>, greater<ll>>

constexpr ll INF = (1ll << 60);
constexpr ll mod = 998244353;
// constexpr ll mod = 67280421310721;
// constexpr ll mod = 1000000007;
constexpr double pi = 3.14159265358979323846;
template <typename T>
inline bool chmax(T &a, T b) {
    if (a < b) {
        a = b;
        return 1;
    }
    return 0;
}
template <typename T>
inline bool chmin(T &a, T b) {
    if (a > b) {
        a = b;
        return 1;
    }
    return 0;
}
template <typename T>
void pt_vll(vector<T> &v) {
    ll vs = v.size();
    rep(i, vs) {
        cout << v[i];
        if (i == vs - 1)
            cout << "\n";
        else
            cout << " ";
    }
}
template <typename T>
void pt_vvll(vector<vector<T>> &v) {
    ll vs = v.size();
    rep(i, vs) pt_vll(v[i]);
}
template <typename T>
void pt(T val) {
    cout << val << "\n";
}

ll gcd(ll a, ll b) {
    if (a % b == 0) return b;
    return gcd(b, a % b);
}
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }

ll modinv(ll a, ll m) {
    ll b = m, u = 1, v = 0;
    while (b) {
        ll t = a / b;
        a -= t * b;
        swap(a, b);
        u -= t * v;
        swap(u, v);
    }
    u %= m;
    if (u < 0) u += m;
    return u;
}

ll modpow(ll x, ll n) {
    ll ret = 1;
    while (n > 0) {
        if (n & 1)
            ret = ret * x % mod;  // n の最下位bitが 1 ならば x^(2^i) をかける
        x = x * x % mod;
        n >>= 1;  // n を1bit 左にずらす
    }
    return ret;
}
ll minv(ll a, ll m) { return modpow(a, m - 2); }

string To_String(ll a) {
    string ret;
    if (a == 0) return "0";

    ll minus = false;
    if (a < 0) {
        minus = true;
        a *= -1;
    }

    while (a) {
        ret.push_back(a % 10 + '0'), a /= 10;
    }

    if (minus) ret.push_back('-');

    reverse(all(ret));
    return ret;
}

P double_to_long_long(string s, ll dig) {
    bool minus = false;
    if (s[0] == '-') {
        s = s.substr(1);
        minus = true;
    }

    ll Int = 0, Dic = 0;

    ll i;
    // 整数部分
    for (i = 0; i < s.size() && s[i] != '.'; i++) {
        Int = Int * 10 + s[i] - '0';
    }

    // 小数部分
    ll mul = 1;
    while (--dig) mul *= 10;
    for (ll j = i + 1; j < s.size(); j++) {
        Dic += (s[j] - '0') * mul;
        mul /= 10;
    }

    if (minus) {
        Int *= -1, Dic *= -1;
    }

    return {Int, Dic};
}

int main() {
    ll N;
    cin >> N;
    vector<string> A(N);
    rep(i, N) cin >> A[i];

    ll Int = 0, Dic = 0;

    rep(i, N) {
        P a = double_to_long_long(A[i], 10);
        Int += a.fi;
        Dic += a.se;
    }

    Int += (Dic / 10000000000);
    Dic %= 10000000000;

    if (Int > 0 && Dic < 0) {
        Dic += 10000000000;
        Int--;
    } else if (Int < 0 && Dic > 0) {
        Dic = abs(Dic - 10000000000);
        Int++;
        if (Int == 0) cout << '-';
    } else if (Int <= 0 && Dic < 0) {
        if (Int == 0) cout << '-';
        Dic *= -1;
    }

    string DIC = To_String(Dic);
    ll pz = To_String(10000000000).size() - DIC.size() - 1;
    reverse(all(DIC));
    rep(i, pz) DIC.push_back('0');
    reverse(all(DIC));
    while (DIC.size() < 10) DIC.push_back('0');

    cout << Int << '.' << DIC << "\n";
    return 0;
}
0