結果

問題 No.1251 絶対に間違ってはいけない最小化問題
ユーザー kirin-masterkirin-master
提出日時 2020-12-07 11:22:45
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 2,696 bytes
コンパイル時間 1,365 ms
コンパイル使用メモリ 170,920 KB
実行使用メモリ 13,760 KB
最終ジャッジ日時 2024-09-17 13:50:54
合計ジャッジ時間 8,183 ms
ジャッジサーバーID
(参考情報)
judge6 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 AC 2 ms
5,376 KB
testcase_02 AC 2 ms
5,376 KB
testcase_03 WA -
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
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 -- -
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp:12: warning: "ONLINE_JUDGE" redefined
   12 | #define ONLINE_JUDGE
      | 
<command-line>: note: this is the location of the previous definition
main.cpp: In function 'std::istream& IN(Ts& ...)':
main.cpp:31:57: warning: fold-expressions only available with '-std=c++17' or '-std=gnu++17' [-Wc++17-extensions]
   31 | std::istream& IN(Ts&... xs){ return (std::cin >> ... >> xs); }
      |                                                         ^~

ソースコード

diff #

#define _USE_MATH_DEFINES
 
#include <bits/stdc++.h>
 
using namespace std;
 
using ll = long long;
using ld = long double;
 
constexpr ll MOD = 998244353;

#define ONLINE_JUDGE
#ifndef ONLINE_JUDGE
template <class T, class U>ostream &operator<<(ostream &o, const map<T, U>&obj) {o << "{"; for (auto &x : obj) o << " (" << x.first << " : " << x.second << ")" << ","; o << " }"; return o;}
template <class T>ostream &operator<<(ostream &o, const set<T>&obj) {o << "{"; for (auto itr = obj.begin(); itr != obj.end(); ++itr) o << (itr != obj.begin() ? ", " : "") << *itr; o << "}"; return o;}
template <class T>ostream &operator<<(ostream &o, const multiset<T>&obj) {o << "{"; for (auto itr = obj.begin(); itr != obj.end(); ++itr) o << (itr != obj.begin() ? ", " : "") << *itr; o << "}"; return o;}
template <class T>ostream &operator<<(ostream &o, const vector<T>&obj) {o << "["; for (int i = 0; i < (int)obj.size(); ++i)o << (i > 0 ? ", " : "") << obj[i]; o << "]"; return o;}
ostream &operator<<(ostream &o, const string &obj) {o << "\""; o << obj.c_str(); o << "\""; return o;}
template <class T, class U>ostream &operator<<(ostream &o, const pair<T, U>&obj) {o << "(" << obj.first << ", " << obj.second << ")"; return o;}
template <template <class tmp>  class T, class U> ostream &operator<<(ostream &o, const T<U> &obj) {o << "{"; for (auto itr = obj.begin(); itr != obj.end(); ++itr)o << (itr != obj.begin() ? ", " : "") << *itr; o << "}"; return o;}
void print_sim_py(void) {cout << endl;}
template <class Head> void print_sim_py(Head&& head) {cout << head;print_sim_py();}
template <class Head, class... Tail> void print_sim_py(Head&& head, Tail&&... tail) {cout << head << " ";print_sim_py(forward<Tail>(tail)...);}

#define print(...) print_sim_py(__VA_ARGS__);
#else
#define print(...);
#endif

template <typename... Ts>
std::istream& IN(Ts&... xs){ return (std::cin >> ... >> xs); }

#define repr(i, a, b) for (int i = a; i <= b; i++)
#define rep(i, n) for (int i = 0; i < n; i++)

ll f(ll x, vector<ll>& b, vector<ll>& a){
    ll ans = 0;
    rep(i, b.size()){
        ans += b[i]*abs(x - a[i]);
    }
    return ans;
}

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

    ll n;
    IN(n);
    vector<ll> a(n),b(n);
    rep(i, n) cin >> a[i];
    rep(i, n) cin >> b[i];

    ll a_min = a[0]; ll a_max = a[0];
    for(auto&& z : a){
        a_min = min(a_min, z);
        a_max = max(a_max, z);
    }

    print(a_min, a_max)

    ll ans = a_max*n;

    ll x = 1;

    repr(i, a_min, a_max){
        ll ans_i = f(i,b,a);
        if(ans_i < ans){
            ans = ans_i;
            x = i;
        }
    }

    cout << x << " " << ans << endl;

    return 0;
}

0