結果

問題 No.1251 絶対に間違ってはいけない最小化問題
ユーザー sapphire__15sapphire__15
提出日時 2020-10-09 21:34:19
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 236 ms / 2,000 ms
コード長 2,112 bytes
コンパイル時間 2,236 ms
コンパイル使用メモリ 111,812 KB
実行使用メモリ 18,312 KB
最終ジャッジ日時 2023-09-27 15:29:43
合計ジャッジ時間 18,038 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 AC 1 ms
4,376 KB
testcase_02 AC 1 ms
4,380 KB
testcase_03 AC 1 ms
4,376 KB
testcase_04 AC 1 ms
4,376 KB
testcase_05 AC 2 ms
4,376 KB
testcase_06 AC 2 ms
4,380 KB
testcase_07 AC 1 ms
4,380 KB
testcase_08 AC 2 ms
4,380 KB
testcase_09 AC 1 ms
4,376 KB
testcase_10 AC 2 ms
4,500 KB
testcase_11 AC 1 ms
4,376 KB
testcase_12 AC 1 ms
4,384 KB
testcase_13 AC 1 ms
4,376 KB
testcase_14 AC 2 ms
4,380 KB
testcase_15 AC 2 ms
4,380 KB
testcase_16 AC 2 ms
4,376 KB
testcase_17 AC 2 ms
4,376 KB
testcase_18 AC 210 ms
17,332 KB
testcase_19 AC 205 ms
17,088 KB
testcase_20 AC 109 ms
11,280 KB
testcase_21 AC 16 ms
4,572 KB
testcase_22 AC 117 ms
11,756 KB
testcase_23 AC 11 ms
4,384 KB
testcase_24 AC 162 ms
14,500 KB
testcase_25 AC 116 ms
11,588 KB
testcase_26 AC 41 ms
6,236 KB
testcase_27 AC 12 ms
4,376 KB
testcase_28 AC 229 ms
18,088 KB
testcase_29 AC 236 ms
18,240 KB
testcase_30 AC 224 ms
18,008 KB
testcase_31 AC 220 ms
18,044 KB
testcase_32 AC 234 ms
18,280 KB
testcase_33 AC 220 ms
18,116 KB
testcase_34 AC 231 ms
18,112 KB
testcase_35 AC 218 ms
18,312 KB
testcase_36 AC 221 ms
18,136 KB
testcase_37 AC 225 ms
18,128 KB
testcase_38 AC 222 ms
18,132 KB
testcase_39 AC 225 ms
18,116 KB
testcase_40 AC 230 ms
18,048 KB
testcase_41 AC 228 ms
18,016 KB
testcase_42 AC 222 ms
18,196 KB
testcase_43 AC 2 ms
4,376 KB
testcase_44 AC 2 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

// #include "pch.h"
#include <iostream>
#include <algorithm>
#include <map>
#include <set>
#include <queue>
#include <bitset>
#include <climits>
#include <string>
#include <cmath>
#include <bitset>
#include <complex>
#include <functional>
#include <ctime>
#include <cassert>
#include <fstream>
#include <stack>
#include <random>

typedef long long ll;
typedef std::pair<int, int> Pii;
typedef std::pair<long long, long long> Pll;
typedef std::pair<double, double> Pdd;

#define rip(i, n, s) for (int i = (s);i < (int)( n ); i++)
#define all(a) a.begin(), a.end()
#define MM << " " <<

template<typename T>
using MaxHeap = std::priority_queue<T>;
template<typename T>
using MinHeap = std::priority_queue<T, std::vector<T>, std::greater<T>>;

template<typename T>
inline bool chmax(T &a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}
template<typename T>
inline bool chmin(T &a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}

# ifndef ONLINE_JUDGE
template<typename T>
void vdeb(std::vector<T> &bb) {
    for (int i = 0;i < bb.size();i++) {
        if (i == bb.size() - 1) std::cout << bb[i];
        else std::cout << bb[i] << ' ';
    }
    std::cout << '\n';
}
template<typename T>
void vdeb(std::vector<std::vector<T>> &bb) {
    for (int i = 0;i < bb.size();i++) {
        std::cout << i << ' ';
        vdeb(bb[i]);
    }
    std::cout << '\n';
}
# endif

using namespace std;

int main() {
    int n; cin >> n;
    vector<ll> a(n);
    rip(i,n,0) cin >> a[i];
    vector<ll> b(n);
    rip(i,n,0) cin >> b[i];
    map<ll, ll> mp;
    rip(i,n,0) {
        if(mp.count(a[i])) {
            mp[a[i]] += b[i]*2;
        }
        else {
            mp[a[i]] = b[i]*2;
        }
    }
    ll prv = (*mp.begin()).first, now = 0, dd = 0, ans =LLONG_MAX/2, ans_id = prv;
    rip(i,n,0) {
        now += abs(prv-a[i]) * b[i];
        dd -= b[i];
    }
    for(auto i:mp) {
        now += dd*(i.first-prv);
        prv = i.first;
        dd += i.second;
        if(chmin(ans, now)) ans_id = prv;
    }
    cout << ans_id MM ans << endl;
}
0