結果
| 問題 |
No.81 すべて足すだけの簡単なお仕事です。
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2025-01-27 15:54:15 |
| 言語 | C++23 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 4 ms / 5,000 ms |
| コード長 | 1,839 bytes |
| コンパイル時間 | 4,922 ms |
| コンパイル使用メモリ | 317,552 KB |
| 実行使用メモリ | 5,248 KB |
| 最終ジャッジ日時 | 2025-01-27 15:54:22 |
| 合計ジャッジ時間 | 6,085 ms |
|
ジャッジサーバーID (参考情報) |
judge1 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 30 |
ソースコード
typedef long long ll;
typedef long double ld;
#include <bits/stdc++.h>
using namespace std;
// #define int long long
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
template<typename T>
using ordered_set = tree<T, null_type, std::less<T>, rb_tree_tag, tree_order_statistics_node_update>;
// std::cout << *s.find_by_order(1) << std::endl; // 2
vector<string> split(string str, char del) {
int first = 0;
int last = str.find_first_of(del);
vector<string> result;
while (first < str.size()) {
result.push_back(str.substr(first, last - first));
first = last + 1;
last = str.find_first_of(del, first);
if (last == string::npos) last = str.size();
}
return result;
}
signed main(){
// これがないと落ちることがある
ios_base::sync_with_stdio(false);
cin.tie(0);
ll n;
cin >> n;
ll sei = 0;
ld sum = 0;
ll sho = 0;
for (ll i = 0; i < n; i++){
string a;
cin >> a;
sum += stold(a);
bool mi = false;
if(a[0]=='-')mi=true;
bool dot = false;
for (auto e : a) {
if(e=='.')dot=true;
}
auto res = split(a, '.');
sei+=stoll(res[0]);
if(dot){
auto num = res[1].insert(res[1].length(),10-res[1].length(),'0');
if(mi){
sho-=stoll(num);
}else{
sho+=stoll(num);
}
if(sho<0){
sei--;
sho+=10000000000;
}
sei += sho/10000000000;
sho %= 10000000000;
}
}
if(sei<0&&sho>0){
sei++;
sho = 10000000000-sho;
}
if(sum<0){
cout << "-";
}
cout << abs(sei)<<"."<<to_string(sho).insert(0, 10-to_string(sho).size(), '0') << endl;
}