結果
| 問題 |
No.81 すべて足すだけの簡単なお仕事です。
|
| コンテスト | |
| ユーザー |
peroon
|
| 提出日時 | 2019-05-03 11:29:59 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 2,420 bytes |
| コンパイル時間 | 2,119 ms |
| コンパイル使用メモリ | 176,560 KB |
| 実行使用メモリ | 6,824 KB |
| 最終ジャッジ日時 | 2024-12-31 15:31:11 |
| 合計ジャッジ時間 | 3,225 ms |
|
ジャッジサーバーID (参考情報) |
judge4 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 24 WA * 6 |
ソースコード
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
#define FOR(i,a,b) for(ll i=(a);i<(b);++i)
#define ALL(v) (v).begin(), (v).end()
#define p(s) cout<<(s)<<endl
#define p2(s, t) cout << (s) << " " << (t) << endl
#define br() p("")
#define pn(s) cout << (#s) << " " << (s) << endl
#define p_yes() p("Yes")
#define p_no() p("No")
const ll mod = 1e9 + 7;
const ll inf = 1e18;
template < typename T >
void vprint(T &V){
for(auto v : V){
cout << v << " ";
}
cout << endl;
}
vector<string> split_str(string s, char c){
vector<string> ret;
stringstream ss;
FOR(i, 0, s.size()){
if(s[i]==c){
ret.push_back(ss.str());
ss.str("");
ss.clear();
}else{
ss << s[i];
}
}
ret.push_back(ss.str());
return ret;
}
// n桁にする
string fill_str(string s, ll n){
ll L = s.size();
stringstream ss;
ss << s;
FOR(i, 0, n-L){
ss << '0';
}
return ss.str();
}
int main(){
cin.tie(0);
ios::sync_with_stdio(false);
// input
ll N;
cin >> N;
ll up = 0;
ll down = 0;
FOR(i, 0, N){
string A;
cin >> A;
bool is_minus = false;
if(A[0]=='-'){
is_minus = true;
A = A.substr(1);
}
// 小数点ないならつける
if(A.find('.')==string::npos){
A += ".0";
}
auto S = split_str(A, '.');
if(!is_minus){
up += stoll(S[0]);
down += stoll(fill_str(S[1], 10));
}else{
up -= stoll(S[0]);
down -= stoll(fill_str(S[1], 10));
}
}
// pn(up);
// pn(down);
// -.+のとき
if(up<0 && down>0){
up += 1;
down -= 1e10;
}
// 小数部の切り上げ
ll kuriagari = down / 1e10;
up += kuriagari;
down -= kuriagari * 1e10;
if(down<0 && up>0){
up--;
down += 1e10;
}
bool is_minus = false;
if(up<0 || down<0){
is_minus = true;
}
// pn(up);
// pn(down);
if(is_minus){
cout << '-';
}
cout << abs(up) << '.' << fill_str(to_string(abs(down)), 10) << endl;
return 0;
}
peroon