結果
問題 |
No.3072 Speedrun Query
|
ユーザー |
![]() |
提出日時 | 2025-05-14 13:08:09 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 3,263 bytes |
コンパイル時間 | 1,204 ms |
コンパイル使用メモリ | 90,036 KB |
実行使用メモリ | 7,848 KB |
最終ジャッジ日時 | 2025-05-14 13:09:50 |
合計ジャッジ時間 | 13,744 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | WA * 1 |
other | WA * 21 |
ソースコード
#include <iostream> #include <cmath> // Required for sqrtl function (square root for long double) #include <iomanip> // Required for std::fixed and std::setprecision for output formatting int main() { // Set up fast input/output. // std::ios_base::sync_with_stdio(false) disables synchronization with C standard streams, // which can speed up C++ stream operations. // std::cin.tie(nullptr) unties cin from cout, further speeding up input operations // by not forcing a flush of cout before cin operations. std::ios_base::sync_with_stdio(false); std::cin.tie(nullptr); int N; // Declare an integer variable N to store the number of elements in the sequence. std::cin >> N; // Read the value of N from standard input. // Declare a variable 'current_sum' of type long double to store the cumulative sum. // long double is used because it typically offers higher precision than double, // which is important given the strict error tolerance requirement (10^-15). // Initialize the sum to 0.0. The 'L' suffix denotes a long double literal. long double current_sum = 0.0L; // Configure the standard output stream (std::cout) for printing floating-point numbers: // - std::fixed forces the output to use fixed-point notation (e.g., 123.45) // instead of scientific notation (e.g., 1.2345e+2). // - std::setprecision(17) sets the number of digits to display after the decimal point to 17. // This level of precision is chosen to meet the problem's requirement for an absolute // or relative error less than 10^-15. Displaying around 17 decimal digits is generally // sufficient to represent the precision of long double and satisfy the error bounds. std::cout << std::fixed << std::setprecision(17); // Loop N times. The loop variable 'i' goes from 0 to N-1. // In each iteration, we process the (i+1)-th element of the sequence. for (int i = 0; i < N; ++i) { long long x; // Declare a variable 'x' of type long long to store the current element. // long long is used because the input values x_i can be up to 10^18, // which fits within a 64-bit signed integer type. std::cin >> x; // Read the value of the current element x_i from standard input. // Calculate the square root of x and add it to the running sum 'current_sum'. // - We use the sqrtl function from <cmath>, which computes the square root for long double arguments. // - We explicitly cast 'x' to long double using static_cast<long double>(x) before passing it to sqrtl. // This ensures that the calculation uses long double precision. // The result is added to 'current_sum'. current_sum += sqrtl(static_cast<long double>(x)); // Print the current value of the cumulative sum S_k = sum_{j=1}^{i+1} sqrt(x_j). // The value is printed according to the formatting set earlier (fixed-point, 17 decimal places). // '\n' adds a newline character, so each sum S_k appears on its own line as required. std::cout << current_sum << '\n'; } // Return 0 to indicate that the program executed successfully. return 0; }