結果

問題 No.81 すべて足すだけの簡単なお仕事です。
ユーザー hotpepsihotpepsi
提出日時 2015-07-30 21:58:38
言語 C++11
(gcc 11.4.0)
結果
WA  
実行時間 -
コード長 738 bytes
コンパイル時間 475 ms
コンパイル使用メモリ 66,608 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-09-24 22:20:45
合計ジャッジ時間 1,677 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <iostream>
#include <algorithm>
#include <sstream>
#include <vector>
#include <cmath>
#include <cstdio>

using namespace std;

int main(int argc, char *argv[])
{
	int N;
	cin >> N;
	long double a = 0, b = 0, d;
	for (int i = 0; i < N; ++i) {
		cin >> d;
		long double n = round(d);

		a += n;
		b += (d - n);
		while (b >= 1) {
			a += 1;
			b -= 1;
		}
		while (b <= -1) {
			a -= 1;
			b += 1;
		}
	}
	if (b >= 1-1e-12) {
		a += 1;
		b = 0;
	}
	if (b <= -1+1e-12) {
		a -= 1;
		b = 0;
	}
	if (a < 0) {
		if (b < 0) {
			b = -b;
		} else {
			a += 1;
			b = 1 - b;
		}
	} else {
		if (b < 0) {
			a -= 1;
			b = 1 + b;
		}
	}
	char w[16];
	sprintf(w, "%.10lf", (double)b);
	printf("%lld%s\n", (long long)a, w + 1);
	return 0;
}
0