結果

問題 No.1251 絶対に間違ってはいけない最小化問題
ユーザー outlineoutline
提出日時 2020-10-09 22:44:48
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,812 bytes
コンパイル時間 1,400 ms
コンパイル使用メモリ 139,316 KB
実行使用メモリ 17,744 KB
最終ジャッジ日時 2023-09-27 18:41:56
合計ジャッジ時間 18,035 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 2 ms
4,380 KB
testcase_03 AC 1 ms
4,376 KB
testcase_04 AC 1 ms
4,376 KB
testcase_05 AC 1 ms
4,376 KB
testcase_06 AC 1 ms
4,380 KB
testcase_07 AC 2 ms
4,380 KB
testcase_08 AC 1 ms
4,380 KB
testcase_09 AC 1 ms
4,376 KB
testcase_10 AC 2 ms
4,380 KB
testcase_11 AC 1 ms
4,376 KB
testcase_12 AC 1 ms
4,376 KB
testcase_13 WA -
testcase_14 AC 2 ms
4,376 KB
testcase_15 WA -
testcase_16 AC 2 ms
4,376 KB
testcase_17 AC 1 ms
4,376 KB
testcase_18 WA -
testcase_19 AC 247 ms
16,340 KB
testcase_20 AC 103 ms
10,800 KB
testcase_21 WA -
testcase_22 AC 114 ms
11,564 KB
testcase_23 AC 9 ms
4,380 KB
testcase_24 WA -
testcase_25 WA -
testcase_26 AC 32 ms
6,072 KB
testcase_27 AC 10 ms
4,376 KB
testcase_28 AC 236 ms
17,484 KB
testcase_29 WA -
testcase_30 AC 241 ms
17,564 KB
testcase_31 AC 238 ms
17,484 KB
testcase_32 AC 244 ms
17,484 KB
testcase_33 WA -
testcase_34 AC 241 ms
17,500 KB
testcase_35 AC 248 ms
17,488 KB
testcase_36 AC 246 ms
17,484 KB
testcase_37 AC 225 ms
17,652 KB
testcase_38 WA -
testcase_39 AC 217 ms
17,372 KB
testcase_40 AC 247 ms
17,552 KB
testcase_41 AC 252 ms
17,564 KB
testcase_42 WA -
testcase_43 AC 2 ms
4,376 KB
testcase_44 AC 1 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <queue>
#include <string>
#include <map>
#include <set>
#include <stack>
#include <tuple>
#include <deque>
#include <array>
#include <numeric>
#include <bitset>
#include <iomanip>
#include <cassert>
#include <chrono>
#include <random>
#include <limits>
#include <iterator>
#include <functional>
#include <sstream>
#include <complex>
#include <cstring>
using namespace std;

using ll = long long;
using P = pair<int, int>;
constexpr int INF = 1001001001;
constexpr int mod = 1000000007;
// constexpr int mod = 998244353;

template<class T>
inline bool chmax(T& x, T y){
    if(x < y){
        x = y;
        return true;
    }
    return false;
}
template<class T>
inline bool chmin(T& x, T y){
    if(x > y){
        x = y;
        return true;
    }
    return false;
}

int main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);

    int N;
    cin >> N;
    vector<int> A(N), B(N);
    map<int, int> mp;
    for(int i = 0; i < N; ++i){
        cin >> A[i];
        mp[A[i]] = -1;
    }
    for(int i = 0; i < N; ++i)  cin >> B[i];

    int K = 0;
    vector<int> xs;
    for(auto& it : mp){
        it.second = K++;
        xs.emplace_back(it.first);
    }
    vector<ll> lsum(K + 1), rsum(K + 1);
    for(int i = 0; i < N; ++i){
        lsum[mp[A[i]] + 1] += B[i];
        rsum[mp[A[i]]] += B[i];
    }
    for(int i = 0; i < K; ++i)  lsum[i + 1] += lsum[i];
    for(int i = K; i > 0; --i)  rsum[i - 1] += rsum[i];
    
    int X = 0;
    ll min_gap = 1e+17;
    for(int i = 0; i < K; ++i){
        ll gap = abs(lsum[i] - rsum[i + 1]);
        if(chmin(min_gap, gap)) X = i;
    }
    X = xs[X];
    ll ans = 0;
    for(int i = 0; i < N; ++i)  ans += (ll)B[i] * abs(X - A[i]);
    cout << X << ' ' << ans << '\n';
}
0