結果
問題 |
No.8072 Sum of sqrt(x)
|
ユーザー |
👑 |
提出日時 | 2020-09-12 18:02:22 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 1,384 ms / 2,000 ms |
コード長 | 1,538 bytes |
コンパイル時間 | 774 ms |
コンパイル使用メモリ | 97,648 KB |
実行使用メモリ | 6,820 KB |
最終ジャッジ日時 | 2025-01-02 10:46:49 |
合計ジャッジ時間 | 128,070 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 27 |
コンパイルメッセージ
main.cpp: In function ‘int main()’: main.cpp:37:8: warning: ignoring return value of ‘char* fgets(char*, int, FILE*)’ declared with attribute ‘warn_unused_result’ [-Wunused-result] 37 | fgets(buf, sizeof(buf), stdin); | ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~ main.cpp:42:10: warning: ignoring return value of ‘char* fgets(char*, int, FILE*)’ declared with attribute ‘warn_unused_result’ [-Wunused-result] 42 | fgets(buf, sizeof(buf), stdin); | ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
ソースコード
#include <cassert> #include <cmath> #include <cstdint> #include <cstdio> #include <cstdlib> #include <cstring> #include <algorithm> #include <bitset> #include <complex> #include <deque> #include <functional> #include <iostream> #include <map> #include <numeric> #include <queue> #include <set> #include <sstream> #include <string> #include <unordered_map> #include <unordered_set> #include <utility> #include <vector> using namespace std; using Int = long long; template <class T1, class T2> ostream &operator<<(ostream &os, const pair<T1, T2> &a) { return os << "(" << a.first << ", " << a.second << ")"; }; template <class T> void pv(T a, T b) { for (T i = a; i != b; ++i) cerr << *i << " "; cerr << endl; } template <class T> bool chmin(T &t, const T &f) { if (t > f) { t = f; return true; } return false; } template <class T> bool chmax(T &t, const T &f) { if (t < f) { t = f; return true; } return false; } int main() { char buf[110]; fgets(buf, sizeof(buf), stdin); const int N = atoi(buf); Int upp = 0; long double low = 0.0, err = 0.0; for (int i = 0; i < N; ++i) { fgets(buf, sizeof(buf), stdin); const Int x = atoll(buf); if (x > 0) { /* sqrt(x) - k = (x - k^2) / (sqrt(x) + k) */ const long double y = sqrtl((long double)x); const Int k = (Int)y; const long double z = (x - k * k) / (y + k); upp += k; const long double tmp = low + z; err += z - (tmp - low); low = tmp; } printf("%.17Lg\n", upp + low + err); } return 0; }