結果

問題 No.1251 絶対に間違ってはいけない最小化問題
ユーザー ぷらぷら
提出日時 2020-10-09 22:31:16
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 850 bytes
コンパイル時間 1,436 ms
コンパイル使用メモリ 169,396 KB
実行使用メモリ 16,816 KB
最終ジャッジ日時 2023-09-27 18:22:02
合計ジャッジ時間 8,978 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
#define int long long
typedef pair<int,int> P;
int INF = 1e9+7;
int mod = 1e9+7;
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};
int N;
double f(double x,vector<double>a,vector<double>b) {
    double res = 0;
    for(int i = 0; i < N; i++) {
        res += abs(x-a[i])*b[i];
    }
    return res;
}
signed main() {
    cin >> N;
    vector<double>A(N),B(N);
    for(int i = 0; i < N; i++) {
        cin >> A[i];
    }
    for(int i = 0; i < N; i++) {
        cin >> B[i];
    }
    double low = -INF,high = INF;
    int time = 1000;
    while (time--) {
        double c1 = (low*2+high)/3;
        double c2 = (low+high*2)/3;
        if(f(c1,A,B) > f(c2,A,B)) {
            low = c1;
        }
        else {
            high = c2;
        }
    }
    cout << high << " " << f(high,A,B) << endl;
}
0