結果
| 問題 | No.81 すべて足すだけの簡単なお仕事です。 |
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2026-01-21 23:58:00 |
| 言語 | C++23 (gcc 15.2.0 + boost 1.89.0) |
| 結果 |
AC
|
| 実行時間 | 2 ms / 5,000 ms |
| コード長 | 5,172 bytes |
| 記録 | |
| コンパイル時間 | 3,687 ms |
| コンパイル使用メモリ | 341,240 KB |
| 実行使用メモリ | 7,848 KB |
| 最終ジャッジ日時 | 2026-01-21 23:58:05 |
| 合計ジャッジ時間 | 4,826 ms |
|
ジャッジサーバーID (参考情報) |
judge2 / judge6 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 30 |
ソースコード
#line 1 "81.test.cpp"
#define PROBLEM "https://yukicoder.me/problems/no/81"
#line 2 "bigdec/bigdec.hpp"
#include <algorithm>
#include <cstdint>
#include <iostream>
#include <string>
template <int P> struct BigDec {
using i128 = __int128_t;
i128 val;
static i128 get_scale() {
i128 x = 1;
for (int i = 0; i < P; i++) x *= 10;
return x;
}
BigDec() : val(0) {}
BigDec(int64_t n) : val((i128)n * get_scale()) {}
BigDec(std::string s) { read_string(s); }
void read_string(std::string s) {
val = 0;
if (s.empty()) return;
bool negative = (s[0] == '-');
if (negative) s = s.substr(1);
size_t dot = s.find('.');
std::string s_int = (dot == std::string::npos) ? s : s.substr(0, dot);
std::string s_frac = (dot == std::string::npos) ? "" : s.substr(dot + 1);
i128 int_part = 0;
if (!s_int.empty()) {
for (char c : s_int) {
int_part = int_part * 10 + (c - '0');
}
}
i128 frac_part = 0;
if (s_frac.length() > P) s_frac = s_frac.substr(0, P);
while (s_frac.length() < P) s_frac += "0";
for (char c : s_frac) frac_part = frac_part * 10 + (c - '0');
val = int_part * get_scale() + frac_part;
if (negative) val = -val;
}
BigDec operator+(const BigDec &other) const {
BigDec ret;
ret.val = val + other.val;
return ret;
}
BigDec &operator+=(const BigDec &other) {
val += other.val;
return *this;
}
BigDec operator-(const BigDec &other) const {
BigDec ret;
ret.val = val - other.val;
return ret;
}
BigDec &operator-=(const BigDec &other) {
val -= other.val;
return *this;
}
BigDec operator*(const BigDec &other) const {
BigDec ret;
ret.val = (val * other.val) / get_scale();
return ret;
}
BigDec &operator*=(const BigDec &other) {
val = (val * other.val) / get_scale();
return *this;
}
BigDec operator/(const BigDec &other) const {
BigDec ret;
ret.val = (val * get_scale()) / other.val;
return ret;
}
BigDec &operator/=(const BigDec &other) {
val = (val * get_scale()) / other.val;
return *this;
}
bool operator<(const BigDec &other) const { return val < other.val; }
bool operator>(const BigDec &other) const { return val > other.val; }
bool operator<=(const BigDec &other) const { return val <= other.val; }
bool operator>=(const BigDec &other) const { return val >= other.val; }
bool operator==(const BigDec &other) const { return val == other.val; }
bool operator!=(const BigDec &other) const { return val != other.val; }
friend std::istream &operator>>(std::istream &is, BigDec &bd) {
std::string s;
is >> s;
bd.read_string(s);
return is;
}
friend std::ostream &operator<<(std::ostream &os, const BigDec &bd) {
i128 temp = bd.val;
if (temp < 0) {
os << "-";
temp = -temp;
}
i128 scale = get_scale();
i128 int_part = temp / scale;
i128 frac_part = temp % scale;
std::string s_int = "";
if (int_part == 0)
s_int = "0";
else {
i128 t = int_part;
while (t > 0) {
s_int += (char)('0' + (t % 10));
t /= 10;
}
std::reverse(s_int.begin(), s_int.end());
}
os << s_int;
os << ".";
std::string s_frac = "";
i128 t_frac = frac_part;
for (int i = 0; i < P; ++i) {
s_frac += (char)('0' + (t_frac % 10));
t_frac /= 10;
}
std::reverse(s_frac.begin(), s_frac.end());
os << s_frac;
return os;
}
};
#line 3 "81.test.cpp"
#include <bits/stdc++.h>
using namespace std;
void solve() {
int N;
cin >> N;
BigDec<10> ans;
for (int i = 0; i < N; i++) {
BigDec<10> now;
cin >> now;
ans += now;
}
cout << ans << '\n';
}
int main() {
ios::sync_with_stdio(false);
cin.tie(NULL);
int t = 1;
// cin >> t;
while (t--) solve();
return 0;
}