結果

問題 No.1251 絶対に間違ってはいけない最小化問題
ユーザー 夜
提出日時 2020-10-09 22:00:44
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 414 ms / 2,000 ms
コード長 1,105 bytes
コンパイル時間 734 ms
コンパイル使用メモリ 90,784 KB
実行使用メモリ 6,672 KB
最終ジャッジ日時 2023-09-27 16:58:20
合計ジャッジ時間 21,484 ms
ジャッジサーバーID
(参考情報)
judge14 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 AC 1 ms
4,376 KB
testcase_02 AC 1 ms
4,376 KB
testcase_03 AC 1 ms
4,380 KB
testcase_04 AC 1 ms
4,376 KB
testcase_05 AC 1 ms
4,380 KB
testcase_06 AC 1 ms
4,376 KB
testcase_07 AC 1 ms
4,380 KB
testcase_08 AC 2 ms
4,376 KB
testcase_09 AC 1 ms
4,376 KB
testcase_10 AC 1 ms
4,380 KB
testcase_11 AC 1 ms
4,380 KB
testcase_12 AC 2 ms
4,380 KB
testcase_13 AC 2 ms
4,380 KB
testcase_14 AC 2 ms
4,380 KB
testcase_15 AC 2 ms
4,380 KB
testcase_16 AC 2 ms
4,380 KB
testcase_17 AC 2 ms
4,376 KB
testcase_18 AC 396 ms
6,404 KB
testcase_19 AC 383 ms
6,228 KB
testcase_20 AC 219 ms
5,100 KB
testcase_21 AC 34 ms
4,380 KB
testcase_22 AC 238 ms
5,216 KB
testcase_23 AC 24 ms
4,380 KB
testcase_24 AC 317 ms
5,840 KB
testcase_25 AC 229 ms
5,160 KB
testcase_26 AC 83 ms
4,380 KB
testcase_27 AC 26 ms
4,376 KB
testcase_28 AC 413 ms
6,460 KB
testcase_29 AC 414 ms
6,468 KB
testcase_30 AC 414 ms
6,488 KB
testcase_31 AC 413 ms
6,476 KB
testcase_32 AC 413 ms
6,672 KB
testcase_33 AC 413 ms
6,528 KB
testcase_34 AC 413 ms
6,612 KB
testcase_35 AC 414 ms
6,468 KB
testcase_36 AC 414 ms
6,588 KB
testcase_37 AC 413 ms
6,460 KB
testcase_38 AC 413 ms
6,456 KB
testcase_39 AC 414 ms
6,456 KB
testcase_40 AC 413 ms
6,588 KB
testcase_41 AC 413 ms
6,460 KB
testcase_42 AC 412 ms
6,612 KB
testcase_43 AC 2 ms
4,376 KB
testcase_44 AC 2 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <cmath>
#include <stdio.h>
#include <queue>
#include <deque>
#include <cstdio>
#include <set>
#include <map>
#include <bitset>
#include <stack>
#include <cctype>
using namespace std;
int n;
long long a[200020], b[200020];
long long check(long long x) {
    long long ans = 0;
    for (int i = 0; i < n; i++) {
        ans += b[i] * abs(x - a[i]);
    }
    return ans;
}
int main() {
    cin >> n;
    for (int i = 0; i < n; i++) {
        cin >> a[i];
    }
    for (int i = 0; i < n; i++) {
        cin >> b[i];
    }
    long long low = -1000007, high = 1000007;
    int co = 500;
    while (co--) {
        long long mid1 = (low * 2 + high) / 3;
        long long mid2 = (low + high * 2) / 3;
        if (check(mid1) > check(mid2)) {
            low = mid1;
        }
        else {
            high = mid2;
        }
    }
    if (check(high-1) > check(high)) {
        cout << high << " " << check(high) << endl;
    }
    else {
        cout << high-1 << " " << check(high-1) << endl;
    }
}
0