結果
問題 | No.2970 三次関数の絶対値 |
ユーザー | SSRS |
提出日時 | 2024-11-29 22:30:03 |
言語 | C++17 (gcc 12.3.0 + boost 1.83.0) |
結果 |
AC
|
実行時間 | 74 ms / 2,000 ms |
コード長 | 1,061 bytes |
コンパイル時間 | 2,215 ms |
コンパイル使用メモリ | 209,368 KB |
実行使用メモリ | 13,148 KB |
最終ジャッジ日時 | 2024-11-29 22:30:09 |
合計ジャッジ時間 | 5,400 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge1 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 31 ms
11,720 KB |
testcase_01 | AC | 34 ms
12,368 KB |
testcase_02 | AC | 30 ms
12,248 KB |
testcase_03 | AC | 55 ms
12,808 KB |
testcase_04 | AC | 32 ms
12,224 KB |
testcase_05 | AC | 34 ms
12,092 KB |
testcase_06 | AC | 34 ms
12,012 KB |
testcase_07 | AC | 34 ms
11,908 KB |
testcase_08 | AC | 34 ms
12,660 KB |
testcase_09 | AC | 32 ms
12,768 KB |
testcase_10 | AC | 36 ms
11,688 KB |
testcase_11 | AC | 38 ms
11,940 KB |
testcase_12 | AC | 33 ms
12,404 KB |
testcase_13 | AC | 40 ms
11,620 KB |
testcase_14 | AC | 30 ms
12,312 KB |
testcase_15 | AC | 37 ms
12,368 KB |
testcase_16 | AC | 44 ms
11,680 KB |
testcase_17 | AC | 33 ms
12,128 KB |
testcase_18 | AC | 32 ms
11,752 KB |
testcase_19 | AC | 31 ms
12,072 KB |
testcase_20 | AC | 34 ms
12,312 KB |
testcase_21 | AC | 32 ms
11,724 KB |
testcase_22 | AC | 32 ms
12,716 KB |
testcase_23 | AC | 33 ms
12,448 KB |
testcase_24 | AC | 32 ms
12,028 KB |
testcase_25 | AC | 35 ms
11,604 KB |
testcase_26 | AC | 34 ms
12,092 KB |
testcase_27 | AC | 35 ms
12,116 KB |
testcase_28 | AC | 42 ms
12,108 KB |
testcase_29 | AC | 34 ms
11,696 KB |
testcase_30 | AC | 33 ms
12,256 KB |
testcase_31 | AC | 39 ms
12,072 KB |
testcase_32 | AC | 35 ms
11,908 KB |
testcase_33 | AC | 30 ms
11,604 KB |
testcase_34 | AC | 34 ms
12,088 KB |
testcase_35 | AC | 32 ms
12,240 KB |
testcase_36 | AC | 31 ms
11,724 KB |
testcase_37 | AC | 41 ms
12,308 KB |
testcase_38 | AC | 33 ms
11,988 KB |
testcase_39 | AC | 74 ms
12,172 KB |
testcase_40 | AC | 34 ms
12,312 KB |
testcase_41 | AC | 33 ms
12,104 KB |
testcase_42 | AC | 32 ms
11,752 KB |
testcase_43 | AC | 32 ms
12,236 KB |
testcase_44 | AC | 40 ms
11,848 KB |
testcase_45 | AC | 30 ms
12,288 KB |
testcase_46 | AC | 37 ms
13,148 KB |
testcase_47 | AC | 31 ms
12,172 KB |
testcase_48 | AC | 37 ms
12,688 KB |
testcase_49 | AC | 34 ms
11,692 KB |
コンパイルメッセージ
main.cpp: In function 'int main()': main.cpp:10:23: warning: narrowing conversion of 'L' from 'int' to 'double' [-Wnarrowing] 10 | vector<double> X = {L, R}; | ^ main.cpp:10:23: warning: narrowing conversion of 'L' from 'int' to 'double' [-Wnarrowing] main.cpp:10:26: warning: narrowing conversion of 'R' from 'int' to 'double' [-Wnarrowing] 10 | vector<double> X = {L, R}; | ^ main.cpp:10:26: warning: narrowing conversion of 'R' from 'int' to 'double' [-Wnarrowing]
ソースコード
#include <bits/stdc++.h> using namespace std; const double INF = 10000000; const double eps = 0.0000001; int main(){ int C0, C1, C2, C3; cin >> C0 >> C1 >> C2 >> C3; int L, R; cin >> L >> R; vector<double> X = {L, R}; if (C3 != 0){ double a = C3 * 3, b = C2 * 2, c = C1; if (b * b - 4 * a * c >= 0){ for (int sgn : {-1, 1}){ double x = (-b + sgn * sqrt(b * b - 4 * a * c)) / (2 * a); if (L <= x && x <= R){ X.push_back(x); } } } } else if (C2 != 0){ double x = -C1 / (C2 * 2); if (L <= x && x <= R){ X.push_back(x); } } int N = 1000000; for (int i = 0; i <= N; i++){ X.push_back((double) (L * i + R * (N - i)) / N); } sort(X.begin(), X.end()); int cnt = X.size(); auto f = [&](double x){ return ((x * C3 + C2) * x + C1) * x + C0; }; double ans = INF; for (int i = 0; i < cnt; i++){ ans = min(ans, abs(f(X[i]))); } for (int i = 0; i < cnt - 1; i++){ if (f(X[i]) * f(X[i + 1]) < eps){ ans = 0; } } cout << ans << endl; }