結果

問題 No.3072 Sum of sqrt(x)
ユーザー 👑 hos.lyrichos.lyric
提出日時 2020-09-12 16:38:37
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 2,016 bytes
コンパイル時間 3,345 ms
コンパイル使用メモリ 94,308 KB
実行使用メモリ 5,024 KB
最終ジャッジ日時 2023-08-30 15:45:54
合計ジャッジ時間 121,669 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 3 ms
4,380 KB
testcase_02 AC 4 ms
4,380 KB
testcase_03 AC 3 ms
4,380 KB
testcase_04 AC 3 ms
4,380 KB
testcase_05 AC 4 ms
4,384 KB
testcase_06 AC 3 ms
4,380 KB
testcase_07 WA -
testcase_08 AC 529 ms
4,384 KB
testcase_09 AC 908 ms
4,384 KB
testcase_10 AC 1,971 ms
4,384 KB
testcase_11 AC 1,980 ms
4,380 KB
testcase_12 AC 1,949 ms
4,992 KB
testcase_13 AC 1,984 ms
4,388 KB
testcase_14 AC 1,976 ms
4,948 KB
testcase_15 AC 1,953 ms
4,388 KB
testcase_16 AC 1,951 ms
4,392 KB
testcase_17 AC 1,937 ms
4,388 KB
testcase_18 AC 1,943 ms
4,388 KB
testcase_19 AC 1,978 ms
4,392 KB
testcase_20 AC 1,975 ms
5,016 KB
testcase_21 AC 1,959 ms
4,388 KB
testcase_22 AC 1,965 ms
5,016 KB
testcase_23 TLE -
testcase_24 AC 1,964 ms
5,016 KB
testcase_25 AC 1,934 ms
4,392 KB
testcase_26 AC 1,995 ms
5,016 KB
testcase_27 AC 1,989 ms
4,388 KB
testcase_28 WA -
testcase_29 AC 1,997 ms
4,388 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#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;
  for (int i = 0; i < N; ++i) {
    fgets(buf, sizeof(buf), stdin);
    const Int x = atoll(buf);
    if (x > 0) {
      /*
        t = sqrt(x) - k
        f(t) = (t + k)^2 - x
        f'(t) = 2 (t + k)
        t <- t - ((t + k)^2 - x) / (2 (t + k)) = (t^2 + x - k^2) / (2 (t + k))
      */
      const long double y = sqrtl((long double)x);
      const Int k = (Int)y;
      long double t = k;
      t = (t * t + (x - k * k)) / (2.0L * (t + k));
      t = (t * t + (x - k * k)) / (2.0L * (t + k));
      t = (t * t + (x - k * k)) / (2.0L * (t + k));
      t = (t * t + (x - k * k)) / (2.0L * (t + k));
      t = (t * t + (x - k * k)) / (2.0L * (t + k));
      t = (t * t + (x - k * k)) / (2.0L * (t + k));
      t = (t * t + (x - k * k)) / (2.0L * (t + k));
      t = (t * t + (x - k * k)) / (2.0L * (t + k));
// cerr<<k<<" "<<t<<endl;
      upp += k;
      low += t;
    }
    sprintf(buf, "%.18Lf", upp + low);
    buf[18] = '\0';
    puts(buf);
  }
  return 0;
}
0