結果

問題 No.81 すべて足すだけの簡単なお仕事です。
ユーザー KKT89KKT89
提出日時 2021-09-05 18:00:03
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 7,889 bytes
コンパイル時間 2,772 ms
コンパイル使用メモリ 151,456 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-08-23 14:15:38
合計ジャッジ時間 4,038 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#pragma GCC optimize("Ofast")
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <queue>
#include <cstdio>
#include <ctime>
#include <assert.h>
#include <chrono>
#include <random>
#include <numeric>
#include <set>
#include <deque>
#include <stack>
#include <sstream>
#include <utility>
#include <cstring>
using namespace std;
typedef long long int ll;
typedef unsigned long long ull;

mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());
ll myRand(ll B) {
    return (ull)rng() % B;
}

// 参考:
// https://awakia-n.hatenablog.com/entry/20100515/1273922367
// 今後参考にしたい:
// https://drive.google.com/file/d/15_gwYirAxwjbTMEq5MXaPEZAlzkbZfia/view
struct BigInt{
    vector<int> d;
    bool minus = false; 
    BigInt& normalize(){
        int i = (int)d.size() - 1;
        while(i>=0 and d[i] == 0)--i;
        d.resize(i+1);
        if((int)d.size() == 0) {
            d.emplace_back(0);
            minus = false;
        }
        return *this;
    }
    int size(){
        return d.size();
    }
    BigInt(ll _x = 0){
        if(_x < 0){
            minus = true;
            _x = -_x;
        }
        while(_x){
            d.emplace_back(_x%10);
            _x /= 10;
        }
        if(d.size() == 0){
            d.emplace_back(0);
        }
    }
    BigInt(string _x){
        for(char &c:_x){
            if(c == '-'){
                minus = true;
            }
            else{
                d.emplace_back(c-'0');
            }
        }
        reverse(d.begin(), d.end());
        normalize();
    }
    BigInt& operator = (const BigInt& x);
    BigInt& operator = (const ll& x);
    BigInt& operator = (const string& x);
    const bool operator < (const BigInt& x) const;
    const bool operator > (const BigInt& x) const;
    const bool operator <= (const BigInt& x) const;
    const bool operator >= (const BigInt& x) const;
    const bool operator != (const BigInt& x) const;
    const bool operator == (const BigInt& x) const;
    BigInt operator -() const;
    BigInt& operator += (const BigInt& x);
    BigInt& operator -= (const BigInt& x);
    BigInt& operator *= (const BigInt& x);
    BigInt& operator /= (const BigInt& x);
    BigInt& operator %= (const BigInt& x);
    const BigInt operator + (const BigInt& x) const;
    const BigInt operator - (const BigInt& x) const;
    const BigInt operator * (const BigInt& x) const;
    const BigInt operator / (const BigInt& x) const;
    const BigInt operator % (const BigInt& x) const;
    friend pair<BigInt, BigInt> divmod (const BigInt& lhs, const BigInt& rhs);
    friend istream& operator >> (istream& is, BigInt& x);
    friend ostream& operator << (ostream& os, const BigInt& x);
    friend const BigInt abs(BigInt x);
};

BigInt& BigInt::operator = (const BigInt& x){
    minus = x.minus;
    d = x.d;
    return *this;
}

BigInt& BigInt::operator = (const ll& x){
    return *this = BigInt(x);
}

BigInt& BigInt::operator = (const string& x){
    return *this = BigInt(x);
}

const bool BigInt::operator < (const BigInt& x) const{
    if(minus != x.minus) return (minus ? true : false);
    if(d.size() != x.d.size()) return (d.size() < x.d.size()) ^ minus;
    for (int i = (int)d.size()-1; i >= 0; --i){
        if(d[i] != x.d[i]) return (d[i] < x.d[i]) ^ minus;
    }
    return false;
}

const bool BigInt::operator > (const BigInt& x) const{return x<(*this);}
const bool BigInt::operator <= (const BigInt& x) const{return !(x<(*this));}
const bool BigInt::operator >= (const BigInt& x) const{return !(x>(*this));}
const bool BigInt::operator != (const BigInt& x) const{return (*this)<x || x<(*this);}
const bool BigInt::operator == (const BigInt& x) const{return !((*this)<x || x<(*this));}

BigInt BigInt::operator -() const{
    BigInt res(*this);
    res.minus = !res.minus;
    return res;
}

BigInt& BigInt::operator += (const BigInt& x){
    if(minus != x.minus) return *this -= -x;
    if(d.size() < x.d.size()) d.resize(x.d.size());
    int tmp = 0;
    for (int i = 0; i < (int)d.size(); ++i) {
        d[i] += (i < (int)x.d.size() ? x.d[i] : 0) + tmp;
        if(d[i] >= 10){
            tmp = 1;
            d[i] -= 10;
        }
        else tmp = 0;
    }
    if(tmp) d.emplace_back(1);
    return *this;
}

BigInt& BigInt::operator -= (const BigInt& x){
    if(minus != x.minus) return *this += -x;
    vector<int> dd(x.d);
    if(((*this)<x) ^ minus){
        swap(d,dd);
        minus = !minus;
    }
    int tmp = 0;
    for (int i = 0; i < (int)d.size(); ++i) {
        d[i] -= (i < (int)dd.size() ? dd[i] : 0) + tmp;
        if(d[i] < 0){
            d[i] += 10;
            tmp = 1;
        }
        else{
            tmp = 0;
        }
    }
    return this->normalize();
}

BigInt& BigInt::operator *= (const BigInt& x){
    minus ^= x.minus;
    int N1 = (int)d.size();
    int N2 = (int)x.d.size();
    int N = N1 + N2;
    vector<int> dd(N);
    for (int i = 0; i < N1; ++i) {
        for (int j = 0; j < N2; ++j) {
            dd[i+j] += d[i] * x.d[j];
        }
    }
    for (int i = 0; i+1 < N; ++i) {
        dd[i+1] += dd[i] / 10;
        dd[i] %= 10;
    }
    swap(d,dd);
    return this->normalize();
}

BigInt& BigInt::operator /= (const BigInt& x){
    return *this = divmod(*this, x).first;
}

BigInt& BigInt::operator %= (const BigInt& x){
    return *this = divmod(*this, x).second;
}

const BigInt BigInt::operator + (const BigInt& x) const{
    BigInt res(*this); return res += x;
}
const BigInt BigInt::operator - (const BigInt& x) const{
    BigInt res(*this); return res -= x;
}
const BigInt BigInt::operator * (const BigInt& x) const{
    BigInt res(*this); return res *= x;
}
const BigInt BigInt::operator / (const BigInt& x) const{
    BigInt res(*this); return res /= x;
}
const BigInt BigInt::operator % (const BigInt& x) const{
    BigInt res(*this); return res %= x;
}

pair<BigInt, BigInt> divmod (const BigInt& lhs, const BigInt& rhs){
    if((int)rhs.d.size() == 1 and rhs.d[0] == 0){
        cerr << "error: division by zero" << endl;
        exit(1);
    }
    if(lhs < rhs){
        return make_pair(BigInt(0), lhs);
    }
    BigInt base,q,r;
    int N = (int)lhs.d.size() - (int)rhs.d.size() + 1;
    base.d.resize(N); base.d.back() = 1;
    q.d.resize(N);
    r = lhs;
    for (int i = N-1; i >= 0; --i) {
        int L = 0, R = 10;
        while(R-L > 1){
            int mid = (L+R)/2;
            if(BigInt(mid)*rhs*base <= r){
                L = mid;
            }
            else{
                R = mid;
            }
        }
        q.d[i] = L;
        r -= BigInt(L)*rhs*base;
        base.d.pop_back(); if(base.d.size()) base.d.back() = 1;
    }
    return make_pair(q.normalize(), r.normalize());
}

istream& operator >> (istream& is, BigInt& x){
    string s; is >> s;
    x = BigInt(s);
    return is;
}

ostream& operator << (ostream& os, const BigInt& x){
    if(x.minus) os << '-';
    int N = x.d.size();
    for (int i = N-1; i >= 0; --i){
        os << x.d[i];
    }
    return os;
}

const BigInt abs(BigInt x){
    x.minus = false;
    return x;
}

int main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    BigInt res=BigInt(0);
    int n; cin >> n;
    for(int i=0;i<n;i++){
        int m=10;
        string s; cin >> s;
        string t="";
        bool flg = false;
        for(char c:s){
            if(c=='.'){
                flg = true;
            }
            else{
                t+=c;
                if(flg)m--;
            }
        }
        BigInt a = BigInt(t);
        for(int j=0;j<m;j++){
            a*=BigInt(10);
        }

        res += a;
    }
    ll u = 1e10;
    if(res.minus){
        cout << "-";
        res.minus = false;
    }
    cout << res/BigInt(u) << ".";
    auto d = (res%BigInt(u));
    cout << d;
    for(int i=0;i<10-d.d.size();i++){
        cout << 0;
    }
    cout << endl;
}
0